Skip to content

Commit

Permalink
UPDATE | setup.sh, include files
Browse files Browse the repository at this point in the history
  • Loading branch information
SerhiiMazurBeetroot committed Nov 10, 2022
1 parent c81326e commit ab86025
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 287 deletions.
27 changes: 27 additions & 0 deletions .env-core/sh/scripts.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash

# shellcheck disable=SC1091
FILE_SETTINGS='./.env-core/settings.log'
FILE_INSTANCES='./.env-core/instances.log'

source_files_in() {
local dir="$1"

if [[ -d "$dir" && -r "$dir" && -x "$dir" ]]; then
for file in "$dir"/*; do
[[ -f "$file" && -r "$file" ]] && . "$file"
done
fi
}

source_files_in "./.env-core/sh/utils"
source_files_in "./.env-core/sh/core"
source_files_in "./.env-core/sh/nginx"
source_files_in "./.env-core/sh/projects/actions"
source_files_in "./.env-core/sh/projects/archives"
source_files_in "./.env-core/sh/projects/database"
source_files_in "./.env-core/sh/projects/docker"
source_files_in "./.env-core/sh/projects/setup"
source_files_in "./.env-core/sh/projects/git"
source_files_in "./.env-core/sh/projects/instances"
source_files_in "./.env-core/sh/projects/wp"
12 changes: 7 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#################################################################################
## #
## GIT IGNORE FOR WORDPRESS SITES #
## GIT IGNORE #
## ------------------------------ #
## Adapted from: http://bigwilliam.com/gitignore-for-wordpress-projects/ #
## and https://github.com/github/gitignore/blob/master/WordPress.gitignore #
Expand Down Expand Up @@ -67,16 +67,18 @@ access_log
node_modules

#===================================#
# WordPress Sites #
# Sites #
#===================================#
/projects/*
!/projects/.gitkeep

/wordpress/*
/bedrock/*
/php/*
/nodejs/*

#===============================#
# Certificates #
#===============================#
/env-core/nginx/certs-root/*
/.env-core/nginx/certs-root/*


#===============================#
Expand Down
Empty file removed projects/.gitkeep
Empty file.
320 changes: 38 additions & 282 deletions setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,294 +3,50 @@
set -o errexit #to stop the script when an error occurs
set -o pipefail

# shellcheck disable=SC1091
source ./env-core/sh/scripts.sh

main_actions () {
EMPTY_LINE
check_package_availability
detect_os
check_instances_file_exists
check_env_settings

# Notice about updates to main menu
[[ ! $ENV_UPDATES ]] && check_env_version "daily"
[[ $ENV_UPDATES == "Everything up-to-date" ]] && ENV_UPDATES=""

while true; do
ECHO_INFO "======== devENV ======="
ECHO_YELLOW "0 - Exit and do nothing"
ECHO_GREEN "1 - Nginx"
ECHO_GREEN "2 - New project"
ECHO_GREEN "3 - Existing project"
ECHO_KEY_VALUE "4 - ENV settings" "$ENV_UPDATES"

read -rp "$(ECHO_YELLOW "Please select one of:")" userChoice

case "$userChoice" in
0)
exit
;;
1)
nginx_actions
;;
2)
docker_wp_create
unset_variables
;;
3)
existing_site_actions
;;
4)
env_settings
;;
esac
done

}

nginx_actions () {
while true; do
EMPTY_LINE
ECHO_INFO "===== Nginx server ===="
ECHO_YELLOW "0 - Return to main menu"
ECHO_GREEN "1 - Setup"
ECHO_GREEN "2 - Stop"
ECHO_GREEN "3 - Start"
ECHO_GREEN "4 - Restart"
ECHO_GREEN "5 - Rebuild"

read -rp "$(ECHO_YELLOW "Please select one of:")" proxy_actions

case $proxy_actions in
0)
main_actions
;;
1)
nginx_proxy
;;
2)
docker_nginx_stop
;;
3)
docker_nginx_start
;;
4)
docker_nginx_restart
;;
5)
docker_nginx_rebuild
;;
esac
done
}

existing_site_actions () {
while true; do
EMPTY_LINE
ECHO_INFO "==== Existing sites ==="
ECHO_YELLOW "0 - Return to main menu"
ECHO_GREEN "1 - Docker actions"
ECHO_GREEN "2 - Database actions"
ECHO_GREEN "3 - GIT actions"
ECHO_INFO "4 - List of existing projects"

read -rp "$(ECHO_YELLOW "Please select one of:")" actions

case $actions in
0)
main_actions
;;
1)
docker_actions
;;
2)
db_actions
;;
3)
git_actions
;;
4)
existing_projects_list
;;
esac
done
}

db_actions () {
while true; do
EMPTY_LINE
ECHO_INFO "========== DB actions ========="
ECHO_YELLOW "0 - Return to the previous menu"
ECHO_GREEN "1 - Update DB (import)"
ECHO_GREEN "2 - Dump DB (export)"
ECHO_GREEN "3 - Search-Replace"
ECHO_GREEN "4 - Replace project from DB"
read -rp "$(ECHO_YELLOW "Please select one of:")" actions

case $actions in
0)
existing_site_actions
;;
1)
running_projects_list "========== IMPORT DB =========="
import_db
unset_variables
;;
2)
running_projects_list "========== EXPORT DB =========="
export_db
unset_variables
;;
3)
running_projects_list "====== Search-Replace DB ======"
search_replace
unset_variables
;;
4)
running_projects_list "=== Replace project from DB ==="
replace_project_from_db
docker_wp_rebuild
docker_wp_restart
import_db
fix_permissions
edit_file_wp_config_setup_beetroot
wp_get_default_theme
wp_composer_install
edit_file_env_setup_beetroot
fix_linux_watchers
edit_file_gitignore
unset_variables
;;
esac
done
}
CORE_VERSION=2.0.0

docker_actions () {
while true; do
EMPTY_LINE
ECHO_INFO "======== Docker actions ======="
ECHO_YELLOW "0 - Return to the previous menu"
ECHO_ATTENTION "1 - Permanently Remove"
ECHO_GREEN "2 - Stop"
ECHO_GREEN "3 - Start"
ECHO_GREEN "4 - Restart"
ECHO_GREEN "5 - Rebuild"
ECHO_INFO "6 - Fix permissions"
ECHO_INFO "7 - Run composer.json"
ECHO_INFO "8 - Install composer package"
read -rp "$(ECHO_YELLOW "Please select one of:")" actions

case $actions in
0)
existing_site_actions
;;
1)
docker_wp_delete
unset_variables
;;
2)
auto_backup_db
docker_wp_stop
unset_variables
;;
3)
docker_wp_start
unset_variables
;;
4)
docker_wp_restart
unset_variables
;;
5)
docker_wp_rebuild
docker_wp_restart
unset_variables
;;
6)
get_existing_domains "======= Fix permissions ======="
fix_permissions
unset_variables
;;
7)
wp_composer_install
unset_variables
existing_site_actions
;;
8)
wp_composer_package
unset_variables
existing_site_actions
;;
esac
done
}

git_actions () {
while true; do
EMPTY_LINE
ECHO_INFO "========= GIT actions ========="
ECHO_YELLOW "0 - Return to the previous menu"
ECHO_GREEN "1 - Clone from repo"
ECHO_GREEN "2 - Create Github repo"
ECHO_GREEN "3 - Create Gitlab repo"
ECHO_GREEN "4 - Repo access"
read -rp "$(ECHO_YELLOW "Please select one of:")" actions
# shellcheck disable=SC1091
source ./.env-core/sh/scripts.sh

case $actions in
0)
existing_site_actions
;;
1)
git_clone_repo
unset_variables
existing_site_actions
;;
2)
get_existing_domains "====== Create Github Repo ====="
get_project_dir "skip_question"
git_create_repo_github
unset_variables
git_actions
;;
3)
get_existing_domains "====== Create GitLab Repo ====="
get_project_dir "skip_question"
git_create_repo_gitlab
unset_variables
git_actions
;;
4)
git_save_access
git_actions
;;
esac
done
}
main_actions() {
EMPTY_LINE
healthcheck

env_settings () {
check_env_version
# Notice about updates to main menu
[[ ! $ENV_UPDATES ]] && check_env_version "daily"
[[ $ENV_UPDATES == "Everything up-to-date" ]] && ENV_UPDATES=""

while true; do
EMPTY_LINE
ECHO_INFO "===== ENV settings ===="
ECHO_YELLOW "0 - Return to main menu"
ECHO_KEY_VALUE "1 - ENV_UPDATES:" "$ENV_UPDATES"
ECHO_KEY_VALUE "2 - ENV_THEME:" "$ENV_THEME"
read -rp "$(ECHO_YELLOW "Please select one of:")" settings
ECHO_INFO "======== devENV ======="
ECHO_YELLOW "0 - Exit and do nothing"
ECHO_GREEN "1 - Nginx"
ECHO_GREEN "2 - New project"
ECHO_GREEN "3 - Existing project"
ECHO_KEY_VALUE "4 - ENV settings" "$ENV_UPDATES"



read -rp "$(ECHO_YELLOW "Please select one of:")" userChoice

case "$userChoice" in
0)
exit
;;
1)
nginx_actions
;;
2)
actions_new_project
;;
3)
actions_existing_project
;;
4)
env_settings
;;
esac
done

case $settings in
0)
main_actions
;;
1)
update_env
;;
2)
change_env_theme
;;
esac
done
}

main_actions

0 comments on commit ab86025

Please sign in to comment.