-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·41 lines (32 loc) · 1.19 KB
/
install.sh
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
#!/usr/bin/env bash
SCRIPT=$(basename "$0")
SOURCEDIR=$(pwd)
[ -z "$1" ] && TARGETDIR="$HOME" || TARGETDIR="${1%\/}"
for directory in $(find . ! -path . ! -path "*\/.*" -type d | sed 's/^\.\///'); do
destination="$TARGETDIR/.$directory"
if [ -d $destination -o -L $destination ]; then
#echo "skip creating directory, '$destination' already exists"
continue
fi
mkdir -p $destination
#echo "directory '$destination' created"
done
for filerc in $(find . ! -path "*\/.*" ! -name "$SCRIPT" ! -iname "*readme*" -type f | sed 's/^\.\///'); do
destination="$TARGETDIR/.$filerc"
source="$SOURCEDIR/$filerc"
if [ -L $destination -a "$(readlink -f $destination)" -ef $source ]; then
#echo "$destination is already symlinked"
continue
fi
if [ -f $destination -a ! -L $destination ]; then
echo "found existing file $destination, creating backup in $destination.orig"
cp $destination $destination.orig
rm $destination
fi
if [ -L $destination ]; then
#echo "replace already exist symlink $destination"
rm $destination
fi
#echo "linked $source -> $destination"
ln -s $source $destination
done