Shell install.sh for repository (rpi_videoloop) I've written my first installation script in shell and was wondering on how I can improve the install procedure to make it more clean?

Here's the code:

#!/bin/bash

#Variables
DEPENDENCIES="omxplayer screen cron usbmount ntfs-3g"
PTH="/home/pi/rpi_videoloop"
INIT="/etc/init.d"
SCRIPT="videoloop_v2.sh"
CONTROLLER="vid_controller"
USBCONF="usbmount.conf"
CRONSTUFF=$(cat cron.txt)

# Checking | Installing Dependancies
if ! apt list "$DEPENDENCIES" | grep -v installed | grep -E 'omxplayer|screen|cron|usbmount|ntfs-3g' &gt; /dev/null
then
echo "Dependencies already installed. Continuing."
else
echo "Installing dependencies."
apt-get update
apt-get install "$DEPENDENCIES" -y
fi

echo "Installing Configurations..."

#Configuring
if [ ! -d "$PTH" ]; then 
    mkdir $PTH
fi
cp $SCRIPT $PTH
if [ ! -f $INIT/$CONTROLLER ]; then
    sudo cp $CONTROLLER $INIT
fi
cp $USBCONF /etc/usbmount/
sudo chmod 755 $PTH/$SCRIPT
sudo chmod 755 $INIT/$CONTROLLER
sudo update-rc.d $CONTROLLER defaults
sudo echo -n " consoleblank=10" | sudo tee -a /boot/cmdline.txt
#cat alias.txt &gt;&gt; ~/.bashrc
#sudo cat alias.txt &gt;&gt; ~/.bashrc
(crontab -u pi -l; echo "$CRONSTUFF" ) | crontab -u pi -

echo "FINISHED INSTALLATION: Service control -&gt; /etc/init.d/vid_controller {start|stop|check|repair}"
Set these options at the beginning:

set -eu


so that errors fail early



Don't use sudo in a script, because it can hang when not connected to a terminal.  Possible exception: once at the beginning:

if ! test $UID -eq 0
then
   test -t 0 &amp;&amp; exec sudo "$0" "$@"
   # Not a terminal - or exec failed
   echo "Insufficient privileges - try sudo $0 $*" &gt;&amp;2
   exit 1
fi




You probably want to be using the standard install command instead of cp and mkdir.  That lets you specify the permissions as you create the targets.



Consider using a $DESTDIR prefix when specifying the targets.  This makes it easier for package builders (such as debhelper) to re-use your script.  They will need to omit the dependency checks, so make that separable if you can (or at least disable it when $DESTDIR is set).