From 27727a7a97d19b4c94c77b0229db10ed1680d379 Mon Sep 17 00:00:00 2001 From: grunjol Date: Tue, 29 Mar 2016 00:34:45 -0300 Subject: [PATCH 1/4] Linux: create Debian package --- bin/package.js | 46 +++++++++++++++---- main/handlers.js | 6 +-- package.json | 1 + static/linux/postinst | 3 ++ static/linux/postrm | 2 + .../webtorrent-desktop.desktop} | 2 +- 6 files changed, 48 insertions(+), 12 deletions(-) create mode 100644 static/linux/postinst create mode 100644 static/linux/postrm rename static/{webtorrent.desktop => linux/webtorrent-desktop.desktop} (96%) diff --git a/bin/package.js b/bin/package.js index 94d6e5ea..c5cb56d3 100755 --- a/bin/package.js +++ b/bin/package.js @@ -16,18 +16,19 @@ var BUILD_NAME = config.APP_NAME + '-v' + config.APP_VERSION function build () { var platform = process.argv[2] + var packageType = process.argv.length > 3 ? process.argv[3] : 'all' if (platform === 'darwin') { buildDarwin(printDone) } else if (platform === 'win32') { buildWin32(printDone) } else if (platform === 'linux') { - buildLinux(printDone) + buildLinux(packageType, printDone) } else { buildDarwin(function (err, buildPath) { printDone(err, buildPath) buildWin32(function (err, buildPath) { printDone(err, buildPath) - buildLinux(printDone) + buildLinux(packageType, printDone) }) }) } @@ -285,16 +286,45 @@ function buildWin32 (cb) { }) } -function buildLinux (cb) { +function buildLinux (packageType, cb) { electronPackager(Object.assign({}, all, linux), function (err, buildPath) { if (err) return cb(err) - // Create .zip file for Linux var distPath = path.join(config.ROOT_PATH, 'dist') - var zipPath = path.join(config.ROOT_PATH, 'dist', BUILD_NAME + '-linux.zip') - var appFolderName = path.basename(buildPath[0]) - cp.execSync(`cd ${distPath} && zip -r -y ${zipPath} ${appFolderName}`) - console.log('Created Linux .zip file.') + var filesPath = buildPath[0] + + if (packageType === 'deb' || packageType === 'all') { + // Create .deb file for debian based platforms + var deb = require('nobin-debian-installer')() + var destPath = path.join('/opt', pkg.name) + + deb.pack({ + package: pkg, + info: { + arch: 'amd64', + targetDir: distPath, + scripts: { + postinst: path.join(config.STATIC_PATH, 'linux', 'postinst'), + postrm: path.join(config.STATIC_PATH, 'linux', 'postrm') + } + } + }, [{ + src: ['./**'], + dest: destPath, + expand: true, + cwd: filesPath + }], function (err, done) { + console.log(err || 'Created Linux .deb file.') + }) + } + + if (packageType === 'zip' || packageType === 'all') { + // Create .zip file for Linux + var zipPath = path.join(config.ROOT_PATH, 'dist', BUILD_NAME + '-linux.zip') + var appFolderName = path.basename(filesPath) + cp.execSync(`cd ${distPath} && zip -r -y ${zipPath} ${appFolderName}`) + console.log('Created Linux .zip file.') + } }) } diff --git a/main/handlers.js b/main/handlers.js index 371d4bfe..be76bd3c 100644 --- a/main/handlers.js +++ b/main/handlers.js @@ -32,7 +32,7 @@ function initLinux () { installIconFile() function installDesktopFile () { - var templatePath = path.join(config.STATIC_PATH, 'webtorrent.desktop') + var templatePath = path.join(config.STATIC_PATH, 'linux', 'webtorrent-desktop.desktop') fs.readFile(templatePath, 'utf8', writeDesktopFile) } @@ -53,7 +53,7 @@ function initLinux () { '.local', 'share', 'applications', - 'webtorrent.desktop' + 'webtorrent-desktop.desktop' ) mkdirp(path.dirname(desktopFilePath)) fs.writeFile(desktopFilePath, desktopFile, function (err) { @@ -74,7 +74,7 @@ function initLinux () { '.local', 'share', 'icons', - 'webtorrent.png' + 'webtorrent-desktop.png' ) mkdirp(path.dirname(iconFilePath)) fs.writeFile(iconFilePath, iconFile, function (err) { diff --git a/package.json b/package.json index f6dac021..216aea83 100644 --- a/package.json +++ b/package.json @@ -37,6 +37,7 @@ "electron-packager": "^6.0.0", "electron-winstaller": "^2.0.5", "gh-release": "^2.0.3", + "nobin-debian-installer": "^0.0.3", "plist": "^1.2.0", "rimraf": "^2.5.2", "standard": "^6.0.5" diff --git a/static/linux/postinst b/static/linux/postinst new file mode 100644 index 00000000..ab6b9eae --- /dev/null +++ b/static/linux/postinst @@ -0,0 +1,3 @@ +#!/bin/sh +chmod +x /opt/webtorrent-desktop/WebTorrent +ln -s /opt/webtorrent-desktop/WebTorrent /usr/bin/webtorrent-desktop diff --git a/static/linux/postrm b/static/linux/postrm new file mode 100644 index 00000000..aaf63fb6 --- /dev/null +++ b/static/linux/postrm @@ -0,0 +1,2 @@ +#!/bin/sh +rm /usr/bin/webtorrent-desktop diff --git a/static/webtorrent.desktop b/static/linux/webtorrent-desktop.desktop similarity index 96% rename from static/webtorrent.desktop rename to static/linux/webtorrent-desktop.desktop index ea956dea..ac37a056 100644 --- a/static/webtorrent.desktop +++ b/static/linux/webtorrent-desktop.desktop @@ -6,7 +6,7 @@ X-GNOME-FullName=$APP_NAME Comment=Download and share files over BitTorrent Encoding=UTF-8 Type=Application -Icon=webtorrent +Icon=webtorrent-desktop Terminal=false Path=$APP_PATH Exec=$EXEC_PATH %U From dd8ed771537ba65c69144f8d73a343c190e42430 Mon Sep 17 00:00:00 2001 From: grunjol Date: Tue, 29 Mar 2016 00:56:42 -0300 Subject: [PATCH 2/4] add package invocation change for deb/zip package --- README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 8b1e53b6..146a4337 100644 --- a/README.md +++ b/README.md @@ -50,10 +50,12 @@ $ npm run package To build for one platform: ``` -$ npm run package -- [platform] +$ npm run package -- [platform] [package-type] ``` -Where `[platform]` is `darwin`, `linux`, or `win32`. +Where `[platform]` is `darwin`, `linux`, or `win32` + +and `[package-type]` is `all` (default), `deb` or `zip` (`linux` platform only) #### Windows build notes @@ -75,4 +77,3 @@ brew install wine ## License MIT. Copyright (c) [Feross Aboukhadijeh](http://feross.org). - From faee840073fc2afcee4d19207b53f8e1a87d1e2a Mon Sep 17 00:00:00 2001 From: grunjol Date: Tue, 29 Mar 2016 10:53:59 -0300 Subject: [PATCH 3/4] update installer version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 216aea83..e5272978 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,7 @@ "electron-packager": "^6.0.0", "electron-winstaller": "^2.0.5", "gh-release": "^2.0.3", - "nobin-debian-installer": "^0.0.3", + "nobin-debian-installer": "^0.0.5", "plist": "^1.2.0", "rimraf": "^2.5.2", "standard": "^6.0.5" From a064794c870244e9b9ceceafaa3567d0924ac680 Mon Sep 17 00:00:00 2001 From: grunjol Date: Sat, 2 Apr 2016 09:19:39 -0300 Subject: [PATCH 4/4] set error handling in pre and post init script --- static/linux/postinst | 1 + static/linux/postrm | 1 + 2 files changed, 2 insertions(+) diff --git a/static/linux/postinst b/static/linux/postinst index ab6b9eae..19145082 100644 --- a/static/linux/postinst +++ b/static/linux/postinst @@ -1,3 +1,4 @@ #!/bin/sh +set -e chmod +x /opt/webtorrent-desktop/WebTorrent ln -s /opt/webtorrent-desktop/WebTorrent /usr/bin/webtorrent-desktop diff --git a/static/linux/postrm b/static/linux/postrm index aaf63fb6..dec86c69 100644 --- a/static/linux/postrm +++ b/static/linux/postrm @@ -1,2 +1,3 @@ #!/bin/sh +set -e rm /usr/bin/webtorrent-desktop