-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsetupenv
executable file
·149 lines (122 loc) · 2.65 KB
/
setupenv
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#!/usr/bin/env bash
show_usage ()
{
echo
echo "Links dotfiles to your $HOME directory"
echo
echo "USAGE: $0 [-f] [--force]"
echo
echo " force Prevents confirmation prompt to override existing files"
echo
[ ! -z "$1" ] && exit $1
}
link_dotfiles ()
{
local FILE
if [ -z $1 ]
then
return
fi
pushd $1 > /dev/null
for FILE in .*
do
if [[ "$FILE" == "." ]]
then
continue
fi
if [[ "$FILE" == ".." ]]
then
continue
fi
if [[ "$FILE" == ".git" ]]
then
continue
fi
if [[ "$FILE" == ".gitmodules" ]]
then
continue
fi
if [[ "$FILE" == ".ssh" ]]
then
# make our ~/.ssh if it doesn't exist
mkdir -p $HOME/.ssh
chmod 700 $HOME/.ssh
# setup proper permissions
[[ -e $HOME/.ssh/id_rsa ]] && chmod 600 $HOME/.ssh/id_rsa
[[ -e $HOME/.ssh/id_ra.pub ]] && chmod 644 ~/.ssh/id_rsa.pub
touch $HOME/.ssh/authorized_keys
chmod 644 $HOME/.ssh/authorized_keys
touch $HOME/.ssh/known_hosts
chmod 644 $HOME/.ssh/known_hosts
# copy any files
cp -rfv $PWD/$FILE/* $HOME/$FILE/
continue
fi
if [ -e "$FILE" ]
then
if [ -d "$HOME/$FILE" ]
then
rm -rf $HOME/$FILE
fi
ln -fsv $PWD/$FILE $HOME/$FILE
fi
done
popd > /dev/null
}
if [ "$1" == "--help" ]
then
show_usage 64
fi;
if [[ "$1" != "--force" && "$1" != "-f" ]]
then
echo
read -p "This may overwrite existing files in your home directory. Are you sure? (Y/n) " -n 1
echo
case $REPLY in
"[Nn]*")
exit 64
;;
esac
fi
# Link dotfiles from this dir
link_dotfiles ${PWD}
# Copy bin files from this dir
if [ -d "./bin" ]
then
cp -rfv ${PWD}/bin $HOME
fi
# Source platform specific profile
UNAME=$(uname)
case $UNAME in
"")
;;
"Darwin")
PLATFORM=osx
;;
"CYGWIN"*)
PLATFORM=windows
;;
"MINGW"*)
PLATFORM=windows
;;
*)
PLATFORM="$(tr [A-Z] [a-z] <<< "$UNAME")"
;;
esac
if [ -d "$PLATFORM" ]
then
pushd $PLATFORM > /dev/null
# Link dotfiles from platform dir
link_dotfiles ${PWD}
# Run setupenv if exists
if [ -x "./setupenv" ]
then
./setupenv
fi
# Copy bin files from platform dir
if [ -d "./bin" ]
then
cp -rfv ${PWD}/bin $HOME
fi
popd > /dev/null
fi