summaryrefslogtreecommitdiff
path: root/deploy.sh
blob: 3b4afa053bff8e1869c60416f973469d3b8023ce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/bin/sh

# forked from: https://github.com/rexim/dotfiles/blob/master/deploy.sh

SCRIPT_DIR="$( cd "$( dirname "$BASH_SOURCE[0]" )" && pwd )"

symlink_file() {
	filename="$SCRIPT_DIR/$1"
	destination="$HOME/$2/$1"

	mkdir -p $(dirname "$destination")

	if [ ! -L "$destination" ]; then
		if [ -e "$destination" ]; then
			echo "[ERROR] $destination exists but it's not a symlink. Please fix that manually" && exit 1
		else
			ln -s "$filename" "$destination"
			echo "[OK] $filename -> $destination"
		fi
	else
		echo "[WARNING] $filename already symlinked"
	fi
}

deploy_manifest() {
	for row in $(cat $SCRIPT_DIR/$1); do
		filename=$(echo $row | cut -d \| -f 1)
		operation=$(echo $row | cut -d \| -f 2)
		destination=$(echo $row | cut -d \| -f 3)

		case $operation in
			symlink)
				symlink_file $filename $destination
				;;

			*)
				echo "[WARNING] Unknown operation $operation. Skipping..."
				;;
		esac
	done
}

echo "--- Configs ---"
deploy_manifest MANIFEST