View difference between Paste ID: gy8q2Q0H and g0rEgkC2
SHOW: | | - or go back to the newest paste.
1
#!/bin/bash
2
3-
##########################################
3+
get_conf() {    ############# CONFIGURATION ###################################################################
4-
#           CONFIGURATION                #
4+
5-
##########################################
5+
    if [ ! -f conf.sh ]; then
6-
root_password="rootpassword"
6+
        wget https://pastebin.com/raw/Ed9xkKq4 -O conf.sh &>/dev/null
7-
username="meinuser"
7+
        echo -e "Datei 'conf.sh' heruntergeladen!"
8-
user_password="benutzerpassword"
8+
        exit
9-
hostname="meinhost"
9+
10-
init_system="runit"
10+
11-
arch_repo="yes"
11+
12-
boot_partition="/dev/nvme1n1p1"
12+
13-
root_partition="/dev/nvme1n1p2"
13+
14-
home_partition="/dev/nvme1n1p3"
14+
15-
timezone="Europe/Zurich"
15+
16-
##########################################
16+
17
18
title() {
19
    clear
20
    echo -ne "${cyan}#                Artix Linux Automated Installer (no interaction)              #${normal}"
21
}
22
23
case "$init_system" in
24
    dinit) export init_programs=("dinit" "elogind-dinit");;
25
    openrc) export init_programs=("openrc" "elogind-openrc");;
26
    runit) export init_programs=("runit" "elogind-runit");;
27-
################################################################################
27+
28-
#                Artix Linux Automated Installer (no interaction)              #
28+
29-
################################################################################
29+
30
31
get_init() {
32
    log "$1"
33
    echo -e "\nWhich init system do you want to use?"
34
    options=("dinit" "openrc" "runit" "s6")
35
    select_option $? 1 "${options[@]}"
36
    case $? in
37
    0) export init_system="dinit"
38
        export init_programs=("dinit" "elogind-dinit");;
39
    1) export init_system="openrc"
40
        export init_programs=("openrc" "elogind-openrc");;
41
    2) export init_system="runit"
42
        export init_programs=("runit" "elogind-runit");;
43
    3) export init_system="s6"
44-
    mkdir -p /mnt/home
44+
        export init_programs=("s6-base" "elogind-s6");;
45-
    mount "${home_partition}" /mnt/home
45+
46
}
47
48
mount_partitions() {
49
    log "$1"
50
    mount "${root_partition}" /mnt
51
    mkdir -p /mnt/boot
52
    mount "${boot_partition}" /mnt/boot
53
}
54
55
init_base() {
56
    log "$1"
57
    loadkeys de_CH-latin1
58
    sed -i '1iServer = https://mirror2.artixlinux.org/$repo/os/$arch' /etc/pacman.d/mirrorlist
59
    sed -i 's/^#Color/Color/' /etc/pacman.conf
60
    sed -i '/^Color/!s/^#Color/Color/' /etc/pacman.conf
61
    if grep -q '^#ParallelDownloads' /etc/pacman.conf; then
62
        sed -i 's/^#ParallelDownloads.*/ParallelDownloads = 10/' /etc/pacman.conf
63
    elif grep -q '^ParallelDownloads' /etc/pacman.conf; then
64
        sed -i 's/^ParallelDownloads.*/ParallelDownloads = 10/' /etc/pacman.conf
65
    else
66
        echo 'ParallelDownloads = 10' >> /etc/pacman.conf
67
    fi
68
}
69
70
install_base_system() {
71
    log "$1"
72
    basestrap /mnt base base-devel linux-zen linux-zen-headers linux-firmware efibootmgr "${init_programs[@]}"
73
    fstabgen -U /mnt >> /mnt/etc/fstab
74
}
75
76
config_time() {
77
    log "$1"
78
    ln -sf "/usr/share/zoneinfo/${timezone}" /etc/localtime
79
    hwclock --systohc
80
}
81
82
config_lang() {
83
    log "$1"
84
    echo -e "en_US.UTF-8 UTF-8\nde_CH.UTF-8 UTF-8" >> /etc/locale.gen
85
    locale-gen
86
    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
87
    echo "KEYMAP=de_CH-latin1" > /etc/vconsole.conf
88
}
89
90
config_network() {
91
    log "$1"
92
    echo "${hostname}" > /etc/hostname
93
    echo -e "127.0.0.1\tlocalhost" >> /etc/hosts
94
    echo -e "::1\t\tlocalhost" >> /etc/hosts
95
    echo -e "127.0.1.1\t${hostname}.localdomain ${hostname}" >> /etc/hosts
96
    pacman -S --noconfirm --needed connman-${init_system}
97
    case "${init_system}" in
98
        dinit) ln -s ../connmand /etc/dinit.d/boot.d/;;
