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/ diff --git a/arch-install.sh b/arch-install.sh index 3394fd3..29e183d 100755 --- a/arch-install.sh +++ b/arch-install.sh @@ -10,9 +10,10 @@ 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" +DEFAULT_KEYMAP="uk" LANG="en_GB.UTF-8" LOCALE=`echo ${LANG} | cut -d'.' -f1` LC_COLLATE="C" @@ -48,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" @@ -72,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'." @@ -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,9 +319,31 @@ 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 + 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,18 +365,18 @@ 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 - umount -fv /var/cache/pacman/pkg + umount -fv ${PKG_CACHE} fi if [ "${PARTITION_LAYOUT}" == "brh" ]; then umount -fv ${TARGET_PREFIX}/home @@ -363,7 +386,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 @@ -393,6 +416,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}" @@ -404,7 +430,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" @@ -623,6 +651,15 @@ function build_configuration() { fi 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" } function apply_configuration() { @@ -638,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 @@ -715,6 +752,13 @@ if [ $? -ne 0 ]; then exit 1 fi +if [ -z "${KEYMAP}" ]; then + echo "==> Keyboard mapping not defined, try to determine from install environment" + 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 echo "ERROR! The keyboard mapping you specified, '${KEYMAP}', is not recognised." @@ -737,6 +781,9 @@ final_warning if [ "${MODE}" == "install" ]; then format_disks mount_disks + if [ -z "${NFS_CACHE}" ]; then + bind_pacman_cache + fi fi build_packages diff --git a/common.sh b/common.sh index 23f1fde..ba0cec6 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 diff --git a/docs/README.md b/docs/README.md new file mode 100644 index 0000000..5c92a0b --- /dev/null +++ b/docs/README.md @@ -0,0 +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" +` + + diff --git a/packages/base/packages-extra.txt b/packages/base/packages-extra.txt index 1403e28..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 @@ -35,4 +35,3 @@ wireless-regdb wireless_tools wpa_supplicant xfsprogs -zd1211-firmware 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 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