aboutsummaryrefslogtreecommitdiffstats
path: root/util/download-latest-save.bash
diff options
context:
space:
mode:
authorm-chandler <mchandler89@gmail.com>2024-10-14 08:35:58 +1000
committerGitHub <noreply@github.com>2024-10-14 08:35:58 +1000
commit9ad64993477c849da2e487b0c8c3034ff9eadb88 (patch)
tree3c6b1029073547e962761f7ce94d1ebb5dded2ce /util/download-latest-save.bash
parentfe59339df077f7c4a02aad744ff136e57ae60176 (diff)
parent3e68275ca3e72895c7af53d788eaa4e8d2c9889c (diff)
Merge pull request #36 from robertmassaioli/bring-in-utility-scripts
Bring in utility scripts
Diffstat (limited to 'util/download-latest-save.bash')
-rw-r--r--util/download-latest-save.bash67
1 files changed, 67 insertions, 0 deletions
diff --git a/util/download-latest-save.bash b/util/download-latest-save.bash
new file mode 100644
index 0000000..2a84660
--- /dev/null
+++ b/util/download-latest-save.bash
@@ -0,0 +1,67 @@
+#!/bin/bash
+
+# Check if remote name is provided
+if [ $# -ne 1 ]; then
+ echo "Usage: $0 <remote_name>"
+ exit 1
+fi
+
+remote_name="$1"
+
+# Generate a human-readable timestamp
+timestamp=$(date +"%Y-%m-%d_%H-%M-%S")
+
+# SSH into the remote instance to find the most recent save file
+ssh_output=$(ssh "ec2-user@$remote_name" << EOF
+ # Record the current directory
+ current_dir=\$(pwd)
+
+ # Find the save directory
+ savedir=\$(sudo mount | grep nfs4 | cut -f3 -d ' ' | xargs -I {} echo "{}/saves")
+ echo "Save directory: \$savedir"
+
+ if [ -z "\$savedir" ]; then
+ echo "ERROR: Save directory not found"
+ exit 1
+ fi
+
+ # Find the most recently modified file in the save directory
+ latest_file=\$(sudo ls -t \$savedir | head -1)
+
+ if [ -z "\$latest_file" ]; then
+ echo "ERROR: No files found in the save directory"
+ exit 1
+ fi
+
+ echo "Latest save file: \$latest_file"
+
+ # Copy the latest file to the current directory
+ sudo cp "\$savedir/\$latest_file" "\$current_dir/"
+
+ # Change ownership of the copied file to ec2-user
+ sudo chown ec2-user:ec2-user "\$current_dir/\$latest_file"
+
+ echo "\$current_dir/\$latest_file"
+EOF
+)
+
+# Check if there was an error in the SSH command
+if echo "$ssh_output" | grep -q "ERROR:"; then
+ echo "$ssh_output"
+ exit 1
+fi
+
+# Extract the full path of the latest file
+latest_file_path=$(echo "$ssh_output" | tail -n 1)
+
+# Extract just the filename
+latest_file=$(basename "$latest_file_path")
+
+# Download the file from the remote instance to the current local directory with the new filename
+new_filename="${remote_name}_${timestamp}_${latest_file}"
+scp "ec2-user@$remote_name:$latest_file_path" "./$new_filename"
+
+# Clean up the temporary file on the remote instance
+ssh "ec2-user@$remote_name" "rm -f $latest_file_path"
+
+echo "Download complete. The latest save file has been saved as '$new_filename' in your current directory." \ No newline at end of file
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage