configure 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  1. #!/bin/sh
  2. ROOT="$(git rev-parse --show-toplevel)"
  3. HEIGHT=13
  4. WIDTH=51
  5. check_retval(){
  6. case $1 in
  7. 1|255)
  8. echo "Stopped"
  9. exit;;
  10. esac
  11. }
  12. check_input(){
  13. if [ "$1" = "" ]
  14. then
  15. echo "Can't be empty"
  16. exit
  17. fi
  18. }
  19. exec 3>&1
  20. domain_root=$(dialog \
  21. --title "Configure" \
  22. --clear \
  23. --ok-label "Ok" \
  24. --cancel-label "Exit" \
  25. --inputbox "Domain root:" $HEIGHT $WIDTH \
  26. 2>&1 1>&3)
  27. check_retval $?
  28. exec 3>&-
  29. check_input $domain_root
  30. exec 3>&1
  31. sub_domain=$(dialog \
  32. --title "Configure" \
  33. --clear \
  34. --ok-label "Ok" \
  35. --cancel-label "Exit" \
  36. --inputbox "Subdomain (can be empty):" $HEIGHT $WIDTH \
  37. 2>&1 1>&3)
  38. check_retval $?
  39. exec 3>&-
  40. exec 3>&1
  41. signed=$(dialog \
  42. --title "Configure" \
  43. --clear \
  44. --ok-label "Ok" \
  45. --cancel-label "Exit" \
  46. --menu "Use certificate signed by Let's Encrypt?" $HEIGHT $WIDTH 2 \
  47. "Y" "" \
  48. "n" "" \
  49. 2>&1 1>&3)
  50. check_retval $?
  51. exec 3>&-
  52. [ "${signed}" = "${signed#[Yy]}" ]
  53. signed=$?
  54. if [ $signed -ne 0 ]; then
  55. exec 3>&1
  56. email=$(dialog \
  57. --title "Configure" \
  58. --clear \
  59. --ok-label "Ok" \
  60. --cancel-label "Exit" \
  61. --inputbox "Email:" $HEIGHT $WIDTH \
  62. 2>&1 1>&3)
  63. check_retval $?
  64. exec 3>&-
  65. check_input $email
  66. fi
  67. if [ -z "$sub_domain" ]
  68. then
  69. domain="${domain_root}"
  70. else
  71. domain="${sub_domain}.${domain_root}"
  72. fi
  73. mkdir -p $ROOT/docker/bootstrap
  74. cat > $ROOT/docker/bootstrap/bootstrap.env <<EOF
  75. #!/bin/sh
  76. email=${email}
  77. domain=${domain}
  78. domain_root=${domain_root}
  79. signed=${signed}
  80. EOF
  81. chmod +x ./docker/bootstrap/bootstrap.env
  82. docker-compose -f docker/bootstrap/bootstrap.yaml up
  83. git_dir=$PWD
  84. while [ ! -d .git ]; do
  85. git_dir=$(dirname "${git_dir}")
  86. done
  87. cd "${git_dir}" || exit
  88. if [ ! -f ./docker/bootstrap/bootstrap.env ]; then
  89. printf "bootstrap.env missing! Please run the bootstrap_certificates script.\n"
  90. exit 1
  91. fi
  92. . ./docker/bootstrap/bootstrap.env
  93. exec 3>&1
  94. dbms=$(dialog \
  95. --title "Configure" \
  96. --clear \
  97. --ok-label "Ok" \
  98. --cancel-label "Exit" \
  99. --menu "Select DBMS:" $HEIGHT $WIDTH 2 \
  100. "postgres" "" \
  101. "mariadb" "" \
  102. 2>&1 1>&3)
  103. check_retval $?
  104. exec 3>&-
  105. exec 3>&1
  106. db=$(dialog \
  107. --title "Configure" \
  108. --clear \
  109. --ok-label "Ok" \
  110. --cancel-label "Exit" \
  111. --inputbox "GNU social database name:" $HEIGHT $WIDTH \
  112. 2>&1 1>&3)
  113. check_retval $?
  114. exec 3>&-
  115. if [ "${dbms}" = 'mariadb' ]
  116. then
  117. exec 3>&1
  118. user=$(dialog \
  119. --title "Configure" \
  120. --clear \
  121. --ok-label "Ok" \
  122. --cancel-label "Exit" \
  123. --inputbox "Database user:" $HEIGHT $WIDTH \
  124. 2>&1 1>&3)
  125. check_retval $?
  126. exec 3>&-
  127. check_input $user
  128. fi
  129. exec 3>&1
  130. password=$(dialog \
  131. --title "Configure" \
  132. --clear \
  133. --ok-label "Ok" \
  134. --cancel-label "Exit" \
  135. --inputbox "Database password:" $HEIGHT $WIDTH \
  136. 2>&1 1>&3)
  137. check_retval $?
  138. exec 3>&-
  139. check_input $password
  140. exec 3>&1
  141. sitename=$(dialog \
  142. --title "Configure" \
  143. --clear \
  144. --ok-label "Ok" \
  145. --cancel-label "Exit" \
  146. --inputbox "Sitename:" $HEIGHT $WIDTH \
  147. 2>&1 1>&3)
  148. check_retval $?
  149. exec 3>&-
  150. check_input $sitename
  151. exec 3>&1
  152. admin_nick=$(dialog \
  153. --title "Configure" \
  154. --clear \
  155. --ok-label "Ok" \
  156. --cancel-label "Exit" \
  157. --inputbox "Admin nickname:" $HEIGHT $WIDTH \
  158. 2>&1 1>&3)
  159. check_retval $?
  160. exec 3>&-
  161. check_input $admin_nick
  162. exec 3>&1
  163. admin_password=$(dialog \
  164. --title "Configure" \
  165. --clear \
  166. --ok-label "Ok" \
  167. --cancel-label "Exit" \
  168. --inputbox "Admin password:" $HEIGHT $WIDTH \
  169. 2>&1 1>&3)
  170. check_retval $?
  171. exec 3>&-
  172. check_input $admin_password
  173. exec 3>&1
  174. profile=$(dialog \
  175. --title "Configure" \
  176. --clear \
  177. --ok-label "Ok" \
  178. --cancel-label "Exit" \
  179. --menu "Site profile:" $HEIGHT $WIDTH 4 \
  180. "public" "" \
  181. "private" "" \
  182. "community" "" \
  183. "single_user" "" \
  184. 2>&1 1>&3)
  185. check_retval $?
  186. exec 3>&-
  187. exec 3>&1
  188. mailer_dsn=$(dialog \
  189. --title "Configure" \
  190. --clear \
  191. --ok-label "Ok" \
  192. --cancel-label "Exit" \
  193. --inputbox "Mailer dsn:" $HEIGHT $WIDTH \
  194. 2>&1 1>&3)
  195. check_retval $?
  196. exec 3>&-
  197. check_input $mailer_dsn
  198. mkdir -p $ROOT/docker/db
  199. if [ "${dbms}" = 'mariadb' ]; then
  200. exec 3>&1
  201. db_root_password=$(dialog \
  202. --title "Configure" \
  203. --clear \
  204. --ok-label "Ok" \
  205. --cancel-label "Exit" \
  206. --inputbox "DB root password" $HEIGHT $WIDTH \
  207. 2>&1 1>&3)
  208. check_retval $?
  209. exec 3>&-
  210. check_input $db_root_password
  211. cat > $ROOT/docker/db/db.env <<EOF
  212. DBMS=${dbms}
  213. MYSQL_ROOT_PASSWORD=${db_root_password}
  214. EOF
  215. database_url="DATABASE_URL=mysql://${user}:${password}@db:3306/${db}"
  216. else
  217. cat > $ROOT/docker/db/db.env <<EOF
  218. DBMS=${dbms}
  219. POSTGRES_USER=postgres
  220. POSTGRES_PASSWORD=${password}
  221. EOF
  222. user='postgres'
  223. database_url="DATABASE_URL=postgresql://${user}:${password}@db:5432/${db}"
  224. fi
  225. echo "${database_url}" >> .env.local
  226. mkdir -p $ROOT/docker/social
  227. cat > $ROOT/docker/social/social.env <<EOF
  228. SOCIAL_DBMS="${dbms}"
  229. SOCIAL_DB="${db}"
  230. SOCIAL_USER="${user}"
  231. SOCIAL_PASSWORD="${password}"
  232. SOCIAL_DOMAIN="${domain}"
  233. SOCIAL_SITENAME="${sitename}"
  234. SOCIAL_ADMIN_NICK="${admin_nick}"
  235. SOCIAL_ADMIN_PASSWORD="${admin_password}"
  236. SOCIAL_ADMIN_EMAIL="${email}"
  237. SOCIAL_SITE_PROFILE="${profile}"
  238. MAILER_DSN="${mailer_dsn}"
  239. EOF
  240. exec 3>&1
  241. docker_compose=$(dialog \
  242. --title "Services" \
  243. --clear \
  244. --ok-label "Ok" \
  245. --cancel-label "Exit" \
  246. --checklist "Services to include in docker-compose:" $HEIGHT $WIDTH 6 \
  247. "nginx" "" on \
  248. "certbot" "" on \
  249. "php" "" on \
  250. "db" "" on \
  251. "redis" "" on \
  252. "mail" "" on \
  253. 2>&1 1>&3)
  254. check_retval $?
  255. exec 3>&-
  256. echo "version: '3.3'" > docker-compose.yaml
  257. echo "\nservices:" >> docker-compose.yaml
  258. case $docker_compose in *"nginx"*)
  259. $ROOT/docker/social/nginx
  260. esac
  261. case $docker_compose in *"certbot"*)
  262. $ROOT/docker/social/certbot
  263. esac
  264. case $docker_compose in *"php"*)
  265. $ROOT/docker/social/php
  266. esac
  267. case $docker_compose in *"db"*)
  268. $ROOT/docker/social/db
  269. esac
  270. case $docker_compose in *"redis"*)
  271. $ROOT/docker/social/redis
  272. esac
  273. case $docker_compose in *"mail"*)
  274. $ROOT/docker/social/mail
  275. exec 3>&1
  276. mail_domain_root=$(dialog \
  277. --title "Configure Mail" \
  278. --clear \
  279. --ok-label "Ok" \
  280. --cancel-label "Exit" \
  281. --inputbox "E-mail domain root:" $HEIGHT $WIDTH \
  282. 2>&1 1>&3)
  283. check_retval $?
  284. exec 3>&-
  285. check_input $mail_domain_root
  286. exec 3>&1
  287. mail_subdomain=$(dialog \
  288. --title "Configure Mail" \
  289. --clear \
  290. --ok-label "Ok" \
  291. --cancel-label "Exit" \
  292. --inputbox "E-mail subdomain (can be empty):" $HEIGHT $WIDTH \
  293. 2>&1 1>&3)
  294. check_retval $?
  295. exec 3>&-
  296. exec 3>&1
  297. mail_user=$(dialog \
  298. --title "Configure Mail" \
  299. --clear \
  300. --ok-label "Ok" \
  301. --cancel-label "Exit" \
  302. --inputbox "E-mail user (name without @domain): " $HEIGHT $WIDTH \
  303. 2>&1 1>&3)
  304. check_retval $?
  305. exec 3>&-
  306. check_input $mail_user
  307. exec 3>&1
  308. mail_pass=$(dialog \
  309. --title "Configure Mail" \
  310. --clear \
  311. --ok-label "Ok" \
  312. --cancel-label "Exit" \
  313. --inputbox "E-mail user password: " $HEIGHT $WIDTH \
  314. 2>&1 1>&3)
  315. check_retval $?
  316. exec 3>&-
  317. check_input $mail_pass
  318. mkdir -p $ROOT/docker/mail
  319. cat > $ROOT/docker/mail/mail.env <<EOF
  320. MAIL_DOMAIN_ROOT="${mail_domain_root}"
  321. MAIL_SUBDOMAIN="${mail_subdomain}"
  322. MAIL_USER="${mail_user}"
  323. MAIL_PASSWORD="${mail_pass}"
  324. EOF
  325. $ROOT/docker/mail/setup.sh
  326. esac
  327. echo "volumes:\n database:" >> docker-compose.yaml