Shell script help

bashcommand linescript

I am new to writing shell scripts for Unix and need a little help. I am not sure why cURL now all of the sudden after running the script is downloading corrupts packages which cannot be mounted and why running the commands separately in Terminal work, but during the script everything fails such as

For cURL it comes back saying command not found
For the mv command it says cannot find file or directory
and of course mounting and everything thereafter fail.

Could you please take a look at the shell script to see what is missing or I am doing wrong?

#!/bin/sh
#Machines must have cURL installed as a prerequisite to download software from internet or FTP server 

# grab files from www.teamviewer.com or custom FTP server
curl -O http://download.teamviewer.com/download/TeamViewerHost.dmg

# grab TeamViewer from custom FTP server
curl -O https://www.dropbox.com/s/***********/com.TeamViewer8.Settings.plist

# Wait for download
sleep 30s

# Place customized plist file into Library/Preferences
mv ~/Downloads/com.TeamViewer8.Settings.plist /Library/Preferences/

# Mount and Install TeamViewer
hdiutil mount ~/Downloads/TeamViewerHost.dmg
installer -pkg /Volumes/TeamViewerHost/Install\ TeamViewerHost.pkg -target /

# Unmount package
hdiutil unmount /Volumes/TeamViewerHost/

Best Answer

This should work. I don't have time currently to explain the changes/additions, but I'll update. You must run this script as sudo for it to work.

Even easier, sudo chmod +s yourscript - will run as root without requiring password.

#!/bin/bash

#Machines must have cURL installed as a prerequisite to download software from internet or FTP server 

#Change to your working directory. 
cd ~/Downloads

#grab files from www.teamviewer.com or custom FTP server
curl -O http://downloadus3.teamviewer.com/download/TeamViewerHost.dmg

#grab TeamViewer from custom FTP server
curl -O https://www.dropbox.com/s/******/com.apple.TeamViewer8.Settings.plist

#Place customized plist file into Library/Preferences
mv ~/Downloads/com.apple.TeamViewer8.Settings.plist /Library/Preferences/

#Mount and Install TeamViewer
hdiutil mount ~/Downloads/TeamViewerHost.dmg
installer -pkg /Volumes/TeamViewerHost/Install\ TeamViewerHost.pkg -target LocalSystem

#Softkill process in order to unmount package
ps aux | grep -i TeamViewer | awk {'print $2'} | xargs kill

#Unmount package
hdiutil unmount /Volumes/TeamViewerHost/