Skip to content

Commit

Permalink
got rid of profiles in favor of simpler config, bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
sdellysse committed Dec 3, 2017
1 parent 090449f commit d56cff3
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 77 deletions.
17 changes: 11 additions & 6 deletions bin/farch-edit
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
global.USAGE = `
USAGE: farch-edit [-o] [-n] FILE
Copies file(s) from system to the configuration profile and edit it.
Copies file(s) from system to the configuration and edit it.
Parameters:
-o: Overwrite target with new copy of the source
-n: Don't open editor, just copy file to configuration profile
-n: Don't open editor, just copy file to configuration
Environment Variables:
If $FARCH_EDITOR is set, then that command is used, falling back to $EDITOR.
Expand All @@ -19,13 +19,13 @@ global.ARGVOPTS = {
"use strict";

const argv = require("minimist")(process.argv.slice(2), global.ARGVOPTS);
const configDir = require("../singletons/config_dir.js");
const copy = require("../lib/util/copy.js");
const exec = require("util").promisify(require("child_process").exec);
const exists = require("../lib/util/exists.js");
const mkdirp = require("fs.extra").mkdirp;
const passthru = require("../lib/util/passthru.js");
const path = require("path");
const profileRoot = require("../lib/singletons/profile_paths.js")[0];

if (argv.help) {
console.log(global.USAGE);
Expand All @@ -37,10 +37,10 @@ global.ARGVOPTS = {
}

const filename = argv._[0];

const source = path.resolve(filename, process.cwd(), filename);
const target = path.join(configDir, source);
if (!(await exists.fileOrSymlink(target)) || argv.o) {
const target = path.join(profileRoot, source);

await mkdirp(path.parse(target).dir);
if (await exists.fileOrSymlink(source)) {
await copy(source, target);
Expand All @@ -52,6 +52,11 @@ global.ARGVOPTS = {
}

if (!argv.n) {
await passthru(`${ process.env["FARCH_EDITOR"] || process.env["EDITOR"] || "vi" } ${ target }`);
const editor = process.env["FARCH_EDITOR"] || process.env["EDITOR"] || "vi";
try {
await passthru(`${ editor } ${ target }`);
} catch (e) {
console.log(`could not start editor '${ editor }'`);
}
}
})();
9 changes: 2 additions & 7 deletions bin/farch-init
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,10 @@ farch-take to pull files from the system into farch to be edited).
}

await mkdirp(configDir);
await mkdirp(workingDir);
await systemstate.save();

await mkdirp(`${ configDir }/profiles`);
await mkdirp(`${ configDir }/profiles/default`);

{
const source = require.resolve("../share/skel/farch_conf.js")
const target = `${ configDir }/profiles/default/farch_conf.js`;
const source = require.resolve("../share/skel/conf.js")
const target = `${ configDir }/conf.js`;
await copy(source, target);
console.log(`${ source } -> ${ target }`);
};
Expand Down
12 changes: 6 additions & 6 deletions bin/farch-mkpasswd
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
#!/usr/bin/perl

print "Password: ";
print STDERR "Password: ";
system("/usr/bin/stty", "-echo");
$password = <STDIN>;
chomp($password);
system("/usr/bin/stty", "echo");
print "\n";
print STDERR "\n";

print "Again: ";
print STDERR "Again: ";
system("/usr/bin/stty", "-echo");
$again = <STDIN>;
chomp($again);
system("/usr/bin/stty", "echo");
print "\n";
print STDERR "\n";

if ($password ne $again) {
print "error dont match\n";
print STDERR "error dont match\n";
exit 1;
}


$salt = join "", ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[map {rand 64} (1..16)];

print "\n".crypt($password,"\$6\$".$salt."\$") . "\n";
print crypt($password,"\$6\$".$salt."\$") . "\n";
4 changes: 2 additions & 2 deletions bin/farch-sync
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ Brings the system state in-line with what is specified in your configuration.
try {
const argv = require("minimist")(process.argv.slice(2));
const changes = require("../lib/singletons/changes.js");
const confPathname = require("../lib/singletons/conf_pathname.js");
const getPathOf = require("../lib/get_path_of.js");
const install = require("../lib/install.js");
const packages = require("../lib/packages.js");
const profileConfPath = require("../lib/singletons/profile_conf_path.js");
const run = require("../lib/run.js");
const services = require("../lib/services.js");
const systemstate = require("../lib/singletons/systemstate");
Expand All @@ -30,7 +30,7 @@ Brings the system state in-line with what is specified in your configuration.
process.exit(1);
}

const conf = require(profileConfPath);
const conf = require(confPathname);
await systemstate.load();

const arg = { install, packages, services, run , getPathOf, changes };
Expand Down
25 changes: 7 additions & 18 deletions lib/get_path_of.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,11 @@
"use strict";

const exists = require("./util/exists.js");
const profilePaths = require("./singletons/profile_paths.js");
const zip = require("./util/zip.js");
const configDir = require("./singletons/config_dir.js");
const exists = require("./util/exists.js");

module.exports = async (name) => {
const paths = profilePaths.map(path => `${ path }/${ name }`);
const tested = zip(
paths,
await Promise.all(paths.map(exists.fileOrSymlink))
);

const found =
tested
.filter(([ _path, exists ]) => !!exists)
.map(([ path, _exists ]) => path)
[0]
;

return found;
};
const pathname = `${ configDir }/${ name }`;
if (await exists.fileOrSymlink(pathname)) {
return pathname;
}
}
5 changes: 5 additions & 0 deletions lib/singletons/conf_pathname.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"use strict";

const configDir = require("./config_dir.js");

module.exports = `${ configDir }/farch_conf.js`;
6 changes: 0 additions & 6 deletions lib/singletons/profile_conf_path.js

This file was deleted.

12 changes: 0 additions & 12 deletions lib/singletons/profile_name.js

This file was deleted.

19 changes: 0 additions & 19 deletions lib/singletons/profile_paths.js

This file was deleted.

4 changes: 3 additions & 1 deletion lib/singletons/systemstate.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ Object.assign(exports, {


exports.save = async () => {
await mkdirp(path.parse(pathname).dir);
await mkdirp(workingDir);
await writeFile(pathname, JSON.stringify(exports, null, 2), { encoding: "utf8" });
};
exports.load = async () => {
await mkdirp(workingDir);

try {
return Object.assign(exports, require(pathname));
} catch (_e) {
Expand Down
3 changes: 3 additions & 0 deletions share/skel/farch_conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ exports.packages = [
{ group: "base" },
//{ group: "base-devel" },
//{ external: "farch"},

//"grub",
//"efibootmgr",
]

/**
Expand Down

0 comments on commit d56cff3

Please sign in to comment.