mirror of
https://github.com/m-housh/dotfiles.git
synced 2026-02-15 06:32:40 +00:00
feat: Updates to hpa config and scripts.
This commit is contained in:
7
env/.config/hpa/config.toml
vendored
7
env/.config/hpa/config.toml
vendored
@@ -44,8 +44,8 @@ useVaultArgs = true
|
|||||||
# instead of the provided / default playbook.
|
# instead of the provided / default playbook.
|
||||||
|
|
||||||
[playbook]
|
[playbook]
|
||||||
directory = '~/.local/share/hpa/playbook'
|
directory = '/root/.local/share/hpa/playbook'
|
||||||
inventory = '~/.local/share/hpa/playbook/inventory.ini'
|
inventory = '/root/.local/share/hpa/playbook/inventory.ini'
|
||||||
version = 'main'
|
version = 'main'
|
||||||
|
|
||||||
# NOTE:
|
# NOTE:
|
||||||
@@ -53,7 +53,8 @@ version = 'main'
|
|||||||
# a remote git repository.
|
# a remote git repository.
|
||||||
[template]
|
[template]
|
||||||
# The directory path on your local system to the template files.
|
# The directory path on your local system to the template files.
|
||||||
directory = '~/.local/share/hpa/template'
|
directory = '/root/.local/share/hpa/template'
|
||||||
|
vars = 'repo_vars'
|
||||||
|
|
||||||
# The url to a git repository that contains your template files.
|
# The url to a git repository that contains your template files.
|
||||||
# url = 'https://git.example.com/consult-template.git'
|
# url = 'https://git.example.com/consult-template.git'
|
||||||
|
|||||||
17
env/.local/scripts/hpa
vendored
17
env/.local/scripts/hpa
vendored
@@ -10,16 +10,12 @@ set -o pipefail
|
|||||||
# Make sure to run 'hpa-init' first on this machine to setup
|
# Make sure to run 'hpa-init' first on this machine to setup
|
||||||
# dependencies, if you have not done so already.
|
# dependencies, if you have not done so already.
|
||||||
#
|
#
|
||||||
# This will mount my home directory inside the container, so
|
|
||||||
# it should somewhat mirror like commands are run on the host os.
|
|
||||||
#
|
|
||||||
# To attach to a shell inside the container run:
|
# To attach to a shell inside the container run:
|
||||||
# `hpa bash`
|
# `hpa bash`
|
||||||
#
|
#
|
||||||
# To run ansible vault commands inside the container run:
|
# To run ansible vault commands inside the container run:
|
||||||
# `hpa ansible-vault ...`
|
# `hpa ansible-vault ...`
|
||||||
#
|
#
|
||||||
#
|
|
||||||
|
|
||||||
SCRIPTS=${SCRIPTS:-$HOME/.local/scripts}
|
SCRIPTS=${SCRIPTS:-$HOME/.local/scripts}
|
||||||
. "$SCRIPTS/utils/hpa/hpa.env"
|
. "$SCRIPTS/utils/hpa/hpa.env"
|
||||||
@@ -28,16 +24,19 @@ SCRIPTS=${SCRIPTS:-$HOME/.local/scripts}
|
|||||||
|
|
||||||
last_pull="0"
|
last_pull="0"
|
||||||
if [[ -f "$HPA_CONFIG_DIR/.lastpull" ]]; then
|
if [[ -f "$HPA_CONFIG_DIR/.lastpull" ]]; then
|
||||||
last_pull=$(cat "$HPA_CONFIG_DIR/.lastpull")
|
last_pull=$(cat "$HPA_CONFIG_DIR/.lastpull")
|
||||||
fi
|
fi
|
||||||
curr=$(date +%s)
|
curr=$(date +%s)
|
||||||
diff=$((curr - last_pull))
|
diff=$((curr - last_pull))
|
||||||
|
|
||||||
if [[ $HPA_AUTO_PULL == "1" ]] && [[ $diff -gt "$HPA_AUTO_PULL_INTERVAL" ]]; then
|
if [[ $HPA_AUTO_PULL == "1" ]] && [[ $diff -gt "$HPA_AUTO_PULL_INTERVAL" ]]; then
|
||||||
. "$SCRIPTS/hpa-pull" "$HPA_AUTO_PULL_OPTS"
|
. "$SCRIPTS/hpa-pull" "$HPA_AUTO_PULL_OPTS"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
podman run --rm --interactive --tty \
|
podman run --rm --interactive --tty \
|
||||||
--volume "$HOME":/root \
|
--volume "$HPA_CONFIG_DIR":/root/.config/hpa:ro \
|
||||||
--secret "$HPA_VAULT_SECRET_KEY" \
|
--volume "$HPA_DATA_DIR":/root/.local/share/hpa:ro \
|
||||||
"$HPA_DOCKER_IMAGE:$HPA_DOCKER_TAG" "$@"
|
--volume "$HPA_CONSULTS_DIR":/consults \
|
||||||
|
--volume "$PWD":/root/project \
|
||||||
|
--secret "$HPA_VAULT_SECRET_KEY" \
|
||||||
|
"$HPA_DOCKER_IMAGE:$HPA_DOCKER_TAG" "$@"
|
||||||
|
|||||||
107
env/.local/scripts/utils/hpa/hpa-create
vendored
107
env/.local/scripts/utils/hpa/hpa-create
vendored
@@ -23,7 +23,7 @@ no_push_flag="0"
|
|||||||
date_opt=$(date '+%Y.%m.%d')
|
date_opt=$(date '+%Y.%m.%d')
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
cat <<EOF
|
cat <<EOF
|
||||||
|
|
||||||
A utility script to generate a new home performance assessment project.
|
A utility script to generate a new home performance assessment project.
|
||||||
|
|
||||||
@@ -47,7 +47,7 @@ FLAGS:
|
|||||||
-p | --no-push: Do not push project to remote repository.
|
-p | --no-push: Do not push project to remote repository.
|
||||||
|
|
||||||
ENVIRONMENT:
|
ENVIRONMENT:
|
||||||
CONSULTS_DIR: Sets the location of new porjects
|
CONSULTS_DIR: Sets the location of new projects
|
||||||
(default: ~/work/consults)
|
(default: ~/work/consults)
|
||||||
|
|
||||||
CONSULT_ORIGIN_BASE_URL: Sets the base url for the project git origin.
|
CONSULT_ORIGIN_BASE_URL: Sets the base url for the project git origin.
|
||||||
@@ -58,59 +58,62 @@ EOF
|
|||||||
|
|
||||||
# Logging utility function, use in place of echo.
|
# Logging utility function, use in place of echo.
|
||||||
log() {
|
log() {
|
||||||
logging log --source "$THIS_FILE" "$@"
|
logging log --source "$THIS_FILE" "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
create() {
|
create() {
|
||||||
local customer container_dir
|
local customer container_dir
|
||||||
customer=${1:-""}
|
customer=${1:-""}
|
||||||
|
|
||||||
[[ -z $customer ]] &&
|
[[ -z $customer ]] &&
|
||||||
log --error "Must supply a customer name for the project" &&
|
log --error "Must supply a customer name for the project" &&
|
||||||
exit 1
|
exit 1
|
||||||
|
|
||||||
[[ ! -f $SCRIPTS/hpa ]] &&
|
[[ ! -f $SCRIPTS/hpa ]] &&
|
||||||
log --error "Unable to find the 'hpa' script." &&
|
log --error "Unable to find the 'hpa' script." &&
|
||||||
exit 1
|
exit 1
|
||||||
|
|
||||||
log "Generating project for: '$customer'"
|
log "Generating project for: '$customer'"
|
||||||
|
|
||||||
container_dir=$(
|
container_dir=$(
|
||||||
"$SCRIPTS/hpa" create --quiet "/consults/$date_opt.$customer"
|
"$SCRIPTS/hpa" create --quiet "/consults/$date_opt.$customer"
|
||||||
)
|
)
|
||||||
echo "$HPA_CONSULTS_DIR/$(basename "$container_dir")"
|
echo "$HPA_CONSULTS_DIR/$(basename "$container_dir")"
|
||||||
}
|
}
|
||||||
|
|
||||||
initialize-git() {
|
initialize-git() {
|
||||||
local dir
|
local dir
|
||||||
read -r dir
|
read -r dir
|
||||||
|
|
||||||
dir=$(echo "$dir" | tr -d '\r' | head -1)
|
dir=$(echo "$dir" | tr -d '\r' | head -1)
|
||||||
|
|
||||||
if [[ $no_git_flag == "0" ]]; then
|
if [[ $no_git_flag == "0" ]]; then
|
||||||
|
|
||||||
[[ ! -d $dir ]] &&
|
[[ ! -d $dir ]] &&
|
||||||
log --error "Could not initialize git directory not found: '$dir'" &&
|
log --error "Could not initialize git directory not found: '$dir'" &&
|
||||||
exit 1
|
exit 1
|
||||||
|
|
||||||
log "Initializing git repository"
|
log "Initializing git repository"
|
||||||
|
|
||||||
pushd "$dir" &>/dev/null || exit 1
|
pushd "$dir" &>/dev/null || exit 1
|
||||||
(
|
(
|
||||||
git init
|
git init
|
||||||
git add .
|
git lfs install
|
||||||
git commit --all --message="Initial commit"
|
git lfs track '*.png'
|
||||||
git remote add origin "$HPA_CONSULT_ORIGIN_BASE_URL/$(basename "$dir")"
|
git lfs track '*.pdf'
|
||||||
if [[ $no_push_flag == "0" ]]; then
|
git add .
|
||||||
git push --set-upstream origin main
|
git commit --all --message="Initial commit"
|
||||||
fi
|
git remote add origin "$HPA_CONSULT_ORIGIN_BASE_URL/$(basename "$dir")"
|
||||||
) &>/dev/null
|
if [[ $no_push_flag == "0" ]]; then
|
||||||
popd &>/dev/null
|
git push --set-upstream origin main
|
||||||
else
|
fi
|
||||||
log "Skipping git initialization"
|
) &>/dev/null
|
||||||
fi
|
popd &>/dev/null
|
||||||
|
else
|
||||||
|
log "Skipping git initialization"
|
||||||
|
fi
|
||||||
|
|
||||||
echo "$dir"
|
echo "$dir"
|
||||||
}
|
}
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
@@ -124,19 +127,19 @@ setup-logging "$LOG_FILE" "$LOG_LABEL"
|
|||||||
declare customer output
|
declare customer output
|
||||||
|
|
||||||
while [[ $# -gt 0 ]]; do
|
while [[ $# -gt 0 ]]; do
|
||||||
if [[ $1 == "-h" ]] || [[ $1 == "--help" ]]; then
|
if [[ $1 == "-h" ]] || [[ $1 == "--help" ]]; then
|
||||||
usage && exit 0
|
usage && exit 0
|
||||||
elif [[ $1 == "-d" ]] || [[ $1 == "--date" ]]; then
|
elif [[ $1 == "-d" ]] || [[ $1 == "--date" ]]; then
|
||||||
shift
|
shift
|
||||||
date_opt="$1"
|
date_opt="$1"
|
||||||
elif [[ $1 == "-g" ]] || [[ $1 == "--no-git" ]]; then
|
elif [[ $1 == "-g" ]] || [[ $1 == "--no-git" ]]; then
|
||||||
no_git_flag="1"
|
no_git_flag="1"
|
||||||
elif [[ $1 == "-p" ]] || [[ $1 == "--no-push" ]]; then
|
elif [[ $1 == "-p" ]] || [[ $1 == "--no-push" ]]; then
|
||||||
no_push_flag="1"
|
no_push_flag="1"
|
||||||
else
|
else
|
||||||
customer=$1
|
customer=$1
|
||||||
fi
|
fi
|
||||||
shift
|
shift
|
||||||
done
|
done
|
||||||
|
|
||||||
output=$(create "$customer" | initialize-git)
|
output=$(create "$customer" | initialize-git)
|
||||||
|
|||||||
Reference in New Issue
Block a user