ArchISO/archiso.sh

140 lines
3.5 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-19 15:38:48 +02:00
#set -eou pipefail
2024-08-19 12:20:08 +02:00
set -x
# Test if archiso is installed
if ! pacman -Qs archiso > /dev/null; then
echo "Error: archiso is not installed."
read -p "Do youwant to install archiso? [Y]es or [N]o. \n" -n 1 -r
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-19 15:38:48 +02:00
sudo rm -rf "${prof_dir}"
2024-08-19 12:20:08 +02:00
sudo rm -rf ${dir}/output/*
2024-08-19 15:38:48 +02:00
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"
sed -i '27s/.*/ ["\/etc\/gshadow"]="0:0:0400"/' "$HOME/.archiso/releng/profiledef.sh"
echo ")" >> "$HOME/.archiso/releng/profiledef.sh"
echo "%wheel ALL=(ALL) ALL" > "${root_etc}/sudoers"
# Create image
mkdir -p "${workdir}"
nice -n 19 ionice -c 3 sudo mkarchiso -w "${workdir}" -o "${dir}/output" "${prof_dir}"
2024-08-19 15:38:48 +02:00
notify-send -t 5000 'ArchISO' 'ISO created successfully.'
2024-08-19 12:20:08 +02:00
exit 0
# To-Dos
2024-08-19 15:38:48 +02:00
# - Locale DE