File: os-detect

package info (click to toggle)
debootstick 2.8
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 296 kB
  • sloc: sh: 1,364; makefile: 34
file content (66 lines) | stat: -rw-r--r-- 2,240 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
# vim: filetype=sh

# check that the given directory looks like an OS
# file structure that we can handle correctly.
check_fs_hierarchy()
{
    fs_tree="$1"
    level="$2"
    case "$level" in
    "1")
        if [ ! -f "$fs_tree/bin/echo" ]
        then
            echo "E: No /bin/echo found in $fs_tree."
            echo "E: This does not seem to be a chroot environment."
            return 1
        fi

        if [ ! -f "$fs_tree/etc/os-release" ]
        then
            echo "E: No /etc/os-release file found in $fs_tree."
            echo "E: Cannot check compatibility. Aborting."
            return 1
        fi

        . "$fs_tree/etc/os-release"
        if [ "$ID" != "debian" -a "$ID_LIKE" != "debian" ]
        then
            echo "E: /etc/os-release file in $fs_tree does not report a debian-like OS."
            echo "E: debootstick currently cannot handle such a chroot environment." >&2
            echo "E: Run 'debootstick --help-os-support' for more info."
            return 1
        fi
        ;;
    "2")
        chroot "$fs_tree" echo -n >/dev/null 2>&1 || {
            echo "E: Unable to execute binaries (/bin/echo at least) in the chroot environment."
            echo "E: Please verify:"
            echo "E: - file permissions in the chroot environment"
            echo "E: - that your host CPU is able to run binaries of the target architecture"
            echo "E: Run 'debootstick --help-os-support' for info about compatible environments."
            return 1
        }
        chroot "$fs_tree" which apt-get >/dev/null 2>&1 || {
            echo "E: No apt-get found in $1."
            echo "E: debootstick cannot handle this kind of chroot environment."
            echo "E: Run 'debootstick --help-os-support' for more info."
            return 1
        }
        ;;
    esac
}

detect_target_type()
{
    fs_tree="$1"
    dir="$DBSTCK_DIR/scripts/create-image/target"
    for subdir in $(ls "$dir")
    do
        "$dir/$subdir/detect.sh" "$fs_tree" >/dev/null && {
            echo "$subdir"
            return
        }
    done
    echo "E: debootstick does not know how to handle your chroot environment." >&2
    echo "E: Run 'debootstick --help-os-support' for more info." >&2
}