pages/action.sh
2023-10-17 16:00:20 +02:00

39 lines
915 B
Bash
Executable File

# Set up private key in a five
SSH_KEY_FILE=/tmp/gitea-pages-ssh-key-$(date +%s)
# set up ssh private key
echo "${INPUT_SSH_KEY}" >> "${SSH_KEY_FILE}"
chmod 600 "${SSH_KEY_FILE}"
cat "${SSH_KEY_FILE}"
# set up ssh remote key
echo "${INPUT_HOST} ${INPUT_HOST_KEY}" >> ~/.ssh/known_hosts
# check if directory present
if [ ! -d "${INPUT_DIRECTORY}" ]; then
echo "Directory ${INPUT_DIRECTORY} does not exist, aborting deploy."
fi
# optionally: create index
if [ "${INPUT_INDEX}" ]; then
if [ ! -e "${INPUT_DIRECTORY}/index.html" ]; then
tree -H "${INPUT_DIRECTORY}" \
-D \
--charset utf-8 \
-T "${INPUT_INDEX_TITLE}" \
> "${INPUT_DIRECTORY}/index.html"
echo "Added index"
else
echo "File index.html exists, not overriding."
fi
fi
# deploy via ssh
tar -C "${INPUT_DIRECTORY}" -czf - . \
| ssh -o "IdentitiesOnly=yes" -i "${SSH_KEY_FILE}" \
"${INPUT_HOST_USER}@${INPUT_HOST}"