use 2 arguments for owner and repository path

This commit is contained in:
Maximilian Keßler 2023-10-17 23:35:57 +02:00
parent 88776d2ec5
commit 9ff3fac39d
Signed by: max
GPG key ID: BCC5A619923C0BA5
2 changed files with 13 additions and 12 deletions

View file

@ -10,12 +10,12 @@
# Abort deploy on any mistake # Abort deploy on any mistake
set -e set -e
WEB_ROOT=/var/www/pages.abstractnonsen.se/ WEB_ROOT=/var/www/wildcard.users.abstractnonsen.se/
STORAGE_ROOT=/var/lib/pages/ STORAGE_ROOT=/var/lib/pages/
PAGES_USER=pages PAGES_USER=pages
if [ "$#" -ne 1 ]; then if [ "$#" -ne 2 ]; then
echo "Usage: $0 DEPLOY_SUBDIR" echo "Usage: $0 NAMESPACE REPOSITORY"
exit 1 exit 1
fi fi
@ -24,9 +24,9 @@ if [ "$(whoami)" != "${PAGES_USER}" ]; then
exit 1 exit 1
fi fi
LINK="${WEB_ROOT}/$1" LINK="${WEB_ROOT}/$1/$2"
LINK_DIRECTORY=$(dirname "${LINK}") LINK_DIRECTORY=$(dirname "${LINK}")
STORAGE_NEW="${STORAGE_ROOT}/$1/$(date +%s)" STORAGE_NEW="${STORAGE_ROOT}/$1/$2/$(date +%s)"
# ensure root paths exist # ensure root paths exist
mkdir -p "${LINK_DIRECTORY}" mkdir -p "${LINK_DIRECTORY}"
@ -53,4 +53,4 @@ else
rm -rf "${STORAGE_OLD}" rm -rf "${STORAGE_OLD}"
fi fi
echo "Successfully deployed to https://pages.abstractnonsen.se/$1" echo "Successfully deployed to https://$1.users.abstractnonsen.se/$2"

View file

@ -12,13 +12,14 @@ DEPLOY_SCRIPT=/home/${PAGES_USER}/deploy.sh
mkdir -p "${KEY_DIR}" mkdir -p "${KEY_DIR}"
if [ "$#" -ne 1 ]; then if [ "$#" -ne 2 ]; then
echo "Usage: $0 DEPLOY_SUBDIR" echo "Usage: $0 OWNER REPOSITORY"
fi fi
KEYNAME=$1 OWNER=$1
REPOSITORY=$2
KEYFILE="${KEY_DIR}/id_${KEYNAME/\//.}" KEYFILE="${KEY_DIR}/id_${OWNER}.${REPOSITORY}"
if [ -e "${KEYFILE}" ]; then if [ -e "${KEYFILE}" ]; then
echo "Found existing key in ${KEYFILE}, aborting." echo "Found existing key in ${KEYFILE}, aborting."
@ -31,10 +32,10 @@ mkdir -p "${KEY_DIR}"
chmod 700 "${KEY_DIR}" chmod 700 "${KEY_DIR}"
# generate key # generate key
ssh-keygen -t ed25519 -f "${KEYFILE}" -N "" -C "deployment key for ${KEYNAME}" > /dev/null ssh-keygen -t ed25519 -f "${KEYFILE}" -N "" -C "deployment key for ${OWNER}/${REPOSITORY}" > /dev/null
# add public key # add public key
echo "command=\"${DEPLOY_SCRIPT} ${KEYNAME}\",no-port-forwarding,no-agent-forwarding,no-X11-forwarding,no-pty,no-user-rc,restrict $(cat ${KEYFILE}.pub)" >> "/home/${PAGES_USER}/.ssh/authorized_keys" echo "command=\"${DEPLOY_SCRIPT} ${OWNER} ${REPOSITORY}\",no-port-forwarding,no-agent-forwarding,no-X11-forwarding,no-pty,no-user-rc,restrict $(cat ${KEYFILE}.pub)" >> "/home/${PAGES_USER}/.ssh/authorized_keys"
echo "Generate and configured new key in ${KEYFILE}" echo "Generate and configured new key in ${KEYFILE}"
echo "Printing private key:" echo "Printing private key:"