All pastes #212954 Raw Edit

Unnamed

public text v1 · immutable
#212954 ·published 2006-10-21 03:40 UTC
rendered paste body
#!/bin/bash

# $Id: rc_init-pre,v 0.9.3 2006/01/28 17:00:00 wolfwood Exp $
#
# rc_init-pre 0.9.3 - A splashutils icon handler script for gentoo-livecd-2006.0.
# http://starwind.homelinux.com/
#
# Copyright (c) 2005-2006 Blackace Enterprises
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the Artistic License as approved
# by the Open Source Initiative.
#
# THIS PACKAGE IS PROVIDED AS IS AND WITHOUT ANY EXPRESS OR IMPLIED
# WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
# MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. See the
# Artistic License as approved by the Open Source Initiative for
# details.
#

# SCRIPT COMMANDS
C_BASH="/bin/bash"
C_CP="/bin/cp"
C_FBRES="/sbin/fbres"
C_MKDIR="/bin/mkdir"
C_MOUNT="/bin/mount"
C_MV="/bin/mv"
C_SED="/bin/sed"
C_TOUCH="/bin/touch"
C_UMOUNT="/bin/umount"

# SCRIPT OPTIONS
O_LOGINFO="/bin/cat >/dev/console"
O_LOGERR="/bin/cat >/dev/console"

# SCRIPT PROPERTIES
P_ERROR="0"
P_THEMEDIR="/etc/splash/${SPLASH_THEME}/"
P_TEMPDIR="${P_THEMEDIR%/}/temp/"
P_ICONW="72"
P_ICONH="72"
P_ICONX="0"
P_ICONY="-72"
P_ICONS=" $( \
  for file in ${P_THEMEDIR%/}/icons/unlit_*.png; do
    file="${file##*/}"
    file="${file#unlit_}"
    echo -n "${file%.png} "
  done \
)"

# SCRIPT ERROR CODES
E_OPT="65"
E_RESOLUTION="1"
E_TEMPDIR="2"
E_SVCDIR="3"

# FUNCTIONS
log() {
  if [ "${1}" = "info" ]; then
    if [ -n "${O_LOGINFO}" -a -x "${O_LOGINFO%% *}" ]; then
      echo "${2}" | eval ${O_LOGINFO}
    else
      echo "${2}"
    fi
  fi
  if [ "${1}" = "err" ]; then
    if [ -n "${O_LOGERR}" -a -x "${O_LOGERR%% *}" ]; then
      echo "${2}" | eval ${O_LOGERR}
    else
      echo "${2}" >&2
    fi
  fi
  if [ "${1}" != "info" -a "${1}" != "err" ]; then
    return 1
  fi
  return 0
}

. /sbin/functions.sh

if [ -z "${1}" ]; then
  log err "no internal runlevel provided"
  exit "${E_OPT}"
elif [ "${1}" != "sysinit" -o "${RUNLEVEL}" != "S" ]; then
  exit 0
fi

P_RESOLUTION="$($C_FBRES)"
if [ -n "${P_RESOLUTION}" -a -n "${P_ICONW}" -a -n "${P_ICONH}" -a -n "${P_ICONX}" -a -n "${P_ICONY}" ]; then
  if [ "${P_ICONX:0:1}" = "-" ]; then
    P_ICONX="$((${P_RESOLUTION%x*} - ${P_ICONX:1}))"
  elif [ "${P_ICONX:0:1}" = "+" ]; then
    P_ICONX="${P_ICONX:1}"
  fi
  if [ "${P_ICONY:0:1}" = "-" ]; then
    P_ICONY="$((${P_RESOLUTION#*x} - ${P_ICONY:1}))"
  elif [ "${P_ICONY:0:1}" = "+" ]; then
    P_ICONY="${P_ICONY:1}"
  fi
else
  log err "failed to configure resolution and icon positioning"
  exit "${E_RESOLUTION}"
fi

