File: basic

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 (134 lines) | stat: -rw-r--r-- 2,058 bytes parent folder | download | duplicates (2)
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# vim: filetype=sh

# basic routines
# --------------
missing_or_empty()
{
    f="$1"
    if [ ! -e "$f" ]
    then
        echo 1
        return
    else
        if [ "$(cat "$f" | wc -l)" -eq 0 ]
        then
            echo 1
            return
        fi
    fi
    echo 0
}

num_dir_entries() {
    d="$1"
    if [ ! -d "$d" ]
    then
        echo 0
    else
        ls -1 "$d" | wc -l
    fi
}

abspath()
{
    echo "$(cd "$(dirname "$1")" && pwd)/$(basename "$1")"
}

print_last_word()
{
    awk '{print $NF}'
}

# divide %1/%2 rounding up
ceil()
{
    divide=$1
    by=$2
    echo $(((divide+by-1)/by))
}

estimated_size_mb()
{
    du -sm "$1" | awk '{print $1}'
}

real_size_human_readable()
{
    du -sh --apparent-size "$1" | awk '{print $1}'
}

device_size_mb()
{
    size_b=$(blockdev --getsize64 $1)
    echo $((size_b/1024/1024))
}

size_as_mb()
{
    echo $(($(echo $1 | sed -e "s/M//" -e "s/G/*1024/")))
}

check_integer() {
    case "$1" in
        ''|*[!0-9]*)
            return 1 ;;   # not a number
        *)
            return 0 ;;   # number
    esac
}

sum_lines() {
    exp="$(paste -sd+ -)"
    [ "$exp" = "" ] && echo 0 || echo "$(($exp))"
}

# grep returns non-zero if no line is found.
# in some cases, having no line is expected
# (e.g. in the case of error lines)
# thus the or-true construct.
happy_grep()
{
    grep "$@" || true
}

# get total size needed taking into account
# an overhead.
# $1: the initial size (not taking the overhead into account)
# $2: percent of overhead
# return value: the size needed (such that applying the
#               overhead would get $1 again)
apply_overhead_percent()
{
    echo $((($1)*100/(100-($2))))
}

quiet()
{
    $* >/dev/null
}

wait_for_device()
{
	while [ ! -e "$1" ]
	do
		sleep 0.1
	done
}

get_vg_name()
{
    case "$1" in
        "draft")
            echo "DRAFT_$2"
            ;;
        "final")
            echo "DBSTCK_$2"
            ;;
    esac
}

get_rootfs_uuid()
{
    image_name="$1"     # final or draft
    cat $DBSTCK_TMPDIR/$image_name/rootfs_vol/uuid
}