106 lines
2.9 KiB
Bash
Executable File
106 lines
2.9 KiB
Bash
Executable File
#!/run/current-system/sw/bin/bash
|
|
set -euo pipefail
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
|
|
if [ -f "$SCRIPT_DIR/.env" ]; then
|
|
# Export all variables from .env for the duration of the script
|
|
set -a
|
|
. "$SCRIPT_DIR/.env"
|
|
set +a
|
|
fi
|
|
|
|
# Configuration
|
|
DEST_USER="${DEPLOY_DEST_USER:?DEPLOY_DEST_USER manquant}"
|
|
DEST_HOST="${DEPLOY_DEST_HOST:?DEPLOY_DEST_HOST manquant}"
|
|
DEST_DIR="/var/lib/www/richard-dern.fr/"
|
|
HUGO_ENV="production"
|
|
TARGET_OWNER="caddy:caddy"
|
|
CHOWN_BIN="/run/current-system/sw/bin/chown"
|
|
SETFACL_BIN="$(realpath /run/current-system/sw/bin/setfacl)"
|
|
|
|
is_local_host() {
|
|
local target="$1"
|
|
local hostnames
|
|
|
|
hostnames="$(hostname) $(hostname -f) $(hostname -s) localhost 127.0.0.1 ::1"
|
|
for name in $hostnames; do
|
|
if [ "$target" = "$name" ]; then
|
|
return 0
|
|
fi
|
|
done
|
|
|
|
return 1
|
|
}
|
|
|
|
LOCAL_DEPLOY=false
|
|
if is_local_host "$DEST_HOST"; then
|
|
LOCAL_DEPLOY=true
|
|
fi
|
|
|
|
echo "==> Vérification des liens externes"
|
|
node "$SCRIPT_DIR/tools/check_external_links.js"
|
|
|
|
echo "==> Vérification des liens internes"
|
|
node "$SCRIPT_DIR/tools/check_internal_links.js"
|
|
|
|
echo "==> Enrichissement météo des articles"
|
|
node "$SCRIPT_DIR/tools/add_weather.js"
|
|
|
|
echo "==> Synchronisation des commentaires Lemmy"
|
|
node "$SCRIPT_DIR/tools/sync_lemmy_comments.js"
|
|
|
|
echo "==> Génération des statistiques"
|
|
npm run stats:generate
|
|
|
|
# echo "==> Application des taxonomies et mots-clés"
|
|
# node "$SCRIPT_DIR/tools/link_taxonomy_terms.js"
|
|
|
|
# echo "==> Ajout des liens vers les mots-clés du frontmatter"
|
|
# node "$SCRIPT_DIR/tools/link_frontmatter_keywords.js"
|
|
|
|
echo "==> Génération du site Hugo pour l'environnement $HUGO_ENV (avec nettoyage de destination)"
|
|
hugo --environment "$HUGO_ENV" --cleanDestinationDir
|
|
|
|
if [ "$LOCAL_DEPLOY" = true ]; then
|
|
if [ ! -d "$DEST_DIR" ]; then
|
|
echo "Dossier de destination introuvable: $DEST_DIR" >&2
|
|
exit 1
|
|
fi
|
|
|
|
echo "==> Vérification/pose des ACL sur $DEST_DIR"
|
|
sudo "$SETFACL_BIN" -R -m u:"$USER":rwx -m m:rwx "$DEST_DIR"
|
|
sudo "$SETFACL_BIN" -dR -m u:"$USER":rwx -m m:rwx "$DEST_DIR"
|
|
fi
|
|
|
|
if [ "$LOCAL_DEPLOY" = true ]; then
|
|
echo "==> Synchronisation locale du site vers $DEST_DIR"
|
|
rsync -rlvz --delete \
|
|
--exclude='data/***' \
|
|
--no-owner --no-group \
|
|
--no-perms --omit-dir-times --no-times \
|
|
--checksum \
|
|
public/ "$DEST_DIR"
|
|
else
|
|
echo "==> Synchronisation du site vers le serveur $DEST_HOST"
|
|
rsync -rlvz --delete \
|
|
--exclude='data/***' \
|
|
--no-owner --no-group \
|
|
--no-perms --omit-dir-times --no-times \
|
|
--checksum \
|
|
public/ "$DEST_USER@$DEST_HOST:$DEST_DIR"
|
|
fi
|
|
|
|
if [ "$LOCAL_DEPLOY" = true ]; then
|
|
find "$DEST_DIR" -type d -name data -exec rm -rf {} +
|
|
sudo "$CHOWN_BIN" -R "$TARGET_OWNER" "$DEST_DIR"
|
|
else
|
|
CMD="find \"$DEST_DIR\" -type d -name data -exec rm -rf {} +"
|
|
ssh "$DEST_USER@$DEST_HOST" "$CMD"
|
|
ssh "$DEST_USER@$DEST_HOST" "$CHOWN_BIN -R $TARGET_OWNER '$DEST_DIR'"
|
|
fi
|
|
|
|
sudo -u lemmy node tools/update_lemmy_post_dates.js
|
|
|
|
echo "==> Déploiement terminé avec succès."
|