blob: 43f4a80ab2ab02c605359797ce6ef127f9155f7f (
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
45
46
47
48
49
|
#!/bin/sh
# forked from: https://github.com/rexim/dotfiles/blob/master/deploy.sh
SCRIPT_DIR="$( cd "$( dirname "$BASH_SOURCE[0]" )" && pwd )"
MANIFEST_FILE="MANIFEST"
symlink_file() {
filename="$SCRIPT_DIR/$1"
destination=$(echo "$HOME/$2/$1" | sed 's/\/\//\//g')
mkdir -p $(dirname "$destination")
if [ -L "$destination" ]; then
echo "info: updating $filename symlink"
rm -f "$destination" > /dev/null
ln -s "$filename" "$destination"
else
if [ -e "$destination" ]; then
echo "error: $destination exists but it's not a symlink. Please fix that manually" && return
else
ln -s "$filename" "$destination"
echo "info: $filename -> $destination"
fi
fi
}
deploy_manifest() {
echo "--- deploying ---"
for row in $(cat "$SCRIPT_DIR/$MANIFEST_FILE"); do
filename=$(echo $row | cut -d \| -f 1)
destination=$(echo $row | cut -d \| -f 2)
symlink_file $filename $destination
done
}
clean() {
echo "--- cleaning up ---"
for row in $(cat "$SCRIPT_DIR/$MANIFEST_FILE"); do
filename=$(echo $row | cut -d \| -f 1)
destination=$(echo $row | cut -d \| -f 2)
result=$(echo "$HOME/$destination/$filename" | sed 's/\/\//\//g')
rm -f "$result" > /dev/null
echo "info: removed $result symlink"
done
}
[ "$1" = "clean" ] && clean && exit
deploy_manifest
|