/ Published in: Bash
                    
                                        
Simple script that updates itself upon launch then lauches whatever else thats included afterwards works well in almost any linux system tested on busyboxes and Debian systems
                
                            
                                Expand |
                                Embed | Plain Text
                            
                        
                        Copy this code and paste it in your HTML
#!/bin/sh
SELF=$(basename $0) #uses the same name as the file
UPDATE_BASE=https://gitlab.com/swe_toast/self-update/raw/master/ #dont link directly to file link to the folder
UPDATE_SELF=${UPDATE_SELF:-1}
self_updater () {
echo "Performing self-update... Please wait..."
if ! wget --quiet --output-document="$0.tmp" $UPDATE_BASE/$SELF ;
then echo "Failed downloading new version!"
echo "File requested: $UPDATE_BASE/$SELF"
exit 1
fi
OCTAL_MODE=$(stat -c '%a' $0)
case ${OCTAL_MODE:--1} in
-[1] ) echo "Failed: Error : OCTAL_MODE was empty"; exit 1 ;;
777|775|755 ) echo "OCTAL mode set:${OCTAL_MODE}" ;;
* ) echo "Failed: Error in OCTAL_MODEs, found value=${OCTAL_MODE}" exit 1 ;;
esac
if ! chmod $OCTAL_MODE $0.tmp ;
then echo "Error on chmod $OCTAL_MODE %0.tmp from $UPDATE_BASE/$SELF, can't continue"
exit 1
fi
cat > /tmp/updatescript.sh << EOF
#!/bin/sh
if mv "$0.tmp" "$0";
then echo "Update complete.."
exec env UPDATE_SELF=0 /bin/sh "$0"
rm \$0
else echo "Update failed.."
fi
EOF
echo "Inserting update process..."
exec /bin/sh /tmp/updatescript.sh; rm /tmp/updatescript.sh
}
check_update () { if [ ${UPDATE_SELF} -ne 0 ]; then self_updater; fi }
check_update
Comments
 Subscribe to comments
                    Subscribe to comments
                
                