forked from alisonperez/chits
-
Notifications
You must be signed in to change notification settings - Fork 15
/
tarlac_install.sh
executable file
·286 lines (226 loc) · 8.17 KB
/
tarlac_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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
#!/bin/bash
if [ -z "$SUDO_USER" ]; then
echo "$0 must be called from sudo. Try: 'sudo ${0}'"
exit 1
fi
echo "Press enter if unsure about the following questions"
echo "Do you want to upgrade all packages? ([y]/n)"
read UPGRADE_ALL
echo "Do you want to remove un-needed packages like games, music players and email? ([y]/n)"
read REMOVE
echo "Do you want to update your apt sources list to remove updates (for a faster install)? ([y]/n)"
read UPDATE_SOURCES
# These are for all configurations
PROGRAMS_TO_INSTALL='openssh-server wget vim'
if [ ! "${REMOVE}" = "n" ]; then
PROGRAMS_TO_REMOVE="gnome-games gnome-games-data openoffice.org-common f-spot ekiga evolution pidgin totem totem-common brasero rhythmbox synaptic gimp"
fi
if [ ! "${UPDATE_SOURCES}" = "n" ]; then
sed -i 's/^\(.*updates.*\)$/#\1/' /etc/apt/sources.list
sed -i 's/^\(.*security.*\)$/#\1/' /etc/apt/sources.list
apt-get update
fi
echo "
set bell-style none
\"\e[A\": history-search-backward
\"\e[B\": history-search-forward
\"\e[5C\": forward-word
\"\e[5D\": backward-word
\"\e\e[C\": forward-word
\"\e\e[D\": backward-word
\$if Bash
Space: magic-space
\$endif" > /home/$SUDO_USER/.inputrc
# Call "install wget" to add wget to the list of programs to install
install () {
PROGRAMS_TO_INSTALL="${PROGRAMS_TO_INSTALL} ${1}"
}
remove () {
PROGRAMS_TO_REMOVE="${PROGRAMS_TO_REMOVE} ${1}"
}
set_mysql_root_password () {
if [ ! "$MYSQL_ROOT_PASSWORD" ]; then
echo "Enter the root password to setup mysql with:"
read MYSQL_ROOT_PASSWORD
fi
echo "mysql-server mysql-server/root_password select ${MYSQL_ROOT_PASSWORD}" | debconf-set-selections
echo "mysql-server mysql-server/root_password_again select ${MYSQL_ROOT_PASSWORD}" | debconf-set-selections
export MYSQL_ROOT_PASSWORD
}
set_chits_live_password () {
if [ ! "$CHITS_LIVE_PASSWORD" ]; then
echo "Enter password for database user chits_live:"
read CHITS_LIVE_PASSWORD
fi
export CHITS_LIVE_PASSWORD
}
autoconnect_to_access_point() {
NETWORK_MANAGER_SYSTEMS_CONNECTION_DIR=/etc/NetworkManager/system-connections
DEFAULT_SSID_FILE="${NETWORK_MANAGER_SYSTEMS_CONNECTION_DIR}/Auto Default"
if [ -e "${DEFAULT_SSID_FILE}" ]; then
return
fi
echo "Setting up NetworkManager to automatically connect to access point with SSD 'default' during boot"
echo "Creating file at ${DEFAULT_SSID_FILE}"
SSID_IN_BYTES="68;101;102;97;117;108;116;"
# Get this by running ruby -i -e 'print "Default".unpack("U*").map{|c|"#{c};"}'
# Change "default" to be name of SSID
mkdir --parents "${NETWORK_MANAGER_SYSTEMS_CONNECTION_DIR}"
echo "
[connection]
id=Auto default
type=802-11-wireless
autoconnect=true
timestamp=1258702919
[ipv4]
method=auto
ignore-auto-routes=false
ignore-auto-dns=false
dhcp-send-hostname=false
never-default=false
[ipv6]
method=ignore
ignore-auto-routes=false
ignore-auto-dns=false
never-default=false
[802-11-wireless]
ssid=${SSID_IN_BYTES}
mode=infrastructure
channel=0
rate=0
tx-power=0
mtu=0
" > "${DEFAULT_SSID_FILE}"
chmod 600 "${DEFAULT_SSID_FILE}"
}
client () {
echo "Client"
install "tuxtype"
apt-get --assume-yes install $PROGRAMS_TO_INSTALL
apt-get --assume-yes remove $PROGRAMS_TO_REMOVE
if [ ! "${UPGRADE_ALL}" = "n" ]; then
apt-get --assume-yes upgrade
fi
autoconnect_to_access_point
# Make firefox launch automatically and point it at http://chits_server
AUTOSTART_DIR=$HOME/.config/autostart
mkdir --parents $AUTOSTART_DIR
echo "[Desktop Entry]
Type=Application
Encoding=UTF-8
Version=1.0
Name=No Name
Name[en_US]=Firefox
Comment[en_US]=Firefox
Comment=Firefox
Exec=/usr/bin/firefox -fullscreen -no-remote -P default http://192.168.2.2
X-GNOME-Autostart-enabled=true" > $AUTOSTART_DIR/firefox.desktop
# Create firefox profile with kiosk/fullscreen mode enabled
wget --output-document=tarlac_firefox_profile.zip http://github.com/mikeymckay/chits/raw/master/install/tarlac_firefox_profile.zip
# unzip this as the user to keep permissions right
su $SUDO_USER -c "unzip tarlac_firefox_profile.zip"
}
server () {
echo "Server"
set_mysql_root_password;
set_chits_live_password;
install "autossh curl"
apt-get --assume-yes install $PROGRAMS_TO_INSTALL
apt-get --assume-yes remove $PROGRAMS_TO_REMOVE
if [ ! "${UPGRADE_ALL}" = "n" ]; then
apt-get --assume-yes upgrade
fi
SERVER_IP_ADDRESS=192.168.2.2
SERVER_GATEWAY=192.168.2.1
echo "Setting static IP for server to: ${SERVER_IP_ADDRESS} and gateway to ${SERVER_GATEWAY}"
echo "
auto lo
iface lo inet loopback
auto wlan0
iface wlan0 inet static
address ${SERVER_IP_ADDRESS}
netmask 255.255.255.0
gateway ${SERVER_GATEWAY}
" > /etc/network/interfaces
autoconnect_to_access_point
wget --output-document=chits_install.sh http://github.com/mikeymckay/chits/raw/master/install/chits_install.sh
chmod +x chits_install.sh mysql_replication.sh setup_reverse_ssh_tunnel
./chits_install.sh
PATH_TO_DBSELECT="/var/www/chits/modules/_dbselect.php"
echo "Editing ${PATH_TO_DBSELECT} so that chits uses the mysql database chits_live"
sed -i 's/chits_development/chits_live/' $PATH_TO_DBSELECT
sed -i 's/chits_developer/chits_live/' $PATH_TO_DBSELECT
sed -i "s/\"password\"/\"${CHITS_LIVE_PASSWORD}\"/" $PATH_TO_DBSELECT
echo "Creating ssh keys so we can reverse ssh into the server"
su $SUDO_USER -c "mkdir /home/$SUDO_USER/.ssh"
su $SUDO_USER -c "ssh-keygen -N \"\" -f /home/$SUDO_USER/.ssh/id_rsa"
echo "Setting up reverse autossh to run when network comes up"
# TODO switch this to use more flexible script under separate github repo
# Generate a random port number to use in the 10000 - 20000 range
PORT_NUMBER=$[ ( $RANDOM % 10000 ) + 10000 ]
MONITORING_PORT_NUMBER=$[ ( $RANDOM % 10000 ) + 20000 ]
echo "#!/bin/sh
# ------------------------------
# Added by tarlac_install script
# ------------------------------
# See autossh and google for reverse ssh tunnels to see how this works
# When this script runs it will allow you to ssh into this machine even if it is behind a firewall or has a NAT'd IP address.
# From any ssh capable machine you just type ssh -p $PORT_MIDDLEMAN_WILL_LISTEN_ON localusername@middleman
# This is the username on your local server who has public key authentication setup at the middleman
USER_TO_SSH_IN_AS=chitstunnel
# This is the username and hostname/IP address for the middleman (internet accessible server)
MIDDLEMAN_SERVER_AND_USERNAME=chitstunnel@chits.ph
# Port that the middleman will listen on (use this value as the -p argument when sshing)
PORT_MIDDLEMAN_WILL_LISTEN_ON=${PORT_NUMBER}
# Connection monitoring port, don't need to know this one
AUTOSSH_PORT=${MONITORING_PORT_NUMBER}
# Ensures that autossh keeps trying to connect
AUTOSSH_GATETIME=0
export AUTOSSH_GATETIME AUTOSSH_PORT
su -c "autossh -f -N -R *:${PORT_MIDDLEMAN_WILL_LISTEN_ON}:localhost:22 ${MIDDLEMAN_SERVER_AND_USERNAME} -oLogLevel=error -oUserKnownHostsFile=/dev/null -oStrictHostKeyChecking=no" $USER_TO_SSH_IN_AS
" > /etc/network/if-up.d/reverse_ssh_tunnel
chmod +x /etc/network/if-up.d/reverse_ssh_tunnel
# echo "Uploading public key to lakota.vdomck.org"
# PUBLIC_KEY_FILENAME=/tmp/`hostname`.public_key
# cp /home/$SUDO_USER/.ssh/id_rsa.pub $PUBLIC_KEY_FILENAME
# cat "\n#{PORT_NUMBER}" >> $PUBLIC_KEY_FILENAME
# curl -F "file=@${PUBLIC_KEY_FILENAME}" lakota.vdomck.org:4567/upload
echo "To setup replication, put all clients and server on the network and ready, run: 'sudo /var/www/chits/install/mysql_replication'"
}
client_and_server () {
echo "Client & Server"
set_mysql_root_password;
set_chits_live_password;
client
server
}
client_with_mysql_replication () {
if [ ! "$MYSQL_ROOT_PASSWORD" ]; then
set_mysql_root_password;
fi
install "mysql-server"
client
echo "Replication needs to be completed by logging onto the master computer and running the mysql_replication.sh script"
}
while : # Loop forever
do
cat << !
${PROGRAMS_TO_INSTALL}
1. Client with mysql replication (recommended)
2. Server with Client (recommended)
3. Client lite
4. Server lite
5. Exit
!
echo -n " Your choice? : "
read choice
case $choice in
1) client_with_mysql_replication; exit ;;
2) client_and_server; exit ;;
3) client; exit ;;
4) server; exit ;;
5) exit ;;
*) echo "\"$choice\" is not valid "; sleep 2 ;;
esac
done
exit