@[has_globals] module main import os import vile.scheme import stutter import nspkg // config_path is the file read at startup, evaluated by Vile // embedded from V. the file is required, since the config carries parts of // vpac (the repos, for one); a setting no form of it names keeps the // default its __global is declared with below, which reset_config puts // back before every load pub const config_path = '/etc/vpac.d/config.vile' __global config_vile = true // the settings below were consts until the config existed. root_path and // db_path are joined onto file names directly, so they keep a trailing slash __global root_path = '/' __global db_path = '/var/lib/pacman/' __global arch = 'x86_64' __global parallel_downloads = 3 // the rank form: how many mirrors to probe at once (0 = unset, so the rank // parallelism falls back to the network's parallel) and how long one probe // may take __global rank_parallel = 0 __global rank_timeout = 10 // the pkgbuild form: the command that builds and how deep the clone is. // where it builds is path #:build. the build command is the system's makepkg, // which ships in the pacman package with the libalpm vpac runs on; #:makepkg // names another // the build command is trusted text: it is spelled whole into a shell that // runs it in the cloned dir, first as the building user and through the // reviews of the pkgbuild for its content. vpac does not vet it — the config // is code the machine's user writes (like pacman.conf no more and no less), // and whoever controls a user's config already controls their shell __global pkgbuild_makepkg = 'makepkg -f' __global pkgbuild_depth = 1 // the unprivileged user libalpm downloads as, like DownloadUser in pacman.conf __global download_user = 'alpm' // the configured directories and lists. the defaults are the values the // hardcoded vpac used __global cfg_cachedirs = ['/var/cache/pacman/pkg/'] // pacman's default HookDir, beside the system one libalpm adds by itself __global cfg_hookdirs = ['/etc/pacman.d/hooks/'] // where pkgbuild packages are cloned and built (path #:build): a relative // dir is taken under the invoking user's home, because makepkg runs as that user __global pkgbuild_dir = '.cache/vpac/pkgbuild' __global cfg_logfile = '' // the keyring signatures are checked against: pacman's GPGDir default, not // moved under a fake root (pacman keeps it as configuration). libalpm has // no default of its own, and without one gpgme falls back on root's own // ~/.gnupg, where no packager's key is __global cfg_gpgdir = '/etc/pacman.d/gnupg/' __global cfg_protocols = ['https'] // the signature level every sync db is registered with and packages are // checked against. libalpm's freshly calloc'd handle verifies nothing, so // vpac defaults to pacman's shipped SigLevel: a package and a database // signature are both verified when they are present, and a mismatching one // fails. override with (network #:siglevel #(...)) __global cfg_siglevel = nspkg.SigLevel.package | .package_optional | .database | .database_optional __global cfg_hold = []string{} __global cfg_ignore = []string{} // the rest of pacman.conf's [options]: groups ignored as cfg_ignore's packages // are, files an upgrade or an install leaves alone, and the download timeout __global cfg_ignore_groups = []string{} __global cfg_noupgrade = []string{} __global cfg_noextract = []string{} __global cfg_disable_timeout = false // pacman.conf's DisableSandboxFilesystem and DisableSandboxSyscalls: libalpm // sandboxes its downloads and extracts, and this turns both parts off __global cfg_disable_sandbox = false // pacman.conf's UseSyslog: libalpm logs to syslog too, (path #:syslog #t) __global cfg_syslog = false // cfg_repos holds the repos the config defines __global cfg_repos = []CfgRepo{} // CfgRepo is one registered repo: a name, a kind ('sync', or 'pkgbuild' for // a site to build from), and the urls to fetch it from, where a url keeps // the $repo and $arch placeholders struct CfgRepo { name string kind string servers []string // what the db is used for, as pacman.conf's Usage; every use by default usage nspkg.DBUsage = nspkg.db_usage_all } // config forms accept scheme keywords as well as stutter's quoted symbols. fn config_keyword_args(form string, args []scheme.Value) !([]string, []scheme.Value) { mut normalized := args.clone() for i := 0; i < normalized.len; i += 2 { if normalized[i].kind() == .keyword { normalized[i] = scheme.symbol(normalized[i].keyword_name()!)! } } return stutter.keyword_args(form, normalized) } // mirror files can extend a binding without requiring the config to seed it. fn prim_defined(mut vm scheme.VM, args []scheme.Value) !scheme.Value { scheme.check_arity('defined?', args.len, 1, 1)! name := args[0].symbol_name()! value := vm.lookup(name) or { if err.msg().starts_with('unbound variable ') { return scheme.boolean(false) } return err } return scheme.boolean(value.kind() != .uninitialized) } // usage_of reads a repo's #:usage, pacman.conf's Usage: one or more of sync, // search, install, upgrade and all fn usage_of(v scheme.Value, what string) !nspkg.DBUsage { names := match v.kind() { .string { [v.as_string()!] } else { stutter.strs_of(v, what)! } } if names.len == 0 { return error('config: ${what} needs at least one of sync, search, install, upgrade, all') } mut usage := unsafe { nspkg.DBUsage(0) } for name in names { usage |= match name.to_lower() { 'sync' { nspkg.DBUsage.sync } 'search' { nspkg.DBUsage.search } 'install' { nspkg.DBUsage.install } 'upgrade' { nspkg.DBUsage.upgrade } 'all' { nspkg.db_usage_all } else { return error('config: ${what} takes sync, search, install, upgrade and all, not "${name}"') } } } return usage } // siglevel_names are the names (network #:siglevel) accepts, mapped onto // libalpm's SigLevel bits, plus what each one means const siglevel_names = { 'package': nspkg.SigLevel.package 'package_optional': nspkg.SigLevel.package_optional 'package_marginal_ok': nspkg.SigLevel.package_marginal_ok 'package_unknown_ok': nspkg.SigLevel.package_unknown_ok 'database': nspkg.SigLevel.database 'database_optional': nspkg.SigLevel.database_optional 'database_marginal_ok': nspkg.SigLevel.database_marginal_ok 'database_unknown_ok': nspkg.SigLevel.database_unknown_ok } // siglevel_of reads a SigLevel out of a config value: one name or an array // of names, e.g. (network #:siglevel #("package" "database_optional")) fn siglevel_of(v scheme.Value, what string) !nspkg.SigLevel { names := match v.kind() { .string { [v.as_string()!] } else { stutter.strs_of(v, what)! } } // an empty one verifies nothing: libalpm would take the silent answer // as handing everything over unsigned, which nobody ever means if names.len == 0 { return error('config: ${what} needs at least one of: ${siglevel_names.keys().join(', ')}') } mut level := unsafe { nspkg.SigLevel(0) } for name in names { key := name.to_lower() bit := siglevel_names[key] or { return error('config: ${what} must be one or more of: ${siglevel_names.keys().join(', ')}') } level |= bit } return level } // prim_path is the config's (path ...) form: root, db, log, gpg, cache, hook, // and #:syslog true for pacman.conf's UseSyslog fn prim_path(mut _vm scheme.VM, args []scheme.Value) !scheme.Value { keys, values := config_keyword_args('path', args)! mut i := 0 for i < keys.len { match keys[i] { 'root' { root_path = stutter.dir_path('path #:root', stutter.str_of(values[i], 'path #:root')!)! } 'db' { db_path = stutter.dir_path('path #:db', stutter.str_of(values[i], 'path #:db')!)! } 'log' { cfg_logfile = stutter.str_of(values[i], 'path #:log')! } 'syslog' { cfg_syslog = stutter.bool_of(values[i], 'path #:syslog')! } 'gpg' { cfg_gpgdir = stutter.dir_path('path #:gpg', stutter.str_of(values[i], 'path #:gpg')!)! } 'cache' { dirs := stutter.strs_of(values[i], 'path #:cache')! cfg_cachedirs = []string{} for dir in dirs { cfg_cachedirs << stutter.dir_path('path #:cache', dir)! } } 'hook' { dirs := stutter.strs_of(values[i], 'path #:hook')! cfg_hookdirs = []string{} for dir in dirs { cfg_hookdirs << stutter.dir_path('path #:hook', dir)! } } 'build' { d := stutter.str_of(values[i], 'path #:build')! if d == '' { return error('config: path #:build must not be empty') } pkgbuild_dir = d } else { return error('config: path has no key #:${keys[i]}') } } i++ } return scheme.nil_value() } // prim_pkg is the config's (pkg ...) form: arch, hold, ignore, and pacman.conf's // IgnoreGroup, NoUpgrade and NoExtract as #:ignoregroup, #:noupgrade and // #:noextract, each a list, e.g. (pkg #:noextract #("usr/share/doc/*")) fn prim_pkg(mut _vm scheme.VM, args []scheme.Value) !scheme.Value { keys, values := config_keyword_args('pkg', args)! mut i := 0 for i < keys.len { match keys[i] { 'arch' { a := stutter.str_of(values[i], 'pkg #:arch')! // it fills the $arch of every server url and is the one // architecture libalpm installs for: one plain word if a == '' || a.contains('/') || a.fields().len != 1 || a.fields()[0] != a { return error('config: pkg #:arch must be one plain word, such as x86_64') } arch = a } 'hold' { cfg_hold = stutter.strs_of(values[i], 'pkg #:hold')! } 'ignore' { cfg_ignore = stutter.strs_of(values[i], 'pkg #:ignore')! } 'ignoregroup' { cfg_ignore_groups = stutter.strs_of(values[i], 'pkg #:ignoregroup')! } 'noupgrade' { cfg_noupgrade = stutter.strs_of(values[i], 'pkg #:noupgrade')! } 'noextract' { cfg_noextract = stutter.strs_of(values[i], 'pkg #:noextract')! } else { return error('config: pkg has no key #:${keys[i]}') } } i++ } return scheme.nil_value() } // prim_network is the config's (network ...) form: parallel, protocols, user, // siglevel, #:disable-timeout true for pacman.conf's DisableDownloadTimeout, and // #:disable-sandbox true for its DisableSandbox fn prim_network(mut _vm scheme.VM, args []scheme.Value) !scheme.Value { keys, values := config_keyword_args('network', args)! mut i := 0 for i < keys.len { match keys[i] { 'parallel' { n := stutter.int_of(values[i], 'network #:parallel')! if n < 1 { return error('config: network #:parallel must be at least 1') } parallel_downloads = n } 'protocols' { protos := stutter.strs_of(values[i], 'network #:protocols')! if protos.len == 0 { return error('config: network #:protocols needs at least one, https or http') } // a scheme no mirror is listed under would filter every // mirror out without a word for proto in protos { if proto !in ['https', 'http'] { return error('config: network #:protocols takes https and http, not "${proto}"') } } cfg_protocols = protos.clone() } 'user' { download_user = stutter.str_of(values[i], 'network #:user')! } 'siglevel' { cfg_siglevel = siglevel_of(values[i], 'network #:siglevel')! } 'disable-timeout' { cfg_disable_timeout = stutter.bool_of(values[i], 'network #:disable-timeout')! } 'disable-sandbox' { cfg_disable_sandbox = stutter.bool_of(values[i], 'network #:disable-sandbox')! } else { return error('config: network has no key #:${keys[i]}') } } i++ } return scheme.nil_value() } // prim_rank is the config's (rank ...) form: parallel and timeout for the // mirror ranking. the parallelism falls back to the network's parallel when // the rank form does not set its own. #:top is how many mirrors are answered, // #:completion (0 to 1) and #:max-delay (seconds) what a mirror must report to // be probed, #:candidates how many get the speed test, #:retest how many of // the fastest are timed twice, #:dir where rank -w writes fn prim_rank(mut _vm scheme.VM, args []scheme.Value) !scheme.Value { keys, values := config_keyword_args('rank', args)! mut i := 0 for i < keys.len { match keys[i] { 'parallel' { n := stutter.int_of(values[i], 'rank #:parallel')! if n < 1 { return error('config: rank #:parallel must be at least 1') } rank_parallel = n } 'timeout' { n := stutter.int_of(values[i], 'rank #:timeout')! if n < 1 { return error('config: rank #:timeout must be at least 1') } rank_timeout = n } 'top' { rank_top = stutter.count_of(values[i], 'rank #:top', 1)! } 'dir' { d := stutter.str_of(values[i], 'rank #:dir')! if !d.starts_with('/') { return error('config: rank #:dir must be an absolute path') } rank_dir = d.trim_right('/') } 'candidates' { rank_speed_candidates = stutter.count_of(values[i], 'rank #:candidates', 1)! } 'retest' { rank_retest = stutter.count_of(values[i], 'rank #:retest', 0)! } 'completion' { rank_min_completion = stutter.ratio_of(values[i], 'rank #:completion')! } 'max-delay' { rank_max_delay = i64(stutter.count_of(values[i], 'rank #:max-delay', 0)!) } else { return error('config: rank has no key #:${keys[i]}') } } i++ } return scheme.nil_value() } // prim_repo is the config's (repo ...) form: a repo's name, its type ('sync', // or 'pkgbuild', a site to build from) and the mirrors it is fetched // from, with $repo and $arch left as placeholders // #:usage is pacman.conf's Usage: a list of sync, search, install, upgrade // and all; every use when it is left out fn prim_repo(mut _vm scheme.VM, args []scheme.Value) !scheme.Value { keys, values := config_keyword_args('repo', args)! mut repo := CfgRepo{ kind: 'sync' } mut i := 0 for i < keys.len { match keys[i] { 'name' { rname := stutter.str_of(values[i], 'repo #:name')! repo = CfgRepo{ ...repo name: rname } } 'type' { rkind := stutter.str_of(values[i], 'repo #:type')! if rkind !in ['sync', 'pkgbuild'] { return error("config: repo #:type is 'sync' or 'pkgbuild', not '${rkind}'") } repo = CfgRepo{ ...repo kind: rkind } } 'src' { rservers := stutter.strs_of(values[i], 'repo #:src')! if rservers.len == 0 { return error('config: repo #:src needs at least one url') } for server in rservers { if server == '' { return error('config: repo #:src has an empty url in it') } } repo = CfgRepo{ ...repo servers: rservers } } 'usage' { rusage := usage_of(values[i], 'repo #:usage')! repo = CfgRepo{ ...repo usage: rusage } } else { return error('config: repo has no key #:${keys[i]}') } } i++ } if repo.name == '' { return error('config: repo needs a #:name') } // libalpm refuses a second db of a name, and 'local' is its own db's: // said here, by name, instead of late and from inside a mode if repo.name == 'local' { return error('config: a repo cannot be named local, the installed packages are') } if cfg_repos.any(it.name == repo.name) { return error('config: repo ${repo.name} is defined twice') } if repo.kind == 'sync' && repo.servers.len == 0 { return error('config: a sync repo takes at least one #:src') } if repo.kind == 'pkgbuild' && repo.servers.len != 1 { return error('config: a pkgbuild repo takes one #:src, the site to build from') } cfg_repos << repo return scheme.nil_value() } // pkgbuild_repos are the configured pkgbuild repos, in config order. the // --pkgbuild flags search and build from all of them, each under its own name fn pkgbuild_repos() []CfgRepo { return cfg_repos.filter(it.kind == 'pkgbuild') } // prim_pkgbuild is the config's (pkgbuild ...) form: makepkg, depth, and // timeout, the seconds one lookup of a pkgbuild repo may take. where the // build happens is path #:build fn prim_pkgbuild(mut _vm scheme.VM, args []scheme.Value) !scheme.Value { keys, values := config_keyword_args('pkgbuild', args)! mut i := 0 for i < keys.len { match keys[i] { 'makepkg' { m := stutter.str_of(values[i], 'pkgbuild #:makepkg')! if m == '' { return error('config: pkgbuild #:makepkg must not be empty') } pkgbuild_makepkg = m } 'depth' { n := stutter.int_of(values[i], 'pkgbuild #:depth')! if n < 1 { return error('config: pkgbuild #:depth must be at least 1') } pkgbuild_depth = n } 'timeout' { pkgbuild_rpc_timeout = stutter.count_of(values[i], 'pkgbuild #:timeout', 1)! } else { return error('config: pkgbuild has no key #:${keys[i]}') } } i++ } return scheme.nil_value() } // option_flags are the mode flags (options ...) can turn on for every run, // by the config's key: each names the field the modes' flag structs keep it // in, so a mode that has no such flag is simply not touched const option_flags = { 'noconfirm': 'noconfirm' 'nopkgbuildconfirm': 'no_pkgbuild_confirm' 'needed': 'needed' 'no-upgrade-deps': 'no_upgrade_deps' 'quiet': 'quiet' 'keep-current': 'keep_current' 'fuzzy': 'fuzzy' 'disable-timeout': 'disable_timeout' } // opt_flags holds the fields of option_flags the config turned on; // opt_color is options #:color, empty when the config names none __global opt_flags = map[string]bool{} __global opt_color = '' // prim_options is the config's (options ...) form: root, the command vpac // gets root with (privilege.v); color, the --color a run starts from; // verbose, the verbose log of a run's housekeeping failures (--verbose); // sync-age, the hours after which the sync dbs are called stale (0: never); // suggest, how close (0 to 1) a name must be to be offered for a typo; and // the mode flags of option_flags, true or false fn prim_options(mut _vm scheme.VM, args []scheme.Value) !scheme.Value { keys, values := config_keyword_args('options', args)! mut i := 0 for i < keys.len { match keys[i] { 'root' { r := stutter.str_of(values[i], 'options #:root')! if r.trim_space() == '' { return error('config: options #:root must not be empty') } root_provider = r } 'color' { c := stutter.str_of(values[i], 'options #:color')! if c !in ['auto', 'always', 'never'] { return error('config: options #:color takes auto, always or never, not "${c}"') } opt_color = c } 'sync-age' { // hours; 0 never warns sync_max_age = i64(stutter.count_of(values[i], 'options #:sync-age', 0)!) * 3600 } 'suggest' { suggest_thold = stutter.ratio_of(values[i], 'options #:suggest')! } 'verbose' { // the verbose log for every run, as --verbose for one cfg_verbose = stutter.bool_of(values[i], 'options #:verbose')! } else { field := option_flags[keys[i]] or { return error('config: options has no key #:${keys[i]}') } // only what is on is held: a false takes back an earlier // true (an --eval over the file) and leaves no entry behind if stutter.bool_of(values[i], 'options #:${keys[i]}')! { opt_flags[field] = true } else { opt_flags.delete(field) } } } i++ } return scheme.nil_value() } // prim_search is the config's (search ...) form: fields, the columns of a // listing when --fields names none, and thold, the fuzzy threshold fn prim_search(mut _vm scheme.VM, args []scheme.Value) !scheme.Value { keys, values := config_keyword_args('search', args)! mut i := 0 for i < keys.len { match keys[i] { 'fields' { names := stutter.strs_of(values[i], 'search #:fields')! if names.len == 0 { return error('config: search #:fields needs at least one field') } cfg_search_fields = parse_fields(names.join(','), []string{}) or { return error('config: search #:fields: ${err.msg()}') } } 'thold' { cfg_search_thold = stutter.ratio_of(values[i], 'search #:thold')! } else { return error('config: search has no key #:${keys[i]}') } } i++ } return scheme.nil_value() } // prim_clean is the config's (clean ...) form: keep, the versions of every // package the cache keeps when -k names none fn prim_clean(mut _vm scheme.VM, args []scheme.Value) !scheme.Value { keys, values := config_keyword_args('clean', args)! mut i := 0 for i < keys.len { match keys[i] { 'keep' { cfg_clean_keep = stutter.count_of(values[i], 'clean #:keep', 0)! } else { return error('config: clean has no key #:${keys[i]}') } } i++ } return scheme.nil_value() } // prim_tree is the config's (tree ...) form: depth, how deep a tree is // drawn when -d names none fn prim_tree(mut _vm scheme.VM, args []scheme.Value) !scheme.Value { keys, values := config_keyword_args('tree', args)! mut i := 0 for i < keys.len { match keys[i] { 'depth' { cfg_tree_depth = stutter.count_of(values[i], 'tree #:depth', 0)! } else { return error('config: tree has no key #:${keys[i]}') } } i++ } return scheme.nil_value() } // prim_color is the config's (color ...) form, the theme: each key is a role // of default_theme, each value one style or a list of them out of // style_names, e.g. (color #:version "cyan" #:warning #("bold" "magenta")) fn prim_color(mut _vm scheme.VM, args []scheme.Value) !scheme.Value { keys, values := config_keyword_args('color', args)! mut i := 0 for i < keys.len { if keys[i] !in theme { return error('config: color has no role #:${keys[i]}, the roles are: ${default_theme().keys().join(', ')}') } styles := stutter.strs_of(values[i], 'color #:${keys[i]}')! for style in styles { if style !in style_names { return error('config: color #:${keys[i]} takes ${style_names.join(', ')}, not "${style}"') } } theme[keys[i]] = styles.clone() i++ } return scheme.nil_value() } // prim_mirrorlist is the config's (mirrorlist ...) form: an os for the // ranker, new or one of its own redefined. #:name is what rank is asked for // (and what /etc/os-release is matched against), #:repo the repo whose db the // speed test pulls, and the mirrors come from one of #:status, a mirror // status json api as arch publishes, or #:list, a Server = mirrorlist at a // url or an absolute path fn prim_mirrorlist(mut _vm scheme.VM, args []scheme.Value) !scheme.Value { keys, values := config_keyword_args('mirrorlist', args)! mut name := '' mut status := '' mut list := '' mut repo := '' mut i := 0 for i < keys.len { match keys[i] { 'name' { name = stutter.str_of(values[i], 'mirrorlist #:name')! } 'status' { status = stutter.str_of(values[i], 'mirrorlist #:status')! } 'list' { list = stutter.str_of(values[i], 'mirrorlist #:list')! } 'repo' { repo = stutter.str_of(values[i], 'mirrorlist #:repo')! } else { return error('config: mirrorlist has no key #:${keys[i]}') } } i++ } if name == '' || name.contains('/') || name.starts_with('.') || name.starts_with('-') || name.fields().len != 1 || name.fields()[0] != name { return error('config: mirrorlist needs a #:name, one plain word') } if repo == '' { return error('config: mirrorlist ${name} needs a #:repo, the repo whose db is timed') } if (status == '') == (list == '') { return error('config: mirrorlist ${name} takes one of #:status and #:list') } if status != '' && !status.starts_with('https://') && !status.starts_with('http://') { return error('config: mirrorlist ${name} #:status must be an http or https url') } if list != '' && !list.starts_with('https://') && !list.starts_with('http://') && !list.starts_with('/') { return error('config: mirrorlist ${name} #:list must be a url or an absolute path') } rank_oses[name] = RankOs{ status_json: status mirrorlist: list repo: repo } return scheme.nil_value() } // prim_progress is the config's (progress ...) form, the bars: style // ('classic' or 'block'); the graphic's pieces start, end, fill, head and // empty; length in cells (0 fills the terminal); percent, eta, elapsed and // rate, true or false; delay, the milliseconds between redraws fn prim_progress(mut _vm scheme.VM, args []scheme.Value) !scheme.Value { keys, values := config_keyword_args('progress', args)! mut i := 0 for i < keys.len { what := 'progress #:${keys[i]}' match keys[i] { 'style' { s := stutter.str_of(values[i], what)! if s !in ['classic', 'block'] { return error('config: ${what} is classic or block, not "${s}"') } cfg_progress.style = s } 'start', 'end' { cfg_progress.parts[keys[i]] = stutter.str_of(values[i], what)! } 'fill', 'empty' { cfg_progress.parts[keys[i]] = stutter.cell_of(values[i], what, false)! } 'head' { cfg_progress.parts[keys[i]] = stutter.cell_of(values[i], what, true)! } 'length' { cfg_progress.length = stutter.count_of(values[i], what, 0)! } 'percent' { cfg_progress.percent = stutter.bool_of(values[i], what)! } 'eta' { cfg_progress.eta = stutter.bool_of(values[i], what)! } 'elapsed' { cfg_progress.elapsed = stutter.bool_of(values[i], what)! } 'rate' { cfg_progress.rate = stutter.bool_of(values[i], what)! } 'delay' { cfg_progress.delay = stutter.count_of(values[i], what, 1)! } else { return error('config: progress has no key #:${keys[i]}') } } i++ } return scheme.nil_value() } // prim_spinner is the config's (spinner ...) form: frames, a set by name // (spinner_sets) or a list of frames of one's own; interval, the // milliseconds a frame stays; done, what a finished step shows in place of // the animation; elapsed, whether the time taken is shown fn prim_spinner(mut _vm scheme.VM, args []scheme.Value) !scheme.Value { keys, values := config_keyword_args('spinner', args)! mut i := 0 for i < keys.len { what := 'spinner #:${keys[i]}' match keys[i] { 'frames' { if values[i].kind() == .string { name := values[i].as_string()! cfg_progress.frames = spinner_frames_named(name) or { return error('config: ${what} knows ${spinner_sets.join(', ')}, not "${name}"; a list gives frames of your own') } } else { frames := stutter.strs_of(values[i], what)! if frames.len == 0 { return error('config: ${what} needs at least one frame') } cfg_progress.frames = frames.clone() } } 'interval' { cfg_progress.interval = stutter.count_of(values[i], what, 1)! } 'done' { cfg_progress.done = stutter.str_of(values[i], what)! } 'elapsed' { cfg_progress.timed = stutter.bool_of(values[i], what)! } else { return error('config: spinner has no key #:${keys[i]}') } } i++ } return scheme.nil_value() } // reset_config puts every config global back at its declared default, the // values the hardcoded vpac used. load_config runs it first, so a second // load in one process neither duplicates the repos nor keeps settings the // new file does not name; a failed load can leave values behind, and the // next load starts clean again fn reset_config() { config_vile = true root_path = '/' root_provider = 'sudo' opt_flags = map[string]bool{} opt_color = '' cfg_verbose = false sync_max_age = i64(24 * 60 * 60) suggest_thold = 0.85 pkgbuild_rpc_timeout = 10 rank_min_completion = 1.0 rank_max_delay = i64(86400) rank_speed_candidates = 40 rank_retest = 5 rank_top = 10 cfg_search_fields = search_default_fields.clone() cfg_search_thold = 0.9 cfg_clean_keep = 0 cfg_tree_depth = 0 theme = default_theme() rank_oses = default_rank_oses() rank_dir = '/etc/vpac.d/mirrors' cfg_progress = ProgressCfg{} db_path = '/var/lib/pacman/' arch = 'x86_64' parallel_downloads = 3 rank_parallel = 0 rank_timeout = 10 pkgbuild_makepkg = 'makepkg -f' pkgbuild_depth = 1 download_user = 'alpm' pkgbuild_dir = '.cache/vpac/pkgbuild' cfg_cachedirs = ['/var/cache/pacman/pkg/'] cfg_hookdirs = ['/etc/pacman.d/hooks/'] cfg_logfile = '' cfg_gpgdir = '/etc/pacman.d/gnupg/' cfg_protocols = ['https'] cfg_siglevel = nspkg.SigLevel.package | .package_optional | .database | .database_optional cfg_hold = []string{} cfg_ignore = []string{} cfg_ignore_groups = []string{} cfg_noupgrade = []string{} cfg_noextract = []string{} cfg_disable_timeout = false cfg_disable_sandbox = false cfg_syslog = false cfg_repos = []CfgRepo{} } // load_config reads the config file -- the one --config names, else // config_path -- and evaluates it in a machine that provides the config // forms. the file is required: vpac has no defaults to fall back to once its // repos, paths and mirror lists live in the config. the --eval snippets run // after it, in the same machine, so they can extend or override the file for // this run. a file that does not parse, or a form with the wrong keys, stops // vpac, because running on silently could act on the wrong database fn load_config(chosen string, evals []string) ! { reset_config() old_path := os.join_path(os.dir(config_path), 'config.scm') path := if chosen != '' { chosen } else if !os.exists(config_path) && os.is_file(old_path) { old_path } else { config_path } config_vile = os.file_ext(path) == '.vile' mut reader := stutter.Config{ name: 'vpac' syntax: if config_vile { .vile } else { .scheme } path: path default_path: config_path required: true max_steps: 100_000_000 primitives: { 'defined?': prim_defined 'path': prim_path 'pkg': prim_pkg 'network': prim_network 'rank': prim_rank 'pkgbuild': prim_pkgbuild 'options': prim_options 'search': prim_search 'clean': prim_clean 'tree': prim_tree 'color': prim_color 'mirrorlist': prim_mirrorlist 'progress': prim_progress 'spinner': prim_spinner 'repo': prim_repo } }.reader()! if config_vile { bind_config_settings(mut reader.machine)! } reader.load()! for source in evals { // Parenthesized command-line overrides have always been Scheme, including // for Vile files. An assignment uses the same syntax as the file. if config_vile && source.trim_space().starts_with('(') { reader.machine.eval(source) or { if scheme.is_control_transfer(err) { return err } return error(': ${err.msg()}') } } else { reader.eval(source, '')! } } } // check_hold refuses to remove a package the config holds, as pacman does for // HoldPkg. libalpm has no option for it, so it is a frontend check fn check_hold(names []string) ! { for name in names { if name in cfg_hold { return error('${name} is held by the config: remove it from pkg #:hold first') } } }