feat: add gitops router script
This commit is contained in:
parent
156b47aded
commit
54e2ec2374
98
gitops_router.sh
Normal file
98
gitops_router.sh
Normal file
@ -0,0 +1,98 @@
|
||||
#!/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"
|
||||
|
||||
ALLOWED_PATH="/home/infilytics/home.tar.gz"
|
||||
|
||||
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
|
||||
;;
|
||||
scp)
|
||||
log info "Accepting scp upload to $ALLOWED_PATH"
|
||||
[[ "${args}" == "-t $ALLOWED_PATH" ]] && eval "$SSH_ORIGINAL_COMMAND" || log error "Invalid scp upload path: $args"
|
||||
;;
|
||||
*)
|
||||
log error "Unknown command: $command"
|
||||
exit 127
|
||||
;;
|
||||
esac
|
Loading…
x
Reference in New Issue
Block a user