pages/action.sh

45 lines
1 KiB
Bash
Raw Permalink Normal View History

2023-10-17 15:49:51 +02:00
# 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}"
2023-10-17 16:04:55 +02:00
if [ ! -s "${SSH_KEY_FILE}" ]; then
echo "Missing ssh key, aborting deploy."
exit 1
fi
2023-10-17 16:00:20 +02:00
2023-10-17 15:49:51 +02:00
# set up ssh remote key
echo "${INPUT_HOST} ${INPUT_HOST_KEY}" >> ~/.ssh/known_hosts
2023-10-17 15:58:57 +02:00
# check if directory present
if [ ! -d "${INPUT_DIRECTORY}" ]; then
echo "Directory ${INPUT_DIRECTORY} does not exist, aborting deploy."
2023-10-17 16:04:55 +02:00
exit 1
2023-10-17 15:58:57 +02:00
fi
2023-10-17 15:49:51 +02:00
# optionally: create index
2023-10-17 16:15:59 +02:00
if "${INPUT_INDEX}"; then
2023-10-17 15:49:51 +02:00
if [ ! -e "${INPUT_DIRECTORY}/index.html" ]; then
2023-10-17 16:09:12 +02:00
tree "${INPUT_DIRECTORY}" -a -H "." \
2023-10-17 15:49:51 +02:00
-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}"
2023-10-17 16:09:12 +02:00
# remove ssh key
rm "${SSH_KEY_FILE}"