]> git.wincent.com - wincent.git/commitdiff
refactor: prepare to add launchd aspect
authorGreg Hurrell <greg@hurrell.net>
Sun, 29 Mar 2020 22:37:48 +0000 (00:37 +0200)
committerGreg Hurrell <greg@hurrell.net>
Sun, 29 Mar 2020 22:37:48 +0000 (00:37 +0200)
Doesn't do anything useful yet, so labeling as "refactor".

aspects/launchd/aspect.json [new file with mode: 0644]
aspects/launchd/index.ts [new file with mode: 0644]
aspects/launchd/templates/run.plist.erb [new file with mode: 0644]
project.json
src/Fig/index.ts
src/Fig/operations/template.ts [new file with mode: 0644]
src/main.ts

diff --git a/aspects/launchd/aspect.json b/aspects/launchd/aspect.json
new file mode 100644 (file)
index 0000000..e47f380
--- /dev/null
@@ -0,0 +1,3 @@
+{
+  "description": "Configures launchd"
+}
diff --git a/aspects/launchd/index.ts b/aspects/launchd/index.ts
new file mode 100644 (file)
index 0000000..a0e6a54
--- /dev/null
@@ -0,0 +1,59 @@
+import {path, template, task} from '../../src/Fig';
+
+task('configure (global) LaunchDaemons', () => {
+  [
+    {
+      dest: '/Library/LaunchDaemons/limit.maxfiles.plist',
+      variables: {
+        arguments: ['limit', 'maxfiles', 65536, 65536],
+      },
+    },
+    {
+      dest: '/Library/LaunchDaemons/limit.maxproc.plist',
+      variables: {
+        arguments: ['limit', 'maxproc', 2048, 2048],
+      },
+    },
+  ].forEach(({dest, variables}) => {
+    template({
+      group: 'wheel',
+      mode: '0644',
+      owner: 'root',
+      path: dest,
+      src: path.template('run.plist.erb'),
+      variables,
+    });
+  });
+});
+
+task('configure (local) LaunchAgents', () => {});
+
+/*
+# @see http://unix.stackexchange.com/questions/108174/how-to-persist-ulimit-settings-in-osx-mavericks
+- name: launchd | configure (global) LaunchDaemons
+  template: group=wheel
+            mode=0644
+            owner=root
+            dest=/Library/LaunchDaemons/{{ item.label }}.plist
+            src=run.plist
+  loop:
+    - label: limit.maxproc
+      args: ['limit', 'maxproc', 2048, 2048]
+    - label: limit.maxfiles
+      args: ['limit', 'maxfiles', 65536, 65536]
+  loop_control:
+    label: '{{item.label}}'
+  become: !!bool yes
+
+- name: launchd | configure (local) LaunchAgents
+  template: mode=0644
+            dest=~/Library/LaunchAgents/{{ item.label }}.plist
+            src=run.plist
+  loop:
+    - label: setenv.lang
+      args: ['setenv', 'LANG', 'en_US.UTF-8']
+    - label: setenv.lc_time
+      args: ['setenv', 'LC_TIME', 'en_AU.UTF-8']
+  loop_control:
+    label: '{{item.label}}'
+*/
diff --git a/aspects/launchd/templates/run.plist.erb b/aspects/launchd/templates/run.plist.erb
new file mode 100644 (file)
index 0000000..2b28c3a
--- /dev/null
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+  <dict>
+    <key>Label</key>
+    <string><%= item.label %></string>
+    <key>ProgramArguments</key>
+    <array>
+      <string>launchctl</string>
+<%- for (const argument in item.arguments) { %>
+      <string><%= arg %></string>
+<%- } %>
+    </array>
+    <key>RunAtLoad</key>
+    <true/>
+    <key>ServiceIPC</key>
+    <false/>
+  </dict>
+</plist>
index 418709ebaaa26b95d52918bf0057290361b25f94..019768f19fbe8c33bf8c350e3141a04926f23d7b 100644 (file)
@@ -1,7 +1,7 @@
 {
   "platforms": {
     "darwin": {
-      "aspects": ["terminfo"],
+      "aspects": ["launchd", "terminfo"],
       "variables": {}
     },
     "linux": {
index 89a8d1e011e741f02b461adc3cbe9af65404771b..f64b5e27dcc071dd0c5d65a54837c6bcba0a72ad 100644 (file)
@@ -3,13 +3,15 @@ import {default as file} from './operations/file';
 import * as path from './path';
 import {default as root} from './root';
 import {default as task} from './task';
+import {default as template} from './operations/template';
 import {default as variable} from './variable';
 
 export {command};
 export {file};
-export {task};
 export {path};
 export {root};
+export {task};
+export {template};
 export {variable};
 
 export interface Fig {
@@ -18,5 +20,6 @@ export interface Fig {
   path: typeof path;
   root: typeof root;
   task: typeof task;
+  template: typeof template;
   variable: typeof variable;
 }
diff --git a/src/Fig/operations/template.ts b/src/Fig/operations/template.ts
new file mode 100644 (file)
index 0000000..29f11b2
--- /dev/null
@@ -0,0 +1,28 @@
+import * as fs from 'fs';
+
+import {log} from '../../console';
+import expand from '../../expand';
+import Context from '../Context';
+
+export default function template({
+  // force,
+  group,
+  mode,
+  owner,
+  path,
+  src,
+  // sudo,
+  variables,
+}: {
+  group?: string;
+  path: string;
+  mode?: string;
+  owner?: string;
+  src: string;
+  variables?: Variables;
+  // force?: boolean;
+  // sudo?: boolean;
+}) {
+  log.info(`template ${src} -> ${path}`);
+  // TODO expand paths
+}
index 5aba13d680535da938739739b310fbad4e680b82..fe4e3d13c0401e10386ff0fa405de575304d465c 100644 (file)
@@ -60,6 +60,9 @@ async function main() {
   // Register tasks.
   for (const aspect of aspects) {
     switch (aspect) {
+      case 'launchd':
+        require('../aspects/launchd');
+        break;
       case 'terminfo':
         require('../aspects/terminfo');
         break;