]> git.wincent.com - wincent.git/blob - aspects/ssh/index.ts
feat: add bin/git-cipher symlink as a convenience
[wincent.git] / aspects / ssh / index.ts
1 import {fail, file, resource, skip, task, template, variable} from 'fig';
2 import stat from 'fig/fs/stat.js';
3
4 task('create ~/.ssh', async () => {
5   await file({
6     mode: '0700',
7     path: '~/.ssh',
8     state: 'directory',
9   });
10 });
11
12 task('install ~/.ssh/config', async () => {
13   if (variable('identity') === 'wincent') {
14     const src = resource.template('.ssh/config.erb');
15
16     const stats = await stat(src);
17
18     // TODO: make this warn instead of fail
19     // (on first run on a new machine, we might not have decrypted yet...
20     // because we won't have the GPG key on the machine yet...
21     // although maybe I should just do that...)
22     if (stats === null) {
23       fail(`"${src}" does not exist; run "bin/git-cipher"`);
24     } else if (stats instanceof Error) {
25       throw stats;
26     } else {
27       await template({
28         mode: '0600',
29         path: '~/.ssh/config',
30         src,
31       });
32     }
33   } else {
34     skip();
35   }
36 });