commit 1102a0806d59a48ee8a552c0318a5419eeeedff8
parent dacc0372205b1e7505b59e78d90e5cb65fda0069
Author: Markus Hanetzok <markus@hanetzok.net>
Date: Mon, 7 Nov 2022 11:12:47 +0100
Refactoring
- Write output of stderror to logfile and exit script when running into
trouble
- Accept column length > 80
- Remove clutter
Diffstat:
M | zerog | | | 77 | +++++++++++++++++++++++++++++++++-------------------------------------------- |
1 file changed, 33 insertions(+), 44 deletions(-)
diff --git a/zerog b/zerog
@@ -2,12 +2,9 @@
### VARIABLES ###
-script_dir="$(dirname "$(realpath $0)")"
-name="$(logname)"
-progs="$script_dir/progs.list"
+name="$(logname)" #
+progs="git.cybvik.xyz/zerog/files/progs.list.html"
dotfiles="git://git.cybvik.xyz/dotfiles"
-src="/home/$name/.local/src"
-giturl="git://git.cybvik.xyz"
logfile="/tmp/zerog.log"
# Repos for AUR programs
@@ -16,10 +13,6 @@ syntaxrepo="https://aur.archlinux.org/zsh-fast-syntax-highlighting.git"
### FUNCTIONS ###
-warning() { # Write to logfile
- printf "WARNING: $1\n" >> "$logfile"
-}
-
error() { # Write to logfile and exit script
printf "ERROR: $1\n" >> "$logfile"
clear
@@ -29,69 +22,70 @@ error() { # Write to logfile and exit script
prepare() {
printf "Preparing...\n"
printf "Refreshing keys...\n(This will take a while!)\n"
+
# Refresh keyring and update keyrings
- pacman-key --refresh >/dev/null 2>&1 ||
- { warning "Could not refresh keys"; return 1; }
- pacman -Sy --noconfirm archlinux-keyring archlinuxarm-keyring \
- parabola-keyring >/dev/null 2>&1 ||
- { warning "Could not install keyrings"; return 1; }
+ pacman-key --refresh >/dev/null 2>>"$logfile" || { error "Could not refresh keys"; }
+ pacman -Sy --noconfirm archlinux-keyring archlinuxarm-keyring parabola-keyring >/dev/null 2>>"$logfile" || { error "Could not install keyrings"; }
+
# Install some essential programs
- pacman -S --noconfirm --needed git zsh ca-certificates >/dev/null 2>&1 ||
- { warning "Initial installs failed"; return 1; }
+ pacman -S --noconfirm --needed git zsh ca-certificates >/dev/null 2>>"$logfile" || { error "Initial installs failed"; }
+
# Enable parallel downloads and make pacman look nice
- grep -q "ILoveCandy" /etc/pacman.conf ||
- sed -i "/#VerbosePkgLists/a ILoveCandy" /etc/pacman.conf
+ grep -q "ILoveCandy" /etc/pacman.conf || sed -i "/#VerbosePkgLists/a ILoveCandy" /etc/pacman.conf
sed -Ei "s/^#(ParallelDownloads).*/\1 = 5/;/^#Color$/s/#//" /etc/pacman.conf
+
+ # Get progs.list
+ cd /tmp && curl -O "$progs" && sed -i 's/<.*>//g; /.*Parabola.*/d; /^$/d' /tmp/progs.list.html || { error "Could not download progs.list"; }
+ mv /tmp/progs.list.html /tmp/progs.list
}
install_programs() { # Read from progs.list and install each entry
printf "### Installing from progs.list ###\n"
while read -r program; do
printf "Installing $program\n"
- pacman -S --noconfirm --needed "$program" >/dev/null 2>&1 ||
- warning "$program could not be installed"
- done < "$progs"
+ pacman -S --noconfirm --needed "$program" >/dev/null 2>>"$logfile" || printf "WARN: $program could not be installed\n" >> "$logfile"
+ done < /tmp/progs.list
}
get_dotfiles() { # Download dotfiles and place them in $HOME
printf "### Installing dotfiles ###\n"
- sudo -u "$name" git clone "$dotfiles" /tmp/dotfiles >/dev/null 2>&1 ||
- { warning "Could not clone dotfiles"; return 1; }
- sudo -u "$name" cp -rfT /tmp/dotfiles "/home/$name" >/dev/null 2>&1
+ sudo -u "$name" git clone "$dotfiles" /tmp/dotfiles >/dev/null 2>>"$logfile" || { error "Could not clone dotfiles"; }
+ sudo -u "$name" cp -rfT /tmp/dotfiles "/home/$name" >/dev/null 2>>"$logfile"
}
suckless() { # Clone and install suckless programs
printf "### Installing suckless software ###\n"
- for program in dwm st dmenu slock; do
- cd "$src"
+ for program in dwm st dmenu slock surf; do
+ cd /home/"$name"/.local/src
printf "Installing $program\n"
- sudo -u "$name" git clone "$giturl/$program-cybvik" >/dev/null 2>&1 ||
- { warning "Could not clone $program"; return 1; }
- cd "$program" && make clean install >/dev/null 2>&1 ||
- { warning "Could not install $program"; return 1; }
+ sudo -u "$name" git clone "git://git.cybvik.xyz/$program-cybvik" >/dev/null 2>>"$logfile" || { error "Could not clone $program"; }
+ cd "$program" && make clean install >/dev/null 2>>"$logfile" || { error "Could not install $program"; }
done
}
git_install() { # Basically a temporary AUR helper
- sudo -u "$name" git clone "$2" /tmp/"$1" >/dev/null 2>&1 ||
- { warning "Could not clone from AUR ($2)"; return 1; }
+ sudo -u "$name" git clone "$2" /tmp/"$1" >/dev/null 2>>"$logfile" || { error "AUR: Could not clone from source ($2)"; }
cd /tmp/"$1"
- yes | sudo -u "$name" LANG=C makepkg -si >/dev/null 2>&1 ||
- { warning "Could not makepkg $2"; return 1; }
+ yes | sudo -u "$name" LANG=C makepkg -si >/dev/null 2>>"$logfile" || { error "Could not makepkg $2"; }
}
follow_up() {
printf "### Finishing touches ###\n"
+
# Make zsh the default shell
- chsh -s /bin/zsh "$name" >/dev/null 2>&1
+ chsh -s /bin/zsh "$name" >/dev/null 2>>"$logfile"
+
# Create some needed dirs
sudo -u "$name" mkdir -p "/home/$name/.cache/zsh/"
sudo -u "$name" mkdir -p "/home/$name/.config/mpd/playlists/"
+
# Turn off the computer beep
rmmod pcspkr
printf "blacklist pcspkr\n" >/etc/modprobe.d/nobeep.conf
+
# Get rid of no longer needed bash files
yes | rm /home/$name/.bash*
+
# Add some services to default runtime
rc-update add avahi-daemon default >/dev/null
rc-update add cupsd default >/dev/null
@@ -103,17 +97,13 @@ follow_up() {
printf "###########################\n########## ZEROG ##########\n###########\
################\n"
-prepare ||
- error "Please make sure that you have a working internet connection and \
-you run ZEROG with sudo!"
+prepare
install_programs
-get_dotfiles ||
- error "Could not install dotfiles"
+get_dotfiles
-suckless ||
- error "Could not install suckless programs"
+suckless
# Git installs are disabled by default so you can choose if you want to install
# these packages from the AUR
@@ -122,8 +112,7 @@ suckless ||
# git_install "$repo"
# done
-follow_up ||
- error "Follow up function failed"
+follow_up
printf "###########################\n########## ZEROG ##########\n###########\
################\nZEROG flight finished. Log in again and run 'startx' to \