if [ ! -d "${P_TEMPDIR%/}/" ]; then
  $C_MKDIR "${P_TEMPDIR%/}/" && $C_TOUCH "${P_TEMPDIR%/}/.keep"
  if [ "$?" -ne "0" ]; then
    log err "failed to make tempdir"
    exit "${E_TEMPDIR}"
  fi
fi

if [ "${P_ERROR}" -eq "0" ]; then
  $C_MOUNT -t tmpfs none "${P_TEMPDIR%/}/"
  if [ "$?" -ne "0" ]; then
    log err "failed to mount tempdir"
    P_ERROR="${E_TEMPDIR}"
  fi
fi

if [ "${P_ERROR}" -eq "0" ]; then
  $C_CP -dpRx $(for file in ${P_THEMEDIR%/}/*; do if [ "${file##*/}" != "temp" ]; then echo -n "${file} "; fi; done) "${P_TEMPDIR%/}/"
  if [ "$?" -ne "0" ]; then
    log err "failed to populate tempdir"
    P_ERROR="${E_TEMPDIR}"
  fi
fi

if [ "${P_ERROR}" -eq "0" ]; then
  $C_CP "${P_TEMPDIR%/}/${P_RESOLUTION}.cfg" "${P_TEMPDIR%/}/${P_RESOLUTION}-core.cfg"
  if [ "$?" -ne "0" ]; then
    log err "failed to populate tempdir"
    P_ERROR="${E_TEMPDIR}"
  fi
fi

if [ "${P_ERROR}" -eq "0" ]; then
  P_SERVICES="$(splash_svclist_get start)"
  for service in ${P_SERVICES}; do
    if [ -z "${P_ICONS/* ${service} */}" ]; then
      echo -e "icon icons/unlit_${service}.png ${P_ICONX} ${P_ICONY} svc_start ${service}\nicon icons/unlit_${service}.png ${P_ICONX} ${P_ICONY} svc_inactive_start ${service}" >>"${P_TEMPDIR%/}/${P_RESOLUTION}.cfg"
      if [ "${P_ICONX}" -eq "0" ]; then
        echo -e "icon icons/lit_${P_RESOLUTION}_${P_ICONX}.png ${P_ICONX} $((${P_ICONY} - 34)) svc_started ${service}\nicon icons/lit_${P_RESOLUTION}_${P_ICONX}.png ${P_ICONX} $((${P_ICONY} - 34)) svc_start_failed ${service}" >>"${P_TEMPDIR%/}/${P_RESOLUTION}.cfg"
      else
        echo -e "icon icons/lit_${P_RESOLUTION}_${P_ICONX}.png $((${P_ICONX} - 4)) $((${P_ICONY} - 34)) svc_started ${service}\nicon icons/lit_${P_RESOLUTION}_${P_ICONX}.png $((${P_ICONX} - 4)) $((${P_ICONY} - 34)) svc_start_failed ${service}" >>"${P_TEMPDIR%/}/${P_RESOLUTION}.cfg"
      fi
      P_ICONX="$((${P_ICONX} + ${P_ICONW}))"
    fi
    if [ "$((${P_ICONX} + ${P_ICONW}))" -gt "$((${P_RESOLUTION%x*} - 40))" ]; then
      break
    fi
  done
fi

if [ "${P_ERROR}" -eq "0" ]; then
  $C_MOUNT --move "${P_TEMPDIR%/}" "${P_THEMEDIR%/}"
  if [ "$?" -ne "0" ]; then
    $C_UMOUNT -l "${P_TEMPDIR%/}/" 2>/dev/null
    $C_UMOUNT -l "${P_THEMEDIR%/}/" 2>/dev/null
    log err "failed to move tempdir mount"
    P_ERROR="${E_TEMPDIR}"
  fi
else
  $C_UMOUNT -l "${P_TEMPDIR%/}/" 2>/dev/null
fi

exit "${P_ERROR}"