~skiqqy/bin

c09547789b9d8303e434a0c7b6316de1633312db — Stephen Cochrane 2 months ago 988bf98
Prog on deploy
1 files changed, 57 insertions(+), 8 deletions(-)

M skiqqy
M skiqqy => skiqqy +57 -8
@@ 5,14 5,15 @@ domain='skiqqy.xyz' # Easy changing if I decide to switch domains.

# Dont Change These.
declare -A commands
commands[check]="Usage: $ $(basename "$0") check [-v] [SUBDOMAIN]\nCheck the status of a sub domain."
commands[list]="Usage: $ $(basename "$0") list\nShow avaible commands."
commands[help]="Usage: $ $(basename "$0") help COMMAND\nShow helpful information for a command, see:\n$ $(basename "$0") list"
commands[init]="Usage: $ $(basename "$0") init [-f]\nInit the configs."
commands[refresh]="Usage: $ $(basename "$0") refresh\nRefresh domains and subdomains IP's."
commands[nginxd]="Usage: $ $(basename "$0") nginxd ARGUMENTS...\nWrapper for nginxd."
commands[update]="Usage: $ $(basename "$0") update\nUpdate the server, pulling and rebuilding the website."
commands[check]="check [-v] [SUBDOMAIN]\nCheck the status of a sub domain."
commands[list]="list\nShow avaible commands."
commands[help]="help COMMAND\nShow helpful information for a command, see:\n$ $(basename "$0") list"
commands[init]="init [-f]\nInit the configs."
commands[refresh]="refresh\nRefresh domains and subdomains IP's."
commands[nginxd]="nginxd ARGUMENTS...\nWrapper for nginxd."
commands[update]="update\nUpdate the server, pulling and rebuilding the website."
commands[error]="[ERROR] Command entered DNE, please see:\n$ $(basename "$0") list"
commands[deploy]="deploy [PORT]\nDeploy an instance of skiqqy.xyz in a container."

### Helper Functions ###



@@ 135,7 136,7 @@ shelp()
	out="${commands[$com]}"
	[ -z "$out" ] && out="${commands[error]}"

	printf '%b\n' "$out"
	printf 'Usage: $ %s %b\n' "$(basename "$0")" "$out"
}

slist()


@@ 235,6 236,54 @@ supdate()
	fi
}

sdeploy()
{
	local port
	local contd
	local url
	local gwiki

	# Set vars
	gwiki='https://git.sr.ht/~skiqqy/gwiki'
	url='https://github.com/skiqqy/skiqqy.github.io' # Repo url for skiqqy.xyz
	contd=
	port=${1:-81} # Deploy to port 81 by default.
	[[ ! $port =~ ^[0-9]+$ ]] && shelp deploy && return 1

	# Find container tool
	command -v podman > /dev/null && contd=podman
	[ -z "$contd" ] && command -v docker > /dev/null && contd=docker
	[ ! "$(whoami)" = root ] && [ "$contd" = docker ] && contd='sudo docker' # Assume sudo needed.
	[ -z "$contd" ] && \
		printf 'Cannot find a container tool, please install docker/podman' && \
		return 1

	# Print what will be done.
	printf 'Deploying skiqqy.xyz, using:\n\n\tContainer Env: %s\n\tPort: %s\n\tRepository: %s\n\n' \
		"$contd" "$port" "$url"

	git clone "$gwiki" /tmp/gwiki

	# Change working directories
	pushd /tmp/gwiki || return 1
		git pull # If /tmp/gwiki was not cloned (ie it was cloned previously) pull the latest
		printf '\nBuilding gwiki, this may take a while...\n\n'
		$contd build -t gwiki:latest .

		if [ -n "$(podman ps -af name=skiqqy | tail -n 1)" ]
		then
			echo TODO: Prompt user to ask if they want to delete old container.
		fi

		$contd run --name skiqqy \
			--restart=always \
			-p "$port":80 \
			--env CONFIG_HOME="$url" \
			--env TIMER=60 \
			gwiki:latest & # Fork the process, in the case of podman being used.
	popd || return 1
}

main()
{
	# Global Vars