forked from mjnaderi/Sharif-Judge
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathsetup.sh
executable file
·143 lines (122 loc) · 3.74 KB
/
setup.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
#!/bin/bash
usage(){
cat << EOF
usage: $0 [-i install_dir] [-o public_dir] -u db_user -p db_password [-n site_name] [base_url]
base url will be set in config.php
OPTIONS:
-h show this message
-i install directory, default to current working directory
-o public directory to put index.php, default to be the public
directory in the same directory as install directory
-u database username
-p database password
-d database name
-n site name to display on top bar and construct base url for uit classes
base_url: Will be use to set base url for the site when site_name is not specified. The https:// part must be included
EOF
}
install="`pwd`"
public=''
db_user=''
db=''
db_password=''
base_url=''
site_name=''
while getopts "hi:o:u:p:d:n:" ops ; do
case "${ops}" in
h) usage ;;
i) install=${OPTARG};;
o) public=${OPTARG};;
u) db_user=${OPTARG};;
p) db_password=${OPTARG};;
d) db=${OPTARG};;
n) site_name=${OPTARG};;
*) usage; exit 1;;
esac
done
shift $((OPTIND-1))
base_url=$1
lw_site_name=`echo $site_name | tr '[:upper:]' '[:lower:]'`
if [ "$site_name" = "" ]; then
if [ "$base_url" = "" ]; then
usage; exit 1
fi
site_name="Wecode-Judge"
else
if [ "$base_url" = "" ] ; then
base_url="https://khmt.uit.edu.vn/laptrinh/`echo $site_name | tr '[:upper:]' '[:lower:]'`/"
fi
fi
if [ "$db_user" = "" ]; then
usage; exit 1
fi
echo $public
if [ "$public" = "" ]; then
public="$install/../public_html"
fi
if [ "$db" = '' ]; then
db="$db_user"
fi
#convert install and public to absolute path
if [ -d "$install" ]; then
install=`readlink -f $install`
else
echo "Installation directory: $install not found"
fi
if [ -d "$public" ]; then
public=`readlink -f $public`
else
echo "Public directory: $public not found"
fi
cat << EOF
"install=$install"
"public=$public"
"db_user=$db_user"
"db=$db"
"db_password=$db_password"
"base_url=$base_url"
"site_name=$site_name"
EOF
cd $install
git clone 'https://github.com/truongan/wecode-judge' .
git checkout working-updateci
cd $public
if cmp -s $install $public; then
echo "Installation dir and public dir are the same; that may pose security risk"
else
read -p "$public/index.php $public/assets $public/.htaccess will be delete permenantly. Continue?" -n 1 -r REPLY
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
rm index.html index.php .htacess
rm -rf ./assets
ln -s $install/index.php $install/assets $install/.htaccess $install/.user.ini .
else
echo "Abort"
exit 0
fi
fi
echo sed -i "s@system_path = 'system'@system_path = '$install/system'@g" index.php
sed -i "s@system_path = 'system'@system_path = '$install/system'@g" index.php
sed -i "s@application_folder = 'application'@application_folder = '$install/application'@g" index.php
cd $install/application/config
cp config.php.example config.php
cp database.php.example database.php
mkdir $install/application/session/
echo sed -i "s@base_url'] = ''@base_url'] = '$base_url'@g" config.php
sed -i "s@base_url'] = ''@base_url'] = '$base_url'@g" config.php
sed -i "s@index_page'] = 'index.php'@index_page'] = ''@g" config.php
sed -i "s@sess_save_path'] = NULL@sess_save_path'] = '$install/application/session/'@g" config.php
#UIT Related settings
#sed -i "s@cookie_path'] = '/'@cookie_path'] = '/laptrinh/$lw_site_name/'@g" config.php
#cp /opt/Login.php $install/application/controllers/Login.php
pwd
sed -i "s/homestead/$db_user/g" database.php
sed -i "s/secret/$db_password/g" database.php
echo sed -i "s/sharif/$db/g" database.php
sed -i "s/sharif/$db/g" database.php
cd $install/application/controllers
echo sed -i "s@_sitenametobereplace_@$site_name@g" Install.php
sed -i "s@_sitenametobereplace_@$site_name@g" Install.php
#Add default admin user, very dangerous and should not be enable by default
#php $install/index.php abc abc%40def.com random_string false