package-homebrew 2.78 KB
Newer Older
Drew's avatar
Drew committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
#!/bin/bash
# Copyright (c) 2016 Anarchy Tools Contributors.
# 
#  Licensed under the Apache License, Version 2.0 (the "License");
#  you may not use this file except in compliance with the License.
#  You may obtain a copy of the License at
# 
#    http://www.apache.org/licenses/LICENSE-2.0
# 
#  Unless required by applicable law or agreed to in writing, software
#  distributed under the License is distributed on an "AS IS" BASIS,
#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#  See the License for the specific language governing permissions and
#  limitations under the License.
set -e

# parse arguments
 while :; do
   case $1 in
    --name)
    if [ -n "$2" ]; then
        NAME=$2
        shift
    fi
    ;;
    --url)
    if [ -n "$2" ]; then
        URL=$2
        shift
    fi
    ;;
Drew's avatar
Drew committed
32 33 34 35 36 37
    --github-project)
    if [ -n "$2" ]; then
        GITHUB_PROJECT=$2
        shift
    fi
    ;;
Drew's avatar
Drew committed
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
    *)
    if [ "$1" == "" ]; then
       break
    fi
    echo "warning: unknown option $1"
    shift
   esac
   shift
done

if [ -z ${NAME+x} ]; then
   echo "NAME is required"
   exit 1
fi

if [ -z ${ATBUILD_PACKAGE_VERSION+x} ]; then
   echo "\$ATBUILD_PACKAGE_VERSION is required"
   exit 1
fi


ATBIN="bin/${NAME}.atbin"
# look up payload by parsing the atbin format
Drew's avatar
Drew committed
61
PAYLOAD=`grep -o ':payload .*' ${ATBIN}/compiled.atpkg | grep -Eo '".*"' | tr -d '"'`
Drew's avatar
Drew committed
62 63 64

echo "Compressing atbin..."
# compress the atbin file
Drew's avatar
Drew committed
65
COMPRESSED="bin/${NAME}-${ATBUILD_PACKAGE_VERSION}-osx.atbin.tar.xz"
Drew's avatar
Drew committed
66
tar c --options "xz:compression-level=9" -Jf ${COMPRESSED} -C bin ${NAME}.atbin
Drew's avatar
Drew committed
67 68 69

# we defer this so we can already have the atbin compressed at this point
if [ -z ${URL+x} ]; then
Drew's avatar
Drew committed
70 71 72 73
    if [ -z ${GITHUB_PROJECT+x} ]; then
        echo "--url or --github-project is required"
        exit 1
    else
Drew's avatar
Drew committed
74
        URL="https://github.com/${GITHUB_PROJECT}/releases/download/${ATBUILD_PACKAGE_VERSION}/${NAME}-${ATBUILD_PACKAGE_VERSION}-osx.atbin.tar.xz"
Drew's avatar
Drew committed
75
    fi
Drew's avatar
Drew committed
76 77 78
fi
# compute the sha256 sum

Drew's avatar
Drew committed
79
SHA=`shasum -a 256 ${COMPRESSED} | cut -d ' ' -f 1`
Drew's avatar
Drew committed
80 81 82

#Convert hyphens to RUBYCASE
#behold the power of perl
Drew's avatar
Drew committed
83
RUBYCASE=`echo "$PAYLOAD" | perl -pe 's/(^|-)./uc($&)/ge;s/-//g'`
Drew's avatar
Drew committed
84 85 86 87

echo "
# Documentation: https://github.com/Homebrew/brew/blob/master/share/doc/homebrew/Formula-Cookbook.md
#                http://www.rubydoc.info/github/Homebrew/brew/master/Formula
Drew's avatar
Drew committed
88
class $RUBYCASE < Formula
Drew's avatar
Drew committed
89 90 91 92 93 94 95
  desc \"No description!  file a bug at https://github.com/AnarchyTools/package-homebrew/issues\"
  homepage \"No homepage! file a bug at https://github.com/AnarchyTools/package-homebrew/issues\"
  url \"${URL}\"
  version \"${ATBUILD_PACKAGE_VERSION}\"
  sha256 \"$SHA\"

  def install
Drew's avatar
Drew committed
96 97
  # We don't need the folder name here; it seems to be supplied automatically
    bin.install \"${PAYLOAD}\"
Drew's avatar
Drew committed
98 99 100
  end
end" > bin/${NAME}.rb
echo "Wrote formula to bin/${NAME}.rb"