-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcapri.sh
555 lines (459 loc) · 16.9 KB
/
capri.sh
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
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
#!/bin/sh
SKINFNAME="Capri"
SKINDIRNAME="capri"
SOURCEPATH="https://raw.githubusercontent.com/cmsnegar/Capri/master/"
DATADIR="/usr/local/directadmin/data/skin_data"
PLUGINPATH="/usr/local/directadmin/data/skin_data/$SKINDIRNAME"
THISPATH=$PWD
LICENSE=CS_a1234567890b
# install the skin
doInstall()
{
echo ""
echo -e "\e[1;37mThis script will install and setup $SKINFNAME Skin for DirectAdmin Control panel."
echo -e "\e[40;37m\e[0m"
echo ""
if [ "$SKNAME" = "" ]; then
echo -n "Please choose a skin name or press enter to use default [$SKINFNAME]: "
read SKNAME
fi
if [ "$SKNAME" = "" ]; then
SKNAME="$SKINFNAME"
fi
SKINPATH="/usr/local/directadmin/data/skins/$SKNAME"
echo -e "Skin name will be:\e[1;37m $SKNAME \e[40;37m\e[0m"
echo ""
echo -n "Please choose a color set (1: blue, 2: grey) [1]: "
read SKCOLOR
echo -n "Would you like to install the login page skin? (y/n) [y]: "
read SKLOGIN
echo ""
echo "Capri skin also have a email-only version for users who have a email services."
echo -n "Would you like to install a second email-only skin (will be called $SKNAME-mail)? (y/n) [n]: "
read SKMAILONLY
echo ""
if [ -n $ARG1 ]; then
LICENSE="$ARG1"
fi
echo $1
if [ ! -d "$DATADIR" ]; then
mkdir $DATADIR
fi
chmod 777 $DATADIR
chown diradmin:diradmin $DATADIR
if [ ! -d "$PLUGINPATH" ]; then
mkdir $PLUGINPATH
fi
chmod 777 $PLUGINPATH
chown diradmin:diradmin $PLUGINPATH
if [ "$OVERWRITE" = "" ]; then
if [ -d "$SKINPATH" ]; then
echo -n "Directory $SKINPATH already exists. Do you want to delete it? (y/n) [y]: "
read ACT1
echo
if [ "$ACT1" = "n" ]; then
echo "Instalation aborted by user.";
exit 0;
else
rm -fr $SKINPATH/*
rmdir $SKINPATH
fi
fi
fi
if [ ! -d "$SKINPATH" ]; then
mkdir $SKINPATH
fi
chmod 755 $SKINPATH
chown diradmin:diradmin $SKINPATH
cd $SKINPATH
echo -n "Downloading skin files... "
if [ "$SKCOLOR" = "2" ]; then
wget -q -O $SKINPATH/$SKINDIRNAME.tar.gz $SOURCEPATH/capri_grey.tar.gz
else
wget -q -O $SKINPATH/$SKINDIRNAME.tar.gz $SOURCEPATH/capri.tar.gz
fi
# aca chequeo si el archivo se descargo
if [ ! -f "$SKINPATH/$SKINDIRNAME.tar.gz" ]; then
echo -e "\e[1;31m Failed \e[40;37m\e[0m"; echo""
echo -e "*** An error occur while downloading files. Please try again or contact support."
echo ""
cd $THISPATH
exit 0;
fi
# aca chequeo si pesa menos de 150k
if [ `du -k $SKINPATH/$SKINDIRNAME.tar.gz |awk '{print $1}'` -lt 200 ]; then
# Si pesa menos lo abro a ver que contiene
if [ `du -b $SKINPATH/$SKINDIRNAME.tar.gz |awk '{print $1}'` -lt 10 ]; then
FILEDATA=`cat $SKINPATH/$SKINDIRNAME.tar.gz`
fi
# Si contiene la palabra "license" es por que es una licencia incorrecta
if [ "$FILEDATA" = "license" ]; then
rm -f $SKINPATH/$SKINDIRNAME.tar.gz
echo -e "\e[1;31m Failed \e[40;37m\e[0m"; echo""
echo -e "*** The license key entered is not active or it is invalid."
echo ""
cd $THISPATH
exit 0;
fi
# Si se descargo otra cosa, borro y termino
rm -f $SKINPATH/$SKINDIRNAME.tar.gz
echo -e "\e[1;31m Failed \e[40;37m\e[0m"; echo""
echo -e "*** An error occur while downloading files. Cannot reach source download URL. Please try again or contact support."
echo ""
cd $THISPATH
exit 0;
fi
echo -e "\e[1;32m Done \e[40;37m\e[0m "
echo -n "Decompressing skin files... "
tar xfz $SKINPATH/$SKINDIRNAME.tar.gz
if [ ! -f "$SKINPATH/files_admin.conf" ]; then
echo -e "\e[1;31m Failed \e[40;37m\e[0m"; echo""
echo -e "*** An error occur while decompressing files. Please try again or contact support."
echo ""
rm -fr $SKINPATH/*
rm -fr $PLUGINPATH/*
rmdir $SKINPATH
rmdir $PLUGINPATH
cd $THISPATH
exit 0;
fi
echo -e "\e[1;32m Done \e[40;37m\e[0m "
# instalo mail only skin
if [ "$SKMAILONLY" = "y" ]; then
if [ ! -d "$SKINPATH-mail" ]; then
mkdir $SKINPATH-mail
fi
chmod 755 $SKINPATH-mail
chown diradmin:diradmin $SKINPATH-mail
cd $SKINPATH-mail
echo -n "Installing email-only skin... "
wget -q -O $SKINPATH-mail/$SKINDIRNAME-mail.tar.gz $SOURCEPATH/capri_mail.tar.gz
if [ ! -f "$SKINPATH-mail/$SKINDIRNAME-mail.tar.gz" ]; then
echo -e "\e[1;31m Failed \e[40;37m\e[0m"; echo""
echo -e "*** An error occur while downloading files. Please try again or contact support."
echo ""
cd $THISPATH
else
if [ `du -k $SKINPATH-mail/$SKINDIRNAME-mail.tar.gz |awk '{print $1}'` -lt 50 ]; then
rm -f $SKINPATH-mail/$SKINDIRNAME-mail.tar.gz
rm -f $SKINPATH-mail/*
rmdir $SKINPATH-mail
echo -e "\e[1;31m Failed \e[40;37m\e[0m";
echo -e "*** An error occur while downloading email-only skin files. Mail-only skin not installed."
cd $THISPATH
else
tar xfz $SKINPATH-mail/$SKINDIRNAME-mail.tar.gz
echo -n "1" > $PLUGINPATH/emailonly
echo -e "\e[1;32m Done \e[40;37m\e[0m "
cd $THISPATH
fi
fi
fi
# instalo login page
if [ "$SKLOGIN" != "n" ]; then
echo -n "Installing login page skin... "
if [ "$SKCOLOR" = "2" ]; then
wget -q -O /usr/local/directadmin/data/templates/capri_login.tar.gz $SOURCEPATH/capri_login_grey.tar.gz
else
wget -q -O /usr/local/directadmin/data/templates/capri_login.tar.gz $SOURCEPATH/capri_login.tar.gz
fi
if [ -f "/usr/local/directadmin/data/templates/capri_login.tar.gz" ]; then
if [ `du -b /usr/local/directadmin/data/templates/capri_login.tar.gz |awk '{print $1}'` -lt 3000 ]; then
rm -f /usr/local/directadmin/data/templates/capri_login.tar.gz
echo -e "\e[1;31m Failed \e[40;37m\e[0m";
echo -e "*** An error occur while downloading login page files. Login page not installed."
else
cd /usr/local/directadmin/data/templates/
tar xfz capri_login.tar.gz
chmod 755 /usr/local/directadmin/data/templates/login_images
chown diradmin:diradmin /usr/local/directadmin/data/templates/login_images
chown diradmin:diradmin /usr/local/directadmin/data/templates/login_images/*
chown diradmin:diradmin /usr/local/directadmin/data/templates/login.html
rm -f capri_login.tar.gz
echo -n "1" > $PLUGINPATH/loginpage
echo -e "\e[1;32m Done \e[40;37m\e[0m "
fi
else
rm -f /usr/local/directadmin/data/templates/capri_login.tar.gz
echo -e "\e[1;31m Failed \e[40;37m\e[0m";
echo -e "*** An error occur while downloading login page files. Login page not installed."
fi
fi
echo -n "Setting permissions... "
chown -R diradmin:diradmin $SKINPATH/*
find $SKINPATH/ -type f -exec chmod 755 {} \;
chmod 777 $SKINPATH/inc
chown diradmin:diradmin $SKINPATH
mv $SKINPATH/skin_data/cron.sh $PLUGINPATH/cron.sh
rm -f $SKINPATH/skin_data/*
rmdir $SKINPATH/skin_data
chmod 666 $PLUGINPATH/*
chmod 755 $PLUGINPATH/cron.sh
chmod 777 $PLUGINPATH
if [ -f "$SKINPATH-mail/header.html" ]; then
find $SKINPATH-mail/ -type f -exec chmod 755 {} \;
chown -R diradmin:diradmin $SKINPATH-mail/*
chown diradmin:diradmin $SKINPATH-mail
fi
echo -n "$LICENSE" > $PLUGINPATH/license
echo -n "$SKNAME" > $PLUGINPATH/name
echo -n "$SKCOLOR" > $PLUGINPATH/color
chmod 777 $PLUGINPATH/license
# seteo cron
perl -ni -e 'unless (m/Added by $SKINFNAME/) { print }' /etc/crontab 2>&1
perl -ni -e 'unless (m/Added by $SKINFNAME/) { print }' /etc/crontab 2>&1
echo "* * * * * root $PLUGINPATH/cron.sh > /dev/null 2>&1 # Added by $SKINFNAME" >> /etc/crontab
echo -e "\e[1;32m Done \e[40;37m\e[0m "
# finalizo la instalacion
echo "";echo ""
echo -e "\e[1;37mCongratulations! $SKINFNAME has been installed. Log in you control panel and switch to $SKNAME skin.\e[40;37m\e[0m"
echo ""
exit 0;
}
####################################################################################################################################################
doUpdate()
{
echo ""
echo -e "Updating $SKINFNAME."
SKINPATH="/usr/local/directadmin/data/skins/$OLDSKINNAME"
if [ -f "$PLUGINPATH/color" ]; then
SKCOLOR=`cat $PLUGINPATH/color`
fi
if [ ! -f "$PLUGINPATH/color" ]; then
echo -n "Please choose a color set (1: blue, 2: grey) [1]: "
read SKCOLOR
fi
if [ -f "$PLUGINPATH/license" ]; then
LICENSE=`cat $PLUGINPATH/license`
else
if [ -f "$SKINPATH/inc/license" ]; then
LICENSE=`cat $PLUGINPATH/license`
fi
fi
if [ "$LICENSE" = "" ]; then
echo ""
echo -n "We can't find you license key. Please insert your license key: "
read LICENSE
echo ""
fi
if [ ! -d "$DATADIR" ]; then
mkdir $DATADIR
fi
chmod 777 $DATADIR
chown diradmin:diradmin $DATADIR
if [ ! -d "$PLUGINPATH" ]; then
mkdir $PLUGINPATH
fi
chmod 777 $PLUGINPATH
chown -R diradmin:diradmin $PLUGINPATH
if [ ! -d "$SKINPATH" ]; then
mkdir $SKINPATH
fi
chmod 755 $SKINPATH
chown -R diradmin:diradmin $SKINPATH
cd $SKINPATH
echo -n "Downloading skin files... "
if [ "$SKCOLOR" = "2" ]; then
wget -q -O $SKINPATH/$SKINDIRNAME.tar.gz $SOURCEPATH/capri_grey.tar.gz
else
wget -q -O $SKINPATH/$SKINDIRNAME.tar.gz $SOURCEPATH/capri.tar.gz
fi
# aca chequeo si el archivo se descargo
if [ ! -f "$SKINPATH/$SKINDIRNAME.tar.gz" ]; then
echo -e "\e[1;31m Failed \e[40;37m\e[0m"; echo""
echo -e "*** An error occur while downloading files. Please try again or contact support."
echo ""
cd $THISPATH
exit 0;
fi
# aca chequeo si pesa menos de 150k
if [ `du -k $SKINPATH/$SKINDIRNAME.tar.gz |awk '{print $1}'` -lt 200 ]; then
# Si pesa menos lo abro a ver que contiene
if [ `du -b $SKINPATH/$SKINDIRNAME.tar.gz |awk '{print $1}'` -lt 10 ]; then
FILEDATA=`cat $SKINPATH/$SKINDIRNAME.tar.gz`
fi
# Si contiene la palabra "license" es por que es una licencia incorrecta
if [ "$FILEDATA" = "license" ]; then
rm -f $SKINPATH/$SKINDIRNAME.tar.gz
echo -e "\e[1;31m Failed \e[40;37m\e[0m"; echo""
echo -e "*** The license key entered is not active or it is invalid."
echo ""
cd $THISPATH
exit 0;
fi
# Si se descargo otra cosa, borro y termino
rm -f $SKINPATH/$SKINDIRNAME.tar.gz
echo -e "\e[1;31m Failed \e[40;37m\e[0m"; echo""
echo -e "*** An error occur while downloading files. Cannot reach source download URL. Please try again or contact support."
echo ""
cd $THISPATH
exit 0;
fi
echo -e "\e[1;32m Done \e[40;37m\e[0m "
echo -n "Decompressing skin files... "
tar xfz $SKINPATH/$SKINDIRNAME.tar.gz
if [ ! -f "$SKINPATH/files_admin.conf" ]; then
echo -e "\e[1;31m Failed \e[40;37m\e[0m"; echo""
echo -e "*** An error occur while decompressing files. Please try again or contact support."
echo ""
cd $THISPATH
exit 0;
fi
echo -e "\e[1;32m Done \e[40;37m\e[0m "
if [ -f "$PLUGINPATH/loginpage" ]; then
echo -n "Installing login page skin... "
if [ "$SKCOLOR" = "2" ]; then
wget -q -O /usr/local/directadmin/data/templates/capri_login.tar.gz $SOURCEPATH/capri_login_grey.tar.gz
else
wget -q -O /usr/local/directadmin/data/templates/capri_login.tar.gz $SOURCEPATH/capri_login.tar.gz
fi
cd /usr/local/directadmin/data/templates/
tar xfz capri_login.tar.gz
chmod 755 /usr/local/directadmin/data/templates/login_images
chown diradmin:diradmin /usr/local/directadmin/data/templates/login_images
chown diradmin:diradmin /usr/local/directadmin/data/templates/login_images/*
chown diradmin:diradmin /usr/local/directadmin/data/templates/login.html
rm -f capri_login.tar.gz
echo -n "1" > $PLUGINPATH/loginpage
echo -e "\e[1;32m Done \e[40;37m\e[0m "
fi
echo -n "Setting permissions... "
mv $SKINPATH/skin_data/cron.sh $PLUGINPATH/cron.sh
rm -f $SKINPATH/skin_data/*
rmdir $SKINPATH/skin_data
chmod 666 $PLUGINPATH/*
chmod 755 $PLUGINPATH/cron.sh
chmod 777 $PLUGINPATH
chown diradmin:diradmin $SKINPATH/*
find $SKINPATH/ -type f -exec chmod 755 {} \;
chmod 777 $SKINPATH/inc
if [ ! -f "$PLUGINPATH/name" ]; then
echo -n "$OLDSKINNAME" > $PLUGINPATH/name
fi
echo -n "$LICENSE" > $PLUGINPATH/license
echo -n "$SKCOLOR" > $PLUGINPATH/color
chmod 666 $PLUGINPATH/license
# seteo cron
perl -ni -e 'unless (m/Added by $SKINFNAME/) { print }' /etc/crontab 2>&1
perl -ni -e 'unless (m/Added by $SKINFNAME/) { print }' /etc/crontab 2>&1
echo "* * * * * root $PLUGINPATH/cron.sh > /dev/null 2>&1 # Added by $SKINFNAME" >> /etc/crontab
echo -e "\e[1;32m Done \e[40;37m\e[0m "
if [ -f "$PLUGINPATH/imagelogo" ]; then
mv $SKINPATH/images/logo.gif $SKINPATH/images/logo.gif.bak
cp $PLUGINPATH/imagelogo $SKINPATH/images/logo.gif
chown diradmin:diradmin $SKINPATH/images/logo.gif
fi
# custom logo
if [ -d "$PLUGINPATH/logos" ]; then
cd $PLUGINPATH/logos
for file in *; do
{
if [ -f "$PLUGINPATH/logos/$file" ] && [ ! -f "$SKINPATH/images/custom/$file.gif" ]; then
cp $PLUGINPATH/logos/$file $SKINPATH/images/custom/$file.gif
fi
}
done;
chmod 666 $SKINPATH/images/custom/*
chown diradmin:diradmin $SKINPATH/images/custom/*
chmod 666 $PLUGINPATH/logos/*
if [ -f "/usr/local/directadmin/data/admin/reseller.list" ]; then
RESELLERS=`cat /usr/local/directadmin/data/admin/reseller.list`
echo -n "" > $SKINPATH/files_custom.conf
for LINE in $RESELLERS; do
{
echo "IMG_RESLOGO_$LINE=images/custom/$LINE.gif" >> $SKINPATH/files_custom.conf
}
done;
fi
fi
# finalizo la instalacion
echo "";echo ""
echo -e "\e[1;37mCongratulations! $SKINFNAME has been updated.\e[40;37m\e[0m"
echo ""
exit 0;
}
####################################################################################################################################################
echo ""
echo ""
echo "________________________________________________________________________________________"
echo ""
echo ""
if [ "$1" = "--license" ] && [ "$2" != "" ]; then
ARG1=$2
fi
if [ -f "/usr/local/directadmin/data/skin_data/$SKINDIRNAME/name" ]; then
if [ -f "/usr/local/directadmin/data/skin_data/$SKINDIRNAME/name" ]; then
OLDSKINNAME=`cat /usr/local/directadmin/data/skin_data/$SKINDIRNAME/name`
fi
if [ "$OLDSKINNAME" != "" ]; then
echo -n "$SKINFNAME skin, named $OLDSKINNAME was found in the server. Do you want to update this skin? (y/n) [y]: "
read UPDATE
echo
if [ "$UPDATE" != "n" ]; then
doUpdate
else
echo -n "Do you want to make a fresh install? (y/n) [y]: "
read FRESHINSTALL
echo
if [ "$FRESHINSTALL" != "n" ]; then
doInstall
else
echo "Nothing to do. Good bye!"
fi
fi
else
echo "$SKINFNAME skin was found in the server, but we can't determine the name."
echo -n "Please enter the skin name o press RETURN to a fresh install: ";
read OLDSKINNAME
echo
if [ "$OLDSKINNAME" = "" ]; then
doInstall
else
if [ -d "/usr/local/directadmin/data/skins/$OLDSKINNAME" ]; then
doUpdate
else
echo -n "We cannot found $OLDSKINNAME location. Do you want to make a fresh install? (y/n) [y]: "
read FRESHINSTALL
echo
if [ "$FRESHINSTALL" != "n" ]; then
doInstall
else
echo "Nothing to do. Good bye!"
fi
fi
fi
fi
else
cd /usr/local/directadmin/data/skins
for dir in *; do
{
if [ -f "/usr/local/directadmin/data/skins/$dir/inc/data" ]; then
OLDSKINNAME="$dir"
fi
}
done;
if [ -z "$OLDSKINNAME" ]; then
doInstall
else
echo -n "Is $OLDSKINNAME the name of your actual installation of $SKINFNAME skin? (y/n) [y]: "
read ISM
fi
if [ "$ISM" = "n" ]; then
doInstall
else
SKNAME="$OLDSKINNAME"
OVERWRITE="1"
OLDLICENSE=`cat /usr/local/directadmin/data/skins/$OLDSKINNAME/inc/license`
if [ "$OLDLICENSE" != "" ]; then
echo -n "Is $OLDLICENSE the license key of you Marina skin= (y/n) [y]: "
read ISL
if [ "$ISM" = "n" ]; then
doInstall
else
LICENSE="$OLDLICENSE"
doInstall
fi
fi
fi
fi
exit 0;