source: lliurex-rpi-packages/trunk/fuentes/ldm/ltsp/ltsp-common-functions @ 2328

Last change on this file since 2328 was 2328, checked in by kbut, 3 years ago

add new package

File size: 2.2 KB
Line 
1# Common functions shared by LTSP scripts
2
3die() {
4    echo "$@" >&2
5    exit 1
6}
7
8boolean_is_true(){
9    case $1 in
10       # match all cases of true|y|yes
11       [Tt][Rr][Uu][Ee]|[Yy]|[Yy][Ee][Ss]) return 0 ;;
12       *) return 1 ;;
13    esac
14}
15
16# list files in a directory consisting only of alphanumerics, hyphens and
17# underscores
18# $1 - directory to list
19# $2 - optional prefix to limit which files are selected
20run_parts_list() {
21    test $# -ge 1 || die "ERROR: Usage: run_parts_list <dir>"
22    if [ -d "$1" ]; then
23        find -L "$1" -mindepth 1 -maxdepth 1 -type f -name "$2*" |
24            sed -n '/.*\/[0-9a-zA-Z_\-]\{1,\}$/p' | sort -n
25    fi
26}
27
28detect_vendor() {
29    if [ -e /etc/sysconfig/ltspdist ]; then
30        . /etc/sysconfig/ltspdist
31        echo "$VENDORDEF"
32    else
33        echo $(lsb_release --id --short | tr " " "_")
34    fi
35}
36
37# Distros may override this function to implement their own
38# architecture detection.
39detect_arch() {
40    echo $(uname -m)
41}
42
43require_root()
44{
45    if [ ${UID:-$(id -u)} -ne 0 ]; then
46        die "Superuser privileges are needed."
47    fi
48}
49
50# Remember mounted dirs so that it's easier to unmount them with a single call
51# to umount_marked. They'll be unmounted in reverse order.
52# Use the normal mount syntax, e.g.
53#   mark_mount -t proc proc "$ROOT/proc"
54mark_mount() {
55    local dir
56
57    # The last parameter is the dir we need to remember to unmount
58    dir=$(eval "echo \$$#")
59    if mount "$@"; then
60        # Use newlines to separate dirs, in case they contain spaces
61        if [ -z "$MARKED_MOUNTS" ]; then
62            MARKED_MOUNTS="$dir"
63        else
64            MARKED_MOUNTS="$dir
65$MARKED_MOUNTS"
66        fi
67    else
68        die "Could not mount $dir."
69    fi
70}
71
72umount_marked() {
73    [ -z "$MARKED_MOUNTS" ] && return
74
75    echo "$MARKED_MOUNTS" | while read dir; do
76        if ! umount "$dir"; then
77            echo "Couldn't unmount $dir." >&2
78        fi
79    done
80}
81
82# Source tool-specific functions, if they're provided.
83# Recursive inclusions shouldn't ever happen, but let's prevent them anyway.
84if [ -z "$ltsp_tool" ]; then
85    ltsp_tool=${0##*/}
86    if [ -f "/usr/share/ltsp/$ltsp_tool-functions" ]; then
87        . "/usr/share/ltsp/$ltsp_tool-functions"
88    fi
89fi
Note: See TracBrowser for help on using the repository browser.