Add libraries, deploys
This commit is contained in:
commit
3dba401c75
26
bootstrap.bash
Executable file
26
bootstrap.bash
Executable file
@ -0,0 +1,26 @@
|
||||
#!/bin/bash
|
||||
|
||||
# The path to the libglm root.
|
||||
LIBGLM_ROOT=${1:-~/.libglm}
|
||||
|
||||
# Get the path of the source file for some libglm mod by name.
|
||||
# $1 - the name of the mod
|
||||
function libglm_mod {
|
||||
source $LIBGLM_ROOT/lib/env.bash
|
||||
source $LIBGLM_ROOT/lib/fs.bash
|
||||
case $1 in
|
||||
deploy|args|env|string|notify|fs)
|
||||
echo $(fs_lib $1)
|
||||
;;
|
||||
*)
|
||||
echo "Error: no such mod name found: $1";
|
||||
;;
|
||||
esac
|
||||
|
||||
}
|
||||
|
||||
# Source the specified mod into the current shell.
|
||||
# $1 - the name of the mod
|
||||
function libglm_load {
|
||||
. $(libglm_mod $1)
|
||||
}
|
12
deploys/edge/garrettmills.bash
Executable file
12
deploys/edge/garrettmills.bash
Executable file
@ -0,0 +1,12 @@
|
||||
#!/bin/bash -xe
|
||||
|
||||
systemctl stop garrettmills
|
||||
|
||||
cd /etc/glmdev/app/garrettmills-dev
|
||||
|
||||
git pull
|
||||
|
||||
yarn install
|
||||
|
||||
systemctl start garrettmills
|
||||
|
2
deploys/localhost.localdomain/test.bash
Executable file
2
deploys/localhost.localdomain/test.bash
Executable file
@ -0,0 +1,2 @@
|
||||
#!/bin/bash
|
||||
echo "Test deployment worked!"
|
69
lib/args.bash
Executable file
69
lib/args.bash
Executable file
@ -0,0 +1,69 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Search the given arguments for the value of the specified key
|
||||
# $1 - the name of the argument - (e.g. "verbose")
|
||||
# $2+ - arguments to parse for value - (e.g. some args --verbose=3 more args)
|
||||
function args_get_long {
|
||||
local want_key=$1; shift;
|
||||
while [[ $# -gt 0 ]]
|
||||
do
|
||||
local key="$1"
|
||||
case $key in
|
||||
"--$want_key")
|
||||
echo $2
|
||||
return
|
||||
;;
|
||||
--$want_key=*)
|
||||
echo "${key#*=}"
|
||||
return
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
}
|
||||
|
||||
# Search the given arguments for the value of the specified key
|
||||
# $1 - the name of the argument's short form - (e.g. "v")
|
||||
# $2+ - arguments to parse for value - (e.g. some args -v=3 more args)
|
||||
function args_get_short {
|
||||
local want_key=$1; shift;
|
||||
while [[ $# -gt 0 ]]
|
||||
do
|
||||
local key="$1"
|
||||
case $key in
|
||||
"-$want_key")
|
||||
echo $2
|
||||
return
|
||||
;;
|
||||
-$want_key=*)
|
||||
echo "${key#*=}"
|
||||
return
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
}
|
||||
|
||||
# Search the given arguments for the value of the specified key or short
|
||||
# $1 - the long name of the argument - (e.g. "verbose")
|
||||
# $2 - the short name of the argument - (e.g. "v")
|
||||
# $3+ - arguments to parse for value - (e.g. some args -w shorts --and longs more args)
|
||||
function args_get {
|
||||
local want_long=$1; shift;
|
||||
local want_short=$1; shift;
|
||||
while [[ $# -gt 0 ]]
|
||||
do
|
||||
local key="$1"
|
||||
case $key in
|
||||
"--$want_long"|"-$want_short")
|
||||
echo $2
|
||||
return
|
||||
;;
|
||||
--$want_long=*|-$want_short=*)
|
||||
echo "${key#*=}"
|
||||
return
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
}
|
15
lib/deploy.bash
Executable file
15
lib/deploy.bash
Executable file
@ -0,0 +1,15 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Get the path to the deploy script for this host by name.
|
||||
# $1 - the name of the deploy script
|
||||
function deploy_get {
|
||||
source $(libglm_mod fs)
|
||||
source $(libglm_mod env)
|
||||
echo "$(fs_glm 'deploys' $LIBGLM_HOSTNAME $1).bash"
|
||||
}
|
||||
|
||||
# Execute the deploy script for this host by name.
|
||||
# $1 - the name of the deploy script
|
||||
function deploy_run {
|
||||
bash -xe $(deploy_get $1)
|
||||
}
|
10
lib/env.bash
Executable file
10
lib/env.bash
Executable file
@ -0,0 +1,10 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Fully qualified URL to the Gotify server. Should not end with a /.
|
||||
NOTIFY_URL="https://notify.garrettmills.dev"
|
||||
|
||||
# App token to use for the Gotify server.
|
||||
NOTIFY_TOKEN="A1dyzPhND7Bq7v_"
|
||||
|
||||
# The current hostname
|
||||
LIBGLM_HOSTNAME=$(hostname)
|
23
lib/fs.bash
Executable file
23
lib/fs.bash
Executable file
@ -0,0 +1,23 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Resolve the arguments into a path, joined by / chars.
|
||||
# $@ - paths to join
|
||||
function fs_resolve {
|
||||
source "$LIBGLM_ROOT/lib/string.bash"
|
||||
local SPLIT_PATH=$(string_join_array / $@)
|
||||
echo $SPLIT_PATH
|
||||
}
|
||||
|
||||
# Resolve the path to a libglm BASH library.
|
||||
# $@ - relative name of the lib - not ending in .bash
|
||||
function fs_lib {
|
||||
local SPLIT_PATH=$(fs_resolve $LIBGLM_ROOT/lib $@)
|
||||
echo $SPLIT_PATH.bash
|
||||
}
|
||||
|
||||
# Resolve the path to a resource in the libglm root.
|
||||
# $@ - relative paths to join
|
||||
function fs_glm {
|
||||
local SPLIT_PATH=$(fs_resolve $LIBGLM_ROOT $@)
|
||||
echo $SPLIT_PATH
|
||||
}
|
15
lib/notify.bash
Executable file
15
lib/notify.bash
Executable file
@ -0,0 +1,15 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Send a notification through the Gotify gateway.
|
||||
# $1 - the title of the message
|
||||
# $2 - the body of the message
|
||||
# [$3 = 5] - the message priority
|
||||
# [$4 = $NOTIFY_TOKEN] - app token to use
|
||||
function notify_push {
|
||||
source $(libglm_mod env)
|
||||
MSG_TITLE=$1
|
||||
MSG_BODY=$2
|
||||
MSG_TOKEN=${4:-$NOTIFY_TOKEN}
|
||||
MSG_PRIORITY=${3:-5}
|
||||
curl -X POST --data "title=$MSG_TITLE" --data "message=$MSG_BODY" --data "priority=$MSG_PRIORITY" "$NOTIFY_URL/message?token=$MSG_TOKEN"
|
||||
}
|
8
lib/string.bash
Executable file
8
lib/string.bash
Executable file
@ -0,0 +1,8 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Joins all arguments by the delimiter.
|
||||
# $1 - delimiter (e.g. ,)
|
||||
# $2+ - strings to be joined by the delimeter
|
||||
function string_join_array {
|
||||
local IFS="$1"; shift; echo "$*";
|
||||
}
|
Loading…
Reference in New Issue
Block a user