- Joined
- Jan 21, 2013
- Messages
- 215
- Reaction score
- 43
Recent changes to how the update system works has changed the way many automated scripts updates Linux based servers. AndyP has been extremely helpful pointing out a possible solution to this. I decided to write a example script to update the server using the checksum so that only files that have been changed willl be downloaded. This method was originally written by Schema and then improved upon. It does rely on curl which is not always installed on distros so you may have to install it.
*Edit: 7/14/2015 added check for missing files
*Edit: 7/14/2015 added check for missing directories and fix for curling web pages with spaces
*Edit: 7/28/2015 Moved to Github added some robustness
https://github.com/doomsider/SMUPDATE
To install:
wget https://raw.githubusercontent.com/doomsider/SMUPDATE/master/update.sh
To Run:
chmod +x update.sh
./update.sh
*Edit: 7/14/2015 added check for missing files
*Edit: 7/14/2015 added check for missing directories and fix for curling web pages with spaces
*Edit: 7/28/2015 Moved to Github added some robustness
https://github.com/doomsider/SMUPDATE
To install:
wget https://raw.githubusercontent.com/doomsider/SMUPDATE/master/update.sh
To Run:
chmod +x update.sh
./update.sh
#!/bin/bash
# Starmade Selective upgrade script for BASH. Please run in the parent or root directory of Starmade
# Requires curl to be installed
# Grab the releaseindex as a very long string variable
echo "This script will install/update StarMade from the master repo. Use ./update.sh force to force a check on all files"
read -s -r -p "Press any key to continue..." -n 1 dummy
if command -v curl >/dev/null
then
echo "Curl was found"
releaseindex=$(curl http://files.star-made.org/releasebuildindex)
# Go to the end of the variable at the last .
newversion=${releaseindex##*.}
echo "newversion $newversion"
# Get the first version to compare
cutstring=${newversion#*_}
NEWSMVERSION1=${cutstring%_*}
echo "NEWSMVERSION1 $NEWSMVERSION1"
# Get the second version to compare
NEWSMVERSION2=${cutstring#*_}
echo "NEWSMVERSION2 $NEWSMVERSION2"
# Gather the old version from the version.txt file in StarMade
oldversion=$(cat StarMade/version.txt)
if [ -z "$oldversion" ]
then
echo "No install found for StarMade"
OLDSMVER1=0
OLDSMVER2=0
else
echo "oldversion $oldversion"
# Get the first version to compare
cutstring=${oldversion#*#}
OLDSMVER1=${cutstring%_*}
echo "OLDSMVER1 $OLDSMVER1"
# Get the second version to compare
OLDSMVER2=${cutstring#*_}
echo "OLDSMVER2 $OLDSMVER2"
fi
# If the first or second newversion exceeds the first or second old version
if [ "$NEWSMVERSION1" -gt "$OLDSMVER1" ] || [ "$NEWSMVERSION2" -gt "$OLDSMVER2" ] || [ "$1" = "force" ]
then
echo "Newer Version Detected"
# Set the field seperator to new line and then store the chucksums as an array with each element being a line
OLD_IFS=$IFS
IFS=$'\n'
releaseindex=( $(curl http://files.star-made.org$newversion/checksums) )
IFS=$OLD_IFS
# Set line count to 0 then go through the array line by line until the array index is unset
LINECOUNT=0
while [ -n "${releaseindex[$LINECOUNT]+set}" ]
do
CURRENTSTRING=${releaseindex[$LINECOUNT]}
#echo $CURRENTSTRING
# Format the current line by removing everything after the first space and then removing ./ in the beginning of the name
cutstring=${CURRENTSTRING%[[:space:]]*}
cutstring=${cutstring%[[:space:]]*}
CURRENTFILE=${cutstring/.\//}
# Formatfile was added here because when requesting web URL space should be replaced with %20
FORMATFILE=${CURRENTFILE// /%20}
cutstring=${CURRENTSTRING%[[:space:]]*}
cutstring=${cutstring##*[[:space:]]}
CURRENTCKSUM=${cutstring%%[[:space:]]*}
OLDCKSUMSTRING=$(cksum "StarMade/$CURRENTFILE")
# Check to see if OLDCKSUMSTRING is set, if not this indicates the file does not exist
if [ -z "$OLDCKSUMSTRING" ]
then
echo "No existing file found - downloading file"
# Makes sure directory structure is created if it does not exist for the file write
if [ ! -f "StarMade/$CURRENTFILE" ]; then
mkdir -p "StarMade/$CURRENTFILE"
rm -r "StarMade/$CURRENTFILE"
fi
curl "http://files.star-made.org$newversion/$FORMATFILE" > "StarMade/$CURRENTFILE"
else
cutstring=${OLDCKSUMSTRING#*[[:space:]]}
OLDCKSUM=${cutstring%%[[:space:]]*}
echo "CURRENTFILE $CURRENTFILE CURRENTCKSUM $CURRENTCKSUM OLDCKSUM $OLDCKSUM"
# Check to see if the cksums differ
if [ "$CURRENTCKSUM" -ne "$OLDCKSUM" ]
then
# Download the new file and then copy it into the proper location
echo "Updated file detected - downloading file"
# Makes sure directory structure is created if it does not exist for the file write
if [ ! -f "StarMade/$CURRENTFILE" ]; then
mkdir -p "StarMade/$CURRENTFILE"
rm -r "StarMade/$CURRENTFILE"
fi
curl "http://files.star-made.org$newversion/$FORMATFILE" > "StarMade/$CURRENTFILE"
else
echo "Current file detected - no action"
fi
fi
let LINECOUNT++
done
else
echo "Version Current"
fi
else
echo "You must install Curl to run this"
fi
# Starmade Selective upgrade script for BASH. Please run in the parent or root directory of Starmade
# Requires curl to be installed
# Grab the releaseindex as a very long string variable
echo "This script will install/update StarMade from the master repo. Use ./update.sh force to force a check on all files"
read -s -r -p "Press any key to continue..." -n 1 dummy
if command -v curl >/dev/null
then
echo "Curl was found"
releaseindex=$(curl http://files.star-made.org/releasebuildindex)
# Go to the end of the variable at the last .
newversion=${releaseindex##*.}
echo "newversion $newversion"
# Get the first version to compare
cutstring=${newversion#*_}
NEWSMVERSION1=${cutstring%_*}
echo "NEWSMVERSION1 $NEWSMVERSION1"
# Get the second version to compare
NEWSMVERSION2=${cutstring#*_}
echo "NEWSMVERSION2 $NEWSMVERSION2"
# Gather the old version from the version.txt file in StarMade
oldversion=$(cat StarMade/version.txt)
if [ -z "$oldversion" ]
then
echo "No install found for StarMade"
OLDSMVER1=0
OLDSMVER2=0
else
echo "oldversion $oldversion"
# Get the first version to compare
cutstring=${oldversion#*#}
OLDSMVER1=${cutstring%_*}
echo "OLDSMVER1 $OLDSMVER1"
# Get the second version to compare
OLDSMVER2=${cutstring#*_}
echo "OLDSMVER2 $OLDSMVER2"
fi
# If the first or second newversion exceeds the first or second old version
if [ "$NEWSMVERSION1" -gt "$OLDSMVER1" ] || [ "$NEWSMVERSION2" -gt "$OLDSMVER2" ] || [ "$1" = "force" ]
then
echo "Newer Version Detected"
# Set the field seperator to new line and then store the chucksums as an array with each element being a line
OLD_IFS=$IFS
IFS=$'\n'
releaseindex=( $(curl http://files.star-made.org$newversion/checksums) )
IFS=$OLD_IFS
# Set line count to 0 then go through the array line by line until the array index is unset
LINECOUNT=0
while [ -n "${releaseindex[$LINECOUNT]+set}" ]
do
CURRENTSTRING=${releaseindex[$LINECOUNT]}
#echo $CURRENTSTRING
# Format the current line by removing everything after the first space and then removing ./ in the beginning of the name
cutstring=${CURRENTSTRING%[[:space:]]*}
cutstring=${cutstring%[[:space:]]*}
CURRENTFILE=${cutstring/.\//}
# Formatfile was added here because when requesting web URL space should be replaced with %20
FORMATFILE=${CURRENTFILE// /%20}
cutstring=${CURRENTSTRING%[[:space:]]*}
cutstring=${cutstring##*[[:space:]]}
CURRENTCKSUM=${cutstring%%[[:space:]]*}
OLDCKSUMSTRING=$(cksum "StarMade/$CURRENTFILE")
# Check to see if OLDCKSUMSTRING is set, if not this indicates the file does not exist
if [ -z "$OLDCKSUMSTRING" ]
then
echo "No existing file found - downloading file"
# Makes sure directory structure is created if it does not exist for the file write
if [ ! -f "StarMade/$CURRENTFILE" ]; then
mkdir -p "StarMade/$CURRENTFILE"
rm -r "StarMade/$CURRENTFILE"
fi
curl "http://files.star-made.org$newversion/$FORMATFILE" > "StarMade/$CURRENTFILE"
else
cutstring=${OLDCKSUMSTRING#*[[:space:]]}
OLDCKSUM=${cutstring%%[[:space:]]*}
echo "CURRENTFILE $CURRENTFILE CURRENTCKSUM $CURRENTCKSUM OLDCKSUM $OLDCKSUM"
# Check to see if the cksums differ
if [ "$CURRENTCKSUM" -ne "$OLDCKSUM" ]
then
# Download the new file and then copy it into the proper location
echo "Updated file detected - downloading file"
# Makes sure directory structure is created if it does not exist for the file write
if [ ! -f "StarMade/$CURRENTFILE" ]; then
mkdir -p "StarMade/$CURRENTFILE"
rm -r "StarMade/$CURRENTFILE"
fi
curl "http://files.star-made.org$newversion/$FORMATFILE" > "StarMade/$CURRENTFILE"
else
echo "Current file detected - no action"
fi
fi
let LINECOUNT++
done
else
echo "Version Current"
fi
else
echo "You must install Curl to run this"
fi
Last edited: