Merge pull request #13965 from kinvolk/krnowak/custom-install-dir

Allow specifying installation directory
This commit is contained in:
Bryant Ung
2017-04-05 15:29:33 -07:00
committed by GitHub
7 changed files with 41 additions and 12 deletions

View File

@@ -29,7 +29,7 @@ To also install the newly built application, use `--create-debian-package` or `-
* `--compress-artifacts`: zips the generated application as `out/atom-{arch}.tar.gz`.
* `--create-debian-package`: creates a .deb package as `out/atom-{arch}.deb`
* `--create-rpm-package`: creates a .rpm package as `out/atom-{arch}.rpm`
* `--install`: installs the application in `/usr/local/`.
* `--install[=dir]`: installs the application in `${dir}`; `${dir}` defaults to `/usr/local`.
### Ubuntu / Debian

View File

@@ -21,7 +21,7 @@ To also install the newly built application, use `script/build --install`.
* `--code-sign`: signs the application with the GitHub certificate specified in `$ATOM_MAC_CODE_SIGNING_CERT_DOWNLOAD_URL`.
* `--compress-artifacts`: zips the generated application as `out/atom-mac.zip`.
* `--install`: installs the application at `/Applications/Atom.app` for dev and stable versions or at `/Applications/Atom-Beta.app` for beta versions.
* `--install[=dir]`: installs the application at `${dir}/Atom.app` for dev and stable versions or at `${dir}/Atom-Beta.app` for beta versions; `${dir}` defaults to `/Applications`.
## Troubleshooting

View File

@@ -35,7 +35,7 @@ To also install the newly built application, use `script\build --create-windows-
* `--code-sign`: signs the application with the GitHub certificate specified in `$WIN_P12KEY_URL`.
* `--compress-artifacts`: zips the generated application as `out\atom-windows.zip` (requires [7-Zip](http://www.7-zip.org)).
* `--create-windows-installer`: creates an `.msi`, an `.exe` and two `.nupkg` packages in the `out` directory.
* `--install`: installs the application in `%LOCALAPPDATA%\Atom\app-dev\`.
* `--install[=dir]`: installs the application in `${dir}\Atom\app-dev`; `${dir}` defaults to `%LOCALAPPDATA%`.
### Running tests

View File

@@ -20,6 +20,7 @@ const argv = yargs
.describe('create-rpm-package', 'Create .rpm package (Linux only)')
.describe('compress-artifacts', 'Compress Atom binaries (and symbols on macOS)')
.describe('install', 'Install Atom')
.string('install')
.wrap(yargs.terminalWidth())
.argv
@@ -99,8 +100,8 @@ dumpSymbols()
console.log('Skipping artifacts compression. Specify the --compress-artifacts option to compress Atom binaries (and symbols on macOS)'.gray)
}
if (argv.install) {
installApplication(packagedAppPath)
if (argv.install != null) {
installApplication(packagedAppPath, argv.install)
} else {
console.log('Skipping installation. Specify the --install option to install Atom'.gray)
}

View File

@@ -0,0 +1,24 @@
'use strict'
const os = require('os')
const passwdUser = require('passwd-user')
const path = require('path')
module.exports = function (aPath) {
if (!aPath.startsWith('~')) {
return aPath
}
const sepIndex = aPath.indexOf(path.sep)
const user = (sepIndex < 0) ? aPath.substring(1) : aPath.substring(1, sepIndex)
const rest = (sepIndex < 0) ? '' : aPath.substring(sepIndex)
const home = (user === '') ? os.homedir() : (() => {
const passwd = passwdUser.sync(user);
if (passwd === undefined) {
throw new Error(`Failed to expand the tilde in ${aPath} - user "${user}" does not exist`)
}
return passwd.homedir
})()
return `${home}${rest}`
}

View File

@@ -1,16 +1,18 @@
'use strict'
const fs = require('fs-extra')
const handleTilde = require('./handle-tilde')
const path = require('path')
const runas = require('runas')
const template = require('lodash.template')
const CONFIG = require('../config')
module.exports = function (packagedAppPath) {
module.exports = function (packagedAppPath, installDir) {
const packagedAppFileName = path.basename(packagedAppPath)
if (process.platform === 'darwin') {
const installationDirPath = path.join(path.sep, 'Applications', packagedAppFileName)
const installPrefix = installDir !== '' ? handleTilde(installDir) : path.join(path.sep, 'Applications')
const installationDirPath = path.join(installPrefix, packagedAppFileName)
if (fs.existsSync(installationDirPath)) {
console.log(`Removing previously installed "${packagedAppFileName}" at "${installationDirPath}"`)
fs.removeSync(installationDirPath)
@@ -18,7 +20,8 @@ module.exports = function (packagedAppPath) {
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')
const installPrefix = installDir !== '' ? installDir : process.env.LOCALAPPDATA
const installationDirPath = path.join(installPrefix, packagedAppFileName, 'app-dev')
try {
if (fs.existsSync(installationDirPath)) {
console.log(`Removing previously installed "${packagedAppFileName}" at "${installationDirPath}"`)
@@ -39,12 +42,12 @@ module.exports = function (packagedAppPath) {
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 prefixDirPath = installDir !== '' ? handleTilde(installDir) : path.join('/usr', 'local')
const shareDirPath = path.join(prefixDirPath, '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 binDirPath = path.join(prefixDirPath, 'bin')
const atomBinDestinationPath = path.join(binDirPath, atomExecutableName)
const apmBinDestinationPath = path.join(binDirPath, apmExecutableName)
@@ -67,7 +70,7 @@ module.exports = function (packagedAppPath) {
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
installDir: prefixDirPath, iconPath
})
fs.writeFileSync(desktopEntryPath, desktopEntryContents)

View File

@@ -23,6 +23,7 @@
"mkdirp": "0.5.1",
"normalize-package-data": "2.3.5",
"npm": "3.10.5",
"passwd-user": "2.1.0",
"pegjs": "0.9.0",
"runas": "3.1.1",
"season": "5.3.0",