1
0
Fork 0
reworking configuration
This commit is contained in:
Luca Bilke 2024-06-26 18:52:20 +02:00
parent 55519b7087
commit 5132ce6902
Signed by: luca
GPG Key ID: F6E11C9BAA7C82F5
6 changed files with 299 additions and 284 deletions

View File

@ -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.[]' <config.yml); do
flags=$(echo "$p" | yq -r '.command[1:].[]')
packages=$(echo "$p" | yq -r '.list[]')
# shellcheck disable=SC2086
[ -n "${packages}" ] && echo $flags $packages |
xargs "$(echo "$p" | yq -r '.command[0]')"
done | scroll 7
info "Done!"
}
@ -143,19 +140,6 @@ install_files() {
info "Done!"
}
create_symlinks() {
#shellcheck disable=SC2016
_loop_wrapper "${SCRIPT_DIR}/symlinks.txt" \
'Creating symlink $(echo $x | cut -d',' -f1) -> $(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[]' <config.yml)
counter=1
num_services=$(echo "$services" | wc -l)
info "Removing old services..."
for sv in /var/service/*; do
grep -qx "$(basename "$sv")" "${SCRIPT_DIR}/services.txt" || rm "$sv"
echo "$services" | grep -qx "$(basename "$sv")" || rm "$sv"
done
# shellcheck disable=2016
_loop_wrapper "${SCRIPT_DIR}/services.txt" \
'Enabling ${x} service' \
'[ ! -L /var/service/${x} ] && ln -s "/etc/sv/${x}" "/var/service/"'
info "Enabling services..."
for service in $services; do
info "Enabling service ${counter} of ${num_services}: ${service}"
[ ! -L "/var/service/${service}" ] && ln -s "/etc/sv/${service}" "/var/service/"
done
info "Done!"
}
@ -245,7 +240,7 @@ finalize() {
gid=$(getent passwd "$username" | cut -d ':' -f 4)
groupname=$(getent group "$gid" | cut -d ':' -f 1)
info "Setting ownership of home directories..."
chown "$username:$groupname" -R "$user_home"
chown -v "$username:$groupname" -R "$user_home" 2>&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

233
config.yml Normal file
View File

@ -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: []

View File

@ -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

View File

@ -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

View File

@ -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

View File