Mostly minor fixes up until version 0.8.10.
[irreco.git] / themes / theme-conf-gen.sh
blob1a8a32c9b8be3c1aaf4976d7bc4740fa0f593597
1 #!/bin/bash
3 SELF="$0"
4 SELF_ABSOLUTE=`readlink -f "$0"`
7 # Script for generating irreco config files for buttons themes.
10 theme_gen_main()
12 COMMAND="$1"
13 ARGS=("$@")
15 case "$COMMAND" in
16 --generate|generate|gen) theme_gen_erate "${ARGS[@]:1}";;
17 *) theme_gen_help;;
18 esac
21 theme_gen_help()
23 echo "Usage: $SELF COMMAND"
24 echo ""
25 echo "Commands:"
26 echo " --generate | generate | gen SOURCE DESTINATION"
27 echo " Generate configuration files and directory structures"
28 echo " for so that Irreco will correctly read the theme."
31 theme_gen_erate()
33 SOURCE="$1"
35 THEME_NAME="$( cat "$SOURCE"/name )"
36 THEME_DIR_NAME="$( theme_gen_dir_name "$THEME_NAME" )"
38 DESTINATION="$2"
39 IRRECO_DIR="$DESTINATION/lib/irreco"
40 THEME_DIR="$IRRECO_DIR/themes/$THEME_DIR_NAME"
41 BUTTON_DIR="$THEME_DIR/buttons"
42 BG_DIR="$THEME_DIR/bg"
44 [[ "$SOURCE" == "" ]] && theme_gen_error \
45 "Source directory not given."
47 [[ "$DESTINATION" == "" ]] && theme_gen_error \
48 "Destination directory not given."
50 [ ! -d "$SOURCE" ] && theme_gen_error \
51 "Source directory does not exist, is not a directory."
53 #[ -e "$DESTINATION" ] && theme_gen_error \
54 # "Destination already exists. Will not overwrite."
56 [ ! -f "$SOURCE"/name ] && theme_gen_error \
57 "Theme name file does not exist."
60 THEME_PREFIX=`basename "$( realpath -f $SOURCE )"`
61 BUTTONDIR="$SOURCE/buttons"
62 BGDIR="$SOURCE/bg"
64 echo "Source: \"$SOURCE\""
65 echo "Buttondir: \"$BUTTONDIR\""
66 echo "Bgdir: \"$BGDIR\""
67 echo "Destination: \"$DESTINATION\""
68 echo "Theme name: \"$THEME_NAME\""
69 echo "Theme dir: \"$THEME_DIR\""
70 echo "Theme prefix: \"$THEME_PREFIX\""
72 if [ ! -d "$DESTINATION" ]; then
73 mkdir "$DESTINATION"
74 check_exit_code "$?"
77 mkdir -p "$BUTTON_DIR"
78 check_exit_code "$?"
79 mkdir -p "$BG_DIR"
80 check_exit_code "$?"
82 echo
83 echo "Creating theme config."
84 theme_gen_theme_config > "$THEME_DIR/theme.conf"
86 echo
87 echo "Installing backgrounds:"
88 if [ -d "$BGDIR" ]; then
89 theme_gen_bg_list | theme_gen_bg_parse
92 echo
93 echo "Installing buttonstyles:"
94 theme_gen_button_list | theme_gen_button_parse
96 #echo
97 #echo "Destination file list:"
98 #cd "$DESTINATION" && find | sort
102 # Generates a lower case name, and replaces spaces with underscores.
104 theme_gen_dir_name()
106 echo "$1" | tr [:upper:] [:lower:] | tr [:blank:] _
109 theme_gen_theme_config()
111 echo "[theme]"
112 echo "name=$THEME_NAME"
113 echo "source=deb"
116 theme_gen_bg_list()
118 cd "$BGDIR"
119 ls -1 | grep '.png$' | sed -r 's/.png//'
122 theme_gen_bg_parse()
124 while read LINE; do
125 echo "Generating: \"$LINE\""
127 DEST_BG_DIR="$( theme_gen_dir_name "$LINE" )"
128 DEST_IMAGE="$DEST_BG_DIR"/image.png
129 DEST_CONFIG="$DEST_BG_DIR"/bg.conf
130 BG_NAME="$LINE"
132 # Copy image.
133 mkdir -p "$BG_DIR"/"$DEST_BG_DIR"
134 cp "$BGDIR"/"$BG_NAME".png \
135 "$BG_DIR"/"$DEST_IMAGE"
136 check_exit_code "$?"
138 # Create configuration.
139 theme_gen_bg_config > "$BG_DIR"/"$DEST_CONFIG"
140 check_exit_code "$?"
141 done
144 theme_gen_bg_config()
146 echo "[theme-bg]"
148 if [[ "$BG_NAME" != "" ]]; then
149 echo "name=$BG_NAME"
152 echo "image=image.png"
155 theme_gen_button_list()
157 cd "$BUTTONDIR"
158 ls -1 | grep '.png$' | sed -r 's/_(pressed|unpressed).png//' | uniq
161 theme_gen_button_parse()
163 while read LINE; do
164 echo -n "Generating: \"$LINE\""
166 DEST_PRESSED="$LINE"/pressed.png
167 DEST_UNPRESSED="$LINE"/unpressed.png
168 DEST_CONFIG="$LINE"/button.conf
169 CONFIG_APPEND="$BUTTONDIR"/"$LINE"_config_append
171 case "$LINE" in
172 down) BUTTON_NAME="Down"
173 ALLOW_TEXT="false";;
174 left) BUTTON_NAME="Left"
175 ALLOW_TEXT="false";;
176 next) BUTTON_NAME="Next"
177 ALLOW_TEXT="false";;
178 pause) BUTTON_NAME="Pause"
179 ALLOW_TEXT="false";;
180 play) BUTTON_NAME="Play"
181 ALLOW_TEXT="false";;
182 playpause) BUTTON_NAME="Play / Pause"
183 ALLOW_TEXT="false";;
184 power) BUTTON_NAME="Power"
185 ALLOW_TEXT="false";;
186 prev) BUTTON_NAME="Prev"
187 ALLOW_TEXT="false";;
188 right) BUTTON_NAME="Right"
189 ALLOW_TEXT="false";;
190 up) BUTTON_NAME="Up"
191 ALLOW_TEXT="false";;
192 menu) BUTTON_NAME="Menu"
193 ALLOW_TEXT="false";;
194 ok) BUTTON_NAME="OK"
195 ALLOW_TEXT="false";;
196 blank) BUTTON_NAME="Blank"
197 ALLOW_TEXT="true";;
198 num_0) BUTTON_NAME="Number 0"
199 ALLOW_TEXT="false";;
200 num_1) BUTTON_NAME="Number 1"
201 ALLOW_TEXT="false";;
202 num_2) BUTTON_NAME="Number 2"
203 ALLOW_TEXT="false";;
204 num_3) BUTTON_NAME="Number 3"
205 ALLOW_TEXT="false";;
206 num_4) BUTTON_NAME="Number 4"
207 ALLOW_TEXT="false";;
208 num_5) BUTTON_NAME="Number 5"
209 ALLOW_TEXT="false";;
210 num_6) BUTTON_NAME="Number 6"
211 ALLOW_TEXT="false";;
212 num_7) BUTTON_NAME="Number 7"
213 ALLOW_TEXT="false";;
214 num_8) BUTTON_NAME="Number 8"
215 ALLOW_TEXT="false";;
216 num_9) BUTTON_NAME="Number 9"
217 ALLOW_TEXT="false";;
218 *) grep '^name=' "$CONFIG_APPEND" > /dev/null
219 if [[ "$?" != "0" ]]; then
220 echo "Error: Custom button type without name."
221 echo "Unknown file: \"$LINE\"";
222 exit 1
225 esac;
227 # Copy unpressed image.
228 mkdir -p "$BUTTON_DIR"/"$LINE"
229 cp "$BUTTONDIR"/"$LINE"_unpressed.png \
230 "$BUTTON_DIR"/"$DEST_UNPRESSED"
231 check_exit_code "$?"
233 # Copy pressed image.
234 if [ -e "$BUTTONDIR"/"$LINE"_pressed.png ]; then
235 cp "$BUTTONDIR"/"$LINE"_pressed.png \
236 "$BUTTON_DIR"/"$DEST_PRESSED"
237 check_exit_code "$?"
238 PRESSED_EXITST='yes'
239 else
240 PRESSED_EXITST='no'
243 theme_gen_button_config > "$BUTTON_DIR"/"$DEST_CONFIG"
244 check_exit_code "$?"
246 #echo "$CONFIG_APPEND"
247 if [ -f "$CONFIG_APPEND" ]; then
248 echo -n " ... appeding config"
249 cat "$CONFIG_APPEND" >> "$BUTTON_DIR"/"$DEST_CONFIG"
250 check_exit_code "$?"
253 echo
254 done
257 theme_gen_button_config()
259 echo "[theme-button]"
261 if [[ "$BUTTON_NAME" != "" ]]; then
262 echo "name=$BUTTON_NAME"
265 if [[ "$ALLOW_TEXT" != "" ]]; then
266 echo "allow-text=$ALLOW_TEXT"
269 echo "up=unpressed.png"
271 if [[ "$PRESSED_EXITST" == "yes" ]]; then
272 echo "down=pressed.png"
277 # Stop script if exit code is not 0
279 # Usage: check_exit_code "$?"
281 check_exit_code()
283 if [[ "$1" != "0" ]]; then
284 echo "Exit code: $1"
285 exit "$1"
289 theme_gen_error()
291 echo "Error:" "$@"
292 exit 1
295 theme_gen_main "$@"