Filter prohibited characters of ISO label for FAT32 partition label

Fixes #34
This commit is contained in:
ValdikSS 2022-12-07 01:41:57 +03:00
parent 1de605529a
commit 6249a7fc98

View File

@ -26,7 +26,7 @@ dirpath="$(dirname "$scriptpath")"
function check_requirements() { function check_requirements() {
local reqs=(awk lsblk 7z mkfs.vfat mkfs.ntfs sfdisk ms-sys mktemp wimsplit) local reqs=(awk lsblk 7z mkfs.vfat mkfs.ntfs sfdisk ms-sys mktemp wimsplit tr)
for req in ${reqs[*]}; do for req in ${reqs[*]}; do
if ! command -v "$req" > /dev/null; if ! command -v "$req" > /dev/null;
@ -76,6 +76,12 @@ function get_iso_name() {
7z l "$1" | awk '/Comment = / {print $3; exit 0}' 7z l "$1" | awk '/Comment = / {print $3; exit 0}'
} }
function sanitize_iso_name() {
# FAT32 does not allow certain characters in names, see
# https://github.com/dosfstools/dosfstools/blob/1da41f0e70dcbfb874e8191c639b91fa58205ea4/src/fatlabel.c#L96
echo "$1" | tr -d '*?.,;:/\\|+=<>[]"'
}
function check_installwim_gt4gib() { function check_installwim_gt4gib() {
7z l "$1" | awk 'BEGIN {doend=1} ($6 ~ /install.wim/) {if ($4 > 4294967296) {doend=0; exit 0}; doend=0; exit 1} END {if (doend) {exit 1}}' 7z l "$1" | awk 'BEGIN {doend=1} ($6 ~ /install.wim/) {if ($4 > 4294967296) {doend=0; exit 0}; doend=0; exit 1} END {if (doend) {exit 1}}'
} }
@ -257,6 +263,8 @@ then
# MBR FAT32 # MBR FAT32
if [[ "$labeltype" == "mbr" ]]; if [[ "$labeltype" == "mbr" ]];
then then
isolabel="$(sanitize_iso_name "$isolabel")"
echo "${bold} == Creating new MBR-formatted partition table ==${normal}" echo "${bold} == Creating new MBR-formatted partition table ==${normal}"
format_drive "dos" "$dev" format_drive "dos" "$dev"
@ -274,6 +282,8 @@ then
# GPT FAT32 # GPT FAT32
elif [[ "$labeltype" == "gpt" ]]; elif [[ "$labeltype" == "gpt" ]];
then then
isolabel="$(sanitize_iso_name "$isolabel")"
echo "${bold} == Creating new GPT-formatted partition table ==${normal}" echo "${bold} == Creating new GPT-formatted partition table ==${normal}"
format_drive "gpt" "$dev" format_drive "gpt" "$dev"