build-release.sh
1 #!/usr/bin/env bash 2 3 # Change this to where AdvancedInstaller outputs built EXE installers 4 SCRIPT_DIR=$(dirname $(realpath "$0")) 5 WINDOWS_INSTALLER_DIR="${SCRIPT_DIR}/../WindowsInstaller/Forknet-SetupFiles" 6 7 set -e 8 shopt -s expand_aliases 9 10 # optional git tag? 11 if [ $# -ge 1 ]; then 12 git_tag="$1" 13 shift 14 fi 15 16 saved_pwd=$PWD 17 18 alias SHA256='(sha256 -q || sha256sum | cut -d" " -f1) 2>/dev/null' 19 20 function 3hash { 21 local zip_src=$1 22 local md5hash=$(md5 ${zip_src} | awk '{ print $NF }') 23 local sha1hash=$(shasum ${zip_src} | awk '{ print $1 }') 24 local sha256hash=$(sha256sum ${zip_src} | awk '{ print $1 }') 25 echo "\`MD5: ${md5hash}\`" 26 echo "\`SHA1: ${sha1hash}\`" 27 echo "\`SHA256: ${sha256hash}\`" 28 } 29 30 # Check we are within a git repo 31 git_dir=$( git rev-parse --show-toplevel ) 32 if [ -z "${git_dir}" ]; then 33 echo "Cannot determine top-level directory for git repo" 34 exit 1 35 fi 36 37 # Change to git top-level 38 cd ${git_dir} 39 40 # Check we are in 'master' branch 41 # branch_name=$( git symbolic-ref -q HEAD ) || echo "Cannot determine branch name" && exit 1 42 # branch_name=${branch_name##refs/heads/} 43 # if [ "${branch_name}" != "master" ]; then 44 # echo "Unexpected current branch '${branch_name}' - expecting 'master'" 45 # exit 1 46 # fi 47 48 # Determine project name 49 project=$( perl -n -e 'if (m/<artifactId>(\w+)<.artifactId>/) { print $1; exit }' pom.xml $) 50 if [ -z "${project}" ]; then 51 echo "Unable to determine project name from pom.xml?" 52 exit 1 53 fi 54 55 # Extract git tag 56 if [ -z "${git_tag}" ]; then 57 git_tag=$( git tag --points-at HEAD ) 58 if [ -z "${git_tag}" ]; then 59 echo "Unable to extract git tag" 60 exit 1 61 fi 62 fi 63 64 # Find origin URL 65 git_url=$( git remote get-url origin ) 66 git_url=https://github.com/${git_url##*:} 67 git_url=${git_url%%.git} 68 69 # Check for EXE 70 exe=${project}.exe 71 exe_src="${WINDOWS_INSTALLER_DIR}/${exe}" 72 if [ ! -r "${exe_src}" ]; then 73 echo "Cannot find EXE installer at ${exe_src}" 74 exit 75 fi 76 77 # Check for ZIP 78 zip_filename=${project}.zip 79 zip_src=${saved_pwd}/${zip_filename} 80 if [ ! -r "${zip_src}" ]; then 81 echo "Cannot find ZIP at ${zip_src}" 82 exit 83 fi 84 85 86 87 # Changes 88 cat <<"__CHANGES__" 89 *Changes in this release:* 90 * 91 __CHANGES__ 92 93 # JAR 94 cat <<__JAR__ 95 96 ### [${project}.jar](${git_url}/releases/download/${git_tag}/${project}.jar) 97 98 __JAR__ 99 3hash target/${project}*.jar 100 101 # EXE 102 cat <<__EXE__ 103 104 ### [${exe}](${git_url}/releases/download/${git_tag}/${exe}) 105 106 __EXE__ 107 3hash "${exe_src}" 108 109 # VirusTotal url is SHA256 of github download url: 110 virustotal_url=$( echo -n "${git_url}/releases/download/${git_tag}/${exe}" | SHA256 ) 111 cat <<__VIRUSTOTAL__ 112 113 [VirusTotal report for ${exe}](https://www.virustotal.com/gui/url/${virustotal_url}/detection) 114 __VIRUSTOTAL__ 115 116 # ZIP 117 cat <<__ZIP__ 118 119 ### [${zip_filename}](${git_url}/releases/download/${git_tag}/${zip_filename}) 120 121 Contains bare minimum of: 122 * built \`${project}.jar\` 123 * \`log4j2.properties\` from git repo 124 * \`start.sh\` from git repo 125 * \`stop.sh\` from git repo 126 * \`printf "{\n}\n" > settings.json\` 127 128 All timestamps set to same date-time as commit, obtained via \`git show --no-patch --format=%cI\` 129 Packed with \`7z a -r -tzip ${zip_filename} ${project}/\` 130 131 __ZIP__ 132 3hash ${zip_src}