aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/InstallItAll.sh
blob: 5e19a7d58f8d33cb64638037ef445a57ca4747d3 (plain)
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
#!/bin/bash

MYSQL_HOST="localhost"
MYSQL_DB="opensim_SC"
MYSQL_USER="opensim_SC"

OS_VER="0.9.0.1"

source scripts/common.sh
getPrgDir

# This should all be safe for pre existing installs that are being updated.

MYSQL_PASSWORD=$1
# Try to get old database credentials if they exist.
if [ -f ${OS_PATH}/config/config.ini ]; then
    # Get the database credentials.
    declare -A creds
    while read -d ';' p; do
	k=$(echo ${p} | cut -d '=' -f 1)
	v=$(echo ${p} | cut -d '=' -f 2)
	creds[${k}]="${v}"
    done < <(sudo grep ConnectionString ${OS_PATH}/config/config.ini | cut -d '"' -f 2)
    # The above seems the best way to get bash to let the creds assignments survive outside the loop.

    MYSQL_HOST="${creds[Data Source]}"
    MYSQL_DB="${creds[Database]}"
    MYSQL_USER="${creds[User ID]}"
    MYSQL_PASSWORD="${creds[Password]}"
fi
if [ -z $MYSQL_PASSWORD ]; then
    MYSQL_PASSWORD="OpenSimSucks${RANDOM}"
fi

USER=$(whoami)

echo "Installing into ${OS_PATH}, as user ${OS_USER} ."
echo "Using MySQL host:${MYSQL_HOST} database:${MYSQL_DB} user:${MYSQL_USER} password:${MYSQL_PASSWORD} ."


echo "Installing and compiling software."
sudo apt install mariadb-server tmux mono-complete mono-devel nunit uuid-runtime monit
# nant is done separately, coz it was removed from Debian for some mysterious reason.
sudo apt install nant
sudo /etc/init.d/mysql restart


echo "Setting up OpenSim users.  This next prompt asks for your MySQL root users password."
# "create user if not exists" doesn't exist until MySQL 5.7, so we have to put up with a warning, which we can ignore.
# Recent Debian based systems install with a passwordless root account, but it only works if run as the OS root user.
# Otherwise you can't get in.  Yep, the -p seems to still be needed.
sudo mysql -u root -p -h localhost << zzzzEOFzzz
create database if not exists $MYSQL_DB;
create user if not exists '$MYSQL_USER' identified by '$MYSQL_PASSWORD';
create user if not exists '$MYSQL_USER'@localhost identified by '$MYSQL_PASSWORD';
grant all on $MYSQL_DB.* to '$MYSQL_USER';
grant all on $MYSQL_DB.* to '$MYSQL_USER'@localhost;
FLUSH PRIVILEGES;
zzzzEOFzzz

sudo adduser --system --shell /bin/bash --group ${OS_USER}
sudo addgroup ${USER} ${OS_USER}


echo "Setting up OpenSim."
sudo rm -fr   ${OS_PATH}/opensim-SC_*
sudo mkdir -p ${OS_PATH}/opensim-SC_${OS_VER}
sudo cp -fr $PRGDIR/* ${OS_PATH}/opensim-SC_${OS_VER}
cd ${OS_PATH}
if [ ! -h current ]; then
    sudo ln -fs opensim-SC_${OS_VER} current
fi

cd current
for dir in AssetFiles backups caches config db logs
do
    if [ ! -d ../$dir ]; then
	sudo cp -fr example/$dir ..
    fi
done

pushd ../config/ROBUST >/dev/null
sudo ln -fs ../../current/scripts/common.sh common.sh
sudo ln -fs ../../current/scripts/start-sim start-sim
sudo ln -fs ../../current/scripts/start-sim stop-sim
sudo sed -i "s@OS_PATH@${OS_PATH}@g" opensim-monit.conf
popd >/dev/null

sudo cp bin/config-include/config_* ../config/
sudo ln -fs  config_localhost.ini ../config/config.ini
sudo sed -i "s@MYSQL_HOST@${MYSQL_HOST}@g" ../config/config_IG.ini
sudo sed -i "s@MYSQL_DB@${MYSQL_DB}@g" ../config/config_IG.ini
sudo sed -i "s@MYSQL_USER@${MYSQL_USER}@g" ../config/config_IG.ini

sudo sed -i "s@MYSQL_HOST@${MYSQL_HOST}@g" ../config/config_MG.ini
sudo sed -i "s@MYSQL_DB@${MYSQL_DB}@g" ../config/config_MG.ini
sudo sed -i "s@MYSQL_USER@${MYSQL_USER}@g" ../config/config_MG.ini

sudo sed -i "s@MYSQL_HOST@${MYSQL_HOST}@g" ../config/config_localhost.ini
sudo sed -i "s@MYSQL_DB@${MYSQL_DB}@g" ../config/config_localhost.ini
sudo sed -i "s@MYSQL_USER@${MYSQL_USER}@g" ../config/config_localhost.ini

sudo chmod 600 ../config/*.ini
sudo sed -i "s@MYSQL_PASSWORD@${MYSQL_PASSWORD}@g" ../config/config_IG.ini
sudo sed -i "s@MYSQL_PASSWORD@${MYSQL_PASSWORD}@g" ../config/config_MG.ini
sudo sed -i "s@MYSQL_PASSWORD@${MYSQL_PASSWORD}@g" ../config/config_localhost.ini
sudo chmod 600 ../config/*.ini

if [ ! -f /home/${OS_USER}/.tmux.conf ]; then
    sudo cp scripts/install/opensim.tmux.conf /home/${OS_USER}/.tmux.conf
    sudo chown ${OS_USER}:${OS_USR} /home/${OS_USER}/.tmux.conf
    sudo chmod 644 /home/${OS_USER}/.tmux.conf
fi


echo "Building OpenSim."
sudo chown -R ${USER}:${USER} ${OS_PATH} *
./BuildIt.sh


cd scripts/install
sudo chmod a+x secure.sh
sudo ./secure.sh

echo "Done installing OpenSim."