From b8ffd24cce92e01b8a60e168de41e566554334b1 Mon Sep 17 00:00:00 2001 From: Andrew Scheller Date: Tue, 29 Nov 2016 23:37:31 +0000 Subject: [PATCH] chore: refactor and enhance dependency checking in build scripts (#908) This refactors the way that the build shell-scripts check for dependencies in order to cut down on code duplication, and also adds additional dependency-checks that were missing previously. Change-Type: minor --- scripts/build/darwin.sh | 7 +++++++ scripts/build/linux.sh | 9 +++++++++ scripts/darwin/installer-dmg.sh | 16 ++++++++++++---- scripts/darwin/installer-zip.sh | 9 +++++++++ scripts/darwin/package.sh | 9 +++++++++ scripts/darwin/sign.sh | 10 ++++++++++ scripts/linux/installer-appimage.sh | 18 +++++++++--------- scripts/linux/installer-deb.sh | 12 ++++++++---- scripts/linux/package.sh | 7 +++++++ scripts/publish/aws-s3.sh | 14 +++++++++----- scripts/publish/bintray-debian.sh | 27 +++++++++++++++++++++++++++ scripts/unix/create-asar.sh | 12 ++++++++---- scripts/unix/dependencies.sh | 22 +++++++++------------- scripts/unix/download-electron.sh | 13 +++++++++---- scripts/unix/package-cli.sh | 22 +++++++++------------- 15 files changed, 151 insertions(+), 56 deletions(-) diff --git a/scripts/build/darwin.sh b/scripts/build/darwin.sh index 1d56ff0b..a0568727 100755 --- a/scripts/build/darwin.sh +++ b/scripts/build/darwin.sh @@ -21,6 +21,13 @@ set -u set -e set -x +function check_dep() { + if ! command -v $1 2>/dev/null 1>&2; then + echo "Dependency missing: $1" 1>&2 + exit 1 + fi +} + OS=`uname` if [[ "$OS" != "Darwin" ]]; then echo "This script is only meant to be run in OS X" 1>&2 diff --git a/scripts/build/linux.sh b/scripts/build/linux.sh index d73290bb..6c450aae 100755 --- a/scripts/build/linux.sh +++ b/scripts/build/linux.sh @@ -21,6 +21,13 @@ set -u set -e set -x +function check_dep() { + if ! command -v $1 2>/dev/null 1>&2; then + echo "Dependency missing: $1" 1>&2 + exit 1 + fi +} + OS=`uname` if [[ "$OS" != "Linux" ]]; then echo "This script is only meant to be run in GNU/Linux" 1>&2 @@ -103,6 +110,8 @@ if [ "$COMMAND" == "installer-debian" ]; then fi if [ "$COMMAND" == "installer-appimage" ]; then + check_dep zip + ./scripts/unix/dependencies.sh -p \ -r "$ARCH" \ -v "$ELECTRON_VERSION" \ diff --git a/scripts/darwin/installer-dmg.sh b/scripts/darwin/installer-dmg.sh index ced6dd60..a3d50614 100755 --- a/scripts/darwin/installer-dmg.sh +++ b/scripts/darwin/installer-dmg.sh @@ -19,16 +19,24 @@ set -u set -e +function check_dep() { + if ! command -v $1 2>/dev/null 1>&2; then + echo "Dependency missing: $1" 1>&2 + exit 1 + fi +} + OS=$(uname) if [[ "$OS" != "Darwin" ]]; then echo "This script is only meant to be run in OS X" 1>&2 exit 1 fi -if ! command -v afsctool 2>/dev/null 1>&2; then - echo "Dependency missing: afsctool" 1>&2 - exit 1 -fi +check_dep hdiutil +check_dep xattr +check_dep tiffutil +check_dep osascript +check_dep afsctool function usage() { echo "Usage: $0" diff --git a/scripts/darwin/installer-zip.sh b/scripts/darwin/installer-zip.sh index 0808f4b5..74a17e55 100755 --- a/scripts/darwin/installer-zip.sh +++ b/scripts/darwin/installer-zip.sh @@ -19,6 +19,15 @@ set -u set -e +function check_dep() { + if ! command -v $1 2>/dev/null 1>&2; then + echo "Dependency missing: $1" 1>&2 + exit 1 + fi +} + +check_dep zip + OS=$(uname) if [[ "$OS" != "Darwin" ]]; then echo "This script is only meant to be run in OS X" 1>&2 diff --git a/scripts/darwin/package.sh b/scripts/darwin/package.sh index 852e48a2..64a6f289 100755 --- a/scripts/darwin/package.sh +++ b/scripts/darwin/package.sh @@ -19,12 +19,21 @@ set -u set -e +function check_dep() { + if ! command -v $1 2>/dev/null 1>&2; then + echo "Dependency missing: $1" 1>&2 + exit 1 + fi +} + OS=$(uname) if [[ "$OS" != "Darwin" ]]; then echo "This script is only meant to be run in OS X" 1>&2 exit 1 fi +check_dep /usr/libexec/PlistBuddy + function usage() { echo "Usage: $0" echo "" diff --git a/scripts/darwin/sign.sh b/scripts/darwin/sign.sh index e1bfcfd8..874bdf38 100755 --- a/scripts/darwin/sign.sh +++ b/scripts/darwin/sign.sh @@ -19,12 +19,22 @@ set -u set -e +function check_dep() { + if ! command -v $1 2>/dev/null 1>&2; then + echo "Dependency missing: $1" 1>&2 + exit 1 + fi +} + OS=$(uname) if [[ "$OS" != "Darwin" ]]; then echo "This script is only meant to be run in OS X" 1>&2 exit 1 fi +check_dep codesign +check_dep spctl + function usage() { echo "Usage: $0" echo "" diff --git a/scripts/linux/installer-appimage.sh b/scripts/linux/installer-appimage.sh index 33eebcaa..a18ab59b 100755 --- a/scripts/linux/installer-appimage.sh +++ b/scripts/linux/installer-appimage.sh @@ -19,21 +19,21 @@ set -u set -e +function check_dep() { + if ! command -v $1 2>/dev/null 1>&2; then + echo "Dependency missing: $1" 1>&2 + exit 1 + fi +} + OS=$(uname) if [[ "$OS" != "Linux" ]]; then echo "This script is only meant to be run in GNU/Linux" 1>&2 exit 1 fi -if ! command -v upx 2>/dev/null 1>&2; then - echo "Dependency missing: upx" 1>&2 - exit 1 -fi - -if ! command -v wget 2>/dev/null 1>&2; then - echo "Dependency missing: wget" 1>&2 - exit 1 -fi +check_dep upx +check_dep wget function usage() { echo "Usage: $0" diff --git a/scripts/linux/installer-deb.sh b/scripts/linux/installer-deb.sh index 9e4aff9e..27512883 100755 --- a/scripts/linux/installer-deb.sh +++ b/scripts/linux/installer-deb.sh @@ -19,16 +19,20 @@ set -u set -e +function check_dep() { + if ! command -v $1 2>/dev/null 1>&2; then + echo "Dependency missing: $1" 1>&2 + exit 1 + fi +} + OS=$(uname) if [[ "$OS" != "Linux" ]]; then echo "This script is only meant to be run in GNU/Linux" 1>&2 exit 1 fi -if ! command -v electron-installer-debian 2>/dev/null 1>&2; then - echo "Dependency missing: electron-installer-debian" 1>&2 - exit 1 -fi +check_dep electron-installer-debian function usage() { echo "Usage: $0" diff --git a/scripts/linux/package.sh b/scripts/linux/package.sh index 0cce786a..aa695339 100755 --- a/scripts/linux/package.sh +++ b/scripts/linux/package.sh @@ -19,6 +19,13 @@ set -u set -e +function check_dep() { + if ! command -v $1 2>/dev/null 1>&2; then + echo "Dependency missing: $1" 1>&2 + exit 1 + fi +} + OS=$(uname) if [[ "$OS" != "Linux" ]]; then echo "This script is only meant to be run in GNU/Linux" 1>&2 diff --git a/scripts/publish/aws-s3.sh b/scripts/publish/aws-s3.sh index b81a2ad6..ebbb6c80 100755 --- a/scripts/publish/aws-s3.sh +++ b/scripts/publish/aws-s3.sh @@ -20,16 +20,20 @@ set -u set -e +function check_dep() { + if ! command -v $1 2>/dev/null 1>&2; then + echo "Dependency missing: $1" 1>&2 + exit 1 + fi +} + +check_dep aws + if [ "$#" -ne 1 ]; then echo "Usage: $0 " 1>&2 exit 1 fi -if ! command -v aws 1>/dev/null 2>/dev/null; then - echo "Dependency missing: aws cli" 1>&2 - exit 1 -fi - ETCHER_VERSION=`node -e "console.log(require('./package.json').version)"` S3_BUCKET="resin-production-downloads" diff --git a/scripts/publish/bintray-debian.sh b/scripts/publish/bintray-debian.sh index 4374da8c..cc262348 100755 --- a/scripts/publish/bintray-debian.sh +++ b/scripts/publish/bintray-debian.sh @@ -1,7 +1,34 @@ #!/bin/bash + +### +# Copyright 2016 resin.io +# +# 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 -u set -e +function check_dep() { + if ! command -v $1 2>/dev/null 1>&2; then + echo "Dependency missing: $1" 1>&2 + exit 1 + fi +} + +check_dep curl + if [ "$#" -ne 1 ]; then echo "Usage: $0 " 1>&2 exit 1 diff --git a/scripts/unix/create-asar.sh b/scripts/unix/create-asar.sh index 0ff7d394..28688454 100755 --- a/scripts/unix/create-asar.sh +++ b/scripts/unix/create-asar.sh @@ -19,10 +19,14 @@ set -u set -e -if ! command -v asar 2>/dev/null 1>&2; then - echo "Dependency missing: asar" 1>&2 - exit 1 -fi +function check_dep() { + if ! command -v $1 2>/dev/null 1>&2; then + echo "Dependency missing: $1" 1>&2 + exit 1 + fi +} + +check_dep asar function usage() { echo "Usage: $0" diff --git a/scripts/unix/dependencies.sh b/scripts/unix/dependencies.sh index e3d2cbda..51b761f9 100755 --- a/scripts/unix/dependencies.sh +++ b/scripts/unix/dependencies.sh @@ -19,20 +19,16 @@ set -u set -e -if ! command -v npm 2>/dev/null 1>&2; then - echo "Dependency missing: npm" 1>&2 - exit 1 -fi +function check_dep() { + if ! command -v $1 2>/dev/null 1>&2; then + echo "Dependency missing: $1" 1>&2 + exit 1 + fi +} -if ! command -v bower 2>/dev/null 1>&2; then - echo "Dependency missing: bower" 1>&2 - exit 1 -fi - -if ! command -v python 2>/dev/null 1>&2; then - echo "Dependency missing: python" 1>&2 - exit 1 -fi +check_dep npm +check_dep bower +check_dep python function usage() { echo "Usage: $0" diff --git a/scripts/unix/download-electron.sh b/scripts/unix/download-electron.sh index be4677c0..baaa9016 100755 --- a/scripts/unix/download-electron.sh +++ b/scripts/unix/download-electron.sh @@ -19,10 +19,15 @@ set -u set -e -if ! command -v wget 2>/dev/null 1>&2; then - echo "Dependency missing: wget" 1>&2 - exit 1 -fi +function check_dep() { + if ! command -v $1 2>/dev/null 1>&2; then + echo "Dependency missing: $1" 1>&2 + exit 1 + fi +} + +check_dep wget +check_dep unzip function usage() { echo "Usage: $0" diff --git a/scripts/unix/package-cli.sh b/scripts/unix/package-cli.sh index ec5702c6..9a168cde 100755 --- a/scripts/unix/package-cli.sh +++ b/scripts/unix/package-cli.sh @@ -19,20 +19,16 @@ set -u set -e -if ! command -v browserify 2>/dev/null 1>&2; then - echo "Dependency missing: browserify" 1>&2 - exit 1 -fi +function check_dep() { + if ! command -v $1 2>/dev/null 1>&2; then + echo "Dependency missing: $1" 1>&2 + exit 1 + fi +} -if ! command -v wget 2>/dev/null 1>&2; then - echo "Dependency missing: wget" 1>&2 - exit 1 -fi - -if ! command -v rsync 2>/dev/null 1>&2; then - echo "Dependency missing: rsync" 1>&2 - exit 1 -fi +check_dep browserify +check_dep wget +check_dep rsync function usage() { echo "Usage: $0"