summaryrefslogtreecommitdiff
path: root/scripts/plymouth-set-default-plugin.in
blob: 2d4728ab5ae1a20319bf03d485784867d596b445 (plain)
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
135
136
137
138
139
140
141
142
143
144
#!/bin/bash

set -e

[ -z "$LIBEXECDIR" ] && LIBEXECDIR="/usr/libexec"
[ -z "$DATADIR" ] && DATADIR="/usr/share"
if [ -z "$LIB" ]; then
  if $(echo nash-showelfinterp /proc/$$/exe | /sbin/nash --forcequiet | grep -q lib64); then
    LIB="lib64"
  else
    LIB="lib"
  fi
fi
[ -z "$LIBDIR" ] && LIBDIR="/usr/$LIB"
[ -z "$BINDIR" ] && BINDIR="/usr/bin"

function usage ()
{
  echo "usage: plymouth-set-default-plugin { --list | --reset | <plugin-name> [ --rebuild-initrd ] }"
}

function list_plugins ()
{
        for plugin in ${LIBDIR}/plymouth/*.so; do
                [ -f $plugin ] || continue;
                [ -L $plugin ] && continue;

                if $(nm -D $plugin | grep -q ply_boot_splash_plugin_get_interface); then
                        echo "$(basename $plugin .so)"
                fi
        done
}

function get_default_plugin ()
{
        PLUGIN_NAME=$(basename $(readlink ${LIBDIR}/plymouth/default.so) .so)
        if [ "$PLUGIN_NAME" = ".so" ]; then
                $0 --reset
                PLUGIN_NAME=$(basename $(readlink ${LIBDIR}/plymouth/default.so) .so)
        fi
        [ "$PLUGIN_NAME" = ".so" ] || echo $PLUGIN_NAME && exit 1
}

DO_RESET=0
DO_INITRD_REBUILD=0
DO_LIST=0
PLUGIN_NAME=""
while [ $# -gt 0 ]; do
        case "$1" in

        --list)
                if [ -n "$PLUGIN_NAME" ]; then
                        echo "You can only specify --list or a plugin name, not both" > /dev/stderr
                        echo $(usage) > /dev/stderr
                        exit 1
                fi

                if [ $DO_RESET -ne 0 ]; then
                        echo "You can only specify --reset or --list, not both" > /dev/stderr
                        echo $(usage) > /dev/stderr
                        exit 1
                fi

                DO_LIST=1
        ;;

        --rebuild-initrd)
                DO_INITRD_REBUILD=1
        ;;

        --reset|default)
                if [ -n "$PLUGIN_NAME" ]; then
                        echo "You can only specify --reset or a plugin name, not both" > /dev/stderr
                        echo $(usage) > /dev/stderr
                        exit 1
                fi

                if [ $DO_LIST -ne 0 ]; then
                        echo "You can only specify --reset or --list, not both" > /dev/stderr
                        echo $(usage) > /dev/stderr
                        exit 1
                fi

                DO_RESET=1
        ;;

        *)
                if [ -n "$PLUGIN_NAME" ]; then
                        echo "You can only specify one plugin at a time" > /dev/stderr
                        echo $(usage) > /dev/stderr
                        exit 1
                fi

                if [ $DO_RESET -ne 0 ]; then
                        echo "You can only specify --reset or a plugin name, not both" > /dev/stderr
                        echo $(usage) > /dev/stderr
                        exit 1
                fi

                if [ $DO_LIST -ne 0 ]; then
                        echo "You can only specify --list or a plugin name, not both" > /dev/stderr
                        echo $(usage) > /dev/stderr
                        exit 1
                fi

                PLUGIN_NAME="$1"
        ;;
  esac
  shift
done

if [ $DO_LIST -ne 0 ]; then
        list_plugins
        exit $?
fi

if [ $DO_RESET -eq 0 ] && [ $DO_INITRD_REBUILD -eq 0 ] && [ -z $PLUGIN_NAME ]; then
        get_default_plugin
        exit $?
fi

if [ `id -u` -ne 0 ]; then
        echo "This program must be run as root" > /dev/stderr
        exit 1
fi

if [ $DO_RESET -ne 0 ]; then
        PLUGIN_NAME=$(basename $(ls -1 -t ${LIBDIR}/plymouth/*.so 2> /dev/null | grep -v default.so | tail -n 1) .so)
        if [ $PLUGIN_NAME = .so ]; then
                rm -f ${LIBDIR}/plymouth/default.so
                exit 0
        fi
fi

if [ ! -e ${LIBDIR}/plymouth/${PLUGIN_NAME}.so ]; then
        echo "${LIBDIR}/plymouth/${PLUGIN_NAME}.so does not exist" > /dev/stderr
        exit 1
fi

(cd ${LIBDIR}/plymouth;
        ln -sf ${PLUGIN_NAME}.so default.so && \
        [ $DO_INITRD_REBUILD -ne 0 ] && \
        $LIBEXECDIR/plymouth/plymouth-update-initrd)