I have a shell script which is being used on an embedded human machine interface (HMI). This script is used to copy a few files from a USB stick to a different place on the device, but with multiple instances of the same file under different names.
If it helps:
- OS is Unix-like (BusyBox v1.11.2)
- Commands available are located here
- The filesystem is JFFS2
Any thoughts on improvements/optimizations would be appreciated.
#! /bin/sh
echo "
****Project Customisation Daemon STARTING****
"
echo "Main Background:"
# First, check the new image exists
if [ -s "/disk/usbsda1/New_Main.png" ]
then
echo " -> Found new file to be used!"
# Check if our directory is already present
if [ -d "/opt/pclient/projekte/Main/" ]
then
# If our directory exists, remove the files
echo " -> Found old directory, removing contents!"
rm -rf /opt/pclient/projekte/Main/*
else
# If the directory isnt present, create it!
echo " -> Creating new directory!"
mkdir -p /opt/pclient/projekte/Main/
fi
# Now copy our files!
echo " -> Copying new files, please wait!"
cp /disk/usbsda1/New_Main.png /opt/pclient/projekte/Main/Main_Page.png
cp /disk/usbsda1/New_Main.png /opt/pclient/projekte/Main/Main_Page2.png
cp /disk/usbsda1/New_Main.png /opt/pclient/projekte/Main/Main_Page3.png
cp /disk/usbsda1/New_Main.png /opt/pclient/projekte/Main/Main_Page4.png
cp /disk/usbsda1/New_Main.png /opt/pclient/projekte/Main/Main_Page5.png
cp /disk/usbsda1/New_Main.png /opt/pclient/projekte/Main/Main_Page6.png
cp /disk/usbsda1/New_Main.png /opt/pclient/projekte/Main/Main_Page7.png
cp /disk/usbsda1/New_Main.png /opt/pclient/projekte/Main/Main_Page8.png
cp /disk/usbsda1/New_Main.png /opt/pclient/projekte/Main/Main_Page9.png
cp /disk/usbsda1/New_Main.png /opt/pclient/projekte/Main/Main_Page10.png
cp /disk/usbsda1/New_Main.png /opt/pclient/projekte/Main/Main_Page11.png
cp /disk/usbsda1/New_Main.png /opt/pclient/projekte/Main/Main_Page12.png
cp /disk/usbsda1/New_Main.png /opt/pclient/projekte/Main/Main_Page13.png
cp /disk/usbsda1/New_Main.png /opt/pclient/projekte/Main/Main_Page14.png
cp /disk/usbsda1/New_Main.png /opt/pclient/projekte/Main/Main_Page15.png
cp /disk/usbsda1/New_Main.png /opt/pclient/projekte/Main/Main_Page16.png
cp /disk/usbsda1/New_Main.png /opt/pclient/projekte/Main/Main_Page17.png
cp /disk/usbsda1/New_Main.png /opt/pclient/projekte/Main/Main_Page18.png
cp /disk/usbsda1/New_Main.png /opt/pclient/projekte/Main/Main_Page19.png
cp /disk/usbsda1/New_Main.png /opt/pclient/projekte/Main/Main_Page20.png
cp /disk/usbsda1/New_Main.png /opt/pclient/projekte/Main/Main_Page21.png
cp /disk/usbsda1/New_Main.png /opt/pclient/projekte/Main/Main_Page22.png
cp /disk/usbsda1/New_Main.png /opt/pclient/projekte/Main/Main_Page23.png
cp /disk/usbsda1/New_Main.png /opt/pclient/projekte/Main/Main_Page24.png
cp /disk/usbsda1/New_Main.png /opt/pclient/projekte/Main/Main_Page25.png
cp /disk/usbsda1/New_Main.png /opt/pclient/projekte/Main/Main_Page26.png
cp /disk/usbsda1/New_Main.png /opt/pclient/projekte/Main/Main_Page27.png
cp /disk/usbsda1/New_Main.png /opt/pclient/projekte/Main/Main_Page28.png
cp /disk/usbsda1/New_Main.png /opt/pclient/projekte/Main/Main_Page29.png
cp /disk/usbsda1/New_Main.png /opt/pclient/projekte/Main/Main_Page30.png
cp /disk/usbsda1/New_Main.png /opt/pclient/projekte/Main/Main_Page31.png
cp /disk/usbsda1/New_Main.png /opt/pclient/projekte/Main/Main_Page32.png
cp /disk/usbsda1/New_Main.png /opt/pclient/projekte/Main/Main_Page33.png
cp /disk/usbsda1/New_Main.png /opt/pclient/projekte/Main/Main_Page34.png
cp /disk/usbsda1/New_Main.png /opt/pclient/projekte/Main/Main_Page35.png
cp /disk/usbsda1/New_Main.png /opt/pclient/projekte/Main/Main_Page36.png
cp /disk/usbsda1/New_Main.png /opt/pclient/projekte/Main/Main_Page38.png
cp /disk/usbsda1/New_Main.png /opt/pclient/projekte/Main/Main_Page62.png
cp /disk/usbsda1/New_Main.png /opt/pclient/projekte/Main/Main_Page63.png
cp /disk/usbsda1/New_Main.png /opt/pclient/projekte/Main/Main_Page64.png
cp /disk/usbsda1/New_Main.png /opt/pclient/projekte/Main/Main_Page65.png
cp /disk/usbsda1/New_Main.png /opt/pclient/projekte/Main/Main_Page66.png
cp /disk/usbsda1/New_Main.png /opt/pclient/projekte/Main/Main_Page67.png
cp /disk/usbsda1/New_Main.png /opt/pclient/projekte/Main/Main_Page68.png
cp /disk/usbsda1/New_Main.png /opt/pclient/projekte/Main/Main_Page69.png
cp /disk/usbsda1/New_Main.png /opt/pclient/projekte/Main/Main_Page610.png
cp /disk/usbsda1/New_Main.png /opt/pclient/projekte/Main/Main_Page611.png
cp /disk/usbsda1/New_Main.png /opt/pclient/projekte/Main/Main_Page615.png
cp /disk/usbsda1/New_Main.png /opt/pclient/projekte/Main/Main_Page616.png
cp /disk/usbsda1/New_Main.png /opt/pclient/projekte/Main/Main_Page618.png
cp /disk/usbsda1/New_Main.png /opt/pclient/projekte/Main/Main_Page619.png
cp /disk/usbsda1/New_Main.png /opt/pclient/projekte/Main/Main_Page620.png
cp /disk/usbsda1/New_Main.png /opt/pclient/projekte/Main/Main_Page621.png
cp /disk/usbsda1/New_Main.png /opt/pclient/projekte/Main/Main_Page622.png
cp /disk/usbsda1/New_Main.png /opt/pclient/projekte/Main/Main_Page623.png
cp /disk/usbsda1/New_Main.png /opt/pclient/projekte/Main/Main_Page624.png
cp /disk/usbsda1/New_Main.png /opt/pclient/projekte/Main/Main_Page626.png
cp /disk/usbsda1/New_Main.png /opt/pclient/projekte/Main/Main_Page627.png
cp /disk/usbsda1/New_Main.png /opt/pclient/projekte/Main/Main_Page628.png
cp /disk/usbsda1/New_Main.png /opt/pclient/projekte/Main/Main_Page629.png
cp /disk/usbsda1/New_Main.png /opt/pclient/projekte/Main/Main_Page630.png
cp /disk/usbsda1/New_Main.png /opt/pclient/projekte/Main/Main_Page631.png
else
echo " -> Could not find new image to use, skipping!"
fi
# Inform the user that the files have been created
echo " -> All background images created!"
echo " -> Now copying to project folder!"
# move the files into the appropriate place
cp /opt/pclient/projekte/Main/* /opt/pclient/projekte/default_prj/terminal_files/
# Next we need to create copies of any additional images we will need
echo "Help Pages:"
# First, check the new image exists
echo " -> Now creating Help logos"
if [ -s "/disk/usbsda1/New_Help.png" ]
then
echo " -> Found new file to be used!"
# Check if our directory is already present
if [ -d "/opt/pclient/projekte/Help/" ]
then
# If our directory exists, remove the files
echo " -> Found old directory, removing contents!"
rm -rf /opt/pclient/projekte/Help/*
else
# If the directory isnt present, create it!
echo " -> Creating new directory!"
mkdir -p /opt/pclient/projekte/Help/
fi
# Now copy our files!
echo " -> Copying new files, please wait!"
cp /disk/usbsda1/New_Help.png /opt/pclient/projekte/Help/Help_Page.png
cp /disk/usbsda1/New_Help.png /opt/pclient/projekte/Help/Help_Page2.png
cp /disk/usbsda1/New_Help.png /opt/pclient/projekte/Help/Help_Page3.png
cp /disk/usbsda1/New_Help.png /opt/pclient/projekte/Help/Help_Page4.png
cp /disk/usbsda1/New_Help.png /opt/pclient/projekte/Help/Help_Page5.png
cp /disk/usbsda1/New_Help.png /opt/pclient/projekte/Help/Help_Page6.png
cp /disk/usbsda1/New_Help.png /opt/pclient/projekte/Help/Help_Page7.png
cp /disk/usbsda1/New_Help.png /opt/pclient/projekte/Help/Help_Page8.png
else
echo " -> Could not find new image to use, skipping!"
fi
# Inform the user that the files have been created
echo " -> Applying changes to project!"
# move the files into the appropriate place
cp /opt/pclient/projekte/Help/* /opt/pclient/projekte/default_prj/terminal_files/
echo "Icon Pages:"
# Check the new Icon pages exists
echo " -> Now creating Icon logos"
if [ -s "/disk/usbsda1/New_Icon.png" ]
then
echo " -> Found new file to be used!"
# Check if our directory is already present
if [ -d "/opt/pclient/projekte/Icon/" ]
then
# If our directory exists, remove the files
echo " -> Found old directory, removing contents!"
rm -rf /opt/pclient/projekte/Icon/*
else
# If the directory isnt present, create it!
echo " -> Creating new directory!"
mkdir -p /opt/pclient/projekte/Icon/
fi
# Now copy our files!
echo " -> Copying new files, please wait!"
cp /disk/usbsda1/New_Icon.png /opt/pclient/projekte/Icon/Icon_Page.png
cp /disk/usbsda1/New_Icon.png /opt/pclient/projekte/Icon/Icon_Page2.png
else
echo " -> Could not find new image to use, skipping!"
fi
# Inform the user that the files have been created
echo " -> Applying changes to project!"
# move the files into the appropriate place
cp /opt/pclient/projekte/Icon/* /opt/pclient/projekte/default_prj/terminal_files/
echo "Additional Logos:"
# Check the new logo page exists
echo " -> Now creating Logo"
if [ -s "/disk/usbsda1/New_Logo.png" ]
then
echo " -> Found new file to be used!"
# Check if our directory is already present
if [ -d "/opt/pclient/projekte/Logo/" ]
then
# If our directory exists, remove the files
echo " -> Found old directory, removing contents!"
rm -rf /opt/pclient/projekte/Logo/*
else
# If the directory isnt present, create it!
echo " -> Creating new directory!"
mkdir -p /opt/pclient/projekte/Logo/
fi
# Now copy our files!
echo " -> Copying new files, please wait!"
cp /disk/usbsda1/New_Logo.png /opt/pclient/projekte/Logo/Logo2.png
else
echo " -> Could not find new image to use, skipping!"
fi
# Inform the user that the files have been created
echo " -> Applying changes to project!"
# move the files into the appropriate place
cp /opt/pclient/projekte/Logo/* /opt/pclient/projekte/default_prj/terminal_files/
# Next we need to copy the boot logo and startup screen logo
echo "Boot Logos:"
# First, check the new image exists
echo " -> Now creating boot logos"
if [ -s "/disk/usbsda1/New_Boot.png" ]
then
echo " -> Found new file to be used!"
# Check if our directory is already present
if [ -d "/opt/pclient/projekte/Boot/" ]
then
# If our directory exists, remove the files
echo " -> Found old directory, removing contents!"
rm -rf /opt/pclient/projekte/Boot/*
else
# If the directory isnt present, create it!
echo " -> Creating new directory!"
mkdir -p /opt/pclient/projekte/Boot/
fi
# Now copy our files!
echo " -> Copying new files, please wait!"
cp /disk/usbsda1/New_Boot.png /opt/pclient/projekte/Boot/loading_screen.png
else
echo " -> Could not find new image to use, skipping!"
fi
# Inform the user that the files have been created
echo " -> Applying changes to project!"
# move the files into the appropriate place
cp /opt/pclient/projekte/Boot/* /opt/pclient/projekte/default_prj/terminal_files/additional_files
setbootlogo /opt/pclient/projekte/default_prj/terminal_files/additional_files/loading_screen.png
echo "Wrapping up:"
# Fully tidy up, by removing any un needed file paths
echo " -> Removing un-needed files!"
rm -rf /opt/pclient/projekte/Main/*
rm -rf /opt/pclient/projekte/Boot/*
rm -rf /opt/pclient/projekte/Help/*
rm -rf /opt/pclient/projekte/Icon/*
rm -rf /opt/pclient/projekte/Logo/*
echo " -> Removing un-needed directories!"
rmdir /opt/pclient/projekte/Main
rmdir /opt/pclient/projekte/Boot
rmdir /opt/pclient/projekte/Help
rmdir /opt/pclient/projekte/Icon
rmdir /opt/pclient/projekte/Logo
echo "
****Project Customisation Daemon COMPLETE****
"