From 167f0890ffc8711312231bc891c7b73f14c507f2 Mon Sep 17 00:00:00 2001 From: Joel McCracken Date: Wed, 15 Nov 2023 02:20:36 -0500 Subject: [PATCH] migrate link-dotfiles to workstation.org --- bootstrap-workstation.sh | 20 ++-- {bin => lib/shell/setup}/link-dotfiles.sh | 3 + workstation.org | 129 ++++++++++++++++++++-- 3 files changed, 132 insertions(+), 20 deletions(-) rename {bin => lib/shell/setup}/link-dotfiles.sh (93%) mode change 100644 => 100755 diff --git a/bootstrap-workstation.sh b/bootstrap-workstation.sh index 40b46331..8fefbe4e 100755 --- a/bootstrap-workstation.sh +++ b/bootstrap-workstation.sh @@ -433,19 +433,19 @@ echo "'ws install' process completed" info linking dotfiles that should be symlinked -bash ~/workstation/bin/link-dotfiles.sh -f -c +bash ~/workstation/lib/shell/setup/link-dotfiles.sh -f -c info finished linking dotfiles -set +e -echo "Running final installs (install)" -if is_linux; then - echo "is linux, installing ripgrep, fdfind, etc via apt"; - time sudo apt-get install ripgrep fd-find zsh make libtool libvterm-dev; - echo "done running final installs"; -else - echo "linux not detected, no final installs necessary"; -fi +# set +e +# echo "Running final installs (install)" +# if is_linux; then +# echo "is linux, installing ripgrep, fdfind, etc via apt"; +# time sudo apt-get install ripgrep fd-find zsh make libtool libvterm-dev; +# echo "done running final installs"; +# else +# echo "linux not detected, no final installs necessary"; +# fi initial_bitwarden_sync diff --git a/bin/link-dotfiles.sh b/lib/shell/setup/link-dotfiles.sh old mode 100644 new mode 100755 similarity index 93% rename from bin/link-dotfiles.sh rename to lib/shell/setup/link-dotfiles.sh index 8ffb09e2..5b663a33 --- a/bin/link-dotfiles.sh +++ b/lib/shell/setup/link-dotfiles.sh @@ -1,5 +1,7 @@ #!/usr/bin/env bash +# Linking dotfiles +# [[file:../../../workstation.org::*Linking dotfiles][Linking dotfiles:1]] source ~/workstation/lib/shell/funcs.sh export FORCE=false; @@ -105,3 +107,4 @@ ln_norm Brewfile.lock.json ln_norm bitbar ln_dotfile_n config/git +# Linking dotfiles:1 ends here diff --git a/workstation.org b/workstation.org index 7d478424..c6436beb 100644 --- a/workstation.org +++ b/workstation.org @@ -412,7 +412,7 @@ echo "'ws install' process completed" #+begin_src shell :noweb yes info linking dotfiles that should be symlinked -bash ~/workstation/bin/link-dotfiles.sh -f -c +bash ~/workstation/lib/shell/setup/link-dotfiles.sh -f -c info finished linking dotfiles #+end_src @@ -421,15 +421,15 @@ TODO fix these, should move to home manager. #+begin_src shell :noweb yes -set +e -echo "Running final installs (install)" -if is_linux; then - echo "is linux, installing ripgrep, fdfind, etc via apt"; - time sudo apt-get install ripgrep fd-find zsh make libtool libvterm-dev; - echo "done running final installs"; -else - echo "linux not detected, no final installs necessary"; -fi +# set +e +# echo "Running final installs (install)" +# if is_linux; then +# echo "is linux, installing ripgrep, fdfind, etc via apt"; +# time sudo apt-get install ripgrep fd-find zsh make libtool libvterm-dev; +# echo "done running final installs"; +# else +# echo "linux not detected, no final installs necessary"; +# fi #+end_src *** set up workstation secrets @@ -768,6 +768,115 @@ function initial_bitwarden_sync() { «initial_bitwarden_sync_function» initial_bitwarden_sync +#+end_src +*** Linking dotfiles +#+begin_src sh :tangle ./lib/shell/setup/link-dotfiles.sh :shebang "#!/usr/bin/env bash" :noweb yes +source ~/workstation/lib/shell/funcs.sh + +export FORCE=false; +export VERBOSE=false; +export CHECK=false; + +function error() { + printf "$@" >&2 + exit 1 +} + +function handle_force() { + if [ "$FORCE" = "true" ]; then + mv_dated_backup "$1" + fi +} + +function verbose() { + if [ "$VERBOSE" = "true" ]; then + echo "$@" + fi +} + +function check () { + if [ "$CHECK" = "true" ] || [ "$VERBOSE" = "true" ]; then + echo "$@" + fi +} + + +function ln_helper() { + dest=~/$2$1 + src=~/workstation/dotfiles/$1 + curr=$(readlink -f "$dest") + + if [ -L "$dest" ] && [ "$curr" = "$src" ]; then + check "OK: $dest already points to $src" + else + check "NOT OK: $dest does not point to $src" + if [ "$CHECK" = "true" ] && ! [ "$FORCE" = "true" ]; then + exit 11 + fi + + handle_force $dest + ln -s "$src" "$dest" + fi +} + +function ln_dotfile() { + ln_helper $1 "." +} + +function ln_norm() { + ln_helper $1 "" +} + +function ln_dotfile_n() { + src=~/workstation/dotfiles/$1 + dest=~/.$1 + destdir=$(dirname dest) + + if [ ! -d $destdir ]; then + mkdir -p $destdir + fi + + ln_helper $1 "." +} + +while (( $# > 0 )); do + opt="$1" + shift + + case $opt in + -f) + FORCE=true + ;; + -v) + VERBOSE=true + ;; + -c) + CHECK=true + ;; + *) + error "%s: error, unknown option '%s'" "$0" "$opt" + exit 1 + ;; + esac +done + +ln_dotfile bashrc +ln_dotfile ghci +ln_dotfile gitconfig +ln_dotfile hammerspoon +ln_dotfile nix-channels +ln_dotfile npmrc +ln_dotfile reddup.yml +ln_dotfile zshrc +ln_dotfile zshrc.aeglos.sh +ln_dotfile doom.d + +ln_norm Brewfile +ln_norm Brewfile.lock.json +ln_norm bitbar + +ln_dotfile_n config/git + #+end_src * Nix components