Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- get_conf() { ############# CONFIGURATION ###################################################################
- log "$1"
- if [ ! -f conf.sh ]; then
- wget https://pastebin.com/raw/Ed9xkKq4 -O conf.sh &>/dev/null
- echo -e "Datei 'conf.sh' heruntergeladen!"
- exit
- fi
- }
- export install_log="$(mktemp -t install_logXXX)"
- export red="\033[1;31m"
- export green="\033[1;32m"
- export cyan="\033[0;36m"
- export normal="\033[0m"
- title() {
- clear
- echo -ne "${cyan}# Artix Linux Automated Installer (no interaction) #${normal}"
- }
- case "$init_system" in
- dinit) export init_programs=("dinit" "elogind-dinit");;
- openrc) export init_programs=("openrc" "elogind-openrc");;
- runit) export init_programs=("runit" "elogind-runit");;
- s6) export init_programs=("s6-base" "elogind-s6");;
- *) echo "Ungültiges init_system!"; exit 1;;
- esac
- get_init() {
- log "$1"
- echo -e "\nWhich init system do you want to use?"
- options=("dinit" "openrc" "runit" "s6")
- select_option $? 1 "${options[@]}"
- case $? in
- 0) export init_system="dinit"
- export init_programs=("dinit" "elogind-dinit");;
- 1) export init_system="openrc"
- export init_programs=("openrc" "elogind-openrc");;
- 2) export init_system="runit"
- export init_programs=("runit" "elogind-runit");;
- 3) export init_system="s6"
- export init_programs=("s6-base" "elogind-s6");;
- esac
- }
- mount_partitions() {
- log "$1"
- mount "${root_partition}" /mnt
- mkdir -p /mnt/boot
- mount "${boot_partition}" /mnt/boot
- }
- init_base() {
- log "$1"
- loadkeys de_CH-latin1
- sed -i '1iServer = https://mirror2.artixlinux.org/$repo/os/$arch' /etc/pacman.d/mirrorlist
- sed -i 's/^#Color/Color/' /etc/pacman.conf
- sed -i '/^Color/!s/^#Color/Color/' /etc/pacman.conf
- if grep -q '^#ParallelDownloads' /etc/pacman.conf; then
- sed -i 's/^#ParallelDownloads.*/ParallelDownloads = 10/' /etc/pacman.conf
- elif grep -q '^ParallelDownloads' /etc/pacman.conf; then
- sed -i 's/^ParallelDownloads.*/ParallelDownloads = 10/' /etc/pacman.conf
- else
- echo 'ParallelDownloads = 10' >> /etc/pacman.conf
- fi
- }
- install_base_system() {
- log "$1"
- basestrap /mnt base base-devel linux-zen linux-zen-headers linux-firmware efibootmgr "${init_programs[@]}"
- fstabgen -U /mnt >> /mnt/etc/fstab
- }
- config_time() {
- log "$1"
- ln -sf "/usr/share/zoneinfo/${timezone}" /etc/localtime
- hwclock --systohc
- }
- config_lang() {
- log "$1"
- echo -e "en_US.UTF-8 UTF-8\nde_CH.UTF-8 UTF-8" >> /etc/locale.gen
- locale-gen
- echo -e "LANG=en_US.UTF-8\nLC_COLLATE=C\nLC_TIME=de_CH.UTF-8\nLC_NUMERIC=de_CH.UTF-8\nLC_MONETARY=de_CH.UTF-8\nLC_PAPER=de_CH.UTF-8\nLC_MEASUREMENT=de_CH.UTF-8" > /etc/locale.conf
- echo "KEYMAP=de_CH-latin1" > /etc/vconsole.conf
- }
- config_network() {
- log "$1"
- echo "${hostname}" > /etc/hostname
- echo -e "127.0.0.1\tlocalhost" >> /etc/hosts
- echo -e "::1\t\tlocalhost" >> /etc/hosts
- echo -e "127.0.1.1\t${hostname}.localdomain ${hostname}" >> /etc/hosts
- pacman -S --noconfirm --needed connman-${init_system}
- case "${init_system}" in
- dinit) ln -s ../connmand /etc/dinit.d/boot.d/;;
- openrc) rc-update add connmand;;
- runit) ln -s /etc/runit/sv/connmand /etc/runit/runsvdir/default;;
- s6) touch /etc/s6/adminsv/default/contents.d/connmand
- s6-db-reload;;
- esac
- }
- create_user() {
- log "$1"
- echo -e "${root_password}\n${root_password}" | passwd
- useradd -m "${username}"
- echo "${username} ALL=(ALL:ALL) ALL" >> /etc/sudoers
- echo -e "${user_password}\n${user_password}" | passwd "${username}"
- usermod -a -G video,audio,input,power,storage,disk,network "${username}"
- }
- add_universe_repo() {
- log "$1"
- sed -i "s/^#ParallelDownloads.*$/ParallelDownloads = 10/" /etc/pacman.conf
- echo -e '\n[universe]\nServer = https://universe.artixlinux.org/$arch' >> /etc/pacman.conf
- pacman -Syy
- }
- add_arch_repo() {
- log "$1"
- pacman -S --noconfirm --needed artix-archlinux-support
- echo -e "\n[extra]\nInclude = /etc/pacman.d/mirrorlist-arch" >> /etc/pacman.conf
- echo -e "\n[multilib]\nInclude = /etc/pacman.d/mirrorlist-arch" >> /etc/pacman.conf
- pacman-key --populate archlinux
- pacman -Syy
- }
- install_microcode() {
- log "$1"
- pacman -S --noconfirm --needed amd-ucode
- }
- configure_mkinitcpio() {
- log "$1"
- sed -i 's/^HOOKS.*$/HOOKS=(base udev autodetect keyboard keymap modconf block filesystems fsck)/g' /etc/mkinitcpio.conf
- mkinitcpio -P
- }
- install_gpu_drivers() {
- log "$1"
- pacman -S --noconfirm --needed mesa mesa-utils amdvlk vulkan-mesa-layers radeontop libva-mesa-driver mesa-vdpau
- }
- move_kernels_efistub_entry() {
- log "$1"
- efidir="/boot/${init_system}"
- mkdir -p "$efidir"
- # Move Kernel, Microcode, Initramfs
- mv /boot/vmlinuz-linux-zen "$efidir/"
- mv /boot/amd-ucode.img "$efidir/"
- mv /boot/initramfs-linux-zen.img "$efidir/"
- mv /boot/initramfs-linux-zen-fallback.img "$efidir/"
- # Get root partition UUID
- ROOT_UUID=$(blkid -s UUID -o value "${root_partition}")
- KERNEL_OPT="rw quiet"
- # Create EFISTUB entry
- efibootmgr --create \
- --disk $(echo $boot_partition | sed 's/[0-9]*$//') \
- --part $(echo $boot_partition | grep -o '[0-9]*$') \
- --label "Artix-${init_system}" \
- --loader "\\${init_system}\\vmlinuz-linux-zen" \
- --unicode "initrd=\\${init_system}\\amd-ucode.img initrd=\\${init_system}\\initramfs-linux-zen.img root=UUID=${ROOT_UUID} ${KERNEL_OPT}" \
- --verbose
- }
- clean() {
- cat /mnt/opt/install_log* >> "${install_log}"
- rm /mnt/opt/install_log*
- umount -R /mnt
- }
- finish() {
- echo -ne "${cyan}
- --------------------------------------------------------------------------------
- Installation is done. Please reboot manually.
- --------------------------------------------------------------------------------
- ${normal}"
- }
- spin() { local i=0; local sp="/-\|"; local n=${#sp}; printf " "; sleep 0.2; while true; do printf "\b${cyan}%s${normal}" "${sp:i++%n:1}"; sleep 0.2; done; }
- log() { exec 3>&1 4>&2; trap 'exec 2>&4 1>&3' 0 1 2 3; exec 1>>"${install_log}" 2>&1; echo -e "\n${cyan}${1}${normal}\n"; }
- run_step() {
- local msg="$1"
- local func="$2"
- printf "${cyan}${msg}${normal}"
- unshare -fp --kill-child -- bash -c "spin" &
- spinpid=$!
- trap 'kill -9 $spinpid' SIGTERM SIGKILL
- ${func} "${msg}" &>/dev/null
- if [[ $? -eq 0 ]]; then
- kill -9 ${spinpid}
- printf "\b \t\t${cyan}[Done]${normal}\n"
- else
- kill -9 ${spinpid}
- printf "\b \t\t${red}[Failed]${normal}\n"
- printf "\n${red}Sorry! ${msg%%\\*} went wrong. See full log at "
- if ! unshare -U true &>/dev/null ; then
- printf "/mnt${install_log} ${normal}\n\n"
- else
- printf "${install_log} ${normal}\n\n"
- fi
- exit 1
- fi
- }
- title
- export -f spin
- export -f log
- export -f run_step
- export -f config_time
- export -f config_lang
- export -f config_network
- export -f create_user
- export -f add_universe_repo
- export -f add_arch_repo
- export -f install_microcode
- export -f enable_zram
- export -f configure_mkinitcpio
- export -f install_gpu_drivers
- export -f move_kernels_efistub_entry
- # --- Ablauf ---
- run_step "Selecting init\t\t\t" "get_init"
- run_step "Getting config\t\t\t" "get_conf"
- run_step "Mounting Partitions\t\t" "mount_partitions"
- run_step "Init Base System\t\t\t" "init_base"
- run_step "Installing Base System\t\t" "install_base_system"
- artix-chroot /mnt bash << '_exit'
- install_log="$(mktemp -p /opt -t install_logXXX)"
- run_step "Configuring Time\t\t" "config_time"
- run_step "Configuring Language\t\t" "config_lang"
- run_step "Configuring Network\t\t" "config_network"
- run_step "Creating User Account\t\t" "create_user"
- run_step "Adding Universe Repo\t\t" "add_universe_repo"
- [[ "${arch_repo}" == "yes" ]] && run_step "Adding Arch Repo\t\t" "add_arch_repo" || true
- run_step "Installing Microcode\t\t" "install_microcode"
- run_step "Configuring mkinitcpio\t\t" "configure_mkinitcpio"
- run_step "Installing GPU Drivers\t\t" "install_gpu_drivers"
- run_step "Move Kernels, create efibootmgr entry\t" "move_kernels_efistub_entry"
- _exit
- if [[ $? -eq 0 ]]; then
- run_step "Cleaning After Install\t\t" "clean"
- finish
- exit 0
- else
- exit 1
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement