2021-04-14 18:32:55 +02:00
|
|
|
#!/usr/local/bin/bash
|
2022-03-16 09:02:27 +01:00
|
|
|
# Usage: `deploy-static [--delete-target] $target`
|
|
|
|
#
|
|
|
|
# Takes the repository in the current directory, and copies the contents of `dist/` into `$target`.
|
|
|
|
# If `--delete-target` is set, then `$target` is deleted before copying, except for hidden files and folders.
|
|
|
|
|
2021-04-18 21:15:06 +02:00
|
|
|
|
|
|
|
if [ "$1" == "--delete-target" ]; then
|
2021-04-21 23:49:21 +02:00
|
|
|
delete_target=true
|
2021-04-18 21:15:06 +02:00
|
|
|
dst_dir="$2"
|
|
|
|
else
|
2021-04-21 23:49:21 +02:00
|
|
|
delete_target=false
|
2021-04-18 21:15:06 +02:00
|
|
|
dst_dir="$1"
|
|
|
|
fi
|
2021-04-14 18:32:55 +02:00
|
|
|
|
2021-04-14 20:05:45 +02:00
|
|
|
repo_dir="$(pwd)"
|
|
|
|
repo_name="$(basename -s .git "$repo_dir")"
|
2021-04-14 19:56:59 +02:00
|
|
|
tmp_dir="$HOME/tmp/git/$repo_name-$(date +%s)"
|
2021-04-14 18:32:55 +02:00
|
|
|
|
2021-04-14 19:56:59 +02:00
|
|
|
echo "[[ Deploy ]] static($repo_name)"
|
|
|
|
echo "[[ Deploy ]] src: '$repo_dir'"
|
|
|
|
echo "[[ Deploy ]] dst: '$dst_dir'"
|
|
|
|
echo "[[ Deploy ]] tmp: '$tmp_dir'"
|
2021-04-14 19:24:11 +02:00
|
|
|
|
2021-04-18 21:15:06 +02:00
|
|
|
|
2021-04-14 19:56:59 +02:00
|
|
|
if test -e "$tmp_dir"; then
|
|
|
|
echo "[[ Deploy ]] Directory '$tmp_dir' already exists, stopping deployment."
|
|
|
|
exit
|
|
|
|
fi
|
2021-04-14 19:13:24 +02:00
|
|
|
|
|
|
|
|
2021-04-14 19:56:59 +02:00
|
|
|
echo "[[ Deploy ]] Creating directories '$dst_dir' and '$tmp_dir'."
|
|
|
|
mkdir -p "$dst_dir" "$tmp_dir"
|
2021-04-14 19:13:24 +02:00
|
|
|
|
2021-04-14 19:56:59 +02:00
|
|
|
echo "[[ Deploy ]] Cloning repository at '$repo_dir' into '$tmp_dir'."
|
|
|
|
git clone "$repo_dir" "$tmp_dir"
|
2022-11-21 22:39:08 +01:00
|
|
|
cd "$tmp_dir" || exit
|
2022-08-20 20:28:41 +02:00
|
|
|
|
|
|
|
if [ ! -d dist/ ]; then
|
|
|
|
echo "[[ Deploy ]] FATAL ERROR: 'dist' directory was not created."
|
|
|
|
exit;
|
|
|
|
fi
|
2021-04-14 19:24:11 +02:00
|
|
|
|
2021-04-21 23:49:21 +02:00
|
|
|
if [ "$delete_target" = true ]; then
|
2021-04-18 21:15:06 +02:00
|
|
|
echo "[[ Deploy ]] Deleting then recreating '$dst_dir'."
|
2022-08-29 01:25:00 +02:00
|
|
|
# shellcheck disable=SC2086
|
|
|
|
rm -rf ${dst_dir:?}/..?* ${dst_dir:?}/.[!.]* ${dst_dir:?}/**
|
2021-04-18 21:15:06 +02:00
|
|
|
chmod g+w "$dst_dir"
|
|
|
|
fi
|
|
|
|
|
2021-04-28 13:18:37 +02:00
|
|
|
echo "[[ Deploy ]] Copying files from '$tmp_dir/dist' to '$dst_dir'."
|
|
|
|
chmod -R g+w "$tmp_dir/dist"
|
|
|
|
cp -r "$tmp_dir/dist/" "$dst_dir"
|
2021-04-14 19:13:24 +02:00
|
|
|
|
2021-04-14 19:56:59 +02:00
|
|
|
echo "[[ Deploy ]] Deleting '$tmp_dir'."
|
|
|
|
rm -rf "$tmp_dir"
|