-
Notifications
You must be signed in to change notification settings - Fork 1
/
install
executable file
·66 lines (51 loc) · 1.45 KB
/
install
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/bin/bash -e
# This script creates symlinks from the home directory to any desired configs in ~/configs
########## Variables
dir=$(readlink -f `dirname $0`) # Change this to the location of this script
olddir=${dir}_old # old configs backup directory
locations="$dir/locations"
########## Functions
function indent {
echo ":: $@"
}
##########
# create configs_old in homedir
cat $locations | while read line; do
set -- $line
backup=$olddir/$1
if [ ! -e "$backup" ]; then
echo "Creating $backup for backup of any existing configs in ~"
mkdir -p $backup
fi
done
echo $dir
cd $dir
cat $locations | while read line; do
# Must be a way to simplify these three lines
set -- $line
source=$1
dest=$(eval echo $2)
indent "Linking files in '$source' to '$dest'"
for file in `ls -A $source`; do
link="$dest/$file"
real="$dir/$source/$file"
# Back up existing files if they exist
if [[ -e $link ]] && [[ ! -h $link ]]; then
echo "Backing up $file"
mv $link $olddir/$source/$file
fi
if [[ "`readlink -f "$link"`" != "$real" ]]; then
if [[ ! -e "$link" ]]; then
echo "Creating $file $link -> $real"
elif [[ -h "$link" ]]; then
echo "Updating $file $link -> $real"
fi
ln -sf $real $link
fi
done
done
echo ''
indent "Running post install hooks"
for hook in $(find $dir/hooks/post_install -type f -executable); do
$hook
done