Skip to content

Commit

Permalink
sudo without password
Browse files Browse the repository at this point in the history
  • Loading branch information
nothub committed Dec 16, 2023
1 parent 3200088 commit fdd5c24
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ echo "ssh-ed25519 AAAA... bar" >> configs/authorized_keys
-s <sign_key> ISO pgp sign key
-o <out_file> ISO output file
-x Power off after install
-z Sudo without password
-v Enable verbose mode
-h Display this help message
```
Expand Down
16 changes: 13 additions & 3 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set -o nounset
set -o pipefail

usage() {
echo "Usage: $0 [-u username] [-p password] [-n hostname] [-d domain] [-a package] [-i iso_url] [-s sign_key] [-o path] [-x] [-v] [-h]"
echo "Usage: $0 [-u username] [-p password] [-n hostname] [-d domain] [-a package] [-i iso_url] [-s sign_key] [-o path] [-x] [-z] [-v] [-h]"
echo "Options:"
echo " -u <username> Admin username"
echo " -p <password> Admin password"
Expand All @@ -16,6 +16,7 @@ usage() {
echo " -s <sign_key> ISO pgp sign key"
echo " -o <out_file> ISO output file"
echo " -x Power off after install"
echo " -z Sudo without password"
echo " -v Enable verbose mode"
echo " -h Display this help message"
}
Expand All @@ -30,8 +31,9 @@ sign_key="DA87E80D6294BE9B"
out_file="debian-12.4.0-amd64-auto.iso"
apt_pkgs=()
poweroff=""
sudonopw=""

while getopts u:p:n:d:a:i:s:o:xvh opt; do
while getopts u:p:n:d:a:i:s:o:xzvh opt; do
case $opt in
u) username="$OPTARG" ;;
p) password="$OPTARG" ; password_mask="true" ;;
Expand All @@ -42,6 +44,7 @@ while getopts u:p:n:d:a:i:s:o:xvh opt; do
s) sign_key="$OPTARG" ;;
o) out_file="$OPTARG" ;;
x) poweroff="true" ;;
z) sudonopw="true" ;;
v) set -o xtrace ;;
h) usage ; exit 0 ;;
*) usage ; exit 1 ;;
Expand Down Expand Up @@ -104,12 +107,19 @@ replace_token "@DOMAIN@" "${domain}"
replace_token "@PACKAGES@" "${apt_pkgs[*]}"

# add poweroff option
if test -n "${poweroff}"; then
if test "${poweroff}" = "true"; then
replace_token "@POWEROFF@" "true"
else
replace_token "@POWEROFF@" "false"
fi

# add sudo no-password option
if test "${sudonopw}" = "true"; then
replace_token "@SUDONOPW@" "true"
else
replace_token "@SUDONOPW@" "false"
fi

# clear existing output iso file
if test -f "${out_file}"; then
rm -f "${out_file}"
Expand Down
6 changes: 6 additions & 0 deletions installer/late.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ prefix="/target"
admin="@USERNAME@"
hostname="@HOSTNAME@"
domain="@DOMAIN@"
sudonopw="@SUDONOPW@"

if test "${hostname}" == "undefined"; then
# generate hostname from mac addresses
Expand All @@ -30,6 +31,11 @@ cp -a "/cdrom/configs/issue" "${prefix}/etc/issue"
cp -a "/cdrom/configs/motd" "${prefix}/etc/motd"
cp -a "/cdrom/configs/sshd_config" "${prefix}/etc/ssh/sshd_config"

# allow sudo without password
if test "${sudonopw}" = "true"; then
echo "${admin} ALL=(ALL) NOPASSWD: ALL" > "${prefix}/etc/sudoers.d/${admin}"
fi

# authorize ssh keys for root user
mkdir -p "${prefix}/root/.ssh"
chmod 700 "${prefix}/root/.ssh"
Expand Down

0 comments on commit fdd5c24

Please sign in to comment.