I have this script, that does several operations on some files, which then creates an output file in the end called flashable.zip.
I’d like to implement that when the user runs the script, it begins with asking for a filename to output in the end. The filename is predefined to looking like this: 1.22.33_DA.zip, where the user gets to choose the 1.22.33 part – It’s like version naming the file.. And it has to be strict, so the user don’t use letters in the 1.22.33 part..
I’m sure I can use something like grep for this, but I’m completely lost in how to do it 🙁
And I’m fairly new to bash scripting, so I’m still learning, the script I got might look pretty messy and can probably be cleaned up a bit 🙂
I’m thinking it would just be something that renames the created zipfile when the operations are done, but I’m not sure though..
Here’s my script:
#!/bin/bash
echo ""
echo "[--- Creating flashable zip ---]"
echo ""
tlock=/home/dan/buildtool/flashable/template/system/media/theme/default
dst=/home/dan/buildtool/flashable/system/media/theme/default
src=/home/dan/buildtool/translations/ma-xml-4.0-danish/extras/lockscreen
parent=/home/dan/buildtool/flashable
src2=/home/dan/buildtool/apk_out
home=/home/dan/buildtool
cd $parent
mkdir system
cd system
mkdir app
mkdir framework
mkdir media
cd media
mkdir theme
mkdir audio
cd theme
mkdir default
cd $parent/system/media/audio
mkdir ringtones
mkdir alarms
mkdir notifications
cd $home
for apk in $(<$home/translation_list.txt); do cp -r -f "$src2/$apk" $parent/system/app; done
mv -f $parent/system/app/framework-miui-res.apk $parent/system/framework
cp -f $parent/template.zip $parent/flashable.zip
cp -f -r $parent/template/system/media/audio $parent/system/media
7za u -tzip $tlock/lockscreen.zip $src/advance
cp -f $tlock/lockscreen.zip $tlock/lockscreen
cp -f $tlock/lockscreen $dst
7za a -tzip $parent/flashable.zip $parent/system -mx3
rm -r $parent/system
cd /home/dan/buildtool
This will read in user input and validate the version via regex.
Output
Explanation
read verReads in user input into thevervariable.^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$1)
^Start of string2)
[0-9]Any digit between 0 and 93)
{1,3}Match at least 1 up to 3 characters4)
\.Match a dot5)
\.[0-9]{1,3}Repeat pattern twice7)
$Match end of string