pub / stagit-scripts

Building src.jayvii.de with stagit
git clone https://src.jayvii.de/pub/stagit-scripts.git
Home | Log | Files | Exports | Refs | README | RSS

git_deploy.sh (1943B)


      1 #!/usr/bin/env sh
      2 # SPDX-License-Identifier: AGPL-3.0-or-later
      3 # SPDX-FileCopyrightText: 2021-2024 JayVii <jayvii[AT]posteo[DOT]de>
      4 
      5 # $1 - HTML Root
      6 # $2 - prv/pub
      7 # $3 - repo name
      8 # $@ - optional list of refs, as given to post-update hook
      9 
     10 # Error out if not all options are given
     11 if [ -z "$3" ]; then
     12     echo "Usage:
     13 git_deploy.sh \\
     14     \"/var/www/git.example.git\" \\
     15     \"pub\" \\
     16     \"stagit-scripts\" \\
     17     \"refs/tags/v0.0.0\" # optional parameters given by post-update hook
     18     "
     19     exit 1;
     20 fi
     21 
     22 for REF in ${4}; do
     23 
     24     # Git-Repository
     25     cd "${1}/${2}/${3}.git"
     26 
     27     # fetch newest tag from given ref
     28     TAG=`git tag --contains $REF | tail -n 1 | awk '{ print $NF }'`
     29 
     30     # check whether a tag was given
     31     if [ ! -z $TAG ]; then
     32 
     33         # fetch the archive from previous export via git_export_tarball.sh
     34         if [ -f "${1}/${2}/${3}/exports/${TAG}.tar.gz" ]; then
     35         
     36             # extract archive to temporary directory
     37             TMPDIR=`mktemp --directory`
     38             tar xfvz "${1}/${2}/${3}/exports/${TAG}.tar.gz" \
     39                 --directory "${TMPDIR}/" > /dev/null
     40 
     41             MAKE_STATUS=0
     42 
     43             # check whether Makefile exists
     44             if [ -f "${TMPDIR}/Makefile" ]; then
     45 
     46                 # check whether Makefile contains the git-hook-deploy rule
     47                 if [ ! -z $(grep "git-hook-deploy" "${TMPDIR}/Makefile") ]; then
     48 
     49                     # run deployment
     50                     cd "$TMPDIR"
     51                     make git-hook-deploy > /dev/null
     52                     MAKE_STATUS=$?
     53 
     54                     # User output
     55                     if [ $MAKE_STATUS = 0 ]; then
     56                         echo "Version ${TAG} has been deployed"
     57                     fi
     58 
     59                 fi
     60 
     61             fi
     62 
     63             # clean up
     64             rm -r "$TMPDIR"
     65 
     66             # error handling
     67             if [ $MAKE_STATUS -gt 0 ]; then
     68                 exit 1
     69             fi
     70 
     71         fi
     72 
     73     fi
     74 
     75 done
     76