Skip to content
Snippets Groups Projects
Commit 09881203 authored by Nikolaos Kakouros's avatar Nikolaos Kakouros
Browse files

wip

parent 318894a9
No related branches found
No related tags found
No related merge requests found
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
# #
# Options: # Options:
# --update Update configuration and dependencies # --update Update configuration and dependencies
# --noninteractive Do not ask anything
# #
# #
# Examples: # Examples:
...@@ -63,6 +64,12 @@ function core_bootstrap_git_lay() { ...@@ -63,6 +64,12 @@ function core_bootstrap_git_lay() {
} }
function core_bootstrap_ask_passphrase() { function core_bootstrap_ask_passphrase() {
@required [boolean] interactive
if [[ "$interactive" == "false" ]]; then
return
fi
. "$_GO_USE_MODULES" 'prompt' . "$_GO_USE_MODULES" 'prompt'
eval "$(ssh-agent -t 300)" eval "$(ssh-agent -t 300)"
...@@ -155,8 +162,6 @@ function core_bootstrap_set_version() { ...@@ -155,8 +162,6 @@ function core_bootstrap_set_version() {
# TODO do this generic, load prompts from conf file # TODO do this generic, load prompts from conf file
function core_bootstrap_configure() { function core_bootstrap_configure() {
@required [boolean] confirm
. "$_GO_USE_MODULES" "prompt" . "$_GO_USE_MODULES" "prompt"
local project_prompt local project_prompt
...@@ -166,7 +171,7 @@ function core_bootstrap_configure() { ...@@ -166,7 +171,7 @@ function core_bootstrap_configure() {
local old_region local old_region
local old_zone local old_zone
if [[ "$confirm" == 'true' && -e "$_HEADSTART_PROJECT_CONFIG" ]]; then if [[ -e "$_HEADSTART_PROJECT_CONFIG" ]]; then
string="The project has already been configured. " string="The project has already been configured. "
string+="Do you want to overwrite the existing configuration?" string+="Do you want to overwrite the existing configuration?"
if ! @go.prompt_for_yes_or_no "$string" 'no'; then if ! @go.prompt_for_yes_or_no "$string" 'no'; then
...@@ -194,8 +199,6 @@ function core_bootstrap_configure() { ...@@ -194,8 +199,6 @@ function core_bootstrap_configure() {
mkdir -p "${_HEADSTART_PROJECT_CONFIG%/*}" mkdir -p "${_HEADSTART_PROJECT_CONFIG%/*}"
fi fi
echo '[default]' >|"$_HEADSTART_PROJECT_CONFIG"
project_prompt="${project_prompt-ID of Google Cloud project: }" project_prompt="${project_prompt-ID of Google Cloud project: }"
local project='' local project=''
@go.prompt_for_input \ @go.prompt_for_input \
...@@ -204,6 +207,7 @@ function core_bootstrap_configure() { ...@@ -204,6 +207,7 @@ function core_bootstrap_configure() {
"${old_project-}" \ "${old_project-}" \
'' "${old_project:-required}" '' "${old_project:-required}"
echo '[default]' >|"$_HEADSTART_PROJECT_CONFIG"
echo "project = $project" >>"$_HEADSTART_PROJECT_CONFIG" echo "project = $project" >>"$_HEADSTART_PROJECT_CONFIG"
reuse_prompt="${reuse_prompt-players per world: }" reuse_prompt="${reuse_prompt-players per world: }"
...@@ -255,15 +259,15 @@ function core_bootstrap_lock() { ...@@ -255,15 +259,15 @@ function core_bootstrap_lock() {
function core_bootstrap() { function core_bootstrap() {
local update=false local update=false
local confirm=true local interactive=true
while [[ "$#" -gt 0 ]]; do while [[ "$#" -gt 0 ]]; do
case "$1" in case "$1" in
--update) --update)
update=true update=true
;; ;;
--noconfirm) --noninteractive)
confirm=false interactive=false
;; ;;
-*) -*)
abort "unrecognized option: $1" "$_HEADSTART_EC_USAGE" abort "unrecognized option: $1" "$_HEADSTART_EC_USAGE"
...@@ -277,6 +281,10 @@ function core_bootstrap() { ...@@ -277,6 +281,10 @@ function core_bootstrap() {
. "$_GO_USE_MODULES" 'installation' 'core' . "$_GO_USE_MODULES" 'installation' 'core'
if [[ ! -r "$_HEADSTART_PROJECT_CONFIG" && "$interactive" == false ]]; then
abort "twmn is not configured yet, run bootstrap in interactive mode" "$_HEADSTART_EC_NOTFND"
fi
if [[ "$(get_installation_status)" == 'bootstrapped' && "$update" == 'false' ]]; then if [[ "$(get_installation_status)" == 'bootstrapped' && "$update" == 'false' ]]; then
warn 'project is already bootstrapped, nothing to do' warn 'project is already bootstrapped, nothing to do'
exit exit
...@@ -284,8 +292,11 @@ function core_bootstrap() { ...@@ -284,8 +292,11 @@ function core_bootstrap() {
mkdir -p "$_HEADSTART_TMP_DIR" mkdir -p "$_HEADSTART_TMP_DIR"
core_bootstrap_ask_passphrase if [[ "$interactive" == true ]]; then
core_bootstrap_configure "$confirm" core_bootstrap_ask_passphrase
core_bootstrap_configure
fi
core_bootstrap_git_collab core_bootstrap_git_collab
core_bootstrap_git_hooks core_bootstrap_git_hooks
core_bootstrap_git_branches core_bootstrap_git_branches
......
...@@ -133,7 +133,7 @@ function headstart() { ...@@ -133,7 +133,7 @@ function headstart() {
elif [[ "${rest[*]}" =~ ^core\ bootstrap$ && "$print_help" == 'true' ]]; then elif [[ "${rest[*]}" =~ ^core\ bootstrap$ && "$print_help" == 'true' ]]; then
@go help "${rest[@]}" @go help "${rest[@]}"
return return
elif [[ "${rest[*]}" =~ ^core\ bootstrap\ *$ ]]; then elif [[ "${rest[*]}" =~ ^core\ bootstrap\.*$ ]]; then
@go "${rest[@]}" @go "${rest[@]}"
return return
else else
......
...@@ -12,12 +12,12 @@ function get_installation_status() { ...@@ -12,12 +12,12 @@ function get_installation_status() {
local project_installation_status local project_installation_status
project_installation_status='uninstalled' project_installation_status='uninstalled'
if [[ -f "$_HEADSTART_CORE_LOCK" ]]; then if [[ -r "$_HEADSTART_CORE_LOCK" && -r "$_HEADSTART_PROJECT_CONFIG" ]]; then
while read -s line; do while read -s line; do
if [[ "$line" =~ ^status=(.*) ]]; then if [[ "$line" =~ ^status=(.*) ]]; then
project_installation_status="${BASH_REMATCH[1]}" project_installation_status="${BASH_REMATCH[1]}"
fi fi
done < "$_HEADSTART_CORE_LOCK" done <"$_HEADSTART_CORE_LOCK"
fi fi
echo $project_installation_status echo $project_installation_status
...@@ -68,8 +68,8 @@ download_tarball() { ...@@ -68,8 +68,8 @@ download_tarball() {
printf "Downloading from '%s'...\n" "$url" printf "Downloading from '%s'...\n" "$url"
mkdir -p "$install_dir" mkdir -p "$install_dir"
if ! "${download_cmd[@]}" | tar -xzf - -C /tmp/ || if ! "${download_cmd[@]}" | tar -xzf - -C /tmp/ \
[[ "${PIPESTATUS[0]}" -ne '0' ]]; then || [[ "${PIPESTATUS[0]}" -ne '0' ]]; then
printf "Failed to download from '%s'.\n" "$url" >&2 printf "Failed to download from '%s'.\n" "$url" >&2
return 1 return 1
elif ! mv "/tmp/$unpacked_dir/"* "$install_dir"; then elif ! mv "/tmp/$unpacked_dir/"* "$install_dir"; then
......
...@@ -23,7 +23,7 @@ function project_get_gce_project() { ...@@ -23,7 +23,7 @@ function project_get_gce_project() {
local ec=0 local ec=0
grep -E "project ?=" "$_HEADSTART_PROJECT_CONFIG" >/dev/null || ec="$?" grep -E "project ?=" "$_HEADSTART_PROJECT_CONFIG" >/dev/null || ec="$?"
if [[ "$ec" -ne 0 ]]; then if [[ "$ec" -ne 0 ]]; then
abort "project.conf is corrupted! Rerun '${_HEADSTART_CMD##*/} project setup'" abort "project.conf is corrupted! Delete it and rerun '${_HEADSTART_CMD##*/} core bootstrap'"
fi fi
project="$(grep -E "project ?=" "$_HEADSTART_PROJECT_CONFIG")" project="$(grep -E "project ?=" "$_HEADSTART_PROJECT_CONFIG")"
project="$(echo "$project" | sed -E 's/[\s\t]*project ?= ?([a-zA-Z0-9-]+)/\1/' | tr -d "[:space:]")" project="$(echo "$project" | sed -E 's/[\s\t]*project ?= ?([a-zA-Z0-9-]+)/\1/' | tr -d "[:space:]")"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment