init.sh 3.8 KB

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