mirror of
https://github.com/m-housh/dotfiles.git
synced 2026-02-15 06:32:40 +00:00
feat: Updates to hpa script.
This commit is contained in:
52
env/.local/scripts/hpa
vendored
52
env/.local/scripts/hpa
vendored
@@ -27,10 +27,15 @@ CONSULT_TEMPLATE_URL="ssh://git@git.housh.dev:2222/hhe/consult-template.git"
|
|||||||
HPA_PLAYBOOK_URL="ssh://git@git.housh.dev:2222/michael/ansible-hpa-playbook.git"
|
HPA_PLAYBOOK_URL="ssh://git@git.housh.dev:2222/michael/ansible-hpa-playbook.git"
|
||||||
HPA_VAULT_SECRET_KEY="${HPA_VAULT_SECRET_KEY:-vault-pass}"
|
HPA_VAULT_SECRET_KEY="${HPA_VAULT_SECRET_KEY:-vault-pass}"
|
||||||
|
|
||||||
|
echoerr() {
|
||||||
|
echo -e "\e[31m[ERROR]:\e[0m $*"
|
||||||
|
}
|
||||||
|
|
||||||
generate-completion() {
|
generate-completion() {
|
||||||
local type=${1:-"zsh"}
|
local output_dir output type
|
||||||
local output=${2:-$HOME/.zsh/completions/_hpa}
|
type=${1:-"zsh"}
|
||||||
local output_dir=$(dirname $output)
|
output=${2:-$HOME/.zsh/completions/_hpa}
|
||||||
|
output_dir=$(dirname "$output")
|
||||||
|
|
||||||
[[ ! -d "$output_dir" ]] && mkdir -p "$output_dir"
|
[[ ! -d "$output_dir" ]] && mkdir -p "$output_dir"
|
||||||
(
|
(
|
||||||
@@ -41,8 +46,9 @@ generate-completion() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
gnnerate-secret() {
|
gnnerate-secret() {
|
||||||
local secret="$(pass -c ansible/vault-pass)"
|
local secret=""
|
||||||
printf "$secret" | podman secret create "$HPA_VAULT_SECRET_KEY" -
|
secret="$(pass -c ansible/vault-pass)"
|
||||||
|
printf "%s" "$secret" | podman secret create "$HPA_VAULT_SECRET_KEY" -
|
||||||
}
|
}
|
||||||
|
|
||||||
# Ensure the dependencies are installed / setup.
|
# Ensure the dependencies are installed / setup.
|
||||||
@@ -65,13 +71,47 @@ run() {
|
|||||||
"$HPA_DOCKER_IMAGE:$HPA_DOCKER_TAG" "$@"
|
"$HPA_DOCKER_IMAGE:$HPA_DOCKER_TAG" "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Helper to generate the project directory properly.
|
||||||
|
#
|
||||||
|
# This allows project to be created using `hpa create Customer`, and the project
|
||||||
|
# will be created with an actual directory named '25.11.05.Customer'.
|
||||||
|
#
|
||||||
|
# This also handles setting parent directory to the `/consults` directory inside
|
||||||
|
# the container, otherwise the project fails to get created.
|
||||||
|
#
|
||||||
|
# We also suppress all output and then generate the actual directory path on the local
|
||||||
|
# file system, so this command can be used like `cd -- $(hpa create Foo | tr -d '\r' | head -1)`.
|
||||||
|
create() {
|
||||||
|
local project project_container_name dir_name
|
||||||
|
project=${1:-""}
|
||||||
|
|
||||||
|
[[ -z $project ]] && echoerr "Must supply a project name." && exit 1
|
||||||
|
|
||||||
|
project_container_name="$(run create --quiet "/consults/$(date '+%Y.%m.%d').$project")"
|
||||||
|
dir_name="$(basename "$project_container_name")"
|
||||||
|
echo "$CONSULTS_DIR/$dir_name"
|
||||||
|
}
|
||||||
|
|
||||||
############################## MAIN ##############################
|
############################## MAIN ##############################
|
||||||
|
|
||||||
first_arg=${1:-""}
|
first_arg=${1:-""}
|
||||||
|
|
||||||
if [[ $first_arg == "init" ]]; then
|
if [[ $first_arg == "init" ]]; then
|
||||||
shift
|
shift
|
||||||
init "$@" && exit 0
|
init "$@"
|
||||||
|
elif [[ $first_arg == "create" ]]; then
|
||||||
|
shift
|
||||||
|
dir=$(create "$@")
|
||||||
|
# Initialize project as a git repo.
|
||||||
|
pushd "$(echo "$dir" | tr -d '\r' | head -1)" &>/dev/null || exit 1
|
||||||
|
(
|
||||||
|
git init
|
||||||
|
git add .
|
||||||
|
git commit --all --message="Initial commit"
|
||||||
|
) >&/dev/null
|
||||||
|
popd &>/dev/null
|
||||||
|
# Echo the project directory.
|
||||||
|
echo "$dir"
|
||||||
else
|
else
|
||||||
run "$@"
|
run "$@"
|
||||||
fi
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user