123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  1. #!/bin/bash
  2. #
  3. # .---. . .
  4. # | | |
  5. # |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
  6. # | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
  7. # ' ' --' --' -' - -' ' ' -' -' -' ' - --'
  8. #
  9. # Freedom in the Cloud
  10. #
  11. # This install script is intended for use with Debian Jessie
  12. #
  13. # License
  14. # =======
  15. #
  16. # Copyright (C) 2014-2017 Bob Mottram <bob@freedombone.net>
  17. #
  18. # This program is free software: you can redistribute it and/or modify
  19. # it under the terms of the GNU Affero General Public License as published by
  20. # the Free Software Foundation, either version 3 of the License, or
  21. # (at your option) any later version.
  22. #
  23. # This program is distributed in the hope that it will be useful,
  24. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  26. # GNU Affero General Public License for more details.
  27. #
  28. # You should have received a copy of the GNU Affero General Public License
  29. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  30. NO_OF_ARGS=$#
  31. PROJECT_NAME='freedombone'
  32. export TEXTDOMAIN=$PROJECT_NAME
  33. export TEXTDOMAINDIR="/usr/share/locale"
  34. PROJECT_INSTALL_DIR=/usr/local/bin
  35. if [ -f /usr/bin/${PROJECT_NAME} ]; then
  36. PROJECT_INSTALL_DIR=/usr/bin
  37. fi
  38. source $PROJECT_INSTALL_DIR/${PROJECT_NAME}-vars
  39. UTILS_FILES=/usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-*
  40. for f in $UTILS_FILES
  41. do
  42. source $f
  43. done
  44. APP_FILES=/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-*
  45. for f in $APP_FILES
  46. do
  47. source $f
  48. done
  49. command_options=$1
  50. if [[ $command_options == "menuconfig-full" ]]; then
  51. MINIMAL_INSTALL="no"
  52. fi
  53. if [[ $command_options == "menuconfig-onion" ]]; then
  54. MINIMAL_INSTALL="yes"
  55. ONION_ONLY="yes"
  56. fi
  57. if [[ $command_options == "menuconfig-gnusocial" ]]; then
  58. MINIMAL_INSTALL="yes"
  59. ONION_ONLY="no"
  60. SOCIALINSTANCE='gnusocial'
  61. fi
  62. if [[ $command_options == "menuconfig-postactiv" ]]; then
  63. MINIMAL_INSTALL="yes"
  64. ONION_ONLY="no"
  65. SOCIALINSTANCE='postactiv'
  66. fi
  67. if [ ! $CONFIGURATION_FILE ]; then
  68. CONFIGURATION_FILE=$HOME/${PROJECT_NAME}.cfg
  69. fi
  70. if [ ! $COMPLETION_FILE ]; then
  71. COMPLETION_FILE=$HOME/${PROJECT_NAME}-completed.txt
  72. fi
  73. # before the interactive config so that wifi adaptors may be detected
  74. setup_wifi_atheros
  75. if [[ $command_options == "menuconfig"* ]]; then
  76. if [[ "$2" == "--reset" ]]; then
  77. if [ -f $CONFIGURATION_FILE ]; then
  78. rm $CONFIGURATION_FILE
  79. fi
  80. if [ -f $COMPLETION_FILE ]; then
  81. rm $COMPLETION_FILE
  82. fi
  83. if [ -f /usr/share/${PROJECT_NAME}/installed.txt ]; then
  84. rm /usr/share/${PROJECT_NAME}/installed.txt
  85. fi
  86. if [ -f /root/removed ]; then
  87. rm /root/removed
  88. fi
  89. fi
  90. # clear the interactive file which indicates configuration success
  91. interactive_file=$HOME/.${PROJECT_NAME}-interactive
  92. if [ -f $interactive_file ]; then
  93. rm $interactive_file
  94. fi
  95. interactive_configuration
  96. # check that the interactive file was created
  97. if [ ! -f $interactive_file ]; then
  98. exit 6393562
  99. fi
  100. rm $interactive_file
  101. else
  102. while [[ $# > 1 ]]
  103. do
  104. key="$1"
  105. case $key in
  106. -h|--help)
  107. show_help
  108. ;;
  109. # load a configuration file
  110. -c|--config)
  111. shift
  112. CONFIGURATION_FILE="$1"
  113. INSTALLING_FROM_CONFIGURATION_FILE="yes"
  114. break
  115. ;;
  116. # username within /home
  117. -u|--user)
  118. shift
  119. MY_USERNAME="$1"
  120. ;;
  121. # default domain name
  122. -d|--domain)
  123. shift
  124. DEFAULT_DOMAIN_NAME="$1"
  125. ;;
  126. # The type of system
  127. -s|--system)
  128. shift
  129. SYSTEM_TYPE="$1"
  130. ;;
  131. # The dynamic DNS provider
  132. --ddns)
  133. shift
  134. DDNS_PROVIDER="$1"
  135. ;;
  136. # Username for the synamic DNS provider
  137. --ddnsuser)
  138. shift
  139. DDNS_USERNAME="$1"
  140. ;;
  141. # Password for the synamic DNS provider
  142. --ddnspass)
  143. shift
  144. DDNS_PASSWORD="$1"
  145. ;;
  146. # Whether this installation is on a Beaglebone Black
  147. --bbb)
  148. INSTALLING_ON_BBB="yes"
  149. ;;
  150. # Static IP address for the system
  151. --ip)
  152. shift
  153. LOCAL_NETWORK_STATIC_IP_ADDRESS=$1
  154. ;;
  155. # IP address for the internet router
  156. --iprouter)
  157. shift
  158. ROUTER_IP_ADDRESS=$1
  159. ;;
  160. # ssh port
  161. --ssh)
  162. shift
  163. SSH_PORT=$1
  164. ;;
  165. # public mailing list name
  166. --list)
  167. shift
  168. PUBLIC_MAILING_LIST="$1"
  169. ;;
  170. # Number of CPU cores
  171. --cores)
  172. shift
  173. CPU_CORES=$1
  174. ;;
  175. # my name
  176. --name)
  177. shift
  178. MY_NAME="$1"
  179. ;;
  180. # my email address
  181. --email)
  182. shift
  183. MY_EMAIL_ADDRESS="$1"
  184. ;;
  185. # USB drive
  186. --usb)
  187. shift
  188. USB_DRIVE=$1
  189. ;;
  190. # Enable B.A.T.M.A.N
  191. --batman)
  192. shift
  193. ENABLE_BATMAN="yes"
  194. ;;
  195. # Mumble server password
  196. --vpass)
  197. shift
  198. MUMBLE_SERVER_PASSWORD=$1
  199. ;;
  200. # Mumble server port
  201. --vport)
  202. shift
  203. MUMBLE_PORT=$1
  204. ;;
  205. # DNS Nameserver 1
  206. --ns1)
  207. shift
  208. NAMESERVER1=$1
  209. ;;
  210. # DNS Nameserver 2
  211. --ns2)
  212. shift
  213. NAMESERVER2=$1
  214. ;;
  215. # DNS Nameserver 3
  216. --ns3)
  217. shift
  218. NAMESERVER3=$1
  219. ;;
  220. # DNS Nameserver 4
  221. --ns4)
  222. shift
  223. NAMESERVER4=$1
  224. ;;
  225. # DNS Nameserver 5
  226. --ns5)
  227. shift
  228. NAMESERVER5=$1
  229. ;;
  230. # DNS Nameserver 6
  231. --ns6)
  232. shift
  233. NAMESERVER6=$1
  234. ;;
  235. # Debian repository
  236. --repo)
  237. shift
  238. DEBIAN_REPO=$1
  239. ;;
  240. # clear the config file
  241. --reset)
  242. if [ -f $CONFIGURATION_FILE ]; then
  243. rm $CONFIGURATION_FILE
  244. fi
  245. if [ -f $COMPLETION_FILE ]; then
  246. rm $COMPLETION_FILE
  247. fi
  248. ;;
  249. # minimal install
  250. --minimal)
  251. shift
  252. MINIMAL_INSTALL=$1
  253. ;;
  254. *)
  255. # unknown option
  256. ;;
  257. esac
  258. shift
  259. done
  260. fi
  261. function parse_args {
  262. if [[ $NO_OF_ARGS == 0 ]]; then
  263. echo 'no_of_args = 0'
  264. show_help
  265. exit 0
  266. fi
  267. read_config_param 'DEFAULT_DOMAIN_NAME'
  268. read_config_param 'MY_USERNAME'
  269. read_config_param 'SYSTEM_TYPE'
  270. read_config_param 'ONION_ONLY'
  271. read_config_param 'DDNS_PROVIDER'
  272. read_config_param 'DDNS_USERNAME'
  273. read_config_param 'DDNS_PASSWORD'
  274. if [ ! -d /home/$MY_USERNAME ]; then
  275. echo $"There is no user '$MY_USERNAME' on the system. Use 'adduser $MY_USERNAME' to create the user."
  276. exit 1
  277. fi
  278. if [ ! "$DEFAULT_DOMAIN_NAME" ]; then
  279. if [[ $SYSTEM_TYPE != "mesh"* ]]; then
  280. echo 'No default domain specified'
  281. show_help
  282. exit 2
  283. fi
  284. fi
  285. if [ ! $MY_USERNAME ]; then
  286. echo 'No username specified'
  287. show_help
  288. exit 3
  289. fi
  290. if [[ $SYSTEM_TYPE != "mesh"* ]]; then
  291. if [[ "$DDNS_PROVIDER" != 'none' ]]; then
  292. if [[ $ONION_ONLY == "no" ]]; then
  293. if [ ! $DDNS_USERNAME ]; then
  294. echo $'Please provide the username for your dynamic DNS provider with the --ddnsuser option'
  295. exit 7823
  296. fi
  297. if [ ! $DDNS_PASSWORD ]; then
  298. echo $'Please provide the password for your dynamic DNS provider with the --ddnspass option'
  299. exit 6382
  300. fi
  301. fi
  302. fi
  303. fi
  304. if [ ! $SYSTEM_TYPE ]; then
  305. SYSTEM_TYPE=$'full'
  306. write_config_param "SYSTEM_TYPE" "$SYSTEM_TYPE"
  307. fi
  308. if [[ $(is_valid_variant) == "0" ]]; then
  309. echo $"'$SYSTEM_TYPE' is an unrecognised ${PROJECT_NAME} variant. Possible variants are:"
  310. show_available_variants
  311. exit 367245
  312. fi
  313. }
  314. # run some initial tests
  315. clear
  316. ${PROJECT_NAME}-tests
  317. if [ ! "$?" = "0" ]; then
  318. exit 768252
  319. fi
  320. clear
  321. echo ''
  322. echo $'Setting up the base installation'
  323. echo ''
  324. export DEBIAN_FRONTEND=noninteractive
  325. upgrade_installation_from_previous_versions
  326. setup_utils
  327. setup_email
  328. setup_web
  329. setup_apps $command_options
  330. setup_final
  331. echo ''
  332. echo "${PROJECT_NAME} installation is complete"
  333. exit 0