99
        openrc) rc-update add connmand;;
100
        runit) ln -s /etc/runit/sv/connmand /etc/runit/runsvdir/default;;
101
        s6) touch /etc/s6/adminsv/default/contents.d/connmand
102
            s6-db-reload;;
103
    esac
104
}
105-
    echo "${username} ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
105+
106
create_user() {
107
    log "$1"
108
    echo -e "${root_password}\n${root_password}" | passwd
109
    useradd -m "${username}"
110
    echo "${username} ALL=(ALL:ALL) ALL" >> /etc/sudoers
111
    echo -e "${user_password}\n${user_password}" | passwd "${username}"
112
    usermod -a -G video,audio,input,power,storage,disk,network "${username}"
113
}
114
115
add_universe_repo() {
116
    log "$1"
117
    sed -i "s/^#ParallelDownloads.*$/ParallelDownloads = 10/" /etc/pacman.conf
118
    echo -e '\n[universe]\nServer = https://universe.artixlinux.org/$arch' >> /etc/pacman.conf
119
    pacman -Syy
120
}
121
122
add_arch_repo() {
123
    log "$1"
124
    pacman -S --noconfirm --needed artix-archlinux-support
125
    echo -e "\n[extra]\nInclude = /etc/pacman.d/mirrorlist-arch" >> /etc/pacman.conf
126
    echo -e "\n[multilib]\nInclude = /etc/pacman.d/mirrorlist-arch" >> /etc/pacman.conf
127
    pacman-key --populate archlinux
128
    pacman -Syy
129
}
130
131-
enable_zram() { :; }
131+
132
    log "$1"
133
    pacman -S --noconfirm --needed amd-ucode
