forked from arakasi72/rtinst
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rtgetscripts
92 lines (76 loc) · 2.2 KB
/
rtgetscripts
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
#!/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
blob=master
RTDIR=https://raw.githubusercontent.com/kvanbiesen/rtinst/$blob
check_url() {
if [[ `wget -S --spider $1 2>&1 | grep 'HTTP/1.1 200 OK'` ]]; then echo "true"; fi
}
get_scripts() {
local script_dest=$1
local script_name=$2
local attempts=0
local script_size=0
local bindest="/usr/local/bin"
if [ -z $script_name ]; then
script_name="${script_dest##*/}"
fi
while [ $script_size = 0 ]
do
rm -f $script_dest
attempts=$(( $attempts + 1 ))
if [ $attempts = 20 ]; then
echo "There is a problem downloading from github. Please check your network or there may be an issue with the github website"
echo "If the Github website is down, you can try again later"
exit
fi
wget -q --no-check-certificate --output-document=$script_dest $RTDIR/$script_name
script_size=$(du -b $script_dest | cut -f1)
done
if case $script_dest in *"${bindest}"*) true;; *) false;; esac; then
chmod 755 $script_dest
fi
}
if ! [ "$LOGNAME" = "root" ]; then
echo "Must be run as root, directly or with sudo"
exit 1
fi
if [ $# = 0 ]; then
echo -n "Updating"
RTDIR=$RTDIR/scripts
if [ "$(check_url $RTDIR/script_list)" = "true" ]; then
script_list=($(curl -s $RTDIR/script_list))
else
echo "Could not access github repository"
exit
fi
for script in "${script_list[@]}"
do
echo -n "."
get_scripts /usr/local/bin/"${script##*/}" $script
done
echo
echo "Completed scripts download"
RUNDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
if [ "$RUNDIR" != "/usr/local/bin" ]; then
rm -f $RUNDIR/rtgetscripts
fi
else
RTDIR=$RTDIR/conf
if [ -z $2 ]; then
scriptnme="${1##*/}"
else
scriptnme=$2
fi
if [ "$(check_url $RTDIR/$scriptnme)" = "true" ]; then
get_scripts $1 $2
else
echo "could not access $scriptnme on github, check github website"
fi
fi