summaryrefslogtreecommitdiff
path: root/dotfiles/system/.local/bin/update-backup-repositories
diff options
context:
space:
mode:
Diffstat (limited to 'dotfiles/system/.local/bin/update-backup-repositories')
-rwxr-xr-xdotfiles/system/.local/bin/update-backup-repositories56
1 files changed, 56 insertions, 0 deletions
diff --git a/dotfiles/system/.local/bin/update-backup-repositories b/dotfiles/system/.local/bin/update-backup-repositories
new file mode 100755
index 0000000..a91b438
--- /dev/null
+++ b/dotfiles/system/.local/bin/update-backup-repositories
@@ -0,0 +1,56 @@
+#!/bin/sh
+# Craig Jennings <c@cjennings.net>
+# updates or clones repositories for backup
+
+REPOS_HOME="/media/backup/repositories/"
+
+# Create REPOS_HOME dir if not exists
+if [ ! -d "$REPOS_HOME" ]; then
+ mkdir -p "$REPOS_HOME"
+fi
+
+# Make sure REPOS_HOME dir is writable
+if [ ! -w "$REPOS_HOME" ]; then
+ echo "Directory $REPOS_HOME is not writable."
+ exit 1
+fi
+
+# Make sure git is available
+if ! command -v git >/dev/null 2>&1; then
+ echo "Git command does not exist. Please install git."
+ exit 1
+fi
+
+cd "$REPOS_HOME"
+
+repos="
+git@cjennings.net:archsetup.git
+git@cjennings.net:dmenu.git
+git@cjennings.net:dotemacs.git
+git@cjennings.net:dotfiles.git
+git@cjennings.net:dwm.git
+git@cjennings.net:pinentry-dmenu.git
+git@cjennings.net:rsyncshot.git
+git@cjennings.net:st.git
+git@github.com:cjennings/emacs-wttrin.git
+https://github.com/d12frosted/elpa-mirror.git
+https://github.com/mirrors/emacs.git
+"
+
+for repo in $repos; do
+ dir=$(echo "$repo" | awk -F'[/:]' '{gsub(/.git/, "", $NF); print $NF}')
+ # Note on the above awk command:
+ # awk -F'[/:]': uses awk with a regex field delimiter that matches both : and /
+ # which will work with both ssh and http style URLs.
+ # '{gsub(/.git/, "", $NF); print $NF}: This removes the ".git" postfixes from the last field ($NF)
+ # which leaves only the repo name.
+
+ fullpath="$REPOS_HOME$dir"
+ if [ -d "$fullpath" ]; then
+ echo "Repository $dir exists at $fullpath, pulling..."
+ (cd "$fullpath" && git pull)
+ else
+ echo "Repository $dir doesn't exist at $fullpath, cloning..."
+ cd "$REPOS_HOME" && git clone --depth 1 "$repo" "$fullpath"
+ fi
+done