#!/bin/sh DIR="$(realpath "$(dirname "$0")")" root_setup() { # script must start at home directory cd "$HOME" || exit 1; usertest() { if test "$(id -u)" -ne 0; then echo "You must run this script as root."; exit 1; fi } createuser() { printf 'full name: ' >&2 read -r NAME printf 'login: ' >&2 read -r LOGIN adduser -g "$NAME" "$LOGIN" || exit 1 adduser "$LOGIN" video || exit 1 adduser "$LOGIN" input || exit 1 adduser "$LOGIN" wheel || exit 1 adduser root wheel || exit 1 } installdoas() { apk add doas alpine-conf echo "permit nopass :wheel" >> /etc/doas.d/doas.conf } if test -z "$DOCKERBUILD"; then usertest && createuser && installdoas else usertest && installdoas fi } user_setup() { cd "$HOME" || exit 1; help_text() { cat <&1) > /dev/null; then echo "doas is not installed."; exit 1 fi dev() { echo "Developer tools..." doas apk add build-base python3 nodejs npm go curl bash shadow || exit 1 if ! test -z "$NVIM"; then doas apk add cargo fi } sysinfo() { echo "Dylan Araps scripts" cd "$HOME" || exit 1; mkdir -p repos git clone https://github.com/dylanaraps/pfetch "$HOME/repos/pfetch" git clone https://github.com/dylanaraps/neofetch "$HOME/repos/neofetch" git clone https://github.com/dylanaraps/fff "$HOME/repos/fff" cd "$HOME/repos/pfetch" || exit 1; doas make install || exit 2; cd "$HOME" || exit 1; cd "$HOME/repos/neofetch" || exit 1; doas make install || exit 2; cd "$HOME" || exit 1; cd "$HOME/repos/fff" || exit 1; doas make install || exit 2; cd "$HOME" || exit 1; } dotfiles() { echo "Adding zsh and tmux configs" # zsh plugins doas apk add zsh zsh-vcs tmux shellcheck fzf export RUNZSH=no sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" git clone https://github.com/zsh-users/zsh-syntax-highlighting.git "$HOME/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting" # dotfiles if ! test -d "$DIR/dots"; then echo "$DIR/dots folder not found."; exit 1; fi cp "$DIR/dots/zshrc" "$HOME/.zshrc" cp "$DIR/dots/tmux.conf" "$HOME/.tmux.conf" # install tpm and plugins git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm || exit 1 tmux start \; \ new -d \; \ run "$HOME/.tmux/plugins/tpm/scripts/install_plugins.sh" \; \ kill-session || exit 1 mkdir -p "$HOME/.local/bin" || exit 1 cp -r "$DIR/scripts/." "$HOME/.local/bin/" || exit 1 } neovim() { # install neovim doas apk add neovim tree-sitter tree-sitter-cli git clone --depth 1 https://github.com/wbthomason/packer.nvim ~/.local/share/nvim/site/pack/packer/start/packer.nvim || exit 1 git clone https://git.junickim.me/junikimm717/nvim2023 ~/.config/nvim || exit 1 nvim -c PackerSync -c 'sleep 10' -c qa --headless echo "sleeping to compile" nvim -c 'sleep 60' -c qa --headless } vimconfigs() { doas apk add vim wget https://git.junickim.me/junikimm717/vim2023/raw/branch/master/lsp.vimrc -O .vimrc } competitiveprogramming() { echo "CP..." git clone https://git.junickim.me/junikimm717/linuxcp "$HOME/cp" go install git.junickim.me/junikimm717/cpgo@latest } nfs() { doas apk add nfs-utils samba cifs-utils mkdir -p "$HOME/nfs/rpi" && mkdir -p "$HOME/nfs/d2" echo 'export WORKSPACES=$HOME/nfs/rpi/ohsg11/s2:$HOME/nfs/d2/ohsg11/s2:$WORKSPACES' >> ~/.zshrc echo "alias schoolmount='doas mount 192.168.1.34:/srv/nfs ~/nfs/rpi'" >> ~/.zshrc cat <> ~/.zshrc alias d2mount='doas mount.cifs -o username=junikim,uid=\$(id -u),gid=\$(id -g) //157.245.86.196/d2nas ~/nfs/d2' EOF } graphical() { # xorg and drivers doas setup-xorg-base doas apk add xf86-video-qxl xf86-video-vmware virtualbox-guest-additions-x11 mesa-egl xrandr doas apk add xf86-input-evdev # wm applications doas apk add i3wm alacritty polybar i3lock rofi feh # fonts doas apk add font-jetbrains-mono-nerd terminus-font ttf-inconsolata ttf-dejavu font-noto font-noto-cjk ttf-font-awesome font-noto-extra doas apk add firefox mkdir -p "$HOME/repos/siji" cd "$HOME/repos/siji" || exit 1 curl -LJO https://github.com/fauno/siji/archive/master.tar.gz || exit 1 tar -xzvf ./siji-master.tar.gz || exit 1 mkdir -p "$HOME/.local/share/fonts" || exit 1 cp ./siji-master/ttf/siji.ttf "$HOME/.local/share/fonts/" || exit 1 fc-cache -rv mkdir -p "$HOME/.config/polybar" || exit 1 mkdir -p "$HOME/.config/i3" || exit 1 mkdir -p "$HOME/.config/picom" || exit 1 cp "$DIR/dots/polybar.ini" "$HOME/.config/polybar/config" || exit 1 cp "$DIR/dots/i3config" "$HOME/.config/i3/config" || exit 1 cp "$DIR/dots/picom.conf" "$HOME/.config/picom/picom.conf" || exit 1 sed -i "s/brave-browser/firefox/" "$HOME/.config/i3/config" mkdir -p "$HOME/.config/alacritty" || exit 1 cp "$DIR/dots/alacritty.yml" "$HOME/.config/alacritty/alacritty.yml" || exit 1 echo "exec i3" > "$HOME/.xinitrc" } (dev && sysinfo && dotfiles && vimconfigs) || exit 1 if ! test -z "$NVIM"; then neovim || exit 1 fi if ! test -z "$CP"; then competitiveprogramming || exit 1 fi if ! test -z "$GRAPHICAL"; then graphical || exit 1 fi if ! test -z "$NFS"; then nfs || exit 1 fi } if test $# -eq 0; then echo "at least one argument: root or user" && exit 1 fi case $1 in root|r) shift root_setup "$@" ;; user|u) shift user_setup "$@" ;; *) echo "Invalid option $1" exit 1 ;; esac