This repository was archived by the owner on Jun 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfoo
More file actions
267 lines (231 loc) · 7.05 KB
/
foo
File metadata and controls
267 lines (231 loc) · 7.05 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
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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
#!/bin/bash
usage ()
{
cat > /dev/stderr << __EOF__
Usage: ./foo {admin|user} {install|uninstall|update}
The working directory MUST be the directory that contains this script.
If you run this script from any other directory, a velociraptor will
jump from the Windows registry and change all your passwords to
"Tr0ub4dor&3".
"admin" vs "user" refers to which batch file was originally executed.
Don't start mixing "admin" and "user".
__EOF__
exit 1
}
# Globals
# dependencies "git python make"
# self_mode "user" or "admin"; depends on $1
# setup_flags "--wait" or "-B"; depends on $1
# mkshortcut_flags none or "-A"; depends on $1
# anonymine_lnk "Anonymine.lnk"
# update_anonymine_lnk "Update Anonymine.lnk"
# uninstall_anonymine_lnk "Uninstall Anonymine.lnk"
ask ()
{
while true ; do
read -p "<<< $1? (yes/no): " answer
if [ -n "$(echo $answer | grep -E '^[Yy]([Ee][Ss])?$')" ]; then
return 0
fi
if [ -n "$(echo $answer | grep -E '^[Nn][Oo]?$')" ]; then
return 1
fi
done
}
error ()
{
while [ $# -gt 0 ]; do
echo "<<error>> $1" >&2
shift
done
}
fatal ()
{
while [ $# -gt 0 ]; do
echo "<<fatal>> $1" >&2
shift
done
echo 'Execution stopped due to fatal error.' >&2
# Terminal's gonna go poof!
while ! ask "Quit"; do
error "No is not an option"
done
exit 1
}
# Wrapper
cyg_setup ()
{
/setup.exe -q $setup_flags -R "$(cygpath --windows /)" $@
}
update ()
{
echo >>log; echo >>log; echo >>log; echo >>log; echo >>log; echo >>log;
echo "Updating anonymine..." >>log; date >>log;
cd anonymine || {
echo "FATAL: Cloned repo of Anonymine not found" >>log;
fatal "Cloned repo of Anonymine not found";
}
while true; do
# Update and log
{
git pull && ./configure -v && make && make install && break;
} >>../log 2>&1
# Not reached, hopefully
error "Failed to update"
ask "Fix manually" && {
less ../log;
echo "This is a new shell; Exit when you're done fixing.";
script -q -a ../log;
ask "Fixed it" && break;
}
ask "Retry" && continue
echo "Failed to update" >>../log
fatal "Failed to update"
done
cd ..
}
uninstall ()
{
# Failing to cd into anonymine, but succeeding to cd to ../ .....
(cd anonymine; make uninstall; cd ..)
# ..... caused really nasty trouble:
rm -rf anonymine
# Remove shortcuts:
# http://superuser.com/questions/86078/where-do-start-menu-all-programs-shortcuts-reside
home="$(cygpath --unix $USERPROFILE)"
directories=(
"/cygdrive/c/Documents and Settings/All Users/Start Menu/Programs/"
"$home/Start Menu/Programs/"
"/cygdrive/c/ProgramData/Microsoft/Windows/Start Menu/Programs/"
"$home/AppData/Roaming/Microsoft/Windows/Start Menu/Programs/"
"/cygdrive/c/Documents and Settings/All Users/Desktop"
"/cygdrive/c/Users/Public/Desktop/"
"$home/Desktop/"
)
files=(
"$anonymine_lnk"
"$update_anonymine_lnk"
"$uninstall_anonymine_lnk"
)
for directory in "${directories[@]}"; do
for file in "${files[@]}"; do
rm "$directory$file" 2> /dev/null
done
done
for dependency in $dependencies; do
ask "Uninstall $dependency" && cyg_setup -x "$dependency"
done
echo; echo; echo "You will have to uninstall Cygwin manually"
while ! ask "Quit"; do echo "No is not an option."; done
}
install ()
{
shortcut_wrap ()
{
# Args:
# {-P|-D} name cmd
# Invokes
# mkshortcut [-A] {-P|-D} -n <name> -a "-lc <command>" \
# -i <icon> /bin/bash.exe
# Command
# /bin/bash.exe -lc "<command>"
# -l flag needed for bash to set the PATH variable, etc
# Use `cd` to move into the working directory
#
mkshortcut $mkshortcut_flags "$1" -n "$2" -a "-lc '$3'" \
-i "$(pwd)/icon.ico" /bin/bash.exe
}
# Get configuration before doing time consuming work.
echo
echo "*****************************"
echo "* *"
echo "* Now for those questions *"
echo "* *"
echo "*****************************"
echo
shortcut_d=0
shortcut_m=0
maintenance_d=0
maintenance_m=0
ask "Desktop shortcut" && shortcut_d=1
ask "Menu shortcut" && shortcut_m=1
ask "Desktop shortcut for update and uninstall" && maintenance_d=1
ask "Menu shortcut for update and uninstall" && maintenance_m=1
echo
echo "*****************************"
echo "* *"
echo "* Installing.... *"
echo "* *"
echo "*****************************"
echo
# Start the time consuming work.
echo >> log; echo >> log; echo >> log; echo >> log; echo >> log
echo "Installing Anonymine..." >> log; date >> log
for dependency in $dependencies; do
cyg_setup -P "$dependency" 2>&1 | tee -a log
done
# This one is here for the convenience of the debuggers.
[ -d anonymine ] && ask "Remove old ./anonymine/" && rm -rf anonymine
git clone https://github.com/oskar-skog/anonymine.git || {
echo "Could not download Anonymine." >> log;
fatal "Could not download Anonymine.";
}
# update does ./configure && make && make install
update
# Create those shortcuts.
if [ $shortcut_d -ne 0 ]; then
shortcut_wrap -D "$anonymine_lnk" "anonymine"
fi
if [ $shortcut_m -ne 0 ]; then
shortcut_wrap -P "$anonymine_lnk" "anonymine"
fi
if [ $maintenance_d -ne 0 ]; then
shortcut_wrap -D "$update_anonymine_lnk" \
"cd \"$(pwd)\"; ./foo $self_mode update"
shortcut_wrap -D "$uninstall_anonymine_lnk" \
"cd \"$(pwd)\"; ./foo $self_mode uninstall"
fi
if [ $maintenance_m -ne 0 ]; then
shortcut_wrap -P "$update_anonymine_lnk" \
"cd \"$(pwd)\"; ./foo $self_mode update"
shortcut_wrap -P "$uninstall_anonymine_lnk" \
"cd \"$(pwd)\"; ./foo $self_mode uninstall"
fi
}
main ()
{
dependencies="git make python"
anonymine_lnk="Anonymine.lnk"
update_anonymine_lnk="Update Anonymine.lnk"
uninstall_anonymine_lnk="Uninstall Anonymine.lnk"
[ $# -ne 2 ] && usage
case "$1" in
user)
setup_flags="-B"
mkshortcut_flags=""
self_mode="user"
;;
admin)
setup_flags="--wait"
mkshortcut_flags="-A"
self_mode="admin"
;;
*)
usage
;;
esac
case "$2" in
install)
install
;;
update)
update
;;
uninstall)
uninstall
;;
*)
usage
esac
}
main "$@"