Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # CaveStorySavegameBackup.sh
- # by Steve Duell
- # FOR THIS SCRIPT TO WORK CORRECTLY,
- # IT MUST BE PLACED IN THE SAME DIRECTORY
- # AS THE CAVE STORY EXECUTABLE (doukutsu).
- # QUESTIONS & COMMENTS ARE WELCOME:
- # steveduell (at) gmail (dot) com
- #!/bin/bash
- # Set backup limits.
- LIMIT=N # Y to limit, N for unlimited
- MAX=30 # Ignored if LIMIT is set to N.
- # Make a directory for backed up savegames if it's not already there:
- mkdir -p ./Savegame_Backups
- # Make a hidden timestamp file for comparing with your savegame:
- touch ./.timestamp
- # Start cave story & run it in the background:
- ./doukutsu &
- # Get the process ID & report it to the terminal:
- PID=$!
- # Title
- echo "***** The CAVE STORY AUTOMATIC SAVEGAME BACKER-UPPER by Steve Duell *****"
- echo ""
- # Inform user of the backup storage configuration:
- if [ $LIMIT = "N" ]
- then
- echo "The script is configured to store an unlimited number of backups."
- echo "If you'd like to change this, set the LIMIT switch to \"Y\"."
- echo ""
- else
- echo "The script is configured to store "$MAX" backups."
- echo "You can increase the maximum by editing the \"MAX\" value."
- echo "You can also set it to unlimited by setting the LIMIT switch to \"N\"."
- echo ""
- fi
- # Loop while cave story is running:
- while kill -0 $PID 2> /dev/null; do
- # If the save file (Profile.dat) is new, then back it up & rename it:
- while test ./Profile.dat -nt ./.timestamp; do
- # Get the current time:
- NOW=$(date "+%y%m%d_%H:%M:%S")
- # Backup the savegame and rename with current time:
- cp ./Profile.dat ./Savegame_Backups/Profile_$NOW.dat
- echo "**"
- echo "Backed up new savegame as Profile_"$NOW".dat"
- # Count the number of backups living in the backups folder:
- COUNT=$(ls ./Savegame_Backups -1 | wc -l)
- # If the number exceeds the maximum allowed, remove the oldest one:
- if [ $LIMIT == Y ]
- then
- if [ $COUNT -gt $MAX ]
- then
- OLD=$(ls ./Savegame_Backups | sort -t _ -k 2,2 | head -n 1)
- rm ./Savegame_Backups/$OLD
- echo "** Maximum backup limit of "$MAX" exceeded. Removing oldest backup."
- echo "** To increase the maximum, set the MAX variable,"
- echo "** or set the LIMIT switch to N for unlimited backups."
- echo ""
- else
- REMAIN=$((MAX - COUNT))
- echo "You have "$REMAIN" backup(s) remaining before reaching your limit."
- echo ""
- fi
- fi
- # Reset timestamp file:
- touch ./.timestamp
- done
- # Wait 1 second before checking for a new savegame:
- sleep 1
- done
- # Countdown to allow users time to view the output of the script before it close automatically:
- timecount(){
- min=0
- while [ $min -ge 0 ]; do
- sec=59
- echo "..."
- echo "Cave Story has shut down."
- echo "The script will continue to run until the timer runs out."
- echo "Press Ctrl^C to exit."
- while [ $sec -ge 0 ]; do
- echo -ne "00:0$min:$sec\033[0K\r"
- sec=$((sec-1))
- sleep 1
- done
- min=$((min-1))
- done
- }
- timecount
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement