forked from sonick13/PerlProjects
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cheater-installer
180 lines (157 loc) · 4.6 KB
/
cheater-installer
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
#!/bin/sh
#cito M:755 O:0 G:0 T:/usr/bin/cheater-installer
#------------------------------------------------------------------------------
# Project Name - PerlProjects/source/cheater/cheater-installer
# Started On - Tue 24 Nov 03:32:18 GMT 2020
# Last Change - Sat 28 Nov 15:08:25 GMT 2020
# Author E-Mail - [email protected]
# Author GitHub - https://github.com/terminalforlife
#------------------------------------------------------------------------------
# Simple, but pretty and mindful Bourne Shell installer for Cheater.
#
# To use this installer, you can either:
#
# Clone the repository, using git(1) command.
#
# OR
#
# Download the archive of it directly from GitHub, then extract its contents.
#
# Since this installer just fetches from GitHub, you needn't actually download
# the entire PerlProjects repository to install it; only the installer.
#
# If you want a HOME-only installation, you'll have to either use Cito, or
# otherwise install it manually, but you may miss out on a lot of features.
#
# NOTE: Due to changes in BASH 4.4, running this therein will spit out errors.
#
# Dependencies:
#
# coreutils (>= 8.25-2)
# curl (>= 7.47.0-1) | wget (>= 1.17.1-1)
#------------------------------------------------------------------------------
if command -v curl 1> /dev/null 2>&1; then
DLCMD='curl -so'
elif command -v wget 1> /dev/null 2>&1; then
DLCMD='wget -qO'
else
printf "ERROR: Neither 'wget' nor 'curl' are available.\n" 1>&2
exit 1
fi
if [ `id -u` -ne 0 ]; then
printf "ERROR: Root access is required for system-wide changes.\n" 1>&2
exit 1
fi
printf 'Install latest version of Cheater? [Y/N] '
read Answer
case $Answer in
[Yy]|[Yy][Ee][Ss])
printf 'Continuing with installation.\n' ;;
[Nn]|[Nn][Oo])
printf 'Abandoning installation.\n'
exit 0 ;;
*)
printf 'ERROR: Invalid response -- quitting.\n' 1>&2
exit 2 ;;
esac
LogFile='/tmp/cheater-installer.log'
[ -f "$LogFile" ] || 1> "$LogFile"
chmod 644 "$LogFile"
TmpDir=`mktemp -d --suffix '_tfl'`
URL='https://raw.githubusercontent.com/terminalforlife'
URL="$URL/PerlProjects/master/source/cheater"
SigHandler(){
Sig=$?
printf 'Cleaning up temporary files:\n'
printf '* Removing '%s' ... ' "$TmpDir"
ErrCount=0
if rm -r "$TmpDir" 2>> "$LogFile"; then
printf '\033[32m[OK]\033[0m\n'
else
printf '\033[31m[ERR]\033[0m\n'
fi
if [ -s "$LogFile" ]; then
printf "Done! -- errors logged in: '${LogFile#$HOME}'\n"
else
printf 'Done!\n'
fi
exit $Sig
}
trap SigHandler EXIT INT QUIT ABRT TERM
printf 'Fetching files from GitHub:\n'
ErrCount=0
for File in\
\
'completions' 'cheater' 'cheater.1.gz' 'excluded_lines'
do
printf "* Downloading '%s' ... " "$File"
if $DLCMD "$TmpDir/$File" "$URL/$File" 2>> "$LogFile"; then
printf '\033[32m[OK]\033[0m\n'
printf '* Verifying file contents ... '
Contents=`< "$TmpDir/$File"`
if [ "$(sed '1!d' "$TmpDir/$File")" = '404: Not Found' ]; then
ErrCount=$((ErrCount + 1))
printf '\033[31m[ERR]\033[0m\n'
rm "$TmpDir/$File" > /dev/null 2>&1
else
printf '\033[32m[OK]\033[0m\n'
fi
else
ErrCount=$((ErrCount + 1))
printf '\033[31m[ERR]\033[0m\n'
fi
done
if [ $ErrCount -gt 0 ]; then
printf 'ERROR: Failed to download one or more files.\n' 1>&2
exit 1
fi
printf '* Making director(ies) ... '
if mkdir -p /usr/share/cheater 2>> "$LogFile"; then
printf '\033[32m[OK]\033[0m\n'
else
printf '\033[31m[ERR]\033[0m\n'
fi
printf 'Setting correct file attributes:\n'
printf '* Assigning owner and group ... '
if chown 0:0 "$TmpDir"/* /usr/share/cheater 2>> "$LogFile"; then
printf '\033[32m[OK]\033[0m\n'
else
printf '\033[31m[ERR]\033[0m\n'
fi
printf '* Assigning modes ... '
ErrCount=0
for File in\
\
'cheater:755' 'completions:644' 'cheater.1.gz:644' 'excluded_lines:644'
do
chmod ${File##*:} "$TmpDir/${File%:*}" 2>> "$LogFile" ||
ErrCount=$((ErrCount + 1))
done
chmod 755 /usr/share/cheater 2>> "$LogFile" || ErrCount=$((ErrCount + 1))
if [ $ErrCount -eq 0 ]; then
printf '\033[32m[OK]\033[0m\n'
else
printf '\033[31m[ERR]\033[0m\n'
fi
printf 'Moving files into place:\n'
ErrCount=0
for File in\
\
'completions:/usr/share/bash-completion/completions/cheater'\
'cheater.1.gz:/usr/share/man/man1/cheater.1.gz' 'cheater:/usr/bin/cheater'\
'excluded_lines:/usr/share/cheater/excluded_lines'
do
printf "* Installing '%s' ... " "${File%%:*}"
if mv "$TmpDir/${File%%:*}" "${File#*:}" 2>> "$LogFile"; then
printf '\033[32m[OK]\033[0m\n'
else
printf '\033[31m[ERR]\033[0m\n'
fi
done
printf 'Checking executables work:\n'
printf "* Verifying 'cheater' ... "
if cheater -v > /dev/null 2>&1; then
printf '\033[32m[OK]\033[0m\n'
else
printf '\033[31m[ERR]\033[0m\n'
fi