-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimage_format.sh
executable file
·66 lines (57 loc) · 1.89 KB
/
image_format.sh
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
#!/bin/sh
IMAGE_FORMAT_PREFIX="IMAGE_FOMAT:"
IMAGE_FORMAT_RAW="raw"
IMAGE_FORMAT_RAW_MIME="application/octet-stream"
IMAGE_FORMAT_RAW_CMD="cat"
IMAGE_FORMAT_XZ="xz"
IMAGE_FORMAT_XZ_MIME="application/x-xz"
IMAGE_FORMAT_XZ_CMD="xz -cdk"
IMAGE_FORMAT_GZIP="gzip"
IMAGE_FORMAT_GZIP_MIME="application/gzip"
IMAGE_FORMAT_GZIP_CMD="gzip -cdk"
IMAGE_FORMAT_ZIP="zip"
IMAGE_FORMAT_ZIP_MIME="application/zip"
IMAGE_FORMAT_ZIP_CMD="unzip -p"
IMAGE_FORMAT_LZ4="lz4"
IMAGE_FORMAT_LZ4_MIME="application/x-lz4"
IMAGE_FORMAT_LZ4_CMD="lz4 -cdk"
IMAGE_FORMAT_ZSTD="zstd"
IMAGE_FORMAT_ZSTD_MIME="application/zstd"
IMAGE_FORMAT_ZSTD_CMD="zstd -cdk"
function IMAGE_FORMAT_detect(){
image_format_detect=$(file -b --mime-type "$1")
if [ "$image_format_detect" = "$IMAGE_FORMAT_RAW_MIME" ]; then
echo $IMAGE_FORMAT_RAW
elif [ "$image_format_detect" = "$IMAGE_FORMAT_XZ_MIME" ]; then
echo $IMAGE_FORMAT_XZ
elif [ "$image_format_detect" = "$IMAGE_FORMAT_GZIP_MIME" ]; then
echo $IMAGE_FORMAT_GZIP
elif [ "$image_format_detect" = "$IMAGE_FORMAT_ZIP_MIME" ]; then
echo $IMAGE_FORMAT_ZIP
elif [ "$image_format_detect" = "$IMAGE_FORMAT_LZ4_MIME" ]; then
echo $IMAGE_FORMAT_LZ4
elif [ "$image_format_detect" = "$IMAGE_FORMAT_ZSTD_MIME" ]; then
echo $IMAGE_FORMAT_ZSTD
else
echo "$IMAGE_FORMAT_PREFIX detect $image_format_detect is not supported." >&2
return 1
fi
}
function IMAGE_FORMAT_getDecCMD(){
if [ "$1" = "$IMAGE_FORMAT_RAW" ]; then
echo "$IMAGE_FORMAT_RAW_CMD"
elif [ "$1" = "$IMAGE_FORMAT_XZ" ]; then
echo "$IMAGE_FORMAT_XZ_CMD"
elif [ "$1" = "$IMAGE_FORMAT_GZIP" ]; then
echo "$IMAGE_FORMAT_GZIP_CMD"
elif [ "$1" = "$IMAGE_FORMAT_ZIP" ]; then
echo "$IMAGE_FORMAT_ZIP_CMD"
elif [ "$1" = "$IMAGE_FORMAT_LZ4" ]; then
echo "$IMAGE_FORMAT_LZ4_CMD"
elif [ "$1" = "$IMAGE_FORMAT_ZSTD" ]; then
echo "$IMAGE_FORMAT_ZSTD_CMD"
else
echo "$IMAGE_FORMAT_PREFIX cmddec $1 is not supported." >&2
return 1
fi
}