From 5b85e1c797eb862c634fcac40587dcd99780ffc6 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Tue, 30 Aug 2016 11:32:22 +0200 Subject: [PATCH] Allow script/build --install on all platforms --- resources/linux/atom.desktop.in | 2 +- script/copy-folder.cmd | 18 +++++++ script/lib/create-debian-package.js | 2 +- script/lib/create-rpm-package.js | 2 +- script/lib/install-application.js | 83 +++++++++++++++++++++++++++-- script/package.json | 1 + 6 files changed, 100 insertions(+), 8 deletions(-) create mode 100644 script/copy-folder.cmd diff --git a/resources/linux/atom.desktop.in b/resources/linux/atom.desktop.in index aa5293e90..6fa5d79c8 100644 --- a/resources/linux/atom.desktop.in +++ b/resources/linux/atom.desktop.in @@ -3,7 +3,7 @@ Name=<%= appName %> Comment=<%= description %> GenericName=Text Editor Exec=<%= installDir %>/share/<%= appFileName %>/atom %F -Icon=<%= iconName %> +Icon=<%= iconPath %> Type=Application StartupNotify=true Categories=GNOME;GTK;Utility;TextEditor;Development; diff --git a/script/copy-folder.cmd b/script/copy-folder.cmd new file mode 100644 index 000000000..1021c30f3 --- /dev/null +++ b/script/copy-folder.cmd @@ -0,0 +1,18 @@ +@echo off + +set USAGE=Usage: %0 source destination + +if [%1] == [] ( + echo %USAGE% + exit 1 +) +if [%2] == [] ( + echo %USAGE% + exit 2 +) + +:: rm -rf %2 +if exist %2 rmdir %2 /s /q + +:: cp -rf %1 %2 +(robocopy %1 %2 /e) ^& IF %ERRORLEVEL% LEQ 1 exit 0 diff --git a/script/lib/create-debian-package.js b/script/lib/create-debian-package.js index 553bc749a..68a88859b 100644 --- a/script/lib/create-debian-package.js +++ b/script/lib/create-debian-package.js @@ -84,7 +84,7 @@ module.exports = function (packagedAppPath) { const desktopEntryTemplate = fs.readFileSync(path.join(CONFIG.repositoryRootPath, 'resources', 'linux', 'atom.desktop.in')) const desktopEntryContents = template(desktopEntryTemplate)({ appName: appName, appFileName: atomExecutableName, description: appDescription, - installDir: '/usr', iconName: atomExecutableName + installDir: '/usr', iconPath: atomExecutableName }) fs.writeFileSync(path.join(debianPackageApplicationsDirPath, `${atomExecutableName}.desktop`), desktopEntryContents) diff --git a/script/lib/create-rpm-package.js b/script/lib/create-rpm-package.js index 76e660a72..1c54160fb 100644 --- a/script/lib/create-rpm-package.js +++ b/script/lib/create-rpm-package.js @@ -60,7 +60,7 @@ module.exports = function (packagedAppPath) { const desktopEntryTemplate = fs.readFileSync(path.join(CONFIG.repositoryRootPath, 'resources', 'linux', 'atom.desktop.in')) const desktopEntryContents = template(desktopEntryTemplate)({ appName: appName, appFileName: atomExecutableName, description: appDescription, - installDir: '/usr', iconName: atomExecutableName + installDir: '/usr', iconPath: atomExecutableName }) fs.writeFileSync(path.join(rpmPackageBuildDirPath, `${atomExecutableName}.desktop`), desktopEntryContents) diff --git a/script/lib/install-application.js b/script/lib/install-application.js index 5852e6604..be790b4c5 100644 --- a/script/lib/install-application.js +++ b/script/lib/install-application.js @@ -2,18 +2,91 @@ const fs = require('fs-extra') const path = require('path') +const runas = require('runas') +const template = require('lodash.template') + +const CONFIG = require('../config') module.exports = function (packagedAppPath) { + const packagedAppFileName = path.basename(packagedAppPath) if (process.platform === 'darwin') { - const packagedAppPathFileName = path.basename(packagedAppPath) - const installationDirPath = path.join(path.sep, 'Applications', packagedAppPathFileName) + const installationDirPath = path.join(path.sep, 'Applications', packagedAppFileName) if (fs.existsSync(installationDirPath)) { - console.log(`Removing previously installed ${packagedAppPathFileName} at ${installationDirPath}`) + console.log(`Removing previously installed "${packagedAppFileName}" at "${installationDirPath}"`) fs.removeSync(installationDirPath) } - console.log(`Installing ${packagedAppPath} at ${installationDirPath}`) + console.log(`Installing "${packagedAppPath}" at "${installationDirPath}"`) fs.copySync(packagedAppPath, installationDirPath) + } else if (process.platform === 'win32') { + const installationDirPath = path.join(process.env.LOCALAPPDATA, packagedAppFileName, 'app-dev') + try { + if (fs.existsSync(installationDirPath)) { + console.log(`Removing previously installed "${packagedAppFileName}" at "${installationDirPath}"`) + fs.removeSync(installationDirPath) + } + console.log(`Installing "${packagedAppPath}" at "${installationDirPath}"`) + fs.copySync(packagedAppPath, installationDirPath) + } catch (e) { + console.log(`Administrator elevation required to install into "${installationDirPath}"`) + const copyScriptPath = path.join(CONFIG.repositoryRootPath, 'script', 'copy-folder.cmd') + const exitCode = runas('cmd', ['/c', copyScriptPath, packagedAppPath, installationDirPath], {admin: true}) + if (exitCode !== 0) { + throw new Error(`Installation failed. "${copyScriptPath}" exited with status: ${exitCode}`) + } + } } else { - throw new Error("Not implemented yet.") + const atomExecutableName = CONFIG.channel === 'beta' ? 'atom-beta' : 'atom' + const apmExecutableName = CONFIG.channel === 'beta' ? 'apm-beta' : 'apm' + const appName = CONFIG.channel === 'beta' ? 'Atom Beta' : 'Atom' + const appDescription = CONFIG.appMetadata.description + const userLocalDirPath = path.join('/usr', 'local') + const shareDirPath = path.join(userLocalDirPath, 'share') + const installationDirPath = path.join(shareDirPath, atomExecutableName) + const applicationsDirPath = path.join(shareDirPath, 'applications') + const desktopEntryPath = path.join(applicationsDirPath, `${atomExecutableName}.desktop`) + const binDirPath = path.join(userLocalDirPath, 'bin') + const atomBinDestinationPath = path.join(binDirPath, atomExecutableName) + const apmBinDestinationPath = path.join(binDirPath, apmExecutableName) + + fs.mkdirpSync(applicationsDirPath) + fs.mkdirpSync(binDirPath) + + if (fs.existsSync(installationDirPath)) { + console.log(`Removing previously installed "${packagedAppFileName}" at "${installationDirPath}"`) + fs.removeSync(installationDirPath) + } + console.log(`Installing "${packagedAppFileName}" at "${installationDirPath}"`) + fs.copySync(packagedAppPath, installationDirPath) + + if (fs.existsSync(desktopEntryPath)) { + console.log(`Removing existing desktop entry file at "${desktopEntryPath}"`) + fs.removeSync(desktopEntryPath) + } + console.log(`Writing desktop entry file at "${desktopEntryPath}"`) + const iconPath = path.join(CONFIG.repositoryRootPath, 'resources', 'app-icons', CONFIG.channel, 'png', '1024.png') + const desktopEntryTemplate = fs.readFileSync(path.join(CONFIG.repositoryRootPath, 'resources', 'linux', 'atom.desktop.in')) + const desktopEntryContents = template(desktopEntryTemplate)({ + appName, appFileName: atomExecutableName, description: appDescription, + installDir: '/usr', iconPath + }) + fs.writeFileSync(desktopEntryPath, desktopEntryContents) + + if (fs.existsSync(atomBinDestinationPath)) { + console.log(`Removing existing executable at "${atomBinDestinationPath}"`) + fs.removeSync(atomBinDestinationPath) + } + console.log(`Copying atom.sh to "${atomBinDestinationPath}"`) + fs.copySync(path.join(CONFIG.repositoryRootPath, 'atom.sh'), atomBinDestinationPath) + + try { + fs.lstatSync(apmBinDestinationPath) + console.log(`Removing existing executable at "${apmBinDestinationPath}"`) + fs.removeSync(apmBinDestinationPath) + } catch (e) { } + console.log(`Symlinking apm to "${apmBinDestinationPath}"`) + fs.symlinkSync(path.join('..', 'share', atomExecutableName, 'resources', 'app', 'apm', 'node_modules', '.bin', 'apm'), apmBinDestinationPath) + + console.log(`Changing permissions to 755 for "${installationDirPath}"`) + fs.chmodSync(installationDirPath, '755') } } diff --git a/script/package.json b/script/package.json index 349451629..0ddc54928 100644 --- a/script/package.json +++ b/script/package.json @@ -21,6 +21,7 @@ "normalize-package-data": "2.3.5", "npm": "3.10.5", "pegjs": "0.9.0", + "runas": "3.1.1", "season": "5.3.0", "semver": "5.3.0", "standard": "6.0.0",