2021-08-24 17:35:39 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# Préparation d'une release ScoDoc:
|
2021-08-26 14:24:25 +02:00
|
|
|
# Utilise jq sur Debian 11 VM
|
2021-08-26 23:43:54 +02:00
|
|
|
apt-get install jq
|
|
|
|
|
2021-08-26 14:24:25 +02:00
|
|
|
|
|
|
|
# Le répertoire de ce script: .../scodoc/tools
|
|
|
|
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
|
|
|
|
|
|
|
|
source "$SCRIPT_DIR/config.sh"
|
|
|
|
source "$SCRIPT_DIR/utils.sh"
|
|
|
|
|
|
|
|
# tente de trouver la version dans le source , pour vérification
|
|
|
|
SCODOC_RELEASE=$(grep SCOVERSION "$SCRIPT_DIR/../sco_version.py" | awk '{ print substr($3, 2, length($3)-2) }')
|
|
|
|
|
|
|
|
# Dernière release
|
2021-09-12 23:06:23 +02:00
|
|
|
GITEA_RELEASE_URL="https://scodoc.org/git/api/v1/repos/viennet/ScoDoc/releases" # ?pre-release=true"
|
2021-08-26 14:24:25 +02:00
|
|
|
|
2021-12-16 16:26:23 +01:00
|
|
|
# suppose que les releases sont nommées 9.0.17, ne considère pas les caractères non numériques
|
|
|
|
LAST_RELEASE_TAG=$(wget -nv -O - "$GITEA_RELEASE_URL" | jq ".[].tag_name" | tr -d -c "0-9.\n" | sort --version-sort | tail -1)
|
2021-09-12 23:06:23 +02:00
|
|
|
# | awk '{ print substr($1, 2, length($1)-2) }')
|
2021-08-26 14:24:25 +02:00
|
|
|
|
|
|
|
echo
|
|
|
|
echo "Version détectée dans le source: $SCODOC_RELEASE"
|
|
|
|
echo "Dernière release trouvée sur gitea: $LAST_RELEASE_TAG"
|
|
|
|
echo -n "Utiliser $LAST_RELEASE_TAG ? (y/n) [y] "
|
|
|
|
read -r ans
|
|
|
|
if [ "$(norm_ans "$ans")" != 'N' ]
|
|
|
|
then
|
|
|
|
PACKAGE_VERSION="$LAST_RELEASE_TAG"
|
|
|
|
else
|
|
|
|
echo -n "Entrer la version à générer: "
|
|
|
|
read PACKAGE_VERSION
|
|
|
|
fi
|
2021-08-24 17:35:39 +02:00
|
|
|
|
|
|
|
PACKAGE_NAME=scodoc9
|
2021-08-26 14:24:25 +02:00
|
|
|
RELEASE_TAG="$PACKAGE_VERSION"
|
|
|
|
VERSION="$PACKAGE_VERSION"
|
2021-08-24 17:35:39 +02:00
|
|
|
RELEASE=1
|
|
|
|
ARCH="amd64"
|
|
|
|
FACTORY_DIR="/opt/factory"
|
|
|
|
DEST_DIR="$PACKAGE_NAME"_"$VERSION"-"$RELEASE"_"$ARCH"
|
2021-08-26 14:24:25 +02:00
|
|
|
GIT_RELEASE_URL="https://scodoc.org/git/viennet/ScoDoc/archive/${RELEASE_TAG}.tar.gz"
|
2021-08-24 17:35:39 +02:00
|
|
|
|
2021-08-26 14:24:25 +02:00
|
|
|
echo "Le paquet sera $DEST_DIR.deb"
|
|
|
|
echo -n "Est-ce ok ? (y/n) [y] "
|
|
|
|
read -r ans
|
|
|
|
if [ "$(norm_ans "$ans")" != 'N' ]
|
|
|
|
then
|
|
|
|
echo "ok"
|
|
|
|
else
|
|
|
|
echo "annulation."
|
|
|
|
exit 0
|
|
|
|
fi
|
2021-08-24 17:35:39 +02:00
|
|
|
|
|
|
|
SCODOC_USER=scodoc
|
|
|
|
# Safety checks
|
|
|
|
[ -z "$FACTORY_DIR" ] && die "empty FACTORY_DIR"
|
|
|
|
[ "$(id -nu)" != "$SCODOC_USER" ] && die "Erreur: le script $0 doit être lancé par l'utilisateur $SCODOC_USER"
|
|
|
|
|
|
|
|
# Création répertoire du paquet, et de opt
|
|
|
|
slash="$FACTORY_DIR"/"$DEST_DIR"
|
|
|
|
optdir="$slash"/opt
|
|
|
|
|
|
|
|
[ -e "$slash" ] && die "Directory $slash already exists"
|
|
|
|
mkdir -p "$optdir" || die "mkdir failure for $optdir"
|
|
|
|
|
|
|
|
# On récupère la release
|
|
|
|
archive="$FACTORY_DIR"/"$PACKAGE_NAME-$RELEASE_TAG".tar.gz
|
|
|
|
echo "Downloading $GIT_RELEASE_URL ..."
|
2021-12-16 16:26:23 +01:00
|
|
|
# curl -o "$archive" "$GIT_RELEASE_URL" || die "curl failure for $GIT_RELEASE_URL"
|
2023-02-20 13:13:23 +01:00
|
|
|
wget --progress=dot -O "$archive" "$GIT_RELEASE_URL" || die "wget failure for $GIT_RELEASE_URL"
|
|
|
|
# -nv
|
2021-08-24 17:35:39 +02:00
|
|
|
|
|
|
|
# On décomprime
|
|
|
|
# normalement le résultat s'appelle "scodoc" et va dans opt
|
|
|
|
(cd "$optdir" && tar xfz "$archive") || die "tar extraction failure"
|
|
|
|
|
|
|
|
SCODOC_DIR="$optdir"/scodoc
|
|
|
|
[ -d "$SCODOC_DIR" ] || die "die Erreur: $SCODOC_DIR inexistant"
|
|
|
|
|
2021-08-26 14:24:25 +02:00
|
|
|
# Inject version (eg 9.0.2) in debian:control
|
2021-08-26 23:43:54 +02:00
|
|
|
sed -i.bak "s/Version: x.y.z/Version: $PACKAGE_VERSION/g" "$SCODOC_DIR/tools/debian/control"
|
2021-08-26 14:24:25 +02:00
|
|
|
# and double check
|
|
|
|
v=$(grep Version "$SCODOC_DIR/tools/debian/control" | awk '{ print $2 }')
|
|
|
|
if [ "$v" != "$PACKAGE_VERSION" ]
|
|
|
|
then
|
|
|
|
echo "error in debian control file: version mismatch (bug)"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2021-08-24 17:35:39 +02:00
|
|
|
# Puis on déplace les fichiers de config (nginx, systemd, ...)
|
|
|
|
# nginx:
|
|
|
|
mkdir -p "$slash"/etc/nginx/sites-available || die "can't mkdir nginx config"
|
2021-09-11 23:42:01 +02:00
|
|
|
cp -p "$SCODOC_DIR"/tools/etc/scodoc9.nginx "$slash"/etc/nginx/sites-available/scodoc9.nginx.distrib || die "can't copy nginx config"
|
2022-02-18 23:30:45 +01:00
|
|
|
mkdir -p "$slash"/etc/nginx/conf.d || die "can't mkdir nginx conf.d"
|
|
|
|
cp -p "$SCODOC_DIR"/tools/etc/scodoc9-nginx-timeout.conf "$slash"/etc/nginx/conf.d/ || die "can't copy nginx timeout config"
|
2021-09-13 10:00:07 +02:00
|
|
|
|
2021-08-24 17:35:39 +02:00
|
|
|
# systemd
|
|
|
|
mkdir -p "$slash"/etc/systemd/system/ || die "can't mkdir systemd config"
|
|
|
|
cp -p "$SCODOC_DIR"/tools/etc/scodoc9.service "$slash"/etc/systemd/system/ || die "can't copy scodoc9.service"
|
|
|
|
|
|
|
|
# Répertoire DEBIAN
|
|
|
|
mv "$SCODOC_DIR"/tools/debian "$slash"/DEBIAN || die "can't install DEBIAN dir"
|
|
|
|
chmod 755 "$slash"/DEBIAN/*inst || die "can't chmod debian scripts"
|
|
|
|
|
2021-08-24 18:55:58 +02:00
|
|
|
# ------------ CREATION DU VIRTUALENV
|
2021-08-24 23:36:58 +02:00
|
|
|
#echo "Creating python3 virtualenv..."
|
|
|
|
#(cd $SCODOC_DIR && python3 -m venv venv) || die "error creating Python 3 virtualenv"
|
2021-08-24 17:35:39 +02:00
|
|
|
|
2021-08-24 18:55:58 +02:00
|
|
|
# ------------ INSTALL DES PAQUETS PYTHON (3.9)
|
|
|
|
# pip in our env, as user "scodoc"
|
2021-08-24 23:36:58 +02:00
|
|
|
#(cd $SCODOC_DIR && source venv/bin/activate && pip install wheel && pip install -r requirements-3.9.txt) || die "Error installing python packages"
|
2021-08-24 18:55:58 +02:00
|
|
|
|
|
|
|
# -------- THE END
|
|
|
|
echo "Terminé."
|
2021-08-26 23:43:54 +02:00
|
|
|
|
2021-12-16 16:26:23 +01:00
|
|
|
# echo -n "Voulez-vous poursuivre et construire le .deb ? (y/n) [y] "
|
|
|
|
# read -r ans
|
|
|
|
# if [ "$(norm_ans "$ans")" != 'N' ]
|
|
|
|
# then
|
|
|
|
# echo "ok"
|
|
|
|
# else
|
|
|
|
# echo "arrêt."
|
|
|
|
# exit 0
|
|
|
|
# fi
|
2021-08-26 23:43:54 +02:00
|
|
|
|
|
|
|
dpkg-deb --build --root-owner-group $DEST_DIR
|
|
|
|
DEB_FILE="$DEST_DIR".deb
|
|
|
|
echo "paquet construit: $DEB_FILE"
|
|
|
|
|
2021-08-24 17:35:39 +02:00
|
|
|
|
|
|
|
|