summaryrefslogtreecommitdiff
path: root/scripts/plymouth-set-default-theme.in
blob: 9ca9f35f5951d90ed0c0de360d737dd17f4e4ad7 (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
145
146
147
#!/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-theme { --list | --reset | <theme-name> [ --rebuild-initrd ] }"
}

function list_themes ()
{
        for theme in ${DATADIR}/plymouth/themes/*/*.plymouth; do
                [ -f $theme ] || continue;
                echo "$(basename $theme .plymouth)"
        done
}

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

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

        --list)
                if [ -n "$THEME_NAME" ]; then
                        echo "You can only specify --list or a theme 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 "$THEME_NAME" ]; then
                        echo "You can only specify --reset or a theme 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 "$THEME_NAME" ]; then
                        echo "You can only specify one theme 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 theme 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 theme name, not both" > /dev/stderr
                        echo $(usage) > /dev/stderr
                        exit 1
                fi

                THEME_NAME="$1"
        ;;
  esac
  shift
done

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

if [ $DO_RESET -eq 0 ] && [ $DO_INITRD_REBUILD -eq 0 ] && [ -z $THEME_NAME ]; then
        get_default_theme
        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
        THEME_NAME=$(basename $(ls -1 -t ${DATADIR}/plymouth/themes/*/*.plymouth 2> /dev/null | tail -n 1) .plymouth)
        if [ $THEME_NAME = .plymouth ]; then
                rm -f ${DATADIR}/plymouth/themes/default.plymouth
                exit 0
        fi
fi

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

MODULE_NAME=$(grep "ModuleName *= *" ${DATADIR}/plymouth/themes/${THEME_NAME}/${THEME_NAME}.plymouth | sed 's/ModuleName *= *//')

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

(cd ${DATADIR}/plymouth/themes;
        ln -sf ${THEME_NAME}/${THEME_NAME}.plymouth default.plymouth && \
        ([ $DO_INITRD_REBUILD -ne 0 ] && \
           $LIBEXECDIR/plymouth/plymouth-update-initrd) || :)