diff options
| author | Craig Jennings <c@cjennings.net> | 2026-05-17 14:08:18 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-05-17 14:08:18 -0500 |
| commit | dae765970268dcbea96060de63cae06c3e63bea6 (patch) | |
| tree | eba6d9d2225b8f17fd2d4fec00251eb0713cfd57 /scripts/post-install.sh | |
| parent | 61bf3e7463c2e7f40874e718911f2bd6b86b859e (diff) | |
| download | archsetup-dae765970268dcbea96060de63cae06c3e63bea6.tar.gz archsetup-dae765970268dcbea96060de63cae06c3e63bea6.zip | |
refactor(scripts/post-install): consolidate gitrepos.sh and harden the script
gitrepos.sh did the same `~/.dotfiles` / `~/.emacs.d` remote swap that
post-install.sh already had, plus a `git pull --set-upstream origin main`
follow-on that post-install was missing. I folded the pull into the
post-install remote-rewrite block and dropped gitrepos.sh.
While in the file, I also:
- Quoted every variable (`"$logfile"`, `"$HOME"` paths, `"$(whoami)"`).
- Sent the remote-rewrite block to the log file like the other blocks
do (was leaking to stdout).
- Made the remote-rewrite idempotent. A re-run used to break the
`cd && remote remove && remote add` chain because remove fails when
origin is already the desired URL. The loop now uses
`git -C "$dir" remote set-url` when origin exists and `remote add`
when it does not.
- Pre-created `~/sync`, `~/pictures`, `~/code`, `~/projects` so the
clones don't fail on missing parent dirs.
- Wrapped each `git clone` in a `clone_if_missing` helper so a re-run
skips destinations that already exist instead of erroring out.
README.md picks up the gitrepos.sh removal in the forking note.
Diffstat (limited to 'scripts/post-install.sh')
| -rwxr-xr-x | scripts/post-install.sh | 117 |
1 files changed, 72 insertions, 45 deletions
diff --git a/scripts/post-install.sh b/scripts/post-install.sh index c3d1022..f184d9d 100755 --- a/scripts/post-install.sh +++ b/scripts/post-install.sh @@ -1,59 +1,86 @@ #!/bin/sh logfile="$HOME/post-install.log" -touch $logfile +touch "$logfile" echo "fixing perms on gpg directory" { - chown -R $(whoami) ~/.gnupg/ - find ~/.gnupg -type f -exec chmod 600 {} \; - find ~/.gnupg -type d -exec chmod 700 {} \; -} >> $logfile 2>&1 + chown -R "$(whoami)" "$HOME/.gnupg/" + find "$HOME/.gnupg" -type f -exec chmod 600 {} \; + find "$HOME/.gnupg" -type d -exec chmod 700 {} \; +} >> "$logfile" 2>&1 echo "fixing remote repositories" { - cd ~/.dotfiles && \ - git remote remove origin && \ - git remote add origin git@cjennings.net:dotfiles.git - - cd ~/.emacs.d && \ - git remote remove origin && \ - git remote add origin git@cjennings.net:dotemacs.git -} + for entry in \ + "$HOME/.dotfiles:git@cjennings.net:dotfiles.git" \ + "$HOME/.emacs.d:git@cjennings.net:dotemacs.git" + do + dir="${entry%%:*}" + url="${entry#*:}" + if [ ! -d "$dir/.git" ]; then + echo "skip: $dir is not a git checkout" + continue + fi + if git -C "$dir" remote | grep -qx origin; then + git -C "$dir" remote set-url origin "$url" + else + git -C "$dir" remote add origin "$url" + fi + git -C "$dir" pull --set-upstream origin main || true + done +} >> "$logfile" 2>&1 echo "cloning git repos" { - git clone cjennings@cjennings.net:git/org.git ~/sync/org - git clone --depth 1 cjennings@cjennings.net:git/wallpaper.git ~/pictures/wallpaper - git clone git@cjennings.net:dwm.git ~/code/dwm - git clone git@cjennings.net:dmenu.git ~/code/dmenu - git clone git@cjennings.net:st.git ~/code/st - git clone git@cjennings.net:slock.git ~/code/slock - git clone git@cjennings.net:pinentry-dmenu.git ~/code/pinentry-dmenu - - git clone git@github.com:cjennings/pocketbook.git ~/code/pocketbook - git clone cjennings@cjennings.net:git/bsdsetup.git ~/code/bsdsetup - git clone git@cjennings.net:git/archsetup.git ~/code/archsetup - git clone git@cjennings.net:dotemacs.git ~/code/dotemacs - - git clone cjennings@cjennings.net:git/wttrin.git ~/code/wttrin.git - git clone cjennings@cjennings.net:git/rsyncshot.git ~/code/rsyncshot.git - - git clone cjennings@cjennings.net:git/exercism.git ~/code/exercism - git clone cjennings@cjennings.net:git/elisp.git ~/code/elisp - git clone cjennings@cjennings.net:git/clisp.git ~/code/clisp - git clone cjennings@cjennings.net:git/lcthw.git ~/code/lcthw - git clone cjennings@cjennings.net:git/100dayspython.git ~/code/100dayspython - - git clone cjennings@cjennings.net:git/documents.git ~/projects/documents - git clone cjennings@cjennings.net:git/kit.git ~/projects/kit - git clone cjennings@cjennings.net:git/clipper.git ~/projects/clipper - git clone cjennings@cjennings.net:git/finances.git ~/projects/finances - git clone cjennings@cjennings.net:git/nasbuild.git ~/projects/nasbuild - git clone cjennings@cjennings.net:git/nextjob.git ~/projects/nextjob - git clone cjennings@cjennings.net:git/elibrary.git ~/projects/elibrary - git clone cjennings@cjennings.net:git/danneel-hoa.git ~/projects/danneel-hoa - git clone cjennings@cjennings.net:git/danneel-remodel.git ~/projects/danneel-remodel -} >> $logfile 2>&1 + mkdir -p "$HOME/sync" "$HOME/pictures" "$HOME/code" "$HOME/projects" + + clone_if_missing() { + _remote="$1" + _dest="$2" + _depth="${3:-}" + if [ -e "$_dest" ]; then + echo "skip: $_dest already exists" + return 0 + fi + if [ -n "$_depth" ]; then + git clone --depth "$_depth" "$_remote" "$_dest" + else + git clone "$_remote" "$_dest" + fi + } + + clone_if_missing cjennings@cjennings.net:git/org.git "$HOME/sync/org" + clone_if_missing cjennings@cjennings.net:git/wallpaper.git "$HOME/pictures/wallpaper" 1 + clone_if_missing git@cjennings.net:dwm.git "$HOME/code/dwm" + clone_if_missing git@cjennings.net:dmenu.git "$HOME/code/dmenu" + clone_if_missing git@cjennings.net:st.git "$HOME/code/st" + clone_if_missing git@cjennings.net:slock.git "$HOME/code/slock" + clone_if_missing git@cjennings.net:pinentry-dmenu.git "$HOME/code/pinentry-dmenu" + + clone_if_missing git@github.com:cjennings/pocketbook.git "$HOME/code/pocketbook" + clone_if_missing cjennings@cjennings.net:git/bsdsetup.git "$HOME/code/bsdsetup" + clone_if_missing git@cjennings.net:git/archsetup.git "$HOME/code/archsetup" + clone_if_missing git@cjennings.net:dotemacs.git "$HOME/code/dotemacs" + + clone_if_missing cjennings@cjennings.net:git/wttrin.git "$HOME/code/wttrin.git" + clone_if_missing cjennings@cjennings.net:git/rsyncshot.git "$HOME/code/rsyncshot.git" + + clone_if_missing cjennings@cjennings.net:git/exercism.git "$HOME/code/exercism" + clone_if_missing cjennings@cjennings.net:git/elisp.git "$HOME/code/elisp" + clone_if_missing cjennings@cjennings.net:git/clisp.git "$HOME/code/clisp" + clone_if_missing cjennings@cjennings.net:git/lcthw.git "$HOME/code/lcthw" + clone_if_missing cjennings@cjennings.net:git/100dayspython.git "$HOME/code/100dayspython" + + clone_if_missing cjennings@cjennings.net:git/documents.git "$HOME/projects/documents" + clone_if_missing cjennings@cjennings.net:git/kit.git "$HOME/projects/kit" + clone_if_missing cjennings@cjennings.net:git/clipper.git "$HOME/projects/clipper" + clone_if_missing cjennings@cjennings.net:git/finances.git "$HOME/projects/finances" + clone_if_missing cjennings@cjennings.net:git/nasbuild.git "$HOME/projects/nasbuild" + clone_if_missing cjennings@cjennings.net:git/nextjob.git "$HOME/projects/nextjob" + clone_if_missing cjennings@cjennings.net:git/elibrary.git "$HOME/projects/elibrary" + clone_if_missing cjennings@cjennings.net:git/danneel-hoa.git "$HOME/projects/danneel-hoa" + clone_if_missing cjennings@cjennings.net:git/danneel-remodel.git "$HOME/projects/danneel-remodel" +} >> "$logfile" 2>&1 printf "\n\nDone.\n\n" |
