diff options
author | Ray Strode <halfline@gmail.com> | 2021-09-27 10:27:11 +0000 |
---|---|---|
committer | Ray Strode <halfline@gmail.com> | 2021-09-27 10:27:11 +0000 |
commit | bad6d41504e82e889a5aad3a72fa7d38216f4197 (patch) | |
tree | 1742d06702e3fcbb295220a357ac99f58810cb8f | |
parent | dae14773bd3b9b86cdaeaab684191238a5eff21e (diff) | |
parent | 3003cabf96d2b8d993a54ee36e045f890d21ed99 (diff) |
main: add ThemePath configuration option
See merge request plymouth/plymouth!142
-rwxr-xr-x | scripts/plymouth-populate-initrd.in | 50 | ||||
-rw-r--r-- | src/libply/ply-utils.h | 2 | ||||
-rw-r--r-- | src/main.c | 71 |
3 files changed, 95 insertions, 28 deletions
diff --git a/scripts/plymouth-populate-initrd.in b/scripts/plymouth-populate-initrd.in index 0ff1f124..2703d483 100755 --- a/scripts/plymouth-populate-initrd.in +++ b/scripts/plymouth-populate-initrd.in @@ -18,6 +18,7 @@ [ -z "$PLYMOUTH_LOGO_FILE" ] && PLYMOUTH_LOGO_FILE="@PLYMOUTH_LOGO_FILE@" [ -n "$PLYMOUTH_THEME_NAME" ] && THEME_OVERRIDE=1 [ -z "$PLYMOUTH_THEME_NAME" ] && PLYMOUTH_THEME_NAME=$(plymouth-set-default-theme) +[ -n "$PLYMOUTH_CONFIGURED_DIR_PATH" ] && THEME_DIR_OVERRIDE=1 [ -z "$PLYMOUTH_CONFDIR" ] && PLYMOUTH_CONFDIR="@PLYMOUTH_CONF_DIR@" [ -z "$PLYMOUTH_POLICYDIR" ] && PLYMOUTH_POLICYDIR="@PLYMOUTH_POLICY_DIR@" [ -z "$PLYMOUTH_DAEMON_PATH" ] && PLYMOUTH_DAEMON_PATH="@PLYMOUTH_DAEMON_DIR@/plymouthd" @@ -374,6 +375,43 @@ inst_recur() { done } +# $1: Configuration file +# $2: Setting name +function read_setting_from_file() +{ + echo $(grep -v '^#' $1 2> /dev/null | + awk ' + BEGIN { + FS="[=[:space:]]+"; + OFS=""; + ORS="" + } + $1 ~/^'"$2"'$/ { print $2 } + ') +} + +# $1: Configuration file +function set_configured_theme_path_from_file() +{ + CONFIGURED_THEME_DIR=$(read_setting_from_file "$1" "ThemeDir") + CONFIGURED_THEME_NAME=$(read_setting_from_file "$1" "Theme") +} + +function set_theme_dir() +{ + set_configured_theme_path_from_file ${PLYMOUTH_CONFDIR}/plymouthd.conf + if [ -z "$CONFIGURED_THEME_DIR" ] || [ ! -d "$CONFIGURED_THEME_DIR/$CONFIGURED_THEME_NAME" ]; then + set_configured_theme_path_from_file ${PLYMOUTH_POLICYDIR}/plymouthd.defaults + fi + + if [ -n "$CONFIGURED_THEME_DIR" ] && [ -d "$CONFIGURED_THEME_DIR/$CONFIGURED_THEME_NAME" ]; then + PLYMOUTH_THEME_NAME=$CONFIGURED_THEME_NAME + PLYMOUTH_THEME_DIR=$CONFIGURED_THEME_DIR/$CONFIGURED_THEME_NAME + else + PLYMOUTH_THEME_DIR=$PLYMOUTH_DATADIR/plymouth/themes/$PLYMOUTH_THEME_NAME + fi +} + function usage() { local output="/proc/self/fd/1" local rc=0 @@ -432,6 +470,9 @@ if [ -z "$PLYMOUTH_THEME_NAME" ]; then exit 1 fi +set_theme_dir +mkdir -p ${INITRDDIR}${PLYMOUTH_THEME_DIR} + if [ $THEME_OVERRIDE ]; then conf=$INITRDDIR/${PLYMOUTH_CONFDIR}/plymouthd.conf echo "modifying plymouthd.conf: Theme=$PLYMOUTH_THEME_NAME" >&2 @@ -439,10 +480,15 @@ if [ $THEME_OVERRIDE ]; then grep -q "^ *\[Daemon\]" $conf || echo "[Daemon]" >> $conf grep -q "^ *Theme *=" $conf || echo "Theme=fade-in" >> $conf sed -i "s/^ *Theme *=.*/# theme modified by plymouth-populate-initrd\nTheme=$PLYMOUTH_THEME_NAME/" $conf + if [ "$THEME_DIR_OVERRIDE" ]; then + echo "modifying plymouthd.conf: ThemeDir=$PLYMOUTH_CONFIGURED_DIR_PATH" >&2 + grep -q "^ *ThemeDir *=" $conf || echo "ThemeDir=/some/path" >> $conf + sed -i "s@^ *ThemeDir *=.*@# theme dir modified by plymouth-populate-initrd\nThemeDir=$PLYMOUTH_CONFIGURED_DIR_PATH@" $conf + PLYMOUTH_THEME_DIR=${PLYMOUTH_CONFIGURED_DIR_PATH} + fi fi -PLYMOUTH_MODULE_NAME=$(grep "ModuleName *= *" ${PLYMOUTH_SYSROOT}${PLYMOUTH_DATADIR}/plymouth/themes/${PLYMOUTH_THEME_NAME}/${PLYMOUTH_THEME_NAME}.plymouth | sed 's/ModuleName *= *//') -PLYMOUTH_THEME_DIR="${PLYMOUTH_DATADIR}/plymouth/themes/${PLYMOUTH_THEME_NAME}" +PLYMOUTH_MODULE_NAME=$(grep "ModuleName *= *" ${PLYMOUTH_SYSROOT}${PLYMOUTH_THEME_DIR}/${PLYMOUTH_THEME_NAME}.plymouth | sed 's/ModuleName *= *//') PLYMOUTH_IMAGE_DIR=$(grep "ImageDir *= *" ${PLYMOUTH_SYSROOT}${PLYMOUTH_THEME_DIR}/${PLYMOUTH_THEME_NAME}.plymouth | sed 's/ImageDir *= *//') if [ ! -f ${PLYMOUTH_SYSROOT}${PLYMOUTH_PLUGIN_PATH}/${PLYMOUTH_MODULE_NAME}.so ]; then diff --git a/src/libply/ply-utils.h b/src/libply/ply-utils.h index d7b76221..47bb3f24 100644 --- a/src/libply/ply-utils.h +++ b/src/libply/ply-utils.h @@ -39,6 +39,8 @@ #define CLAMP(a, b, c) (MIN (MAX ((a), (b)), (c))) #endif +#define PLY_NUMBER_OF_ELEMENTS(arr) (sizeof (arr) / sizeof ((arr)[0])) + #define PLY_UTF8_CHARACTER_SIZE_MAX 4 typedef intptr_t ply_module_handle_t; @@ -262,6 +262,35 @@ show_messages (state_t *state) } static bool +get_theme_path (const char *splash_string, + const char *configured_theme_dir, + char **theme_path) +{ + const char *paths[] = { PLYMOUTH_RUNTIME_THEME_PATH, + configured_theme_dir, + PLYMOUTH_THEME_PATH }; + size_t i; + + for (i = 0; i < PLY_NUMBER_OF_ELEMENTS (paths); ++i) { + if (paths[i] == NULL) + continue; + + asprintf (theme_path, + "%s/%s/%s.plymouth", + paths[i], splash_string, splash_string); + if (ply_file_exists (*theme_path)) { + ply_trace ("Theme is %s", *theme_path); + return true; + } + ply_trace ("Theme %s not found", *theme_path); + free (*theme_path); + *theme_path = NULL; + } + + return false; +} + +static bool load_settings (state_t *state, const char *path, char **theme_path) @@ -280,17 +309,11 @@ load_settings (state_t *state, splash_string = ply_key_file_get_value (key_file, "Daemon", "Theme"); if (splash_string != NULL) { - asprintf (theme_path, - PLYMOUTH_RUNTIME_THEME_PATH "%s/%s.plymouth", - splash_string, splash_string); - ply_trace ("Checking if %s exists", *theme_path); - if (!ply_file_exists (*theme_path)) { - ply_trace ("%s not found, fallbacking to " PLYMOUTH_THEME_PATH, - *theme_path); - asprintf (theme_path, - PLYMOUTH_THEME_PATH "%s/%s.plymouth", - splash_string, splash_string); - } + char *configured_theme_dir; + configured_theme_dir = ply_key_file_get_value (key_file, "Daemon", + "ThemeDir"); + get_theme_path (splash_string, configured_theme_dir, theme_path); + free (configured_theme_dir); } if (isnan (state->splash_delay)) { @@ -354,19 +377,9 @@ find_override_splash (state_t *state) if (splash_string != NULL) { ply_trace ("Splash is configured to be '%s'", splash_string); - asprintf (&state->override_splash_path, - PLYMOUTH_RUNTIME_THEME_PATH "%s/%s.plymouth", - splash_string, splash_string); - - ply_trace ("Checking if %s exists", state->override_splash_path); - if (!ply_file_exists (state->override_splash_path)) { - ply_trace ("%s not found, fallbacking to " PLYMOUTH_THEME_PATH, - state->override_splash_path); - free (state->override_splash_path); - asprintf (&state->override_splash_path, - PLYMOUTH_THEME_PATH "%s/%s.plymouth", - splash_string, splash_string); - } + + get_theme_path (splash_string, NULL, &state->override_splash_path); + free (splash_string); } @@ -402,7 +415,8 @@ find_system_default_splash (state_t *state) return; } - ply_trace ("System configured theme file is '%s'", state->system_default_splash_path); + if (state->system_default_splash_path != NULL) + ply_trace ("System configured theme file is '%s'", state->system_default_splash_path); } static void @@ -419,7 +433,8 @@ find_distribution_default_splash (state_t *state) } } - ply_trace ("Distribution default theme file is '%s'", state->distribution_default_splash_path); + if (state->distribution_default_splash_path != NULL) + ply_trace ("Distribution default theme file is '%s'", state->distribution_default_splash_path); } static void @@ -2357,6 +2372,10 @@ main (int argc, ply_free_error_log (); + free (state.override_splash_path); + free (state.system_default_splash_path); + free (state.distribution_default_splash_path); + return exit_code; } /* vim: set ts=4 ts=4 sw=4 expandtab autoindent cindent cino={.5s,(0: */ |