-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsetup-user-config.sh
executable file
·101 lines (79 loc) · 3.14 KB
/
setup-user-config.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
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/bin/sh
# Check for dependencies
command -v readlink >/dev/null 2>&1 || {
echo >&2 "readlink is required for install.";
echo >&2 "Consider manually adding symlinks to the config files you want.";
echo >&2 "Exiting.";
exit 1;
}
backupdir='replaced';
mergeddir='merged';
# Find home directory
installdir=$HOME;
[ ! -d $installdir ] && installdir='~';
[ ! -d $installdir ] && installdir='..';
[ ! -d $installdir ] && echo "can't find home directory" && exit 0;
# Find this directory
scriptpath=$(readlink -f $0);
projectdir=`dirname "$scriptpath"`
[ ! -d $projectdir ] && echo "can't get current directory" && exit 0;
backupdir=$projectdir/$backupdir;
mergeddir=$projectdir/$mergeddir;
installfile()
{
echo " - == Installing $1";
# Get filenames
localname=$projectdir/$1;
backupname=$backupdir/$1;
source=$3;
# If a different option was supplied for install name, use that
if [ ! -z $2 ]; then
installname=$installdir/$2;
else
installname=$installdir/$1;
fi
link=`readlink -f $installname`;
# Doesn't exist, create symlink (simplest)
if ! [ -e $installname ]; then
ln -s $localname $installname && echo " - Created symlink to .shellconfig";
# If one of our links
elif [ -L $installname ] && [ "${link#*$projectdir}" != "$link" ]; then
# Remove old link and create new one
rm $installname && echo " - Removed old link to .shellconfig";
ln -s $localname $installname && echo " - Created symlink to merged file";
# If we're to source it
elif [ -e $installname ] && [ $source ]; then
source_line="source $localname; #nottrobin-shellconfig"
if ! grep -q "${source_line}" $installname; then
echo ${source_line} >> $installname && echo " - Sourced from .shellconfig";
else
echo " - Already sourced"
fi
# Exists but not sourceable
elif [ -e $installname ]; then
# Make directories if they don't exist
[ ! -e $backupdir ] && mkdir $backupdir && echo " - Made backup directory";
# Back up the existing file
cp -r $installname $backupname && echo " - Backed up original file";
# Remove original file
rm -r $installname && echo " - Removed original file";
# Link to our version
ln -s $localname $installname && echo " - Created symlink to our file";
fi
}
# Setup normal files
for filename in '.tmux.conf' '.vim' '.bazaar'; do
installfile $filename && echo " - == Installed $filename";
done
# Source bash files
for filename in '.bashrc'; do
installfile $filename $filename true && echo " - == Installed $filename";
done
# Setup global git config (needs special name)
installfile '.globalgitconfig' '.gitconfig' && echo " - == Installed .gitconfig";
# Setup global git config (needs special name)
if [ -d $installdir/.config/sublime-text-3/Packages ]; then
mkdir -p $installdir/.config/sublime-text-3/Packages/User
installfile '.user-preferences.sublime-settings' '.config/sublime-text-3/Packages/User/Preferences.sublime-settings' && echo " - == Installed sublime user settings";
fi
echo "~~ Setting applied. Restart your terminal to see the changes. ~~"