2017-01-28 16:11:05 -05:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
#
|
|
|
|
# KeePassXC Release Preparation Helper
|
|
|
|
# Copyright (C) 2017 KeePassXC team <https://keepassxc.org/>
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 2 or (at your option)
|
|
|
|
# version 3 of the License.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2017-02-11 11:05:28 -05:00
|
|
|
printf "\e[1m\e[32mKeePassXC\e[0m Release Preparation Helper\n"
|
|
|
|
printf "Copyright (C) 2017 KeePassXC Team <https://keepassxc.org/>\n\n"
|
2017-01-28 16:11:05 -05:00
|
|
|
|
|
|
|
|
|
|
|
# -----------------------------------------------------------------------
|
|
|
|
# global default values
|
|
|
|
# -----------------------------------------------------------------------
|
|
|
|
RELEASE_NAME=""
|
|
|
|
APP_NAME="KeePassXC"
|
|
|
|
SRC_DIR="."
|
|
|
|
GPG_KEY="CFB4C2166397D0D2"
|
|
|
|
GPG_GIT_KEY=""
|
|
|
|
OUTPUT_DIR="release"
|
|
|
|
SOURCE_BRANCH=""
|
|
|
|
TARGET_BRANCH="master"
|
|
|
|
TAG_NAME=""
|
|
|
|
DOCKER_IMAGE=""
|
|
|
|
DOCKER_CONTAINER_NAME="keepassxc-build-container"
|
|
|
|
CMAKE_OPTIONS=""
|
|
|
|
COMPILER="g++"
|
|
|
|
MAKE_OPTIONS="-j8"
|
2017-11-27 22:46:03 -05:00
|
|
|
BUILD_PLUGINS="all"
|
2017-01-28 16:11:05 -05:00
|
|
|
INSTALL_PREFIX="/usr/local"
|
|
|
|
BUILD_SOURCE_TARBALL=true
|
2017-11-27 22:46:03 -05:00
|
|
|
BUILD_SNAPSHOT=false
|
2017-01-28 16:11:05 -05:00
|
|
|
ORIG_BRANCH=""
|
|
|
|
ORIG_CWD="$(pwd)"
|
|
|
|
|
|
|
|
# -----------------------------------------------------------------------
|
|
|
|
# helper functions
|
|
|
|
# -----------------------------------------------------------------------
|
|
|
|
printUsage() {
|
|
|
|
local cmd
|
|
|
|
if [ "" == "$1" ] || [ "help" == "$1" ]; then
|
|
|
|
cmd="COMMAND"
|
2017-12-13 16:38:44 -05:00
|
|
|
elif [ "check" == "$1" ] || [ "merge" == "$1" ] || [ "build" == "$1" ] || [ "gpgsign" == "$1" ] || [ "appsign" == "$1" ]; then
|
2017-01-28 16:11:05 -05:00
|
|
|
cmd="$1"
|
|
|
|
else
|
2017-01-28 17:17:48 -05:00
|
|
|
logError "Unknown command: '$1'\n"
|
2017-01-28 16:11:05 -05:00
|
|
|
cmd="COMMAND"
|
|
|
|
fi
|
2017-12-13 16:38:44 -05:00
|
|
|
|
|
|
|
printf "\e[1mUsage:\e[0m $(basename $0) $cmd [options]\n"
|
2017-01-28 16:11:05 -05:00
|
|
|
|
|
|
|
if [ "COMMAND" == "$cmd" ]; then
|
|
|
|
cat << EOF
|
|
|
|
|
|
|
|
Commands:
|
2017-06-06 10:35:16 -04:00
|
|
|
check Perform a dry-run check, nothing is changed
|
2017-01-28 16:19:23 -05:00
|
|
|
merge Merge release branch into main branch and create release tags
|
2017-01-28 16:11:05 -05:00
|
|
|
build Build and package binary release from sources
|
2017-12-13 16:38:44 -05:00
|
|
|
gpgsign Sign previously compiled release packages with GPG
|
|
|
|
appsign Sign binaries with code signing certificates on Windows and macOS
|
2017-01-28 16:11:05 -05:00
|
|
|
help Show help for the given command
|
|
|
|
EOF
|
|
|
|
elif [ "merge" == "$cmd" ]; then
|
|
|
|
cat << EOF
|
|
|
|
|
2017-01-29 06:52:05 -05:00
|
|
|
Merge release branch into main branch and create release tags
|
|
|
|
|
2017-01-28 16:11:05 -05:00
|
|
|
Options:
|
|
|
|
-v, --version Release version number or name (required)
|
|
|
|
-a, --app-name Application name (default: '${APP_NAME}')
|
|
|
|
-s, --source-dir Source directory (default: '${SRC_DIR}')
|
|
|
|
-g, --gpg-key GPG key used to sign the merge commit and release tag,
|
|
|
|
leave empty to let Git choose your default key
|
|
|
|
(default: '${GPG_GIT_KEY}')
|
|
|
|
-r, --release-branch Source release branch to merge from (default: 'release/VERSION')
|
|
|
|
--target-branch Target branch to merge to (default: '${TARGET_BRANCH}')
|
|
|
|
-t, --tag-name Override release tag name (defaults to version number)
|
|
|
|
-h, --help Show this help
|
|
|
|
EOF
|
|
|
|
elif [ "build" == "$cmd" ]; then
|
|
|
|
cat << EOF
|
|
|
|
|
2017-01-29 06:52:05 -05:00
|
|
|
Build and package binary release from sources
|
|
|
|
|
2017-01-28 16:11:05 -05:00
|
|
|
Options:
|
|
|
|
-v, --version Release version number or name (required)
|
|
|
|
-a, --app-name Application name (default: '${APP_NAME}')
|
|
|
|
-s, --source-dir Source directory (default: '${SRC_DIR}')
|
|
|
|
-o, --output-dir Output directory where to build the release
|
|
|
|
(default: '${OUTPUT_DIR}')
|
|
|
|
-t, --tag-name Release tag to check out (defaults to version number)
|
|
|
|
-b, --build Build sources after exporting release
|
|
|
|
-d, --docker-image Use the specified Docker image to compile the application.
|
|
|
|
The image must have all required build dependencies installed.
|
|
|
|
This option has no effect if --build is not set.
|
|
|
|
--container-name Docker container name (default: '${DOCKER_CONTAINER_NAME}')
|
|
|
|
The container must not exist already
|
|
|
|
-c, --cmake-options Additional CMake options for compiling the sources
|
|
|
|
--compiler Compiler to use (default: '${COMPILER}')
|
|
|
|
-m, --make-options Make options for compiling sources (default: '${MAKE_OPTIONS}')
|
|
|
|
-i, --install-prefix Install prefix (default: '${INSTALL_PREFIX}')
|
|
|
|
-p, --plugins Space-separated list of plugins to build
|
|
|
|
(default: ${BUILD_PLUGINS})
|
2017-11-27 22:46:03 -05:00
|
|
|
--snapshot Don't checkout the release tag
|
2017-01-28 16:11:05 -05:00
|
|
|
-n, --no-source-tarball Don't build source tarball
|
|
|
|
-h, --help Show this help
|
|
|
|
EOF
|
2017-12-13 16:38:44 -05:00
|
|
|
elif [ "gpgsign" == "$cmd" ]; then
|
2017-01-28 16:11:05 -05:00
|
|
|
cat << EOF
|
|
|
|
|
2017-12-13 16:38:44 -05:00
|
|
|
Sign previously compiled release packages with GPG
|
2017-01-29 06:52:05 -05:00
|
|
|
|
2017-01-28 16:11:05 -05:00
|
|
|
Options:
|
2017-10-05 18:04:41 -04:00
|
|
|
-f, --files Files to sign (required)
|
|
|
|
-g, --gpg-key GPG key used to sign the files (default: '${GPG_KEY}')
|
2017-12-13 16:38:44 -05:00
|
|
|
-h, --help Show this help
|
|
|
|
EOF
|
|
|
|
elif [ "appsign" == "$cmd" ]; then
|
|
|
|
cat << EOF
|
|
|
|
|
|
|
|
Sign binaries with code signing certificates on Windows and macOS
|
|
|
|
|
|
|
|
Options:
|
|
|
|
-f, --files Files to sign (required)
|
|
|
|
-k, --signtool-key Key to be used with signtool (required for Windows EXE)
|
|
|
|
-i, --identity Apple Developer ID to be used with codesign (required for macOS APP and DMG)
|
2017-10-05 18:04:41 -04:00
|
|
|
-h, --help Show this help
|
2017-01-28 16:11:05 -05:00
|
|
|
EOF
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
logInfo() {
|
2017-02-11 11:05:28 -05:00
|
|
|
printf "\e[1m[ \e[34mINFO\e[39m ]\e[0m $1\n"
|
2017-01-28 16:11:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
logError() {
|
2017-02-11 11:05:28 -05:00
|
|
|
printf "\e[1m[ \e[31mERROR\e[39m ]\e[0m $1\n" >&2
|
2017-01-28 16:11:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
init() {
|
2017-06-06 10:35:16 -04:00
|
|
|
if [ "" == "$RELEASE_NAME" ]; then
|
|
|
|
logError "Missing arguments, --version is required!\n"
|
|
|
|
printUsage "check"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "" == "$TAG_NAME" ]; then
|
|
|
|
TAG_NAME="$RELEASE_NAME"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "" == "$SOURCE_BRANCH" ]; then
|
|
|
|
SOURCE_BRANCH="release/${RELEASE_NAME}"
|
|
|
|
fi
|
|
|
|
|
2017-01-28 16:11:05 -05:00
|
|
|
ORIG_CWD="$(pwd)"
|
2017-06-06 10:35:16 -04:00
|
|
|
SRC_DIR="$(realpath "$SRC_DIR")"
|
2017-01-28 16:11:05 -05:00
|
|
|
cd "$SRC_DIR" > /dev/null 2>&1
|
|
|
|
ORIG_BRANCH="$(git rev-parse --abbrev-ref HEAD 2> /dev/null)"
|
|
|
|
cd "$ORIG_CWD"
|
|
|
|
}
|
|
|
|
|
|
|
|
cleanup() {
|
|
|
|
logInfo "Checking out original branch..."
|
|
|
|
if [ "" != "$ORIG_BRANCH" ]; then
|
|
|
|
git checkout "$ORIG_BRANCH" > /dev/null 2>&1
|
|
|
|
fi
|
|
|
|
logInfo "Leaving source directory..."
|
|
|
|
cd "$ORIG_CWD"
|
|
|
|
}
|
|
|
|
|
|
|
|
exitError() {
|
|
|
|
logError "$1"
|
|
|
|
cleanup
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
exitTrap() {
|
|
|
|
exitError "Existing upon user request..."
|
|
|
|
}
|
|
|
|
|
|
|
|
checkSourceDirExists() {
|
|
|
|
if [ ! -d "$SRC_DIR" ]; then
|
|
|
|
exitError "Source directory '${SRC_DIR}' does not exist!"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
checkOutputDirDoesNotExist() {
|
|
|
|
if [ -e "$OUTPUT_DIR" ]; then
|
|
|
|
exitError "Output directory '$OUTPUT_DIR' already exists. Please choose a different location!"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
checkGitRepository() {
|
|
|
|
if [ ! -d .git ] || [ ! -f CHANGELOG ]; then
|
|
|
|
exitError "Source directory is not a valid Git repository!"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
checkTagExists() {
|
|
|
|
git tag | grep -q "$TAG_NAME"
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
exitError "Tag '${TAG_NAME}' does not exist!"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
checkReleaseDoesNotExist() {
|
|
|
|
git tag | grep -q "$TAG_NAME"
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
exitError "Release '$RELEASE_NAME' (tag: '$TAG_NAME') already exists!"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
checkWorkingTreeClean() {
|
|
|
|
git diff-index --quiet HEAD --
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
exitError "Current working tree is not clean! Please commit or unstage any changes."
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
checkSourceBranchExists() {
|
|
|
|
git rev-parse "$SOURCE_BRANCH" > /dev/null 2>&1
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
exitError "Source branch '$SOURCE_BRANCH' does not exist!"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
checkTargetBranchExists() {
|
|
|
|
git rev-parse "$TARGET_BRANCH" > /dev/null 2>&1
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
exitError "Target branch '$TARGET_BRANCH' does not exist!"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
checkVersionInCMake() {
|
|
|
|
local app_name_upper="$(echo "$APP_NAME" | tr '[:lower:]' '[:upper:]')"
|
2017-06-06 10:35:16 -04:00
|
|
|
local major_num="$(echo ${RELEASE_NAME} | cut -f1 -d.)"
|
|
|
|
local minor_num="$(echo ${RELEASE_NAME} | cut -f2 -d.)"
|
2018-02-17 11:46:19 -05:00
|
|
|
local patch_num="$(echo ${RELEASE_NAME} | cut -f3 -d. | cut -f1 -d-)"
|
2017-06-06 10:35:16 -04:00
|
|
|
|
|
|
|
grep -q "${app_name_upper}_VERSION_MAJOR \"${major_num}\"" CMakeLists.txt
|
2017-01-28 16:11:05 -05:00
|
|
|
if [ $? -ne 0 ]; then
|
2017-06-06 10:35:16 -04:00
|
|
|
exitError "${app_name_upper}_VERSION_MAJOR not updated to '${major_num}' in CMakeLists.txt!"
|
2017-01-28 16:11:05 -05:00
|
|
|
fi
|
|
|
|
|
2017-06-06 10:35:16 -04:00
|
|
|
grep -q "${app_name_upper}_VERSION_MINOR \"${minor_num}\"" CMakeLists.txt
|
2017-01-28 16:11:05 -05:00
|
|
|
if [ $? -ne 0 ]; then
|
2017-06-06 10:35:16 -04:00
|
|
|
exitError "${app_name_upper}_VERSION_MINOR not updated to '${minor_num}' in CMakeLists.txt!"
|
|
|
|
fi
|
|
|
|
|
|
|
|
grep -q "${app_name_upper}_VERSION_PATCH \"${patch_num}\"" CMakeLists.txt
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
exitError "${app_name_upper}_VERSION_PATCH not updated to '${patch_num}' in CMakeLists.txt!"
|
2017-01-28 16:11:05 -05:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
checkChangeLog() {
|
|
|
|
if [ ! -f CHANGELOG ]; then
|
|
|
|
exitError "No CHANGELOG file found!"
|
|
|
|
fi
|
|
|
|
|
|
|
|
grep -qPzo "${RELEASE_NAME} \(\d{4}-\d{2}-\d{2}\)\n=+\n" CHANGELOG
|
|
|
|
if [ $? -ne 0 ]; then
|
2017-10-17 08:36:18 -04:00
|
|
|
exitError "'CHANGELOG' has not been updated to the '${RELEASE_NAME}' release!"
|
2017-01-28 16:11:05 -05:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2017-10-17 08:36:18 -04:00
|
|
|
checkAppStreamInfo() {
|
2017-10-26 07:00:50 -04:00
|
|
|
if [ ! -f share/linux/org.keepassxc.KeePassXC.appdata.xml ]; then
|
2017-10-17 08:36:18 -04:00
|
|
|
exitError "No AppStream info file found!"
|
2017-01-28 17:02:26 -05:00
|
|
|
fi
|
2017-06-06 10:35:16 -04:00
|
|
|
|
2017-10-26 07:00:50 -04:00
|
|
|
grep -qPzo "<release version=\"${RELEASE_NAME}\" date=\"\d{4}-\d{2}-\d{2}\">" share/linux/org.keepassxc.KeePassXC.appdata.xml
|
2017-10-17 08:36:18 -04:00
|
|
|
if [ $? -ne 0 ]; then
|
2017-10-26 07:00:50 -04:00
|
|
|
exitError "'share/linux/org.keepassxc.KeePassXC.appdata.xml' has not been updated to the '${RELEASE_NAME}' release!"
|
2017-06-06 10:35:16 -04:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
checkSnapcraft() {
|
|
|
|
if [ ! -f snapcraft.yaml ]; then
|
|
|
|
echo "No snapcraft file found!"
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
grep -qPzo "version: ${RELEASE_NAME}" snapcraft.yaml
|
|
|
|
if [ $? -ne 0 ]; then
|
2017-10-17 08:36:18 -04:00
|
|
|
exitError "'snapcraft.yaml' has not been updated to the '${RELEASE_NAME}' release!"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
checkTransifexCommandExists() {
|
|
|
|
command -v tx > /dev/null
|
|
|
|
if [ 0 -ne $? ]; then
|
2017-12-13 16:38:44 -05:00
|
|
|
exitError "Transifex tool 'tx' not installed! Please install it using 'pip install transifex-client'."
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2017-12-14 12:17:43 -05:00
|
|
|
checkOsslsigncodeCommandExists() {
|
|
|
|
command -v osslsigncode > /dev/null
|
2017-12-13 16:38:44 -05:00
|
|
|
if [ 0 -ne $? ]; then
|
2017-12-14 12:17:43 -05:00
|
|
|
exitError "osslsigncode command not found on the PATH! Please install it using 'pacman -S mingw-w64-osslsigncode'."
|
2017-12-13 16:38:44 -05:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2017-11-27 22:46:03 -05:00
|
|
|
checkSigntoolCommandExists() {
|
|
|
|
command -v signtool > /dev/null
|
|
|
|
if [ 0 -ne $? ]; then
|
|
|
|
exitError "signtool command not found on the PATH! Add the Windows SDK binary folder to your PATH."
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2017-12-13 16:38:44 -05:00
|
|
|
checkCodesignCommandExists() {
|
|
|
|
command -v codesign > /dev/null
|
|
|
|
if [ 0 -ne $? ]; then
|
|
|
|
exitError "codesign command not found on the PATH! Please check that you have correctly installed Xcode."
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2017-10-17 08:54:11 -04:00
|
|
|
checkQt5LUpdateExists() {
|
|
|
|
command -v lupdate > /dev/null
|
|
|
|
if [ 0 -eq $? ] && ! $(lupdate -version | grep -q "lupdate version 5\."); then
|
|
|
|
command -v lupdate-qt5 > /dev/null
|
|
|
|
if [ 0 -ne $? ]; then
|
|
|
|
exitError "Qt Linguist tool (lupdate-qt5) is not installed! Please install using 'apt install qttools5-dev-tools'"
|
|
|
|
fi
|
2017-06-06 10:35:16 -04:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
performChecks() {
|
|
|
|
logInfo "Performing basic checks..."
|
|
|
|
|
|
|
|
checkSourceDirExists
|
|
|
|
|
|
|
|
logInfo "Changing to source directory..."
|
|
|
|
cd "${SRC_DIR}"
|
|
|
|
|
|
|
|
logInfo "Validating toolset and repository..."
|
|
|
|
|
|
|
|
checkTransifexCommandExists
|
2017-10-17 08:54:11 -04:00
|
|
|
checkQt5LUpdateExists
|
2017-06-06 10:35:16 -04:00
|
|
|
checkGitRepository
|
|
|
|
checkReleaseDoesNotExist
|
|
|
|
checkWorkingTreeClean
|
|
|
|
checkSourceBranchExists
|
|
|
|
checkTargetBranchExists
|
|
|
|
|
|
|
|
logInfo "Checking out '${SOURCE_BRANCH}'..."
|
|
|
|
git checkout "$SOURCE_BRANCH"
|
|
|
|
|
|
|
|
logInfo "Attempting to find '${RELEASE_NAME}' in various files..."
|
|
|
|
|
|
|
|
checkVersionInCMake
|
|
|
|
checkChangeLog
|
2017-10-17 08:36:18 -04:00
|
|
|
checkAppStreamInfo
|
2017-06-06 10:35:16 -04:00
|
|
|
checkSnapcraft
|
|
|
|
|
|
|
|
logInfo "\e[1m\e[32mAll checks passed!\e[0m"
|
2017-01-28 17:02:26 -05:00
|
|
|
}
|
|
|
|
|
2017-01-31 13:25:15 -05:00
|
|
|
# re-implement realpath for OS X (thanks mschrag)
|
2017-01-31 19:03:30 -05:00
|
|
|
# https://superuser.com/questions/205127/
|
2017-02-11 11:08:53 -05:00
|
|
|
if ! $(command -v realpath > /dev/null); then
|
2017-01-31 13:25:15 -05:00
|
|
|
realpath() {
|
|
|
|
pushd . > /dev/null
|
|
|
|
if [ -d "$1" ]; then
|
2017-01-31 19:03:30 -05:00
|
|
|
cd "$1"
|
|
|
|
dirs -l +0
|
|
|
|
else
|
|
|
|
cd "$(dirname "$1")"
|
|
|
|
cur_dir=$(dirs -l +0)
|
2017-01-31 13:25:15 -05:00
|
|
|
|
|
|
|
if [ "$cur_dir" == "/" ]; then
|
2017-01-31 19:03:30 -05:00
|
|
|
echo "$cur_dir$(basename "$1")"
|
2017-01-31 13:25:15 -05:00
|
|
|
else
|
2017-01-31 19:03:30 -05:00
|
|
|
echo "$cur_dir/$(basename "$1")"
|
2017-01-31 13:25:15 -05:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
popd > /dev/null
|
|
|
|
}
|
|
|
|
fi
|
|
|
|
|
2017-01-28 16:11:05 -05:00
|
|
|
|
|
|
|
trap exitTrap SIGINT SIGTERM
|
|
|
|
|
2017-06-06 10:35:16 -04:00
|
|
|
# -----------------------------------------------------------------------
|
|
|
|
# check command
|
|
|
|
# -----------------------------------------------------------------------
|
|
|
|
check() {
|
|
|
|
while [ $# -ge 1 ]; do
|
|
|
|
local arg="$1"
|
|
|
|
case "$arg" in
|
|
|
|
-v|--version)
|
|
|
|
RELEASE_NAME="$2"
|
|
|
|
shift ;;
|
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
|
|
|
|
init
|
|
|
|
|
|
|
|
performChecks
|
|
|
|
|
|
|
|
cleanup
|
|
|
|
|
|
|
|
logInfo "Congrats! You can successfully merge, build, and sign KeepassXC."
|
|
|
|
}
|
2017-01-28 16:11:05 -05:00
|
|
|
|
|
|
|
# -----------------------------------------------------------------------
|
|
|
|
# merge command
|
|
|
|
# -----------------------------------------------------------------------
|
|
|
|
merge() {
|
|
|
|
while [ $# -ge 1 ]; do
|
|
|
|
local arg="$1"
|
|
|
|
case "$arg" in
|
|
|
|
-v|--version)
|
|
|
|
RELEASE_NAME="$2"
|
|
|
|
shift ;;
|
|
|
|
|
|
|
|
-a|--app-name)
|
|
|
|
APP_NAME="$2"
|
|
|
|
shift ;;
|
|
|
|
|
|
|
|
-s|--source-dir)
|
|
|
|
SRC_DIR="$2"
|
|
|
|
shift ;;
|
|
|
|
|
|
|
|
-g|--gpg-key)
|
|
|
|
GPG_GIT_KEY="$2"
|
|
|
|
shift ;;
|
|
|
|
|
|
|
|
-r|--release-branch)
|
|
|
|
SOURCE_BRANCH="$2"
|
|
|
|
shift ;;
|
|
|
|
|
|
|
|
--target-branch)
|
|
|
|
TARGET_BRANCH="$2"
|
|
|
|
shift ;;
|
|
|
|
|
|
|
|
-t|--tag-name)
|
|
|
|
TAG_NAME="$2"
|
|
|
|
shift ;;
|
|
|
|
|
|
|
|
-h|--help)
|
|
|
|
printUsage "merge"
|
|
|
|
exit ;;
|
|
|
|
|
|
|
|
*)
|
|
|
|
logError "Unknown option '$arg'\n"
|
|
|
|
printUsage "merge"
|
|
|
|
exit 1 ;;
|
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
|
|
|
|
init
|
|
|
|
|
2017-06-06 10:35:16 -04:00
|
|
|
performChecks
|
2017-01-28 17:02:26 -05:00
|
|
|
|
|
|
|
logInfo "Updating language files..."
|
2018-01-20 11:05:29 -05:00
|
|
|
./share/translations/update.sh update
|
|
|
|
./share/translations/update.sh pull
|
2017-01-28 17:02:26 -05:00
|
|
|
if [ 0 -ne $? ]; then
|
|
|
|
exitError "Updating translations failed!"
|
|
|
|
fi
|
|
|
|
git diff-index --quiet HEAD --
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
git add ./share/translations/*
|
|
|
|
logInfo "Committing changes..."
|
|
|
|
if [ "" == "$GPG_GIT_KEY" ]; then
|
|
|
|
git commit -m "Update translations"
|
|
|
|
else
|
|
|
|
git commit -m "Update translations" -S"$GPG_GIT_KEY"
|
|
|
|
fi
|
|
|
|
fi
|
2017-01-28 16:11:05 -05:00
|
|
|
|
2017-02-11 11:19:46 -05:00
|
|
|
CHANGELOG=$(grep -Pzo "(?<=${RELEASE_NAME} \(\d{4}-\d{2}-\d{2}\)\n)=+\n\n?(?:.|\n)+?\n(?=\n)" \
|
|
|
|
CHANGELOG | grep -Pzo '(?<=\n\n)(.|\n)+' | tr -d \\0)
|
|
|
|
COMMIT_MSG="Release ${RELEASE_NAME}"
|
|
|
|
|
2017-01-28 16:11:05 -05:00
|
|
|
logInfo "Checking out target branch '${TARGET_BRANCH}'..."
|
|
|
|
git checkout "$TARGET_BRANCH"
|
|
|
|
|
|
|
|
logInfo "Merging '${SOURCE_BRANCH}' into '${TARGET_BRANCH}'..."
|
|
|
|
|
|
|
|
git merge "$SOURCE_BRANCH" --no-ff -m "$COMMIT_MSG" -m "${CHANGELOG}" "$SOURCE_BRANCH" -S"$GPG_GIT_KEY"
|
|
|
|
|
|
|
|
logInfo "Creating tag '${TAG_NAME}'..."
|
|
|
|
if [ "" == "$GPG_GIT_KEY" ]; then
|
|
|
|
git tag -a "$TAG_NAME" -m "$COMMIT_MSG" -m "${CHANGELOG}" -s
|
|
|
|
else
|
|
|
|
git tag -a "$TAG_NAME" -m "$COMMIT_MSG" -m "${CHANGELOG}" -s -u "$GPG_GIT_KEY"
|
|
|
|
fi
|
|
|
|
|
|
|
|
cleanup
|
|
|
|
|
|
|
|
logInfo "All done!"
|
|
|
|
logInfo "Please merge the release branch back into the develop branch now and then push your changes."
|
|
|
|
logInfo "Don't forget to also push the tags using \e[1mgit push --tags\e[0m."
|
|
|
|
}
|
|
|
|
|
|
|
|
# -----------------------------------------------------------------------
|
|
|
|
# build command
|
|
|
|
# -----------------------------------------------------------------------
|
|
|
|
build() {
|
|
|
|
while [ $# -ge 1 ]; do
|
|
|
|
local arg="$1"
|
|
|
|
case "$arg" in
|
|
|
|
-v|--version)
|
|
|
|
RELEASE_NAME="$2"
|
|
|
|
shift ;;
|
|
|
|
|
|
|
|
-a|--app-name)
|
|
|
|
APP_NAME="$2"
|
|
|
|
shift ;;
|
|
|
|
|
|
|
|
-s|--source-dir)
|
|
|
|
SRC_DIR="$2"
|
|
|
|
shift ;;
|
|
|
|
|
|
|
|
-o|--output-dir)
|
|
|
|
OUTPUT_DIR="$2"
|
|
|
|
shift ;;
|
|
|
|
|
|
|
|
-t|--tag-name)
|
|
|
|
TAG_NAME="$2"
|
|
|
|
shift ;;
|
|
|
|
|
|
|
|
-d|--docker-image)
|
|
|
|
DOCKER_IMAGE="$2"
|
|
|
|
shift ;;
|
|
|
|
|
|
|
|
--container-name)
|
|
|
|
DOCKER_CONTAINER_NAME="$2"
|
|
|
|
shift ;;
|
|
|
|
|
|
|
|
-c|--cmake-options)
|
|
|
|
CMAKE_OPTIONS="$2"
|
|
|
|
shift ;;
|
|
|
|
|
|
|
|
--compiler)
|
|
|
|
COMPILER="$2"
|
|
|
|
shift ;;
|
|
|
|
|
|
|
|
-m|--make-options)
|
|
|
|
MAKE_OPTIONS="$2"
|
|
|
|
shift ;;
|
|
|
|
|
|
|
|
-i|--install-prefix)
|
|
|
|
INSTALL_PREFIX="$2"
|
|
|
|
shift ;;
|
|
|
|
|
|
|
|
-p|--plugins)
|
|
|
|
BUILD_PLUGINS="$2"
|
|
|
|
shift ;;
|
|
|
|
|
|
|
|
-n|--no-source-tarball)
|
|
|
|
BUILD_SOURCE_TARBALL=false ;;
|
2017-11-27 22:46:03 -05:00
|
|
|
|
|
|
|
--snapshot)
|
|
|
|
BUILD_SNAPSHOT=true ;;
|
2017-01-28 16:11:05 -05:00
|
|
|
|
|
|
|
-h|--help)
|
|
|
|
printUsage "build"
|
|
|
|
exit ;;
|
|
|
|
|
|
|
|
*)
|
|
|
|
logError "Unknown option '$arg'\n"
|
|
|
|
printUsage "build"
|
|
|
|
exit 1 ;;
|
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|
2017-06-06 10:35:16 -04:00
|
|
|
|
2017-01-28 16:11:05 -05:00
|
|
|
init
|
|
|
|
|
|
|
|
OUTPUT_DIR="$(realpath "$OUTPUT_DIR")"
|
2017-10-05 18:04:41 -04:00
|
|
|
|
2018-02-17 11:46:19 -05:00
|
|
|
if ${BUILD_SNAPSHOT}; then
|
2017-11-27 22:46:03 -05:00
|
|
|
TAG_NAME="HEAD"
|
|
|
|
local branch=`git rev-parse --abbrev-ref HEAD`
|
|
|
|
logInfo "Using current branch ${branch} to build..."
|
|
|
|
RELEASE_NAME="${RELEASE_NAME}-snapshot"
|
2018-02-17 11:46:19 -05:00
|
|
|
CMAKE_OPTIONS="${CMAKE_OPTIONS} -DKEEPASSXC_BUILD_TYPE=Snapshot"
|
2017-11-27 22:46:03 -05:00
|
|
|
else
|
2018-02-17 11:46:19 -05:00
|
|
|
checkWorkingTreeClean
|
|
|
|
|
|
|
|
if $(echo "$TAG_NAME" | grep -qP "\-(alpha|beta)\\d+\$"); then
|
|
|
|
CMAKE_OPTIONS="${CMAKE_OPTIONS} -DKEEPASSXC_BUILD_TYPE=PreRelease"
|
|
|
|
logInfo "Checking out pre-release tag '${TAG_NAME}'..."
|
|
|
|
else
|
|
|
|
CMAKE_OPTIONS="${CMAKE_OPTIONS} -DKEEPASSXC_BUILD_TYPE=Release"
|
|
|
|
logInfo "Checking out release tag '${TAG_NAME}'..."
|
|
|
|
fi
|
2017-11-27 22:46:03 -05:00
|
|
|
git checkout "$TAG_NAME"
|
|
|
|
fi
|
2017-10-05 18:04:41 -04:00
|
|
|
|
2017-01-28 16:11:05 -05:00
|
|
|
logInfo "Creating output directory..."
|
|
|
|
mkdir -p "$OUTPUT_DIR"
|
|
|
|
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
exitError "Failed to create output directory!"
|
|
|
|
fi
|
|
|
|
|
2018-02-17 11:46:19 -05:00
|
|
|
if ${BUILD_SOURCE_TARBALL}; then
|
2017-01-28 16:11:05 -05:00
|
|
|
logInfo "Creating source tarball..."
|
|
|
|
local app_name_lower="$(echo "$APP_NAME" | tr '[:upper:]' '[:lower:]')"
|
2018-02-22 15:53:29 -05:00
|
|
|
local prefix="${app_name_lower}-${RELEASE_NAME}"
|
|
|
|
local tarball_name="${prefix}-src.tar"
|
|
|
|
|
|
|
|
git archive --format=tar "$TAG_NAME" --prefix="${prefix}/" --output="${OUTPUT_DIR}/${tarball_name}"
|
|
|
|
|
2018-02-24 17:20:53 -05:00
|
|
|
if ! ${BUILD_SNAPSHOT}; then
|
|
|
|
# add .version file to tar
|
|
|
|
mkdir "${prefix}"
|
|
|
|
echo -n ${RELEASE_NAME} > "${prefix}/.version"
|
|
|
|
tar --append --file="${OUTPUT_DIR}/${tarball_name}" "${prefix}/.version"
|
|
|
|
rm "${prefix}/.version"
|
|
|
|
rmdir "${prefix}" 2> /dev/null
|
|
|
|
fi
|
2018-02-22 15:53:29 -05:00
|
|
|
|
|
|
|
xz -6 "${OUTPUT_DIR}/${tarball_name}"
|
2017-01-28 16:11:05 -05:00
|
|
|
fi
|
2018-02-17 11:46:19 -05:00
|
|
|
|
2018-02-24 17:20:53 -05:00
|
|
|
if ! ${BUILD_SNAPSHOT} && [ -e "${OUTPUT_DIR}/build-release" ]; then
|
2018-02-17 11:46:19 -05:00
|
|
|
logInfo "Cleaning existing build directory..."
|
|
|
|
rm -r "${OUTPUT_DIR}/build-release" 2> /dev/null
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
exitError "Failed to clean existing build directory, please do it manually."
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2017-01-28 16:11:05 -05:00
|
|
|
logInfo "Creating build directory..."
|
|
|
|
mkdir -p "${OUTPUT_DIR}/build-release"
|
|
|
|
cd "${OUTPUT_DIR}/build-release"
|
|
|
|
|
|
|
|
logInfo "Configuring sources..."
|
2018-02-17 11:46:19 -05:00
|
|
|
for p in ${BUILD_PLUGINS}; do
|
2017-01-28 16:11:05 -05:00
|
|
|
CMAKE_OPTIONS="${CMAKE_OPTIONS} -DWITH_XC_$(echo $p | tr '[:lower:]' '[:upper:]')=On"
|
|
|
|
done
|
|
|
|
|
|
|
|
if [ "$COMPILER" == "g++" ]; then
|
|
|
|
export CC=gcc
|
|
|
|
elif [ "$COMPILER" == "clang++" ]; then
|
|
|
|
export CC=clang
|
|
|
|
fi
|
|
|
|
export CXX="$COMPILER"
|
|
|
|
|
|
|
|
if [ "" == "$DOCKER_IMAGE" ]; then
|
2017-01-29 14:46:57 -05:00
|
|
|
if [ "$(uname -s)" == "Darwin" ]; then
|
2018-02-21 15:35:17 -05:00
|
|
|
# Building on macOS
|
|
|
|
local qt_vers="$(ls /usr/local/Cellar/qt 2> /dev/null | sort -r | head -n1)"
|
2017-01-29 14:46:57 -05:00
|
|
|
if [ "" == "$qt_vers" ]; then
|
2018-02-21 15:35:17 -05:00
|
|
|
exitError "Couldn't find Qt5! Please make sure it is available in '/usr/local/Cellar/qt'."
|
2017-01-29 14:46:57 -05:00
|
|
|
fi
|
2018-02-21 15:35:17 -05:00
|
|
|
|
|
|
|
export MACOSX_DEPLOYMENT_TARGET=10.10
|
|
|
|
|
2017-01-29 14:46:57 -05:00
|
|
|
logInfo "Configuring build..."
|
2018-02-21 15:35:17 -05:00
|
|
|
cmake -DCMAKE_BUILD_TYPE=Release \
|
|
|
|
-DCMAKE_OSX_ARCHITECTURES=x86_64 -DCMAKE_INSTALL_PREFIX="${INSTALL_PREFIX}" \
|
|
|
|
-DCMAKE_PREFIX_PATH="/usr/local/Cellar/qt/${qt_vers}/lib/cmake" \
|
|
|
|
${CMAKE_OPTIONS} "$SRC_DIR"
|
|
|
|
|
2017-01-29 14:46:57 -05:00
|
|
|
logInfo "Compiling and packaging sources..."
|
2018-02-21 15:35:17 -05:00
|
|
|
make ${MAKE_OPTIONS} package
|
2017-01-29 14:46:57 -05:00
|
|
|
|
|
|
|
mv "./${APP_NAME}-${RELEASE_NAME}.dmg" ../
|
|
|
|
elif [ "$(uname -o)" == "Msys" ]; then
|
2018-02-21 15:35:17 -05:00
|
|
|
# Building on Windows with Msys2
|
2017-01-28 16:19:23 -05:00
|
|
|
logInfo "Configuring build..."
|
|
|
|
cmake -DCMAKE_BUILD_TYPE=Release -DWITH_TESTS=Off -G"MSYS Makefiles" \
|
|
|
|
-DCMAKE_INSTALL_PREFIX="${INSTALL_PREFIX}" $CMAKE_OPTIONS "$SRC_DIR"
|
|
|
|
|
2017-01-28 16:45:07 -05:00
|
|
|
logInfo "Compiling and packaging sources..."
|
2018-02-21 15:35:17 -05:00
|
|
|
mingw32-make ${MAKE_OPTIONS} preinstall
|
2017-12-09 09:02:57 -05:00
|
|
|
# Call cpack directly instead of calling make package.
|
|
|
|
# This is important because we want to build the MSI when making a
|
|
|
|
# release.
|
2018-02-17 11:46:19 -05:00
|
|
|
cpack -G "NSIS;ZIP;${CPACK_GENERATORS}"
|
2017-01-28 16:19:23 -05:00
|
|
|
|
2018-02-21 21:27:19 -05:00
|
|
|
mv "./${APP_NAME}-"*.* ../
|
2017-01-29 14:46:57 -05:00
|
|
|
else
|
2017-01-29 14:58:09 -05:00
|
|
|
mkdir -p "${OUTPUT_DIR}/bin-release"
|
|
|
|
|
2017-01-29 14:46:57 -05:00
|
|
|
# Building on Linux without Docker container
|
2017-01-28 16:19:23 -05:00
|
|
|
logInfo "Configuring build..."
|
|
|
|
cmake -DCMAKE_BUILD_TYPE=Release -DWITH_TESTS=Off $CMAKE_OPTIONS \
|
2017-10-16 11:51:16 -04:00
|
|
|
-DCMAKE_INSTALL_PREFIX="${INSTALL_PREFIX}" \
|
|
|
|
-DKEEPASSXC_DIST_TYPE=AppImage "$SRC_DIR"
|
2017-01-28 16:19:23 -05:00
|
|
|
|
|
|
|
logInfo "Compiling sources..."
|
|
|
|
make $MAKE_OPTIONS
|
|
|
|
|
2017-01-28 16:11:05 -05:00
|
|
|
logInfo "Installing to bin dir..."
|
|
|
|
make DESTDIR="${OUTPUT_DIR}/bin-release" install/strip
|
|
|
|
|
|
|
|
logInfo "Creating AppImage..."
|
|
|
|
${SRC_DIR}/AppImage-Recipe.sh "$APP_NAME" "$RELEASE_NAME"
|
|
|
|
fi
|
|
|
|
else
|
2017-01-29 14:58:09 -05:00
|
|
|
mkdir -p "${OUTPUT_DIR}/bin-release"
|
|
|
|
|
2017-01-28 16:11:05 -05:00
|
|
|
logInfo "Launching Docker container to compile sources..."
|
|
|
|
|
|
|
|
docker run --name "$DOCKER_CONTAINER_NAME" --rm \
|
2017-10-07 18:30:33 -04:00
|
|
|
--cap-add SYS_ADMIN --security-opt apparmor:unconfined --device /dev/fuse \
|
2017-01-28 16:11:05 -05:00
|
|
|
-e "CC=${CC}" -e "CXX=${CXX}" \
|
|
|
|
-v "$(realpath "$SRC_DIR"):/keepassxc/src:ro" \
|
|
|
|
-v "$(realpath "$OUTPUT_DIR"):/keepassxc/out:rw" \
|
|
|
|
"$DOCKER_IMAGE" \
|
|
|
|
bash -c "cd /keepassxc/out/build-release && \
|
|
|
|
cmake -DCMAKE_BUILD_TYPE=Release -DWITH_TESTS=Off $CMAKE_OPTIONS \
|
2017-12-21 13:12:51 -05:00
|
|
|
-DCMAKE_INSTALL_PREFIX=\"${INSTALL_PREFIX}\" \
|
|
|
|
-DKEEPASSXC_DIST_TYPE=AppImage /keepassxc/src && \
|
2017-01-28 16:11:05 -05:00
|
|
|
make $MAKE_OPTIONS && make DESTDIR=/keepassxc/out/bin-release install/strip && \
|
2017-01-28 17:24:12 -05:00
|
|
|
/keepassxc/src/AppImage-Recipe.sh "$APP_NAME" "$RELEASE_NAME""
|
2017-01-28 16:11:05 -05:00
|
|
|
|
|
|
|
if [ 0 -ne $? ]; then
|
|
|
|
exitError "Docker build failed!"
|
|
|
|
fi
|
|
|
|
|
|
|
|
logInfo "Build finished, Docker container terminated."
|
|
|
|
fi
|
|
|
|
|
|
|
|
cleanup
|
|
|
|
|
|
|
|
logInfo "All done!"
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# -----------------------------------------------------------------------
|
2017-12-13 16:38:44 -05:00
|
|
|
# gpgsign command
|
2017-01-28 16:11:05 -05:00
|
|
|
# -----------------------------------------------------------------------
|
2017-12-13 16:38:44 -05:00
|
|
|
gpgsign() {
|
|
|
|
local sign_files=()
|
|
|
|
|
2017-01-28 16:11:05 -05:00
|
|
|
while [ $# -ge 1 ]; do
|
|
|
|
local arg="$1"
|
|
|
|
case "$arg" in
|
|
|
|
-f|--files)
|
|
|
|
while [ "${2:0:1}" != "-" ] && [ $# -ge 2 ]; do
|
2017-12-13 16:38:44 -05:00
|
|
|
sign_files+=("$2")
|
2017-01-28 16:11:05 -05:00
|
|
|
shift
|
|
|
|
done ;;
|
2017-12-13 16:38:44 -05:00
|
|
|
|
2017-01-28 16:11:05 -05:00
|
|
|
-g|--gpg-key)
|
|
|
|
GPG_KEY="$2"
|
|
|
|
shift ;;
|
2017-10-05 18:04:41 -04:00
|
|
|
|
2017-01-28 16:11:05 -05:00
|
|
|
-h|--help)
|
2017-12-13 16:38:44 -05:00
|
|
|
printUsage "gpgsign"
|
2017-01-28 16:11:05 -05:00
|
|
|
exit ;;
|
2017-12-13 16:38:44 -05:00
|
|
|
|
2017-01-28 16:11:05 -05:00
|
|
|
*)
|
|
|
|
logError "Unknown option '$arg'\n"
|
2017-12-13 16:38:44 -05:00
|
|
|
printUsage "gpgsign"
|
2017-01-28 16:11:05 -05:00
|
|
|
exit 1 ;;
|
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
|
2017-12-13 16:38:44 -05:00
|
|
|
if [ -z "${sign_files}" ]; then
|
2017-01-28 16:11:05 -05:00
|
|
|
logError "Missing arguments, --files is required!\n"
|
2017-12-13 16:38:44 -05:00
|
|
|
printUsage "gpgsign"
|
2017-01-28 16:11:05 -05:00
|
|
|
exit 1
|
|
|
|
fi
|
2017-10-05 18:04:41 -04:00
|
|
|
|
2017-12-13 16:38:44 -05:00
|
|
|
for f in "${sign_files[@]}"; do
|
2017-01-28 16:11:05 -05:00
|
|
|
if [ ! -f "$f" ]; then
|
2017-12-13 16:38:44 -05:00
|
|
|
exitError "File '${f}' does not exist or is not a file!"
|
2017-01-28 16:11:05 -05:00
|
|
|
fi
|
2017-10-05 18:04:41 -04:00
|
|
|
|
|
|
|
logInfo "Signing file '${f}' using release key..."
|
2017-01-28 16:11:05 -05:00
|
|
|
gpg --output "${f}.sig" --armor --local-user "$GPG_KEY" --detach-sig "$f"
|
|
|
|
|
|
|
|
if [ 0 -ne $? ]; then
|
|
|
|
exitError "Signing failed!"
|
|
|
|
fi
|
2017-12-13 16:38:44 -05:00
|
|
|
|
2017-01-28 16:11:05 -05:00
|
|
|
logInfo "Creating digest for file '${f}'..."
|
2017-02-17 11:21:27 -05:00
|
|
|
local rp="$(realpath "$f")"
|
|
|
|
local bname="$(basename "$f")"
|
|
|
|
(cd "$(dirname "$rp")"; sha256sum "$bname" > "${bname}.DIGEST")
|
2017-01-28 16:11:05 -05:00
|
|
|
done
|
|
|
|
|
|
|
|
logInfo "All done!"
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-13 16:38:44 -05:00
|
|
|
|
|
|
|
# -----------------------------------------------------------------------
|
|
|
|
# appsign command
|
|
|
|
# -----------------------------------------------------------------------
|
|
|
|
appsign() {
|
|
|
|
local sign_files=()
|
|
|
|
local signtool_key
|
|
|
|
local codesign_identity
|
|
|
|
|
|
|
|
while [ $# -ge 1 ]; do
|
|
|
|
local arg="$1"
|
|
|
|
case "$arg" in
|
|
|
|
-f|--files)
|
|
|
|
while [ "${2:0:1}" != "-" ] && [ $# -ge 2 ]; do
|
|
|
|
sign_files+=("$2")
|
|
|
|
shift
|
|
|
|
done ;;
|
|
|
|
|
|
|
|
-k|--signtool-key)
|
|
|
|
signtool_key="$2"
|
|
|
|
shift ;;
|
|
|
|
|
|
|
|
-i|--identity)
|
|
|
|
codesign_identity="$2"
|
|
|
|
shift ;;
|
|
|
|
|
|
|
|
-h|--help)
|
|
|
|
printUsage "appsign"
|
|
|
|
exit ;;
|
|
|
|
|
|
|
|
*)
|
|
|
|
logError "Unknown option '$arg'\n"
|
|
|
|
printUsage "appsign"
|
|
|
|
exit 1 ;;
|
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
|
|
|
|
if [ -z "${sign_files}" ]; then
|
|
|
|
logError "Missing arguments, --files is required!\n"
|
|
|
|
printUsage "appsign"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
for f in "${sign_files[@]}"; do
|
|
|
|
if [ ! -f "${f}" ]; then
|
|
|
|
exitError "File '${f}' does not exist or is not a file!"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
if [ "$(uname -s)" == "Darwin" ]; then
|
|
|
|
if [ -z "${codesign_identity}" ]; then
|
|
|
|
logError "Missing arguments, --identity is required on macOS!\n"
|
|
|
|
printUsage "appsign"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
checkCodesignCommandExists
|
|
|
|
|
|
|
|
local orig_dir="$(pwd)"
|
|
|
|
for f in "${sign_files[@]}"; do
|
|
|
|
if [[ ${f: -4} == '.dmg' ]]; then
|
|
|
|
logInfo "Unpacking disk image '${f}'..."
|
|
|
|
local tmp_dir="/tmp/KeePassXC_${RANDOM}"
|
2018-01-13 16:10:26 -05:00
|
|
|
mkdir -p ${tmp_dir}/mnt
|
2017-12-13 16:38:44 -05:00
|
|
|
hdiutil attach -quiet -noautoopen -mountpoint ${tmp_dir}/mnt "${f}"
|
|
|
|
cd ${tmp_dir}
|
2018-01-13 16:10:26 -05:00
|
|
|
cp -a ./mnt ./app
|
2017-12-13 16:38:44 -05:00
|
|
|
hdiutil detach -quiet ${tmp_dir}/mnt
|
|
|
|
|
|
|
|
if [ ! -d ./app/KeePassXC.app ]; then
|
|
|
|
cd "${orig_dir}"
|
|
|
|
exitError "Unpacking failed!"
|
|
|
|
fi
|
|
|
|
|
|
|
|
logInfo "Signing app using codesign..."
|
|
|
|
codesign --sign "${codesign_identity}" --verbose --deep ./app/KeePassXC.app
|
|
|
|
|
|
|
|
if [ 0 -ne $? ]; then
|
|
|
|
cd "${orig_dir}"
|
|
|
|
exitError "Signing failed!"
|
|
|
|
fi
|
|
|
|
|
2018-01-13 16:10:26 -05:00
|
|
|
logInfo "Repacking disk image..."
|
|
|
|
hdiutil create \
|
|
|
|
-volname "KeePassXC" \
|
|
|
|
-size $((1000 * ($(du -sk ./app | cut -f1) + 5000))) \
|
|
|
|
-srcfolder ./app \
|
|
|
|
-fs HFS+ \
|
|
|
|
-fsargs "-c c=64,a=16,e=16" \
|
|
|
|
-format UDBZ \
|
|
|
|
"${tmp_dir}/$(basename "${f}")"
|
2017-12-13 16:38:44 -05:00
|
|
|
cd "${orig_dir}"
|
2018-01-13 16:10:26 -05:00
|
|
|
cp -f "${tmp_dir}/$(basename "${f}")" "${f}"
|
2017-12-13 16:38:44 -05:00
|
|
|
rm -Rf ${tmp_dir}
|
|
|
|
else
|
|
|
|
logInfo "Skipping non-DMG file '${f}'..."
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
elif [ "$(uname -o)" == "Msys" ]; then
|
|
|
|
if [ -z "${signtool_key}" ]; then
|
|
|
|
logError "Missing arguments, --signtool-key is required on Windows!\n"
|
|
|
|
printUsage "appsign"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2017-12-14 12:17:43 -05:00
|
|
|
checkOsslsigncodeCommandExists
|
2017-12-13 16:38:44 -05:00
|
|
|
|
|
|
|
if [[ ! -f "${signtool_key}" ]]; then
|
|
|
|
exitError "Key file was not found!"
|
|
|
|
fi
|
|
|
|
|
|
|
|
read -s -p "Key password: " password
|
|
|
|
echo
|
|
|
|
|
|
|
|
for f in "${sign_files[@]}"; do
|
2017-11-27 22:46:03 -05:00
|
|
|
if [[ ${f: -4} == ".exe" ]]; then
|
2017-12-14 12:17:43 -05:00
|
|
|
logInfo "Signing file '${f}' using osslsigncode..."
|
|
|
|
# output a signed exe; we have to use a different name due to osslsigntool limitations
|
2017-11-27 22:46:03 -05:00
|
|
|
osslsigncode sign -pkcs12 "${signtool_key}" -pass "${password}" -n "KeePassXC" \
|
2017-12-14 12:17:43 -05:00
|
|
|
-t "http://timestamp.comodoca.com/authenticode" -in "${f}" -out "${f}.signed"
|
2017-12-13 16:38:44 -05:00
|
|
|
|
|
|
|
if [ 0 -ne $? ]; then
|
2017-12-14 12:17:43 -05:00
|
|
|
rm -f "${f}.signed"
|
2017-12-13 16:38:44 -05:00
|
|
|
exitError "Signing failed!"
|
|
|
|
fi
|
2017-12-14 12:17:43 -05:00
|
|
|
|
|
|
|
# overwrite the original exe with the signed exe
|
|
|
|
mv -f "${f}.signed" "${f}"
|
2017-11-27 22:46:03 -05:00
|
|
|
elif [[ ${f: -4} == ".msi" ]]; then
|
|
|
|
# Make sure we can find the signtool
|
|
|
|
checkSigntoolCommandExists
|
|
|
|
|
|
|
|
# osslsigncode does not succeed at signing MSI files at this time...
|
|
|
|
logInfo "Signing file '${f}' using Microsoft signtool..."
|
|
|
|
signtool sign -f "${signtool_key}" -p "${password}" -d "KeePassXC" \
|
|
|
|
-t "http://timestamp.comodoca.com/authenticode" "${f}"
|
|
|
|
|
|
|
|
if [ 0 -ne $? ]; then
|
|
|
|
exitError "Signing failed!"
|
|
|
|
fi
|
2017-12-13 16:38:44 -05:00
|
|
|
else
|
2017-11-27 22:46:03 -05:00
|
|
|
logInfo "Skipping non-executable file '${f}'..."
|
2017-12-13 16:38:44 -05:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
else
|
|
|
|
exitError "Unsupported platform for code signing!\n"
|
|
|
|
fi
|
|
|
|
|
|
|
|
logInfo "All done!"
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-01-28 16:11:05 -05:00
|
|
|
# -----------------------------------------------------------------------
|
|
|
|
# parse global command line
|
|
|
|
# -----------------------------------------------------------------------
|
|
|
|
MODE="$1"
|
|
|
|
shift
|
|
|
|
if [ "" == "$MODE" ]; then
|
|
|
|
logError "Missing arguments!\n"
|
|
|
|
printUsage
|
|
|
|
exit 1
|
|
|
|
elif [ "help" == "$MODE" ]; then
|
|
|
|
printUsage "$1"
|
|
|
|
exit
|
2017-12-13 16:38:44 -05:00
|
|
|
elif [ "check" == "$MODE" ] || [ "merge" == "$MODE" ] || [ "build" == "$MODE" ] || [ "gpgsign" == "$MODE" ] || [ "appsign" == "$MODE" ]; then
|
|
|
|
${MODE} "$@"
|
2017-01-28 17:17:48 -05:00
|
|
|
else
|
|
|
|
printUsage "$MODE"
|
2017-01-28 16:11:05 -05:00
|
|
|
fi
|