From 0d8090e3c8df0db30c81d5f7915ab5ddee1b4cc7 Mon Sep 17 00:00:00 2001 From: faulty Date: Sun, 19 Feb 2023 21:02:08 +0100 Subject: [PATCH] refactor: v3 --- README.md | 20 ++-- command.list | 6 - comp.sh | 21 ---- .../.config/alacritty/alacritty.yml | 0 files/{%HOME => home}/.config/kanshi/config | 0 .../{%HOME => home}/.config/kitty/kitty.conf | 0 .../{%HOME => home}/.config/rofi/config.rasi | 0 files/{%HOME => home}/.config/sway/config | 0 files/{%HOME => home}/.config/sway/status.py | 0 files/{%HOME => home}/.config/sway/status.sh | 0 files/{%HOME => home}/.vimrc | 0 files/{%HOME => home}/.zsh_preferences | 0 files/{%HOME => home}/.zsh_scripts | 0 files/{%HOME => home}/.zshrc | 0 files/{ => root}/etc/pacman.conf | 0 files/{ => root}/etc/pacman.d/mirrorlist | 0 gpackage.list | 1 - lib/Dockerfile | 7 -- lib/deploy.sh | 18 --- lib/docker.py | 31 ----- lib/lib.sh | 32 ------ scripts/00-install-requirements.sh | 6 + scripts/10-copy-files.sh | 8 ++ scripts/20-install-pkgs.sh | 23 ++++ sync.conf | 16 --- sync.sh | 108 ++---------------- 26 files changed, 55 insertions(+), 242 deletions(-) delete mode 100644 command.list delete mode 100755 comp.sh rename files/{%HOME => home}/.config/alacritty/alacritty.yml (100%) rename files/{%HOME => home}/.config/kanshi/config (100%) rename files/{%HOME => home}/.config/kitty/kitty.conf (100%) rename files/{%HOME => home}/.config/rofi/config.rasi (100%) rename files/{%HOME => home}/.config/sway/config (100%) rename files/{%HOME => home}/.config/sway/status.py (100%) rename files/{%HOME => home}/.config/sway/status.sh (100%) rename files/{%HOME => home}/.vimrc (100%) rename files/{%HOME => home}/.zsh_preferences (100%) rename files/{%HOME => home}/.zsh_scripts (100%) rename files/{%HOME => home}/.zshrc (100%) rename files/{ => root}/etc/pacman.conf (100%) rename files/{ => root}/etc/pacman.d/mirrorlist (100%) delete mode 100644 lib/Dockerfile delete mode 100644 lib/deploy.sh delete mode 100644 lib/docker.py delete mode 100644 lib/lib.sh create mode 100644 scripts/00-install-requirements.sh create mode 100644 scripts/10-copy-files.sh create mode 100644 scripts/20-install-pkgs.sh delete mode 100644 sync.conf diff --git a/README.md b/README.md index 23b8670..2e5da9f 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,9 @@ -# Dotfiles (v2) +# Faulty's Dotfiles +Version: 3 -This repo has a simple sync script with a few features: -- file sync (not symlinked anymore) -- package install -- after install commands -- deploy script +--- -## Deployment -To import the dotfiles run: -`curl --proto '=https' --tlsv1.2 -sSf https://git.faulty.nl/didier/dotfiles/-/raw/main/lib/deploy.sh | sh` - -## Notes -- `gpackage.list` -This is a list with packages only installed if the `-g` or `--graphical` flag is used. \ No newline at end of file +## file sync +files in `./files` are synced across the system. +files in `./files/home` are synced to the home of the user running the script. +files in `./files/root` are synced with sudo to the root of the script. \ No newline at end of file diff --git a/command.list b/command.list deleted file mode 100644 index c855eca..0000000 --- a/command.list +++ /dev/null @@ -1,6 +0,0 @@ -^. ./sync.conf && $PM_COMMAND $PM_UPGRADE $PM_NOCONFIRM || printf "" -^[ -d /tmp/yay ] && rm -rf /tmp/yay || printf "" -command -v makepkg && (command -v yay || (git clone https://aur.archlinux.org/yay /tmp/yay && (cd /tmp/yay && makepkg --noconfirm -si))) || printf "" -^[ -d /tmp/pfetch ] && rm -rf /tmp/pfetch || printf "" -^(git clone https://github.com/dylanaraps/pfetch.git /tmp/pfetch && cd /tmp/pfetch && (chmod a+x ./pfetch && $SYS_SUDO mv ./pfetch /usr/local/pfetch)) || printf "" -sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended || echo "zsh not installed" diff --git a/comp.sh b/comp.sh deleted file mode 100755 index 0d6c724..0000000 --- a/comp.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/sh - -# #################### # -# Compatibility Script # -# #################### # -if [ ! -z "$1" ]; then - cmd=$1; shift -fi - -case $cmd in - debian|ubuntu|apt|deb) - PM_COMMAND=apt \ - PM_NOCONFIRM=-y \ - PM_INSTALL=install \ - PM_UPDATE=update \ - PM_UPGRADE=upgrade \ - PM_REMOVE=purge \ - ./sync.sh $@ - ;; - *|''|arch) ./sync.sh $cmd $@ ;; -esac \ No newline at end of file diff --git a/files/%HOME/.config/alacritty/alacritty.yml b/files/home/.config/alacritty/alacritty.yml similarity index 100% rename from files/%HOME/.config/alacritty/alacritty.yml rename to files/home/.config/alacritty/alacritty.yml diff --git a/files/%HOME/.config/kanshi/config b/files/home/.config/kanshi/config similarity index 100% rename from files/%HOME/.config/kanshi/config rename to files/home/.config/kanshi/config diff --git a/files/%HOME/.config/kitty/kitty.conf b/files/home/.config/kitty/kitty.conf similarity index 100% rename from files/%HOME/.config/kitty/kitty.conf rename to files/home/.config/kitty/kitty.conf diff --git a/files/%HOME/.config/rofi/config.rasi b/files/home/.config/rofi/config.rasi similarity index 100% rename from files/%HOME/.config/rofi/config.rasi rename to files/home/.config/rofi/config.rasi diff --git a/files/%HOME/.config/sway/config b/files/home/.config/sway/config similarity index 100% rename from files/%HOME/.config/sway/config rename to files/home/.config/sway/config diff --git a/files/%HOME/.config/sway/status.py b/files/home/.config/sway/status.py similarity index 100% rename from files/%HOME/.config/sway/status.py rename to files/home/.config/sway/status.py diff --git a/files/%HOME/.config/sway/status.sh b/files/home/.config/sway/status.sh similarity index 100% rename from files/%HOME/.config/sway/status.sh rename to files/home/.config/sway/status.sh diff --git a/files/%HOME/.vimrc b/files/home/.vimrc similarity index 100% rename from files/%HOME/.vimrc rename to files/home/.vimrc diff --git a/files/%HOME/.zsh_preferences b/files/home/.zsh_preferences similarity index 100% rename from files/%HOME/.zsh_preferences rename to files/home/.zsh_preferences diff --git a/files/%HOME/.zsh_scripts b/files/home/.zsh_scripts similarity index 100% rename from files/%HOME/.zsh_scripts rename to files/home/.zsh_scripts diff --git a/files/%HOME/.zshrc b/files/home/.zshrc similarity index 100% rename from files/%HOME/.zshrc rename to files/home/.zshrc diff --git a/files/etc/pacman.conf b/files/root/etc/pacman.conf similarity index 100% rename from files/etc/pacman.conf rename to files/root/etc/pacman.conf diff --git a/files/etc/pacman.d/mirrorlist b/files/root/etc/pacman.d/mirrorlist similarity index 100% rename from files/etc/pacman.d/mirrorlist rename to files/root/etc/pacman.d/mirrorlist diff --git a/gpackage.list b/gpackage.list index 661b9ba..2f78a0b 100644 --- a/gpackage.list +++ b/gpackage.list @@ -1,4 +1,3 @@ alacritty sway -wlogout kanshi diff --git a/lib/Dockerfile b/lib/Dockerfile deleted file mode 100644 index d174a2e..0000000 --- a/lib/Dockerfile +++ /dev/null @@ -1,7 +0,0 @@ -FROM python:3.10-alpine - -RUN apk add git -RUN git clone https://git.faulty.nl/didier/dotfiles /app - -WORKDIR /app -ENTRYPOINT ["python3", "/app/lib/docker.py"] \ No newline at end of file diff --git a/lib/deploy.sh b/lib/deploy.sh deleted file mode 100644 index 04a7b34..0000000 --- a/lib/deploy.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/sh - -REPO_LIST="https://git.faulty.nl/didier/dotfiles" -DOTFILES_DIR="$HOME/.local/dotfiles" - -clone() { - for repo in $REPO_LIST; do - git clone "$repo" "$DOTFILES_DIR" && return 0 - done -} - -main() { - [ -d "$DOTFILES_DIR" ] || clone - cd "$DOTFILES_DIR" || exit 1 - ./comp.sh "$@" -} - -main "$@" \ No newline at end of file diff --git a/lib/docker.py b/lib/docker.py deleted file mode 100644 index 08ad428..0000000 --- a/lib/docker.py +++ /dev/null @@ -1,31 +0,0 @@ -# any HTTP request returns the contents of: ./lib/deploy.sh -# If the deploy script is older then a day, do a git pull - -from http.server import BaseHTTPRequestHandler, HTTPServer -import subprocess -import os -import time - -class handler(BaseHTTPRequestHandler): - def do_GET(self): - self.send_response(200) - self.send_header('Content-type','text/plain') - self.end_headers() - if (time.time() - os.path.getmtime('./lib/deploy.sh') > 86400) or self.path == '/pull': - subprocess.call(['git', 'pull']) - with open('./lib/deploy.sh') as f: - self.wfile.write(bytes(f.read(), 'utf-8')) - self.wfile.write(bytes("# Git pull: " + str(time.time() - os.path.getmtime('./lib/deploy.sh')) + " seconds ago", 'utf-8')) - - -def main(): - try: - server = HTTPServer(('', 80), handler) - print('started httpserver...') - server.serve_forever() - except KeyboardInterrupt: - print('^C received, shutting down the web server') - server.socket.close() - -if __name__ == '__main__': - main() \ No newline at end of file diff --git a/lib/lib.sh b/lib/lib.sh deleted file mode 100644 index 5ba6f73..0000000 --- a/lib/lib.sh +++ /dev/null @@ -1,32 +0,0 @@ -#!/bin/sh - -. ./sync.conf || . ../sync.conf - -DRY_RUN=${DRY_RUN:-no} - -bool() { - case "$1" in - 1|true|yes|on|TRUE|YES|ON) return 0 ;; - *) return 1 ;; - esac -} - -run() { - # Check if command starts with NO_RUN ($*) and remove it - if echo "$*" | grep -q "^NO_RUN"; then - return 0 - fi - - if bool "$DRY_RUN"; then - echo "DRY: + $*" - else - echo "+ $*" - "$@" - fi -} - -is_graphical() { - command -v $PREF_TERM > /dev/null && return 0 || return 1 -} - -command -v $SYS_SUDO > /dev/null || SYS_SUDO="NO_RUN" diff --git a/scripts/00-install-requirements.sh b/scripts/00-install-requirements.sh new file mode 100644 index 0000000..33a1cf5 --- /dev/null +++ b/scripts/00-install-requirements.sh @@ -0,0 +1,6 @@ +#!/bin/sh + +# This file only installs what is needed for the sync to perform... + +$SUDO $PM $PM_INSTALL $PM_NOCONFIRM \ + rsync \ No newline at end of file diff --git a/scripts/10-copy-files.sh b/scripts/10-copy-files.sh new file mode 100644 index 0000000..e5c4941 --- /dev/null +++ b/scripts/10-copy-files.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +HOME_FILES=${HOME_FILES:-./files/home} +ROOT_FILES=${ROOT_FILES:-./files/root} + +# overwrite files but preserve files surrounding +rsync -av $HOME_FILES/ $HOME +$SUDO rsync -av $ROOT_FILES/ / \ No newline at end of file diff --git a/scripts/20-install-pkgs.sh b/scripts/20-install-pkgs.sh new file mode 100644 index 0000000..b2f0fd2 --- /dev/null +++ b/scripts/20-install-pkgs.sh @@ -0,0 +1,23 @@ +#!/bin/sh + +PACKAGE_LIST=${PACKAGE_LIST:-./package.list} +GRAPHICAL_PACKAGE_LIST=${GRAPHICAL_PACKAGE_LIST:-./gpackage.list} + +_APPLICATIONS="" +while read -r pkg; do + [ -z "$pkg" ] && continue + [ "$(echo "$pkg" | cut -c1)" = "#" ] && continue + _APPLICATIONS="$_APPLICATIONS $pkg" +done < "$PACKAGE_LIST" + +if [ "${GRAPHICAL:-no}" = "yes" ]; then + if [ -f "$GRAPHICAL_PACKAGE_LIST" ]; then + while read -r pkg; do + [ -z "$pkg" ] && continue + [ "$(echo "$pkg" | cut -c1)" = "#" ] && continue + _APPLICATIONS="$_APPLICATIONS $pkg" + done < "$GRAPHICAL_PACKAGE_LIST" + fi +fi + +$SUDO $PM $PM_INSTALL $PM_NOCONFIRM $_APPLICATIONS diff --git a/sync.conf b/sync.conf deleted file mode 100644 index 8c57fc4..0000000 --- a/sync.conf +++ /dev/null @@ -1,16 +0,0 @@ -# PM - Package Manager Options -PM_COMMAND=${PM_COMMAND:-pacman} -PM_NOCONFIRM=${PM_NOCONFIRM:-"--noconfirm"} -PM_INSTALL=${PM_INSTALL:--S} -PM_REMOVE=${PM_REMOVE:-R} -PM_UPDATE=${PM_UPDATE:--Sy} -PM_UPGRADE=${PM_UPGRADE:--Syyu} - -# SYS - System Options -SYS_SUDO=${SYS_SUDO:-"sudo"} -SYS_ROOT=${SYS_ROOT:-"/"} - -# PREF - Preferences -PREF_TERM=${PREF_TERM:-alacritty} -PREF_TERM_SET_TITLE=${PREF_TERM_SET_TITLE:--t} -PREF_TERM_RUN_CMD=${PREF_TERM_RUN_CMD:--e} \ No newline at end of file diff --git a/sync.sh b/sync.sh index a753714..e0a04d2 100755 --- a/sync.sh +++ b/sync.sh @@ -1,104 +1,18 @@ #!/bin/sh -SYNC_FILES=${SYNC_FILES:-yes} -INSTALL_PKGS=${INSTALL_PKGS:-yes} -RUN_CMDS=${RUN_CMDS:-yes} -PULL_GIT=${PULL_GIT:-yes} -TIME_TRACK=${TIME_TRACK:-no} +SUDO=${SUDO:-sudo} -ARGS="$@" - -. ./lib/lib.sh - -set -e # Exit on error - -_install_pkgs() { - run $SYS_SUDO $PM_COMMAND $PM_UPDATE $PM_NOCONFIRM - _APPLICATIONS="" - while read -r pkg; do - [ -z "$pkg" ] && continue - [ "$(echo "$pkg" | cut -c1)" = "#" ] && continue - _APPLICATIONS="$_APPLICATIONS $pkg" - done <"$1" - run $SYS_SUDO $PM_COMMAND $PM_INSTALL $PM_NOCONFIRM $_APPLICATIONS -} - -_sync_files() { - #copy all files and folders from ./files to / - #except for ./files/%HOME - - for item in ./files/*; do - [ "$item" = "./files/%HOME" ] && continue - # e.g. ./files/etc -> /etc - run mkdir -p "$SYS_ROOT/$(basename "${item#./files/}")" - run $SYS_SUDO cp -r "$item/." "$SYS_ROOT/${item#./files/}" - done -} - -_run_cmds() { - while read -r cmd; do - if [ "$(echo "$cmd" | cut -c1)" = "^" ]; then - run $SYS_SUDO sh -c "$(echo "$cmd" | cut -c2-)" - else - run sh -c "$cmd" - fi - done <./command.list -} - -ARGS="$@" -_skip_next_arg="n" -arg_handler() { - for arg in $ARGS; do - bool $_skip_next_arg && continue - - case $arg in - +files) SYNC_FILES=yes ;; - -files) SYNC_FILES=no ;; - +pkgs) INSTALL_PKGS=yes ;; - -pkgs) INSTALL_PKGS=no ;; - +cmds) RUN_CMDS=yes ;; - -cmds) RUN_CMDS=no ;; - +git) PULL_GIT=yes ;; - -git) PULL_GIT=no ;; - +) SYNC_FILES=yes; INSTALL_PKGS=yes; RUN_CMDS=yes; PULL_GIT=yes ;; - -) SYNC_FILES=no; INSTALL_PKGS=no; RUN_CMDS=no; PULL_GIT=no ;; - +*) - echo "# Unknown argument: $arg" - exit 1 - ;; - -*) - echo "# Unknown argument: $arg" - exit 1 - ;; - esac - done -} +PM=${PM:-pacman} +PM_INSTALL=${PM_INSTALL:--S} +PM_NOCONFIRM=${PM_NOCONFIRM:---noconfirm} main() { - arg_handler - - echo "# hook: PULL_GIT" - bool "$PULL_GIT" && run git pull - - echo "# hook: SYNC_FILES (/)" - bool "$SYNC_FILES" && run cp -a "./files/%HOME/." "$HOME" - - echo "# hook: SYNC_FILES" - bool "$SYNC_FILES" && _sync_files - - echo "# hook: INSTALL_PKGS" - bool "$INSTALL_PKGS" && _install_pkgs ./package.list - - echo "# hook: RUN_CMDS" - bool "$RUN_CMDS" && _run_cmds - - return 0 + for script in ./scripts/* ; do + echo "# exec $script" + . $script + done } -echo "# exec: start." -if bool $TIME_TRACK; then - time main "$@" -else - main "$@" -fi -echo "# exec: done." +main "$@" + +echo "# OK" \ No newline at end of file