Skip to content

Commit 0f8b90e

Browse files
committed
installer.sh: support selecting superuser access tool
ref: void-linux/void-packages#56055
1 parent f9923f5 commit 0f8b90e

File tree

1 file changed

+95
-14
lines changed

1 file changed

+95
-14
lines changed

installer.sh

Lines changed: 95 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ USERPASSWORD_DONE=
3737
USERNAME_DONE=
3838
USERGROUPS_DONE=
3939
USERACCOUNT_DONE=
40+
SUPERUSER_DONE=
4041
BOOTLOADER_DONE=
4142
PARTITIONS_DONE=
4243
NETWORK_DONE=
@@ -788,6 +789,69 @@ set_useraccount() {
788789
chroot $TARGETDIR chpasswd -c SHA512
789790
}
790791

792+
menu_superuser() {
793+
local _preset
794+
while true; do
795+
DIALOG --title "Select a superuser access tool (Optional). If ${RED}sudo${RESET} or ${RED}opendoas${RESET} are selected, the configured non-root user will be given access via the ${RED}wheel${RESET} group." \
796+
--menu "$MENULABEL" ${MENUSIZE} \
797+
su "basic user switching tool (default, requires root password)" \
798+
sudo "common and complex superuser tool" \
799+
opendoas "superuser tool from OpenBSD"
800+
if [ $? -eq 0 ]; then
801+
set_option SUPERUSER "$(cat $ANSWER)"
802+
SUPERUSER_DONE=1
803+
break
804+
else
805+
return
806+
fi
807+
done
808+
}
809+
810+
validate_superuser() {
811+
local ROOTPASSWORD="$(get_option ROOTPASSWORD)"
812+
local SUPERUSER="$(get_option SUPERUSER)"
813+
local USERLOGIN="$(get_option USERLOGIN)"
814+
815+
if [ "$SUPERUSER" = su ] && [ -z "$ROOTPASSWORD" ]; then
816+
return 1
817+
fi
818+
if [ "$SUPERUSER" != su ] && [ -z "$USERLOGIN" ]; then
819+
return 2
820+
fi
821+
return 0
822+
}
823+
824+
set_superuser() {
825+
local SUPERUSER="$(get_option SUPERUSER)"
826+
local USERLOGIN="$(get_option USERLOGIN)"
827+
828+
case "$SUPERUSER" in
829+
su)
830+
# nothing, this is part of util-linux and is installed by default
831+
;;
832+
sudo)
833+
if [ -z "$(echo $(get_option USERGROUPS) | grep -w wheel)" -a -n "$USERLOGIN" ]; then
834+
# enable sudo for primary user USERLOGIN who is not member of wheel
835+
echo "# Enable sudo for login '$USERLOGIN'" > "$TARGETDIR/etc/sudoers.d/$USERLOGIN"
836+
echo "$USERLOGIN ALL=(ALL:ALL) ALL" >> "$TARGETDIR/etc/sudoers.d/$USERLOGIN"
837+
else
838+
# enable sudo for members of group wheel
839+
echo "%wheel ALL=(ALL:ALL) ALL" > "$TARGETDIR/etc/sudoers.d/wheel"
840+
fi
841+
;;
842+
opendoas)
843+
if [ -z "$(echo $(get_option USERGROUPS) | grep -w wheel)" -a -n "$USERLOGIN" ]; then
844+
# enable doas for primary user USERLOGIN who is not member of wheel
845+
echo "# Enable doas for login '$USERLOGIN'" > "$TARGETDIR/etc/doas.conf"
846+
echo "permit $USERLOGIN" >> "$TARGETDIR/etc/doas.conf"
847+
else
848+
# enable doas for members of group wheel
849+
echo "permit :wheel" > "$TARGETDIR/etc/doas.conf"
850+
fi
851+
;;
852+
esac
853+
}
854+
791855
menu_bootloader() {
792856
while true; do
793857
DIALOG --title " Select the disk to install the bootloader" \
@@ -1234,6 +1298,11 @@ install_packages() {
12341298
fi
12351299
fi
12361300

1301+
local _superuser="$(get_option SUPERUSER)"
1302+
if [ "$_superuser" = su ]; then
1303+
_superuser=""
1304+
fi
1305+
12371306
_syspkg="base-system"
12381307

12391308
mkdir -p $TARGETDIR/var/db/xbps/keys $TARGETDIR/usr/share
@@ -1248,7 +1317,7 @@ install_packages() {
12481317
_arch=$(xbps-uhelper arch)
12491318

12501319
stdbuf -oL env XBPS_ARCH=${_arch} \
1251-
xbps-install -r $TARGETDIR -SyU ${_syspkg} ${_grub} 2>&1 | \
1320+
xbps-install -r $TARGETDIR -SyU ${_syspkg} ${_grub} ${_superuser} 2>&1 | \
12521321
DIALOG --title "Installing base system packages..." \
12531322
--programbox 24 80
12541323
if [ $? -ne 0 ]; then
@@ -1336,6 +1405,23 @@ with the root user in your new system.${RESET}\n\n
13361405
${BOLD}Do you want to continue?${RESET}" 10 60 || return
13371406
fi
13381407

1408+
# validate superuser configuration
1409+
SUPERUSER_DONE="$(validate_superuser)"
1410+
1411+
case "$SUPERUSER_DONE" in
1412+
1)
1413+
DIALOG --yesno "${BOLD}Superuser access is not set up properly.${RESET}\n\n
1414+
${BOLD}${RED}WARNING: The root password is not set and superuser access is configured to su. Superuser access will not be possible.${RESET}\n\n
1415+
${BOLD}Do you want to continue?${RESET}" 10 60 || return
1416+
;;
1417+
2)
1418+
DIALOG --yesno "${BOLD}Superuser access is not set up properly.${RESET}\n\n
1419+
${BOLD}${RED}WARNING: A non-root user account is not configured and superuser access is configured to sudo or opendoas. Superuser access will not be possible.${RESET}\n\n
1420+
${BOLD}Do you want to continue?${RESET}" 10 60 || return
1421+
;;
1422+
*) ;;
1423+
esac
1424+
13391425
DIALOG --yesno "${BOLD}The following operations will be executed:${RESET}\n\n
13401426
${BOLD}${TARGETFS}${RESET}\n
13411427
${BOLD}${RED}WARNING: data on partitions will be COMPLETELY DESTROYED for new \
@@ -1380,6 +1466,9 @@ ${BOLD}Do you want to continue?${RESET}" 20 80 || return
13801466
if [ "$(get_option BOOTLOADER)" = none ]; then
13811467
TO_REMOVE+=" grub-x86_64-efi grub-i386-efi grub"
13821468
fi
1469+
if [ "$(get_option SUPERUSER)" != sudo ]; then
1470+
TO_REMOVE+=" sudo"
1471+
fi
13831472
# uninstall separately to minimise errors
13841473
for pkg in $TO_REMOVE; do
13851474
xbps-remove -r $TARGETDIR -Ry "$pkg" >>$LOG 2>&1
@@ -1439,18 +1528,7 @@ ${BOLD}Do you want to continue?${RESET}" 20 80 || return
14391528
fi
14401529
fi
14411530

