Issue
I want to create a update function for my bash script so that in the future any changes I commit to the script which is stored on github can be updated by the end-users. I can't find any example of an update function for bash.
if I just make a function like so:
function update(){
git clone https://path/to/my/repo.git
}
It simply creates another copy of my repo in the present directory that I'm in. Adding a path directly to the script doesn t work either. How can I make it happen?
Solution
I needed an update function in a subscript without git pulling the whole directrory, it ended up like this: (from https://bitbucket.org/jupiter126/sheldon/raw/master/backup_skel.sh)
if [ "$(grep 'autoupdate=1' $directory/backup_$(hostname).sh)" != "" ]; then
oldver=$(cat "$directory/backup_skel.sh"|grep -v "("|grep backupversion|cut -f2 -d"=")
newver=$(curl -s https://bitbucket.org/jupiter126/sheldon/raw/master/backup_skel.sh|grep -v "("|grep backupversion|cut -f2 -d"=")
if [ "$newver" -gt "$oldver" ]; then
echo "new version detected, updating backup script"
mv "$directory/backup_skel.sh" "$directory/backup_skel.old"
$wwwget -q https://bitbucket.org/jupiter126/sheldon/raw/master/backup_skel.sh -O"$directory/backup_skel.sh" && sleep 2 && chmod +x "$directory/backup_skel.sh" && sleep 2 && exec "$directory/backup_skel.sh"
fi
fi
Answered By - user1747036 Answer Checked By - David Goodson (WPSolving Volunteer)