diff --git a/build/resources/linux/debian/postinst b/build/resources/linux/debian/postinst new file mode 100755 index 000000000..52520e656 --- /dev/null +++ b/build/resources/linux/debian/postinst @@ -0,0 +1,161 @@ +#!/bin/sh +# postinst script for Nylas +# +# see: dh_installdeb(1) + +# summary of how this script can be called: +# * `configure' +# * abort-upgrade' +# * `abort-remove' `in-favour' +# +# * `abort-remove' +# * `abort-deconfigure' `in-favour' +# `removing' +# +# for details, see http://www.debian.org/doc/debian-policy/ or +# the debian-policy package + +UBUNTU_CODENAMES="lucid maverick natty oneiric precise quantal raring saucy trusty utopic vivid" +DEBIAN_CODENAMES="squeeze wheezy jessie sid" + +case "$1" in + configure) + gtk-update-icon-cache /usr/share/icons/hicolor > /dev/null 2>&1 + + DISTRO=`lsb_release -s -i` + + if [ "$DISTRO" = "Ubuntu" ]; then + DISTS=$UBUNTU_CODENAMES + DISTRO="ubuntu" + elif [ "$DISTRO" = "Debian" ]; then + DISTS=$DEBIAN_CODENAMES + DISTRO="debian" + else + echo "You are not running Debian or Ubuntu. Not adding Nylas repository." + DISTRO="" + fi + + if [ -n "$DISTRO" ]; then + # Add the Nylas repository. + # Copyright (c) 2009 The Chromium Authors. All rights reserved. + # Use of this source code is governed by a BSD-style license. + + # Install the repository signing key + install_key() { + APT_KEY="`which apt-key 2> /dev/null`" + if [ -x "$APT_KEY" ]; then + "$APT_KEY" add - >/dev/null 2>&1 </dev/null | cut -d ':' -f 1) + if [ -n "$SOURCELIST" ]; then + return 0 + fi + + printf "$REPOCONFIG\n" > "$APT_SOURCESDIR/nylas.list" + if [ $? -eq 0 ]; then + return 1 + fi + fi + return 2 + } + + install_key + update_sources_lists + + fi + ;; + + abort-upgrade|abort-remove|abort-deconfigure) + ;; + + *) + echo "postinst called with unknown argument '$1'" >&2 + exit 1 + ;; +esac + +set -e + +exit 0 diff --git a/build/resources/linux/debian/postrm b/build/resources/linux/debian/postrm new file mode 100755 index 000000000..33c830065 --- /dev/null +++ b/build/resources/linux/debian/postrm @@ -0,0 +1,58 @@ +#!/bin/sh +# Remove the Nylas repository. +# Copyright (c) 2009 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license. + +set -e +action="$1" + +# Only do complete clean-up on purge. +if [ "$action" != "purge" ] ; then + exit 0 +fi + +APT_GET="`which apt-get 2> /dev/null`" +APT_CONFIG="`which apt-config 2> /dev/null`" + +# Parse apt configuration and return requested variable value. +apt_config_val() { + APTVAR="$1" + if [ -x "$APT_CONFIG" ]; then + "$APT_CONFIG" dump | sed -e "/^$APTVAR /"'!d' -e "s/^$APTVAR \"\(.*\)\".*/\1/" + fi +} + +uninstall_key() { + APT_KEY="`which apt-key 2> /dev/null`" + if [ -x "$APT_KEY" ]; then + # don't fail if the key wasn't found + "$APT_KEY" rm 7D0ACF4A >/dev/null 2>&1 || true + fi +} + +# Set variables for the locations of the apt sources lists. +find_apt_sources() { + APTDIR=$(apt_config_val Dir) + APTETC=$(apt_config_val 'Dir::Etc') + APT_SOURCES="$APTDIR$APTETC$(apt_config_val 'Dir::Etc::sourcelist')" + APT_SOURCESDIR="$APTDIR$APTETC$(apt_config_val 'Dir::Etc::sourceparts')" +} + +# Remove a repository from the apt sources. +# Returns: +# 0 - successfully removed, or not configured +# 1 - failed to remove +clean_sources_lists() { + find_apt_sources + + if [ -d "$APT_SOURCESDIR" ]; then + rm -f "$APT_SOURCESDIR/nylas.list" + fi + + return 0 +} + +uninstall_key +clean_sources_lists + +exit 0 diff --git a/build/tasks/mkdeb-task.coffee b/build/tasks/mkdeb-task.coffee index 2ff79a1e2..6ee6ad8b4 100644 --- a/build/tasks/mkdeb-task.coffee +++ b/build/tasks/mkdeb-task.coffee @@ -33,7 +33,7 @@ module.exports = (grunt) -> {name, version, description} = grunt.file.readJSON('package.json') section = 'devel' - maintainer = 'Nylas ' + maintainer = 'Nylas Team ' installDir = '/usr' iconName = 'nylas' getInstalledSize buildDir, (error, installedSize) -> @@ -41,9 +41,11 @@ module.exports = (grunt) -> controlFilePath = fillTemplate(path.join('build', 'resources', 'linux', 'debian', 'control'), data) desktopFilePath = fillTemplate(path.join('build', 'resources', 'linux', 'nylas.desktop'), data) icon = path.join('build', 'resources', 'nylas.png') + postinstFilePath = path.join('build', 'resources', 'linux', 'debian', 'postinst') + postrmFilePath = path.join('build', 'resources', 'linux', 'debian', 'postrm') cmd = path.join('script', 'mkdeb') - args = [version, arch, controlFilePath, desktopFilePath, icon, buildDir] + args = [version, arch, controlFilePath, desktopFilePath, icon, postinstFilePath, postrmFilePath, buildDir] spawn {cmd, args}, (error) -> if error? done(error) diff --git a/script/mkdeb b/script/mkdeb index 8c9fc3347..afa3d1275 100755 --- a/script/mkdeb +++ b/script/mkdeb @@ -1,5 +1,5 @@ #!/bin/bash -# mkdeb version control-file-path deb-file-path +# mkdeb version arch control-file-path desktop-file-path icon-file-path sources-file-path deb-file-path set -e @@ -12,7 +12,9 @@ ARCH="$2" CONTROL_FILE="$3" DESKTOP_FILE="$4" ICON_FILE="$5" -DEB_PATH="$6" +POSTINST_FILE="$6" +POSTRM_FILE="$7" +DEB_PATH="$8" FILE_MODE=755 TARGET_ROOT="`mktemp -d`" @@ -25,6 +27,9 @@ env INSTALL_PREFIX="$TARGET/usr" script/grunt install mkdir -m $FILE_MODE -p "$TARGET/DEBIAN" cp "$CONTROL_FILE" "$TARGET/DEBIAN/control" +cp "$POSTINST_FILE" "$TARGET/DEBIAN/postinst" +cp "$POSTRM_FILE" "$TARGET/DEBIAN/postrm" + mkdir -m $FILE_MODE -p "$TARGET/usr/share/applications" cp "$DESKTOP_FILE" "$TARGET/usr/share/applications"