This repository has been archived by the owner on Nov 14, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathpostinst
executable file
·171 lines (131 loc) · 5.69 KB
/
postinst
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
#!/bin/bash
echo "Resetting permissions ..."
chmod -R g+w /home/ubuntu/workspace
#don't do this, eats space! chown -R ubuntu:ubuntu /home/ubuntu > /dev/null 2>&1
chown -R ubuntu:ubuntu /var/c9sdk/plugins/c9.ide.cs50* > /dev/null 2>&1
chown -R ubuntu:ubuntu /var/c9sdk/configs/ > /dev/null 2>&1
chown -R ubuntu:ubuntu /home/ubuntu/.local/ 2>&1
chown -R ubuntu:ubuntu /home/ubuntu/.cs50/ 2>&1
chmod 644 /etc/apt/sources.list.d/cs50.list > /dev/null 2>&1 || true
chmod 644 /home/ubuntu/workspace/.eslintrc 2>&1 || true
chmod 644 /home/ubuntu/.cs50/py_modules/pylint50.py || true
chmod 644 /etc/bash_completion.d/make
# remove dropbox functions
sed -i 's:source /home/ubuntu/.dropbox50::g' ~/.bashrc
# add courses group and cs50 user
groupadd -r courses > /dev/null 2>&1 || true
adduser --gecos "CS50,,,," --ingroup courses --disabled-login --system cs50 > /dev/null 2>&1 || true
# set permissions and ownership of /home/cs50 files
chown -R cs50.courses /home/cs50
# executables, scripts, and directories
chmod -R 755 /home/cs50 /home/ubuntu/.cs50/bin
# non-executables
find /home/cs50/ -type f -name *.* -exec chmod 644 {} \;
# use clang 3.8 by default
update-alternatives --install /usr/bin/clang clang /usr/bin/clang-3.8 380 \
--slave /usr/bin/clang++ clang++ /usr/bin/clang++-3.8 \
--slave /usr/bin/clang-check clang-check /usr/bin/clang-check-3.8 \
--slave /usr/bin/clang-query clang-query /usr/bin/clang-query-3.8 \
--slave /usr/bin/clang-rename clang-rename /usr/bin/clang-rename-3.8
# otherwise lsof doesn't see server
chown ubuntu:courses /home/cs50/pset6/server
# prep instance's index page
if [ -f /var/www/html/index.html ]; then
rm -f /var/www/html/index.html
fi
# remove apache test file from workspace
if grep -qs '^Success$' /var/www/html/file; then
rm -f /var/www/html/file
fi
# add ide50 source file to apache's envvars
if ! grep -qs 'ide50.sh' /etc/apache2/envvars; then
sed -i 's-cloud9.sh-cloud9.sh\n. /etc/profile.d/ide50.sh-' /etc/apache2/envvars
fi
# make sure ubuntu can write to phpmyadmin's upload directory
chown ubuntu /var/lib/phpmyadmin/tmp
# increase phpmyadmin cookie timeout to one day
if ! grep -qs 'LoginCookieValidity' /etc/phpmyadmin/config.inc.php; then
sudo sed -i '$a$cfg["LoginCookieValidity"] = 86400;' /etc/phpmyadmin/config.inc.php
fi
# change phpmyadmin auth_type from cookie to http
sudo sed -i "s:\('auth_type'.*\)'cookie':\1'http':" /etc/phpmyadmin/config.inc.php
# Change user running apache from www-data to ubuntu
sudo sed -i "s/APACHE_RUN_USER=www-data/APACHE_RUN_USER=ubuntu/" /etc/apache2/envvars
sudo sed -i "s/APACHE_RUN_GROUP=www-data/APACHE_RUN_GROUP=ubuntu/" /etc/apache2/envvars
# remove ubuntu from group www-data
sudo gpasswd -d ubuntu www-data 2> /dev/null
# enable cs50 PHP config
if [ ! -h /etc/php5/apache2/conf.d/50-cs50.ini ]; then
ln -s /etc/php5/mods-available/cs50.ini /etc/php5/apache2/conf.d/50-cs50.ini
# attempt to reload apache
/usr/bin/apache50 reload > /dev/null 2>&1
fi
# in interactive shells, prevent manual flow control so Ctrl-S doesn't pause
if ! grep -qs 'stty -ixon' /home/ubuntu/.bashrc; then
echo "stty -ixon" >> /home/ubuntu/.bashrc
fi
# allow `cd` to bring user back to workspace (`cd ~` to homedir)
if ! grep -qs "alias cd" /home/ubuntu/.bashrc; then
echo 'alias cd="HOME=~/workspace cd"' >> /home/ubuntu/.bashrc
fi
if [ -f /home/ubuntu/.cs50/prompt ] && ! grep -qs 'prompt' /home/ubuntu/.bashrc; then
echo "source /home/ubuntu/.cs50/prompt" >> /home/ubuntu/.bashrc
fi
# update path in existing .bashrc files
sed -i "s#\(/home/ubuntu/\).prompt50#\1.cs50/prompt#" /home/ubuntu/.bashrc
# remove old source file if it exists
if [ -f /etc/profile.d/app.sh ]; then
rm -f /etc/profile.d/app.sh
fi
# create a password50 file, if it doesn't exist
sudo -Eu ubuntu /usr/bin/password50 > /dev/null 2>&1
# add mysql username and password to env
sudo cat > /etc/profile.d/mysql.sh <<EOF
export MYSQL_USERNAME="$(username50)"
export MYSQL_PASSWORD="$(password50)"
export MYSQL_HOSTNAME="localhost"
EOF
# add mysql username and password env vars to apache's environment
if ! grep -qs 'mysql.sh' /etc/apache2/envvars; then
sed -i 's-ide50.sh-ide50.sh\n. /etc/profile.d/mysql.sh-' /etc/apache2/envvars
fi
####################
# the remaining requires a recent update50 and some env variables must exist
if [ -z "$C9_USER" ]; then
echo
echo "Please run update50 again to complete the installation!"
exit 0
fi
# set up MySQL
echo "Setting up MySQL ..."
/usr/bin/mysql50 install > /dev/null 2>&1
# start MySQL by default
/usr/bin/mysql50 start > /dev/null 2>&1
if [ ${IDE_OFFLINE+x} ]; then
# add offline source file to apache's envvars
if ! grep -qs 'offline.sh' /etc/apache2/envvars; then
sed -i 's-ide50.sh-ide50.sh\n. /etc/profile.d/offline.sh-' /etc/apache2/envvars
fi
# add c9 alias to profile
if ! grep -qs 'alias c9' /etc/profile.d/offline.sh; then
echo -e "\nalias c9=/var/c9sdk/bin/c9" >> /etc/profile.d/offline.sh
fi
# remove old config file
rm -rf /var/c9sdk/configs/client-workspace-cs50.js
# offline only: update c9sdk and plugins
echo "Updating Cloud9 SDK ..."
pushd /var/c9sdk > /dev/null 2>&1
# https://github.com/c9/core/issues/432
npm install -g [email protected]
git reset --hard
sudo -Eu ubuntu scripts/install-sdk.sh > /dev/null 2>&1
popd > /dev/null 2>&1
else
# plugin updates aren't necessary for online IDEs; remove files
rm -rf /var/c9sdk/plugins/c9.ide.cs50* > /dev/null 2>&1
rmdir -p /var/c9sdk/plugins/ > /dev/null 2>&1
rm -rf /var/c9sdk/configs/client-workspace-cs50.js > /dev/null 2>&1
rm -rf /var/c9sdk/configs/ide/workspace-cs50.js > /dev/null 2>&1
rmdir -p /var/c9sdk/configs/ide > /dev/null 2>&1
fi
exit 0