forked from QuickBox/DockBox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
box
256 lines (238 loc) · 8.03 KB
/
box
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
#!/bin/bash
#
# [Quick Box :: QuickBox Package Manager Batch CLI Installer `box`]
# `box -h` for commands and info
#
# GITHUB REPOS
# GitHub _ packages : https://github.com/QuickBox/quickbox_packages
# LOCAL REPOS
# Local _ packages : ~/QuickBox/packages
# Author : QuickBox.IO | liara
# URL : https://plaza.quickbox.io
#
# QuickBox Copyright (C) 2017 QuickBox.io
# Licensed under GNU General Public License v3.0 GPL-3 (in short)
#
# You may copy, distribute and modify the software as long as you track
# changes/dates in source files. Any modifications to our software
# including (via compiler) GPL-licensed code must also be made available
# under the GPL along with build & install instructions.
#
#################################################################################
function _intro() {
whiptail --title "DockBox" --msgbox "Welcome to the DockBox Installer." 15 50
}
function _function() {
function=$(whiptail --title "QBPM" --menu "Choose an option:" --ok-button "Continue" --nocancel 12 50 3 \
Install "packages" \
Remove "packages" \
Exit "" 3>&1 1>&2 2>&3)
if [[ $function == Install ]]; then
_install
elif [[ $function == Remove ]]; then
_remove
elif [[ $function == Exit ]]; then
exit 0
fi
}
function _install() {
installa=()
locks=($(find scripts/install -type f -printf "%f\n" | cut -d "." -f 1 | sort -d))
for i in "${locks[@]}"; do
app=${i}
if [[ ! -f /install/.$app.lock ]]; then
installa+=("$i" '""')
fi
done
whiptail --title "Install Software" --checklist --noitem --separate-output "Make some choices:" 15 40 7 "${installa[@]}" 2>results
readarray packages < results
for i in "${packages[@]}"; do
echo -e "Installing $i ";
bash $i.sh
done
rm results
_function
}
function _remove() {
removea=()
locks=($(find scripts/uninstall -type f -printf "%f\n" | cut -d "." -f 1 | sort -d))
for i in "${locks[@]}"; do
app=${i}
if [[ $i == autodl ]]; then app=autodlirssi; fi
if [[ -f /install/.$app.lock ]]; then
removea+=("$i" '""')
fi
done
whiptail --title "Remove Software" --noitem --checklist --separate-output "Make some choices:" 15 26 7 "${removea[@]}" 2>results
readarray packages < results
for i in "${packages[@]}"; do
echo -e "Removing $i ";
bash /usr/local/bin/quickbox/package/remove/removepackage-$i
done
rm results
_function
}
function _cli() {
arg=("$@")
packages=("${arg[@]:1}")
repo=($(find /usr/local/bin/quickbox/package/install -type f -printf "%f\n" | cut -d "-" -f 2))
for i in "${packages[@]}"; do
app=${i}
if [[ $i == autodl ]]; then app=autodlirssi; fi
if [[ -f /install/.${app}.lock ]]; then
echo -e "Package $i already installed"
else
if [[ "${repo[@]}" =~ $i ]]; then
echo -e "Installing $i "
bash /usr/local/bin/quickbox/package/install/installpackage-$i
else
echo -e "Package $i not found"
fi
fi
done
}
function _clr() {
arg=("$@")
packages=("${arg[@]:1}")
for i in "${packages[@]}"; do
app=${i}
if [[ $i == autodl ]]; then app=autodlirssi; fi
if [[ -f /install/.$app.lock ]]; then
echo -e "Removing $i "
bash /usr/local/bin/quickbox/package/remove/removepackage-$i
else
echo -e "Package $i not installed"
fi
done
}
function _updateqb() {
echo -e "Updating QuickBox local repository"
if [[ ! -f /install/.developer.lock ]]; then
if [[ -d /etc/QuickBox ]]; then
cd /root/
rm -rf QuickBox
git clone --recursive https://github.com/QuickBox/QuickBox QuickBox
cd /etc/QuickBox
git submodule foreach git reset HEAD --hard
git submodule foreach git checkout master
git submodule foreach git pull
cd -
else
cd /etc/QuickBox
git submodule foreach git reset HEAD --hard
git submodule foreach git checkout master
git submodule foreach git pull
cd -
fi
else
if [[ -d /etc/QuickBox ]]; then
cd /root/
rm -rf QuickBox
git clone --recursive --branch "development" https://github.com/QuickBox/QuickBox /etc/QuickBox
cd /etc/QuickBox
git submodule foreach git reset HEAD --hard
git submodule foreach git checkout development
git submodule foreach git pull
cd -
else
cd /etc/QuickBox
git submodule foreach git reset HEAD --hard
git submodule foreach git checkout development
git submodule foreach git pull
fi
fi
}
function _help() {
sgformat="${bold}%-15s${normal}"
spacing=$(echo $'\t' | pr -Te15)
echo -e "Usage: `basename $0` [ install | remove ] ${bold}pkg1 pkg2 [...]${normal}\n"
echo -e " `basename $0` [ list | update | upgrade ]\n"
echo -e " `basename $0`\n"
echo -e "Note: Only install and remove functions accept package arguments. List and update must be run without modifiers\n" | fmt --goal=66 --tagged-paragraph
echo -e "\n"
printf "${sgformat}" "install"
echo -e "The install function requires at least one package name as an argument but will accept multiples\n" | fmt --goal=50 | sed -e "2,\$s/^/$spacing/"
echo -e " Example: box install quassel syncthing znc\n" | fmt --goal=50 | sed -e "2,\$s/^/$spacing/"
printf "${sgformat}" "remove"
echo -e "The remove function requires at least one package name as an argument but will accept multiples\n" | fmt --goal=50 | sed -e "2,\$s/^/$spacing/"
echo -e " Example: box remove quassel syncthing znc\n" | fmt --goal=50 | sed -e "2,\$s/^/$spacing/"
printf "${sgformat}" "update"
echo -e "The update command will update your local QuickBox repository to the latest version\n" | fmt --goal=50 | sed -e "2,\$s/^/$spacing/"
printf "${sgformat}" "upgrade"
echo -e "The upgrade command will update your local QuickBox installation to the latest version\n" | fmt --goal=50 | sed -e "2,\$s/^/$spacing/"
printf "${sgformat}" "list"
echo -e "The list command will list packages available to be managed by box\n" | fmt --goal=50 | sed -e "2,\$s/^/$spacing/"
}
function _list() {
repo=($(find /usr/local/bin/quickbox/package/install -type f -printf "%f\n" | cut -d "-" -f 2 | sort -d))
for i in "${repo[@]}"; do
locale=$(cat /srv/rutorrent/home/inc/localize.php | grep language | cut -d "'" -f 2)
app=$i
if [[ $i == plexrequests ]]; then app=plex_requests; fi
sgformat="${bold}%-15s${normal}"
spacing=$(echo $'\t' | pr -Te15)
description=$(cat /srv/rutorrent/home/lang/$locale | grep -i -m 1 \\\[\'$app | cut -d= -f2 | sed "s/ '//g" | sed "s/';//g" | sed "s/\\\'/'/g")
if [[ -z $description ]]; then description="Description missing";fi
printf "${sgformat}" "$i"
echo -e "${description}\n" | fmt --goal=50 | sed -e "2,\$s/^/$spacing/"
done
}
normal=$(tput sgr0)
yellow=$(tput setaf 3)
bold=$(tput bold)
if [[ -z $1 ]]; then
_intro
_function
exit 0
fi
if [[ "$1" == "-h" ]]; then
_help "$0"
exit 0
fi
if [[ ! $1 =~ ("install"|"list"|"remove"|"update"|"upgrade") ]]; then
echo "Error: $1 invalid command"
exit 0
fi
if [[ $1 == update ]]; then
_updateqb
exit 0
fi
if [[ $1 == upgrade ]]; then
_updateqb
echo "Upgrading QuickBox ... This may take a moment"
if [[ ! -f /install/.developer.lock ]]; then
if [[ -d /root/QuickBox ]]; then
rm -rf /root/QuickBox
bash /etc/QuickBox/packages/system/updateQuickBox
git clone --recursive https://github.com/QuickBox/QuickBox /etc/QuickBox
else
bash /etc/QuickBox/packages/system/updateQuickBox
fi
else
if [[ -d /root/QuickBox ]]; then
rm -rf /root/QuickBox
bash /etc/QuickBox/packages/system/updateQuickBox
git clone --recursive --branch "development" https://github.com/QuickBox/QuickBox /etc/QuickBox
else
bash /etc/QuickBox/packages/system/updateQuickBox
fi
fi
#printf "" > /srv/rutorrent/home/db/output.log
exit 0
fi
if [[ $1 == list ]]; then
_list
exit 0
fi
if [[ -n $1 ]] && [[ -z $2 ]]; then
echo "Error: You must choose some packages"
exit 0
fi
if [[ $1 == install ]]; then
_cli "$@"
exit 0
fi
if [[ $1 == remove ]]; then
_clr "$@"
exit 0
fi