-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
254 additions
and
644 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,19 @@ | ||
#!/bin/bash | ||
|
||
# This script variables | ||
# Author: [email protected] | ||
# Script: _deployments.sh | ||
# Link https://github.com/xorenio/deploy-cli.sh | ||
# Description: Functions script. | ||
|
||
# Script variables | ||
NOWDATESTAMP="${NOWDATESTAMP:-$(date "+%Y-%m-%d_%H-%M-%S")}" | ||
|
||
SCRIPT_NAME="${SCRIPT_NAME:-$(basename "$(test -L "$0" && readlink "$0" || echo "$0")" | sed 's/\.[^.]*$//')}" | ||
SCRIPT="${SCRIPT:-$(basename "$(test -L "$0" && readlink "$0" || echo "$0")")}" | ||
SCRIPT_DIR="${SCRIPT_DIR:-$(cd "$(dirname "$0")" && pwd)}" | ||
SCRIPT_DIR_NAME="${SCRIPT_DIR_NAME:-$(basename "$PWD")}" | ||
SCRIPT_DEBUG=${SCRIPT_DEBUG:-false} | ||
|
||
# Terminal starting directory | ||
STARTING_LOCATION=${STARTING_LOCATION:-"$(pwd)"} | ||
|
||
# Deployment environment | ||
DEPLOYMENT_ENV=${DEPLOYMENT_ENV:-"production"} | ||
|
||
|
@@ -886,37 +890,6 @@ _download_project_files() { | |
|
||
# END - UPDATE FUNCTIONS | ||
|
||
# START - COMPLETION | ||
# _script_completion() { | ||
# local cur prev opts | ||
# COMPREPLY=() | ||
# cur="${COMP_WORDS[COMP_CWORD]}" | ||
# prev="${COMP_WORDS[COMP_CWORD-1]}" | ||
# opts="user:add linux:install setup:hpages setup:ssh:keys setup:certbot setup:git:profile setup:well-known certbot:add system:json repo:check repo:update queue:worker config:backup config:restore version:local version:remote" | ||
|
||
# case "${prev}" in | ||
# certbot:add) | ||
# # Custom completion for certbot:add option | ||
# COMPREPLY=($(compgen -f -- "${cur}")) | ||
# return 0 | ||
# ;; | ||
# user:add) | ||
# # Custom completion for user:add option | ||
# COMPREPLY=($(compgen -f -- "${cur}")) | ||
# return 0 | ||
# ;; | ||
# *) | ||
# ;; | ||
# esac | ||
|
||
# COMPREPLY=($(compgen -W "${opts}" -- "${cur}")) | ||
# return 0 | ||
# } | ||
|
||
# complete -F _script_completion "${SCRIPT}" | ||
|
||
# END - COMPLETION | ||
|
||
# START - SETUP | ||
|
||
# Function: _setup | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,29 @@ | ||
#!/bin/bash | ||
|
||
# This script variables | ||
# Author: [email protected] | ||
# Script: _extras.sh | ||
# Link https://github.com/xorenio/deploy-cli.sh | ||
# Description: Functions script. | ||
|
||
# Script variables | ||
NOWDATESTAMP="${NOWDATESTAMP:-$(date "+%Y-%m-%d_%H-%M-%S")}" | ||
|
||
SCRIPT_NAME="${SCRIPT_NAME:-$(basename "$(test -L "$0" && readlink "$0" || echo "$0")" | sed 's/\.[^.]*$//')}" | ||
SCRIPT="${SCRIPT:-$(basename "$(test -L "$0" && readlink "$0" || echo "$0")")}" | ||
SCRIPT_DIR="${SCRIPT_DIR:-$(cd "$(dirname "$0")" && pwd)}" | ||
SCRIPT_DIR_NAME="${SCRIPT_DIR_NAME:-$(basename "$PWD")}" | ||
SCRIPT_DEBUG=${SCRIPT_DEBUG:-false} | ||
|
||
# Terminal starting directory | ||
STARTING_LOCATION=${STARTING_LOCATION:-"$(pwd)"} | ||
# Commandline arguments. | ||
SCRIPT_CMD_ARG=${SCRIPT_CMD_ARG:-("${@:1}")} | ||
FUNCTION_ARG=${FUNCTION_ARG:-("${@:2}")} | ||
|
||
# Deployment environment | ||
DEPLOYMENT_ENV=${DEPLOYMENT_ENV:-"production"} | ||
|
||
# Enable location targeted deployment | ||
DEPLOYMENT_ENV_LOCATION=${DEPLOYMENT_ENV_LOCATION:-false} | ||
|
||
# Deployment location | ||
ISOLOCATION=${ISOLOCATION:-"GB"} | ||
ISOSTATELOCATION=${ISOSTATELOCATION:-""} | ||
|
||
# Git repo name | ||
GIT_REPO_NAME="${GIT_REPO_NAME:-$(basename "$(git rev-parse --show-toplevel)")}" | ||
|
||
# if using GitHub, Github Details if not ignore | ||
GITHUB_REPO_OWNER="${GITHUB_REPO_OWNER:-$(git remote get-url origin | sed -n 's/.*github.com:\([^/]*\)\/.*/\1/p')}" | ||
GITHUB_REPO_URL="${GITHUB_REPO_URL:-"https://api.github.com/repos/$GITHUB_REPO_OWNER/$GIT_REPO_NAME/commits"}" | ||
|
||
SCRIPT_LOG_FILE=${SCRIPT_LOG_FILE:-"${SCRIPT_DIR}/${SCRIPT_NAME}.log"} | ||
SCRIPT_LOG_EMAIL_FILE=${SCRIPT_LOG_EMAIL_FILE:-"$HOME/${SCRIPT_NAME}.mail.log"} | ||
JSON_FILE_NAME=${JSON_FILE_NAME:-"${SCRIPT_DIR}/${SCRIPT_NAME}_${NOWDATESTAMP}.json"} | ||
SCRIPT_RUNNING_FILE=${SCRIPT_RUNNING_FILE:-"${HOME}/${GIT_REPO_NAME}_running.txt"} | ||
|
||
LATEST_PROJECT_SHA=${LATEST_PROJECT_SHA:-0} | ||
|
||
# START - IMPORT FUNCTIONS | ||
if [[ ! -n "$(type -t _registered)" ]]; then | ||
if [[ -f "${SCRIPT_DIR}/.${SCRIPT_NAME}/_functions.sh" ]]; then | ||
|
@@ -42,3 +32,64 @@ if [[ ! -n "$(type -t _registered)" ]]; then | |
fi | ||
fi | ||
# END - IMPORT FUNCTIONS | ||
|
||
# Function: _registered_extras | ||
# Description: function to registered this file as imported as to not reimport this file. | ||
# Parameters: None | ||
# Returns: 0 | ||
|
||
_registered_extras() { | ||
return 0 | ||
} | ||
|
||
# Function: __extras_options | ||
# Description: function to manage extra script actions. | ||
# Parameters: None | ||
# Returns: 0 | ||
|
||
__extras_options() { | ||
local SCRIPT_CMD_ARG="$1" | ||
case "${SCRIPT_CMD_ARG[0]}" in | ||
"user:create") | ||
_create_user "${FUNCTION_ARG[@]}" | ||
_exit_script | ||
;; | ||
"user:remove") | ||
_remove_user "${FUNCTION_ARG[@]}" | ||
_exit_script | ||
;; | ||
esac | ||
} | ||
|
||
# Function: __display_info_extras | ||
# Description: function to display extra actions info. | ||
# Parameters: None | ||
# Returns: 0 | ||
|
||
__display_info_extras() { | ||
cat <<EOF | ||
user:create Synchronised create user on cluster. | ||
user:remove Synchronised remove user on cluster. | ||
EOF | ||
} | ||
|
||
# Function: _create_user | ||
# Description: function to create/ensure a user on all VMs is cluster. | ||
# Parameters: None | ||
# Returns: | ||
|
||
_create_user() { | ||
_log_info "Disabled atm, not seeting up user $1" | ||
return | ||
} | ||
|
||
# Function: _remove_user | ||
# Description: function to remove a user on all VMs is cluster. | ||
# Parameters: None | ||
# Returns: | ||
|
||
_remove_user() { | ||
_log_info "Remove user hasn't been setup, not seeting up user $1" | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,67 +2,12 @@ | |
|
||
# Author: [email protected] | ||
# Script: _functions.sh | ||
# Link https://github.com/xorenio | ||
# Link https://github.com/xorenio/deploy-cli.sh | ||
# Description: Functions script. | ||
|
||
### | ||
#INDEX | ||
## Function | ||
# _log_error() | ||
# _log_info() | ||
# _log_debug() | ||
# _log_success() | ||
# _log_data() | ||
# _log_to_file() | ||
# _log_console() | ||
# _create_running_file() | ||
# _check_running_file() | ||
# _delete_running_file() | ||
# _exit_script() | ||
# _in_working_schedule() | ||
# _check_working_schedule() | ||
# _is_present() | ||
# _is_file_open() | ||
# _is_in_screen() | ||
# _interactive_shell() | ||
# _wait_pid_expirer() | ||
# _install_cronjob() | ||
# _remove_cronjob() | ||
# _calculate_folder_size() | ||
# _delete_old_project_files() | ||
# _valid_ip() | ||
# _set_location_var() | ||
# _check_project_secrets() | ||
# _load_project_secrets() | ||
# _write_project_secrets() | ||
# _ensure_project_secrets_file() | ||
# _replace_env_project_secrets() | ||
# _get_project_docker_compose_file() | ||
# _install_update_cron() | ||
# _remove_update_cron() | ||
# _git_service_provider() | ||
# _check_github_token() | ||
# _check_github_token_file() | ||
# _load_github_token() | ||
# _write_github_token() | ||
# _get_project_github_latest_sha() | ||
# _check_onedev_token() | ||
# _check_onedev_file() | ||
# _load_onedev_token() | ||
# _write_onedev_token() | ||
# _get_project_onedev_latest_sha() | ||
# _download_project_files() | ||
# _update() | ||
# _set_latest_sha() | ||
# _check_latest_sha() | ||
# _check_update() | ||
# _script_completion() | ||
# _setup() | ||
|
||
# Defaulting variables | ||
# Script variables | ||
NOWDATESTAMP="${NOWDATESTAMP:-$(date "+%Y-%m-%d_%H-%M-%S")}" | ||
|
||
# This script variables | ||
SCRIPT_NAME="${SCRIPT_NAME:-$(basename "$(test -L "$0" && readlink "$0" || echo "$0")" | sed 's/\.[^.]*$//')}" | ||
SCRIPT="${SCRIPT:-$(basename "$(test -L "$0" && readlink "$0" || echo "$0")")}" | ||
SCRIPT_DIR="${SCRIPT_DIR:-$(cd "$(dirname "$0")" && pwd)}" | ||
|
@@ -178,9 +123,28 @@ _delete_running_file() { | |
|
||
# END - RUNNING FILE | ||
|
||
# Function: _exit_script | ||
# Description: Graceful exiting of script. | ||
# Parameters: None | ||
# Returns: None | ||
|
||
_exit_script() { | ||
|
||
rm "${SCRIPT_LOG_EMAIL_FILE}" | ||
|
||
# Delete running file | ||
_delete_running_file | ||
|
||
# Return users tty to starting directory or home or do nothing. | ||
cd "${STARTING_LOCATION}" || cd "$HOME" || exit | ||
|
||
# Making sure we do stop the script. | ||
exit | ||
} | ||
|
||
# START - WORKING SCHEDULE | ||
|
||
# Function: _in_working_schedule | ||
# Function: _in_working_schedule (NOT WORKING, NOT FINISHED) | ||
# Description: Validate working schedule variable and checks if in time. | ||
# Parameters: None | ||
# Returns: | ||
|
@@ -190,6 +154,8 @@ _delete_running_file() { | |
|
||
_in_working_schedule() { | ||
local pattern="^[0-7]-[0-7]:[0-2][0-9]:[0-5][0-9]-[0-2][0-9]:[0-5][0-9]$" | ||
local day_of_week current_hour current_day_schedule | ||
|
||
if [[ ! $WORKING_SCHEDULE =~ $pattern ]]; then | ||
_log_error "Invalid WORKING_SCHEDULE format. Please use the format: day(s):start_time-end_time." | ||
_exit_script | ||
|
@@ -231,11 +197,10 @@ _in_working_schedule() { | |
|
||
if [ "$current_hour" -ge "$start_time" ] && [ "$current_hour" -le "$end_time" ]; then | ||
_log_error "Script is running within the allowed time range. Stopping..." | ||
echo 1 | ||
return | ||
return 0 | ||
fi | ||
fi | ||
echo 0 | ||
return 1 # Outside of working hours | ||
} | ||
|
||
# Function: _check_working_schedule | ||
|
@@ -359,8 +324,10 @@ _install_linux_dep() { | |
# END - SET DISTRO VARIABLES | ||
|
||
# START - EXTRAS | ||
if [[ -f "${SCRIPT_DIR}/.${SCRIPT_NAME}/_extras.sh" ]]; then | ||
# shellcheck source=_update.sh | ||
source "${SCRIPT_DIR}/.${SCRIPT_NAME}/_extras.sh" | ||
if [[ ! -n "$(type -t _registered_extras)" ]]; then | ||
if [[ -f "${SCRIPT_DIR}/.${SCRIPT_NAME}/_extras.sh" ]]; then | ||
# shellcheck source=_functions.sh | ||
source "${SCRIPT_DIR}/.${SCRIPT_NAME}/_extras.sh" | ||
fi | ||
fi | ||
# END -EXTRAS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,19 @@ | ||
#!/bin/bash | ||
|
||
# Author: [email protected] | ||
# Script: _logs.sh | ||
# Link https://github.com/xorenio/deploy-cli.sh | ||
# Description: Functions script. | ||
|
||
# Defaulting variables | ||
NOWDATESTAMP="${NOWDATESTAMP:-$(date "+%Y-%m-%d_%H-%M-%S")}" | ||
|
||
# This script variables | ||
SCRIPT_NAME="${SCRIPT_NAME:-$(basename "$(test -L "$0" && readlink "$0" || echo "$0")" | sed 's/\.[^.]*$//')}" | ||
SCRIPT="${SCRIPT:-$(basename "$(test -L "$0" && readlink "$0" || echo "$0")")}" | ||
SCRIPT_DIR="${SCRIPT_DIR:-$(cd "$(dirname "$0")" && pwd)}" | ||
SCRIPT_DIR_NAME="${SCRIPT_DIR_NAME:-$(basename "$PWD")}" | ||
SCRIPT_DEBUG=${SCRIPT_DEBUG:-false} | ||
|
||
# Terminal starting directory | ||
STARTING_LOCATION=${STARTING_LOCATION:-"$(pwd)"} | ||
|
||
# Deployment environment | ||
DEPLOYMENT_ENV=${DEPLOYMENT_ENV:-"production"} | ||
|
||
|
@@ -32,10 +33,6 @@ GITHUB_REPO_URL="${GITHUB_REPO_URL:-"https://api.github.com/repos/$GITHUB_REPO_O | |
|
||
SCRIPT_LOG_FILE=${SCRIPT_LOG_FILE:-"${SCRIPT_DIR}/${SCRIPT_NAME}.log"} | ||
SCRIPT_LOG_EMAIL_FILE=${SCRIPT_LOG_EMAIL_FILE:-"$HOME/${SCRIPT_NAME}.mail.log"} | ||
JSON_FILE_NAME=${JSON_FILE_NAME:-"${SCRIPT_DIR}/${SCRIPT_NAME}_${NOWDATESTAMP}.json"} | ||
SCRIPT_RUNNING_FILE=${SCRIPT_RUNNING_FILE:-"${HOME}/${GIT_REPO_NAME}_running.txt"} | ||
|
||
LATEST_PROJECT_SHA=${LATEST_PROJECT_SHA:-0} | ||
|
||
# # START - IMPORT FUNCTIONS | ||
if [[ ! -n "$(type -t _registered)" ]]; then | ||
|
Oops, something went wrong.