1442-
if [ -d $TARGETDIR/etc/sudoers.d ]; then
1443-
USERLOGIN="$(get_option USERLOGIN)"
1444-
if [ -z "$(echo $(get_option USERGROUPS) | grep -w wheel)" -a -n "$USERLOGIN" ]; then
1445-
# enable sudo for primary user USERLOGIN who is not member of wheel
1446-
echo "# Enable sudo for login '$USERLOGIN'" > "$TARGETDIR/etc/sudoers.d/$USERLOGIN"
1447-
echo "$USERLOGIN ALL=(ALL:ALL) ALL" >> "$TARGETDIR/etc/sudoers.d/$USERLOGIN"
1448-
else
1449-
# enable the sudoers entry for members of group wheel
1450-
echo "%wheel ALL=(ALL:ALL) ALL" > "$TARGETDIR/etc/sudoers.d/wheel"
1451-
fi
1452-
unset USERLOGIN
1453-
fi
1531+
set_superuser
14541532

14551533
# clean up polkit rule - it's only useful in live systems
14561534
rm -f $TARGETDIR/etc/polkit-1/rules.d/void-live.rules
@@ -1528,6 +1606,7 @@ menu() {
15281606
"Timezone" "Set system time zone" \
15291607
"RootPassword" "Set system root password" \
15301608
"UserAccount" "Set primary user name and password" \
1609+
"SuperUser" "Set up superuser access" \
15311610
"BootLoader" "Set disk to install bootloader" \
15321611
"Partition" "Partition disk(s)" \
15331612
"Filesystems" "Configure filesystems and mount points" \
@@ -1548,6 +1627,7 @@ menu() {
15481627
"Timezone" "Set system time zone" \
15491628
"RootPassword" "Set system root password" \
15501629
"UserAccount" "Set primary user name and password" \
1630+
"SuperUser" "Set up superuser access" \
15511631
"BootLoader" "Set disk to install bootloader" \
15521632
"Partition" "Partition disk(s)" \
15531633
"Filesystems" "Configure filesystems and mount points" \
@@ -1575,7 +1655,8 @@ menu() {
15751655
"Timezone") menu_timezone && [ -n "$TIMEZONE_DONE" ] && DEFITEM="RootPassword";;
15761656
"RootPassword") menu_rootpassword && [ -n "$ROOTPASSWORD_DONE" ] && DEFITEM="UserAccount";;
15771657
"UserAccount") menu_useraccount && [ -n "$USERLOGIN_DONE" ] && [ -n "$USERPASSWORD_DONE" ] \
1578-
&& DEFITEM="BootLoader";;
1658+
&& DEFITEM="SuperUser";;
1659+
"SuperUser") menu_superuser && [ -n "$SUPERUSER_DONE" ] && DEFITEM="BootLoader";;
15791660
"BootLoader") menu_bootloader && [ -n "$BOOTLOADER_DONE" ] && DEFITEM="Partition";;
15801661
"Partition") menu_partitions && [ -n "$PARTITIONS_DONE" ] && DEFITEM="Filesystems";;
15811662
"Filesystems") menu_filesystems && [ -n "$FILESYSTEMS_DONE" ] && DEFITEM="Install";;

0 commit comments

Comments
 (0)