From 721a9d18131c96666cf08074e54077288fd79b72 Mon Sep 17 00:00:00 2001 From: Didier Date: Fri, 1 Sep 2023 03:34:16 +0200 Subject: [PATCH] stuff --- .gitignore | 2 - README.md | 10 -- crates/00-system/crate.arch.sh | 11 ++ crates/00-system/crate.sh | 7 + .../00-system/files}/pacman.conf | 0 .../etc => crates/00-system/files}/sudoers | 0 crates/10-zsh/crate.arch.sh | 7 + crates/10-zsh/crate.sh | 41 ++++++ crates/10-zsh/files/.zshrc | 23 +++ crates/20-vim/crate.arch.sh | 7 + crates/20-vim/files/.ideavimrc | 10 ++ {home => crates/20-vim/files}/.vimrc | 1 - crates/30-alacritty/crate.arch.sh | 7 + crates/30-alacritty/crate.sh | 12 ++ .../30-alacritty/files}/alacritty.yml | 4 - distros/alpine/package.list | 1 - distros/alpine/pm.sh | 20 --- distros/alpine/root/etc/doas.conf | 1 - distros/alpine/sys-scripts/00-remove-sudo.sh | 5 - distros/any/package.list | 4 - distros/arch/package.list | 2 - distros/arch/pm.sh | 22 --- distros/arch/sys-scripts/00-reflector.sh | 12 -- distros/arch/user-scripts/00-yay.sh | 13 -- dot | 85 +++++++++++ skip_steps.sh | 7 - sync.sh | 132 ------------------ unlink.sh | 10 -- 28 files changed, 210 insertions(+), 246 deletions(-) delete mode 100644 .gitignore delete mode 100644 README.md create mode 100644 crates/00-system/crate.arch.sh create mode 100644 crates/00-system/crate.sh rename {distros/arch/root/etc => crates/00-system/files}/pacman.conf (100%) rename {distros/any/root/etc => crates/00-system/files}/sudoers (100%) create mode 100644 crates/10-zsh/crate.arch.sh create mode 100644 crates/10-zsh/crate.sh create mode 100644 crates/10-zsh/files/.zshrc create mode 100644 crates/20-vim/crate.arch.sh create mode 100644 crates/20-vim/files/.ideavimrc rename {home => crates/20-vim/files}/.vimrc (96%) create mode 100644 crates/30-alacritty/crate.arch.sh create mode 100644 crates/30-alacritty/crate.sh rename {home/.config/alacritty => crates/30-alacritty/files}/alacritty.yml (56%) delete mode 100644 distros/alpine/package.list delete mode 100644 distros/alpine/pm.sh delete mode 100644 distros/alpine/root/etc/doas.conf delete mode 100644 distros/alpine/sys-scripts/00-remove-sudo.sh delete mode 100644 distros/any/package.list delete mode 100644 distros/arch/package.list delete mode 100644 distros/arch/pm.sh delete mode 100644 distros/arch/sys-scripts/00-reflector.sh delete mode 100644 distros/arch/user-scripts/00-yay.sh create mode 100755 dot delete mode 100644 skip_steps.sh delete mode 100644 sync.sh delete mode 100644 unlink.sh diff --git a/.gitignore b/.gitignore deleted file mode 100644 index e0318d4..0000000 --- a/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -.idea/ -.dotfiles/ \ No newline at end of file diff --git a/README.md b/README.md deleted file mode 100644 index e6074a3..0000000 --- a/README.md +++ /dev/null @@ -1,10 +0,0 @@ -# Dotfiles - -## `distros/` -This directory is meant to setup the distro to the liking of the user. -### `distros/*/root` -Contains files to overlay over the executing system. -### `distro/*/sys-scripts` -scripts that are ran as `root` -### `distro/*/user-scripts` -scripts that are ran as the user \ No newline at end of file diff --git a/crates/00-system/crate.arch.sh b/crates/00-system/crate.arch.sh new file mode 100644 index 0000000..ce3f7dd --- /dev/null +++ b/crates/00-system/crate.arch.sh @@ -0,0 +1,11 @@ +super_apply() { + pacman -S --needed sudo reflector + if ! grep -q "Reflector" /etc/pacman.d/mirrorlist; then + cp /etc/pacman.d/mirrorlist /etc/pacman.d/mirrorlist.bak + reflector -c NL -f 10 --threads 4 --save /etc/pacman.d/mirrorlist + else + echo "err: reflector already executed -- skipping..." + fi + + cp files/pacman.conf /etc/pacman.conf +} \ No newline at end of file diff --git a/crates/00-system/crate.sh b/crates/00-system/crate.sh new file mode 100644 index 0000000..2a73944 --- /dev/null +++ b/crates/00-system/crate.sh @@ -0,0 +1,7 @@ +#!/bin/sh + +describe="Install stuff on the system!" + +super_apply() { + cp files/sudoers /etc/sudoers +} \ No newline at end of file diff --git a/distros/arch/root/etc/pacman.conf b/crates/00-system/files/pacman.conf similarity index 100% rename from distros/arch/root/etc/pacman.conf rename to crates/00-system/files/pacman.conf diff --git a/distros/any/root/etc/sudoers b/crates/00-system/files/sudoers similarity index 100% rename from distros/any/root/etc/sudoers rename to crates/00-system/files/sudoers diff --git a/crates/10-zsh/crate.arch.sh b/crates/10-zsh/crate.arch.sh new file mode 100644 index 0000000..b44c9ed --- /dev/null +++ b/crates/10-zsh/crate.arch.sh @@ -0,0 +1,7 @@ +super_apply() { + pacman -S --needed zsh cmake +} + +super_undo() { + pacman -R zsh +} \ No newline at end of file diff --git a/crates/10-zsh/crate.sh b/crates/10-zsh/crate.sh new file mode 100644 index 0000000..2e470d8 --- /dev/null +++ b/crates/10-zsh/crate.sh @@ -0,0 +1,41 @@ +#!/bin/sh + +describe="Install zsh and oh-my-zsh!" +scripts="@distro @self" + +super_apply() { + [ -d /tmp/fastfetch ] || git clone https://github.com/LinusDierheimer/fastfetch /tmp/fastfetch + + if ! command -v fastfetch &> /dev/null; then + cd /tmp/fastfetch + mkdir -p build + cd build + cmake .. + cmake --build . --target fastfetch + mv fastfetch /usr/local/bin/fastfetch + fi + + usermod $USER --shell /bin/zsh +} + +super_undo() { + usermod $USER --shell /bin/bash +} + +apply() { + if [ ! -d "$HOME/.oh-my-zsh" ]; then + sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended + + PL_DIR=${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions + [ -d "$PL_DIR" ] || git clone https://github.com/zsh-users/zsh-autosuggestions $PL_DIR + PL_DIR=${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting + [ -d "$PL_DIR" ] || git clone https://github.com/zsh-users/zsh-syntax-highlighting.git $PL_DIR + fi + + [ -e "$HOME/.zshrc" ] || ln files/.zshrc $HOME/.zshrc +} + +undo() { + unlink $HOME/.zshrc + rm -rf $HOME/.oh-my-zsh +} \ No newline at end of file diff --git a/crates/10-zsh/files/.zshrc b/crates/10-zsh/files/.zshrc new file mode 100644 index 0000000..58358a2 --- /dev/null +++ b/crates/10-zsh/files/.zshrc @@ -0,0 +1,23 @@ +export GPG_TTY=$(tty) + +# paths +export PATH="$HOME/.yarn/bin:$HOME/.config/yarn/global/node_modules/.bin:$PATH" + +# ZSH +export ZSH="$HOME/.oh-my-zsh" + +ZSH_THEME="afowler" +plugins=(git docker docker-compose node zsh-autosuggestions zsh-syntax-highlighting) +source $ZSH/oh-my-zsh.sh + +# ALIASES +alias open="xdg-open" +alias nobeep="sudo modprobe -r pcspkr" +alias s="title $HOST && cmatrix -rs && clear" +alias q="exit" + +# COSMETICS +fastfetch + +export PATH="${PATH}:/home/${USER}/.local/bin" +export SSH_AUTH_SOCK="/run/user/1000/keyring/ssh" diff --git a/crates/20-vim/crate.arch.sh b/crates/20-vim/crate.arch.sh new file mode 100644 index 0000000..d95ce2d --- /dev/null +++ b/crates/20-vim/crate.arch.sh @@ -0,0 +1,7 @@ +super_apply() { + pacman -S --needed vim +} + +super_undo() { + echo "we never uninstall vim -_-" +} \ No newline at end of file diff --git a/crates/20-vim/files/.ideavimrc b/crates/20-vim/files/.ideavimrc new file mode 100644 index 0000000..115e47f --- /dev/null +++ b/crates/20-vim/files/.ideavimrc @@ -0,0 +1,10 @@ +source ~/.vimrc + +set scrolloff=5 +set incsearch + +map Q gq + +Plug 'machakann/vim-highlightedyank' +Plug 'tpope/vim-commentary' +Plug 'wellle/targets.vim' diff --git a/home/.vimrc b/crates/20-vim/files/.vimrc similarity index 96% rename from home/.vimrc rename to crates/20-vim/files/.vimrc index 6f12643..abb89b3 100644 --- a/home/.vimrc +++ b/crates/20-vim/files/.vimrc @@ -1,3 +1,2 @@ set number set relativenumber - diff --git a/crates/30-alacritty/crate.arch.sh b/crates/30-alacritty/crate.arch.sh new file mode 100644 index 0000000..a91b78b --- /dev/null +++ b/crates/30-alacritty/crate.arch.sh @@ -0,0 +1,7 @@ +super_apply() { + pacman -S --needed alacritty +} + +super_undo() { + pacman -R alacritty +} \ No newline at end of file diff --git a/crates/30-alacritty/crate.sh b/crates/30-alacritty/crate.sh new file mode 100644 index 0000000..3a433d2 --- /dev/null +++ b/crates/30-alacritty/crate.sh @@ -0,0 +1,12 @@ +#!/bin/sh + +describe="Installs alacritty and configs" +scripts="@distro @self" + +apply() { + [ -e "$HOME/.config/alacritty/alacritty.yml" ] || ln files/alacritty.yml $HOME/.config/alacritty/alacritty.yml +} + +undo() { + unlink $HOME/.config/alacritty/alacritty.yml +} \ No newline at end of file diff --git a/home/.config/alacritty/alacritty.yml b/crates/30-alacritty/files/alacritty.yml similarity index 56% rename from home/.config/alacritty/alacritty.yml rename to crates/30-alacritty/files/alacritty.yml index 3bc0096..1a30120 100644 --- a/home/.config/alacritty/alacritty.yml +++ b/crates/30-alacritty/files/alacritty.yml @@ -1,7 +1,3 @@ -bell: - animation: 'Ease' - duration: 50 - color: '#555555' cursor: style: shape: 'Block' diff --git a/distros/alpine/package.list b/distros/alpine/package.list deleted file mode 100644 index 9d32a57..0000000 --- a/distros/alpine/package.list +++ /dev/null @@ -1 +0,0 @@ -doas \ No newline at end of file diff --git a/distros/alpine/pm.sh b/distros/alpine/pm.sh deleted file mode 100644 index 7560ed9..0000000 --- a/distros/alpine/pm.sh +++ /dev/null @@ -1,20 +0,0 @@ -cmd="apk" -while getopts "icru" opt; do - case $opt in - i) - cmd="$cmd add" - ;; - u) - cmd="$cmd add" - ;; - r) - cmd="$cmd del" - ;; - c) - cmd="$cmd info -q" - ;; - esac -done -shift $((OPTIND-1)) - -$cmd $@ \ No newline at end of file diff --git a/distros/alpine/root/etc/doas.conf b/distros/alpine/root/etc/doas.conf deleted file mode 100644 index c50a253..0000000 --- a/distros/alpine/root/etc/doas.conf +++ /dev/null @@ -1 +0,0 @@ -permit persit wheel \ No newline at end of file diff --git a/distros/alpine/sys-scripts/00-remove-sudo.sh b/distros/alpine/sys-scripts/00-remove-sudo.sh deleted file mode 100644 index 2845cb8..0000000 --- a/distros/alpine/sys-scripts/00-remove-sudo.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh - -# removes sudo - -apk del sudo \ No newline at end of file diff --git a/distros/any/package.list b/distros/any/package.list deleted file mode 100644 index 53b3000..0000000 --- a/distros/any/package.list +++ /dev/null @@ -1,4 +0,0 @@ -neofetch -git -vim -sudo \ No newline at end of file diff --git a/distros/arch/package.list b/distros/arch/package.list deleted file mode 100644 index c3e02c8..0000000 --- a/distros/arch/package.list +++ /dev/null @@ -1,2 +0,0 @@ -reflector # for scripts/00-reflector.sh -alacritty # favourite terminal emulator \ No newline at end of file diff --git a/distros/arch/pm.sh b/distros/arch/pm.sh deleted file mode 100644 index 0fd802c..0000000 --- a/distros/arch/pm.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/sh - -cmd="pacman --noconfirm" -while getopts "icru" opt; do - case $opt in - i) - cmd="$cmd -S" - ;; - u) - cmd="$cmd -Syyu" - ;; - r) - cmd="$cmd -R" - ;; - c) - cmd="$cmd -Q" - ;; - esac -done -shift $((OPTIND-1)) - -$cmd $@ \ No newline at end of file diff --git a/distros/arch/sys-scripts/00-reflector.sh b/distros/arch/sys-scripts/00-reflector.sh deleted file mode 100644 index 7d2aa9d..0000000 --- a/distros/arch/sys-scripts/00-reflector.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/sh - -# Sets up fast mirrors on arch - -if ! pacman -Q reflector; then - echo "reflector was not installed" - exit 1 -fi - -cp /etc/pacman.d/mirrorlist /etc/pacman.d/mirrorlist.bak -reflector -c NL -f 10 --threads 4 --save /etc/pacman.d/mirrorlist -echo "Server = arch.neo.faulty.nl/$repo/os/$arch" >> /etc/pacman.d/mirrorlist \ No newline at end of file diff --git a/distros/arch/user-scripts/00-yay.sh b/distros/arch/user-scripts/00-yay.sh deleted file mode 100644 index 4ce4631..0000000 --- a/distros/arch/user-scripts/00-yay.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/sh - -# Installs yay. - -[ "$UID" = "0" ] || exit 0 - -yaytmpdir=$(mktemp -d) - -git clone https://aur.archlinux.org/yay $yaytmpdir -oldpwd=$(pwd) -cd $yaytmpdir -makepkg -si -cd $oldpwd diff --git a/dot b/dot new file mode 100755 index 0000000..7993255 --- /dev/null +++ b/dot @@ -0,0 +1,85 @@ +#!/bin/sh + +ask=0 + +is_function() { + type "$1" 2> /dev/null | sed "s/$1//" | grep -qwi function +} + +curr_distro() { + cat /etc/os-release | grep -G "^ID=" | sed 's/ID=//' +} + +include() { + [ -f "$1" ] || return 1 + . $1 + return 0 +} + +func() { + if is_function $(echo "super_$2"); then + sudo sh -c ". $1 && super_$2" + fi + is_function $2 && $2 +} + +get_command() { + case $1 in + a*) + printf "apply" + ;; + u*) + printf "undo" + ;; + *) + echo "err: not supported" >&2 + exit 1 + ;; + esac +} + +# only run this *in crate dir* +run_crate() { + include ./crate.sh || exit 1 + if [ -n "$describe" ]; then + echo "desc($(basename $PWD)): $describe" + fi + cmd=$(get_command $1) + scripts=${scripts:-"@self @distro"} + for s in $scripts; do + echo "exec($(basename $PWD)): $s/$cmd" + case $s in + @self) + func ./crate.sh $cmd + ;; + @distro) + unset -f super_$cmd + unset -f $cmd + include ./crate.$(curr_distro).sh + func ./crate.$(curr_distro).sh $cmd + unset -f super_$cmd + unset -f $cmd + include ./crate.sh + ;; + *) + sh $s + ;; + esac + done +} + +if [ $# -eq 2 ]; then + [ -d crates/*$1 ] || exit 1 + cd crates/*$1 + run_crate $2 + cd ../.. +else + [ $# -eq 0 ] && exit 2 + for crate in $(find ./crates -mindepth 1 -maxdepth 1 -type d | sort); do + cd $crate + run_crate $1 + cd ../.. + done +fi + + \ No newline at end of file diff --git a/skip_steps.sh b/skip_steps.sh deleted file mode 100644 index b6e9ee1..0000000 --- a/skip_steps.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/sh - -mkdir .dotfiles &>/dev/null - -for item in ${@:-update install_package_list run_system_scripts run_user_scripts link_home overlay}; do - echo "executed_step:$item" >> .dotfiles/pending_sync -done \ No newline at end of file diff --git a/sync.sh b/sync.sh deleted file mode 100644 index 89ed355..0000000 --- a/sync.sh +++ /dev/null @@ -1,132 +0,0 @@ -#!/bin/sh - -osreleaseprop() { - cat /etc/os-release | grep -e "^$1=" | sed 's/ID=//' -} - -elevated() { - s=${SUDO:-sudo} - if [ ! "$s" = "none" ]; then - if ! command -v $s &> /dev/null; then - echo "command \"$s\" not found" - exit 1 - fi - else - s="" - fi - $s $@ -} - -DISTRO=$(osreleaseprop ID) -if [ ! -d "distros/$DISTRO" ]; then - echo "$DISTRO is not supported." - exit 1 -fi - -pm() { - elevated "sh distros/$DISTRO/pm.sh $@" -} - -install_package_list() { - pkgs="" - [ -f "distros/${1:-$DISTRO}/package.list" ] || return 1 - for pkg in $(cat distros/${1:-$DISTRO}/package.list | sed 's/#.*$//'); do - pkgs="$pkgs $pkg" - done - pm -i $pkgs -} - -run_scripts() { - cmd=$1 - shift - case $cmd in - sys) - dir="distros/${1:-$DISTRO}/sys-scripts" - [ -d "$dir" ] || return - for s in $(ls $dir); do - echo "# running $dir/$s..." - elevated sh $dir/$s || exit 1 - done - ;; - user) - dir="distros/${1:-$DISTRO}/user-scripts" - [ -d "$dir" ] || return - for s in $(ls $dir); do - echo "# running $dir/$s..." - sh $dir/$s || exit 1 - done - ;; - esac -} - -overlay() { - [ -d "distros/${1:-$DISTRO}/root" ] || return 0 - elevated cp -r distros/${1:-$DISTRO}/root / -} - -__step_update() { - echo "# updating system..." - pm -u -} - -__step_install_package_list() { - echo "# installing package lists..." - install_package_list any - install_package_list -} - -__step_run_system_scripts() { - echo "# running system scripts..." - run_scripts sys any - run_scripts sys -} - -__step_run_user_scripts() { - echo "# running user scripts..." - run_scripts user any - run_scripts user -} - -__step_overlay() { - echo "# overlaying root directories..." - overlay any - overlay -} - -__step_link_home() { - echo "# linking all home files..." - trackingfile=".dotfiles/$(git rev-parse HEAD)-links" - for item in $(find ./home -type f); do - path=$(echo $item | sed "s/\.\/home//") - [ -z "$path" ] && continue - grep -q "$path" $trackingfile &> /dev/null && continue - path="$HOME$path" - mkdir -p $(dirname $path) &> /dev/null - ln $item $path && echo "$path" >> $trackingfile - done -} - -step() { - if ! grep -q "executed_step:$1" .dotfiles/pending_sync &> /dev/null; then - $(printf "__step_%s" "$1") - echo "executed_step:$1" >> .dotfiles/pending_sync - fi -} - -mkdir -p .dotfiles &> /dev/null -touch .dotfiles/pending_sync - -if [ -n "$1" ]; then - step $1 -else - echo "started_sync:$(date)" >> .dotfiles/log - step update - step install_package_list - step run_system_scripts - step run_user_scripts - step link_home - step overlay - echo "finished_sync:$(date)" >> .dotfiles/log -fi - -unlink .dotfiles/pending_sync diff --git a/unlink.sh b/unlink.sh deleted file mode 100644 index 44e593c..0000000 --- a/unlink.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/sh - -for linkfile in ${@:-$(find .dotfiles -type f -name *-links)}; do - echo "# processing linkfile $linkfile..." - for link in $(cat $linkfile); do - echo "# unlinking $link..." - unlink $link - done - rm -rf $linkfile -done \ No newline at end of file