-
Notifications
You must be signed in to change notification settings - Fork 0
/
vchsetup
executable file
·226 lines (198 loc) · 6.63 KB
/
vchsetup
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
#!/bin/bash
set -o pipefail
PROGNAME=$(basename ${0})
PROGDIR=$(dirname ${0})
VERSION='0.0.1'
echo ''
echo "vch setup and update script (version: $VERSION)"
echo ''
# rcfile
. ${PROGDIR}/config.sh
if [ -e ${PROGDIR}/${PROGNAME}.local ]; then
. ${PROGDIR}/${PROGNAME}.local
elif [ -e ~/.${PROGNAME} ]; then
. ~/.${PROGNAME}
fi
/bin/echo -n "OS type: "
case "$OSTYPE" in
darwin*) echo -e "\033[32mOSX\033[0m" ; export OSVER='OSX' ; export INSTYPE='brew' ;;
linux*) echo -e "\033[32mLINUX\033[0m" ; export OSVER='LINUX' ; export INSTYPE='manual' ;;
*) echo -e "unknown: \033[31m$OSTYPE\033[0m" ; export OSVER='unknown' ; export INSTYPE='manual' ;;
esac
echo "Install Type: $INSTYPE"
echo
APPLIST='myrepos vcsh git-crypt'
VCHDIR="${HOME}/.vch"
MRGIT="${VCHDIR}/myrepos"
MRBRANCH='master'
VCSHGIT="${VCHDIR}/vcsh"
VCSHBRANCH='release'
GITCRYPT="${VCHDIR}/git-crypt"
GITCRYPTBRANCH='master'
DESTDIR="${VCHDIR}"
CONFDIR="${HOME}/.config"
MRDIR="${CONFDIR}/mr"
VCSHDIR="${CONFDIR}/vcsh"
SHORTNAME=$(hostname -s)
if [ $OSVER == 'OSX' ]; then
read -e -p "Override install type $INSTYPE? [yN] " override
case $override in
[yY]*)
echo "Overriding to manual"
INSTYPE='manual'
;;
*)
echo "Not changing install type"
;;
esac
fi
read -e -p "Enter your myrepos URI [$myrepos]: " uri
export myrepos_uri=${uri:-$myrepos}
if [ $INSTYPE == 'manual' ]; then
failed=0
# vcsh uses to make doc
echo -ne "\033[32mChecking for ronn gem -> \033[0m "
if ! hash ronn 2>/dev/null; then
echo -e "\033[31mMISSING\033[0m"
failed=1
else
echo -e "\033[93mFOUND\033[0m"
fi
VCSH_PERL_MOD=" \
Shell::Command \
Test::Most \
"
for MOD in $VCSH_PERL_MOD; do
echo -ne "\033[32mChecking for perl module '${MOD}' -> \033[0m "
perl -e "use ${MOD};" > /dev/null 2>&1
xc=$?;
if [ $xc -eq 0 ]; then
echo -e "\033[93mFOUND\033[0m"
else
echo -e "\033[31mMISSING\033[0m"
failed=1
fi
done
if [ $failed -ne 0 ]; then exit 128; fi
fi
if [[ $OSVER == unknown ]]; then
echo "Don't know what to do; exiting, badly."
exit 1
elif [[ $INSTYPE == brew ]]; then
echo -e "\033[32mUpdate Homebrew\033[0m"
brew update
xc=$?; if [ $xc -ne 0 ]; then exit $xc; fi
echo
for APP in $APPLIST; do
echo -e "\033[32mChecking for $APP\033[0m"
brew ls $APP > /dev/null 2>&1
xc=$?
if [ $xc -ne 0 ]; then
echo -e "\033[93mInstalling $APP\033[0m"
brew install $APP
else
echo -e "\033[96mAttempting to upgrade $APP\033[0m"
brew upgrade $APP
fi
echo
done
elif [[ $INSTYPE == manual ]]; then
echo -e "\033[32mChecking local directories\033[0m"
mkdir -vp ${VCHDIR} ${MRGIT} ${VCSHGIT} ${DESTDIR}
echo
echo -e "\033[32mChecking for myrepos\033[0m"
if [ ! -d ${MRGIT}/.git ]; then
echo -e "\033[94mInstalling GIT repo of myrepos\033[0m"
git clone [email protected]:joeyh/myrepos.git ${MRGIT}
else
echo -e "\033[96mUpdating GIT repo of myrepos\033[0m"
git --work-tree=${MRGIT} --git-dir=${MRGIT}/.git remote prune origin
git --work-tree=${MRGIT} --git-dir=${MRGIT}/.git fetch --all
git --work-tree=${MRGIT} --git-dir=${MRGIT}/.git fetch --tags
git --work-tree=${MRGIT} --git-dir=${MRGIT}/.git pull
fi
git --work-tree=${MRGIT} --git-dir=${MRGIT}/.git checkout ${MRBRANCH}
echo -e "\033[93mInstalling myrepos\033[0m"
make -C ${MRGIT} DESTDIR=${DESTDIR} install
echo
echo -e "\033[32mChecking for vcsh\033[0m"
if [ ! -d ${VCSHGIT}/.git ]; then
echo -e "\033[94mInstalling GIT repo of vcsh\033[0m"
git clone [email protected]:RichiH/vcsh.git ${VCSHGIT}
else
echo -e "\033[96mUpdating GIT repo of vcsh\033[0m"
git --work-tree=${VCSHGIT} --git-dir=${VCSHGIT}/.git remote prune origin
git --work-tree=${VCSHGIT} --git-dir=${VCSHGIT}/.git fetch --all
git --work-tree=${VCSHGIT} --git-dir=${VCSHGIT}/.git fetch --tags
git --work-tree=${VCSHGIT} --git-dir=${VCSHGIT}/.git pull
fi
git --work-tree=${VCSHGIT} --git-dir=${VCSHGIT}/.git checkout ${VCSHBRANCH}
echo -e "\033[93mInstalling vcsh\033[0m"
make -C ${VCSHGIT} DESTDIR=${DESTDIR} install
echo
echo -e "\033[32mChecking for git-crypt\033[0m"
if [ ! -d ${GITCRYPT}/.git ]; then
echo -e "\033[94mInstalling GIT repo of git-crypt\033[0m"
git clone [email protected]:AGWA/git-crypt.git ${GITCRYPT}
else
echo -e "\033[95mCleaning GIT repo git-crypt\033[0m"
make -C ${GITCRYPT} DESTDIR=${DESTDIR} PREFIX=/usr clean
echo -e "\033[96mUpdating GIT repo of git-crypt\033[0m"
git --work-tree=${GITCRYPT} --git-dir=${GITCRYPT}/.git remote prune origin
git --work-tree=${GITCRYPT} --git-dir=${GITCRYPT}/.git fetch --all
git --work-tree=${GITCRYPT} --git-dir=${GITCRYPT}/.git fetch --tags
git --work-tree=${GITCRYPT} --git-dir=${GITCRYPT}/.git pull
fi
git --work-tree=${GITCRYPT} --git-dir=${GITCRYPT}/.git checkout ${GITCRYPTBRANCH}
echo -e "\033[95mBuilding git-crypt\033[0m"
make -C ${GITCRYPT} DESTDIR=${DESTDIR} PREFIX=/usr
echo -e "\033[93mInstalling git-crypt\033[0m"
make -C ${GITCRYPT} DESTDIR=${DESTDIR} PREFIX=/usr install
echo
export PATH="${HOME}/.vch/usr/bin:$path"
fi
echo ; echo
# IMP - Add key collection/creation
if [ -f ${HOME}/.ssh/id_rsa ] || [ -f ${HOME}/.ssh/id_dsa ]; then
if [ -f ${HOME}/.ssh/id_rsa.pub ]; then
KEY=$(/bin/cat ${HOME}/.ssh/id_rsa.pub)
elif [ -f ${HOME}/.ssh/id_dsa.pub ]; then
KEY=$(/bin/cat ${HOME}/.ssh/id_dsa.pub)
else
echo "berp"
exit 128
fi
else
if [ ! -d ${HOME}/.ssh ]; then mkdir ${HOME}/.ssh; fi
/usr/bin/ssh-keygen -P '' -f ${HOME}/.ssh/id_rsa
KEY=$(/bin/cat ${HOME}/.ssh/id_rsa.pub)
fi
echo -e '\033[32mCurrent public SSH key\033[0m'
echo; echo $KEY; echo
read -p 'Does it exist in the GIT services configurations?'
# IMP - Add repo collection/creation
# vcsh clone ${myrepos_uri}
# touch ${MRDIR}/hosts.d/${SHORTNAME}
# cd ${MRDIR}/config.d && ln -s ../hosts.d/${SHORTNAME} host
# vcsh mr add ${MRDIR}/hosts.d/${SHORTNAME}
# vcsh mr commit ${MRDIR}/hosts.d/${SHORTNAME}
echo ; echo
if [[ $OSTYPE == darwin* ]]; then
if [ $SHELL == '/bin/tcsh' ]; then
echo 'rehash'
elif [ $SHELL == '/bin/bash' ]; then
echo
else
echo "berp"
fi
elif [[ $OSTYPE == linux* ]]; then
if [ $SHELL == '/bin/tcsh' ]; then
echo 'set path = ( ${HOME}/.vch/usr/bin $path )'
echo 'rehash'
elif [ $SHELL == '/bin/bash' ]; then
echo 'export PATH="${HOME}/.vch/usr/bin:$path"'
else
echo "berp"
fi
fi
echo ; echo