From adfd0eb28e15b896cc4c20147347a8f5fbc66777 Mon Sep 17 00:00:00 2001 From: WickedYoda <68271168+wickedyoda@users.noreply.github.com> Date: Mon, 2 Dec 2024 14:13:00 -0600 Subject: [PATCH] Starting mac scripts --- mac-scripts/rsync basic.sh | 56 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 mac-scripts/rsync basic.sh diff --git a/mac-scripts/rsync basic.sh b/mac-scripts/rsync basic.sh new file mode 100644 index 0000000..3f0074c --- /dev/null +++ b/mac-scripts/rsync basic.sh @@ -0,0 +1,56 @@ +#!/bin/bash + +# SMB share credentials +NAS_USERNAME="your_username" +NAS_PASSWORD="your_password" +NAS_ADDRESS="nas" +NAS_SHARE="mymedia" + +# Local folders to sync +LOCAL_FOLDERS=( + "/path/to/your/folder1" + "/path/to/your/folder2" +) + +# Mount point for the SMB share +MOUNT_POINT="/Volumes/mymedia" + +# Ensure the mount point exists +if [ ! -d "$MOUNT_POINT" ]; then + mkdir -p "$MOUNT_POINT" +fi + +# Mount the SMB share +echo "Mounting SMB share..." +mount -t smbfs "//$NAS_USERNAME:$NAS_PASSWORD@$NAS_ADDRESS/$NAS_SHARE" "$MOUNT_POINT" +if [ $? -ne 0 ]; then + echo "Failed to mount SMB share. Please check your credentials and network connection." + exit 1 +fi + +echo "SMB share mounted successfully at $MOUNT_POINT." + +# Sync local folders to the SMB share +for LOCAL_FOLDER in "${LOCAL_FOLDERS[@]}"; do + BASENAME=$(basename "$LOCAL_FOLDER") + DESTINATION="$MOUNT_POINT/$BASENAME" + + echo "Syncing $LOCAL_FOLDER to $DESTINATION..." + rsync -avh --progress "$LOCAL_FOLDER/" "$DESTINATION/" + if [ $? -ne 0 ]; then + echo "Failed to sync $LOCAL_FOLDER." + else + echo "Successfully synced $LOCAL_FOLDER." + fi +done + +# Unmount the SMB share +echo "Unmounting SMB share..." +umount "$MOUNT_POINT" +if [ $? -ne 0 ]; then + echo "Failed to unmount SMB share. Please unmount it manually." +else + echo "SMB share unmounted successfully." +fi + +echo "Sync operation completed." \ No newline at end of file