diff --git a/package/BuildAndPackage.command b/package/BuildAndPackage.command index 106944b..40c827b 100755 --- a/package/BuildAndPackage.command +++ b/package/BuildAndPackage.command @@ -2,14 +2,58 @@ CONFIGURATION="Release" -GIT_ROOT_DIR="$(dirname $(dirname ${BASH_SOURCE[0]}))" +DEFAULT_DEVELOPER_ID_INSTALLER="Developer ID Installer: Yoann GINI (CRXPBZF3N4)" +DEVELOPER_ID_INSTALLER=${CUSTOM_DEVELOPER_ID_INSTALLER:-${DEFAULT_DEVELOPER_ID_INSTALLER}} + +echo "Packaging will use ${DEVELOPER_ID_INSTALLER}" + +GIT_ROOT_DIR="$(git rev-parse --show-toplevel)" PROJECT_DIR="${GIT_ROOT_DIR}/src" BUILT_PRODUCTS_DIR="$(mktemp -d)" cd "${GIT_ROOT_DIR}" +CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD) + +if [[ "$CURRENT_BRANCH" == "master" ]] +then + CONFIGURATION="Release" +elif [[ "$CURRENT_BRANCH" == release* ]] +then + CONFIGURATION="Release" +else + CONFIGURATION="Debug" +fi + +UNCOMMITED_CHANGE=$(git status -s | wc -l | bc) + +if [ -z $FORCE_SKIP_REPO_STATE ] +then + if [ $UNCOMMITED_CHANGE -ne 0 ] && [ "$CONFIGURATION" == "Release" ] + then + echo "Your are on ${CURRENT_BRANCH} and there" + echo "is some uncommited change to the repo." + echo "Please, commit and try again or use" + echo "a development branch." + exit 1 + fi +fi + PKG_VERSION=$(/usr/libexec/PlistBuddy -c "print CFBundleShortVersionString" "${PROJECT_DIR}/Hello IT/Info.plist") +if [[ "$CURRENT_BRANCH" == release* ]] +then + CONFIGURATION="Release" + VERSION_FROM_BRANCH=$(echo "${CURRENT_BRANCH}" | awk -F'/' '{print $2}') + if [[ "$VERSION_FROM_BRANCH" =~ ^[0-9]+\.[0-9]+ ]] + then + PKG_VERSION=$VERSION_FROM_BRANCH + /usr/libexec/PlistBuddy -c "Set CFBundleShortVersionString $PKG_VERSION" "${PROJECT_DIR}/Hello IT/Info.plist" + git add "${PROJECT_DIR}/Hello IT/Info.plist" + git commit -m "Update app version number according to release branch" + fi +fi + BASE_RELEASE_LOCATION="${GIT_ROOT_DIR}/package/build" RELEASE_LOCATION="${BASE_RELEASE_LOCATION}/${PKG_VERSION}-${CONFIGURATION}" RELEASE_PRODUCT_LOCATION="${RELEASE_LOCATION}/Products" @@ -54,7 +98,12 @@ cp -r "${GIT_ROOT_DIR}/package/LaunchAgents/com.github.ygini.hello-it.plist" "${ #sudo chown -R root:wheel "${PKG_ROOT}" -pkgbuild --sign "Developer ID Installer: Yoann GINI (CRXPBZF3N4)" --root "${PKG_ROOT}" --scripts "${GIT_ROOT_DIR}/package/pkg_scripts" --identifier "com.github.ygini.hello-it" --version "${PKG_VERSION}" "${RELEASE_LOCATION}/Hello-IT-${PKG_VERSION}-${CONFIGURATION}.pkg" +PBK_BUILD_COMPONENT="${BUILT_PRODUCTS_DIR}/components.plist" +pkgbuild --analyze --root "${PKG_ROOT}" "${PBK_BUILD_COMPONENT}" + +/usr/libexec/PlistBuddy -c "Set 0:BundleIsRelocatable bool false" "${PBK_BUILD_COMPONENT}" +/usr/libexec/PlistBuddy -c "Print" "${PBK_BUILD_COMPONENT}" +pkgbuild --component-plist "${PBK_BUILD_COMPONENT}" --sign "${DEVELOPER_ID_INSTALLER}" --root "${PKG_ROOT}" --scripts "${GIT_ROOT_DIR}/package/pkg_scripts" --identifier "com.github.ygini.hello-it" --version "${PKG_VERSION}" "${RELEASE_LOCATION}/Hello-IT-${PKG_VERSION}-${CONFIGURATION}.pkg" rm -rf "${PKG_ROOT}" diff --git a/package/LaunchAgents/com.github.ygini.hello-it.plist b/package/LaunchAgents/com.github.ygini.hello-it.plist index afc78a1..c57acce 100644 --- a/package/LaunchAgents/com.github.ygini.hello-it.plist +++ b/package/LaunchAgents/com.github.ygini.hello-it.plist @@ -3,7 +3,7 @@ KeepAlive - + Label com.github.ygini.hello-it ProgramArguments diff --git a/package/README.md b/package/README.md new file mode 100644 index 0000000..74bc45c --- /dev/null +++ b/package/README.md @@ -0,0 +1,31 @@ +# Building Hello-IT + +To prepare a new Hello-IT release, some steps must be followed in a specific order. + +## Preparation + +General code submission follows the git flow pattern. + +Once `develop` branch is ready for a new version, a new `release` branch named with the version number only (no `v` first). + +## Building the release + +To build the release once in the release branch, use the `BuildAndPackage.command` script. + +By default, build script will look for the Developer ID Installer named `Developer ID Installer: Yoann GINI (CRXPBZF3N4)`. Use `CUSTOM_DEVELOPER_ID_INSTALLER` environmental variable to specify your own. + +The script will build the app with all dependencies in the right order, sign it, create the package, and sign it too. + +The script will build the app in `Release` config when the current branch is under `release` or is `master`. All other branches will be built in `Debug` config. + +App version will be grabbed from git branches name or let untouched if the branch name does not match the pattern `release/version`. If version number is updated, it will automatically be committed before building the release. + +Build version is generated from the number of git commits in the history from the current branch point of view. + +Once built and tested, and only for final release (not for beta), the release branch must be merged in the master tree. Last commit to merge should be the one updating the app version. Returning to this exact commit will allow a developer to recreate the app in the exact same states (and so build version will be the same). + +The build will deny to start if there is some uncommitted change to the repo. + +## Distribution + +The pkg created at the previous step can now be updated into the Github Release system with a nice description and the pkg as the only payload. \ No newline at end of file diff --git a/src/HITDevKit/HITDevKit/Info.plist b/src/HITDevKit/HITDevKit/Info.plist index 1ad6ce0..78963ca 100644 --- a/src/HITDevKit/HITDevKit/Info.plist +++ b/src/HITDevKit/HITDevKit/Info.plist @@ -19,7 +19,7 @@ CFBundleSignature ???? CFBundleVersion - 178 + 199 NSHumanReadableCopyright Copyright © 2015 Yoann Gini (Open Source Project). All rights reserved. NSPrincipalClass diff --git a/src/Hello IT/AppDelegate.m b/src/Hello IT/AppDelegate.m index e9c22d4..c9764cc 100644 --- a/src/Hello IT/AppDelegate.m +++ b/src/Hello IT/AppDelegate.m @@ -293,7 +293,7 @@ - (void)loadMenu { - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { if ([keyPath isEqualToString:@"testState"]) { - int substate = 0; + int substate = HITPluginTestStateNone; if ([self.statusMenuManager respondsToSelector:@selector(testState)]) { substate |= [self.statusMenuManager testState]; diff --git a/src/Hello IT/Info.plist b/src/Hello IT/Info.plist index ff4953a..bad3981 100644 --- a/src/Hello IT/Info.plist +++ b/src/Hello IT/Info.plist @@ -17,11 +17,11 @@ CFBundlePackageType APPL CFBundleShortVersionString - 1.2.11 + 1.2.12 CFBundleSignature ???? CFBundleVersion - 178 + 199 LSApplicationCategoryType public.app-category.utilities LSMinimumSystemVersion diff --git a/src/Plugins/OpenApplication/OpenApplication/Info.plist b/src/Plugins/OpenApplication/OpenApplication/Info.plist index b02c3da..d05f4fe 100644 --- a/src/Plugins/OpenApplication/OpenApplication/Info.plist +++ b/src/Plugins/OpenApplication/OpenApplication/Info.plist @@ -19,7 +19,7 @@ CFBundleSignature ???? CFBundleVersion - 178 + 199 HITPFunctionIdentifier public.open.application NSHumanReadableCopyright diff --git a/src/Plugins/OpenResource/OpenResource/Info.plist b/src/Plugins/OpenResource/OpenResource/Info.plist index 677b56a..acff105 100644 --- a/src/Plugins/OpenResource/OpenResource/Info.plist +++ b/src/Plugins/OpenResource/OpenResource/Info.plist @@ -19,7 +19,7 @@ CFBundleSignature ???? CFBundleVersion - 178 + 199 HITPFunctionIdentifier public.open.resource NSHumanReadableCopyright diff --git a/src/Plugins/Quit/Quit/Info.plist b/src/Plugins/Quit/Quit/Info.plist index b0abbcd..2fa4c04 100644 --- a/src/Plugins/Quit/Quit/Info.plist +++ b/src/Plugins/Quit/Quit/Info.plist @@ -19,7 +19,7 @@ CFBundleSignature ???? CFBundleVersion - 178 + 199 HITPFunctionIdentifier public.quit NSHumanReadableCopyright diff --git a/src/Plugins/ScriptedItem/CustomScripts/com.github.ygini.hello-it.hostname.sh b/src/Plugins/ScriptedItem/CustomScripts/com.github.ygini.hello-it.hostname.sh index 720848c..bf68d35 100755 --- a/src/Plugins/ScriptedItem/CustomScripts/com.github.ygini.hello-it.hostname.sh +++ b/src/Plugins/ScriptedItem/CustomScripts/com.github.ygini.hello-it.hostname.sh @@ -13,7 +13,7 @@ . "$HELLO_IT_SCRIPT_FOLDER/com.github.ygini.hello-it.scriptlib.sh" -function updateTitleWithArgs { +function getHostname { hostname=$(scutil --get HostName) localhostname=$(scutil --get LocalHostName) computername=$(scutil --get ComputerName) @@ -25,12 +25,18 @@ function updateTitleWithArgs { format="%C" fi - title=$(echo "$format" | sed "s/%C/$computername/g" | sed "s/%H/$hostname/g" | sed "s/%L/$localhostname/g") + echo "$format" | sed "s/%C/$computername/g" | sed "s/%H/$hostname/g" | sed "s/%L/$localhostname/g" + +} + +function updateTitleWithArgs { + title=$(getHostname) updateTitle "Hostname: $title" } function onClickAction { updateTitleWithArgs "$@" + getHostname | pbcopy } function fromCronAction { diff --git a/src/Plugins/ScriptedItem/CustomScripts/com.github.ygini.hello-it.ip.sh b/src/Plugins/ScriptedItem/CustomScripts/com.github.ygini.hello-it.ip.sh index 09f4baf..1d169b1 100755 --- a/src/Plugins/ScriptedItem/CustomScripts/com.github.ygini.hello-it.ip.sh +++ b/src/Plugins/ScriptedItem/CustomScripts/com.github.ygini.hello-it.ip.sh @@ -14,6 +14,20 @@ . "$HELLO_IT_SCRIPT_FOLDER/com.github.ygini.hello-it.scriptlib.sh" +mode=0 +mainBSDInterface=$(route -n get 8.8.8.8 | grep "interface: " | awk -F ": " '{print $2}') + +while getopts "m:i:" o; do + case "${o}" in + m) + mode=${OPTARG} + ;; + i) + mainBSDInterface=${OPTARG} + ;; + esac +done + function handleStateUpdate { mode=$1 requestedState=$2 @@ -37,23 +51,13 @@ function handleStateUpdate { fi } -function updateTitleWithArgs { - mode=0 - mainBSDInterface=$(route -n get 8.8.8.8 | grep "interface: " | awk -F ": " '{print $2}') - - while getopts "m:i:" o; do - case "${o}" in - m) - mode=${OPTARG} - ;; - i) - mainBSDInterface=${OPTARG} - ;; - esac - done - - ipAddress=$(ifconfig "$mainBSDInterface" | grep "inet " | sed "s/.*inet \([0-9.]*\).*/\1/" | head -n1) +function getIP { + ifconfig "$mainBSDInterface" | grep "inet " | sed "s/.*inet \([0-9.]*\).*/\1/" | head -n1 +} +function updateTitleWithArgs { + ipAddress=$(getIP "$@") + if [ -z "$ipAddress" ] then updateTitle "No IP Address" @@ -66,7 +70,7 @@ function updateTitleWithArgs { updateTooltip "No network connection available" fi else - updateTitle "IP: $ipAddress" + updateTitle "Local IP: $ipAddress" handleStateUpdate $mode ${STATE[0]} updateTooltip "Having an IP address doesn't mean you've Internet access" fi @@ -75,6 +79,7 @@ function updateTitleWithArgs { function onClickAction { updateTitleWithArgs "$@" + getIP "$@" | pbcopy } function fromCronAction { diff --git a/src/Plugins/ScriptedItem/CustomScripts/com.github.ygini.hello-it.public-ip.sh b/src/Plugins/ScriptedItem/CustomScripts/com.github.ygini.hello-it.public-ip.sh new file mode 100755 index 0000000..59c15a6 --- /dev/null +++ b/src/Plugins/ScriptedItem/CustomScripts/com.github.ygini.hello-it.public-ip.sh @@ -0,0 +1,95 @@ +#!/bin/bash + +# Display Public IP address as title +# With no option, the script detect the public +# address using https://ip.abelionni.com/script/ +# +# You can specify the test URL using -u +# +# You can specify the behavior if no IP +# are found with -m option: +# 0: show IP if available, hide if not +# 1: show IP if available, specify if not, no $STATE +# 2: show IP if available, specify if not, use $STATE + +. "$HELLO_IT_SCRIPT_FOLDER/com.github.ygini.hello-it.scriptlib.sh" + +mode=0 +public_ip_url="https://ip.abelionni.com/script/" + +while getopts "m:u:" o; do + case "${o}" in + m) + mode=${OPTARG} + ;; + u) + public_ip_url=${OPTARG} + ;; + esac +done + +function handleStateUpdate { + mode=$1 + requestedState=$2 + + if [ $mode -eq 0 ] + then + if [ "$requestedState" == ${STATE[0]} ] + then + setHidden NO + else + setHidden YES + fi + else + setHidden NO + if [ $mode -eq 1 ] + then + updateState ${STATE[4]} + else + updateState $requestedState + fi + fi +} + +function getIP { + curl -s "$public_ip_url" +} + +function updateTitleWithArgs { + ipAddress=$(curl -s "$public_ip_url") + + if [ -z "$ipAddress" ] + then + updateTitle "No IP Address" + if [[ "$HELLO_IT_NETWORK_STATE" == "1" ]] + then + handleStateUpdate $mode ${STATE[2]} + updateTooltip "Please, check your Ethernet or WiFi connection" + else + handleStateUpdate $mode ${STATE[3]} + updateTooltip "No internet connection available" + fi + else + updateTitle "Public IP: $ipAddress" + handleStateUpdate $mode ${STATE[0]} + updateTooltip "You should have access to Internet" + fi + +} + +function onClickAction { + updateTitleWithArgs "$@" + getIP "$@" | pbcopy +} + +function fromCronAction { + updateTitleWithArgs "$@" +} + +function setTitleAction { + updateTitleWithArgs "$@" +} + +main "$@" + +exit 0 diff --git a/src/Plugins/ScriptedItem/ScriptedItem/Info.plist b/src/Plugins/ScriptedItem/ScriptedItem/Info.plist index 1517372..7bd501a 100644 --- a/src/Plugins/ScriptedItem/ScriptedItem/Info.plist +++ b/src/Plugins/ScriptedItem/ScriptedItem/Info.plist @@ -19,7 +19,7 @@ CFBundleSignature ???? CFBundleVersion - 178 + 199 HITPFunctionIdentifier public.script.item NSHumanReadableCopyright diff --git a/src/Plugins/Separator/Separator/Info.plist b/src/Plugins/Separator/Separator/Info.plist index 1891f94..28d1d97 100644 --- a/src/Plugins/Separator/Separator/Info.plist +++ b/src/Plugins/Separator/Separator/Info.plist @@ -19,7 +19,7 @@ CFBundleSignature ???? CFBundleVersion - 178 + 199 HITPFunctionIdentifier public.separator NSHumanReadableCopyright diff --git a/src/Plugins/SubMenu/SubMenu/Info.plist b/src/Plugins/SubMenu/SubMenu/Info.plist index 9756999..0a5a3bc 100644 --- a/src/Plugins/SubMenu/SubMenu/Info.plist +++ b/src/Plugins/SubMenu/SubMenu/Info.plist @@ -19,7 +19,7 @@ CFBundleSignature ???? CFBundleVersion - 178 + 199 HITPFunctionIdentifier public.submenu NSHumanReadableCopyright diff --git a/src/Plugins/TestHTTP/TestHTTP/Info.plist b/src/Plugins/TestHTTP/TestHTTP/Info.plist index 9da8421..0f2db5d 100644 --- a/src/Plugins/TestHTTP/TestHTTP/Info.plist +++ b/src/Plugins/TestHTTP/TestHTTP/Info.plist @@ -19,7 +19,7 @@ CFBundleSignature ???? CFBundleVersion - 178 + 199 HITPFunctionIdentifier public.test.http NSHumanReadableCopyright diff --git a/src/Plugins/Title/Title/Info.plist b/src/Plugins/Title/Title/Info.plist index 70d3ace..4639402 100644 --- a/src/Plugins/Title/Title/Info.plist +++ b/src/Plugins/Title/Title/Info.plist @@ -19,7 +19,7 @@ CFBundleSignature ???? CFBundleVersion - 178 + 199 HITPFunctionIdentifier public.title NSHumanReadableCopyright