diff options
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." |
