Add install-systemd-service.js

This commit is contained in:
Christian Bundy 2020-01-03 21:06:08 -08:00
parent 280bf8df70
commit 48cac575e7
5 changed files with 41 additions and 24 deletions

View File

@ -23,6 +23,7 @@
"recps", "recps",
"roadmap", "roadmap",
"sameorigin", "sameorigin",
"systemctl",
"socio", "socio",
"ssbc", "ssbc",
"summerfruit", "summerfruit",

View File

@ -1,23 +0,0 @@
#!/usr/bin/env bash
SCRIPT_DIR=`dirname "$0"`
test "$XDG_CONFIG_HOME" || XDG_CONFIG_HOME=$HOME/.config
test "$SYSTEMD_USER_HOME" || SYSTEMD_USER_HOME="$XDG_CONFIG_HOME"/systemd/user
TARGET_PATH="$SYSTEMD_USER_HOME"/oasis.service
if [ -f "$TARGET_PATH" ]; then
printf "Cowardly refusing to overwrite file: %s\n\n" "$TARGET_PATH"
else
mkdir -p "$SYSTEMD_USER_HOME"
cp "$SCRIPT_DIR"/oasis.service "$TARGET_PATH"
systemctl --user daemon-reload
printf "Service configuration has been installed to: %s\n\n" "$TARGET_PATH"
fi
printf "To start Oasis automatically in the future, run:\n\n"
printf " systemctl --user enable oasis\n\n"
printf "To start and open Oasis right now, run:\n\n"
printf " systemctl --user start oasis\n"
printf " xdg-open http://localhost:4515\n"

View File

@ -0,0 +1,38 @@
const fs = require('fs')
const path = require('path')
const mkdirp = require('mkdirp')
const { execSync } = require('child_process')
let xdgConfigHome = process.env.XDG_CONFIG_HOME
let systemdUserHome = process.env.SYSTEMD_USER_HOME
if (xdgConfigHome == null) {
// Note: path.join() throws when arguments are null-ish.
xdgConfigHome = path.join(process.env.HOME, '.config')
}
if (systemdUserHome == null) {
systemdUserHome = path.join(xdgConfigHome, 'systemd', 'user')
}
const targetPath = path.join(systemdUserHome, 'oasis.service')
if (fs.existsSync(targetPath)) {
console.log('Cowardly refusing to overwrite file:', targetPath)
} else {
mkdirp(systemdUserHome)
const sourcePath = path.join(__dirname, 'oasis.service')
fs.copyFileSync(sourcePath, targetPath)
execSync('systemctl', '--user', 'daemon-reload')
console.log('Service configuration has been installed to:', targetPath)
// Since this isn't in a post-install script we can just enable it.
execSync('systemctl', '--user', 'enable', 'oasis')
}
console.log(`
To start and open Oasis right now, run:
systemctl --user start oasis
xdg-open http://localhost:4515`)

View File

@ -8,7 +8,7 @@ start in the background when you start your computer. This is good for SSB and
makes it more likely that you'll download messages that you want. makes it more likely that you'll download messages that you want.
```shell ```shell
bash contrib/install-systemd-service.bash node contrib/install-systemd-service.js
``` ```
Follow the instructions to finish configuring the background service. Follow the instructions to finish configuring the background service.

View File

@ -47,6 +47,7 @@
"cspell": "^4.0.43", "cspell": "^4.0.43",
"dependency-check": "^4.1.0", "dependency-check": "^4.1.0",
"husky": "^3.0.5", "husky": "^3.0.5",
"mkdirp": "^0.5.1",
"nodemon": "^2.0.2", "nodemon": "^2.0.2",
"standard": "^14.3.0", "standard": "^14.3.0",
"stylelint": "^12.0.1", "stylelint": "^12.0.1",