PageRenderTime 24ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/boca-1.5.0/tools/installv2.sh

https://bitbucket.org/jorgenio/boca
Shell | 320 lines | 256 code | 39 blank | 25 comment | 58 complexity | a4b4c7fdf104e1cb51c9d021bf487c0e MD5 | raw file
Possible License(s): LGPL-2.1
  1. #!/bin/bash
  2. # ////////////////////////////////////////////////////////////////////////////////
  3. # //BOCA Online Contest Administrator
  4. # // Copyright (C) 2003-2012 by BOCA Development Team (bocasystem@gmail.com)
  5. # //
  6. # // This program is free software: you can redistribute it and/or modify
  7. # // it under the terms of the GNU General Public License as published by
  8. # // the Free Software Foundation, either version 3 of the License, or
  9. # // (at your option) any later version.
  10. # //
  11. # // This program is distributed in the hope that it will be useful,
  12. # // but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # // GNU General Public License for more details.
  15. # // You should have received a copy of the GNU General Public License
  16. # // along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. # ////////////////////////////////////////////////////////////////////////////////
  18. # // Last modified 06/aug/2012 by cassio@ime.usp.br
  19. #///////////////////////////////////////////////////////////////////////////////////////////
  20. echo "#############################################################"
  21. echo "### installv2.sh of 06/Aug/2012 (A) by cassio@ime.usp.br ###"
  22. echo "#############################################################"
  23. for i in id chown chmod cut awk tail grep cat sed mkdir rm mv sleep apt-get add-apt-repository update-alternatives; do
  24. p=`which $i`
  25. if [ -x "$p" ]; then
  26. echo -n ""
  27. else
  28. echo command "$i" not found
  29. exit 1
  30. fi
  31. done
  32. sleep 2
  33. echo "$0" | grep -q "install.*sh"
  34. if [ $? != 0 ]; then
  35. echo "Make the install script executable (using chmod) and run it directly, like ./installv2.sh"
  36. else
  37. if [ "`id -u`" != "0" ]; then
  38. echo "Must be run as root"
  39. exit 1
  40. fi
  41. if [ "$1" != "alreadydone" ]; then
  42. echo "It is recommended that you run the commands"
  43. echo " apt-get update; apt-get upgrade"
  44. echo "by your own before running this script. If you have already done it,"
  45. echo "please run the script as"
  46. echo " ./install.sh alreadydone"
  47. exit 1
  48. fi
  49. if [ ! -r /etc/lsb-release ]; then
  50. echo "File /etc/lsb-release not found. Is this a ubuntu or debian-like distro?"
  51. exit 1
  52. fi
  53. . /etc/lsb-release
  54. echo "============================================================="
  55. echo "============== DISABLING AUTO-UPDATE POP-UPS ==============="
  56. echo "============================================================="
  57. gconftool -s --type bool /apps/update-notifier/auto_launch false
  58. gsettings set com.ubuntu.update-notifier no-show-notifications true
  59. sed -i 's/X-GNOME-Autostart-Delay=60/X-GNOME-Autostart-enabled=false/' /etc/xdg/autostart/update-notifier.desktop
  60. echo "============================================================="
  61. echo "========= UNINSTALLING SOME UNNECESSARY PACKAGES ==========="
  62. echo "============================================================="
  63. apt-get -y purge libreoffice-common libreoffice-base-core bluez thunderbird \
  64. ubuntuone-client python-ubuntuone-client \
  65. ubuntuone-installer python-ubuntuone-storageprotocol
  66. sysvutils=sysvutils
  67. if [ "$DISTRIB_CODENAME" == "oneiric" -o "$DISTRIB_CODENAME" == "precise" ]; then
  68. sysvutils=sysvinit-utils
  69. fi
  70. echo "====================================================================="
  71. echo "============== CHECKING FOR canonical.com APT SERVER ==============="
  72. echo "====================================================================="
  73. cd
  74. grep -q "^[^\#]*deb http://archive.canonical.com.* $DISTRIB_CODENAME .*partner" /etc/apt/sources.list
  75. if [ $? != 0 ]; then
  76. add-apt-repository "deb http://archive.canonical.com/ubuntu $DISTRIB_CODENAME partner"
  77. fi
  78. apt-get -y update
  79. apt-get -y upgrade
  80. libCppdev=`apt-cache search libstdc++ | grep "libstdc++6-.*-dev " | sort | tail -n1 | cut -d' ' -f1`
  81. if [ "$libCppdev" == "" ]; then
  82. echo "libstdc++6-*-dev not found"
  83. exit 1
  84. fi
  85. libCppdbg=`apt-cache search libstdc++ | grep "libstdc++6-.*-dbg " | sort | tail -n1 | cut -d' ' -f1`
  86. if [ "$libCppdbg" == "" ]; then
  87. echo "libstdc++6-*-dbg not found"
  88. exit 1
  89. fi
  90. libCppdoc=`apt-cache search libstdc++ | grep "libstdc++6-.*-doc " | sort | tail -n1 | cut -d' ' -f1`
  91. if [ "$libCppdoc" == "" ]; then
  92. echo "libstdc++6-*-doc not found"
  93. exit 1
  94. fi
  95. echo "====================================================================="
  96. echo "================= installing packages needed by BOCA ==============="
  97. echo "====================================================================="
  98. apt-get -y install zenity apache2 eclipse-pde eclipse-rcp eclipse-platform eclipse-jdt eclipse emacs \
  99. evince g++ gcc gedit scite libstdc++6 makepasswd manpages-dev mii-diag php5-cli php5-mcrypt openjdk-6-dbg \
  100. php5 php5-pgsql postgresql postgresql-client postgresql-contrib quota sharutils default-jdk openjdk-6-doc \
  101. vim-gnome geany geany-plugin-addons geany-plugin-gdb geany-plugins default-jre sysstat \
  102. $sysvutils vim xfce4 $libCppdev $libCppdoc $libCppdbg php5-gd stl-manual gcc-doc debootstrap schroot c++-annotations
  103. if [ $? != 0 ]; then
  104. echo ""
  105. echo "ERROR running the apt-get -- must check if all needed packages are available"
  106. exit 1
  107. fi
  108. for i in makepasswd useradd update-rc.d; do
  109. p=`which $i`
  110. if [ -x "$p" ]; then
  111. echo -n ""
  112. else
  113. echo command "$i" not found
  114. exit 1
  115. fi
  116. done
  117. echo "=================================================================="
  118. echo "============= creating user icpc with password icpc ============="
  119. echo "=================================================================="
  120. pass=`echo -n icpc | makepasswd --clearfrom - --crypt-md5 | cut -d'$' -f2-`
  121. pass=\$`echo $pass`
  122. id -u icpc >/dev/null 2>/dev/null
  123. if [ $? != 0 ]; then
  124. useradd -d /home/icpc -m -p "$pass" -s /bin/bash -g users icpc
  125. else
  126. usermod -d /home/icpc -p "$pass" -s /bin/bash -g users icpc
  127. echo "user icpc already exists"
  128. fi
  129. if [ -f /etc/lightdm/lightdm.conf ]; then
  130. echo "=============================================================="
  131. echo "============ disabling guest account on lightdm.conf ========"
  132. echo "=============================================================="
  133. grep -q "^[^\#]*allow-guest" /etc/lightdm/lightdm.conf
  134. if [ $? != 0 ]; then
  135. echo "allow-guest=false" >> /etc/lightdm/lightdm.conf
  136. fi
  137. grep -q "^[^\#]*greeter-hide-users" /etc/lightdm/lightdm.conf
  138. if [ $? != 0 ]; then
  139. echo "greeter-hide-users=true" >> /etc/lightdm/lightdm.conf
  140. fi
  141. fi
  142. echo "====================================================================================="
  143. echo "============ updating grub boot loader to make it password protected ==============="
  144. echo "====================================================================================="
  145. grep -q "^[^\#]*password" /etc/grub.d/40_custom
  146. if [ $? != 0 ]; then
  147. echo "updated with new password (if needed, see the password at /etc/grub.d/40_custom)"
  148. echo -e "set superusers=\"root\"" >> /etc/grub.d/40_custom
  149. echo -e "password root `makepasswd`" >> /etc/grub.d/40_custom
  150. chmod go-rw /etc/grub.d/40_custom
  151. grub-mkconfig > /boot/grub/grub.cfg
  152. chmod go-rw /boot/grub/grub.cfg
  153. fi
  154. echo "grub loader configured with password (if needed, see the password at /etc/grub.d/40_custom)"
  155. echo "=============================================================="
  156. echo "============= INSTALLING SCRIPTS at /etc/icpc ==============="
  157. echo "=============================================================="
  158. mkdir -p /etc/icpc
  159. chown root.root /etc/icpc
  160. chmod 755 /etc/icpc
  161. cat <<EOF > /etc/icpc/installscripts.sh
  162. #!/bin/bash
  163. echo "================================================================================"
  164. echo "========== downloading config files from www.ime.usp.br/~cassio/boca =========="
  165. echo "================================================================================"
  166. iptables -F
  167. wget -O /tmp/.boca.tmp "http://www.ime.usp.br/~cassio/boca/icpc.etc.date.txt"
  168. echo ">>>>>>>>>>"
  169. echo ">>>>>>>>>> Downloading scripts release \`cat /tmp/.boca.tmp\`"
  170. echo ">>>>>>>>>>"
  171. if [ "\$1" == "" ]; then
  172. wget -O /tmp/.boca.tmp "http://www.ime.usp.br/~cassio/boca/icpc.etc.ver.txt"
  173. icpcver=\`cat /tmp/.boca.tmp\`
  174. else
  175. icpcver=\$1
  176. fi
  177. echo "Looking for version \$icpcver from http://www.ime.usp.br/~cassio/boca/"
  178. rm -f /tmp/icpc.etc.tgz
  179. wget -O /tmp/icpc.etc.tgz "http://www.ime.usp.br/~cassio/boca/download.php?filename=icpc-\$icpcver.etc.tgz"
  180. if [ "\$?" != "0" -o ! -f /tmp/icpc.etc.tgz ]; then
  181. echo "ERROR downloading file icpc-\$icpcver.etc.tgz. Aborting *****************"
  182. exit 1
  183. fi
  184. grep -qi "bad parameters" /tmp/icpc.etc.tgz
  185. if [ "\$?" == "0" ]; then
  186. echo "ERROR downloading file icpc-\$icpcver.etc.tgz. Aborting *****************"
  187. exit 1
  188. fi
  189. cd /etc
  190. di=\`date +%s\`
  191. echo "=============================================================="
  192. echo "====================== BACKUPING CONFIG FILES ==============="
  193. for i in \`tar tvzf /tmp/icpc.etc.tgz | awk '{ print \$6; }'\`; do
  194. if [ -f "\$i" ]; then
  195. bn=\`basename \$i\`
  196. dn=\`dirname \$i\`
  197. mv \$i \$dn/.\$bn.bkp.\$di
  198. chmod 600 \$dn/.\$bn.bkp.\$di
  199. fi
  200. done
  201. echo "=============================================================="
  202. echo "====================== EXTRACTING CONFIG FILES ==============="
  203. tar -xkvzf /tmp/icpc.etc.tgz
  204. for i in \`tar tvzf /tmp/icpc.etc.tgz | awk '{ print \$6; }'\`; do
  205. chown root.root \$i
  206. chmod o-w,u+x \$i
  207. done
  208. EOF
  209. chmod 750 /etc/icpc/installscripts.sh
  210. /etc/icpc/installscripts.sh $3
  211. service procps start
  212. grep -q "quota" /etc/fstab
  213. if [ $? != 0 ]; then
  214. cp -f /etc/fstab /etc/fstab.bkp.$di
  215. sed "s/relatime/quota,relatime/" < /etc/fstab.bkp.$di > /etc/fstab.bkp.$di.1
  216. sed "s/errors=remount-ro/quota,errors=remount-ro/" < /etc/fstab.bkp.$di.1 > /etc/fstab
  217. fi
  218. echo "============================================================"
  219. echo "===================== SETTING UP USER QUOTA ==============="
  220. echo "============================================================"
  221. for i in `mount | grep gvfs | cut -d' ' -f3`; do
  222. umount $i
  223. done
  224. mount / -o remount
  225. quotaoff -a 2>/dev/null
  226. quotacheck -M -a
  227. quotaon -a
  228. setquota -u postgres 0 3000000 0 10000 -a
  229. setquota -u icpc 0 500000 0 10000 -a
  230. setquota -u nobody 0 500000 0 10000 -a
  231. setquota -u www-data 0 1500000 0 10000 -a
  232. echo "=============================================================="
  233. echo "================= UPDATING rc.local symlinks ==============="
  234. echo "=============================================================="
  235. update-rc.d rc.local defaults
  236. update-rc.d -f cups remove
  237. apt-get -y clean
  238. #echo "=============================================================="
  239. #echo "====================== SETTING UP IPs and PASSWORDs (server config follows) ==============="
  240. #
  241. /etc/icpc/restart.sh
  242. #/etc/icpc/setup.sh
  243. startscript="NOTOK"
  244. if [ -f /etc/lightdm/lightdm.conf ]; then
  245. startscript="OK"
  246. grep -q "^[^\#]*display-setup-script=/etc/icpc/setup.sh" /etc/lightdm/lightdm.conf
  247. if [ $? != 0 ]; then
  248. echo "display-setup-script=/etc/icpc/setup.sh" >> /etc/lightdm/lightdm.conf
  249. fi
  250. fi
  251. if [ -d /etc/gdm/Init ]; then
  252. startscript="OK"
  253. echo "======================================================================================"
  254. echo "========== UPDATING /etc/gdm/Init/Default TO PROVIDE CONFIG AT STARTUP ==============="
  255. echo "======================================================================================"
  256. echo -e "#!/bin/bash\n[ -x /etc/icpc/setup.sh ] && /etc/icpc/setup.sh\n\n" > /tmp/.boca.tmp
  257. cat /etc/gdm/Init/Default >> /tmp/.boca.tmp
  258. mv /tmp/.boca.tmp /etc/gdm/Init/Default
  259. chmod 755 /etc/gdm/Init/Default
  260. fi
  261. if [ "$startscript" != "OK" ]; then
  262. echo "************ STARTUP CALL OF SCRIPTS NOT CONFIGURED **************"
  263. echo "****** neither /etc/gdm/Init nor /etc/lightdm/lightdm.conf were found ************"
  264. fi
  265. if [ -f /etc/icpc/createbocajail.sh ]; then
  266. chmod 750 /etc/icpc/createbocajail.sh
  267. if [ "$2" != "notbuildjail" ]; then
  268. /etc/icpc/createbocajail.sh
  269. fi
  270. else
  271. echo "************** SCRIPT TO CREATE BOCAJAIL NOT FOUND -- SOMETHING LOOKS WRONG ***************"
  272. fi
  273. # BOCA CONFIG
  274. if [ -f /etc/icpc/installboca.sh ]; then
  275. chmod 750 /etc/icpc/installboca.sh
  276. /sbin/iptables -F
  277. /etc/icpc/installboca.sh "$3" "$4"
  278. else
  279. echo "************* SCRIPT TO INSTALL BOCA NOT FOUND -- SOMETHING IS WRONG -- I CANT INSTALL BOCA **************"
  280. fi
  281. fi