File: snaps.name

package info (click to toggle)
snapd 2.72-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 80,412 kB
  • sloc: sh: 16,506; ansic: 16,211; python: 11,213; makefile: 1,919; exp: 190; awk: 58; xml: 22
file content (77 lines) | stat: -rwxr-xr-x 1,601 bytes parent folder | download | duplicates (3)
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/bin/bash

show_help() {
    echo "usage: snaps.name gadget, kernel, core, snap-suffix"
    echo ""
    echo "get the name of a specific snap for the current system"
}

gadget_name() {
    snap list | grep -E '(gadget$|gadget,)' | awk '{ print $1 }'
}

kernel_name(){
    # TODO this may not always be true during remodel scenarios
    # if the old kernel remains
    snap list | grep -E '(kernel$|kernel,)' | awk '{ print $1 }'
}

core_name(){
    local core_name
    core_name="$(snap model --verbose | grep -Po "^base:\\s+\\K.*" || true)"
    if [ -z "$core_name" ]; then
        core_name="core"
    fi
    echo "$core_name"
}

snap_suffix(){
    if os.query is-core18; then
        echo "-core18"
    elif os.query is-core20; then
        echo "-core20"
    elif os.query is-core22; then
        echo "-core22"
    elif os.query is-core24; then
        echo "-core24"
    fi
}

main() {
    if [ $# -eq 0 ]; then
        show_help
        exit 0
    fi

    while [ $# -gt 0 ]; do
        case "$1" in
            -h|--help)
                show_help
                exit 0
                ;;
            gadget)
                gadget_name
                exit
                ;;
            kernel)
                kernel_name
                exit
                ;;
            core)
                core_name
                exit
                ;;
            snap-suffix)
                snap_suffix
                exit
                ;;
            *)
                echo "snaps.name: unknown snap $1" >&2
                exit 1
                ;;
        esac
    done

}

main "$@"