-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathbios-image-format.sh
More file actions
executable file
·80 lines (69 loc) · 2.06 KB
/
bios-image-format.sh
File metadata and controls
executable file
·80 lines (69 loc) · 2.06 KB
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
#!/usr/bin/env bash
#
# Convert any image into appropriate dimensions and color profile for BIOS splash screen
#
# Josh Boudreau 2025 <jboudreau@45drives.com>
if ! command -v convert >/dev/null; then
echo "Missing 'convert' from imagemagick!" >&2
exit 1
fi
# MANUFACTURER WIDTH HEIGHT COLOR_FORMAT BIT_DEPTH IMAGE_FORMAT
MFR_LUT='
SUPERMICRO 1024 768 truecolor 8 bmp
GIGABYTE 1024 768 truecolor 8 bmp
ASROCK 800 600 truecolor 8 jpg
AMI 300 300 truecolor 8 bmp
'
usage() {
printf 'Usage: %s [ -h ] MANUFACTURER IMAGE OUTPUT\n' "$0"
echo
echo 'Options:'
echo ' -h - Print this message'
echo ' -b BG_COLOR - Set background fill color, default = black'
echo ' MANUFACTURER - Mobo manufacturer'
echo ' IMAGE - input image file'
echo ' OUTPUT - output image file (extension auto added)'
echo
echo 'MANUFACTURER values:'
awk '/.+/{print " " $1}' <<<"$MFR_LUT"
}
BG=black
while getopts 'hb:' opt; do
case $opt in
h)
usage
exit 0
;;
b)
BG="$OPTARG"
;;
*)
usage >&2 # print to stderr
exit 2 # exit with usage error (2)
;;
esac
done
shift $((OPTIND - 1)) # after this line, $@ will contain remaining non-option arguments
if [ $# -lt 3 ]; then
echo "Not enough arguments!" >&2
usage >&2
exit 2
fi
MFR=$(echo "$1" | tr '[:lower:]' '[:upper:]')
INPUT=$2
OUTPUT=$3
if ! grep "$MFR" >/dev/null <<<"$MFR_LUT"; then
echo "Invalid manufacturer: $MFR"
echo "valid manufacturers:"
awk '/.+/{print $1}' <<<"$MFR_LUT"
exit 2
fi
WIDTH=$(awk '/^'"$MFR"'/{print $2}' <<<"$MFR_LUT")
HEIGHT=$(awk '/^'"$MFR"'/{print $3}' <<<"$MFR_LUT")
TYPE=$(awk '/^'"$MFR"'/{print $4}' <<<"$MFR_LUT")
DEPTH=$(awk '/^'"$MFR"'/{print $5}' <<<"$MFR_LUT")
EXT=$(awk '/^'"$MFR"'/{print $6}' <<<"$MFR_LUT")
if [[ "$OUTPUT" != *."$EXT" ]]; then
OUTPUT="$OUTPUT"."$EXT"
fi
convert "$INPUT" -background "$BG" -flatten +matte -resize "${WIDTH}x${HEIGHT}" -gravity center -extent "${WIDTH}x${HEIGHT}" -type "$TYPE" -depth "$DEPTH" "$OUTPUT"