freedombone 8.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  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. # Debian repository
  206. --repo)
  207. shift
  208. DEBIAN_REPO=$1
  209. ;;
  210. # clear the config file
  211. --reset)
  212. if [ -f $CONFIGURATION_FILE ]; then
  213. rm $CONFIGURATION_FILE
  214. fi
  215. if [ -f $COMPLETION_FILE ]; then
  216. rm $COMPLETION_FILE
  217. fi
  218. ;;
  219. # minimal install
  220. --minimal)
  221. shift
  222. MINIMAL_INSTALL=$1
  223. ;;
  224. *)
  225. # unknown option
  226. ;;
  227. esac
  228. shift
  229. done
  230. fi
  231. function parse_args {
  232. if [[ $NO_OF_ARGS == 0 ]]; then
  233. echo 'no_of_args = 0'
  234. show_help
  235. exit 0
  236. fi
  237. read_config_param 'DEFAULT_DOMAIN_NAME'
  238. read_config_param 'MY_USERNAME'
  239. read_config_param 'SYSTEM_TYPE'
  240. read_config_param 'ONION_ONLY'
  241. if [ ! -d /home/$MY_USERNAME ]; then
  242. echo $"There is no user '$MY_USERNAME' on the system. Use 'adduser $MY_USERNAME' to create the user."
  243. exit 1
  244. fi
  245. if [ ! "$DEFAULT_DOMAIN_NAME" ]; then
  246. if [[ $SYSTEM_TYPE != "mesh"* ]]; then
  247. echo 'No default domain specified'
  248. show_help
  249. exit 2
  250. fi
  251. fi
  252. if [ ! $MY_USERNAME ]; then
  253. echo 'No username specified'
  254. show_help
  255. exit 3
  256. fi
  257. if [[ $SYSTEM_TYPE != "mesh"* ]]; then
  258. if [[ $ONION_ONLY == "no" ]]; then
  259. if [ ! $DDNS_USERNAME ]; then
  260. echo $'Please provide the username for your dynamic DNS provider with the --ddnsuser option'
  261. exit 7823
  262. fi
  263. if [ ! $DDNS_PASSWORD ]; then
  264. echo $'Please provide the password for your dynamic DNS provider with the --ddnspass option'
  265. exit 6382
  266. fi
  267. fi
  268. fi
  269. if [ ! $SYSTEM_TYPE ]; then
  270. SYSTEM_TYPE=$'full'
  271. write_config_param "SYSTEM_TYPE" "$SYSTEM_TYPE"
  272. fi
  273. if [[ $(is_valid_variant) == "0" ]]; then
  274. echo $"'$SYSTEM_TYPE' is an unrecognised ${PROJECT_NAME} variant. Possible variants are:"
  275. show_available_variants
  276. exit 367245
  277. fi
  278. }
  279. # run some initial tests
  280. clear
  281. ${PROJECT_NAME}-tests
  282. if [ ! "$?" = "0" ]; then
  283. exit 768252
  284. fi
  285. clear
  286. echo ''
  287. echo $'Setting up the base installation'
  288. echo ''
  289. export DEBIAN_FRONTEND=noninteractive
  290. upgrade_installation_from_previous_versions
  291. setup_utils
  292. setup_email
  293. setup_web
  294. setup_apps $command_options
  295. setup_final
  296. echo "${PROJECT_NAME} installation is complete"
  297. exit 0