freedombone-utils-interactive 9.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. #!/bin/bash
  2. #
  3. # .---. . .
  4. # | | |
  5. # |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
  6. # | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
  7. # ' ' --' --' -' - -' ' ' -' -' -' ' - --'
  8. #
  9. # Freedom in the Cloud
  10. #
  11. # Interactive install functions
  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. function interactive_configuration_remote_backups {
  31. if [[ $SYSTEM_TYPE == "mesh"* ]]; then
  32. return
  33. fi
  34. if [ ! -f /usr/local/bin/${PROJECT_NAME}-remote ]; then
  35. if [ ! -f /usr/bin/${PROJECT_NAME}-remote ]; then
  36. echo $"The command ${PROJECT_NAME}-remote was not found"
  37. exit 87354
  38. fi
  39. fi
  40. ${PROJECT_NAME}-remote -u $MY_USERNAME -l $FRIENDS_SERVERS_LIST -m $MINIMUM_PASSWORD_LENGTH -r yes
  41. if [ ! "$?" = "0" ]; then
  42. echo $'Command failed:'
  43. echo ''
  44. echo $" ${PROJECT_NAME}-remote -u $MY_USERNAME -l $FRIENDS_SERVERS_LIST -m $MINIMUM_PASSWORD_LENGTH -r yes"
  45. echo ''
  46. exit 65892
  47. fi
  48. }
  49. function interactive_configuration {
  50. if [ ! -f /usr/local/bin/${PROJECT_NAME}-config ]; then
  51. if [ ! -f /usr/bin/${PROJECT_NAME}-config ]; then
  52. echo $"The command ${PROJECT_NAME}-config was not found"
  53. exit 63935
  54. fi
  55. fi
  56. if [ -f /tmp/meshuserdevice ]; then
  57. rm -f /tmp/meshuserdevice
  58. fi
  59. if [ $SOCIALINSTANCE ]; then
  60. ${PROJECT_NAME}-config \
  61. -f $CONFIGURATION_FILE \
  62. -w $PROJECT_WEBSITE \
  63. -m $MINIMUM_PASSWORD_LENGTH \
  64. --minimal "yes" \
  65. --social $SOCIALINSTANCE
  66. else
  67. if [[ $ONION_ONLY == "no" ]]; then
  68. if [[ $MINIMAL_INSTALL == "no" ]]; then
  69. ${PROJECT_NAME}-config \
  70. -f $CONFIGURATION_FILE \
  71. -w $PROJECT_WEBSITE \
  72. -m $MINIMUM_PASSWORD_LENGTH
  73. else
  74. ${PROJECT_NAME}-config \
  75. -f $CONFIGURATION_FILE \
  76. -w $PROJECT_WEBSITE \
  77. -m $MINIMUM_PASSWORD_LENGTH \
  78. --minimal "yes"
  79. fi
  80. else
  81. ${PROJECT_NAME}-config \
  82. -f $CONFIGURATION_FILE \
  83. -w $PROJECT_WEBSITE \
  84. -m $MINIMUM_PASSWORD_LENGTH \
  85. --onion "yes"
  86. fi
  87. fi
  88. if [ -f /tmp/meshuserdevice ]; then
  89. # mesh network user device installation
  90. rm -f /tmp/meshuserdevice
  91. exit 0
  92. fi
  93. if [ ! "$?" = "0" ]; then
  94. echo $'Command failed:'
  95. echo ''
  96. echo $" ${PROJECT_NAME}-config -u $MY_USERNAME -f $CONFIGURATION_FILE -w $PROJECT_WEBSITE -b $PROJECT_BITMESSAGE -m $MINIMUM_PASSWORD_LENGTH --minimal [yes|no]"
  97. echo ''
  98. exit 73594
  99. fi
  100. if [[ $SYSTEM_TYPE == "mesh"* ]]; then
  101. FRIENDS_SERVERS_LIST=/home/$MY_USERNAME/backup.list
  102. dialog --title $"Encrypted backup to other servers" \
  103. --backtitle $"${PROJECT_NAME} Configuration" \
  104. --defaultno \
  105. --yesno $"\nDo you wish to configure some remote backup locations?" 7 60
  106. sel=$?
  107. case $sel in
  108. 0) interactive_configuration_remote_backups;;
  109. esac
  110. fi
  111. }
  112. function interactive_site_details {
  113. site_name="$1"
  114. site_name_upper=${site_name^^}
  115. SITE_BACKTITLE=$"Freedombone Configuration"
  116. SITE_CONFIG_TITLE=$"${site_name^} Configuration"
  117. SITE_FORM_TEXT=$"\nPlease enter your ${site_name^} details.\n\nIMPORTANT: This should be a domain name which is supported by Let's Encrypt:"
  118. SITE_DOMAIN_NAME=
  119. SITE_CODE=
  120. SITE_DETAILS_COMPLETE=
  121. while [ ! $SITE_DETAILS_COMPLETE ]
  122. do
  123. data=$(tempfile 2>/dev/null)
  124. trap "rm -f $data" 0 1 2 5 15
  125. if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
  126. dialog --backtitle "$SITE_BACKTITLE" \
  127. --title "$SITE_CONFIG_TITLE" \
  128. --form "$SITE_FORM_TEXT" 14 55 3 \
  129. $"Domain:" 1 1 "$(grep '${site_name_upper}_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 16 33 40 \
  130. $"Code:" 2 1 "$(grep '${site_name_upper}_CODE' temp.cfg | awk -F '=' '{print $2}')" 2 16 33 255 \
  131. 2> $data
  132. else
  133. dialog --backtitle "$SITE_BACKTITLE" \
  134. --title "$SITE_CONFIG_TITLE" \
  135. --form "$SITE_FORM_TEXT" 11 55 3 \
  136. $"Domain:" 1 1 "$(grep '${site_name_upper}_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 16 33 40 \
  137. 2> $data
  138. fi
  139. sel=$?
  140. case $sel in
  141. 1) exit 1;;
  142. 255) exit 1;;
  143. esac
  144. SITE_DOMAIN_NAME=$(cat $data | sed -n 1p)
  145. if [ $SITE_DOMAIN_NAME ]; then
  146. TEST_DOMAIN_NAME=$SITE_DOMAIN_NAME
  147. validate_domain_name
  148. if [[ $TEST_DOMAIN_NAME != $SITE_DOMAIN_NAME ]]; then
  149. SITE_DOMAIN_NAME=
  150. dialog --title $"Domain name validation" --msgbox "$TEST_DOMAIN_NAME" 15 50
  151. else
  152. if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
  153. SITE_CODE=$(cat $data | sed -n 2p)
  154. validate_freedns_code "$SITE_CODE"
  155. if [ ! $VALID_CODE ]; then
  156. SITE_DOMAIN_NAME=
  157. fi
  158. fi
  159. fi
  160. fi
  161. if [ $SITE_DOMAIN_NAME ]; then
  162. SITE_DETAILS_COMPLETE="yes"
  163. fi
  164. done
  165. # save the results in the config file
  166. write_config_param "${site_name_upper}_DOMAIN_NAME" "$SITE_DOMAIN_NAME"
  167. site_code_str="$SITE_CODE"
  168. if [ ${#site_code_str} -gt 1 ]; then
  169. write_config_param "${site_name_upper}_CODE" "${SITE_CODE}"
  170. fi
  171. }
  172. function interactive_site_details_with_title {
  173. site_name="${1}"
  174. SITE_BACKTITLE=$"Freedombone Configuration"
  175. SITE_CONFIG_TITLE=$"${site_name^} Configuration"
  176. SITE_FORM_TEXT=$"\nPlease enter your ${site_name^} details.\n\nIMPORTANT: This should be a domain name which is supported by Let's Encrypt:"
  177. SITE_TITLE=
  178. SITE_DOMAIN_NAME=
  179. SITE_CODE=
  180. SITE_DETAILS_COMPLETE=
  181. while [ ! $SITE_DETAILS_COMPLETE ]
  182. do
  183. data=$(tempfile 2>/dev/null)
  184. trap "rm -f $data" 0 1 2 5 15
  185. if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
  186. dialog --backtitle $"Freedombone Configuration" \
  187. --title "$SITE_BACKTITLE" \
  188. --form "$SITE_FORM_TEXT" 14 55 4 \
  189. $"Title:" 1 1 "$(grep '$SITE_TITLE' temp.cfg | awk -F '=' '{print $2}')" 1 16 33 40 \
  190. $"Domain:" 2 1 "$(grep '$SITE_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 2 16 33 40 \
  191. $"Code:" 3 1 "$(grep '$SITE_CODE' temp.cfg | awk -F '=' '{print $2}')" 3 16 33 255 \
  192. 2> $data
  193. else
  194. dialog --backtitle "$SITE_BACKTITLE" \
  195. --title "$SITE_CONFIG_TITLE" \
  196. --form "$SITE_FORM_TEXT" 11 55 3 \
  197. $"Title:" 1 1 "$(grep '$SITE_TITLE' temp.cfg | awk -F '=' '{print $2}')" 1 16 33 40 \
  198. $"Domain:" 2 1 "$(grep '$SITE_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 2 16 33 40 \
  199. 2> $data
  200. fi
  201. sel=$?
  202. case $sel in
  203. 1) exit 1;;
  204. 255) exit 1;;
  205. esac
  206. SITE_TITLE=$(cat $data | sed -n 1p)
  207. SITE_DOMAIN_NAME=$(cat $data | sed -n 2p)
  208. site_domain_name_str="$SITE_DOMAIN_NAME"
  209. if [ ${#site_domain_name_str} -gt 1 ]; then
  210. TEST_DOMAIN_NAME="$SITE_DOMAIN_NAME"
  211. validate_domain_name
  212. if [[ "$TEST_DOMAIN_NAME" != "${SITE_DOMAIN_NAME}" ]]; then
  213. SITE_DOMAIN_NAME=
  214. dialog --title $"Domain name validation" --msgbox "$TEST_DOMAIN_NAME" 15 50
  215. else
  216. if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
  217. SITE_CODE=$(cat $data | sed -n 3p)
  218. validate_freedns_code "${SITE_CODE}"
  219. if [ ! $VALID_CODE ]; then
  220. SITE_DOMAIN_NAME=
  221. fi
  222. fi
  223. fi
  224. fi
  225. site_title_str="$SITE_TITLE"
  226. if [ ${#site_title_str} -gt 0 ]; then
  227. if [ ${SITE_DOMAIN_NAME} ]; then
  228. SITE_DETAILS_COMPLETE="yes"
  229. fi
  230. fi
  231. done
  232. # save the results in the config file
  233. write_config_param "$2" "${SITE_TITLE}"
  234. write_config_param "$3" "${SITE_DOMAIN_NAME}"
  235. site_code_str="$SITE_CODE"
  236. if [ ${#site_code_str} -gt 1 ]; then
  237. write_config_param "$4" "${SITE_CODE}"
  238. fi
  239. }
  240. # NOTE: deliberately no exit 0