ArchISO/archiso.sh

155 lines
4.1 KiB
Bash
Raw Normal View History

2024-08-19 12:20:08 +02:00
#!/usr/bin/env bash
### https://wiki.archlinux.org/title/Archiso
2024-08-23 16:25:42 +02:00
set -eou pipefail
2024-08-19 12:20:08 +02:00
# Test if archiso is installed
if ! pacman -Qs archiso > /dev/null; then
echo "Error: archiso is not installed."
read -p "Do you want to install archiso? [Y]es or [N]o. \n" -n 1 -r
2024-08-19 12:20:08 +02:00
if [[ $REPLY =~ ^[Yy]$ ]]; then
sudo pacman -Sy archiso
else
echo "Exiting."
exit 0
fi
fi
# Write log
logdir="/home/$USER/.archiso/logs"
mkdir -p "${logdir}"
logfile="${logdir}/$(date +%Y-%m-%d_%H:%M).log"
exec >> >(tee -i "${logfile}")
exec 2>&1
2024-08-19 15:38:48 +02:00
### Customization
# 1. Username
#USER=""
# 2. Packages
declare -a pkgs=(
firefox
konsole
plasma-desktop
sddm
plasma-nm
networkmanager
)
# 3. Plasma session
session="plasmax11" # X11
#session="plasma" # Wayland
2024-08-19 12:20:08 +02:00
2024-08-19 15:38:48 +02:00
# 4. Profile to use
2024-08-19 12:20:08 +02:00
profile="releng"
#profile="baseline"
# releng is used to create the official monthly installation ISO.
# It can be used as a starting point for creating a customized ISO image.
# baseline is a minimal configuration, that includes only the bare minimum
# packages required to boot the live environment from the medium.
2024-08-19 15:38:48 +02:00
# Ask password for ISO user
pw_hash=$(openssl passwd -6)
2024-08-19 12:20:08 +02:00
# Define directories
dir="/home/$USER/.archiso"
prof_dir="${dir}/${profile}"
pkgs_file="${prof_dir}/packages.x86_64"
workdir="/tmp/archiso"
root_etc="${prof_dir}/airootfs/etc"
# Delete old profile
2024-08-23 16:25:42 +02:00
err sudo rm -rf "${prof_dir}"
err sudo rm -rf ${dir}/output/*
err sudo rm -rf ${workdir}
2024-08-19 12:20:08 +02:00
# Copy new profile template
# https://wiki.archlinux.org/title/Archiso#Prepare_a_custom_profile
cp -r "/usr/share/archiso/configs/${profile}" "${dir}"
# Define packages to install
# https://wiki.archlinux.org/title/Archiso#Selecting_packages
touch "${pkgs_file}"
for pkg in "${pkgs[@]}"; do
echo "${pkg}" >> "${pkgs_file}"
done
# Activate sddm.service
# https://wiki.archlinux.org/title/Archiso#Login_manager
ln -s /usr/lib/systemd/system/sddm.service \
"${root_etc}/systemd/system/display-manager.service"
2024-08-19 15:38:48 +02:00
# Enable NetworkManager
mkdir -p "${root_etc}/systemd/system/network-online.target.wants"
ln -s /usr/lib/systemd/system/NetworkManager.service \
"${root_etc}/systemd/system/network-online.target.wants/"
2024-08-19 12:20:08 +02:00
# Autologin config
# https://wiki.archlinux.org/title/Archiso#Changing_automatic_login
mkdir "${root_etc}/sddm.conf.d"
cat << EOF > "${root_etc}/sddm.conf.d/autologin.conf"
[Autologin]
Relogin=false
2024-08-19 15:38:48 +02:00
Session=${session}
User=${USER}
2024-08-19 12:20:08 +02:00
[Theme]
Current=breeze
CursorTheme=Breeze_Light
EOF
# Create user
# https://wiki.archlinux.org/title/Archiso#Users_and_passwords
root_etc="${prof_dir}/airootfs/etc"
echo root:x:0:0:root:/root:/usr/bin/zsh > "${root_etc}/passwd"
echo "${USER}":x:1000:1000::/home/"${USER}":/usr/bin/zsh >> "${root_etc}/passwd"
echo "${USER}:${pw_hash}:14871::::::" >> "${root_etc}/shadow"
echo root:x:0:root > "${root_etc}/group"
echo adm:x:4:"${USER}" >> "${root_etc}/group"
echo wheel:x:10:"${USER}" >> "${root_etc}/group"
echo uucp:x:14:"${USER}" >> "${root_etc}/group"
echo "${USER}":x:1000: >> "${root_etc}/group"
echo root:!*::root > "${root_etc}/gshadow"
echo "${USER}":!*:: >> "${root_etc}/gshadow"
2024-08-23 16:25:42 +02:00
sed -i '27s/.*/ ["\/etc\/gshadow"]="0:0:0400"/' "${HOME}/.archiso/releng/profiledef.sh"
echo ")" >> "${HOME}/.archiso/releng/profiledef.sh"
2024-08-19 12:20:08 +02:00
echo "%wheel ALL=(ALL) ALL" > "${root_etc}/sudoers"
2024-08-23 16:25:42 +02:00
# Change keyboard layout to German
echo "KEYMAP=de-latin1" > "${root_etc}/vconsole.conf"
mkdir -p "${root_etc}/X11/xorg.conf.d"
cat << EOF > "${root_etc}/X11/xorg.conf.d/00-keyboard.conf"
# Written by systemd-localed(8), read by systemd-localed and Xorg. It's
# probably wise not to edit this file manually. Use localectl(1) to
# instruct systemd-localed to update it.
Section "InputClass"
Identifier "system-keyboard"
MatchIsKeyboard "on"
Option "XkbLayout" "de"
EndSection
EOF
2024-08-19 12:20:08 +02:00
# Create image
mkdir -p "${workdir}"
2024-08-23 16:25:42 +02:00
sudo mkarchiso -w "${workdir}" -o "${dir}/output" "${prof_dir}"
2024-08-19 12:20:08 +02:00
2024-08-23 16:25:42 +02:00
# Notification
notify-send -t 5000 'ArchISO' 'ISO created successfully.' &&
if [[ -f /usr/share/sounds/ocean/stereo/dialog-information.oga ]]; then
pw-play /usr/share/sounds/ocean/stereo/dialog-information.oga
fi
2024-08-19 12:20:08 +02:00
2024-08-23 16:25:42 +02:00
exit 0