aboutsummaryrefslogtreecommitdiff
path: root/contrib/cpt-reset
blob: a2336e340fb34fca3ebdbf062c921bcb8ffe41eb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/bin/sh -e
# Remove all packages except for the base
#
# Disable word-splittng warnings as they're safe here.
# shellcheck disable=SC2046
# shellcheck source=../src/cpt-lib

## SYNOPSIS:
## .Nm
## DESCRIPTION:
## .Nm
## removes all packages from the system that is not defined as a base package in
## .Pa /etc/cpt-base .

parser_definition() {
    setup REST help:usage -- "usage: ${0##*/}"
    global_options compact
    msg -- '' "Remove all packages outside of base definition"
}

. cpt-lib
base=$(pkg_get_base nonl)

set --
cd "$sys_db"

set +f; for pkg in *; do
    contains "$base" "$pkg" || set -- "$pkg" "$@"
done

[ -z "$1" ] && {
    log "No package outside of the base definition could be found, not continuing."
    exit 0
}

warn "" "This is a potentially harmful operation, do NOT continue unless"
warn "" "you know exactly what you are doing. Continuing will remove $#"
warn "" "packages that are not listed in the base definition or that the"
warn "" "base packages don't depend on. See the CPT BASE section on the"
warn "" "user manual to learn more."
prompt && cpt-remove "$@"