diff --git a/bin/farch-edit b/bin/farch-edit index 69ac7d4..6fecb4c 100755 --- a/bin/farch-edit +++ b/bin/farch-edit @@ -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. @@ -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); @@ -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); @@ -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 }'`); + } } })(); diff --git a/bin/farch-init b/bin/farch-init index dd98009..78e247e 100755 --- a/bin/farch-init +++ b/bin/farch-init @@ -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 }`); }; diff --git a/bin/farch-mkpasswd b/bin/farch-mkpasswd index fa723ee..b6f59ed 100755 --- a/bin/farch-mkpasswd +++ b/bin/farch-mkpasswd @@ -1,25 +1,25 @@ #!/usr/bin/perl -print "Password: "; +print STDERR "Password: "; system("/usr/bin/stty", "-echo"); $password = ; chomp($password); system("/usr/bin/stty", "echo"); -print "\n"; +print STDERR "\n"; -print "Again: "; +print STDERR "Again: "; system("/usr/bin/stty", "-echo"); $again = ; 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"; diff --git a/bin/farch-sync b/bin/farch-sync index e5bbec1..50c48fa 100755 --- a/bin/farch-sync +++ b/bin/farch-sync @@ -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"); @@ -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 }; diff --git a/lib/get_path_of.js b/lib/get_path_of.js index c945810..1b9091d 100644 --- a/lib/get_path_of.js +++ b/lib/get_path_of.js @@ -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; + } +} diff --git a/lib/singletons/conf_pathname.js b/lib/singletons/conf_pathname.js new file mode 100644 index 0000000..d9dbc04 --- /dev/null +++ b/lib/singletons/conf_pathname.js @@ -0,0 +1,5 @@ +"use strict"; + +const configDir = require("./config_dir.js"); + +module.exports = `${ configDir }/farch_conf.js`; diff --git a/lib/singletons/profile_conf_path.js b/lib/singletons/profile_conf_path.js deleted file mode 100644 index 1f85652..0000000 --- a/lib/singletons/profile_conf_path.js +++ /dev/null @@ -1,6 +0,0 @@ -"use strict"; - -const profileName = require("./profile_name.js"); -const configDir = require("./config_dir.js"); - -module.exports = `${ configDir }/profiles/${ profileName }/farch_conf.js`; diff --git a/lib/singletons/profile_name.js b/lib/singletons/profile_name.js deleted file mode 100644 index 4e4e891..0000000 --- a/lib/singletons/profile_name.js +++ /dev/null @@ -1,12 +0,0 @@ -"use strict"; - -const existsSync = require("fs").existsSync; -const readFileSync = require("fs").readFileSync; -const configDir = require("./config_dir.js"); - -if (0) { -} else if (existsSync(`${ configDir }/system_profile`)) { - module.exports = readFileSync(`${ configDir }/system_profile`, "utf8").split("\n")[0]; -} else { - module.exports = "default"; -} diff --git a/lib/singletons/profile_paths.js b/lib/singletons/profile_paths.js deleted file mode 100644 index 3135df6..0000000 --- a/lib/singletons/profile_paths.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict"; - -const configDir = require("./config_dir.js"); -const profileName = require("./profile_name.js"); - -module.exports = []; - -const addLine = (profileName) => { - if (profileName === "default") { - module.exports.push(`${ configDir }/profiles/default`); - } else { - const dir = `${ configDir }/profiles/${ profileName }`; - module.exports.push(dir); - - const confPathname = `${ dir }/farch_conf.js`; - addLine(require(confPathname).parent || "default"); - } -}; -addLine(profileName); diff --git a/lib/singletons/systemstate.js b/lib/singletons/systemstate.js index 54e82f1..a5b9f7c 100644 --- a/lib/singletons/systemstate.js +++ b/lib/singletons/systemstate.js @@ -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) { diff --git a/share/skel/farch_conf.js b/share/skel/farch_conf.js index be9d06a..828515a 100644 --- a/share/skel/farch_conf.js +++ b/share/skel/farch_conf.js @@ -37,6 +37,9 @@ exports.packages = [ { group: "base" }, //{ group: "base-devel" }, //{ external: "farch"}, + + //"grub", + //"efibootmgr", ] /**