-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·134 lines (110 loc) · 4.41 KB
/
setup.sh
File metadata and controls
executable file
·134 lines (110 loc) · 4.41 KB
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
#!/bin/bash
COMPETITION="RoboBoat"
HERE=$(cd -- $(dirname ${BASH_SOURCE[0]}) > /dev/null && pwd)
cd -- "$HERE"
###
# Setup this server if it is running Ubuntu
###
setup_ubuntu() {
## Install new apt-get repo
sudo add-apt-repository -y ppa:webupd8team/java
## Update Ubuntu
wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
echo 'deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main' | sudo tee /etc/apt/sources.list.d/google-chrome.list
sudo apt-get -y update
## Install key apps
sudo apt-get -y install vim google-chrome-stable curl jq \
openssh-server \
git maven python-software-properties debconf-utils apache2
echo "oracle-java8-installer shared/accepted-oracle-license-v1-1 select true" | sudo debconf-set-selections
sudo apt-get -y install oracle-java8-installer #apt-get is unable to find java9 these days... revisit later
## Clean up old packages
sudo apt -y autoremove
## Install Chrome in Launcher
gsettings set com.canonical.Unity.Launcher favorites "['application://org.gnome.Nautilus.desktop', 'application://google-chrome.desktop', 'application://firefox.desktop', 'application://org.gnome.Software.desktop', 'application://unity-control-center.desktop', 'unity://running-apps', 'application://gnome-terminal.desktop', 'unity://expo-icon', 'unity://devices']" || echo "No X11 available while running this script"
## Open ports & setup Apache webserver
sudo ufw allow 'Apache Full'
sudo sed -i 's/\/var\/www\/html/\/home\/robonation\/roboboat\/roboboat-server\/src\/main\/webapp/' /etc/apache2/sites-available/000-default.conf
sudo sed -i 's/\/var\/www/\/home\/robonation\/roboboat\/roboboat-server\/src\/main\/webapps/' /etc/apache2/apache2.conf
##Boot to console
sudo sed -i 's/^GRUB_CMDLINE_LINUX=""//' /etc/default/grub && sudo sed -i 's/^GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"/\n### Boot to UI\n#GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"\n#GRUB_CMDLINE_LINUX=""\n\n### Boot to console\nGRUB_CMDLINE_LINUX_DEFAULT="text"\nGRUB_TERMINAL=console\n/g' /etc/default/grub
sudo update-grub
sudo systemctl set-default multi-user.target
## Make this script run as a service
sudo cp competition-setup /etc/init.d/competition-setup
sudo update-rc.d competition-setup defaults
}
###
# Check when was the last time this script was ran and updates it is >24h
# Return 0 if up-to-date or successfully update; 1 if no network connection
##
auto_update_script() {
if ! ping -q -c 1 -W 1 google.com >/dev/null; then
echo "===> Internet access not available. Skip auto-update"
return 1
fi
file="last_setup.time"
LASTTIME=0
if [ -s $file ]; then
LASTTIME=`cat $file`
fi
NOW=`date +%s`
# Update last_setup.time to now
echo "$NOW" > last_setup.time
let YESTERDAY="$NOW - (3600 * 24)"
if [ "$YESTERDAY" -gt "$LASTTIME" ]; then
echo " Updating this script since last pull is >24h"
git pull
printf " Restarting setup script \n\n"
exec $(readlink -f "$0")
fi
return 0
}
###
# RoboBoat setup
###
setup_roboboat() {
file="/home/robonation/roboboat"
if [ ! -d $file ]; then
git clone https://github.com/robonation/roboboat-server.git "$file/roboboat-server/"
fi
sudo mkdir -p /etc/roboboat
sudo chown robonation:robonation /etc/roboboat
sudo cp $file/roboboat-server/roboboat-server /etc/init.d/roboboat-server
sudo update-rc.d roboboat-server defaults
}
###
# RobotX setup
###
setup_robotx() {
echo "RobotX not yet implemented"
}
###
#
###
check_git_setup() {
file="/home/robonation/.git-credentials"
if [ ! -f $file ]; then
printf "*** Unable to setup competition software as git-setup is not complete on this server. Please run 'git config --global credential.helper store && git clone https://github.com/robonation/roboboat-server /tmp/roboboat-server && rm -rf /tmp/roboboat-server'\n\n"
exit 1
fi
}
###
# Main script
###
printf "*** RoboNation's server setup script \n (note: robonation password is on the back of the server)\n"
## 1. Check if script is up-to-date
auto_update_script;
DISTRO="$(uname -v)"
case $DISTRO in
*"Ubuntu"*) setup_ubuntu;;
*) echo "This script does not support '$DISTRO'";;
esac
check_git_setup;
case $COMPETITION in
*"RoboBoat"*) setup_roboboat;;
*"RobotX"*) setup_robotx;;
*) echo "This script does not support competition '$COMPETITION'";;
esac
printf "*** RoboNation's server setup script successfull completed its run ***\n"
exit 0