diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-06 02:41:06 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-06 02:41:06 +0000 |
commit | cfa363aeeda6881266b5da46afd478a255ce996e (patch) | |
tree | f4a77457d4c8183d324dfd239e4889b975c3718c /tests | |
parent | Initial commit. (diff) | |
download | tasksel-upstream.tar.xz tasksel-upstream.zip |
Adding upstream version 3.53.upstream/3.53upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rwxr-xr-x | tests/debconf | 23 | ||||
-rwxr-xr-x | tests/default-desktop | 39 | ||||
-rwxr-xr-x | tests/desktop | 120 | ||||
-rwxr-xr-x | tests/lang | 19 | ||||
-rwxr-xr-x | tests/laptop | 13 | ||||
-rwxr-xr-x | tests/new-install | 34 | ||||
-rwxr-xr-x | tests/server | 16 |
7 files changed, 264 insertions, 0 deletions
diff --git a/tests/debconf b/tests/debconf new file mode 100755 index 0000000..88b2a77 --- /dev/null +++ b/tests/debconf @@ -0,0 +1,23 @@ +#!/bin/sh +# +# Allows a task to be enabled or disabled if tasksel is running inside a +# debconf instance, as in the first stage Debian install. +# +# To enable this test insert your tasks stanza a keyword like: +# +# Test-debconf: false +# +# This will cause the task to be available only if tasksel is not running +# in debconf. + +if [ "$DEBIAN_HAS_FRONTEND" ] || [ "$DEBCONF_READFD" ]; then + if [ "$2" = true ]; then + exit 3 # display task, not marked for installation + fi +else + if [ "$2" = false ]; then + exit 3 # display task, not marked for installation + fi +fi + +exit 1 # do not display task diff --git a/tests/default-desktop b/tests/default-desktop new file mode 100755 index 0000000..2b6a3b8 --- /dev/null +++ b/tests/default-desktop @@ -0,0 +1,39 @@ +#!/bin/sh +# Test-default-desktop: 3 $desktopname +# +# Will check if tasksel/desktop has been preseeded to "$desktopname", +# or if it's the default desktop for the architecture. +# If so, marks the task for installation. +# +# Otherwise, exits with the provided value. +# (3 will display the task not marked for installation; ). +set +e + +DEFAULT="$2" +DESKTOPNAME="$3" + +if ! [ "$NEW_INSTALL" ]; then + exit $DEFAULT +fi + +. /usr/share/debconf/confmodule +. /usr/lib/tasksel/default_desktop + +check_desktop_wanted() { + # see if the desktop test thinks the system wants a desktop + /usr/lib/tasksel/tests/desktop + if [ "$?" = 2 ]; then + exit 2 + fi +} + +if db_get "tasksel/desktop"; then + if echo "$RET" | grep -q "$DESKTOPNAME"; then + check_desktop_wanted + fi +else + if [ "$DESKTOPNAME" = "$(default_desktop_for_arch $(dpkg --print-architecture))" ]; then + check_desktop_wanted + fi +fi +exit $DEFAULT diff --git a/tests/desktop b/tests/desktop new file mode 100755 index 0000000..c3daaee --- /dev/null +++ b/tests/desktop @@ -0,0 +1,120 @@ +#!/bin/sh +# Try to guess at whether the user would like a desktop installed on their +# system. Of course Debian has many users who use it on a wide array of +# hardware, so this is tricky, but it's only a default. +set -e + +if ! [ "$NEW_INSTALL" ]; then + exit 3 +fi + +arch="$(dpkg --print-architecture)" + +unmark () { + exit 3 +} +mark () { + exit 2 +} + +# A few arches have the lion's share of desktops. +common_desktop_architecture () { + case "$arch" in + i386|amd64|powerpc*) + return 0 + ;; + *) + return 1 + ;; + esac +} + +# On some arches it's almost unheard of to run a desktop, at least using +# this task. +unlikely_desktop_architecture () { + case "$arch" in + m68k|s390|s390x|hppa) + return 0 + ;; + *) + return 1 + ;; + esac +} + +# Modern desktops take a lot of ram. +enough_ram () { + min_ram=64 + ram=$(grep ^MemTotal: /proc/meminfo | { read x y z; echo $y; }) || true # kb + # The 4 is a fuzz factor to allow for kernel ram usage. + if [ "$ram" ] && [ "$ram" -ge "$(expr $(expr $min_ram - 4) \* 1024)" ]; then + return 0 + else + return 1 + fi +} + +# The desktop task requires 2 gb or so of disk in /usr, and .5 in /var for +# the debs. +# FIXME: this should really be generalised and used for tasksel to not +# suggest any task for which there is not enough disk. +enough_disk () { + min_disk=3 + disk=$(df -P /usr | tail -1 | awk '{print $4}') + if [ "$disk" ] && [ "$disk" -ge "$(expr $min_disk \* 1024 \* 1024)" ]; then + return 0 + else + return 1 + fi +} + +desktop_hardware () { + if which laptop-detect >/dev/null 2>&1 && \ + laptop-detect; then + # Nearly always appropriate to include a desktop. + return 0 + else + # TODO: test for the existence of a framebuffer and a mouse. + # A mouse, in particular, almost always indicates a + # desktop. + : + fi + return 1 +} + +rack_hardware () { + if which dmidecode >/dev/null 2>&1 && \ + dmidecode | grep -q 'Type: Rack Mount Chassis'; then + return 0 + fi + + # XXX further heuristics here to avoid selecting the task on + # high-end hardware that's intended to be used as a server. + # For example, if it has two NICs with link, it's probably a + # server. + + return 1 +} + +if ! enough_ram || ! enough_disk; then + unmark +fi + +if desktop_hardware; then + mark +fi + +if unlikely_desktop_architecture; then + unmark +elif common_desktop_architecture; then + if rack_hardware; then + unmark + else + mark # probably a desktop ... + fi +else + # XXX further heuristics here + : +fi + +unmark diff --git a/tests/lang b/tests/lang new file mode 100755 index 0000000..243b9cc --- /dev/null +++ b/tests/lang @@ -0,0 +1,19 @@ +#!/bin/sh +# Hide all language tasks, and select any that match the current LANG +# setting for installation. +if [ "$NEW_INSTALL" ]; then + set -e + shift 1 + baselang=${LANG%%_*} + fulllang=${LANG%%.*} + for locale in $@; do + if ( [ -n "$LANG" ] && [ "$LANG" = "$locale" ] ) || \ + ( [ -n "$fulllang" ] && [ "$fulllang" = "$locale" ] ) || \ + ( [ -n "$baselang" ] && [ "$baselang" = "$locale" ] ); then + exit 0 # install without display + fi + done + exit 1 # do not display +else + exit 1 +fi diff --git a/tests/laptop b/tests/laptop new file mode 100755 index 0000000..c205f4d --- /dev/null +++ b/tests/laptop @@ -0,0 +1,13 @@ +#!/bin/sh +# Causes a task to be selected if the machine appears to be a laptop. + +if [ "$NEW_INSTALL" ]; then + if which laptop-detect >/dev/null 2>&1 && \ + laptop-detect; then + exit 0 # hide; install + else + exit 1 # hide; do not install + fi +else + exit 3 +fi diff --git a/tests/new-install b/tests/new-install new file mode 100755 index 0000000..88a7d87 --- /dev/null +++ b/tests/new-install @@ -0,0 +1,34 @@ +#!/bin/sh +# +# Controls behavior for a task on new install or not. +# +# To enable this test insert your tasks stanza a keyword like: +# +# Test-new-install: mark skip +# +# This will cause the task to be marked for install on new install, and +# hidden otherwise. + +if [ "$NEW_INSTALL" ]; then + var=$2 +else + var=$3 +fi + +case "$var" in + install) + exit 0 # do not display, but do install task + ;; + skip) + exit 1 # do not display task + ;; + mark) + exit 2 # display task, marked for installation + ;; + show) + exit 3 # display task, not marked for installation + ;; + *) + exit 1 # unknown value, skip the task + ;; +esac diff --git a/tests/server b/tests/server new file mode 100755 index 0000000..3aeff7c --- /dev/null +++ b/tests/server @@ -0,0 +1,16 @@ +#!/bin/sh + +if ! [ "$NEW_INSTALL" ]; then + exit 3 +fi + +/usr/lib/tasksel/tests/desktop +ret=$? +case $ret in + 0|2) # is desktop + exit 3 # not server + ;; + *) + exit 2 # likely is server + ;; +esac |