-
Notifications
You must be signed in to change notification settings - Fork 0
/
get-hunix.sh
executable file
·253 lines (221 loc) · 5.48 KB
/
get-hunix.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
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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
#!/bin/bash
#
# .hunix/
# |-- bin
# `-- lib
# .local/
# |-- bin -> ~/.hunix/bin
# |-- etc
# | `-- archive
# |-- lib -> ~/.hunix/lib
# |-- log
# `-- opt
#
pathadd() {
if [ -d "$1" ] && [[ ":$PATH:" != *":$1:"* ]]; then
PATH="${PATH:+"$PATH:"}$1"
fi
}
BIN=${HOME}/.local/bin/
add_gitignore () {
grep -qxF $1 ${BIN}.gitignore || echo "$1" >> ${BIN}.gitignore
}
cd ${HOME}
if [ -d "${HOME}/.hunix" ] ; then
echo "hunix is already installed"
echo " nuke and pave with get-hunix.sh nuke"
if [[ "nuke" == "$1" ]]; then
echo "nukeing hunix install..."
rm -rf .hunix .yadm .config/yadm .local/bin .local/lib .local/etc /tmp/tmp_unzip* .emacs-site-lisp .bash_aliases .bash_profile .emacs .tmux.conf
fi
exit 1
fi
# base dependencies
if which curl > /dev/null 2>&1 ; then
echo "curl ok"
else
echo "installing curl..."
sudo apt-get install curl
fi
if which git > /dev/null 2>&1 ; then
echo "git ok"
else
echo "installing git..."
sudo apt-get install git
fi
# ensure giant rsa keys
if [ ! -f "${HOME}/.ssh/id_rsa.pub" ]; then
echo "generating big rsa key"
mkdir ${HOME}/.ssh 2>/dev/null
ssh-keygen -t rsa -b 4096 -f ${HOME}/.ssh/id_rsa -q -N ""
chmod 700 ${HOME}/.ssh
chmod 600 ${HOME}/.ssh/*
fi
echo ""
echo -n "Are you Heow? (y/n) "
read ISHUBERT
# am I heow?
if [ "$ISHUBERT" == "y" ]; then
echo 'foo' | base64 --decode > ${HOME}/.ssh/github-access-2021
chmod 600 ${HOME}/.ssh/github-access-2021
GIT_SSH_COMMAND="ssh -i ${HOME}/.ssh/github-access-2021" git clone [email protected]:heow/hunix.git .hunix
else
git clone https://github.com/heow/hunix.git .hunix
fi
# create and link to .local
mkdir -p ${HOME}/.local/opt 2>/dev/null
mkdir -p ${HOME}/.local/log 2>/dev/null
ln -s ${HOME}/.hunix/bin ${HOME}/.local/
ln -s ${HOME}/.hunix/lib ${HOME}/.local/
touch ${BIN}/.gitignore
# add self to bin/.gitignore, it's only for automation
add_gitignore .gitignore
pathadd ${HOME}/.local/bin
export PATH
if [ "$ISHUBERT" == "y" ]; then
echo 'foo' | base64 --decode > ${HOME}/.ssh/yadm-access-2021
chmod 600 ${HOME}/.ssh/yadm-access-2021
# yadm
if which yadm > /dev/null 2>&1 ; then
echo "yadm ok"
else
echo "installing yadm..."
sudo apt-get install yadm
fi
echo "make backward compatible with old yadm"
mkdir -p ${HOME}/.config/yadm
ln -s ${HOME}/.config/yadm ${HOME}/.yadm
echo "cloning yadm..."
GIT_SSH_COMMAND="ssh -i ${HOME}/.ssh/yadm-access-2021" yadm clone [email protected]:heow/yadm.git
# add overlayed yadm files from ~/.local/bin to .gitignore
add_gitignore msg
add_gitignore sync-with-cloud.sh
echo -n "Decrypt YADM secrets? (y/n) "
read YN
if [ "$YN" == "y" ]; then
# dependency
if which gpg > /dev/null 2>&1 ; then
echo "gpg ok"
else
sudo apt-get install gpg
fi
yadm decrypt
fi
fi
echo ""
echo -n "Install large x86 binaries? (y/n) "
read YN
if [ "$YN" == "y" ]; then
echo "installing..."
else
exit
fi
if which rclone > /dev/null 2>&1 ; then
echo "rclone ok"
else
echo "installing rclone..."
OS="$(uname)"
case $OS in
Linux)
OS='linux'
;;
FreeBSD)
OS='freebsd'
;;
NetBSD)
OS='netbsd'
;;
OpenBSD)
OS='openbsd'
;;
Darwin)
OS='osx'
;;
SunOS)
OS='solaris'
echo 'OS not supported'
exit 2
;;
*)
echo 'OS not supported'
exit 2
;;
esac
OS_type="$(uname -m)"
case "$OS_type" in
x86_64|amd64)
OS_type='amd64'
;;
i?86|x86)
OS_type='386'
;;
aarch64|arm64)
OS_type='arm64'
;;
arm*)
OS_type='arm'
;;
*)
echo 'OS type not supported'
exit 2
;;
esac
download_link="https://downloads.rclone.org/rclone-current-${OS}-${OS_type}.zip"
rclone_zip="rclone-current-${OS}-${OS_type}.zip"
curl -OfsS "$download_link"
unzip_dir="/tmp/tmp_unzip_dir_for_rclone"
mkdir "$unzip_dir"
unzip -a "$rclone_zip" -d "$unzip_dir"
pushd $unzip_dir/*
mv rclone ~/.local/bin/
popd
add_gitignore rclone
fi
echo "logseq (100MB)"
curl https://github.com/logseq/logseq/releases/download/0.4.4/logseq-linux-x64-0.4.4.AppImage --output ${BIN}/logseq
chmod +x ${BIN}/logseq
add_gitignore logseq
echo "babashka (77MB)"
pushd /tmp
curl -sLO https://raw.githubusercontent.com/babashka/babashka/master/install
/bin/bash ./install --dir ${BIN} --static
rm ./install
rm ${BIN}/bb.old 2>/dev/null
add_gitignore bb
popd
echo "ngrok (33MB)"
pushd /tmp
curl https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip -o ngrok.zip
unzip ngrok.zip
mv ngrok ${BIN}/ngrok
rm ngrok-stable-linux-amd64.zip
add_gitignore ngrok
popd
exit
#
# pre-yadm logic
#
echo ""
echo "Linking hostfiles to $HOME directory, which system?"
echo "(type in the name or 'all')"
ls -1 ./etc/host-confs
read SYSTYPE
if [ "$SYSTYPE" == "all" ]; then
SYSTYPE=`ls -1 ./etc/host-confs`
fi
for SYS in $SYSTYPE; do
cd $HOME/.hunix/etc/host-confs >> /dev/null 2>&1
cd ./$SYS/dotfiles-home
echo ""
echo "$SYS files and directories:"
ls -pd .* | grep -v "\./"
echo -n "copy or link the above files to $HOME? (cp/ln) "
read CPLN
if [ "$CPLN" == "ln" ]; then
echo "linking..."
~/.hunix/bin/ln2home.sh
else
echo "copying..."
~/.hunix/bin/cp2home.sh
fi
done