Skip to content

Commit

Permalink
Merge pull request atom#13965 from kinvolk/krnowak/custom-install-dir
Browse files Browse the repository at this point in the history
Allow specifying installation directory
  • Loading branch information
Bryant Ung committed Apr 5, 2017
2 parents 9e10cde + 1e9083d commit 2f6880a
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 12 deletions.
2 changes: 1 addition & 1 deletion docs/build-instructions/linux.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion docs/build-instructions/macOS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion docs/build-instructions/windows.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 3 additions & 2 deletions script/build
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
}
Expand Down
24 changes: 24 additions & 0 deletions script/lib/handle-tilde.js
Original file line number Diff line number Diff line change
@@ -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}`
}
17 changes: 10 additions & 7 deletions script/lib/install-application.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
'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)
}
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}"`)
Expand All @@ -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)

Expand All @@ -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)

Expand Down
1 change: 1 addition & 0 deletions script/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 2f6880a

Please sign in to comment.