This repository has been archived by the owner on Oct 22, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·196 lines (192 loc) · 4.97 KB
/
install.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
#!/bin/bash
# Config
ENVIROMENT="dev";
TMP="/tmp/omni-setup";
if [[ "$1" != "" ]];then
ENVIROMENT="$1";
fi;
REGISTER_URL="http://api.omnimaga.org/register/$ENVIROMENT";
PHPMYADMIN_URL="http://downloads.sourceforge.net/project/phpmyadmin/phpMyAdmin/4.2.9.1/phpMyAdmin-4.2.9.1-english.tar.xz";
UNREALIRCD_URL="https://www.unrealircd.org/downloads/Unreal3.2.10.4.tar.gz";
# Functions for logging
section(){
# section <message>
echo "=> Starting Section \"$@\"";
}
log(){
# log <message>
echo "|-> $@";
}
sublog(){
# sublog <message>
echo "|--> $@";
}
info(){
# info <message>
echo "|-> INFO: $@";
}
subinfo(){
# subinfo <message>
echo "|--> INFO $@";
}
install(){
# install <packages>
apt-get -qq install $@;
}
updatesudo(){
# updatesudo <path>
if visudo -q -c -fdata/etc/$1;then
cp data/etc/$1 /etc/$1;
fi;
}
site(){
# site <site>
cp data/etc/apache2/sites-available/$1.conf /etc/apache2/sites-available/$1.conf;
a2ensite $1;
}
host(){
# host <host> [<ip>]
local ip=$2;
if [[ "$ip" == "" ]];then
ip="127.0.0.1";
fi;
HOSTS=$HOSTS"$ip\t$1\n";
}
download(){
local url=$1;
local path=$2;
echo -n " ";
rm -f $2;
wget --progress=dot $url -O $path 2>&1 | grep --line-buffered "%" | sed -u -e "s,\.,,g" | awk '{printf("\b\b\b\b%4s", $2)}';
echo -ne "\b\b\b\b";
}
clone(){
git clone -q $1 $2;
}
# Make sure the script is running as root
if [ "$(id -u)" != "0" ];then
echo "Running with sudo";
sudo $0;
exit;
fi;
# Actually run the install
section "Prep";
TMP="$TMP/temp/";
mkdir -p $TMP;
rm -rf $TMP/*;
section "Registering";
log "Getting IDs";
sublog "Hostname";
download "$REGISTER_URL/hostname" $TMP/hostname;
if [[ "$(cat $TMP/hostname)" == "" ]];then
download "$REGISTER_URL/name/$(hostname)" $TMP/hostname;
if [[ "$(cat $TMP/hostname)" == "" ]];then
hostname > $TMP/hostname;
fi;
fi;
info "HOSTNAME SET TO $(cat $TMP/hostname)";
download "$REGISTER_URL/replication_id" $TMP/replication_id;
info "REPLICATION ID SET TO $(cat $TMP/replication_id)";
hostname $(cat $TMP/hostname);
HOSTS="127.0.0.1\tlocalhost\n127.0.0.1\t$(hostname)\n::1\t\tlocalhost ip6-localhost ip6-loopback\nff02::1\t\tip6-allnodes\nff02::2\t\tip6-allrouters\n";
cp $TMP/hostname /etc/hostname;
section "Package Installation";
log "LAMP Stack";
install lamp-server^;
log "Node.js"
install nodejs;
log "SSH Server";
install ssh;
log "Git";
install git;
log "htop";
install htop;
log "zsh";
install zsh;
log "openssl";
install openssl;
log "build tools";
install build-essential;
install libcurl4-openssl-dev;
section "Custom Packages";
log "Omnimaga-Server-Utils";
sublog "Creating directories";
mkdir /opt/omnimaga/bin -p;
chown root:users /opt/omnimaga/bin;
sublog "Adding to path";
echo "export PATH=\$PATH:/opt/omnimaga/bin;" > /etc/profile.d/omnimaga-server-utils.sh;
. /etc/profile.d/omnimaga-server-utils.sh;
sublog "getting files";
rm -rf /opt/omnimaga/bin;
clone https://github.com/Omnimaga/server-utils.git /opt/omnimaga/bin/;
chmod a+x /opt/omnimaga/bin/*;
log "phpmyadmin";
sublog "Downloading";
download $PHPMYADMIN_URL $TMP/pma.tar.xz;
sublog "Extracting";
tar -C $TMP/ -xf $TMP/pma.tar.xz;
sublog "Copying";
rm -rf /var/www/phpmyadmin/;
mkdir -p /var/www/phpmyadmin/;
cp -R $TMP/phpMyAdmin-*/{*,.[a-zA-Z0-9]*} /var/www/phpmyadmin/;
cp data/var/www/phpmyadmin/config.inc.php /var/www/phpmyadmin/;
chown www-data:www-data /var/www/phpmyadmin -R;
log "unrealircd";
download $UNREALIRCD_URL $TMP/unreal.tar.gz;
adduser --system --no-create-home ircd;
rm -rf /opt/unrealircd/;
mkdir -p /opt/unrealircd;
tar -C $TMP/ -xf $TMP/unreal.tar.gz
cp -R $TMP/Unreal*/{*,.[a-zA-Z0-9]*} /opt/unrealircd;
cp data/opt/unrealircd/config.settings /opt/unrealircd;
pushd $(pwd);
cd /opt/unrealircd;
./curlinstall;
./Config -quick -nointro;
make;
popd;
section "Config";
log "Sudoers";
updatesudo sudoers;
log "Groups";
sublog "web";
groupadd -f web;
updatesudo sudoers.d/web;
sublog "ircd";
groupadd -f ircd;
updatesudo sudoers.d/ircd;
sublog "admin";
groupadd -f admin;
log "Services";
sublog "mysqld";
cp data/etc/mysql/conf.d/replication.cnf /etc/mysql/conf.d/replication.cnf;
sed -i "s/__SERVER_ID__/$(cat $TMP/replication_id)/" /etc/mysql/conf.d/replication.cnf;
service mysql reload;
sublog "apache2";
a2enmod -q vhost_alias;
a2enmod -q rewrite;
site omnimaga;
site pma;
sed -i "s/__SERVER_HOSTNAME__/$(cat $TMP/hostname)/" /etc/apache2/sites-available/pma.conf;
service apache2 reload;
log "Core";
sublog "shell";
cp data/etc/adduser.conf /etc/adduser.conf;
cp data/etc/default/useradd /etc/default/useradd;
grep -v nologin /etc/passwd | grep -v /bin/false | grep -v /bin/sync | grep -v /var/lib/libuuid | cut -d : -f 1 | while read user;do
if [[ "$user" != "root" ]];then
chsh -s /bin/zsh $user;
info "Changed shell for $user";
done;
sublog "hosts";
host omnimaga.org;
host www.omnimaga.org;
host $(hostname).omnimaga.org;
host pma.$(hostname).omnimaga.org;
echo -e $HOSTS > /etc/hosts;
sublog "phpmyadmin";
echo -n "root@localhost mysql pass:";
read -s pass;
cat /var/www/phpmyadmin/examples/create_tables.sql | mysql -u root -p"$pass";
echo -e "\n\n\n";
echo "Install Finished";