core: add the splashy2fbsplash theme converter
[fbsplash.git] / core / scripts / splash_geninitramfs.in
blob9d75d21cacee9c575daf28ec3fc47e95ba93e6ed
1 #!/bin/bash
3 # splash_geninitramfs -- an utility to create initramfs images for use with fbsplash
5 # Copyright (C) 2004-2007, Michal Januszewski <spock@gentoo.org>
7 # This file is a part of the splashutils package.
9 # This file is subject to the terms and conditions of the GNU General Public
10 # License v2. See the file COPYING in the main directory of this archive for
11 # more details.
14 cleanup()
16 rm -rf ${workdir}
19 usage()
21 cat <<EOTB
22 splash_geninitramfs/splashutils-@PACKAGE_VERSION@
23 Usage: splash_geninitramfs [options] [--all|theme ...]
25 Main operation modes:
26 -g, --generate=IMG generate an initramfs image with all necessary files
27 -a, --append=IMG append a theme and helper files (if necessary)
28 to an initramfs image
29 -c, --copy=DIR copy all necessary files into the specified directory;
30 DIR should point to the root directory of an initramfs
31 -o, --overlay=DIR include the contents of DIR in the initramfs image
32 -h, --help show this help message
34 Options:
35 -r, --res=RES copy data for specific resolutions only; RES is a
36 comma-separated list of the resolutions for which the images
37 are to be copied
38 -v, --verbose verbose output
39 --no8bpp ignore 8bpp images (can save a lot of space)
40 EOTB
42 # -d use dynamically linked splash helper
45 printv()
47 if [ $verbose -gt 0 ]; then
48 echo "$*"
52 put_item()
54 item="$1"
56 if [ "${item:0:1}" == "/" ]; then
57 cp -pRH --parents "${item}" "${imgdir}"
58 else
59 cp -pRH --parents "${themedir}/${theme}/${item}" "${imgdir}"
63 themedir="@themedir@"
64 declare -a themes
65 mode="h"
66 splash_hlp="@sbindir@/fbcondecor_helper"
67 res=""
68 overlay=""
69 verbose=0
70 index=0
71 no8bpp=0
73 args="$@"
74 temp=`getopt -l no8bpp,all,generate:,append:,copy:,overlay:,help,verbose,res: a:g:c:r:o:hv "$@"`
76 if [ $? != 0 ]; then
77 usage; exit 2
80 eval set -- "$temp"
82 for i ; do
83 case "$i" in
84 -a|--append) mode='a'; img="$2"; shift; shift;;
85 -g|--generate) mode='g'; img="$2"; shift; shift;;
86 -c|--copy) mode='c'; destdir="$2"; shift; shift;;
87 -h|--help) usage; exit 2;;
88 -r|--res) res=${2/,/ }; shift; shift;;
89 -v|--verbose) verbose=$(($verbose + 1)); shift;;
90 -o|--overlay) overlay="$2"; shift; shift;;
91 --no8bpp) no8bpp=1; shift;;
92 --) shift; break;;
93 --all)
94 shift;
95 for i in ${themedir}/* ; do
96 if [ ! -d "$i" ] ; then
97 continue
99 themes[$index]="`basename "$i"`"
100 let "index++"
101 done;;
102 esac
103 done
105 if [ "$mode" == "h" ]; then
106 usage ; exit 2
109 if [ $index -eq 0 ]; then
110 for i ; do
111 themes[$index]="$i"
112 let "index++"
113 done
116 if [ $index -eq 0 ]; then
117 echo "No themes specified." 1>&2 ; exit 5
120 if [ "$mode" == "c" ]; then
121 if [ ! -d $destdir ]; then
122 echo "Destination directory does not exist." 1>&2 ; exit 3
124 imgdir=$destdir
125 else
126 if [ "$mode" == "a" ] && [ ! -e $img ]; then
127 echo "Specified image file does not exist." 1>&2 ; exit 4
130 workdir=${TMPDIR-/tmp}/splash.$$.$RANDOM
132 if (umask 077 && mkdir $workdir); then
133 trap "cleanup" EXIT
134 else
135 echo "Could not create temporary directory! Exiting." 1>&2 ; exit 1
139 if [ "$mode" != "c" ]; then
140 imgdir="${workdir}/img"
141 mkdir "${imgdir}"
144 if [ "$mode" == "a" ]; then
145 printv "o Unpacking $img.."
146 cp "$img" "${imgdir}"
147 (cd "${imgdir}"; (gunzip -c "$(basename $img)" 2>/dev/null || cat "$(basename $img)") | cpio -idm --no-absolute-filenames --quiet -H newc)
148 rm -f "${imgdir}/$(basename $img)"
151 printv "o Creating directory structure.."
152 mkdir -p ${imgdir}/{dev,dev/fb,dev/misc,dev/vc,$themedir,lib/splash/proc,root,sbin,lib/splash/sys}
154 if [ $EUID == 0 ]; then
155 [[ ! -e "${imgdir}/dev/null" ]] && mknod "${imgdir}/dev/null" c 1 3
156 [[ ! -e "${imgdir}/dev/console" ]] && mknod "${imgdir}/dev/console" c 5 1
157 [[ ! -e "${imgdir}/dev/tty0" ]] && mknod "${imgdir}/dev/tty0" c 4 0
158 else
159 echo "Since you are running this script as a non-root user, no device nodes" 1>&2
160 echo "will be created in the initramfs. Make sure your initramfs contains" 1>&2
161 echo "at least the following nodes: /dev/null, /dev/console, /dev/tty0." 1>&2
164 if [ ! -e ${splash_hlp} ]; then
165 echo "${splash_hlp} does not exist." 1>&2 ; exit 4
168 printv "o Copying ${splash_hlp}.."
169 cp "${splash_hlp}" "${imgdir}@sbindir@"
170 ln -sf "${splash_hlp}" "${imgdir}@sbindir@/splash_helper"
172 res=${res//,/ }
174 printv "o Copying themes.."
175 for (( i=0 ; i < index ; i++ )) ; do
176 theme=${themes[$i]}
178 printv " - ${theme}"
180 # check if the user specified which resolutions are accepted
181 # (default: all res)
182 if [ -z "$res" ]; then
183 res=$(cd ${themedir}/${theme} ; ls *cfg | sed -e 's/.cfg//g')
186 for j in $res ; do
187 if [ ! -e "${themedir}/${theme}/${j}.cfg" ]; then
188 echo "Warning: config file for theme '${theme}', resolution ${j} does not exist!" 1>&2
189 continue
192 cp -pRH --parents "${themedir}/${theme}/${j}.cfg" "${imgdir}"
194 if [[ ${no8bpp} == 0 ]]; then
195 t="[0-9*]"
196 else
197 t=""
200 # config file parsing
201 pics=`cat "${themedir}/${theme}/${j}.cfg" | \
202 sed -r -e "/(^(silent)?jpeg=)|(^(silent)?pic${t}*=)/! d" \
203 -e 's/[a-z0-9]+=(.*)/\1/'`
204 for pic in $pics ; do
205 put_item "${pic}"
206 done
208 icons=`cat "${themedir}/${theme}/${j}.cfg" | \
209 egrep -v '^#' | grep 'icon ' | awk '{print $2}'`
210 for icon in ${icons} ; do
211 put_item "${icon}"
212 done
214 fonts=`cat "${themedir}/${theme}/${j}.cfg" | \
215 egrep -v '^#' | grep 'text ' | grep -o '[^ ]\+\.ttf'`
216 for font in ${fonts} ; do
217 put_item "${font}"
218 done
220 font=`cat "${themedir}/${theme}/${j}.cfg" | egrep -v '^#' | grep 'text_font='`
221 font=${font#*=}
222 if [[ -n "${font}" ]]; then
223 put_item "${font}"
224 else
225 put_item "${themedir}/luxisri.ttf"
227 done
228 done
230 if [ -n "${overlay}" ]; then
231 printv "o Adding files from overlay: $overlay"
232 cp -pRH ${overlay}/* "${imgdir}"
235 printv "o Creating initramfs image.."
236 if [ "$mode" == "g" ] || [ "$mode" == "a" ]; then
237 (cd "${imgdir}" ; find . | cpio --quiet -o -H newc | gzip -9 >../img.cpio.gz)
238 mv "${workdir}/img.cpio.gz" "${img}"
241 exit 0
243 # vim: set ts=4 sts=4 :