From 5132ce690221096064904caec389b233d45de05d Mon Sep 17 00:00:00 2001 From: Luca Bilke Date: Wed, 26 Jun 2024 18:52:20 +0200 Subject: [PATCH] WIP reworking configuration --- bootstrap.sh | 137 ++++++++++++++-------------- config.yml | 233 ++++++++++++++++++++++++++++++++++++++++++++++++ directories.txt | 14 --- packages.txt | 179 ------------------------------------- services.txt | 20 ----- symlinks.txt | 0 6 files changed, 299 insertions(+), 284 deletions(-) create mode 100644 config.yml delete mode 100644 directories.txt delete mode 100644 packages.txt delete mode 100644 services.txt delete mode 100644 symlinks.txt diff --git a/bootstrap.sh b/bootstrap.sh index 2ec7b5d..c21a8c8 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -1,8 +1,12 @@ #!/bin/sh + +set -eu + DOTS_REPO="https://git.snaile.de/luca/dotfiles" DOTS_BRANCH="main" STOW_DIR=".local/share/stow" DOTS_PACKAGE="dots" +CONFIG_FILE="./config.yml" USER_GROUPS="wheel,floppy,audio,video,cdrom,optical,kvm,xbuilder,users,docker" # Comma separated list SCRIPT_DIR="$(dirname "$(readlink -f "$0")")" @@ -42,31 +46,34 @@ warn() { print_buffer() { buffer_size=$1 + line_length=$2 for i in $(seq 1 "$((buffer_size))"); do + # shellcheck disable=SC2016 if [ "$trim" = "y" ]; then - eval "printf '%-${line_length}s\n' \"\$buffer${i}\"" + template='%-${line_length}s\n' else - eval "printf '%-${line_length}.${line_length}s\n' \"\$buffer${i}\"" + template='%-${line_length}.${line_length}s\n' fi + # shellcheck disable=SC2086 + eval '[ -z "${buffer'"$i"':-}" ] || { + printf "'"$template"'" "${buffer'$i'}" + }' done } push_buffer() { line=$1 buffer_size=$2 - for i in $(seq 1 $((buffer_size))); do - eval "buffer$i=\$buffer$((i + 1))" + for i in $(seq 1 $((buffer_size - 1))); do + eval 'buffer'"$i"'="${buffer'$((i + 1))':-}"' done - # shellcheck disable=SC2034 - eval "buffer${buffer_size}='$line'" - # buffer1="$line" + eval 'buffer'"$buffer_size"'=''''"$line"''''' } scroll() { buffer_size=$1 # int trim=${2:-y} # 'y' | 'n' - line_length=$(tput cols) trap 'line_length=$(tput cols)' WINCH @@ -75,41 +82,20 @@ scroll() { push_buffer "$line" "$buffer_size" tput sc - print_buffer "$buffer_size" + print_buffer "$buffer_size" "$line_length" tput rc - - sleep 0.5 done tput cnorm for i in $(seq 1 $((buffer_size))); do - eval "buffer$i=''" + eval "unset buffer$i" done - print_buffer "$buffer_size" + print_buffer "$buffer_size" "$line_length" trap - WINCH } -_loop_wrapper() { - unset n - unset total - file=$1 - message=$2 - command=$3 - - skip_regex="^(#.*)?$" - total=$(grep -cvP "$skip_regex" "$file") - - while read -r x; do - echo "$x" | grep -qvP "$skip_regex" || continue - n=$((n + 1)) - eval "info \"(${n}/${total}) $message\"" - eval "$command" - done <"$file" | scroll 7 -} - check_root() { - [ "$(id -u)" != "0" ] && - error "This script needs root!" + [ "$(id -u)" = "0" ] || error "This script needs root!" } setup() { @@ -118,7 +104,12 @@ setup() { if ! xbps-query ntp >/dev/null 2>&1; then info "Installing ntp..." - xbps-install -y ntp >/dev/null 2>&1 + progs="ntp jq yq git stow" + # shellcheck disable=SC2086 + xbps-install -y $progs >/dev/null 2>&1 + for prog in $progs; do + command -v "${prog}" 1>/dev/null 2>&1 || error "${prog} isn't installed even though it should be!" + done info "Synchronizing time..." ntpdate "pool.ntp.org" >/dev/null 2>&1 || warn "Failed to synchronize time!" @@ -128,10 +119,16 @@ setup() { } install_packages() { - #shellcheck disable=SC2016,SC2046 - { sed '/^[[:space:]]*#/d;/^$/d' "${SCRIPT_DIR}/packages.txt" | xargs -r xbps-install -y || error "Invalid package in packages.txt"; } | grep -v 'already installed' - command -v git 1>/dev/null 2>&1 || error "git isn't installed even though it should be!" - command -v stow 1>/dev/null 2>&1 || error "stow isn't installed even though it should be!" + IFS=' +' + for p in $(yq -c '.packages.[]' $(echo $x | cut -d',' -f2)' \ - ' - source=$(echo $x | cut -d"," -f2) - target=$(echo $x | cut -d"," -f1) - [ -L $target ] && rm $target - ln -s $source $target - ' - info "Done!" -} - create_user() { failed=false while ! echo "$username" | grep "^[a-z_][a-z0-9_-]*$" | grep -qv "root"; do @@ -192,18 +176,21 @@ create_user() { create_directories() { #shellcheck disable=SC2016 - _loop_wrapper "${SCRIPT_DIR}/directories.txt" \ - 'Creating directory $(echo $x | cut -d"," -f1)' \ - ' - set -e - dir=$(echo $x | cut -d"," -f1) - mod=$(echo $x | cut -d"," -f2) - [ "$dir" = "$mod" ] && mod="755" - [ -d "${user_home}/${dir}" ] || mkdir -p "${user_home}/${dir}" - sudo -u "$username" mkdir -p "${user_home}/${dir}" - chmod "${mod}" "${user_home}/${dir}" - set +e - ' + directories=$(yq -c '[].directories' <${CONFIG_FILE}) + counter=1 + num_dirs=$(echo "$directories" | wc -l) + + for entry in $directories; do + path=$(echo "$entry" | jq -r '.path') + mode=$(echo "$entry" | jq -r '.mode') + [ "$mode" = "null" ] && mode="0755" + + info "Creating directory ${counter} of ${num_dirs}: ~/${path}" + [ -d "${user_home}/${path}" ] || sudo -u "$username" mkdir -m "${mode}" -p "${user_home}/${path}" + + counter=$((counter + 1)) + done + info "Done!" } @@ -231,13 +218,21 @@ select_keymap() { } enable_services() { + services=$(yq -r '.services[]' &1 | scroll 7 info "Done!" } @@ -258,8 +253,8 @@ check_root emphasize "-- Copying Files --" install_files -emphasize "-- Creating Symlinks --" -create_symlinks +# emphasize "-- Creating Symlinks --" +# create_symlinks emphasize "-- Preparing Installation --" setup diff --git a/config.yml b/config.yml new file mode 100644 index 0000000..b9a8ca7 --- /dev/null +++ b/config.yml @@ -0,0 +1,233 @@ +--- +services: + - ngetty + - bluetoothd + - crond + - cupsd + - dbus + - docker + - elogind + - nanoklogd + - NetworkManager + - pcscd + - polkitd + - smbd + - socklog-unix + - tlp + - udevd + +directories: + - path: ".cache" + - path: ".config" + - path: ".config/dwm/autorun.d" + - path: ".local/libexec/" + - path: ".local/log" + - path: ".local/share/" + - path: ".local/state" + - path: ".local/sv" + - path: "Desktop" + - path: "Documents/dev" + - path: "Downloads" + - path: "Pictures/Screenshots" + - path: "Videos" + - path: ".ssh" + mode: "0700" + +packages: + - command: ["xbps-install", "-y"] + list: + - 7zip + - ImageMagick + - NetworkManager + - Signal-Desktop + - ansible + - apache-htpasswd + - arandr + - atool + - bandwhich + - base-devel + - base-system + - bat + - bind-utils + - binutils + - blueman + - bluez + - bottom + - breeze-icons + - cargo + - catdoc + - chafa + - clipmenu + - cpanminus + - cronie + - cups + - cups-filters + - cups-pdf + - curl + - dbus + - delta + - dmenu-custom + - docker + - docker-buildx + - docker-compose + - dragon + - dua-cli + - dunst + - dwm-custom + - dwmblocks-custom + - elogind + - fd + - ffmpeg + - ffmpegthumbnailer + - firefox + - font-firacode-nf-ttf + - fswatch + - fzf + - git + - git-lfs + - github-cli + - glib + - glow + - gnome-keyring + - gnumeric + - gnupg2-scdaemon + - gpgme + - htop + - jq + - just + - k9s + - kdash + - kubectl + - kubernetes-helm + - lazygit + - lf + - libspa-bluetooth + - lm_sensors + - lsof + - lynx + - maim + - man-db + - mediainfo + - mime-types + - moreutils + - mpv + - mtr + - ncpamixer + - neofetch + - neovim + - nmap + - noto-fonts-cjk + - noto-fonts-emoji + - noto-fonts-ttf + - noto-fonts-ttf-extra + - nsxiv + - ntp + - odt2txt + - openjdk21 + - pamixer + - pcsc-ccid + - picom + - pinentry-gnome + - pipewire + - playerctl + - pnpm + - polkit + - poppler + - progress + - psmisc + - pulsemixer + - pv-migrate + - pwgen + - python3-ansible-lint + - python3-devel + - python3-neovim + - python3-pip + - ranger + - rbw + - ripgrep + - rlwrap + - rsync + - ruby-asciidoctor + - rust + - rust-analyzer + - rust-src + - rust-std + - seahorse + - shellcheck + - shfmt + - simple-mtpfs + - smbclient + - socat + - socklog-void + - st-custom + - stow + - strace + - syncthing + - syncthingtray + - system-config-printer + - tcpdump + - terraform + - thunderbird + - tlp + - tmux + - tokyonight-theme + - trash-util + - tree-sitter-devel + - unclutter-xfixes + - vault + - velero + - virtualenvwrapper + - void-repo-nonfree + - vpsm + - vsv + - wget + - wireplumber + - xcape + - xclip + - xdg-user-dirs + - xdg-utils + - xdotool + - xinit + - xmenu + - xorg + - xournalpp + - xscreensaver + - xsecurelock + - xsel + - xss-lock + - xtools + - xwallpaper + - xxd + - xz + - ykpers + - yt-dlp + - yubikey-manager + - zathura + - zathura-pdf-mupdf + - zk + - zsh + - zsh-autosuggestions + - zsh-completions + - zsh-syntax-highlighting + - command: ["pnpm", "install", "-g"] + list: + - "neovim" + - command: ["cargo", "install", "-j", "-2"] + list: + - "oatmeal" + - "gpg-tui" + - command: ["composer", "global", "require"] + list: [] + - command: ["gem", "install"] + list: + - asciidoctor + - asciidoctor-pdf + - asciidoctor + - asciidoctor-diagram + - pygments.rb + - neovim + - command: ["cpanm"] + list: + - Neovim::Ext + - command: ["pipx", "--global", "install"] + list: [] diff --git a/directories.txt b/directories.txt deleted file mode 100644 index 5fac2ab..0000000 --- a/directories.txt +++ /dev/null @@ -1,14 +0,0 @@ -.cache -.config -.config/dwm/autorun.d -.local/libexec/ -.local/log -.local/share/ -.local/state -.local/sv -Desktop -Documents/dev -Downloads -Pictures/Screenshots -Videos -.ssh,700 diff --git a/packages.txt b/packages.txt deleted file mode 100644 index 51915ba..0000000 --- a/packages.txt +++ /dev/null @@ -1,179 +0,0 @@ -7zip -ansible -apache-htpasswd -arandr -atool -bandwhich -base-devel -base-system -bat -bind-utils -binutils -blueman -bluez -bottom -breeze-icons -cargo -catdoc -chafa -clipmenu -cronie -cups -cups-filters -cups-pdf -curl -dbus -delta -dmenu-custom -docker -docker-buildx -docker-compose -dragon -dua-cli -dunst -dwm-custom -dwmblocks-custom -elogind -fd -ffmpeg -ffmpegthumbnailer -firefox -font-firacode-nf-ttf -fswatch -fzf -git -git-lfs -github-cli -glib -glow -gnome-keyring -gnumeric -gnupg2-scdaemon -gpgme -htop -ImageMagick -jq -just -k9s -kdash -kubectl -kubernetes-helm -lazygit -lf -libspa-bluetooth -lm_sensors -lsof -lynx -maim -man-db -mediainfo -mime-types -moreutils -mpv -mtr -ncpamixer -neofetch -neovim -NetworkManager -nmap -noto-fonts-cjk -noto-fonts-emoji -noto-fonts-ttf -noto-fonts-ttf-extra -nsxiv -ntp -odt2txt -openjdk21 -pamixer -pcsc-ccid -picom -pinentry-gnome -pipewire -playerctl -pnpm -polkit -poppler -progress -psmisc -pulsemixer -pv-migrate -pwgen -python3-ansible-lint -python3-devel -python3-pip -python3-neovim -ranger -rbw -ripgrep -rlwrap -rsync -ruby-asciidoctor -rust -rust-analyzer -rust-src -rustup -seahorse -shellcheck -shfmt -Signal-Desktop -simple-mtpfs -smbclient -socat -socklog-void -st-custom -stow -strace -syncthing -syncthingtray -system-config-printer -tcpdump -terraform -thunderbird -tlp -tmux -tokyonight-theme -trash-util -tree-sitter-devel -unclutter-xfixes -vault -velero -virtualenvwrapper -void-repo-nonfree -vpsm -vsv -wget -wireplumber -xcape -xclip -xdg-user-dirs -xdg-utils -xdotool -xinit -xmenu -xorg -xournalpp -xscreensaver -xsecurelock -xsel -xss-lock -xtools -xwallpaper -xxd -xz -ykpers -yt-dlp -yubikey-manager -zathura -zathura-pdf-mupdf -zk -zsh -zsh-autosuggestions -zsh-completions -zsh-syntax-highlighting - -# TODO: npm install prettier, @fsouza/prettierd neovim -# TODO: cargo install oatmeal, bandwhich, gpg-tui -# TODO: composer install php-cs-fixer -# TODO: gem install asciidoctor asciidoctor-pdf asciidoctor asciidoctor-diagram pygments.rb neovim -# TODO: cpanm install Neovim::Ext -# TODO: pipx install diff --git a/services.txt b/services.txt deleted file mode 100644 index 68086c4..0000000 --- a/services.txt +++ /dev/null @@ -1,20 +0,0 @@ -agetty-tty1 -agetty-tty2 -agetty-tty3 -agetty-tty4 -agetty-tty5 -agetty-tty6 -bluetoothd -crond -cupsd -dbus -docker -elogind -nanoklogd -NetworkManager -pcscd -polkitd -smbd -socklog-unix -tlp -udevd diff --git a/symlinks.txt b/symlinks.txt deleted file mode 100644 index e69de29..0000000