diff --git a/scripts/build/AppImages/AppImageAssistant-x64 b/scripts/build/AppImages/AppImageAssistant-x64 deleted file mode 100755 index dc85eeee..00000000 Binary files a/scripts/build/AppImages/AppImageAssistant-x64 and /dev/null differ diff --git a/scripts/build/AppImages/AppImageAssistant-x86 b/scripts/build/AppImages/AppImageAssistant-x86 deleted file mode 100755 index 52bddcea..00000000 Binary files a/scripts/build/AppImages/AppImageAssistant-x86 and /dev/null differ diff --git a/scripts/build/AppImages/AppRun-x64 b/scripts/build/AppImages/AppRun-x64 deleted file mode 100755 index a81b6bf9..00000000 Binary files a/scripts/build/AppImages/AppRun-x64 and /dev/null differ diff --git a/scripts/build/AppImages/AppRun-x86 b/scripts/build/AppImages/AppRun-x86 deleted file mode 100755 index 1f2159e4..00000000 Binary files a/scripts/build/AppImages/AppRun-x86 and /dev/null differ diff --git a/scripts/build/AppImages/Etcher.desktop b/scripts/build/AppImages/Etcher.desktop deleted file mode 100644 index 31970063..00000000 --- a/scripts/build/AppImages/Etcher.desktop +++ /dev/null @@ -1,6 +0,0 @@ -[Desktop Entry] -Name=Etcher -Exec=etcher.wrapper -Comment=Burn images to SD cards & USB drives, safe & easy -Icon=icon -Type=Application diff --git a/scripts/build/AppImages/desktopintegration b/scripts/build/AppImages/desktopintegration deleted file mode 100755 index 3a7f6455..00000000 --- a/scripts/build/AppImages/desktopintegration +++ /dev/null @@ -1,267 +0,0 @@ -#!/bin/bash - -# The purpose of this script is to provide lightweight desktop integration -# into the host system without special help from the host system. -# If you want to use it, then place this in usr/bin/$APPNAME.wrapper -# and set it as the Exec= line of the .desktop file in the AppImage. -# -# For example, to install the appropriate icons for Scribus, -# put them into the AppDir at the following locations: -# -# ./usr/share/icons/default/128x128/apps/scribus.png -# ./usr/share/icons/default/128x128/mimetypes/application-vnd.scribus.png -# -# Note that the filename application-vnd.scribus.png is derived from -# and must be match MimeType=application/vnd.scribus; in scribus.desktop -# (with "/" characters replaced by "-"). -# -# Then, change Exec=scribus to Exec=scribus.wrapper and place the script -# below in usr/bin/scribus.wrapper and make it executable. -# When you run AppRun, then AppRun runs the wrapper script below -# which in turn will run the main application. -# -# TODO: -# Handle multiple versions of the same AppImage? -# Handle removed AppImages? Currently we are just setting TryExec= -# See http://specifications.freedesktop.org/thumbnail-spec/thumbnail-spec-latest.html#DELETE -# Possibly move this to the C runtime that is part of every AppImage? - -# Exit on errors -set -e - -# Be verbose if $DEBUG=1 is set -if [ ! -z "$DEBUG" ] ; then - env - set -x -fi - -THIS="$0" -args=("$@") # http://stackoverflow.com/questions/3190818/ -NUMBER_OF_ARGS="$#" - -# Please do not change $VENDORPREFIX as it will allow for desktop files -# belonging to AppImages to be recognized by future AppImageKit components -# such as desktop integration daemons -VENDORPREFIX=appimagekit - -find-up () { - path="$(dirname "$(readlink -f "${THIS}")")" - while [[ "$path" != "" && ! -e "$path/$1" ]]; do - path=${path%/*} - done - # echo "$path" -} - -if [ -z $APPDIR ] ; then - # Find the AppDir. It is the directory that contains AppRun. - # This assumes that this script resides inside the AppDir or a subdirectory. - # If this script is run inside an AppImage, then the AppImage runtime - # likely has already set $APPDIR - APPDIR=$(find-up "AppRun") -fi - -# echo "$APPDIR" - -FILENAME="$(readlink -f "${THIS}")" - -# echo "$FILENAME" - -if [[ "$FILENAME" != *.wrapper ]] ; then - echo "${THIS} is not named correctly. It should be named \$Exec.wrapper" - exit 0 -fi - -BIN=$(echo "$FILENAME" | sed -e 's|.wrapper||g') -if [[ ! -f "$BIN" ]] ; then - echo "$BIN not found" - exit 0 -fi - -trap atexit EXIT - -# Note that the following handles 0, 1 or more arguments (file paths) -# which can include blanks but uses a bashism; can the same be achieved -# in POSIX-shell? (FIXME) -# http://stackoverflow.com/questions/3190818 -atexit() -{ -if [ $NUMBER_OF_ARGS -eq 0 ] ; then - exec "${BIN}" -else - exec "${BIN}" "${args[@]}" -fi -} - -error() -{ - if [ -x /usr/bin/zenity ] ; then - LD_LIBRARY_PATH="" zenity --error --text "${1}" 2>/dev/null - elif [ -x /usr/bin/kdialog ] ; then - LD_LIBRARY_PATH="" kdialog --msgbox "${1}" 2>/dev/null - elif [ -x /usr/bin/Xdialog ] ; then - LD_LIBRARY_PATH="" Xdialog --msgbox "${1}" 2>/dev/null - else - echo "${1}" - fi - exit 1 -} - -yesno() -{ - TITLE=$1 - TEXT=$2 - if [ -x /usr/bin/zenity ] ; then - LD_LIBRARY_PATH="" zenity --question --title="$TITLE" --text="$TEXT" 2>/dev/null || exit 0 - elif [ -x /usr/bin/kdialog ] ; then - LD_LIBRARY_PATH="" kdialog --caption "Disk auswerfen?" --title "$TITLE" -yesno "$TEXT" || exit 0 - elif [ -x /usr/bin/Xdialog ] ; then - LD_LIBRARY_PATH="" Xdialog --title "$TITLE" --clear --yesno "$TEXT" 10 80 || exit 0 - else - echo "zenity, kdialog, Xdialog missing. Skipping ${THIS}." - exit 0 - fi -} - -check_prevent() -{ - FILE=$1 - if [ -e "$FILE" ] ; then - exit 0 - fi -} - -# Exit immediately of one of these files is present -# (e.g., because the desktop environment wants to handle desktop integration itself) -check_prevent "$HOME/.local/share/$VENDORPREFIX/no_desktopintegration" -check_prevent "/usr/share/$VENDORPREFIX/no_desktopintegration" -check_prevent "/etc/$VENDORPREFIX/no_desktopintegration" - -# Exit immediately if appimaged is running -pidof appimaged 2>/dev/null && exit 0 - -# Exit immediately if $DESKTOPINTEGRATION is not empty -if [ ! -z "$DESKTOPINTEGRATION" ] ; then - exit 0 -fi - -check_dep() -{ - DEP=$1 - if [ -z $(which $DEP) ] ; then - echo "$DEP is missing. Skipping ${THIS}." - exit 0 - fi -} - -DIRNAME=$(dirname $FILENAME) - -# Check whether dependencies are present in base system (we do not bundle these) -# http://cgit.freedesktop.org/xdg/desktop-file-utils/ -check_dep desktop-file-validate -check_dep update-desktop-database -check_dep desktop-file-install -check_dep xdg-icon-resource -check_dep xdg-mime -check_dep xdg-desktop-menu - -DESKTOPFILE=$(find "$APPDIR" -maxdepth 1 -name "*.desktop" | head -n 1) -# echo "$DESKTOPFILE" -DESKTOPFILE_NAME=$(basename "${DESKTOPFILE}") - -if [ ! -f "$DESKTOPFILE" ] ; then - echo "Desktop file is missing. Please run ${THIS} from within an AppImage." - exit 0 -fi - -if [ -z "$APPIMAGE" ] ; then - APPIMAGE="$APPDIR/AppRun" - # Not running from within an AppImage; hence using the AppRun for Exec= -fi - -# Construct path to the icon according to -# http://specifications.freedesktop.org/thumbnail-spec/thumbnail-spec-latest.html -ABS_APPIMAGE=$(readlink -e "$APPIMAGE") -ICONURL="file://$ABS_APPIMAGE" -MD5=$(echo -n $ICONURL | md5sum | cut -c -32) -ICONFILE="$HOME/.cache/thumbnails/normal/$MD5.png" -if [ ! -f "$ICONFILE" ] ; then - echo "$ICONFILE is missing. Probably not running ${THIS} from within an AppImage." - echo "Hence falling back to using .DirIcon" - ICONFILE="$APPDIR/.DirIcon" -fi - -# $XDG_DATA_DIRS contains the default paths /usr/local/share:/usr/share -# desktop file has to be installed in an applications subdirectory -# of one of the $XDG_DATA_DIRS components -if [ -z "$XDG_DATA_DIRS" ] ; then - echo "\$XDG_DATA_DIRS is missing. Please run ${THIS} from within an AppImage." - exit 0 -fi - -# Determine where the desktop file should be installed -if [[ $EUID -ne 0 ]]; then - DESTINATION_DIR_DESKTOP="$HOME/.local/share/applications" - SYSTEM_WIDE="" -else - # TODO: Check $XDG_DATA_DIRS - DESTINATION_DIR_DESKTOP="/usr/local/share/applications" - SYSTEM_WIDE="--mode system" # for xdg-mime and xdg-icon-resource -fi - -# Check if the desktop file is already there -# and if so, whether it points to the same AppImage -if [ -e "$DESTINATION_DIR_DESKTOP/$VENDORPREFIX-$DESKTOPFILE_NAME" ] ; then - # echo "$DESTINATION_DIR_DESKTOP/$VENDORPREFIX-$DESKTOPFILE_NAME already there" - EXEC=$(grep "^Exec=" "$DESTINATION_DIR_DESKTOP/$VENDORPREFIX-$DESKTOPFILE_NAME" | head -n 1 | cut -d " " -f 1) - # echo $EXEC - if [ "Exec=\"$APPIMAGE\"" == "$EXEC" ] ; then - exit 0 - fi -fi - -# We ask the user only if we have found no reason to skip until here -if [ -z "$SKIP" ] ; then - yesno "Install" "Would you like to integrate $APPIMAGE with your system?\n\nThis will add it to your applications menu and install icons.\nIf you don't do this you can still launch the application by double-clicking on the AppImage." -fi - -APP=$(echo "$DESKTOPFILE_NAME" | sed -e 's/.desktop//g') - -# If the user has agreed, rewrite and install the desktop file, and the MIME information -if [ -z "$SKIP" ] ; then - # desktop-file-install is supposed to install .desktop files to the user's - # applications directory when run as a non-root user, - # and to /usr/share/applications if run as root - # but that does not really work for me... - # - # For Exec we must use quotes - # For TryExec quotes is not supported, so, space must be replaced to \s - # https://askubuntu.com/questions/175404/how-to-add-space-to-exec-path-in-a-thumbnailer-descrption/175567 - desktop-file-install --rebuild-mime-info-cache \ - --vendor=$VENDORPREFIX --set-key=Exec --set-value="\"${APPIMAGE}\" %U" \ - --set-key=X-AppImage-Comment --set-value="Generated by ${THIS}" \ - --set-icon="$ICONFILE" --set-key=TryExec --set-value=${APPIMAGE// /\\s} "$DESKTOPFILE" \ - --dir "$DESTINATION_DIR_DESKTOP" - chmod a+x "$DESTINATION_DIR_DESKTOP/"* - RESOURCE_NAME=$(echo "$VENDORPREFIX-$DESKTOPFILE_NAME" | sed -e 's/.desktop//g') - # echo $RESOURCE_NAME - - # Install the icon files for the application; TODO: scalable - ICONS=$(find "${APPDIR}/usr/share/icons/" -wholename "*/apps/${APP}.png" 2>/dev/null || true) - for ICON in $ICONS ; do - ICON_SIZE=$(echo "${ICON}" | rev | cut -d "/" -f 3 | rev | cut -d "x" -f 1) - xdg-icon-resource install --context apps --size ${ICON_SIZE} "${ICON}" "${RESOURCE_NAME}" - done - - # Install mime type - find "${APPDIR}/usr/share/mime/" -type f -name *xml -exec xdg-mime install $SYSTEM_WIDE --novendor {} \; 2>/dev/null || true - - # Install the icon files for the mime type; TODO: scalable - ICONS=$(find "${APPDIR}/usr/share/icons/" -wholename "*/mimetypes/*.png" 2>/dev/null || true) - for ICON in $ICONS ; do - ICON_SIZE=$(echo "${ICON}" | rev | cut -d "/" -f 3 | rev | cut -d "x" -f 1) - xdg-icon-resource install --context mimetypes --size ${ICON_SIZE} "${ICON}" $(basename $ICON | sed -e 's/.png//g') - done - - xdg-desktop-menu forceupdate - gtk-update-icon-cache # for MIME -fi diff --git a/scripts/build/linux.sh b/scripts/build/linux.sh index 93ac83b3..892b379f 100755 --- a/scripts/build/linux.sh +++ b/scripts/build/linux.sh @@ -27,16 +27,6 @@ if [[ "$OS" != "Linux" ]]; then exit 1 fi -if ! command -v bower 2>/dev/null; then - echo "Dependency missing: bower" 1>&2 - exit 1 -fi - -if ! command -v python 2>/dev/null; then - echo "Dependency missing: python" 1>&2 - exit 1 -fi - if [ "$#" -ne 2 ]; then echo "Usage: $0 " 1>&2 exit 1 @@ -48,13 +38,6 @@ if [ "$COMMAND" != "install" ] && [ "$COMMAND" != "package" ] && [ "$COMMAND" != exit 1 fi -if [ "$COMMAND" == "debian" ] || [ "$COMMAND" == "all" ]; then - if ! command -v electron-installer-debian 2>/dev/null; then - echo "Dependency missing: electron-installer-debian" 1>&2 - exit 1 - fi -fi - if [ "$COMMAND" == "appimage" ] || [ "$COMMAND" == "all" ]; then if ! command -v upx 2>/dev/null; then echo "Dependency missing: upx" 1>&2 @@ -68,155 +51,47 @@ if [ "$ARCH" != "x64" ] && [ "$ARCH" != "x86" ]; then exit 1 fi -ELECTRON_PACKAGER=./node_modules/.bin/electron-packager ELECTRON_VERSION=`node -e "console.log(require('./package.json').devDependencies['electron-prebuilt'])"` APPLICATION_NAME=`node -e "console.log(require('./package.json').displayName)"` -APPLICATION_COPYRIGHT=`node -e "console.log(require('./package.json').copyright)"` +APPLICATION_DESCRIPTION=`node -e "console.log(require('./package.json').description)"` APPLICATION_VERSION=`node -e "console.log(require('./package.json').version)"` -function install { - - # Can be either "x64" or "ia32" - local architecture=$1 - - # Ensure native addons are compiled with the correct headers - # See https://github.com/electron/electron/blob/master/docs/tutorial/using-native-node-modules.md - export npm_config_disturl=https://atom.io/download/atom-shell - export npm_config_target=$ELECTRON_VERSION - export npm_config_arch=$architecture - export npm_config_runtime=electron - - rm -rf node_modules bower_components - npm install --build-from-source - bower install --production --allow-root -} - -function package_x86 { - local output_directory=$1 - local output_package=$output_directory/Etcher-linux-x86 - - $ELECTRON_PACKAGER . $APPLICATION_NAME \ - --platform=linux \ - --arch=ia32 \ - --version=$ELECTRON_VERSION \ - --ignore="`node scripts/packageignore.js`" \ - --asar \ - --app-version="$APPLICATION_VERSION" \ - --build-version="$APPLICATION_VERSION" \ - --overwrite \ - --out=$output_directory - - # Change ia32 suffix to x86 for consistency - rm -rf $output_package - mv $output_directory/Etcher-linux-ia32 $output_package - - mv $output_package/Etcher $output_package/etcher - chmod a+x $output_package/*.so* -} - -function package_x64 { - local output_directory=$1 - local output_package=$output_directory/Etcher-linux-x64 - - $ELECTRON_PACKAGER . $APPLICATION_NAME \ - --platform=linux \ - --arch=x64 \ - --version=$ELECTRON_VERSION \ - --ignore="`node scripts/packageignore.js`" \ - --asar \ - --app-version="$APPLICATION_VERSION" \ - --build-version="$APPLICATION_VERSION" \ - --overwrite \ - --out=$output_directory - - mv $output_package/Etcher $output_package/etcher - chmod a+x $output_package/*.so* -} - -function app_dir_create { - local source_directory=$1 - local architecture=$2 - local output_directory=$3 - - mkdir -p $output_directory/usr/bin - cp ./scripts/build/AppImages/AppRun-$architecture $output_directory/AppRun - cp ./scripts/build/AppImages/Etcher.desktop $output_directory - cp ./assets/icon.png $output_directory - cp -rf $source_directory/* $output_directory/usr/bin - cp ./scripts/build/AppImages/desktopintegration $output_directory/usr/bin/etcher.wrapper -} - -function installer { - local source_directory=$1 - local architecture=$2 - local output_directory=$3 - local appdir_temporary_location=$output_directory/Etcher-linux-$architecture.AppDir - local output_file=$output_directory/Etcher-linux-$architecture.AppImage - - mkdir -p $output_directory - app_dir_create $source_directory $architecture $appdir_temporary_location - rm -f $output_file - ./scripts/build/AppImages/AppImageAssistant-$architecture $appdir_temporary_location $output_file - - pushd $output_directory - zip Etcher-$APPLICATION_VERSION-linux-$architecture.zip Etcher-linux-$architecture.AppImage - rm Etcher-linux-$architecture.AppImage - popd - - rm -rf $appdir_temporary_location -} - if [ "$COMMAND" == "install" ] || [ "$COMMAND" == "all" ]; then - if [ "$ARCH" == "x86" ]; then - install ia32 - fi - - if [ "$ARCH" == "x64" ]; then - install x64 - fi + ./scripts/linux/dependencies.sh \ + -r "$ARCH" \ + -e "$ELECTRON_VERSION" fi if [ "$COMMAND" == "package" ] || [ "$COMMAND" == "all" ]; then - if [ "$ARCH" == "x86" ]; then - package_x86 etcher-release - fi - - if [ "$ARCH" == "x64" ]; then - package_x64 etcher-release - fi + ./scripts/linux/package.sh \ + -n "$APPLICATION_NAME" \ + -r "$ARCH" \ + -v "$APPLICATION_VERSION" \ + -e "$ELECTRON_VERSION" \ + -o etcher-release/$APPLICATION_NAME-linux-$ARCH fi if [ "$COMMAND" == "debian" ] || [ "$COMMAND" == "all" ]; then - if [ "$ARCH" == "x86" ]; then - DEBARCH=i386 - fi - - if [ "$ARCH" == "x64" ]; then - DEBARCH=amd64 - fi - - cp scripts/build/debian/etcher-electron.sh etcher-release/Etcher-linux-$ARCH/ - electron-installer-debian --src etcher-release/Etcher-linux-$ARCH \ - --dest etcher-release/installers \ - --config scripts/build/debian/config.json \ - --arch $DEBARCH - rm etcher-release/Etcher-linux-$ARCH/etcher-electron.sh + ./scripts/linux/installer-deb.sh \ + -p etcher-release/$APPLICATION_NAME-linux-$ARCH \ + -r "$ARCH" \ + -c scripts/build/debian/config.json \ + -o etcher-release/installers fi if [ "$COMMAND" == "appimage" ] || [ "$COMMAND" == "all" ]; then - package_directory=etcher-release/Etcher-linux-$ARCH + ./scripts/linux/installer-appimage.sh \ + -n "$APPLICATION_NAME" \ + -d "$APPLICATION_DESCRIPTION" \ + -p etcher-release/Etcher-linux-$ARCH \ + -r $ARCH \ + -b etcher \ + -i assets/icon.png \ + -o etcher-release/$APPLICATION_NAME-linux-$ARCH.AppImage - if [ "$ARCH" == "x86" ]; then - - # UPX fails for some reason with some other so libraries - # other than libnode.so in the x86 build - upx -9 $package_directory/etcher $package_directory/libnode.so - - fi - - if [ "$ARCH" == "x64" ]; then - upx -9 $package_directory/etcher $package_directory/*.so* - fi - - installer $package_directory $ARCH etcher-release/installers + pushd etcher-release + zip Etcher-$APPLICATION_VERSION-linux-$ARCH.zip Etcher-linux-$ARCH.AppImage + mkdir -p installers + mv Etcher-$APPLICATION_VERSION-linux-$ARCH.zip installers + popd fi diff --git a/scripts/linux/dependencies.sh b/scripts/linux/dependencies.sh new file mode 100755 index 00000000..76964223 --- /dev/null +++ b/scripts/linux/dependencies.sh @@ -0,0 +1,82 @@ +#!/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 + +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 npm 2>/dev/null 1>&2; then + echo "Dependency missing: npm" 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 + +function usage() { + echo "Usage: $0" + echo "" + echo "Options" + echo "" + echo " -r " + echo " -e " + exit 0 +} + +ARGV_ARCHITECTURE="" +ARGV_ELECTRON_VERSION="" + +while getopts ":r:e:" option; do + case $option in + r) ARGV_ARCHITECTURE=$OPTARG ;; + e) ARGV_ELECTRON_VERSION=$OPTARG ;; + *) usage ;; + esac +done + +if [ -z "$ARGV_ARCHITECTURE" ] || [ -z "$ARGV_ELECTRON_VERSION" ]; then + usage +fi + +# Ensure native addons are compiled with the correct headers +# See https://github.com/electron/electron/blob/master/docs/tutorial/using-native-node-modules.md +export npm_config_disturl=https://atom.io/download/atom-shell +export npm_config_target=$ARGV_ELECTRON_VERSION +export npm_config_runtime=electron + +if [ "$ARGV_ARCHITECTURE" == "x86" ]; then + export npm_config_arch=ia32 +else + export npm_config_arch=$ARGV_ARCHITECTURE +fi + +rm -rf node_modules bower_components +npm install --build-from-source +bower install --production --allow-root diff --git a/scripts/linux/installer-appimage.sh b/scripts/linux/installer-appimage.sh new file mode 100755 index 00000000..1f76865c --- /dev/null +++ b/scripts/linux/installer-appimage.sh @@ -0,0 +1,151 @@ +#!/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 + +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 + +function usage() { + echo "Usage: $0" + echo "" + echo "Options" + echo "" + echo " -n " + echo " -d " + echo " -p " + echo " -r " + echo " -b " + echo " -i " + echo " -o " + exit 0 +} + +ARGV_APPLICATION_NAME="" +ARGV_DESCRIPTION="" +ARGV_PACKAGE="" +ARGV_ARCHITECTURE="" +ARGV_BINARY="" +ARGV_ICON="" +ARGV_OUTPUT="" + +while getopts ":n:d:p:r:b:i:o:" option; do + case $option in + n) ARGV_APPLICATION_NAME="$OPTARG" ;; + d) ARGV_DESCRIPTION="$OPTARG" ;; + p) ARGV_PACKAGE="$OPTARG" ;; + r) ARGV_ARCHITECTURE="$OPTARG" ;; + b) ARGV_BINARY="$OPTARG" ;; + i) ARGV_ICON="$OPTARG" ;; + o) ARGV_OUTPUT="$OPTARG" ;; + *) usage ;; + esac +done + +if [ -z "$ARGV_APPLICATION_NAME" ] \ + || [ -z "$ARGV_DESCRIPTION" ] \ + || [ -z "$ARGV_PACKAGE" ] \ + || [ -z "$ARGV_ARCHITECTURE" ] \ + || [ -z "$ARGV_BINARY" ] \ + || [ -z "$ARGV_ICON" ] \ + || [ -z "$ARGV_OUTPUT" ] +then + usage +fi + +function download_executable() { + local url=$1 + local output=$2 + wget "$url" -O "$output" + chmod +x "$output" +} + +APPIMAGES_TAG=6 +APPIMAGES_GITHUB_RELEASE_BASE_URL=https://github.com/probonopd/AppImageKit/releases/download/$APPIMAGES_TAG + +if [ "$ARGV_ARCHITECTURE" == "x64" ]; then + APPIMAGES_ARCHITECTURE="x86_64" +elif [ "$ARGV_ARCHITECTURE" == "x86" ]; then + APPIMAGES_ARCHITECTURE="i686" +else + echo "Invalid architecture: $ARGV_ARCHITECTURE" 1>&2 + exit 1 +fi + +# Create AppDir +OUTPUT_FILENAME="$(basename "$ARGV_OUTPUT")" +APPDIR_PATH=/tmp/${OUTPUT_FILENAME%.*}.AppDir +APPDIR_ICON_FILENAME=icon +mkdir -p "$(dirname "$ARGV_OUTPUT")" +rm -rf "$APPDIR_PATH" +mkdir -p "$APPDIR_PATH/usr/bin" +download_executable \ + "$APPIMAGES_GITHUB_RELEASE_BASE_URL/AppRun_$APPIMAGES_TAG-$APPIMAGES_ARCHITECTURE" \ + "$APPDIR_PATH/AppRun" + +cat >"$APPDIR_PATH/$ARGV_APPLICATION_NAME.desktop" <&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 + +function usage() { + echo "Usage: $0" + echo "" + echo "Options" + echo "" + echo " -p " + echo " -r " + echo " -c " + echo " -o " + exit 0 +} + +ARGV_DIRECTORY="" +ARGV_ARCHITECTURE="" +ARGV_DEBIAN_CONFIGURATION="" +ARGV_OUTPUT="" + +while getopts ":p:r:c:o:" option; do + case $option in + p) ARGV_DIRECTORY="$OPTARG" ;; + r) ARGV_ARCHITECTURE="$OPTARG" ;; + c) ARGV_DEBIAN_CONFIGURATION="$OPTARG" ;; + o) ARGV_OUTPUT="$OPTARG" ;; + *) usage ;; + esac +done + +if [ -z "$ARGV_DIRECTORY" ] \ + || [ -z "$ARGV_ARCHITECTURE" ] \ + || [ -z "$ARGV_DEBIAN_CONFIGURATION" ] \ + || [ -z "$ARGV_OUTPUT" ] +then + usage +fi + +if [ "$ARGV_ARCHITECTURE" == "x86" ]; then + DEBARCH=i386 +elif [ "$ARGV_ARCHITECTURE" == "x64" ]; then + DEBARCH=amd64 +else + echo "Unsupported architecture: $ARGV_ARCHITECTURE" 1>&2 + exit 1 +fi + +mkdir -p "$ARGV_OUTPUT" +cp scripts/build/debian/etcher-electron.sh "$ARGV_DIRECTORY" +electron-installer-debian \ + --src "$ARGV_DIRECTORY" \ + --dest "$ARGV_OUTPUT" \ + --config "$ARGV_DEBIAN_CONFIGURATION" \ + --arch "$DEBARCH" +rm "$ARGV_DIRECTORY/etcher-electron.sh" diff --git a/scripts/linux/package.sh b/scripts/linux/package.sh new file mode 100755 index 00000000..8aa5463b --- /dev/null +++ b/scripts/linux/package.sh @@ -0,0 +1,107 @@ +#!/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 + +OS=$(uname) +if [[ "$OS" != "Linux" ]]; then + echo "This script is only meant to be run in GNU/Linux" 1>&2 + exit 1 +fi + +function usage() { + echo "Usage: $0" + echo "" + echo "Options" + echo "" + echo " -n " + echo " -r " + echo " -v " + echo " -e " + echo " -o " + exit 0 +} + +ARGV_APPLICATION_NAME="" +ARGV_ARCHITECTURE="" +ARGV_VERSION="" +ARGV_ELECTRON_VERSION="" +ARGV_OUTPUT="" + +while getopts ":n:r:v:e:o:" option; do + case $option in + n) ARGV_APPLICATION_NAME="$OPTARG" ;; + r) ARGV_ARCHITECTURE="$OPTARG" ;; + v) ARGV_VERSION="$OPTARG" ;; + e) ARGV_ELECTRON_VERSION="$OPTARG" ;; + o) ARGV_OUTPUT="$OPTARG" ;; + *) usage ;; + esac +done + +if [ -z "$ARGV_APPLICATION_NAME" ] \ + || [ -z "$ARGV_ARCHITECTURE" ] \ + || [ -z "$ARGV_VERSION" ] \ + || [ -z "$ARGV_ELECTRON_VERSION" ] \ + || [ -z "$ARGV_OUTPUT" ] +then + usage +fi + +ELECTRON_PACKAGER=./node_modules/.bin/electron-packager + +if [ ! -x $ELECTRON_PACKAGER ]; then + echo "Couldn't find $ELECTRON_PACKAGER" 1>&2 + echo "Have you installed the dependencies first?" 1>&2 + exit 1 +fi + +OUTPUT_DIRNAME=$(dirname "$ARGV_OUTPUT") + +mkdir -p "$OUTPUT_DIRNAME" + +ELECTRON_PACKAGER_ARCH=$ARGV_ARCHITECTURE +if [ "$ELECTRON_PACKAGER_ARCH" == "x86" ]; then + ELECTRON_PACKAGER_ARCH="ia32" +fi + +ELECTRON_PACKAGE_OUTPUT=$OUTPUT_DIRNAME/$ARGV_APPLICATION_NAME-linux-$ARGV_ARCHITECTURE + +rm -rf "$ELECTRON_PACKAGE_OUTPUT" + +$ELECTRON_PACKAGER . "$ARGV_APPLICATION_NAME" \ + --platform=linux \ + --arch="$ELECTRON_PACKAGER_ARCH" \ + --version="$ARGV_ELECTRON_VERSION" \ + --ignore="$(node scripts/packageignore.js)" \ + --asar \ + --app-version="$ARGV_VERSION" \ + --build-version="$ARGV_VERSION" \ + --overwrite \ + --out="$OUTPUT_DIRNAME" + +if [ "$ELECTRON_PACKAGE_OUTPUT" != "$ARGV_OUTPUT" ]; then + mv "$ELECTRON_PACKAGE_OUTPUT" "$ARGV_OUTPUT" +fi + +# Transform binary to lowercase +FINAL_BINARY_FILENAME=$(echo "$ARGV_APPLICATION_NAME" | tr '[:upper:]' '[:lower:]') +mv "$ARGV_OUTPUT/$ARGV_APPLICATION_NAME" "$ARGV_OUTPUT/$FINAL_BINARY_FILENAME" + +chmod a+x "$ARGV_OUTPUT"/*.so*