• [^] # Re: Gittea

    Posté par . En réponse au journal Serveur Git perso via SSH. Évalué à 3.

    J'ai fait un script pour l'automatisation des mises à jour.

    #!/bin/bash
    # Téléchargement et installation du binaire gitea depuis Github
    # set -euo pipefail
    CURL=$(which curl)
    CHMOD=$(which chmod)
    CUT=$(which cut)
    ECHO=$(which echo)
    GITEA=$(which gitea)
    GREP=$(which grep)
    MV=$(which mv)
    SED=$(which sed)
    RM=$(which rm)
    SYSTEMCTL=$(which systemctl)
    GITEA_BINARY=/usr/local/bin/gitea
    # Définit le dossier du script comme dossier courant
    cd "${0%/*}" || exit
    ${ECHO} "Mise à jour de gitea ..."
    VERSION=$(${CURL} --silent https://api.github.com/repos/go-gitea/gitea/releases/latest | ${GREP} '"tag_name":' | ${CUT} -d'"' -f4 | ${SED} 's/v//')
    VERSION_LOCAL=$(${GITEA} --version 2>/dev/null | ${CUT} -d " " -f 3)
    ${ECHO} "Version distante : ${VERSION}"
    ${ECHO} "Version locale : "$VERSION_LOCAL
    if [[ ${VERSION} == ${VERSION_LOCAL} ]]; then
     ${ECHO} "Déjà à jours, fin des opérations"
     exit
    fi
    # Stop Gitea
    ${SYSTEMCTL} stop gitea
    # Sauvegarde de l'ancien binaire
    if test -f "${GITEA_BINARY}"; then
     ${ECHO} "Sauvegarde du binaire"
     ${MV} "${GITEA_BINARY}" "${GITEA_BINARY}".bak
    fi
    TELECHARGEMENT=$(${CURL} -s -w "%{http_code}" -S -L https://github.com/go-gitea/gitea/releases/download/v${VERSION}/gitea-${VERSION}-linux-amd64 -o ${GITEA_BINARY}) > /dev/null 2>&1;
    if [[ ${TELECHARGEMENT} -eq 200 ]]; then
     ${ECHO} "Nouvelle version téléchargé, remplacement du binaire..."
     # ${MV} /tmp/gitea "${GITEA_BINARY}"
     ${CHMOD} +x "${GITEA_BINARY}"
     # Redémarrage du service gitea
     ${SYSTEMCTL} start gitea
     VERSION_LOCAL=$(${GITEA_BINARY} --version | ${CUT} -d " " -f 3)
     if [[ ${VERSION} == ${VERSION_LOCAL} ]]; then
     ${ECHO} "Mise à jour réussit, suppression de la sauvegarde"
     # Suppression de l'ancien binaire
     if test -f "${GITEA_BINARY}.bak"; then
     ${RM} "${GITEA_BINARY}.bak"
     fi
     exit
     fi
    else
     ${ECHO} "Erreur lors du téléchargement, restauration de la sauvegarde"
     if test -f "${GITEA_BINARY}.bak"; then
     ${MV} "${GITEA_BINARY}.bak" "${GITEA_BINARY}"
     fi
    fi
    exit
    ${ECHO} "Un problème est survenu."
    exit 1