134
}
135
136
configure_mkinitcpio() {
137
    log "$1"
138
    sed -i 's/^HOOKS.*$/HOOKS=(base udev autodetect keyboard keymap modconf block filesystems fsck)/g' /etc/mkinitcpio.conf
139
    mkinitcpio -P
140
}
141
142
install_gpu_drivers() {
143
    log "$1"
144
    pacman -S --noconfirm --needed mesa mesa-utils amdvlk vulkan-mesa-layers radeontop libva-mesa-driver mesa-vdpau
145
}
146
147
move_kernels_efistub_entry() {
148
    log "$1"
149
    efidir="/boot/${init_system}"
150
    mkdir -p "$efidir"
151
    # Move Kernel, Microcode, Initramfs
152
    mv /boot/vmlinuz-linux-zen "$efidir/"
153
    mv /boot/amd-ucode.img "$efidir/"
154
    mv /boot/initramfs-linux-zen.img "$efidir/"
155
    mv /boot/initramfs-linux-zen-fallback.img "$efidir/"
156
    # Get root partition UUID
157
    ROOT_UUID=$(blkid -s UUID -o value "${root_partition}")
158
    KERNEL_OPT="rw quiet"
159
    # Create EFISTUB entry
160
    efibootmgr --create \
161-
      --unicode "initrd=\\${init_system}\\amd-ucode.img initrd=\\${init_system}\\initramfs-linux-zen.img root=UUID=${ROOT_UUID} rw quiet" \
161+
162
      --part $(echo $boot_partition | grep -o '[0-9]*$') \
163
      --label "Artix-${init_system}" \
164
      --loader "\\${init_system}\\vmlinuz-linux-zen" \
165
      --unicode "initrd=\\${init_system}\\amd-ucode.img initrd=\\${init_system}\\initramfs-linux-zen.img root=UUID=${ROOT_UUID} ${KERNEL_OPT}" \
166
      --verbose
167
}
168
169
clean() {
170
    cat /mnt/opt/install_log* >> "${install_log}"
171
    rm /mnt/opt/install_log*
172
    umount -R /mnt
173
}
174
175
finish() {
176
    echo -ne "${cyan}
177
--------------------------------------------------------------------------------
178
        Installation is done. Please reboot manually.
179
--------------------------------------------------------------------------------
180
${normal}"
181
}
182
183
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; }
184
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"; }
185
run_step() {
186
    local msg="$1"
187
    local func="$2"
188
    printf "${cyan}${msg}${normal}"
189
    unshare -fp --kill-child -- bash -c "spin" &
190
    spinpid=$!
191
    trap 'kill -9 $spinpid' SIGTERM SIGKILL
192
    ${func} "${msg}" &>/dev/null
193
    if [[ $? -eq 0 ]]; then
194
        kill -9 ${spinpid}
195
        printf "\b \t\t${cyan}[Done]${normal}\n"
196
    else
197
        kill -9 ${spinpid}
198
        printf "\b \t\t${red}[Failed]${normal}\n"
199
        printf "\n${red}Sorry! ${msg%%\\*} went wrong. See full log at "
200
        if ! unshare -U true &>/dev/null ; then
201
            printf "/mnt${install_log} ${normal}\n\n"
202
        else
203
            printf "${install_log} ${normal}\n\n"
204
        fi
205
        exit 1
206
    fi
207
}
208
209
title
210
export -f spin
211
export -f log
212
export -f run_step
213
export -f config_time
214
export -f config_lang
215
export -f config_network
216
export -f create_user
217
export -f add_universe_repo
218
export -f add_arch_repo
219
export -f install_microcode
220
export -f enable_zram
221
export -f configure_mkinitcpio
222
export -f install_gpu_drivers
223
export -f move_kernels_efistub_entry
224
225
# --- Ablauf ---
226
run_step "Selecting init\t\t\t" "get_init"
227
run_step "Getting config\t\t\t" "get_conf"
228
run_step "Mounting Partitions\t\t" "mount_partitions"
229
run_step "Init Base System\t\t\t" "init_base"
230
run_step "Installing Base System\t\t" "install_base_system"
231
232
artix-chroot /mnt bash << '_exit'
233
install_log="$(mktemp -p /opt -t install_logXXX)"
234
run_step "Configuring Time\t\t" "config_time"
235
run_step "Configuring Language\t\t" "config_lang"
236
run_step "Configuring Network\t\t" "config_network"
237
run_step "Creating User Account\t\t" "create_user"
238
run_step "Adding Universe Repo\t\t" "add_universe_repo"
239
[[ "${arch_repo}" == "yes" ]] && run_step "Adding Arch Repo\t\t" "add_arch_repo" || true
240
run_step "Installing Microcode\t\t" "install_microcode"
241
run_step "Configuring mkinitcpio\t\t" "configure_mkinitcpio"
242
run_step "Installing GPU Drivers\t\t" "install_gpu_drivers"
243
run_step "Move Kernels, create efibootmgr entry\t" "move_kernels_efistub_entry"
244
_exit
245
246
if [[ $? -eq 0 ]]; then
247
    run_step "Cleaning After Install\t\t" "clean"
248
    finish
249
    exit 0
250
else
251
    exit 1
252
fi