-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·93 lines (83 loc) · 3 KB
/
install.sh
File metadata and controls
executable file
·93 lines (83 loc) · 3 KB
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
#!/bin/bash
set -e
# config sources and destinations parallel arrays
s1="config/.bashrc config/.vimrc config/.gitconfig config/.ctags config/ssh_config config/.gitignore_global config/.xscreensaver config/.tmux.conf config/.bcrc config/.inputrc config/.xsessionrc config/awk/date.awk config/awk/reduce.awk config/awk/sumcols.awk config/awk/stats.awk config/awk/groupstats.awk config/awk/hist.awk config/dunstrc"
d1="$HOME/.bashrc $HOME/.vimrc $HOME/.gitconfig $HOME/.ctags $HOME/.ssh/config $HOME/.gitignore_global $HOME/.xscreensaver $HOME/.tmux.conf $HOME/.bcrc $HOME/.inputrc $HOME/.xsessionrc $HOME/.awk/date.awk $HOME/.awk/reduce.awk $HOME/.awk/sumcols.awk $HOME/.awk/stats.awk $HOME/.awk/groupstats.awk $HOME/.awk/hist.awk $HOME/.config/dunst/dunstrc"
linkDestinationsToSources() {
warning=
if [[ -z $1 || -z $2 ]]
then
echo "need sources destinations! s: $1 d: $2"
exit 1
fi
sources=( `echo "$1"` )
destinations=( `echo "$2"` )
count=${#sources[@]}
if [ $count -ne ${#destinations[@]} ]
then
echo "UH OH, destinations and sources don't match length! quitting"
echo ${sources[@]}
echo ${destinations[@]}
echo $count ${#destinations[@]}
exit 1
fi
currDir=`pwd`
for ((i=0; i<count; i+=1))
do
s=$currDir/${sources[$i]}
if [ ! -e $s ]
then
echo "UH OH, no file $s in environment! skipping..."
warning=1
continue
fi
d=${destinations[$i]}
if [ ! -e $d ] && [ -h $d ]; then
rm $d
fi
echo -n "$d"
if [ -e $d ]; then
if [ $d -ef $s ]; then
echo " already linked to environment"
else
echo " already exists! skipping. just rm it and run this again."
warning=1
fi
else
#first make sure we have the relevant directory
mkdir --parents $(dirname "$d")
#then create a symlink to our config file so it stays under version control
ln -s $s $d
echo " linked from $d"
fi
done
}
#first link the configs
echo "linking configs..."
linkDestinationsToSources "$s1" "$d1"
if [ ! -z "$warning" ]; then echo ""; echo "There are warnings above!"; fi
#then link the executables to ~/bin
#make sure ~/bin exists
if [[ ! -d ~/bin ]]
then
if [[ -e ~/bin ]]
then
echo "UH OH, ~/bin exists, but isn't a directory!"
exit 1
else
echo "creating ~/bin..."
mkdir ~/bin
fi
fi
s=`find bin/ -executable -type f`
s_array=( `echo "$s"` )
d=""
count=${#s_array[@]}
for ((i=0; i<count; i+=1))
do
d="$d $HOME/${s_array[$i]}"
done
echo ""
echo "linking binaries..."
linkDestinationsToSources "$s" "$d"
if [ ! -z "$warning" ]; then echo ""; echo "There are warnings above!"; fi