1
0

init.sh 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. #!/bin/bash
  2. set -e
  3. red='\e[91m'
  4. green='\e[92m'
  5. yellow='\e[93m'
  6. magenta='\e[95m'
  7. cyan='\e[96m'
  8. none='\e[0m'
  9. _red() { echo -e "${red}$*${none}"; }
  10. _green() { echo -e "${green}$*${none}"; }
  11. _yellow() { echo -e "${yellow}$*${none}"; }
  12. _magenta() { echo -e "${magenta}$*${none}"; }
  13. _cyan() { echo -e "${cyan}$*${none}"; }
  14. modules="metasrht"
  15. domain_name="http://localhost"
  16. function add_module() {
  17. read -r input
  18. echo
  19. if [[ "$input" -le 1 ]]; then
  20. modules=$modules" "$1
  21. echo -e "$yellow $1 is selected${none}"
  22. fi
  23. }
  24. # Git or Mercurial or Both
  25. echo -e "Select your distributed version control system ${cyan}1.Git${none} or ${cyan}2.Mercurial${none} or ${cyan}3.Both${none}?"
  26. read -r version_control_system_input
  27. echo
  28. if [[ "$version_control_system_input" -le 1 ]]; then
  29. module="git.sr.ht"
  30. modules=$modules" "$module
  31. echo -e "$yellow $module is selected${none}"
  32. elif [[ "$version_control_system_input" -le 2 ]]; then
  33. module="hg.sr.ht"
  34. modules=$modules" "$module
  35. echo -e "$yellow $module is selected${none}"
  36. else
  37. module="git.sr.ht hg.sr.ht"
  38. modules=$modules" "$module
  39. echo -e "$yellow $module are selected${none}"
  40. fi
  41. # Domain
  42. echo -e "Set your ${cyan} Domain name ${none} or ${cyan}s (skip)${none}?"
  43. read -r domain_input
  44. echo
  45. if [[ "$domain_input" == 's' ]] || [[ -z "$null" ]]; then
  46. echo -e "$yellow skip${none}"
  47. else
  48. domain_name=$domain_input
  49. fi
  50. # CI
  51. # builds.sr.ht
  52. echo -e "Do you want to use ${cyan} Sourcehut CI ${none}? ${cyan}1.Yes${none} or ${cyan}2.No${none}?"
  53. add_module "builds.sr.ht"
  54. echo -e "Do you want to use ${cyan}Mailing list service${none}? ${cyan}1.Yes${none} or ${cyan}2.No${none}?"
  55. add_module "lists.sr.ht"
  56. # a wiki service
  57. # man.sr.ht
  58. echo -e "Do you want to use ${cyan}Wiki service${none}? ${cyan}1.Yes${none} or ${cyan}2.No${none}?"
  59. add_module "man.sr.h"
  60. # Syntax highlighting
  61. # paste.sr.ht
  62. echo -e "Do you want to use ${cyan}Syntax highlighting${none}? ${cyan}1.Yes${none} or ${cyan}2.No${none}?"
  63. add_module "paste.sr.ht"
  64. # issue and bug tracker service
  65. # todo.sr.ht
  66. echo -e "Do you want to use ${cyan}issue and bug tracker service${none}? ${cyan}1.Yes${none} or ${cyan}2.No${none}?"
  67. add_module "todo.sr.ht"
  68. echo
  69. echo
  70. echo -e "---------------------------${green}Start generate Dockerfile ${none}--------------------------------------"
  71. echo
  72. echo
  73. sed "s/{{MODULES}}/$modules/" ./template/Dockerfile.template >Dockerfile
  74. # TODO start.sh
  75. echo
  76. echo
  77. echo -e "---------------------------${green}Generate Dockerfile success${none}--------------------------------------"
  78. ## build base image
  79. #
  80. #echo -e "---------------------------${green}Start build base image ${none}--------------------------------------"
  81. #docker build -t sr.ht-base:dev ./base/
  82. #echo
  83. #echo -e "---------------------------${green}Build base image success${none}--------------------------------------"
  84. ## generate keys
  85. echo -e "---------------------------${green}Start generate keys${none}-----------------------------------------"
  86. echo
  87. echo
  88. docker run sr.ht-base:dev sh -c 'srht-keygen service && srht-keygen network && srht-keygen webhook' | awk '{n[1]="Service";n[2]="Network";n[3]=n[4]="Webhook";print n[NR]" "$0 > "genkeys"}'
  89. echo
  90. echo
  91. echo -e "$(<genkeys)"
  92. echo -e "${yellow}Distribute the webhook public key to anyone who would want to verify ${none}"
  93. echo -e "${yellow}webhook payloads from your service.${none}"
  94. echo -e "${yellow}you can see generated keys in the 'genkeys' file ${none}"
  95. echo
  96. echo
  97. echo -e "---------------------------${green}Generate keys success${none}-----------------------------------------"
  98. echo
  99. echo
  100. ## generate config
  101. echo -e "---------------------------${green}Start generate config${none}---------------------------------------"
  102. echo
  103. echo
  104. service_key=$(<genkeys grep Service | awk -F: '{print $2}')
  105. network_key=$(<genkeys grep Network | awk -F: '{print $2}')
  106. webhook_key=$(<genkeys grep Webhook | awk -F: 'BEGIN{print $2}')
  107. sed "s/{{SERVICE_KEY}}/$service_key/" ./template/config.ini.template > config.ini
  108. sed -i "s/{{NETWORK_KEY}}/$network_key/" config.ini
  109. sed -i "s/{{WEBHOOK_KEY}}/$webhook_key/" config.ini
  110. echo "$domain_name"
  111. sed -i "s@{{DOMAIN}}@$domain_name@" config.ini
  112. echo
  113. echo
  114. echo -e "---------------------------${green}Generate keys success${none}-----------------------------------------"
  115. # TODO modules config