ソースを参照

✨: select mode

ulyc 2 年 前
コミット
dc40621313
1 ファイル変更102 行追加50 行削除
  1. 102 50
      init.sh

+ 102 - 50
init.sh

@@ -3,6 +3,7 @@
 #   Author: ulyc
 #======================================
 set -eo pipefail
+
 red='\e[91m'
 green='\e[92m'
 yellow='\e[93m'
@@ -15,8 +16,15 @@ _yellow() { echo -e "${yellow}$*${none}"; }
 _magenta() { echo -e "${magenta}$*${none}"; }
 _cyan() { echo -e "${cyan}$*${none}"; }
 
-modules="metasrht"
 domain_name="http://localhost"
+modules=""
+git_module="git.sr.ht"
+hg_module="hg.sr.ht"
+build_module="builds.sr.h"
+list_module="lists.sr.ht"
+man_module="man.sr.ht"
+paste_module="paste.sr.ht"
+todo_module="todo.sr.ht"
 
 function add_module() {
   read -r input
@@ -48,34 +56,100 @@ function generate_config() {
   sed -i "s@{{DOMAIN}}@$domain_name@" config.ini
 }
 
+function generate_keys() {
+  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"}'
+}
+
 function build_base_image() {
   docker build -t sr.ht-base:dev ./base/ && echo
 }
 
-function generate_keys() {
-  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"}'
+function select_version_control() {
+  # Git or Mercurial or Both
+  echo -e "Select your distributed version control system ${cyan}1.Git${none} or ${cyan}2.Mercurial${none} or ${cyan}3.Both${none}?"
+  read -r version_control_system_input
+  echo
+
+  if [[ "$version_control_system_input" -le 1 ]]; then
+    modules=$modules" "$git_module
+    echo -e "$yellow $modules is selected${none}"
+  elif [[ "$version_control_system_input" -le 2 ]]; then
+    modules=$modules" "$hg_module
+    echo -e "$yellow  $modules is selected${none}"
+  else
+    modules=$modules' '$git_module' '$hg_module
+    echo -e "$yellow $modules are selected${none}"
+  fi
 }
 
-# Git or Mercurial or Both
-echo -e "Select your distributed version control system ${cyan}1.Git${none} or ${cyan}2.Mercurial${none} or ${cyan}3.Both${none}?"
-read -r version_control_system_input
-echo
+function advance_config() {
+  # CI
+  # builds.sr.ht
 
-if [[ "$version_control_system_input" -le 1 ]]; then
-  module="git.sr.ht"
-  modules=$modules" "$module
-  echo -e "$yellow $module is selected${none}"
-elif [[ "$version_control_system_input" -le 2 ]]; then
-  module="hg.sr.ht"
-  modules=$modules" "$module
-  echo -e "$yellow  $module is selected${none}"
-else
-  module="git.sr.ht hg.sr.ht"
-  modules=$modules" "$module
-  echo -e "$yellow $module are selected${none}"
-fi
+  echo -e "Do you want to use ${cyan} Sourcehut CI ${none}? ${cyan}1.Yes${none} or ${cyan}2.No${none}?"
+  add_module "$build_module"
+
+  echo -e "Do you want to use ${cyan}Mailing list service${none}? ${cyan}1.Yes${none} or ${cyan}2.No${none}?"
+  add_module "$list_module"
+
+  # wiki service
+  #  man.sr.ht
+  echo -e "Do you want to use ${cyan}Wiki service${none}? ${cyan}1.Yes${none} or ${cyan}2.No${none}?"
+  add_module "$man_module"
+
+  # Syntax highlighting
+  # paste.sr.ht
+  echo -e "Do you want to use ${cyan}Syntax highlighting${none}? ${cyan}1.Yes${none} or ${cyan}2.No${none}?"
+  add_module "$paste_module"
+
+  # issue and bug tracker service
+  # todo.sr.ht
+  echo -e "Do you want to use ${cyan}issue and bug tracker service${none}? ${cyan}1.Yes${none} or ${cyan}2.No${none}?"
+  add_module "$todo_module"
 
-# Domain
+}
+
+function select_mode() {
+  min_mode="Minimal Installation(Install only required modules)"
+  max_mod="Maximize Installation(Install all modules)"
+  adv_mod="Advanced Mode(Choose your own personalized modules)"
+  quit="Quit"
+  mode=("$min_mode" "$max_mod" "$adv_mod" "$quit")
+  PS3="Select the installation mode: "
+  select item in "${mode[@]}"; do
+    case $item in
+    "$min_mode")
+      echo "$item"
+      select_version_control
+      break
+      ;;
+    "$max_mod")
+      echo "$item"
+      modules=$modules"$git_module $hg_module $build_module $list_module $man_module $paste_module $todo_module"
+      break
+      ;;
+    "$adv_mod")
+      echo "$item"
+      advance_config
+      break
+      ;;
+    "$quit")
+      exit
+      ;;
+    quit)
+      break
+      ;;
+    *)
+      echo "Invalid option $REPLY"
+      ;;
+    esac
+  done
+}
+
+## Start
+select_mode
+
+# Set Domain
 echo -e "Set your ${cyan} Domain name ${none} or ${cyan}s (skip)${none}?"
 read -r domain_input
 echo
@@ -85,45 +159,23 @@ else
   domain_name=$domain_input
 fi
 
-# CI
-# builds.sr.ht
-
-echo -e "Do you want to use ${cyan} Sourcehut CI ${none}? ${cyan}1.Yes${none} or ${cyan}2.No${none}?"
-add_module "builds.sr.ht"
-
-echo -e "Do you want to use ${cyan}Mailing list service${none}? ${cyan}1.Yes${none} or ${cyan}2.No${none}?"
-add_module "lists.sr.ht"
-
-#  a wiki service
-#  man.sr.ht
-echo -e "Do you want to use ${cyan}Wiki service${none}? ${cyan}1.Yes${none} or ${cyan}2.No${none}?"
-add_module "man.sr.h"
-
-# Syntax highlighting
-# paste.sr.ht
-echo -e "Do you want to use ${cyan}Syntax highlighting${none}? ${cyan}1.Yes${none} or ${cyan}2.No${none}?"
-add_module "paste.sr.ht"
-
-# issue and bug tracker service
-# todo.sr.ht
-echo -e "Do you want to use ${cyan}issue and bug tracker service${none}? ${cyan}1.Yes${none} or ${cyan}2.No${none}?"
-add_module "todo.sr.ht"
-
+# TODO start.sh
+#
 echo
 echo
 sed "s/{{MODULES}}/$modules/" ./template/Dockerfile.template >Dockerfile &
-progress $! "🐋Generate Dockerfile"
-# TODO start.sh
+progress $! "🐋 Generate Dockerfile"
+
 
 echo
 echo
 build_base_image &
-progress $! "🐋Build Base Image"
+progress $! "🐋 Build Base Image"
 
 echo
 echo
 generate_keys &
-progress $! "🔒Generate Keys"
+progress $! "🔒 Generate Keys"
 echo
 echo
 echo -e "$(<genkeys)"
@@ -134,7 +186,7 @@ echo -e "${yellow}you can see generated keys in the  'genkeys' file ${none}"
 echo
 echo
 generate_config
-progress $! "🔧Generate Config"
+progress $! "🔧 Generate Config"
 echo
 echo