diff options
author | David Walter Seikel | 2016-11-08 22:17:09 +1000 |
---|---|---|
committer | David Walter Seikel | 2016-11-08 22:17:09 +1000 |
commit | 3c279d6c3b66a7f5ad49e16180b69ffa94513dc5 (patch) | |
tree | 796f28d91cbc7339d8c5202c429bad07b4e27cd7 /InstallItAll.sh | |
parent | New README and TODO I forgot to commit before. (diff) | |
download | opensim-SC-3c279d6c3b66a7f5ad49e16180b69ffa94513dc5.zip opensim-SC-3c279d6c3b66a7f5ad49e16180b69ffa94513dc5.tar.gz opensim-SC-3c279d6c3b66a7f5ad49e16180b69ffa94513dc5.tar.bz2 opensim-SC-3c279d6c3b66a7f5ad49e16180b69ffa94513dc5.tar.xz |
Installation script.
Diffstat (limited to '')
-rwxr-xr-x | InstallItAll.sh | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/InstallItAll.sh b/InstallItAll.sh new file mode 100755 index 0000000..e421d09 --- /dev/null +++ b/InstallItAll.sh | |||
@@ -0,0 +1,111 @@ | |||
1 | #!/bin/bash | ||
2 | |||
3 | OSPATH="/opt/opensim" | ||
4 | MYSQL_HOST="localhost" | ||
5 | MYSQL_DB="InfiniteGrid" | ||
6 | MYSQL_USER="opensim" | ||
7 | OS_USER="opensim" | ||
8 | |||
9 | OSVER="8.2.1" | ||
10 | |||
11 | |||
12 | # Figure out where we are, most of this mess is to troll through soft links. | ||
13 | PRG="$0" | ||
14 | while [ -h "${PRG}" ] ; do | ||
15 | ls=$(ls -ld "${PRG}") | ||
16 | link=`expr "${ls}" : '.*-> \(.*\)$'` | ||
17 | if expr "${link}" : '.*/.*' > /dev/null; then | ||
18 | PRG="${link}" | ||
19 | else | ||
20 | PRG=$(dirname "${PRG}")/"${link}" | ||
21 | fi | ||
22 | done | ||
23 | PRGDIR=$(dirname "${PRG}") | ||
24 | pushd ${PRGDIR} >/dev/null | ||
25 | PRGDIR=$(pwd) | ||
26 | popd >/dev/null | ||
27 | |||
28 | # This should all be safe for pre existing installs that are being updated. | ||
29 | |||
30 | MYSQL_PASSWORD=$1 | ||
31 | # Try to get old database credentials if they exist. | ||
32 | if [ -f ${OSPATH}/config/config.ini ]; then | ||
33 | # Get the database credentials. | ||
34 | declare -A creds | ||
35 | while read -d ';' p; do | ||
36 | k=$(echo ${p} | cut -d '=' -f 1) | ||
37 | v=$(echo ${p} | cut -d '=' -f 2) | ||
38 | creds[${k}]="${v}" | ||
39 | done < <(sudo grep ConnectionString ${OSPATH}/config/config.ini | cut -d '"' -f 2) | ||
40 | # The above seems the best way to get bash to let the creds assignments survive outside the loop. | ||
41 | |||
42 | MYSQL_HOST="${creds[Data Source]}" | ||
43 | MYSQL_DB="${creds[Database]}" | ||
44 | MYSQL_USER="${creds[User ID]}" | ||
45 | MYSQL_PASSWORD="${creds[Password]}" | ||
46 | fi | ||
47 | if [ -z $MYSQL_PASSWORD ]; then | ||
48 | MYSQL_PASSWORD="OpenSimSucks${RANDOM}" | ||
49 | fi | ||
50 | |||
51 | USER=$(whoami) | ||
52 | |||
53 | echo "Installing software." | ||
54 | sudo apt-get install mysql-server tmux mono-complete uuid-runtime monit mc | ||
55 | sudo /etc/init.d/mysql restart | ||
56 | |||
57 | echo "Setting up mySQL." | ||
58 | mysql -u root -p -h localhost << zzzzEOFzzz | ||
59 | create database if not exists '$MYSQL_DB'; | ||
60 | create user '$OS_USER' identified by '$MYSQL_PASSWORD'; | ||
61 | create user '$OS_USER'@'localhost' identified by '$MYSQL_PASSWORD'; | ||
62 | grant all on $MYSQL_DB.* to '$OS_USER'; | ||
63 | grant all on $MYSQL_DB.* to '$OS_USER'@'localhost'; | ||
64 | FLUSH PRIVILEGES; | ||
65 | zzzzEOFzzz | ||
66 | |||
67 | echo "Setting up OpenSim." | ||
68 | sudo adduser --system --shell /bin/false --group $OS_USER | ||
69 | sudo addgroup $USER $OS_USER | ||
70 | |||
71 | sudo rm -fr $OSPATH/opensim-IG_* | ||
72 | sudo mkdir -p $OSPATH/opensim-IG_$OSVER | ||
73 | sudo cp -fr $PRGDIR/* $OSPATH/opensim-IG_$OSVER | ||
74 | |||
75 | cd $OSPATH | ||
76 | sudo ln -fs opensim-IG_$OSVER current | ||
77 | |||
78 | cd current | ||
79 | |||
80 | sudo chown -R $OS_USER:$OS_USER $OSPATH | ||
81 | sudo chmod -R 775 $OSPATH | ||
82 | sudo chmod -R a-x $OSPATH | ||
83 | sudo chmod -R a+X $OSPATH | ||
84 | sudo chmod -R g+w $OSPATH | ||
85 | sudo chmod -R a+x $OSPATH/current/scripts/*.sh | ||
86 | sudo chmod a+x $OSPATH/current/scripts/show-console | ||
87 | sudo chmod a+x $OSPATH/current/scripts/start-sim | ||
88 | sudo chmod ug+rwx config | ||
89 | sudo chmod g+s config | ||
90 | sudo chmod 600 config/config.ini | ||
91 | |||
92 | for dir in AssetFiles backups caches config db logs | ||
93 | do | ||
94 | sudo cp -fr $dir .. | ||
95 | sudo rm -fr $dir | ||
96 | sudo ln -fs ../$dir $dir | ||
97 | done | ||
98 | |||
99 | sudo sed -i "s@MYSQL_HOST@${MYSQL_HOST}@g" config/config.ini | ||
100 | sudo sed -i "s@MYSQL_DB@${MYSQL_DB}@g" config/config.ini | ||
101 | sudo sed -i "s@MYSQL_USER@${MYSQL_USER}@g" config/config.ini | ||
102 | sudo chmod 600 config/config.ini | ||
103 | sudo sed -i "s@MYSQL_PASSWORD@${MYSQL_PASSWORD}@g" config/config.ini | ||
104 | sudo chmod 600 config/config.ini | ||
105 | |||
106 | sudo cp scripts/opensim.tmux.conf /home/$OS_USER/.tmux.conf | ||
107 | sudo chown $USER /home/$OS_USER/.tmux.conf | ||
108 | sudo chmod 644 /home/$OS_USER/.tmux.conf | ||
109 | |||
110 | sudo scripts/fix_var_run.sh | ||
111 | sudo cat scripts/opensim-crontab.txt | sudo crontab -u $OS_USER - | ||