Fix most shellcheck complaints
This commit is contained in:
parent
7b507c6c99
commit
7ae44e8e37
122
convert.sh
122
convert.sh
@ -1,17 +1,19 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
scriptName="UUP Converter v0.7.2"
|
scriptName="UUP Converter v0.7.2"
|
||||||
UUP_CONVERTER_SCRIPT=1
|
export UUP_CONVERTER_SCRIPT=1
|
||||||
|
|
||||||
export PATH=${PATH}:/usr/sbin
|
export PATH=${PATH}:/usr/sbin
|
||||||
|
|
||||||
if [ -f `dirname $0`/convert_ve_plugin ]; then
|
BASE_DIR=$(dirname "$0")
|
||||||
. `dirname $0`/convert_ve_plugin
|
|
||||||
|
if [ -f "$BASE_DIR"/convert_ve_plugin ]; then
|
||||||
|
. "$BASE_DIR"/convert_ve_plugin
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -f `dirname $0`/convert_config_linux ] && [ `uname` == "Linux" ]; then
|
if [ -f "$BASE_DIR"/convert_config_linux ] && [ "$(uname)" == "Linux" ]; then
|
||||||
. `dirname $0`/convert_config_linux
|
. "$BASE_DIR"/convert_config_linux
|
||||||
elif [ -f `dirname $0`/convert_config_macos ] && [ `uname` == "Darwin" ]; then
|
elif [ -f "$BASE_DIR"/convert_config_macos ] && [ "$(uname)" == "Darwin" ]; then
|
||||||
. `dirname $0`/convert_config_macos
|
. "$BASE_DIR"/convert_config_macos
|
||||||
else
|
else
|
||||||
VIRTUAL_EDITIONS_LIST="CoreSingleLanguage Enterprise EnterpriseN Education \
|
VIRTUAL_EDITIONS_LIST="CoreSingleLanguage Enterprise EnterpriseN Education \
|
||||||
EducationN ProfessionalEducation ProfessionalEducationN \
|
EducationN ProfessionalEducation ProfessionalEducationN \
|
||||||
@ -276,7 +278,7 @@ infoColor="\033[1;94m"
|
|||||||
errorColor="\033[1;91m"
|
errorColor="\033[1;91m"
|
||||||
resetColor="\033[0m"
|
resetColor="\033[0m"
|
||||||
|
|
||||||
if [ "$1" == "-?" -o "$1" == "--help" -o "$1" == "-h" ]; then
|
if [ "$1" == "-?" ] || [ "$1" == "--help" ] || [ "$1" == "-h" ]; then
|
||||||
echo "Usage:"
|
echo "Usage:"
|
||||||
echo "$0 [compression] [uups_directory] [create_virtual_editions]"
|
echo "$0 [compression] [uups_directory] [create_virtual_editions]"
|
||||||
echo ""
|
echo ""
|
||||||
@ -288,9 +290,9 @@ if [ "$1" == "-?" -o "$1" == "--help" -o "$1" == "-h" ]; then
|
|||||||
echo "0 - do not create virtual editions (default)"
|
echo "0 - do not create virtual editions (default)"
|
||||||
echo "1 - create virtual edtitions"
|
echo "1 - create virtual edtitions"
|
||||||
echo ""
|
echo ""
|
||||||
if [ `uname` == "Linux" ]; then
|
if [ "$(uname)" == "Linux" ]; then
|
||||||
echo -e "${infoColor}convert_config_linux file${resetColor}"
|
echo -e "${infoColor}convert_config_linux file${resetColor}"
|
||||||
elif [ `uname` == "Darwin" ]; then
|
elif [ "$(uname)" == "Darwin" ]; then
|
||||||
echo -e "${infoColor}convert_config_macos file${resetColor}"
|
echo -e "${infoColor}convert_config_macos file${resetColor}"
|
||||||
fi
|
fi
|
||||||
echo "This file can be used to configure some advanced options of this script."
|
echo "This file can be used to configure some advanced options of this script."
|
||||||
@ -325,25 +327,25 @@ if [ $mkiso_present -eq 0 ]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! [ -z $1 ]; then
|
if [ -n "$1" ]; then
|
||||||
type="$1"
|
type="$1"
|
||||||
else
|
else
|
||||||
type="wim"
|
type="wim"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! [ "$type" == "wim" -o "$type" == "esd" ]; then
|
if [ "$type" != "wim" ] && [ "$type" != "esd" ]; then
|
||||||
echo -e "$errorColor""Incorrect compression type.""$resetColor"
|
echo -e "$errorColor""Incorrect compression type.""$resetColor"
|
||||||
echo "Possible options: wim, esd"
|
echo "Possible options: wim, esd"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! [ -z $2 ]; then
|
if [ -n "$2" ]; then
|
||||||
uupDir="$2"
|
uupDir="$2"
|
||||||
else
|
else
|
||||||
uupDir="UUPs"
|
uupDir="UUPs"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! [ -z $3 ]; then
|
if [ -n "$3" ]; then
|
||||||
runVirtualEditions="$3"
|
runVirtualEditions="$3"
|
||||||
else
|
else
|
||||||
runVirtualEditions=0
|
runVirtualEditions=0
|
||||||
@ -367,7 +369,7 @@ function cleanup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function errorHandler() {
|
function errorHandler() {
|
||||||
if [ $1 != 0 ]; then
|
if [ "$1" != 0 ]; then
|
||||||
echo -e "${errorColor}$2${resetColor}"
|
echo -e "${errorColor}$2${resetColor}"
|
||||||
cleanup
|
cleanup
|
||||||
exit 1
|
exit 1
|
||||||
@ -396,40 +398,40 @@ fi
|
|||||||
list=
|
list=
|
||||||
|
|
||||||
firstMetadata=$(head -1 <<< "$metadataFiles")
|
firstMetadata=$(head -1 <<< "$metadataFiles")
|
||||||
getLang=`wimlib-imagex info "$firstMetadata" 3`
|
getLang=$(wimlib-imagex info "$firstMetadata" 3)
|
||||||
lang=`grep -i "^Default Language:" <<< "$getLang" | sed "s/.* //g"`
|
lang=$(grep -i "^Default Language:" <<< "$getLang" | sed "s/.* //g")
|
||||||
#lang=$(grep -i "_..-.*.esd" <<< "$metadataFiles" | head -1 | tr '[:upper:]' '[:lower:]' | sed 's/.*_//g;s/.esd//g')
|
#lang=$(grep -i "_..-.*.esd" <<< "$metadataFiles" | head -1 | tr '[:upper:]' '[:lower:]' | sed 's/.*_//g;s/.esd//g')
|
||||||
metadataFiles=$(grep -i "$lang" <<< "$metadataFiles" | sort | uniq)
|
metadataFiles=$(grep -i "$lang" <<< "$metadataFiles" | sort | uniq)
|
||||||
firstMetadata=$(head -1 <<< "$metadataFiles")
|
firstMetadata=$(head -1 <<< "$metadataFiles")
|
||||||
|
|
||||||
tempDir=`mktemp -d`
|
tempDir=$(mktemp -d)
|
||||||
extractDir="$tempDir/extract"
|
extractDir="$tempDir/extract"
|
||||||
|
|
||||||
echo -e "\033[1m$scriptName\033[0m"
|
echo -e "\033[1m$scriptName\033[0m"
|
||||||
|
|
||||||
updatesDetected=false
|
updatesDetected=false
|
||||||
for file in `find "$uupDir" -type f -iname "*windows1*-kb*.cab" -or -iname "ssu-*.cab"`; do
|
while IFS= read -r -d '' file; do
|
||||||
updatesDetected=true
|
updatesDetected=true
|
||||||
done
|
done < <(find "$uupDir" -print0 -type f -iname "*windows1*-kb*.cab" -or -iname "ssu-*.cab")
|
||||||
|
|
||||||
if [ $updatesDetected == true ]; then
|
if [ $updatesDetected == true ]; then
|
||||||
echo -e "\033[33mNote: This script does not and cannot support the integration of updates.\nUse the Windows version of the converter to integrate updates."
|
echo -e "\033[33mNote: This script does not and cannot support the integration of updates.\nUse the Windows version of the converter to integrate updates."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ $runVirtualEditions -eq 1 ] && [ "$VIRTUAL_EDITIONS_PLUGIN_LOADED" != "1" ]; then
|
if [ "$runVirtualEditions" -eq 1 ] && [ "$VIRTUAL_EDITIONS_PLUGIN_LOADED" != "1" ]; then
|
||||||
echo "Virtual editions will be not created, because plugin isn't loaded."
|
echo "Virtual editions will be not created, because plugin isn't loaded."
|
||||||
runVirtualEditions=0
|
runVirtualEditions=0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
cabextractVersion=$(cabextract --version | cut -d ' ' -f 3)
|
cabextractVersion=$(cabextract --version | cut -d ' ' -f 3)
|
||||||
if [ $(version $cabextractVersion) -ge $(version "1.10") ] ; then
|
if [ "$(version "$cabextractVersion")" -ge "$(version "1.10")" ] ; then
|
||||||
keepSymlinks="-k"
|
keepSymlinks="-k"
|
||||||
else
|
else
|
||||||
keepSymlinks=""
|
keepSymlinks=""
|
||||||
fi
|
fi
|
||||||
for file in `find "$uupDir" -type f -iname "*.cab" -not -iname "*windows1*-kb*.cab" -not -iname "ssu-*.cab" -not -iname "*desktopdeployment*.cab" -not -iname "*aggregatedmetadata*.cab"`; do
|
while IFS= read -r -d '' file; do
|
||||||
fileName=`basename $file .cab`
|
fileName=$(basename "$file" .cab)
|
||||||
echo -e "$infoColor""CAB -> ESD:""$resetColor"" $fileName"
|
echo -e "$infoColor""CAB -> ESD:""$resetColor"" $fileName"
|
||||||
|
|
||||||
mkdir "$extractDir"
|
mkdir "$extractDir"
|
||||||
@ -442,7 +444,8 @@ for file in `find "$uupDir" -type f -iname "*.cab" -not -iname "*windows1*-kb*.c
|
|||||||
errorHandler $? "Failed to create $fileName.esd"
|
errorHandler $? "Failed to create $fileName.esd"
|
||||||
|
|
||||||
rm -rf "$extractDir"
|
rm -rf "$extractDir"
|
||||||
done
|
done < <(find "$uupDir" -print0 -type f -iname "*.cab" -not -iname "*windows1*-kb*.cab" -not -iname "ssu-*.cab" -not -iname "*desktopdeployment*.cab" -not -iname "*aggregatedmetadata*.cab")
|
||||||
|
|
||||||
|
|
||||||
fileName=
|
fileName=
|
||||||
file=
|
file=
|
||||||
@ -533,13 +536,16 @@ done
|
|||||||
files=$(find ISODIR -regex ".*/sources/.*" | eval grep $list)
|
files=$(find ISODIR -regex ".*/sources/.*" | eval grep $list)
|
||||||
list=
|
list=
|
||||||
|
|
||||||
echo "delete /Windows/System32/winpeshl.ini" >"$tempDir/update.txt"
|
cat >"$tempDir/update.txt" <<EOF
|
||||||
echo "add ISODIR/setup.exe /setup.exe" >>"$tempDir/update.txt"
|
delete /Windows/System32/winpeshl.ini
|
||||||
echo "add ISODIR/sources/inf/setup.cfg /sources/inf/setup.cfg" >>"$tempDir/update.txt"
|
add ISODIR/setup.exe /setup.exe
|
||||||
echo "add ISODIR/sources/$bckimg /sources/background.bmp" >>"$tempDir/update.txt"
|
add ISODIR/sources/inf/setup.cfg /sources/inf/setup.cfg
|
||||||
echo "add ISODIR/sources/$bckimg /Windows/system32/setup.bmp" >>"$tempDir/update.txt"
|
add ISODIR/sources/$bckimg /sources/background.bmp
|
||||||
echo "add ISODIR/sources/$bckimg /Windows/system32/winpe.jpg" >>"$tempDir/update.txt"
|
add ISODIR/sources/$bckimg /Windows/system32/setup.bmp
|
||||||
echo "add ISODIR/sources/$bckimg /Windows/system32/winre.jpg" >>"$tempDir/update.txt"
|
add ISODIR/sources/$bckimg /Windows/system32/winpe.jpg
|
||||||
|
add ISODIR/sources/$bckimg /Windows/system32/winre.jpg
|
||||||
|
EOF
|
||||||
|
|
||||||
for i in $files; do
|
for i in $files; do
|
||||||
echo "add ISODIR/$i /$i" >>"$tempDir/update.txt"
|
echo "add ISODIR/$i /$i" >>"$tempDir/update.txt"
|
||||||
done
|
done
|
||||||
@ -554,18 +560,18 @@ if [ -e ./ISODIR/sources/winpe.jpg ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
refglobs=false
|
refglobs=false
|
||||||
for file in `find "$tempDir" -type f -iname "*.esd"`; do
|
while IFS= read -r -d '' file; do
|
||||||
refglobs=true
|
refglobs=true
|
||||||
done
|
done < <(find "$tempDir" -print0 -type f -iname "*.esd")
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
indexesExported=0
|
indexesExported=0
|
||||||
for metadata in $metadataFiles; do
|
for metadata in $metadataFiles; do
|
||||||
currentInfo=`wimlib-imagex info "$metadata" 3`
|
currentInfo=$(wimlib-imagex info "$metadata" 3)
|
||||||
|
|
||||||
currentEdition=`grep -i "^Edition ID:" <<< "$currentInfo" | sed "s/.* //g"`
|
currentEdition=$(grep -i "^Edition ID:" <<< "$currentInfo" | sed "s/.* //g")
|
||||||
currentName=`grep -i "^Name:" <<< "$currentInfo" | sed "s/.* //g"`
|
currentName=$(grep -i "^Name:" <<< "$currentInfo" | sed "s/.* //g")
|
||||||
currentType=`grep -i "^Installation Type:" <<< "$currentInfo" | sed "s/.* //g"`
|
currentType=$(grep -i "^Installation Type:" <<< "$currentInfo" | sed "s/.* //g")
|
||||||
|
|
||||||
if [ "$currentType" == "Server Core" ] && [ "$currentEdition" == "ServerStandard" ]; then
|
if [ "$currentType" == "Server Core" ] && [ "$currentEdition" == "ServerStandard" ]; then
|
||||||
currentEdition="ServerStandardCore"
|
currentEdition="ServerStandardCore"
|
||||||
@ -575,43 +581,43 @@ for metadata in $metadataFiles; do
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
editionName="Windows 10 $currentEdition"
|
editionName="Windows 10 $currentEdition"
|
||||||
if echo $currentName | grep -ow "Windows 11" >/dev/null; then
|
if echo "$currentName" | grep -ow "Windows 11" >/dev/null; then
|
||||||
editionName="Windows 11 $currentEdition"
|
editionName="Windows 11 $currentEdition"
|
||||||
fi
|
fi
|
||||||
if echo $currentEdition | grep -i "^Server" >/dev/null; then
|
if echo "$currentEdition" | grep -i "^Server" >/dev/null; then
|
||||||
editionName="Windows Server 2022 $currentEdition"
|
editionName="Windows Server 2022 $currentEdition"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo -e "$infoColor""Exporting $editionName to install.$type...""$resetColor"
|
echo -e "$infoColor""Exporting $editionName to install.$type...""$resetColor"
|
||||||
|
|
||||||
if [ $refglobs == true ]; then
|
if [ $refglobs == true ]; then
|
||||||
wimlib-imagex export "$metadata" 3 ISODIR/sources/install.$type \
|
wimlib-imagex export "$metadata" 3 "ISODIR/sources/install.$type" \
|
||||||
"$editionName" $compressParam --ref={"$uupDir","$tempDir"}/*.[eE][sS][dD]
|
"$editionName" $compressParam --ref={"$uupDir","$tempDir"}/*.[eE][sS][dD]
|
||||||
else
|
else
|
||||||
wimlib-imagex export "$metadata" 3 ISODIR/sources/install.$type \
|
wimlib-imagex export "$metadata" 3 "ISODIR/sources/install.$type" \
|
||||||
"$editionName" $compressParam --ref="$uupDir"/*.[eE][sS][dD]
|
"$editionName" $compressParam --ref="$uupDir"/*.[eE][sS][dD]
|
||||||
fi
|
fi
|
||||||
|
|
||||||
errorHandler $? "Failed to export $editionName to install.$type""$resetColor"
|
errorHandler $? "Failed to export $editionName to install.$type""$resetColor"
|
||||||
|
|
||||||
let indexesExported++
|
((indexesExported++))
|
||||||
|
|
||||||
wimlib-imagex info ISODIR/sources/install.$type $indexesExported \
|
wimlib-imagex info "ISODIR/sources/install.$type" $indexesExported \
|
||||||
--image-property FLAGS="$currentEdition" >/dev/null
|
--image-property FLAGS="$currentEdition" >/dev/null
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
echo -e "$infoColor""Adding winre.wim for $editionName...""$resetColor"
|
echo -e "$infoColor""Adding winre.wim for $editionName...""$resetColor"
|
||||||
wimlib-imagex update ISODIR/sources/install.$type $indexesExported \
|
wimlib-imagex update "ISODIR/sources/install.$type" $indexesExported \
|
||||||
--command "add $tempDir/winre.wim /Windows/System32/Recovery/winre.wim"
|
--command "add $tempDir/winre.wim /Windows/System32/Recovery/winre.wim"
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
done
|
done
|
||||||
|
|
||||||
info=`wimlib-imagex info "$firstMetadata" 3`
|
info=$(wimlib-imagex info "$firstMetadata" 3)
|
||||||
build=`grep -i "^Build:" <<< "$info" | sed "s/.* //g"`
|
build=$(grep -i "^Build:" <<< "$info" | sed "s/.* //g")
|
||||||
|
|
||||||
addedVirtualEditions=0
|
addedVirtualEditions=0
|
||||||
if [ $runVirtualEditions -eq 1 ] && [ $build -ge 17063 ]; then
|
if [ "$runVirtualEditions" -eq 1 ] && [ "$build" -ge 17063 ]; then
|
||||||
echo -e "$infoColor""Creating virtual editions...""$resetColor"
|
echo -e "$infoColor""Creating virtual editions...""$resetColor"
|
||||||
for virtualEdition in $VIRTUAL_EDITIONS_LIST; do
|
for virtualEdition in $VIRTUAL_EDITIONS_LIST; do
|
||||||
echo -e "$infoColor""Adding $virtualEdition edition...""$resetColor"
|
echo -e "$infoColor""Adding $virtualEdition edition...""$resetColor"
|
||||||
@ -619,17 +625,17 @@ if [ $runVirtualEditions -eq 1 ] && [ $build -ge 17063 ]; then
|
|||||||
error=$?
|
error=$?
|
||||||
if [ $error -ne 1 ]; then
|
if [ $error -ne 1 ]; then
|
||||||
errorHandler $error "Failed to create virtual edition"
|
errorHandler $error "Failed to create virtual edition"
|
||||||
let addedVirtualEditions++
|
((addedVirtualEditions++))
|
||||||
fi
|
fi
|
||||||
echo ""
|
echo ""
|
||||||
done
|
done
|
||||||
elif [ $build -lt 17063 ]; then
|
elif [ "$build" -lt 17063 ]; then
|
||||||
echo "Virtual editions creation requires build 17063 or later"
|
echo "Virtual editions creation requires build 17063 or later"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
let indexesSum=$addedVirtualEditions+$indexesExported
|
((indexesSum=addedVirtualEditions+indexesExported))
|
||||||
spbuild=`grep -i "^Service Pack Build:" <<< "$info" | sed "s/.* //g"`
|
spbuild=$(grep -i "^Service Pack Build:" <<< "$info" | sed "s/.* //g")
|
||||||
arch=`grep -i "^Architecture:" <<< "$info" | sed "s/.* //g"`
|
arch=$(grep -i "^Architecture:" <<< "$info" | sed "s/.* //g")
|
||||||
|
|
||||||
if [ "$arch" == "x86_64" ]; then
|
if [ "$arch" == "x86_64" ]; then
|
||||||
arch="x64"
|
arch="x64"
|
||||||
@ -638,11 +644,11 @@ fi
|
|||||||
if [ $indexesSum -gt 1 ]; then
|
if [ $indexesSum -gt 1 ]; then
|
||||||
isoEdition="MULTI"
|
isoEdition="MULTI"
|
||||||
else
|
else
|
||||||
isoEdition=`grep -i "^Edition ID:" <<< "$info" | sed "s/.* //g"`
|
isoEdition=$(grep -i "^Edition ID:" <<< "$info" | sed "s/.* //g")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
isoLabel=`tr "[:lower:]" "[:upper:]" <<< "${build}.${spbuild}_${arch}_${lang}"`
|
isoLabel=$(tr "[:lower:]" "[:upper:]" <<< "${build}.${spbuild}_${arch}_${lang}")
|
||||||
isoName=`tr "[:lower:]" "[:upper:]" <<< "${build}.${spbuild}_${isoEdition}_${arch}_${lang}.iso"`
|
isoName=$(tr "[:lower:]" "[:upper:]" <<< "${build}.${spbuild}_${isoEdition}_${arch}_${lang}.iso")
|
||||||
|
|
||||||
if [ -e "$isoName" ]; then
|
if [ -e "$isoName" ]; then
|
||||||
rm "$isoName"
|
rm "$isoName"
|
||||||
@ -650,11 +656,11 @@ fi
|
|||||||
|
|
||||||
if [ $addedVirtualEditions -ge 1 ]; then
|
if [ $addedVirtualEditions -ge 1 ]; then
|
||||||
echo -e "$infoColor""Optimizing install.$type...""$resetColor"
|
echo -e "$infoColor""Optimizing install.$type...""$resetColor"
|
||||||
wimlib-imagex optimize ISODIR/sources/install.$type
|
wimlib-imagex optimize "ISODIR/sources/install.$type"
|
||||||
echo ""
|
echo ""
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ $build -ge 18890 ]; then
|
if [ "$build" -ge 18890 ]; then
|
||||||
wimlib-imagex extract "$firstMetadata" 3 "/Windows/Boot/Fonts" \
|
wimlib-imagex extract "$firstMetadata" 3 "/Windows/Boot/Fonts" \
|
||||||
--no-acls --dest-dir="ISODIR/boot" >/dev/null
|
--no-acls --dest-dir="ISODIR/boot" >/dev/null
|
||||||
mv -f ISODIR/boot/Fonts/* ISODIR/boot/fonts
|
mv -f ISODIR/boot/Fonts/* ISODIR/boot/fonts
|
||||||
|
Loading…
Reference in New Issue
Block a user