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_export_tarball.sh (1441B)


      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_export_tarball.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 # Git-Repository
     23 cd "${1}/${2}/${3}.git" || exit 1;
     24 
     25 # Retrieve URL if set
     26 if [ -f "${1}/url" ]; then
     27     URL=`cat ${1}/url`
     28 fi
     29 
     30 for REF in ${4}; do
     31 
     32     # fetch branches and tags from given ref
     33     BRANCHES="
     34         `git branch -a --contains $REF | awk '{ print $NF }'`
     35         `git tag --contains $REF | awk '{ print $NF }'`
     36     "
     37 
     38     # cycle through branches and tags
     39     for BRANCH in $BRANCHES; do
     40 
     41         # create archive
     42         git archive ${BRANCH} . \
     43             --format=tar.gz \
     44             -o "${BRANCH}.tar.gz"
     45 
     46         # create sha256 sum
     47         sha256sum "${BRANCH}.tar.gz" | \
     48             tee "${1}/${2}/${3}/exports/${BRANCH}.tar.gz.sha256" > /dev/null
     49 
     50         # move archive into exports folder
     51         mv "${BRANCH}.tar.gz" "${1}/${2}/${3}/exports/${BRANCH}.tar.gz"
     52 
     53         # Output for user
     54         echo "Archive can be retrieved from ${URL}/${2}/${3}/exports/${BRANCH}.tar.gz"
     55 
     56     done
     57 
     58 done
     59