|
| 1 | +#! /usr/bin/env bash |
| 2 | +# |
| 3 | +# Copyright (c) 2017 Nat! - Codeon GmbH |
| 4 | +# All rights reserved. |
| 5 | +# |
| 6 | +# Redistribution and use in source and binary forms, with or without |
| 7 | +# modification, are permitted provided that the following conditions are met: |
| 8 | +# |
| 9 | +# Redistributions of source code must retain the above copyright notice, this |
| 10 | +# list of conditions and the following disclaimer. |
| 11 | +# |
| 12 | +# Redistributions in binary form must reproduce the above copyright notice, |
| 13 | +# this list of conditions and the following disclaimer in the documentation |
| 14 | +# and/or other materials provided with the distribution. |
| 15 | +# |
| 16 | +# Neither the name of Mulle kybernetiK nor the names of its contributors |
| 17 | +# may be used to endorse or promote products derived from this software |
| 18 | +# without specific prior written permission. |
| 19 | +# |
| 20 | +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 21 | +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 22 | +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 23 | +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
| 24 | +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 25 | +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 26 | +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 27 | +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 28 | +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 29 | +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 30 | +# POSSIBILITY OF SUCH DAMAGE. |
| 31 | +# |
| 32 | +# |
| 33 | +# For documentation and help see: |
| 34 | +# https://github.com/mulle-nat/mulle-homebrew |
| 35 | +# |
| 36 | +# Run this somewhat like this (for real: remove -n): |
| 37 | +# ./bin/release.sh -v -n --publisher mulle-nat --publisher-tap mulle-kybernetik/software/ |
| 38 | +# |
| 39 | + |
| 40 | +EXE_DIR="`dirname -- $0`" |
| 41 | + |
| 42 | +# if there is a release-info.sh file read it |
| 43 | +if [ -f "${EXE_DIR}/release-info.sh" ] |
| 44 | +then |
| 45 | + DO_GIT_RELEASE="YES" |
| 46 | + . "${EXE_DIR}/release-info.sh" |
| 47 | +fi |
| 48 | + |
| 49 | +# if there is a formula-info.sh file read it |
| 50 | +if [ -f "${EXE_DIR}/formula-info.sh" ] |
| 51 | +then |
| 52 | + DO_GENERATE_FORMULA="YES" |
| 53 | + . "${EXE_DIR}/formula-info.sh" |
| 54 | +fi |
| 55 | + |
| 56 | +# |
| 57 | +# If there is a - possibly .gitignored - tap-info.sh file read it. |
| 58 | +# It could store PUBLISHER and PUBLISHER_TAP |
| 59 | +# |
| 60 | +if [ -f "${EXE_DIR}/tap-info.sh" ] |
| 61 | +then |
| 62 | + . "${EXE_DIR}/tap-info.sh" |
| 63 | +fi |
| 64 | + |
| 65 | + |
| 66 | +####### |
| 67 | +# If you are using mulle-build, you don't hafta change anything after this |
| 68 | +####### |
| 69 | + |
| 70 | +# |
| 71 | +# Generate your `def install` `test do` lines here. echo them to stdout. |
| 72 | +# |
| 73 | +generate_brew_formula_build() |
| 74 | +{ |
| 75 | + local project="$1" |
| 76 | + local name="$2" |
| 77 | + local version="$3" |
| 78 | + |
| 79 | + cat <<EOF |
| 80 | + def install |
| 81 | + xcodebuild "install", "-target", "${project}", "DSTROOT=/", "INSTALL_PATH=#{bin}" |
| 82 | + end |
| 83 | +
|
| 84 | + test do |
| 85 | + system "#{bin}/${project}", "-version" |
| 86 | + end |
| 87 | +EOF |
| 88 | +} |
| 89 | + |
| 90 | + |
| 91 | +# |
| 92 | +# If you are unhappy with the formula in general, then change |
| 93 | +# this function. Print your formula to stdout. |
| 94 | +# |
| 95 | +generate_brew_formula() |
| 96 | +{ |
| 97 | +# local project="$1" |
| 98 | +# local name="$2" |
| 99 | +# local version="$3" |
| 100 | +# local dependencies="$4" |
| 101 | +# local builddependencies="$5" |
| 102 | +# local homepage="$6" |
| 103 | +# local desc="$7" |
| 104 | +# local archiveurl="$8" |
| 105 | + |
| 106 | + _generate_brew_formula "$@" |
| 107 | +} |
| 108 | + |
| 109 | +####### |
| 110 | +# Ideally changes to the following values are done with the command line |
| 111 | +# which makes it easier for forks. |
| 112 | +####### |
| 113 | + |
| 114 | +MULLE_BOOTSTRAP_FAIL_PREFIX="`basename -- $0`" |
| 115 | +MULLE_HOMEBREW_VERSION="4.1.0" |
| 116 | + |
| 117 | +# |
| 118 | +# prefer local mulle-homebrew if available |
| 119 | +# Do not embed it anymore! |
| 120 | +# |
| 121 | +if [ -z "`command -v mulle-homebrew-env`" ] |
| 122 | +then |
| 123 | + cat <<EOF >&2 |
| 124 | +mulle-homebrew-env not found in PATH. |
| 125 | +Visit the homepage for installation instructions: |
| 126 | + https://github.com/mulle-nat/mulle-homebrew |
| 127 | +EOF |
| 128 | + exit 1 |
| 129 | +fi |
| 130 | + |
| 131 | +INSTALLED_MULLE_HOMEBREW_VERSION="`mulle-homebrew-env version`" || exit 1 |
| 132 | +LIBEXEC_DIR="`mulle-homebrew-env libexec-path`" || exit 1 |
| 133 | + |
| 134 | +. "${LIBEXEC_DIR}/mulle-homebrew.sh" || exit 1 |
| 135 | +. "${LIBEXEC_DIR}/mulle-git.sh" || exit 1 |
| 136 | +. "${LIBEXEC_DIR}/mulle-version.sh" || exit 1 |
| 137 | +. "${LIBEXEC_DIR}/mulle-environment.sh" || exit 1 |
| 138 | + |
| 139 | + |
| 140 | +main() |
| 141 | +{ |
| 142 | + if [ "${DO_GIT_RELEASE}" != "YES" -a "${DO_GENERATE_FORMULA}" != "YES" ] |
| 143 | + then |
| 144 | + fail "Nothing to do. release-info.sh and formula-info.sh are missing" |
| 145 | + fi |
| 146 | + |
| 147 | + if [ "${DO_GIT_RELEASE}" = "YES" ] |
| 148 | + then |
| 149 | + # do the release |
| 150 | + git_main "${BRANCH}" "${ORIGIN}" "${TAG}" "${GITHUB}" || exit 1 |
| 151 | + fi |
| 152 | + |
| 153 | + if [ "${DO_GENERATE_FORMULA}" = "YES" ] |
| 154 | + then |
| 155 | + if [ -z "${PUBLISHER}" ] |
| 156 | + then |
| 157 | + fail "You need to specify a publisher with --publisher (hint: https://github.com/<publisher>)" |
| 158 | + fi |
| 159 | + |
| 160 | + if [ -z "${PUBLISHER_TAP}" ] |
| 161 | + then |
| 162 | + fail "You need to specify a publisher tap with --tap (hint: <mulle-kybernetik/software>)" |
| 163 | + fi |
| 164 | + |
| 165 | + # generate the formula and push it |
| 166 | + homebrew_main "${PROJECT}" \ |
| 167 | + "${NAME}" \ |
| 168 | + "${VERSION}" \ |
| 169 | + "${DEPENDENCIES}" \ |
| 170 | + "${BUILD_DEPENDENCIES}" \ |
| 171 | + "${HOMEPAGE_URL}" \ |
| 172 | + "${DESC}" \ |
| 173 | + "${ARCHIVE_URL}" \ |
| 174 | + "${HOMEBREW_TAP}" \ |
| 175 | + "${RBFILE}" |
| 176 | + fi |
| 177 | +} |
| 178 | + |
| 179 | +main "$@" |
0 commit comments