unix/fiss

etc/utils in master
Repositories | Summary | Log | Files | LICENSE

utils (1179B) download


 1# *-*-shell-*-*
 2
 3msg() {
 4    # bold
 5    printf "\033[1m=> $@\033[m\n"
 6}
 7
 8msg_ok() {
 9    # bold/green
10    printf "\033[1m\033[32m OK\033[m\n"
11}
12
13msg_error() {
14    # bold/red
15    printf "\033[1m\033[31mERROR: $@\033[m\n"
16}
17
18msg_warn() {
19    # bold/yellow
20    printf "\033[1m\033[33mWARNING: $@\033[m\n"
21}
22
23emergency_shell() {
24    echo
25    echo "Cannot continue due to errors above, starting emergency shell."
26    echo "When ready type exit to continue booting."
27    /bin/sh -l
28}
29
30detect_virt() {
31    # Detect LXC (and other) containers
32    [ -z "${container+x}" ] || export VIRTUALIZATION=1
33}
34
35deactivate_vgs() {
36    _group=${1:-All}
37    if [ -x /sbin/vgchange -o -x /bin/vgchange ]; then
38        vgs=$(vgs|wc -l)
39        if [ $vgs -gt 0 ]; then
40            msg "Deactivating $_group LVM Volume Groups..."
41            vgchange -an
42        fi
43    fi
44}
45
46deactivate_crypt() {
47    if [ -x /sbin/dmsetup -o -x /bin/dmsetup ]; then
48        msg "Deactivating Crypt Volumes"
49        for v in $(dmsetup ls --target crypt --exec "dmsetup info -c --noheadings -o open,name"); do
50            [ ${v%%:*} = "0" ] && cryptsetup close ${v##*:}
51        done
52        deactivate_vgs "Crypt"
53    fi
54}