protothreads.c

Git mirror of http://dunkels.com/adam/pt/index.html
git clone git://git.finwo.net/lib/protothreads.c
Log | Files | Refs

build-tag.sh (2408B)


      1 #!/usr/bin/env bash
      2 
      3 DIR=$(realpath $(dirname $0))
      4 TAG="${TAG:-v1.4}"
      5 
      6 # Load ini lib
      7 source "${DIR}/ini.sh"
      8 
      9 function usage {
     10   echo ""
     11   echo "Usage: $(basename $0) [options] <tag>"
     12   echo ""
     13   echo "Options:"
     14   echo "  -h --help  Show this usage"
     15   echo ""
     16   echo "Tag:"
     17   echo ""
     18   echo "  The default tag configured is '${TAG}', but specifying one will allow"
     19   echo "  you to load a different configuration to build the tag for."
     20   echo ""
     21 }
     22 
     23 # Parse arguments
     24 while [[ "$#" -gt 0 ]]; do
     25   case "$1" in
     26     -h|--help)
     27       usage
     28       exit 0
     29       ;;
     30     *)
     31       TAG="$1"
     32       ;;
     33   esac
     34   shift
     35 done
     36 
     37 # Ensure tag is given
     38 if [ -z "${TAG}" ]; then
     39   usage
     40   exit 1
     41 fi
     42 
     43 # Ensure the config for the given tag exists
     44 CFGFILE="${DIR}/../config/package-${TAG}.ini"
     45 if [ ! -f "${CFGFILE}" ]; then
     46   echo "Configuration for tag '${TAG}' does not exist"
     47   exit 1
     48 fi
     49 
     50 # Make an artifact directory, as a stand-alone git repository
     51 rm -rf "${DIR}/../build"
     52 git init "${DIR}/../build"
     53 git -C "${DIR}/../build" remote add origin "$(git -C "${DIR}/../" remote get-url origin)"
     54 git -C "${DIR}/../build" fetch --all
     55 git -C "${DIR}/../build" checkout "release-${TAG}" || git -C "${DIR}/../build" checkout -b "release-${TAG}"
     56 rm -rf "${DIR}/../build/*"
     57 
     58 # Load tarball into directory
     59 TARBALL=$(ini_foreach ini_output_value "${CFGFILE}" "mirror.tarball")
     60 if [ ! -z "${TARBALL}" ]; then
     61   TARBALLTMP=$(mktemp)
     62   curl -sSL "${TARBALL}" > "${TARBALLTMP}"
     63   tar -x -C "${DIR}/../build" -f "${TARBALLTMP}" --strip-components=1
     64   rm -f "${TARBALLTMP}"
     65 fi
     66 
     67 # Handle specific sources
     68 while read srcfg; do
     69   DST=${srcfg%%=*}
     70   DST=${DST%%*( )}
     71   SRC=${srcfg#*=}
     72   SRC=${SRC##*( )}
     73   curl -sSL "${SRC}" > "${DIR}/../build/${DST}"
     74 done < <(ini_foreach ini_output_value "${CFGFILE}" "mirror.source")
     75 
     76 # Install package.ini into the build directory without mirror config
     77 ini_foreach ini_output_full "${CFGFILE}" \
     78   | grep -vE '^mirror\.' \
     79   | ini_write "${DIR}/../build/package.ini"
     80 
     81 # Create a commit+tag of this version and push to origin
     82 git -C "${DIR}/../build" add .
     83 git -C "${DIR}/../build" commit -m "Release (update) $(TZ=UTC date '+%Y-%m-%dT%H:%MZ')"
     84 git -C "${DIR}/../build" push -f origin HEAD
     85 
     86 # Push only specified tags
     87 while read tag; do
     88   git -C "${DIR}/../build" tag -f "${tag}"
     89   git -C "${DIR}/../build" push -f origin "refs/tags/${tag}"
     90 done < <(ini_foreach ini_output_value "${CFGFILE}" "mirror.tag")
     91 
     92 # Done