93 lines
1.8 KiB
Bash
93 lines
1.8 KiB
Bash
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
PERSON="$1"
|
|
HOST="alps:3222"
|
|
PROTOCOL="http"
|
|
REPO="babbarc/workspaces"
|
|
BRANCH="master"
|
|
URL="$PROTOCOL://$HOST/$REPO/raw/branch/$BRANCH"
|
|
|
|
LOG_FILE="/tmp/.gitops-router-${PERSON}.log"
|
|
|
|
log() {
|
|
local level="${1^^}" # convert to uppercase
|
|
shift
|
|
echo "[$(date '+%Y-%m-%d %H:%M:%S')] [$level] $*" | tee -a "$LOG_FILE"
|
|
}
|
|
|
|
log info "Received SSH_ORIGINAL_COMMAND: $SSH_ORIGINAL_COMMAND"
|
|
|
|
# Ensure the variable is set
|
|
if [[ -z "${SSH_ORIGINAL_COMMAND:-}" ]]; then
|
|
log error "No SSH_ORIGINAL_COMMAND provided."
|
|
exit 1
|
|
fi
|
|
|
|
function run() {
|
|
"$HOME"/.local/bin/"$1"
|
|
}
|
|
|
|
function update() {
|
|
fname=$(basename "$1")
|
|
output_path="$HOME/$2/$fname"
|
|
[ -f "$output_path" ] && chmod 700 "$output_path"
|
|
curl -fsSL "$URL/$1" -o "$output_path" && log info "Downloaded $URL/$1 to $output_path"
|
|
chmod "$3" "$output_path"
|
|
}
|
|
|
|
# Strip arguments and parse command
|
|
read -r command args <<<"$SSH_ORIGINAL_COMMAND"
|
|
|
|
# Define command routing
|
|
case "$command" in
|
|
build)
|
|
case "$args" in
|
|
base)
|
|
run build-base.sh
|
|
;;
|
|
workspace)
|
|
run build-workspace.sh
|
|
;;
|
|
*)
|
|
log error "Invalid arguments for build command: $args"
|
|
;;
|
|
esac
|
|
;;
|
|
update)
|
|
case "$args" in
|
|
workspace)
|
|
update build-workspace.sh .local/bin 500
|
|
;;
|
|
base)
|
|
update build-base.sh .local/bin 500
|
|
;;
|
|
access)
|
|
update access.yml . 400
|
|
;;
|
|
ssh_router)
|
|
update ssh_router.sh .local/bin 500
|
|
;;
|
|
gitops_router)
|
|
update gitops_router.sh .local/bin 500
|
|
;;
|
|
clean_dangling_images)
|
|
update .bin/clean_dangling_images.sh .local/bin 500
|
|
;;
|
|
*)
|
|
log error "Invalid arguments for update command: $args"
|
|
;;
|
|
esac
|
|
;;
|
|
clean)
|
|
"$HOME"/.local/bin/clean_dangling_images.sh
|
|
;;
|
|
status)
|
|
podman images
|
|
;;
|
|
*)
|
|
log error "Unknown command: $command"
|
|
exit 127
|
|
;;
|
|
esac
|