47 lines
1.1 KiB
Bash
Executable File
47 lines
1.1 KiB
Bash
Executable File
#!/usr/local/bin/bash
|
|
# Usage: deploy-static [--delete-target] target
|
|
|
|
if [ "$1" == "--delete-target" ]; then
|
|
delete_target=true
|
|
dst_dir="$2"
|
|
else
|
|
delete_target=false
|
|
dst_dir="$1"
|
|
fi
|
|
|
|
repo_dir="$(pwd)"
|
|
repo_name="$(basename -s .git "$repo_dir")"
|
|
tmp_dir="$HOME/tmp/git/$repo_name-$(date +%s)"
|
|
|
|
echo "[[ Deploy ]] static($repo_name)"
|
|
echo "[[ Deploy ]] src: '$repo_dir'"
|
|
echo "[[ Deploy ]] dst: '$dst_dir'"
|
|
echo "[[ Deploy ]] tmp: '$tmp_dir'"
|
|
|
|
|
|
if test -e "$tmp_dir"; then
|
|
echo "[[ Deploy ]] Directory '$tmp_dir' already exists, stopping deployment."
|
|
exit
|
|
fi
|
|
|
|
|
|
echo "[[ Deploy ]] Creating directories '$dst_dir' and '$tmp_dir'."
|
|
mkdir -p "$dst_dir" "$tmp_dir"
|
|
|
|
echo "[[ Deploy ]] Cloning repository at '$repo_dir' into '$tmp_dir'."
|
|
git clone "$repo_dir" "$tmp_dir"
|
|
rm -rf "$tmp_dir/.git/"
|
|
|
|
if [ "$delete_target" = true ]; then
|
|
echo "[[ Deploy ]] Deleting then recreating '$dst_dir'."
|
|
rm -rf "${dst_dir:?}/**"
|
|
chmod g+w "$dst_dir"
|
|
fi
|
|
|
|
echo "[[ Deploy ]] Copying files from '$tmp_dir' to '$dst_dir'."
|
|
chmod -R g+w "$tmp_dir"
|
|
cp -r "$tmp_dir/" "$dst_dir"
|
|
|
|
echo "[[ Deploy ]] Deleting '$tmp_dir'."
|
|
rm -rf "$tmp_dir"
|