85 lines
2.2 KiB
Bash
85 lines
2.2 KiB
Bash
|
#!/usr/bin/env bash
|
||
|
set -e
|
||
|
|
||
|
# Function to display usage
|
||
|
usage() {
|
||
|
echo "Usage: $0 [--video]"
|
||
|
exit 1
|
||
|
}
|
||
|
|
||
|
# Parse command-line arguments
|
||
|
COPY_VIDEOS=false
|
||
|
|
||
|
while [[ "$#" -gt 0 ]]; do
|
||
|
case $1 in
|
||
|
-v|--video)
|
||
|
COPY_VIDEOS=true
|
||
|
shift
|
||
|
;;
|
||
|
-h|--help)
|
||
|
usage
|
||
|
;;
|
||
|
*)
|
||
|
echo "Unknown parameter passed: $1"
|
||
|
usage
|
||
|
;;
|
||
|
esac
|
||
|
done
|
||
|
|
||
|
if [ -n "$(find . -maxdepth 1 -type f -name "*.bplist" -print -quit)" ]; then
|
||
|
scp ./*.bplist winroar:BSManager/BSInstances/1.39.1/Playlists/
|
||
|
rm -v ./*.bplist
|
||
|
fi
|
||
|
|
||
|
##
|
||
|
## Playlist Archive
|
||
|
##
|
||
|
|
||
|
# Define remote and local directories for playlist synchronization
|
||
|
REMOTE_PLAYLISTS="BSManager/BSInstances/1.39.1/Playlists/"
|
||
|
LOCAL_ARCHIVE_DIR=~/archive/beatsaber-playlists/
|
||
|
LOCAL_ARCHIVE_SUBDIR=~/archive/beatsaber-playlists/archive/
|
||
|
PREVIOUS_LIST=~/archive/beatsaber-playlists/previous_bplist_files.txt
|
||
|
|
||
|
# Ensure archive subdirectory exists
|
||
|
mkdir -p "$LOCAL_ARCHIVE_SUBDIR"
|
||
|
|
||
|
# Fetch current remote *.bplist files
|
||
|
ssh winroar "cd \"${REMOTE_PLAYLISTS}\" && dir /B *.bplist" > current_bplist_files.txt
|
||
|
|
||
|
# Compare with previous list to find deleted files
|
||
|
if [[ -f "$PREVIOUS_LIST" ]]; then
|
||
|
deleted_files=$(comm -23 <(sort "$PREVIOUS_LIST") <(sort current_bplist_files.txt))
|
||
|
for file in $deleted_files; do
|
||
|
filename=$(basename "$file")
|
||
|
if [[ -f "${LOCAL_ARCHIVE_DIR}${filename}" ]]; then
|
||
|
mv "${LOCAL_ARCHIVE_DIR}${filename}" "$LOCAL_ARCHIVE_SUBDIR"
|
||
|
echo "Archived deleted playlist: $filename"
|
||
|
fi
|
||
|
done
|
||
|
fi
|
||
|
|
||
|
# Update the previous list
|
||
|
mv current_bplist_files.txt "$PREVIOUS_LIST"
|
||
|
|
||
|
# Sync playlist files from remote to local
|
||
|
scp -q winroar:"${REMOTE_PLAYLISTS}*.bplist" "$LOCAL_ARCHIVE_DIR"
|
||
|
|
||
|
# Optional video synchronization
|
||
|
if $COPY_VIDEOS; then
|
||
|
echo "Starting video synchronization..."
|
||
|
|
||
|
# Copy videos from remote to local Downloads folder
|
||
|
scp -r winroar:"Videos/Beat Saber/" "$HOME/Downloads/"
|
||
|
|
||
|
echo "Video files copied successfully."
|
||
|
|
||
|
echo "Press [Enter] to delete videos on winroar."
|
||
|
read -r
|
||
|
|
||
|
# Delete videos on remote after confirmation
|
||
|
ssh winroar 'rmdir Videos/Beat\ Saber /q /s'
|
||
|
|
||
|
echo "Remote video directory deleted."
|
||
|
fi
|