forked from dannyti/seedbox-from-scratch
-
Notifications
You must be signed in to change notification settings - Fork 4
/
createSeedboxUser
executable file
·429 lines (371 loc) · 14.5 KB
/
createSeedboxUser
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
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
#!/bin/bash
# Hellish Tech
# No commercial usage without authorization
exec 1> >(logger -s -t $(basename $0)) 2>&1
trlt="$(curl -s https://api.github.com/repos/autodl-community/autodl-trackers/releases/latest | sed -rn 's/(.*)"tag_name": "v(.*)",/\2/p')"
dltrkrs="https://github.com/autodl-community/autodl-trackers/releases/download/community-v$trlt/autodl-trackers-v$trlt.zip"
function getString
{
local ISPASSWORD=$1
local LABEL=$2
local RETURN=$3
local DEFAULT=$4
local NEWVAR1=a
local NEWVAR2=b
local YESYES=YESyes
local NONO=NOno
local YESNO=$YESYES$NONO
while [ ! $NEWVAR1 = $NEWVAR2 ] || [ -z "$NEWVAR1" ];
do
clear
echo
if [ "$ISPASSWORD" == "YES" ]; then
read -s -p "$DEFAULT" -p "$LABEL" NEWVAR1
else
read -e -i "$DEFAULT" -p "$LABEL" NEWVAR1
fi
if [ -z "$NEWVAR1" ]; then
NEWVAR1=a
continue
fi
if [ ! -z "$DEFAULT" ]; then
if grep -q "$DEFAULT" <<< "$YESNO"; then
if grep -q "$NEWVAR1" <<< "$YESNO"; then
if grep -q "$NEWVAR1" <<< "$YESYES"; then
NEWVAR1=YES
else
NEWVAR1=NO
fi
else
NEWVAR1=a
fi
fi
fi
if [ "$NEWVAR1" == "$DEFAULT" ]
then
NEWVAR2=$NEWVAR1
else
if [ "$ISPASSWORD" == "YES" ]; then
echo
read -s -p "Retype: " NEWVAR2
else
read -p "Retype: " NEWVAR2
fi
if [ -z "$NEWVAR2" ]; then
NEWVAR2=b
continue
fi
fi
if [ ! -z "$DEFAULT" ]; then
if grep -q "$DEFAULT" <<< "$YESNO"; then
if grep -q "$NEWVAR2" <<< "$YESNO"; then
if grep -q "$NEWVAR2" <<< "$YESYES"; then
NEWVAR2=YES
else
NEWVAR2=NO
fi
else
NEWVAR2=a
fi
fi
fi
echo "---> $NEWVAR2"
done
eval $RETURN=\$NEWVAR1
}
function genPasswd {
local l=$1
[ "$l" == "" ] && l=32
tr -dc A-Za-z0-9 < /dev/urandom | head -c ${l} | xargs
}
#
#
if [[ "$0" == "-bash" ]]; then
echo "This script is not executable, please run chmod +x on it."
exit 0
fi
NEWUSER1=a
NEWUSER2=b
PASSWORD1=a
PASSWORD2=b
if [ $1 ]; then
NEWUSER1=$1
NEWUSER2=$1
else
getString NO "Username for your seedbox user: " NEWUSER1
fi
if [ $2 ]; then
PASSWORD1=$2
PASSWORD2=$2
else
getString YES "ruTorrent password for user $NEWUSER1: " PASSWORD1
fi
if [ $3 ]
then
if [ "$3" == "YES" ] || [ "$3" == "NO" ]; then
USERHASSSHACCESS1=$3
USERHASSSHACCESS2=$3
else
getString NO "User can login via SSH?: " USERHASSSHACCESS1 NO
fi
else
getString NO "User can login via SSH?: " USERHASSSHACCESS1 NO
fi
CHROOTJAIL1=NO
#if [ -f /etc/jailkit/jk_init.ini ] && [ "$USERHASSSHACCESS1" == "YES" ]; then
# if [ $4 ]
# then
# if [ "$4" == "YES" ] || [ "$4" == "NO" ]; then
# CHROOTJAIL1=$4
# CHROOTJAIL2=$4
# else
# getString NO "User should be in a chroot jail?: " CHROOTJAIL1 YES
# fi
# else
# getString NO "User should be in a chroot jail?: " CHROOTJAIL1 YES
# fi
#else
# CHROOTJAIL1=NO
#fi
if [ $5 ]
then
if [ "$5" == "YES" ] || [ "$5" == "NO" ]; then
USERINSUDOERS1=$5
USERINSUDOERS2=$5
else
getString NO "Add user to sudoers?: " USERINSUDOERS1 NO
fi
else
getString NO "Add user to sudoers?: " USERINSUDOERS1 NO
fi
if [ "$USERINSUDOERS1" == "YES" ]; then
echo "$NEWUSER1" | sudo tee -a /etc/vsftpd.chroot_list &> /dev/null
fi
if [ $6 ]
then
if [ "$6" == "YES" ] || [ "$6" == "NO" ]; then
USERISCHROOT1=$6
USERISCHROOT2=$6
else
getString NO "Chroot this User?: " USERISCHROOT1 NO
fi
else
getString NO "Chroot this User?: " USERISCHROOT1 NO
fi
OS1=$(lsb_release -si)
HOMEBASE1=/home/$NEWUSER1
HOMEDIR1=$HOMEBASE1
HOMEJAILED1=$HOMEBASE1
JAILDIR1=$HOMEBASE1
if [ "$CHROOTJAIL1" == "YES" ]; then
JAILDIR1=$HOMEDIR1/jail
HOMEDIR1=$HOMEDIR1/home
HOMEJAILED1=$JAILDIR1/home
fi
JAILDIR1_ESCAPED=`echo $JAILDIR1 | sed s,/,\\\\\\\\\\/,g`
HOMEDIR1_ESCAPED=`echo $HOMEDIR1 | sed s,/,\\\\\\\\\\/,g`
HOMEJAILED1_ESCAPED=`echo $HOMEJAILED1 | sed s,/,\\\\\\\\\\/,g`
IPADDRESS1=`cat /etc/seedbox-from-scratch/hostname.info`
SBFSCURRENTVERSION=`cat /etc/seedbox-from-scratch/version.info`
NEWFTPPORT1=`cat /etc/seedbox-from-scratch/ftp.info`
NEWSSHPORT1=`cat /etc/seedbox-from-scratch/ssh.info`
MAINUSER1=`cat /etc/seedbox-from-scratch/mainuser.info`
# 3.2
set -x verbose
# 3.3
sudo rm -f -r $HOMEDIR1
sudo mkdir -p $HOMEDIR1
sudo useradd --create-home --home $HOMEDIR1 --user-group --password $(mkpasswd -s -m md5 $PASSWORD1) --shell /bin/bash $NEWUSER1
if [ ! -f $HOMEDIR1/.profile ]; then
sudo cp /etc/skel/.bashrc $HOMEDIR1
sudo cp /etc/skel/.bash_logout $HOMEDIR1
sudo cp /etc/skel/.profile $HOMEDIR1
sudo chown $NEWUSER1: $HOMEDIR1
sudo chown $NEWUSER1: $HOMEDIR1/.bashrc
sudo chown $NEWUSER1: $HOMEDIR1/.bash_logout
sudo chown $NEWUSER1: $HOMEDIR1/.profile
fi
if [ "$CHROOTJAIL1" == "YES" ]; then
sudo mkdir -p $JAILDIR1
sudo chown root: $HOMEDIR1
sudo chown root: $JAILDIR1
sudo jk_init -v $JAILDIR1 basicshell editors extendedshell jk_lsh git rsync openvpn perl vncserver netbasics netutils openvpn scp ssh terminfo rtorrent irssi screen id php pgrep mediainfo ffmpeg curl plowup unzip unrar ping wget dig nslookup groups pkill
sudo jk_jailuser -m -j $JAILDIR1 $NEWUSER1
sudo jk_cp -j $JAILDIR1 /etc/ld.so.cache
sudo jk_cp -j $JAILDIR1 /usr/lib/liblwres.so.80
sudo jk_cp -j $JAILDIR1 /usr/lib/libdns.so.81
sudo jk_cp -j $JAILDIR1 /usr/lib/libbind9.so.80
sudo jk_cp -j $JAILDIR1 /usr/lib/libisccfg.so.82
sudo jk_cp -j $JAILDIR1 /usr/lib/libisc.so.83
sudo jk_cp -j $JAILDIR1 /usr/lib/libGeoIP.so.1
sudo jk_cp -j $JAILDIR1 /usr/lib/ssl/openssl.cnf
sudo jk_cp -j $JAILDIR1 /usr/lib/`uname -m`-linux-gnu/openssl-1.0.0/engines/libgost.so
sudo jk_cp -j $JAILDIR1 /lib/`uname -m`-linux-gnu/libpthread.so.0
sudo jk_cp -j $JAILDIR1 /lib/`uname -m`-linux-gnu/libc.so.6
sudo jk_cp -j $JAILDIR1 /usr/lib/`uname -m`-linux-gnu/libgssapi_krb5.so.2
sudo jk_cp -j $JAILDIR1 /lib/`uname -m`-linux-gnu/libcrypto.so.1.0.0
sudo jk_cp -j $JAILDIR1 /usr/lib/`uname -m`-linux-gnu/libxml2.so.2
sudo jk_cp -j $JAILDIR1 /usr/lib/`uname -m`-linux-gnu/libkrb5.so.3
sudo jk_cp -j $JAILDIR1 /usr/lib/`uname -m`-linux-gnu/libk5crypto.so.3
sudo jk_cp -j $JAILDIR1 /lib/`uname -m`-linux-gnu/libcom_err.so.2
sudo jk_cp -j $JAILDIR1 /usr/lib/`uname -m`-linux-gnu/libkrb5support.so.0
sudo jk_cp -j $JAILDIR1 /lib/`uname -m`-linux-gnu/libdl.so.2
sudo jk_cp -j $JAILDIR1 /lib/`uname -m`-linux-gnu/libz.so.1
sudo jk_cp -j $JAILDIR1 /lib/`uname -m`-linux-gnu/libm.so.6
sudo jk_cp -j $JAILDIR1 /lib/`uname -m`-linux-gnu/libkeyutils.so.1
sudo jk_cp -j $JAILDIR1 /lib/`uname -m`-linux-gnu/libresolv.so.2
sudo jk_cp -j $JAILDIR1 /lib/`uname -m`-linux-gnu/libnss_compat.so.2
sudo jk_cp -j $JAILDIR1 /lib/`uname -m`-linux-gnu/libnss_dns.so.2
sudo jk_cp -j $JAILDIR1 /lib/`uname -m`-linux-gnu/libnss_files.so.2
sudo jk_cp -j $JAILDIR1 /dev/tty*
sudo cp /etc/skel/.bashrc $HOMEJAILED1
sudo cp /usr/sbin/jk_lsh $JAILDIR1/usr/sbin/jk_lsh
sudo perl -pi -e "s/\/usr\/sbin\/jk_lsh/\/bin\/bash/g" $JAILDIR1/etc/passwd
sudo mkdir -p $HOMEJAILED1
sudo chown -R $NEWUSER1: $HOMEJAILED1
sudo cp /usr/sbin/jk_lsh $JAILDIR1/usr/sbin/jk_lsh
sudo killall jk_socketd
sudo jk_socketd
echo "[$NEWUSER1]" | sudo tee -a /etc/jailkit/jk_chrootsh.ini
echo "environment=TERM=linux" | sudo tee -a /etc/jailkit/jk_chrootsh.ini
echo "env= TERM" | sudo tee -a /etc/jailkit/jk_chrootsh.ini
echo "export TERM=linux" | sudo tee -a $JAILDIR1/home/$NEWUSER1/home/.bashrc
sudo ldconfig -r $JAILDIR1
sudo mkdir $JAILDIR1/proc
sudo cp /lib/terminfo/l/linux $JAILDIR1/usr/share/terminfo/l/
sudo mount proc $JAILDIR1/proc -t proc
sudo mount -t devpts devpts $JAILDIR1/dev/pts -o mode=666
#chrrot /var/run === /run
sudo chown root: $JAILDIR1/run/screen
sudo chmod u+s $JAILDIR1/usr/bin/screen
sudo chmod 755 $JAILDIR1/run/screen
sudo chmod -R 777 $JAILDIR1/dev/pts
sudo chmod 666 $JAILDIR1/dev/null
sudo chmod -R 700 $JAILDIR1/run/screen/S-$NEWUSER1
HOMEJAILED1=$HOMEJAILED1/$NEWUSER1/home
ADDHOME1=\\/home
sudo mkdir $JAILDIR1/tmp
sudo chmod 1777 $JAILDIR1/tmp
sudo mount --bind /tmp $JAILDIR1/tmp
sudo chmod a-w $HOMEJAILED1
chown -R $NEWUSER1:$NEWUSER1 /home/$NEWUSER1
chown root:$NEWUSER1 /home/$NEWUSER1
chmod 755 /home/$NEWUSER1
fi
# 3.4
if [ "$USERISCHROOT1" == "YES" ]; then
sudo addgroup $NEWUSER1 sftponly
sudo chown root:root $HOMEJAILED1
fi
if [ "$USERINSUDOERS1" == "YES" ]; then
if [ "$OS1" = "Debian" ]; then
sudo addgroup $NEWUSER1 sudo
else
sudo addgroup $NEWUSER1 admin
fi
fi
if [ "$USERHASSSHACCESS1" == "YES" ]; then
sudo addgroup $NEWUSER1 sshdusers
fi
sudo service ssh restart
NEWRPC1=`head -n 1 /etc/seedbox-from-scratch/rpc.txt | tail -n 1`
sudo perl -pi -e "s/^$NEWRPC1.*\n$//g" /etc/seedbox-from-scratch/rpc.txt
IRSSIPORT1=`head -n 1 /etc/seedbox-from-scratch/ports.txt | tail -n 1`
sudo perl -pi -e "s/^$IRSSIPORT1.*\n$//g" /etc/seedbox-from-scratch/ports.txt
SCGIPORT1=`head -n 1 /etc/seedbox-from-scratch/ports.txt | tail -n 1`
sudo perl -pi -e "s/^$SCGIPORT1.*\n$//g" /etc/seedbox-from-scratch/ports.txt
NETWORKPORT1=`head -n 1 /etc/seedbox-from-scratch/ports.txt | tail -n 1`
sudo perl -pi -e "s/^$NETWORKPORT1.*\n$//g" /etc/seedbox-from-scratch/ports.txt
IRSSIPASSWORD1=`makepasswd`
# 12.
sudo bash /etc/seedbox-from-scratch/changeUserPassword $NEWUSER1 $PASSWORD1 rutorrent
sudo bash /etc/seedbox-from-scratch/changeUserPassword $NEWUSER1 $PASSWORD1 private
# 20.
sudo mkdir -p $HOMEJAILED1/downloads/auto
sudo mkdir -p $HOMEJAILED1/downloads/manual
sudo mkdir -p $HOMEJAILED1/services/
sudo mkdir -p $HOMEJAILED1/media/
sudo mkdir -p $HOMEJAILED1/media/comics
sudo mkdir -p $HOMEJAILED1/media/books
sudo mkdir -p $HOMEJAILED1/media/files
sudo mkdir -p $HOMEJAILED1/media/music
sudo mkdir -p $HOMEJAILED1/media/photos
sudo mkdir -p $HOMEJAILED1/media/movies
sudo mkdir -p $HOMEJAILED1/media/tvshows
sudo mkdir -p $HOMEJAILED1/downloads/watch
sudo mkdir -p $HOMEJAILED1/downloads/.session
sudo chown -R $NEWUSER1:$NEWUSER1 $HOMEJAILED1/downloads
sudo chown -R $NEWUSER1:$NEWUSER1 $HOMEJAILED1/media
sudo mkdir $HOMEJAILED1/log
sudo chown $NEWUSER1: $HOMEJAILED1/log
sudo chown www-data:www-data $HOMEJAILED1/services/
sudo chmod 770 $HOMEJAILED1/log
# 29.3
echo "http://$IPADDRESS1/private/SBinfo.txt" | sudo tee -a /etc/seedbox-from-scratch/users/$NEWUSER1.info
echo "" | sudo tee -a /etc/seedbox-from-scratch/users/$NEWUSER1.info
echo "User personal info" | sudo tee -a /etc/seedbox-from-scratch/users/$NEWUSER1.info
echo "-------------------" | sudo tee -a /etc/seedbox-from-scratch/users/$NEWUSER1.info
echo "Username: $NEWUSER1" | sudo tee -a /etc/seedbox-from-scratch/users/$NEWUSER1.info
echo "Password: $PASSWORD1" | sudo tee -a /etc/seedbox-from-scratch/users/$NEWUSER1.info
echo "IRSSI Password: $IRSSIPASSWORD1" | sudo tee -a /etc/seedbox-from-scratch/users/$NEWUSER1.info
echo "SSH: $USERHASSSHACCESS1" | sudo tee -a /etc/seedbox-from-scratch/users/$NEWUSER1.info
echo "Sudo powers: $USERINSUDOERS1" | sudo tee -a /etc/seedbox-from-scratch/users/$NEWUSER1.info
echo "Jailed: $CHROOTJAIL1" | sudo tee -a /etc/seedbox-from-scratch/users/$NEWUSER1.info
echo "" | sudo tee -a /etc/seedbox-from-scratch/users/$NEWUSER1.info
echo "Directories" | sudo tee -a /etc/seedbox-from-scratch/users/$NEWUSER1.info
echo "-----" | sudo tee -a /etc/seedbox-from-scratch/users/$NEWUSER1.info
echo "Home base: $HOMEBASE1" | sudo tee -a /etc/seedbox-from-scratch/users/$NEWUSER1.info
echo "Home dir: $HOMEDIR1" | sudo tee -a /etc/seedbox-from-scratch/users/$NEWUSER1.info
echo "Home jail: $HOMEJAILED1" | sudo tee -a /etc/seedbox-from-scratch/users/$NEWUSER1.info
echo "Jail dir: $JAILDIR1" | sudo tee -a /etc/seedbox-from-scratch/users/$NEWUSER1.info
echo "" | sudo tee -a /etc/seedbox-from-scratch/users/$NEWUSER1.info
echo "Ports" | sudo tee -a /etc/seedbox-from-scratch/users/$NEWUSER1.info
echo "-----" | sudo tee -a /etc/seedbox-from-scratch/users/$NEWUSER1.info
echo "SSH port: $NEWSSHPORT1" | sudo tee -a /etc/seedbox-from-scratch/users/$NEWUSER1.info
echo "SFTP port: $NEWSSHPORT1" | sudo tee -a /etc/seedbox-from-scratch/users/$NEWUSER1.info
echo "vsftp port: $NEWFTPPORT1" | sudo tee -a /etc/seedbox-from-scratch/users/$NEWUSER1.info
echo "" | sudo tee -a /etc/seedbox-from-scratch/users/$NEWUSER1.info
echo "Links" | sudo tee -a /etc/seedbox-from-scratch/users/$NEWUSER1.info
echo "-----" | sudo tee -a /etc/seedbox-from-scratch/users/$NEWUSER1.info
echo "Downloads Directory: http://$IPADDRESS1/private/Downloads" | sudo tee -a /etc/seedbox-from-scratch/users/$NEWUSER1.info
echo "Webmin: https://$IPADDRESS1:10000" | sudo tee -a /etc/seedbox-from-scratch/users/$NEWUSER1.info
echo "FTP: ftp://$IPADDRESS1:$NEWFTPPORT1/" | sudo tee -a /etc/seedbox-from-scratch/users/$NEWUSER1.info
echo "OpenVPN config: https://$IPADDRESS1/private/client.zip" | sudo tee -a /etc/seedbox-from-scratch/users/$NEWUSER1.info
sudo mkdir $HOMEJAILED1/private
sudo cp /etc/seedbox-from-scratch/users/$NEWUSER1.info $HOMEJAILED1/private/SBinfo.txt
cd $HOMEJAILED1/private
sudo ln -s $HOMEJAILED1/downloads/manual Downloads
cd ..
sudo chown -v -R $NEWUSER1: private
#sudo chmod 400 $HOMEJAILED1/$NEWUSER1.info
cd $HOMEJAILED1/
sudo cp /etc/seedbox-from-scratch/templates/crontabentries.template $HOMEJAILED1/crontabentries
sudo perl -pi -e "s/USERNAME/$NEWUSER1/g" $HOMEJAILED1/crontabentries
sudo chmod +x $HOMEJAILED1/crontabentries
sudo bash $HOMEJAILED1/crontabentries
sudo cp /etc/seedbox-from-scratch/webserver/* $HOMEJAILED1/private/
## Aliases
sudo echo "alias port='sudo netstat -tulpn | grep' " | sudo tee -a $HOMEJAILED1/.bashrc
sudo echo "alias ro='screen -dr root' " | sudo tee -a $HOMEJAILED1/.bashrc
sudo echo "alias vcsd5='vcs *.mp4 -U0 -i 5m -c 3 -H 200 -a 300/200 -o ~/movieinfo/save-filename.jpg' " | sudo tee -a $HOMEJAILED1/.bashrc
sudo echo "alias vcsd10='vcs *.mp4 -U0 -i 10m -c 3 -H 200 -a 300/200 -o ~/movieinfo/save-filename.jpg' " | sudo tee -a $HOMEJAILED1/.bashrc
sudo echo "alias vcsd15='vcs *.mp4 -U0 -i 15m -c 3 -H 200 -a 300/200 -o ~/movieinfo/save-filename.jpg' " | sudo tee -a $HOMEJAILED1/.bashrc
sudo mkdir $HOMEJAILED1/bin
cd $HOMEJAILED1/bin
sudo cp /etc/seedbox-from-scratch/templates/mtn.sh $HOMEJAILED1/bin
sudo chmod +x mtn.sh
sudo rm $HOMEJAILED1/crontabentries
sudo chown $NEWUSER1: -R $HOMEJAILED1/bin
sudo chown $NEWUSER1: -R $HOMEJAILED1/private/
sudo service webmin restart
set +x verbose
clear
echo ""
echo "Looks like your new user is created"
echo "User Login info can be found at https://$IPADDRESS1/private/SBinfo.txt"
echo "Download Data Directory is located at https://$IPADDRESS1/private "
echo ""
echo ""
echo "Here is Login info for SeedboxUser"
cat /etc/seedbox-from-scratch/users/$NEWUSER1.info
##################### LAST LINE ###########