diff options
| author | Mosder <xmosder12@gmail.com> | 2026-06-10 03:23:10 +0200 |
|---|---|---|
| committer | Mosder <xmosder12@gmail.com> | 2026-06-10 03:23:10 +0200 |
| commit | 476fafe75f23802ea9a28ed3c00a245c7db13f91 (patch) | |
| tree | 5a240c56b16020723a06dc17a136b3f2efc93a1b /update_from_disk.sh | |
| parent | 1f2824b912b22a687fb0f1c56f82198128bef1ca (diff) | |
added shell scripts to load config from repo and update repo from disk
Diffstat (limited to 'update_from_disk.sh')
| -rwxr-xr-x | update_from_disk.sh | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/update_from_disk.sh b/update_from_disk.sh new file mode 100755 index 0000000..c0e9d55 --- /dev/null +++ b/update_from_disk.sh @@ -0,0 +1,45 @@ +#!/usr/bin/env bash + +# Ensure good argument is passed +if [[ $# -ne 1 ]]; then + echo "Usage: $0 (desktop | laptop)" + exit 1 +elif [[ "$1" != "laptop" && "$1" != "desktop" ]]; then + echo "Target must be \"laptop\" or \"desktop\"" + exit 1 +fi + +TARGET=$1 +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" + +copy_file() { + local src="$1" + local dest="$2" + echo "cp -a $src $dest" + if ! cp -a "$src" "$dest" 2>/dev/null; then + echo "Failed - using sudo..." + sudo cp -a "$src" "$dest" + fi +} + +update_repo() { + local repo_dir="$1" + cd "$repo_dir" + + find . -mindepth 1 | while read -r node; do + # ./node -> /node + src="${node#.}" + + if [[ -f "$src" ]]; then + copy_file "$src" "$node" + elif [[ ! -d "$src" ]]; then + echo "Skipped missing: $src" + fi + done +} + +update_repo "$SCRIPT_DIR/common" +update_repo "$SCRIPT_DIR/$TARGET" + +cd "$SCRIPT_DIR" +echo "Done." |
