-
Notifications
You must be signed in to change notification settings - Fork 13
/
ncdu.install
executable file
·407 lines (402 loc) · 13.5 KB
/
ncdu.install
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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
#!/bin/bash
#
############################
##### Basic Info Start #####
############################
#
# Script Author: adamaze
#
# Script Contributors:
#
# License: This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License. https://creativecommons.org/licenses/by-sa/4.0/
#
# Bash Command for easy reference:
#
# wget -qO ~/ncdu.install http://git.io/vTwuq && bash ~/ncdu.install
#
############################
###### Basic Info End ######
############################
#
############################
#### Script Notes Start ####
############################
#
## See readme.md
#
############################
##### Script Notes End #####
############################
#
############################
## Version History Starts ##
############################
#
if [[ ! -z "$1" && "$1" = 'changelog' ]]
then
echo
#
# put your version changes in the single quotes and then uncomment the line.
#
#echo 'v0.1.0 - My changes go here'
#echo 'v0.0.9 - My changes go here'
#echo 'v0.0.8 - My changes go here'
#echo 'v0.0.7 - My changes go here'
#echo 'v0.0.6 - My changes go here'
#echo 'v0.0.5 - My changes go here'
#echo 'v0.0.4 - My changes go here'
#echo 'v0.0.3 - My changes go here'
#echo 'v0.0.2 - My changes go here'
echo 'v0.0.1 - initial commit'
#
echo
exit
fi
#
############################
### Version History Ends ###
############################
#
############################
###### Variable Start ######
############################
#
# Script Version number is set here.
scriptversion="0.0.1"
#
# Script name goes here. Please prefix with install.
scriptname="install.ncdu"
#
# Author name goes here.
scriptauthor="adamaze"
#
# Contributor's names go here.
contributors="None credited"
#
# Set the http://git.io/ shortened URL for the raw github URL here:
gitiourl="http://git.io/vTwuq"
#
# Don't edit: This is the bash command shown when using the info option.
gitiocommand="wget -qO ~/$scriptname $gitiourl && bash ~/$scriptname"
#
# This is the raw github url of the script to use with the built in updater.
scripturl="https://raw.githubusercontent.com/frankthetank7254/feral/master/ncdu.install"
#
# This will generate a 20 character random passsword for use with your applications.
apppass="$(< /dev/urandom tr -dc '1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz' | head -c20; echo;)"
# This will generate a random port for the script between the range 10001 to 32001 to use with applications. You can ignore this unless needed.
appport="$(shuf -i 10001-32001 -n 1)"
#
# This wil take the previously generated port and test it to make sure it is not in use, generating it again until it has selected an open port.
while [[ "$(netstat -ln | grep ':'"$appport"'' | grep -c 'LISTEN')" -eq "1" ]]; do appport="$(shuf -i 10001-32001 -n 1)"; done
#
# Script user's http www URL in the format http://username.server.feralhosting.com/
host1http="http://$(whoami).$(hostname -f)/"
# Script user's https www URL in the format https://username.server.feralhosting.com/
host1https="https://$(whoami).$(hostname -f)/"
# Script user's http www url in the format https://server.feralhosting.com/username/
host2http="http://$(hostname -f)/$(whoami)/"
# Script user's https www url in the format https://server.feralhosting.com/username/
host2https="https://$(hostname -f)/$(whoami)/"
#
# feralwww - sets the full path to the default public_html directory if it exists.
[[ -d ~/www/"$(whoami)"."$(hostname -f)"/public_html ]] && feralwww="$HOME/www/$(whoami).$(hostname -f)/public_html/"
# rtorrentdata - sets the full path to the rtorrent data directory if it exists.
[[ -d ~/private/rtorrent/data ]] && rtorrentdata="$HOME/private/rtorrent/data"
# deluge - sets the full path to the deluge data directory if it exists.
[[ -d ~/private/deluge/data ]] && delugedata="$HOME/private/deluge/data"
# transmission - sets the full path to the transmission data directory if it exists.
[[ -d ~/private/transmission/data ]] && transmissiondata="$HOME/private/transmission/data"
#
# Bug reporting varaibles.
makeissue=".makeissue $scriptname A description of the issue"
ticketurl="https://www.feralhosting.com/manager/tickets/new"
gitissue="https://github.com/feralhosting/feralfilehosting/issues/new"
#
############################
## Custom Variables Start ##
############################
#
##
#
############################
### Custom Variables End ###
############################
#
# Disables the built in script updater permanently by setting this variable to 0.
updaterenabled="1"
#
############################
####### Variable End #######
############################
#
############################
###### Function Start ######
############################
#
example () {
echo "This is my example function"
}
#
############################
####### Function End #######
############################
#
############################
#### Script Help Starts ####
############################
#
if [[ ! -z "$1" && "$1" = 'help' ]]
then
echo
echo -e "\033[32m""Script help and usage instructions:""\e[0m"
echo
#
###################################
##### Custom Help Info Starts #####
###################################
#
echo -e "Running this script will automatically install NCurses Disk Usage (ncdu)"
#
###################################
###### Custom Help Info Ends ######
###################################
#
echo
exit
fi
#
############################
##### Script Help Ends #####
############################
#
############################
#### Script Info Starts ####
############################
#
# Use this to show a user script information when they use the info option with the script.
if [[ ! -z "$1" && "$1" = 'info' ]]
then
echo
echo -e "\033[32m""Script Details:""\e[0m"
echo
echo "Script version: $scriptversion"
echo
echo "Script Author: $scriptauthor"
echo
echo "Script Contributors: $contributors"
echo
echo -e "\033[32m""Script options:""\e[0m"
echo
echo -e "\033[36mhelp\e[0m = See the help section for this script."
echo
echo -e "Example usage: \033[36m$scriptname help\e[0m"
echo
echo -e "\033[36mchangelog\e[0m = See the version history and change log of this script."
echo
echo -e "Example usage: \033[36m$scriptname changelog\e[0m"
echo
echo -e "\033[36minfo\e[0m = Show the script information and usage instructions."
echo
echo -e "Example usage: \033[36m$scriptname info\e[0m"
echo
echo -e "\033[31mImportant note:\e[0m Options \033[36mqr\e[0m and \033[36mnu\e[0m are interchangeable and usable together."
echo
echo -e "For example: \033[36m$scriptname qr nu\e[0m or \033[36m$scriptname nu qr\e[0m will both work"
echo
echo -e "\033[36mqr\e[0m = Quick Run - use this to bypass the default update prompts and run the main script directly."
echo
echo -e "Example usage: \033[36m$scriptname qr\e[0m"
echo
echo -e "\033[36mnu\e[0m = No Update - disable the built in updater. Useful for testing new features or debugging."
echo
echo -e "Example usage: \033[36m$scriptname nu\e[0m"
echo
echo -e "\033[32mBash Commands:\e[0m"
echo
echo -e "\033[36m""$gitiocommand""\e[0m"
echo
echo -e "\033[36m""~/bin/$scriptname""\e[0m"
echo
echo -e "\033[36m""$scriptname""\e[0m"
echo
echo -e "\033[32m""Bug Reporting:""\e[0m"
echo
echo -e "These are the recommended ways to report bugs for scripts in the FAQs:"
echo
echo -e "1: In IRC you can use wikibot to create a github issue by using this command format:"
echo
echo -e "\033[36m""$makeissue""\e[0m"
echo
echo -e "2: You could open a ticket describing the problem with details of which script and what the problem is."
echo
echo -e "\033[36m""$ticketurl""\e[0m"
echo
echo -e "3: You can create an issue directly on github using your github account."
echo
echo -e "\033[36m""$gitissue""\e[0m"
echo
echo -e "\033[33m""All bug reports are welcomed and very much appreciated, as they benefit all users.""\033[32m"
#
echo
exit
fi
#
############################
##### Script Info Ends #####
############################
#
############################
#### Self Updater Start ####
############################
#
# Checks for the positional parameters $1 and $2 to be reset if the script is updated.
[[ ! -z "$1" && "$1" != 'qr' ]] || [[ ! -z "$2" && "$2" != 'qr' ]] && echo -en "$1\n$2" > ~/.passparams
# Quick Run option part 1: If qr is used it will create this file. Then if the script also updates, which would reset the option, it will then find this file and set it back.
[[ ! -z "$1" && "$1" = 'qr' ]] || [[ ! -z "$2" && "$2" = 'qr' ]] && echo -n '' > ~/.quickrun
#
# No Update option: This disables the updater features if the script option "nu" was used when running the script.
if [[ ! -z "$1" && "$1" = 'nu' ]] || [[ ! -z "$2" && "$2" = 'nu' ]]
then
echo
echo "The Updater has been temporarily disabled"
echo
scriptversion="$scriptversion-nu"
else
#
# Check to see if the variable "updaterenabled" is set to 1. If it is set to 0 the script will bypass the built in updater regardless of the options used.
if [[ "$updaterenabled" -eq "1" ]]
then
[[ ! -d ~/bin ]] && mkdir -p ~/bin
[[ ! -f ~/bin/"$scriptname" ]] && wget -qO ~/bin/"$scriptname" "$scripturl"
#
wget -qO ~/.000"$scriptname" "$scripturl"
#
if [[ "$(sha256sum ~/.000"$scriptname" | awk '{print $1}')" != "$(sha256sum ~/bin/"$scriptname" | awk '{print $1}')" ]]
then
echo -e "#!/bin/bash\nwget -qO ~/bin/$scriptname $scripturl\ncd && rm -f $scriptname{.sh,}\nbash ~/bin/$scriptname\nexit" > ~/.111"$scriptname"
bash ~/.111"$scriptname"
exit
else
if [[ -z "$(pgrep -fu "$(whoami)" "bash $HOME/bin/$scriptname")" && "$(pgrep -fu "$(whoami)" "bash $HOME/bin/$scriptname")" -ne "$$" ]]
then
echo -e "#!/bin/bash\ncd && rm -f $scriptname{.sh,}\nbash ~/bin/$scriptname\nexit" > ~/.222"$scriptname"
bash ~/.222"$scriptname"
exit
fi
fi
cd && rm -f .{000,111,222}"$scriptname"
chmod -f 700 ~/bin/"$scriptname"
echo
else
echo
echo "The Updater has been disabled"
echo
scriptversion="$scriptversion-DEV"
fi
fi
#
# Quick Run option part 2: If quick run was set and the updater section completes this will enable quick run again then remove the file.
[[ -f ~/.quickrun ]] && updatestatus="y"; rm -f ~/.quickrun
#
# resets the positional parameters $1 and $2 post update.
[[ -f ~/.passparams ]] && set "$1" "$(sed -n '1p' ~/.passparams)" && set "$2" "$(sed -n '2p' ~/.passparams)"; rm -f ~/.passparams
#
############################
##### Self Updater End #####
############################
#
############################
## Positional Param Start ##
############################
#
if [[ ! -z "$1" && "$1" = "example" ]]
then
echo
#
# Edit below this line
#
echo "Add your custom positional parameters in this section."
#
if [[ -n "$2" ]]
then
echo "You used $scriptname $1 $2 when calling this example"
fi
#
# Edit above this line
#
echo
exit
fi
#
############################
### Positional Param End ###
############################
#
############################
#### Core Script Starts ####
############################
#
if [[ "$updatestatus" = "y" ]]
then
:
else
echo -e "Hello $(whoami), you have the latest version of the" "\033[36m""$scriptname""\e[0m" "script. This script version is:" "\033[31m""$scriptversion""\e[0m"
echo
read -ep "The script has been updated, enter [y] to continue or [q] to exit: " -i "y" updatestatus
echo
fi
#
if [[ "$updatestatus" =~ ^[Yy]$ ]]
then
#
############################
#### User Script Starts ####
############################
#
if [ $(dpkg -s libncurses5-dev 2> /dev/null | grep -c "Status: install ok installed" ) = 1 ] && [ $(dpkg -s libncursesw5-dev 2> /dev/null | grep -c "Status: install ok installed" ) = 1 ]; then
echo "Downloading..."
wget -qO ~/ncdu-1.11.tar.gz http://dev.yorhel.nl/download/ncdu-1.11.tar.gz
cd ~/
tar xzf ncdu-1.11.tar.gz
cd ncdu-1.11
echo "Configuring..."
./configure --prefix=$HOME > /dev/null 2&>1
make > /dev/null 2&>1
make install > /dev/null 2&>1
cd ~/
rm -r ~/ncdu-1.11*
echo "All done"
if [ $(echo $PATH | grep -c ${whoami}/bin) = 1 ]; then
echo "Use 'ncdu ~/' to run, the arrow keys, enter, and delete to navigate, and 'q' to quit"
else
echo "sue '~/bin/ncdu ~/' to run, the arrow keys, enter, and delete to navigate, and 'q' to quit"
fi
else
echo "You will need to open a ticket to install some dependencies before you can continue the install."
echo -e "\033[34m""https://www.feralhosting.com/manager/tickets/""\e[0m"
echo "Use 'Dependancy Install' as the subject, and following as the body:"
echo "Please can you install the libncurses5-dev libncursesw5-dev dependencies for NCDU?
https://packages.debian.org/en/wheezy/libncurses5-dev
https://packages.debian.org/en/wheezy/libncursesw5-dev
apt-get install libncurses5-dev libncursesw5-dev
Thank you."
echo
echo "Once you hear back that they are installed, you can run this script again to complete the install."
fi
#
############################
##### User Script End #####
############################
#
else
echo -e "You chose to exit after updating the scripts."
echo
cd && bash
exit
fi
#
############################
##### Core Script Ends #####
############################
#