-
Notifications
You must be signed in to change notification settings - Fork 259
/
rtdload
executable file
·81 lines (68 loc) · 2.31 KB
/
rtdload
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
#!/bin/bash
######################################################################
#
# Copyright (c) 2015 arakasi72 (https://github.com/arakasi72)
#
# --> Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
#
######################################################################
PATH=/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/bin:/sbin
lineno=$(sed -n '/dload-loc/=' /etc/nginx/sites-available/default)
dlstatus=disabled
# function to ask user for y/n response
ask_user(){
while true
do
read answer
case $answer in [Yy]* ) return 0 ;;
[Nn]* ) return 1 ;;
* ) echo "Enter y or n";;
esac
done
}
if [ "$(id -u)" != "0" ]; then
echo "Must be run as root, directly or with sudo"
exit 1
fi
if [ -f /etc/nginx/conf.d/rtdload ]; then rm -f /etc/nginx/conf.d/rtdload; fi
sed -i '/rtdload/d' /etc/nginx/sites-available/default
if [ $# = 0 ]; then
rtdgrep1=$(grep dload-loc /etc/nginx/sites-available/default)
rtdgrep2=$(grep dload-loc /etc/nginx/sites-available/default | grep '#')
if [ -n "$rtdgrep1" -a -z "$rtdgrep2" ]; then dlstatus=enabled; fi
if [ -t 1 ]; then
if [ $dlstatus = enabled ]; then
echo "Http downloads are Enabled"
dlswitch=disable
elif [ $dlstatus = disabled ]; then
echo "Http downloads are Disabled"
dlswitch=enable
fi
echo "Would you like to $dlswitch http downloads (y/n)?"
if ask_user; then
rtdload $dlswitch
fi
else
echo $dlstatus
fi
elif [ "$1" = "enable" ]; then
if ! [ -f /etc/nginx/sites-available/dload-loc ]; then
cp -f /etc/rtinst/conf/nginxsitedl /etc/nginx/sites-available/dload-loc
fi
if [ -z "$lineno" ]; then
sed -i '/location \~ \/\\\.ht/ i\ include \/etc\/nginx\/sites-available\/dload-loc;\n' /etc/nginx/sites-available/default
else
sed -i '/dload-loc/ c\ include \/etc\/nginx\/sites-available\/dload-loc;' /etc/nginx/sites-available/default
fi
service nginx reload
echo "http download enabled"
elif [ "$1" = "disable" ]; then
if ! [ -z "$lineno" ]; then
sed -i '/dload-loc/ c\ #include \/etc\/nginx\/sites-available\/dload-loc;' /etc/nginx/sites-available/default
service nginx reload
fi
echo "http download disabled"
else
echo "argument must be enable or disable"
exit 1
fi