aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2023-07-25 22:22:43 +0200
committerEgor Tensin <Egor.Tensin@gmail.com>2023-07-25 22:22:43 +0200
commit2c881cb668293b4a7c3c8777a03165c919914f60 (patch)
tree8d6de338bf4141ea6ebbf482a1b655e4db0f1e81
parentREADME: update (diff)
downloadlinux-home-2c881cb668293b4a7c3c8777a03165c919914f60.tar.gz
linux-home-2c881cb668293b4a7c3c8777a03165c919914f60.zip
update.sh: refactoring
Diffstat (limited to '')
-rwxr-xr-xupdate.sh56
1 files changed, 47 insertions, 9 deletions
diff --git a/update.sh b/update.sh
index 597070f..b3bbe05 100755
--- a/update.sh
+++ b/update.sh
@@ -1,10 +1,5 @@
#!/usr/bin/env bash
-# Some utilities (for example, ssh) fix too relaxed file permissions
-# automatically. Others (GHCi is the reason this script exists) just spit out a
-# warning and ignore such files. This script simply removes the write
-# permission for everybody except myself for every file in this repository.
-
set -o errexit -o nounset -o pipefail
shopt -s inherit_errexit 2> /dev/null || true
shopt -s lastpipe
@@ -13,8 +8,51 @@ script_dir="$( dirname -- "${BASH_SOURCE[0]}" )"
script_dir="$( cd -- "$script_dir" && pwd )"
readonly script_dir
-export PATH="$script_dir/../config-links:$PATH"
+repo_dir=''
+
+cleanup_repo() {
+ if [ -n "$repo_dir" ]; then
+ echo "Cleaning up directory: $repo_dir"
+ rm -rf -- "$repo_dir"
+ fi
+}
+
+config_links_in_path() {
+ # Make sure the links-* utils are available.
+
+ if command -v links-update &> /dev/null; then
+ return 0
+ fi
+
+ # This is a common directory to clone config-links for me.
+ if [ -d "$script_dir/../config-links" ]; then
+ export PATH="$script_dir/../config-links:$PATH"
+ return 0
+ fi
+
+ # If config-links is unavailable, clone it.
+ readonly repo_url=https://github.com/egor-tensin/config-links.git
+ trap cleanup_repo EXIT
+ repo_dir="$( mktemp -d )"
+
+ git clone -q -- "$repo_url" "$repo_dir"
+ export PATH="$repo_dir:$PATH"
+}
+
+links_update() {
+ cd -- "$script_dir"
+ links-update
+
+ # Some utilities (for example, ssh) fix too relaxed file permissions
+ # automatically. Others (GHCi is the reason this exists) just spit out a
+ # warning and ignore such files. This script simply removes the write
+ # permission for everybody except myself for every file in this repository.
+ links-chmod go-w
+}
+
+main() {
+ config_links_in_path
+ links_update
+}
-cd -- "$script_dir"
-links-update
-links-chmod go-w
+main