Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] setup scripts #338

Draft
wants to merge 10 commits into
base: master
Choose a base branch
from
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ xbps-cachedir*
stamps*
!dracut/*/*.sh
!packer/scripts/*.sh
!setupscripts/**
66 changes: 19 additions & 47 deletions build-x86-images.sh.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash

set -eu

Expand All @@ -11,6 +11,13 @@ help() {
echo "${0#/*}: [-a arch] [-b base|enlightenment|xfce|mate|cinnamon|gnome|kde|lxde|lxqt] [-r repo]" >&2
}

includedir=$(mktemp -d -p .)
cleanup() {
rm -rf "$includedir"
}
trap "cleanup" INT TERM QUIT
cp -r setupscripts "$includedir/"

while getopts "a:b:hr:" opt; do
case $opt in
a) ARCH="$OPTARG";;
Expand All @@ -26,61 +33,26 @@ build_variant() {
variant="$1"
shift
IMG=void-live-${ARCH}-${DATE}-${variant}.iso
GRUB_PKGS="grub-i386-efi grub-x86_64-efi"
PKGS="dialog cryptsetup lvm2 mdadm void-docs-browse xtools-minimal xmirror $GRUB_PKGS"
XORG_PKGS="xorg-minimal xorg-input-drivers xorg-video-drivers setxkbmap xauth font-misc-misc terminus-font dejavu-fonts-ttf alsa-plugins-pulseaudio"
SERVICES="sshd"

case $variant in
base)
SERVICES="$SERVICES dhcpcd wpa_supplicant acpid"
;;
enlightenment)
PKGS="$PKGS $XORG_PKGS lightdm lightdm-gtk3-greeter enlightenment terminology udisks2 firefox"
SERVICES="$SERVICES acpid dhcpcd wpa_supplicant lightdm dbus polkitd"
;;
xfce)
PKGS="$PKGS $XORG_PKGS lightdm lightdm-gtk3-greeter xfce4 gnome-themes-standard gnome-keyring network-manager-applet gvfs-afc gvfs-mtp gvfs-smb udisks2 firefox"
SERVICES="$SERVICES dbus elogind lightdm NetworkManager polkitd"
;;
mate)
PKGS="$PKGS $XORG_PKGS lightdm lightdm-gtk3-greeter mate mate-extra gnome-keyring network-manager-applet gvfs-afc gvfs-mtp gvfs-smb udisks2 firefox"
SERVICES="$SERVICES dbus elogind lightdm NetworkManager polkitd"
;;
cinnamon)
PKGS="$PKGS $XORG_PKGS lightdm lightdm-gtk3-greeter cinnamon gnome-keyring colord gnome-terminal gvfs-afc gvfs-mtp gvfs-smb udisks2 firefox"
SERVICES="$SERVICES dbus elogind lightdm NetworkManager polkitd"
;;
gnome)
PKGS="$PKGS $XORG_PKGS gnome firefox"
SERVICES="$SERVICES dbus elogind gdm NetworkManager polkitd"
;;
kde)
PKGS="$PKGS $XORG_PKGS kde5 konsole firefox dolphin"
SERVICES="$SERVICES dbus elogind NetworkManager sddm"
;;
lxde)
PKGS="$PKGS $XORG_PKGS lxde lightdm lightdm-gtk3-greeter gvfs-afc gvfs-mtp gvfs-smb udisks2 firefox"
SERVICES="$SERVICES acpid dbus dhcpcd wpa_supplicant lightdm polkitd"
;;
lxqt)
PKGS="$PKGS $XORG_PKGS lxqt sddm gvfs-afc gvfs-mtp gvfs-smb udisks2 firefox"
SERVICES="$SERVICES elogind dbus dhcpcd wpa_supplicant sddm polkitd"
;;
*)
>&2 echo "Unknown variant $variant"
exit 1
;;
esac
export SETUP_TYPE=iso
. ./setupscripts/main.sh
setup_variant "$variant"

./mklive.sh -a "$ARCH" -o "$IMG" -p "$PKGS" -S "$SERVICES" ${REPO} "$@"
./mklive.sh -a "$ARCH" -o "$IMG" -p "${PKGSSTR}" -S "${SERVICESSTR}" -I ${includedir} ${REPO} "$@"
}

if [ ! -x mklive.sh ]; then
echo mklive.sh not found >&2
exit 1
fi

for image in $IMAGES; do
if [ ! -f "setupscripts/variants/$image.sh" ]; then
echo "Unknown variant $image" >&2
exit 1
fi
done

for image in $IMAGES; do
build_variant "$image" "$@"
done
4 changes: 0 additions & 4 deletions dracut/vmklive/adduser.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ USERSHELL=$(getarg live.shell)
[ -x $NEWROOT/bin/bash -a -z "$USERSHELL" ] && USERSHELL=/bin/bash
[ -z "$USERSHELL" ] && USERSHELL=/bin/sh

# Create /etc/default/live.conf to store USER.
echo "USERNAME=$USERNAME" >> ${NEWROOT}/etc/default/live.conf
chmod 644 ${NEWROOT}/etc/default/live.conf

if ! grep -q ${USERSHELL} ${NEWROOT}/etc/shells ; then
echo ${USERSHELL} >> ${NEWROOT}/etc/shells
fi
Expand Down
106 changes: 22 additions & 84 deletions installer.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -1145,7 +1145,7 @@ mount_filesystems() {
umount_filesystems() {
local f

for f in sys/fs/fuse/connections sys proc dev; do
for f in sys/fs/fuse/connections sys/fs/cgroup/* sys/fs/cgroup sys/kernel/security sys proc dev/pts dev/shm dev; do
echo "Unmounting $TARGETDIR/$f..." >$LOG
umount $TARGETDIR/$f >$LOG 2>&1
done
Expand All @@ -1168,53 +1168,14 @@ umount_filesystems() {
umount $TARGETDIR >$LOG 2>&1
}

log_and_count() {
local progress whole tenth
while read line; do
echo "$line" >$LOG
copy_count=$((copy_count + 1))
progress=$((1000 * copy_count / copy_total))
if [ "$progress" != "$copy_progress" ]; then
whole=$((progress / 10))
tenth=$((progress % 10))
printf "Progress: %d.%d%% (%d of %d files)\n" $whole $tenth $copy_count $copy_total
copy_progress=$progress
fi
done
}
run_setupscript() {
local PKGSSTR="" SERVICESSTR=""

copy_rootfs() {
local tar_in="--create --one-file-system --xattrs"
TITLE="Check $LOG for details ..."
INFOBOX "Counting files, please be patient ..." 4 60
copy_total=$(tar ${tar_in} -v -f /dev/null / 2>/dev/null | wc -l)
export copy_total copy_count=0 copy_progress=
clear
tar ${tar_in} -f - / 2>/dev/null | \
tar --extract --xattrs --xattrs-include='*' --preserve-permissions -v -f - -C $TARGETDIR | \
log_and_count | \
DIALOG --title "${TITLE}" \
--progressbox "Copying live image to target rootfs." 5 60
if [ $? -ne 0 ]; then
DIE 1
fi
unset copy_total copy_count copy_percent
}

install_packages() {
local _grub= _syspkg=

if [ -n "$EFI_SYSTEM" ]; then
if [ $EFI_FW_BITS -eq 32 ]; then
_grub="grub-i386-efi"
else
_grub="grub-x86_64-efi"
fi
else
_grub="grub"
fi

_syspkg="base-system"
cd /
export SETUP_TYPE=system
. /setupscripts/main.sh
setup_variant base
cd -

mkdir -p $TARGETDIR/var/db/xbps/keys $TARGETDIR/usr/share
cp -a /usr/share/xbps.d $TARGETDIR/usr/share/
Expand All @@ -1228,18 +1189,22 @@ install_packages() {
_arch=$(xbps-uhelper arch)

stdbuf -oL env XBPS_ARCH=${_arch} \
xbps-install -r $TARGETDIR -SyU ${_syspkg} ${_grub} 2>&1 | \
DIALOG --title "Installing base system packages..." \
xbps-install -r $TARGETDIR -SyU ${PKGSSTR} 2>&1 | \
DIALOG --title "Installing packages..." \
--programbox 24 80
if [ $? -ne 0 ]; then
DIE 1
fi
xbps-reconfigure -r $TARGETDIR -f base-files >/dev/null 2>&1
chroot $TARGETDIR xbps-reconfigure -a

for service in ${SERVICESSTR}; do
enable_service "$service"
done
}

enable_dhcpd() {
ln -sf /etc/sv/dhcpcd $TARGETDIR/etc/runit/runsvdir/default/dhcpcd
enable_service() {
ln -sf /etc/sv/$1 $TARGETDIR/etc/runit/runsvdir/default/$1
}

menu_install() {
Expand Down Expand Up @@ -1275,37 +1240,10 @@ ${BOLD}Do you want to continue?${RESET}" 20 80 || return

# Create and mount filesystems
create_filesystems

# If source not set use defaults.
if [ "$(get_option SOURCE)" = "local" -o -z "$SOURCE_DONE" ]; then
copy_rootfs
. /etc/default/live.conf
rm -f $TARGETDIR/etc/motd
rm -f $TARGETDIR/etc/issue
rm -f $TARGETDIR/usr/sbin/void-installer
# Remove modified sddm.conf to let sddm use the defaults.
rm -f $TARGETDIR/etc/sddm.conf
# Remove live user.
echo "Removing $USERNAME live user from targetdir ..." >$LOG
chroot $TARGETDIR userdel -r $USERNAME >$LOG 2>&1
rm -f $TARGETDIR/etc/sudoers.d/99-void-live
sed -i "s,GETTY_ARGS=\"--noclear -a $USERNAME\",GETTY_ARGS=\"--noclear\",g" $TARGETDIR/etc/sv/agetty-tty1/conf
TITLE="Check $LOG for details ..."
INFOBOX "Rebuilding initramfs for target ..." 4 60
echo "Rebuilding initramfs for target ..." >$LOG
# mount required fs
mount_filesystems
chroot $TARGETDIR dracut --no-hostonly --add-drivers "ahci" --force >>$LOG 2>&1
INFOBOX "Removing temporary packages from target ..." 4 60
echo "Removing temporary packages from target ..." >$LOG
xbps-remove -r $TARGETDIR -Ry dialog xtools-minimal xmirror >>$LOG 2>&1
rmdir $TARGETDIR/mnt/target
else
# mount required fs
mount_filesystems
# network install, use packages.
install_packages
fi
# mount required fs
mount_filesystems
# install packages and enable services
run_setupscript

INFOBOX "Applying installer settings..." 4 60

Expand Down Expand Up @@ -1339,7 +1277,7 @@ ${BOLD}Do you want to continue?${RESET}" 20 80 || return
cp /etc/wpa_supplicant/wpa_supplicant.conf $TARGETDIR/etc/wpa_supplicant
ln -sf /etc/sv/wpa_supplicant $TARGETDIR/etc/runit/runsvdir/default/wpa_supplicant
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ln -sf /etc/sv/wpa_supplicant $TARGETDIR/etc/runit/runsvdir/default/wpa_supplicant
enable_service wpa_supplicant

another candidate maybe ?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also like the idea of this PR...

fi
enable_dhcpd
enable_service dhcpcd
elif [ -n "$_dev" -a "$_type" = "static" ]; then
# static IP through dhcpcd.
mv $TARGETDIR/etc/dhcpcd.conf $TARGETDIR/etc/dhcpcd.conf.orig
Expand All @@ -1349,7 +1287,7 @@ ${BOLD}Do you want to continue?${RESET}" 20 80 || return
echo "static ip_address=$_ip" >>$TARGETDIR/etc/dhcpcd.conf
echo "static routers=$_gw" >>$TARGETDIR/etc/dhcpcd.conf
echo "static domain_name_servers=$_dns1 $_dns2" >>$TARGETDIR/etc/dhcpcd.conf
enable_dhcpd
enable_service dhcpcd
fi
fi

Expand Down
40 changes: 40 additions & 0 deletions setupscripts/main.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/bash

# snippets used in individual variants to avoid repetition
base() {
PKGS+=("base-system")
if [ "$SETUP_TYPE" = "iso" ]; then
PKGS+=("dialog" "cryptsetup" "lvm2" "mdadm" "void-docs-browse" "xtools-minimal" "grub-i386-efi" "grub-x86_64-efi" "xmirror")
SERVICES+=("sshd")
elif [ "$SETUP_TYPE" = "system" ]; then
if [ -n "$EFI_SYSTEM" ]; then
if [ "$EFI_FW_BITS" -eq 32 ]; then
PKGS+=("grub-i386-efi")
else
PKGS+=("grub-x86_64-efi")
fi
else
PKGS+=("grub")
fi
fi

}

xorg_base() {
base
PKGS+=("xorg-minimal" "xorg-input-drivers" "xorg-video-drivers" "setxkbmap" "xauth" "font-misc-misc" "terminus-font" "dejavu-fonts-ttf" "alsa-plugins-pulseaudio")
}

deduplicate() {
printf "%s\n" $@ | sort -u | tr '\n' ' '
}

# set PKGS, SERVICES and other variables based on which variant we want to set up for
setup_variant() {
variant="$1" # xfce, base, gnome, etc.
local PKGS=()
local SERVICES=()
. "setupscripts/variants/$variant.sh"
PKGSSTR=$(deduplicate "${PKGS[@]}")
SERVICESSTR=$(deduplicate "${SERVICES[@]}")
}
4 changes: 4 additions & 0 deletions setupscripts/variants/base.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
base

SERVICES+=("dhcpcd" "wpa_supplicant" "acpid")
5 changes: 5 additions & 0 deletions setupscripts/variants/cinnamon.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
xorg_base

PKGS+=("lightdm" "cinnamon" "gnome-keyring" "colord" "gnome-terminal" "gvfs-afc" "gvfs-mtp" "gvfs-smb" "udisks2" "firefox")
SERVICES+=("dbus" "elogind" "lightdm" "NetworkManager" "polkitd")
5 changes: 5 additions & 0 deletions setupscripts/variants/enlightenment.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
xorg_base

PKGS+=("lightdm" "enlightenment" "terminology" "udisks2" "firefox")
SERVICES+=("acpid" "dhcpcd" "wpa_supplicant" "lightdm" "dbus" "polkitd")
5 changes: 5 additions & 0 deletions setupscripts/variants/gnome.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
xorg_base

PKGS+=("gnome" "firefox")
SERVICES+=("dbus" "elogind" "gdm" "NetworkManager" "polkitd")
5 changes: 5 additions & 0 deletions setupscripts/variants/kde.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
xorg_base

PKGS+=("kde5" "konsole" "firefox" "dolphin")
SERVICES+=("dbus" "elogind" "NetworkManager" "sddm")
5 changes: 5 additions & 0 deletions setupscripts/variants/lxde.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
xorg_base

PKGS+=("lxde" "lightdm" "gvfs-afc" "gvfs-mtp" "gvfs-smb" "udisks2" "firefox")
SERVICES+=("acpid" "dbus" "dhcpcd" "wpa_supplicant" "lightdm" "polkitd")
5 changes: 5 additions & 0 deletions setupscripts/variants/lxqt.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
xorg_base

PKGS+=("lxqt" "lightdm" "gvfs-afc" "gvfs-mtp" "gvfs-smb" "udisks2" "firefox")
SERVICES+=("elogind" "dbus" "dhcpcd" "wpa_supplicant" "lightdm" "polkitd")
5 changes: 5 additions & 0 deletions setupscripts/variants/mate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
xorg_base

PKGS+=("lightdm" "mate" "mate-extra" "gnome-keyring" "network-manager-applet" "gvfs-afc" "gvfs-mtp" "gvfs-smb" "udisks2" "firefox")
SERVICES+=("dbus" "elogind" "lightdm" "NetworkManager" "polkitd")
5 changes: 5 additions & 0 deletions setupscripts/variants/xfce.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
xorg_base

PKGS+=("lightdm" "xfce4" "gnome-themes-standard" "gnome-keyring" "network-manager-applet" "gvfs-afc" "gvfs-mtp" "gvfs-smb" "udisks2" "firefox")
SERVICES+=("dbus" "elogind" "lightdm" "NetworkManager" "polkitd")