123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  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-2016 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 [ ! $CONFIGURATION_FILE ]; then
  58. CONFIGURATION_FILE=$HOME/${PROJECT_NAME}.cfg
  59. fi
  60. if [ ! $COMPLETION_FILE ]; then
  61. COMPLETION_FILE=$HOME/${PROJECT_NAME}-completed.txt
  62. fi
  63. # before the interactive config so that wifi adaptors may be detected
  64. setup_wifi_atheros
  65. if [[ $command_options == "menuconfig"* ]]; then
  66. if [[ "$2" == "--reset" ]]; then
  67. if [ -f $CONFIGURATION_FILE ]; then
  68. rm $CONFIGURATION_FILE
  69. fi
  70. if [ -f $COMPLETION_FILE ]; then
  71. rm $COMPLETION_FILE
  72. fi
  73. if [ -f /usr/share/${PROJECT_NAME}/installed.txt ]; then
  74. rm /usr/share/${PROJECT_NAME}/installed.txt
  75. fi
  76. if [ -f /root/removed ]; then
  77. rm /root/removed
  78. fi
  79. fi
  80. # clear the interactive file which indicates configuration success
  81. interactive_file=$HOME/.${PROJECT_NAME}-interactive
  82. if [ -f $interactive_file ]; then
  83. rm $interactive_file
  84. fi
  85. interactive_configuration
  86. # check that the interactive file was created
  87. if [ ! -f $interactive_file ]; then
  88. exit 6393562
  89. fi
  90. rm $interactive_file
  91. else
  92. while [[ $# > 1 ]]
  93. do
  94. key="$1"
  95. case $key in
  96. -h|--help)
  97. show_help
  98. ;;
  99. # load a configuration file
  100. -c|--config)
  101. shift
  102. CONFIGURATION_FILE="$1"
  103. INSTALLING_FROM_CONFIGURATION_FILE="yes"
  104. break
  105. ;;
  106. # username within /home
  107. -u|--user)
  108. shift
  109. MY_USERNAME="$1"
  110. ;;
  111. # default domain name
  112. -d|--domain)
  113. shift
  114. DEFAULT_DOMAIN_NAME="$1"
  115. ;;
  116. # The type of system
  117. -s|--system)
  118. shift
  119. SYSTEM_TYPE="$1"
  120. ;;
  121. # The dynamic DNS provider
  122. --ddns)
  123. shift
  124. DDNS_PROVIDER="$1"
  125. ;;
  126. # Username for the synamic DNS provider
  127. --ddnsuser)
  128. shift
  129. DDNS_USERNAME="$1"
  130. ;;
  131. # Password for the synamic DNS provider
  132. --ddnspass)
  133. shift
  134. DDNS_PASSWORD="$1"
  135. ;;
  136. # Whether this installation is on a Beaglebone Black
  137. --bbb)
  138. INSTALLING_ON_BBB="yes"
  139. ;;
  140. # Static IP address for the system
  141. --ip)
  142. shift
  143. LOCAL_NETWORK_STATIC_IP_ADDRESS=$1
  144. ;;
  145. # IP address for the internet router
  146. --iprouter)
  147. shift
  148. ROUTER_IP_ADDRESS=$1
  149. ;;
  150. # ssh port
  151. --ssh)
  152. shift
  153. SSH_PORT=$1
  154. ;;
  155. # public mailing list name
  156. --list)
  157. shift
  158. PUBLIC_MAILING_LIST="$1"
  159. ;;
  160. # Number of CPU cores
  161. --cores)
  162. shift
  163. CPU_CORES=$1
  164. ;;
  165. # my name
  166. --name)
  167. shift
  168. MY_NAME="$1"
  169. ;;
  170. # my email address
  171. --email)
  172. shift
  173. MY_EMAIL_ADDRESS="$1"
  174. ;;
  175. # USB drive
  176. --usb)
  177. shift
  178. USB_DRIVE=$1
  179. ;;
  180. # Enable B.A.T.M.A.N
  181. --batman)
  182. shift
  183. ENABLE_BATMAN="yes"
  184. ;;
  185. # Mumble server password
  186. --vpass)
  187. shift
  188. MUMBLE_SERVER_PASSWORD=$1
  189. ;;
  190. # Mumble server port
  191. --vport)
  192. shift
  193. MUMBLE_PORT=$1
  194. ;;
  195. # DNS Nameserver 1
  196. --ns1)
  197. shift
  198. NAMESERVER1=$1
  199. ;;
  200. # DNS Nameserver 2
  201. --ns2)
  202. shift
  203. NAMESERVER2=$1
  204. ;;
  205. # DNS Nameserver 3
  206. --ns3)
  207. shift
  208. NAMESERVER3=$1
  209. ;;
  210. # DNS Nameserver 4
  211. --ns4)
  212. shift
  213. NAMESERVER4=$1
  214. ;;
  215. # DNS Nameserver 5
  216. --ns5)
  217. shift
  218. NAMESERVER5=$1
  219. ;;
  220. # DNS Nameserver 6
  221. --ns6)
  222. shift
  223. NAMESERVER6=$1
  224. ;;
  225. # Debian repository
  226. --repo)
  227. shift
  228. DEBIAN_REPO=$1
  229. ;;
  230. # clear the config file
  231. --reset)
  232. if [ -f $CONFIGURATION_FILE ]; then
  233. rm $CONFIGURATION_FILE
  234. fi
  235. if [ -f $COMPLETION_FILE ]; then
  236. rm $COMPLETION_FILE
  237. fi
  238. ;;
  239. # minimal install
  240. --minimal)
  241. shift
  242. MINIMAL_INSTALL=$1
  243. ;;
  244. *)
  245. # unknown option
  246. ;;
  247. esac
  248. shift
  249. done
  250. fi
  251. function parse_args {
  252. if [[ $NO_OF_ARGS == 0 ]]; then
  253. echo 'no_of_args = 0'
  254. show_help
  255. exit 0
  256. fi
  257. read_config_param 'DEFAULT_DOMAIN_NAME'
  258. read_config_param 'MY_USERNAME'
  259. read_config_param 'SYSTEM_TYPE'
  260. read_config_param 'ONION_ONLY'
  261. read_config_param 'DDNS_PROVIDER'
  262. read_config_param 'DDNS_USERNAME'
  263. read_config_param 'DDNS_PASSWORD'
  264. if [ ! -d /home/$MY_USERNAME ]; then
  265. echo $"There is no user '$MY_USERNAME' on the system. Use 'adduser $MY_USERNAME' to create the user."
  266. exit 1
  267. fi
  268. if [ ! "$DEFAULT_DOMAIN_NAME" ]; then
  269. if [[ $SYSTEM_TYPE != "mesh"* ]]; then
  270. echo 'No default domain specified'
  271. show_help
  272. exit 2
  273. fi
  274. fi
  275. if [ ! $MY_USERNAME ]; then
  276. echo 'No username specified'
  277. show_help
  278. exit 3
  279. fi
  280. if [[ $SYSTEM_TYPE != "mesh"* ]]; then
  281. if [[ "$DDNS_PROVIDER" != 'none' ]]; then
  282. if [[ $ONION_ONLY == "no" ]]; then
  283. if [ ! $DDNS_USERNAME ]; then
  284. echo $'Please provide the username for your dynamic DNS provider with the --ddnsuser option'
  285. exit 7823
  286. fi
  287. if [ ! $DDNS_PASSWORD ]; then
  288. echo $'Please provide the password for your dynamic DNS provider with the --ddnspass option'
  289. exit 6382
  290. fi
  291. fi
  292. fi
  293. fi
  294. if [ ! $SYSTEM_TYPE ]; then
  295. SYSTEM_TYPE=$'full'
  296. write_config_param "SYSTEM_TYPE" "$SYSTEM_TYPE"
  297. fi
  298. if [[ $(is_valid_variant) == "0" ]]; then
  299. echo $"'$SYSTEM_TYPE' is an unrecognised ${PROJECT_NAME} variant. Possible variants are:"
  300. show_available_variants
  301. exit 367245
  302. fi
  303. }
  304. # run some initial tests
  305. clear
  306. ${PROJECT_NAME}-tests
  307. if [ ! "$?" = "0" ]; then
  308. exit 768252
  309. fi
  310. clear
  311. echo ''
  312. echo $'Setting up the base installation'
  313. echo ''
  314. export DEBIAN_FRONTEND=noninteractive
  315. upgrade_installation_from_previous_versions
  316. setup_utils
  317. setup_email
  318. setup_web
  319. setup_apps $command_options
  320. setup_final
  321. echo ''
  322. echo "${PROJECT_NAME} installation is complete"
  323. exit 0