From ea7cf650b742cd102b583a2e96f6bc4788fea9ff Mon Sep 17 00:00:00 2001 From: Tobias Mucke Date: Sat, 23 Mar 2019 08:42:04 +0000 Subject: [PATCH 01/12] Add docs with first example showing how to start ArchInstaller. --- docs/README.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 docs/README.md diff --git a/docs/README.md b/docs/README.md new file mode 100644 index 0000000..dd015c7 --- /dev/null +++ b/docs/README.md @@ -0,0 +1 @@ +#. -d sda -p brh -w test-124 -b msdos -f xfs -e xfce -k de-latin1 -l en_US.UTF-8 -n arch001 -r desktop -t Europe/Berlin From 3c40e89d1d9ac2a832d1c903baa2a65efa7736c5 Mon Sep 17 00:00:00 2001 From: Tobias Mucke Date: Sat, 23 Mar 2019 08:55:20 +0000 Subject: [PATCH 02/12] Adapt package lists to actually available packages. --- packages/base/packages-extra.txt | 1 - packages/desktop/packages-cups.txt | 1 - packages/desktop/packages-mate.txt | 2 +- packages/desktop/packages-xfce.txt | 2 +- 4 files changed, 2 insertions(+), 4 deletions(-) diff --git a/packages/base/packages-extra.txt b/packages/base/packages-extra.txt index 1403e28..111d0c5 100644 --- a/packages/base/packages-extra.txt +++ b/packages/base/packages-extra.txt @@ -35,4 +35,3 @@ wireless-regdb wireless_tools wpa_supplicant xfsprogs -zd1211-firmware diff --git a/packages/desktop/packages-cups.txt b/packages/desktop/packages-cups.txt index 1199ef6..d1f54ac 100644 --- a/packages/desktop/packages-cups.txt +++ b/packages/desktop/packages-cups.txt @@ -3,7 +3,6 @@ cups-filters foomatic-db foomatic-db-engine foomatic-db-nonfree -foomatic-filters ghostscript gsfonts gutenprint diff --git a/packages/desktop/packages-mate.txt b/packages/desktop/packages-mate.txt index 55d716a..3f900d6 100644 --- a/packages/desktop/packages-mate.txt +++ b/packages/desktop/packages-mate.txt @@ -1,6 +1,6 @@ +lightdm-gtk-greeter accountsservice cups-pk-helper -lightdm-gtk2-greeter mate mate-extras network-manager-applet diff --git a/packages/desktop/packages-xfce.txt b/packages/desktop/packages-xfce.txt index f5c395f..305923d 100644 --- a/packages/desktop/packages-xfce.txt +++ b/packages/desktop/packages-xfce.txt @@ -1,4 +1,4 @@ -lightdm-gtk2-greeter +lightdm-gtk-greeter xfce4 xfce4-goodies network-manager-applet From 12076b2cf693830d0e87d0e8aefa32d19b282b0d Mon Sep 17 00:00:00 2001 From: Tobias Mucke Date: Sun, 24 Mar 2019 10:38:41 +0100 Subject: [PATCH 03/12] Rename .gitingnore to .gitignore. Exclude IntelliJ from version control. --- .gitingnore => .gitignore | 5 +++++ 1 file changed, 5 insertions(+) rename .gitingnore => .gitignore (55%) diff --git a/.gitingnore b/.gitignore similarity index 55% rename from .gitingnore rename to .gitignore index 4650968..8766a45 100644 --- a/.gitingnore +++ b/.gitignore @@ -2,3 +2,8 @@ local.txt prime.txt users.csv + +# +# IntelliJ Idea +# +/.idea/ From 2d492da8cf2f49e99fdb41506cc716495c8c2154 Mon Sep 17 00:00:00 2001 From: Tobias Mucke Date: Sun, 24 Mar 2019 20:45:17 +0100 Subject: [PATCH 04/12] Add explanation of supported parameters. --- docs/README.md | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/docs/README.md b/docs/README.md index dd015c7..5c92a0b 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1 +1,62 @@ +The power of ArchInstaller a little more in detail. Enjoy! + +# Parameters + +The script arch-install.sh supports several parameters to customize the +Archlinux installation. Some of the parameters are required but most of +them are optional. + +## Required parameters + +| Parameter | Explanation | Options | Example | +|--- |--- |--- |--- | +| -d | Target device. | - | sda | +| -p | Partition layout. | brh / br | brh: /boot, /root, /home +| | | | br: /boot, /root +| -w | Root password, unencrypted. | - | brh: /boot, /root, /home + + #. -d sda -p brh -w test-124 -b msdos -f xfs -e xfce -k de-latin1 -l en_US.UTF-8 -n arch001 -r desktop -t Europe/Berlin + +## Optional parameters + +| Parameter | Explanation | Options | Example | +|--- |--- |--- |--- | +| -b | Partition type. Default: msdos | msdos / gpt | msdos | +| -f | Filesystems to format the partitions. Default: ext4 | bfs / btrfs / ext2 / ext3 / ext4 / f2fs / jfs / nilfs / ntfs / reiserfs / xfs | xfs +| -c | NFS export to mount and used as pacman cache. | - | nas.local:/srv/pacman/cache +| -e | Desktop environment to install. Default: none | none / cinnamon / gnome / kde / lxde / mate / xfce | xfce +| -k | Keyboard mapping. Default: uk | See '/usr/share/kbd/keymaps/' for options. | de-latin1 +| -l | System language. Default: en_GB.UTF-8 | See '/etc/locale.gen' for options. | en_US.UTF-8 +| -n | Hostname, fully qualified. Default: arch.example.org | - | arch001.local +| -r | Computer role. Default: desktop | desktop / server | desktop +| -t | Timezone. Default: Europe/London | See '/usr/share/zoneinfo/' for options. | Europe/Berlin + + +## Example + +The following command installs Archlinux with these attributes: + +- Desktop system leveraging XFCE as desktop environment +- English as system language +- German keyboard layout +- German timezone +- Erase disk /dev/sda and format with a classical partitioning. +- Create three filesystems: /boot, /root and /home, the latter two + formated with XFS, /boot is always ext2 +- Simple root password, don't use it in your installation +- Set hostname to arch001.local + +`./arch-install.sh -d sda -p brh -w test-123! -b msdos -f xfs -e xfce -k +de-latin1 -l en_US.UTF-8 -n arch001.local -r desktop -t Europe/Berlin` + +# User provisioning + +To provision users create a file in the following format to define user +accounts. + +` +"username,password,comment,extra_groups" +` + + From 8caea4da5e00bed3f9926a888021c83ddd0a0ce1 Mon Sep 17 00:00:00 2001 From: Tobias Mucke Date: Fri, 29 Mar 2019 09:19:30 +0100 Subject: [PATCH 05/12] Support comments in package lists. --- arch-install.sh | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/arch-install.sh b/arch-install.sh index 3394fd3..f84aad1 100755 --- a/arch-install.sh +++ b/arch-install.sh @@ -318,9 +318,25 @@ function mount_disks() { fi } +function chain_package_lists() { + # Chain package lists + for f in $*; do + if [ -r $f ]; then + files+="$f " + else + echo "ERROR! file $f not readable." + fi + done + + if [ -n "${files}" ]; then + # Remove lines starting with #, replace trailing comments introduced by #, remove empty lines + cat ${files} | sed '/^#.*$/d' | sed 's/[[:space:]]*#.*$//' | sed '/^[[:space:]]*$/d' + fi +} + function build_packages() { # Chain packages - cat packages/base/packages-extra.txt > /tmp/packages.txt + chain_package_lists packages/base/packages-extra.txt > /tmp/packages.txt if [ "${DE}" != "none" ] && [ "${INSTALL_TYPE}" == "desktop" ]; then if [ "${DE}" == "kde" ]; then if [ "${LOCALE}" == "pt_BR" ] || [ "${LOCALE}" == "en_GB" ] || [ "${LOCALE}" == "zh_CN" ]; then @@ -342,14 +358,14 @@ function build_packages() { fi # Chain the DE packages. - cat packages/desktop/packages-xorg.txt packages/desktop/packages-${DE}.txt packages/desktop/packages-gst.txt packages/desktop/packages-cups.txt packages/desktop/packages-ttf.txt >> /tmp/packages.txt + chain_package_lists packages/desktop/packages-xorg.txt packages/desktop/packages-${DE}.txt packages/desktop/packages-gst.txt packages/desktop/packages-cups.txt packages/desktop/packages-ttf.txt >> /tmp/packages.txt fi } function install_packages() { # Install packages if [ "${MODE}" == "install" ]; then - pacstrap -c ${TARGET_PREFIX} $(cat packages/base/packages-base.txt /tmp/packages.txt) + pacstrap -c ${TARGET_PREFIX} $(chain_package_lists packages/base/packages-base.txt /tmp/packages.txt) if [ $? -ne 0 ]; then echo "ERROR! 'pacstrap' failed. Cleaning up and exitting." if [ -n "${NFS_CACHE}" ]; then @@ -363,7 +379,7 @@ function install_packages() { fi else pacman -Rs --noconfirm heirloom-mailx - pacman -S --noconfirm --needed $(cat packages/base/packages-base.txt) + pacman -S --noconfirm --needed $(chain_package_lists packages/base/packages-base.txt) if [ "${BASE_ARCH}" == "x86" ]; then pacman -S --noconfirm --needed $(cat /tmp/packages.txt) else From 10ee7ea9ba852a25a96cbd5fe60a3e16ff85bb38 Mon Sep 17 00:00:00 2001 From: Tobias Mucke Date: Fri, 29 Mar 2019 09:33:23 +0100 Subject: [PATCH 06/12] Add post install feature and use it to set keymap for vconsole and X11. --- arch-install.sh | 9 ++++++++- common.sh | 22 ++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/arch-install.sh b/arch-install.sh index f84aad1..36e87dc 100755 --- a/arch-install.sh +++ b/arch-install.sh @@ -409,6 +409,9 @@ function build_configuration() { # Start building the configuration script start_config + # Start building the configuration script + start_postinstall + # Configure the hostname. add_config "echo ${FQDN} > /etc/hostname" add_config "hostnamectl set-hostname --static ${FQDN}" @@ -420,7 +423,9 @@ function build_configuration() { # Font and font map FONT="ter-116b" - add_config "echo KEYMAP=${KEYMAP} > /etc/vconsole.conf" + add_postinstall "# Set keymap to none first, to make sure localectl sets keymap for vconsole and X11." + add_postinstall "localectl set-keymap none" + add_postinstall "localectl set-keymap ${KEYMAP}" add_config "echo FONT=${FONT} >> /etc/vconsole.conf" add_config "echo FONT_MAP=${FONT_MAP} >> /etc/vconsole.conf" add_config "sed -i \"s/#${LANG}/${LANG}/\" /etc/locale.gen" @@ -639,6 +644,8 @@ function build_configuration() { fi done fi + + add_postinstall "systemctl disable arch-postinstall" } function apply_configuration() { diff --git a/common.sh b/common.sh index 23f1fde..c60c0c9 100755 --- a/common.sh +++ b/common.sh @@ -398,6 +398,28 @@ add_config() { echo "${1}" >> ${TARGET_PREFIX}/usr/local/bin/arch-config.sh } +start_postinstall() { + cat <<- 'EOF' > ${TARGET_PREFIX}/etc/systemd/system/arch-postinstall.service + [Unit] + Description=Post Install Script + + [Service] + ExecStart=/usr/local/bin/arch-postinstall.sh + + [Install] + WantedBy=local-fs.target + EOF + + add_config "systemctl enable arch-postinstall" + + echo "#!/usr/bin/env bash" > ${TARGET_PREFIX}/usr/local/bin/arch-postinstall.sh + chmod +x ${TARGET_PREFIX}/usr/local/bin/arch-postinstall.sh +} + +add_postinstall() { + echo "${1}" >> ${TARGET_PREFIX}/usr/local/bin/arch-postinstall.sh +} + detect_laptop() { # Are we a mac? if test -d /proc/pmu; then From 74ef8c226b2e2ef36eaa5a21a97c0589cc3b55c6 Mon Sep 17 00:00:00 2001 From: Tobias Mucke Date: Fri, 29 Mar 2019 10:36:26 +0100 Subject: [PATCH 07/12] Adopt proxy configuration from Arch Linux Live to installed system. --- arch-install.sh | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/arch-install.sh b/arch-install.sh index 36e87dc..69c9157 100755 --- a/arch-install.sh +++ b/arch-install.sh @@ -645,6 +645,13 @@ function build_configuration() { done fi + if [ "${MODE}" == "install" ]; then + proxies="$(set | grep -i -E "^[a-z]*_proxy")" + for proxy in $proxies; do + add_config "echo export ${proxy} >> /etc/profile.d/proxy.sh" + done + fi + add_postinstall "systemctl disable arch-postinstall" } From b6ebf79b0a44031b429375cd16d563a0a925fe38 Mon Sep 17 00:00:00 2001 From: Tobias Mucke Date: Fri, 29 Mar 2019 10:42:22 +0100 Subject: [PATCH 08/12] Adopt defined display manager package to actual Archlinux repo. --- packages/desktop/packages-cinnamon.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/desktop/packages-cinnamon.txt b/packages/desktop/packages-cinnamon.txt index c040019..e34d90b 100644 --- a/packages/desktop/packages-cinnamon.txt +++ b/packages/desktop/packages-cinnamon.txt @@ -18,7 +18,7 @@ gnome-screenshot gnome-system-log gnome-system-monitor gksu -lightdm-gtk3-greeter +lightdm-gtk-greeter nemo networkmanager-openvpn networkmanager-pptp From af8166722982e53dfb2ed31a18d5d2dce5f531a3 Mon Sep 17 00:00:00 2001 From: Tobias Mucke Date: Fri, 29 Mar 2019 11:09:00 +0100 Subject: [PATCH 09/12] Fix EOF in HERE document and adopt package list with bluez-firmware to actual Archlinux repo. --- common.sh | 2 +- packages/base/packages-extra.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/common.sh b/common.sh index c60c0c9..ba0cec6 100755 --- a/common.sh +++ b/common.sh @@ -408,7 +408,7 @@ start_postinstall() { [Install] WantedBy=local-fs.target - EOF +EOF add_config "systemctl enable arch-postinstall" diff --git a/packages/base/packages-extra.txt b/packages/base/packages-extra.txt index 111d0c5..1571c71 100644 --- a/packages/base/packages-extra.txt +++ b/packages/base/packages-extra.txt @@ -1,7 +1,7 @@ alsa-firmware avahi b43-fwcutter -bluez-firmware +#bluez-firmware btrfs-progs ca-certificates cpupower From c1313e72b75cf07a5d3401900465cfb29df1d006 Mon Sep 17 00:00:00 2001 From: Tobias Mucke Date: Sat, 30 Mar 2019 23:07:39 +0100 Subject: [PATCH 10/12] Mount pacman package cache from target system via bind mount to prevent downloading into cowspace which is too small to install an Archlinux server or desktop. --- arch-install.sh | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/arch-install.sh b/arch-install.sh index 69c9157..ef88210 100755 --- a/arch-install.sh +++ b/arch-install.sh @@ -10,6 +10,7 @@ fi BASE_GROUPS="adm,audio,disk,lp,optical,storage,video,games,power,scanner,uucp" DSK="" NFS_CACHE="" +PKG_CACHE="/var/cache/pacman/pkg" FQDN="arch.example.org" TIMEZONE="Europe/London" KEYMAP="uk" @@ -176,7 +177,7 @@ function test_nfs_cache() { echo echo "Testing NFS cache : ${NFS_CACHE}" systemctl start rpc-statd.service >/dev/null - mount -t nfs ${NFS_CACHE} /var/cache/pacman/pkg >/dev/null + mount -t nfs ${NFS_CACHE} ${PKG_CACHE} >/dev/null if [ $? -ne 0 ]; then echo "ERROR! Unable to mount ${NFS_CACHE}" echo " - See `basename ${0}` -h" @@ -184,12 +185,12 @@ function test_nfs_cache() { fi # Make sure the cache is writeable - touch /var/cache/pacman/pkg/cache.test 2>/dev/null + touch ${PKG_CACHE}/cache.test 2>/dev/null if [ $? -ne 0 ]; then echo "ERROR! The NFS cache, ${NFS_CACHE}, is read-only." exit 1 else - rm /var/cache/pacman/pkg/cache.test 2>/dev/null + rm ${PKG_CACHE}/cache.test 2>/dev/null fi fi } @@ -318,6 +319,12 @@ function mount_disks() { fi } +function bind_pacman_cache() { + echo "==> Bind mounting pacman cache" + mkdir -p ${TARGET_PREFIX}${PKG_CACHE} + mount --bind ${TARGET_PREFIX}${PKG_CACHE} ${PKG_CACHE} +} + function chain_package_lists() { # Chain package lists for f in $*; do @@ -369,7 +376,7 @@ function install_packages() { if [ $? -ne 0 ]; then echo "ERROR! 'pacstrap' failed. Cleaning up and exitting." if [ -n "${NFS_CACHE}" ]; then - umount -fv /var/cache/pacman/pkg + umount -fv ${PKG_CACHE} fi if [ "${PARTITION_LAYOUT}" == "brh" ]; then umount -fv ${TARGET_PREFIX}/home @@ -668,9 +675,9 @@ function apply_configuration() { function cleanup() { sync if [ -n "${NFS_CACHE}" ]; then - addlinetofile "${NFS_CACHE} /var/cache/pacman/pkg nfs defaults,relatime,noauto,x-systemd.automount,x-systemd.device-timeout=5s 0 0" ${TARGET_PREFIX}/etc/fstab + addlinetofile "${NFS_CACHE} ${PKG_CACHE} nfs defaults,relatime,noauto,x-systemd.automount,x-systemd.device-timeout=5s 0 0" ${TARGET_PREFIX}/etc/fstab if [ "${MODE}" == "install" ]; then - umount -fv /var/cache/pacman/pkg + umount -fv ${PKG_CACHE} fi fi @@ -767,6 +774,9 @@ final_warning if [ "${MODE}" == "install" ]; then format_disks mount_disks + if [ -z "${NFS_CACHE}" ]; then + bind_pacman_cache + fi fi build_packages From 113bacf66032c3caefa67bba7e2d444502957330 Mon Sep 17 00:00:00 2001 From: Tobias Mucke Date: Sun, 31 Mar 2019 10:26:28 +0200 Subject: [PATCH 11/12] Determine keyboad map from install environment if not specified at the command line. --- arch-install.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/arch-install.sh b/arch-install.sh index ef88210..40693d2 100755 --- a/arch-install.sh +++ b/arch-install.sh @@ -752,6 +752,10 @@ if [ $? -ne 0 ]; then exit 1 fi +if [ -z "${KEYMAP}" ]; then + echo "==> Keyboard mapping not defined, try to determine from install environment" + KEYMAP="$(fc -ln 0 | grep "^loadkeys " | tail -1 | awk '{print $2}')" +fi KEYMAP_TEST=`ls -1 /usr/share/kbd/keymaps/*/*/*${KEYMAP}*` if [ $? -ne 0 ]; then echo "ERROR! The keyboard mapping you specified, '${KEYMAP}', is not recognised." From 4e09f478ed71217af2768cdd963209f49aecb8fc Mon Sep 17 00:00:00 2001 From: Tobias Mucke Date: Sun, 31 Mar 2019 11:52:23 +0200 Subject: [PATCH 12/12] Fix approach to determine keyboad map from installation environment and consider default keymap set in install script. --- arch-install.sh | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/arch-install.sh b/arch-install.sh index 40693d2..29e183d 100755 --- a/arch-install.sh +++ b/arch-install.sh @@ -13,7 +13,7 @@ NFS_CACHE="" PKG_CACHE="/var/cache/pacman/pkg" FQDN="arch.example.org" TIMEZONE="Europe/London" -KEYMAP="uk" +DEFAULT_KEYMAP="uk" LANG="en_GB.UTF-8" LOCALE=`echo ${LANG} | cut -d'.' -f1` LC_COLLATE="C" @@ -49,9 +49,9 @@ function usage() { echo echo "Usage" if [ "${MODE}" == "install" ]; then - echo " ${0} -d sda -p brh -w P@ssw0rd -b ${PARTITION_TYPE} -f ${FS} -k ${KEYMAP} -l ${LANG} -n ${FQDN} -t ${TIMEZONE}" + echo " ${0} -d sda -p brh -w P@ssw0rd -b ${PARTITION_TYPE} -f ${FS} -k ${DEFAULT_KEYMAP} -l ${LANG} -n ${FQDN} -t ${TIMEZONE}" else - echo " ${0} -w P@ssw0rd -k ${KEYMAP} -l ${LANG} -n ${FQDN} -t ${TIMEZONE}" + echo " ${0} -w P@ssw0rd -k ${DEFAULT_KEYMAP} -l ${LANG} -n ${FQDN} -t ${TIMEZONE}" fi echo echo "Required parameters" @@ -73,7 +73,7 @@ function usage() { fi echo " -c : The NFS export to mount and use as the pacman cache." echo " -e : The desktop environment to install. Defaults to '${DE}'. Can be 'none', 'cinnamon', 'gnome', 'kde', 'lxde', 'mate' or 'xfce'" - echo " -k : The keyboard mapping to use. Defaults to '${KEYMAP}'. See '/usr/share/kbd/keymaps/' for options." + echo " -k : The keyboard mapping to use. Defaults to '${DEFAULT_KEYMAP}'. See '/usr/share/kbd/keymaps/' for options." echo " -l : The language to use. Defaults to '${LANG}'. See '/etc/locale.gen' for options." echo " -n : The hostname to use. Defaults to '${FQDN}'" echo " -r : The computer role. Defaults to '${INSTALL_TYPE}'. Can be 'desktop' or 'server'." @@ -754,7 +754,10 @@ fi if [ -z "${KEYMAP}" ]; then echo "==> Keyboard mapping not defined, try to determine from install environment" - KEYMAP="$(fc -ln 0 | grep "^loadkeys " | tail -1 | awk '{print $2}')" + KEYMAP="$(cat ~/.zsh_history | awk -F";" '{print $NF}' | grep "^loadkeys " | tail -1 | awk '{print $2}')" + if [ -z "${KEYMAP}" ]; then + KEYMAP="${DEFAULT_KEYMAP}" + fi fi KEYMAP_TEST=`ls -1 /usr/share/kbd/keymaps/*/*/*${KEYMAP}*` if [ $? -ne 0 ]; then