From e8a3f3cec97b574fd7d7319178238d3b737a9a40 Mon Sep 17 00:00:00 2001 From: Alban Bronisz Date: Sat, 1 Aug 2026 10:20:12 +0200 Subject: [PATCH] New version --- README.md | 14 ++++-------- card_sync.sh | 59 --------------------------------------------------- config.sh | 36 +++++++++++++++++++++++++++++++ phone_sync.sh | 59 --------------------------------------------------- run.sh | 55 +++++++++++++++++++++++++++++++++++++++++++++-- 5 files changed, 93 insertions(+), 130 deletions(-) delete mode 100755 card_sync.sh create mode 100644 config.sh delete mode 100755 phone_sync.sh diff --git a/README.md b/README.md index 57e6ab5..b7009cf 100644 --- a/README.md +++ b/README.md @@ -31,22 +31,16 @@ This app has a widget that show IP address when turned on. sudo apt install lftp -- Configure the script [phone_synch.sh](./phone_synch.sh) (doc is embedded on the first lines). +- Configure the script [config.sh](./config.sh) to set FTP credentials and sync folders for phone and card. Synchronize ----------- At home, connect your mobile and computer to the wifi. -Start the mobile FPT server, using the widget +Start the mobile FTP server, using the widget Launch the script : - ./synch_phone.sh - - -Have also a memory card on your phone? --------------------------------------- -No problemo :) -Configure also the script [card_synch.sh](./card_synch.sh) and to launch both synchronisation, run: - ./run.sh +This will synchronize both phone and card data according to the configuration in [config.sh](./config.sh). + diff --git a/card_sync.sh b/card_sync.sh deleted file mode 100755 index 6a7a064..0000000 --- a/card_sync.sh +++ /dev/null @@ -1,59 +0,0 @@ -#!/bin/bash -set -e # Exit if error - - -# This script synchronizes data from FTP into local folder: -# - remove file that do not exist anymore in the FTP (mirror -e) -# -# No modification will be done in the FTP. -# -# Configuration is gathered at the beginning of the script. - - -# ============================================================================= -# Configuration -# ============================================================================= -FTP_USER=card -FTP_PASS=card -FTP_IP=192.168.1.30 -FTP_PORT=2121 - - -DESTINATION=Card/ # Local folder where to save files - -# List of folders to save -# example: LINK+=("/distant/dir" "dir2") -# will saved FTP folder "/distant/dir" in local folder "$DESTINATION/dir2" - -LINK=() -LINK+=("DCIM" "DCIM") -LINK+=("Download" "Download") - - - - - - - -# ============================================================================= -echo "=========================================================" -echo "Start synchronisation to ${DESTINATION}" -echo "=========================================================" -find ${DESTINATION} -type f -exec chmod 644 {} \; -find ${DESTINATION} -type d -exec chmod 755 {} \; - -for ((i=0; i<${#LINK[@]}; i+=2)); do - DISTANT_DIR=${LINK[i]} - LOCAL_DIR=${LINK[i+1]} - echo "############################## ${DISTANT_DIR} > ${LOCAL_DIR}" - mkdir -p "${DESTINATION}/${LOCAL_DIR}/" - - if lftp ftp://${FTP_USER}:${FTP_PASS}@${FTP_IP}:${FTP_PORT} -e "mirror -e -x .thumbnails -x "saved" \"${DISTANT_DIR}\" \"${DESTINATION}/${LOCAL_DIR}\" ; quit" ; then - echo "Success :)" - else - echo 'Failed !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!' - fi -done - - - diff --git a/config.sh b/config.sh new file mode 100644 index 0000000..123bed3 --- /dev/null +++ b/config.sh @@ -0,0 +1,36 @@ +#!/bin/bash +# Configuration file for run.sh + +# ============================================================================= +# Phone Configuration +# ============================================================================= +PHONE_FTP_USER=ftp +PHONE_FTP_PASS=ftp +PHONE_FTP_IP=192.168.1.30 +PHONE_FTP_PORT=2121 +PHONE_DESTINATION="Phone/" + +# List of folders to sync: pairs of (remote_dir, local_dir) +PHONE_LINKS=( + "/DCIM" "DCIM" + "/Pictures" "Pictures" + "/Download" "Download" + "/WhatsApp/Media/WhatsApp Video" "WhatsApp_Video" + "/WhatsApp/Media/WhatsApp Images" "WhatsApp_Images" + "/Documents" "Documents" +) + +# ============================================================================= +# Card Configuration +# ============================================================================= +CARD_FTP_USER=card +CARD_FTP_PASS=card +CARD_FTP_IP=192.168.1.30 +CARD_FTP_PORT=2121 +CARD_DESTINATION="Card/" + +# List of folders to sync: pairs of (remote_dir, local_dir) +CARD_LINKS=( + "DCIM" "DCIM" + "Download" "Download" +) diff --git a/phone_sync.sh b/phone_sync.sh deleted file mode 100755 index 5738e35..0000000 --- a/phone_sync.sh +++ /dev/null @@ -1,59 +0,0 @@ -#!/bin/bash -set -e # Exit if error - - -# This script synchronizes data from FTP into local folder: -# - remove file that do not exist anymore in the FTP (mirror -e) -# -# No modification will be done in the FTP. -# -# Configuration is gathered at the beginning of the script. - - -# ============================================================================= -# Configuration -# ============================================================================= -FTP_USER=ftp -FTP_PASS=ftp -FTP_IP=192.168.1.30 -FTP_PORT=2121 - - -DESTINATION=Phone/ # Local folder where to save files - -# List of folders to save -# example: LINK+=("/distant/dir" "dir2") -# will saved FTP folder "/distant/dir" in local folder "$DESTINATION/dir2" - -LINK=() -LINK+=("/DCIM" "DCIM") -LINK+=("/Pictures" "Pictures") -LINK+=("/Download" "Download") -LINK+=("/WhatsApp/Media/WhatsApp Video" "WhatsApp_Video") -LINK+=("/WhatsApp/Media/WhatsApp Images" "WhatsApp_Images") -LINK+=("/Documents" "Documents") - - -# ============================================================================= -echo "=========================================================" -echo "Start synchronisation to ${DESTINATION}" -echo "=========================================================" -find ${DESTINATION} -type f -exec chmod 644 {} \; -find ${DESTINATION} -type d -exec chmod 755 {} \; - -for ((i=0; i<${#LINK[@]}; i+=2)); do - DISTANT_DIR=${LINK[i]} - LOCAL_DIR=${LINK[i+1]} - echo "############################## ${DISTANT_DIR} > ${LOCAL_DIR}" - mkdir -p "${DESTINATION}/${LOCAL_DIR}/" - - if lftp ftp://${FTP_USER}:${FTP_PASS}@${FTP_IP}:${FTP_PORT} -e "mirror -e -x .thumbnails -x "saved" \"${DISTANT_DIR}\" \"${DESTINATION}/${LOCAL_DIR}\" ; quit" ; then - echo "Success :)" - else - echo 'Failed !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!' - fi -done - - - - diff --git a/run.sh b/run.sh index 13b0129..8c7d617 100755 --- a/run.sh +++ b/run.sh @@ -2,6 +2,57 @@ set -e # Exit if error +# Load configuration +source "$(dirname "$0")/config.sh" -./phone_sync.sh -./card_sync.sh +# ============================================================================= +# Sync function +# Usage: sync_ftp PREFIX +# PREFIX = PHONE or CARD (used to get config vars: ${PREFIX}_FTP_USER, etc.) +# ============================================================================= +sync_ftp() { + local PREFIX=$1 + local FTP_USER_var="${PREFIX}_FTP_USER" + local FTP_PASS_var="${PREFIX}_FTP_PASS" + local FTP_IP_var="${PREFIX}_FTP_IP" + local FTP_PORT_var="${PREFIX}_FTP_PORT" + local DESTINATION_var="${PREFIX}_DESTINATION" + local LINKS_NAME="${PREFIX}_LINKS" + + local FTP_USER="${!FTP_USER_var}" + local FTP_PASS="${!FTP_PASS_var}" + local FTP_IP="${!FTP_IP_var}" + local FTP_PORT="${!FTP_PORT_var}" + local DESTINATION="${!DESTINATION_var}" + + echo "=========================================================" + echo "Start synchronisation to ${DESTINATION}" + echo "=========================================================" + + # Set permissions + find "${DESTINATION}" -type f -exec chmod 644 {} \; + find "${DESTINATION}" -type d -exec chmod 755 {} \; + + # Get links array + eval "local LINKS=(\"\${$LINKS_NAME[@]}\")" + + # Sync each folder pair + for ((i=0; i<${#LINKS[@]}; i+=2)); do + local DISTANT_DIR="${LINKS[i]}" + local LOCAL_DIR="${LINKS[i+1]}" + echo "############################## ${DISTANT_DIR} > ${LOCAL_DIR}" + mkdir -p "${DESTINATION}${LOCAL_DIR}/" + + if lftp ftp://"${FTP_USER}:${FTP_PASS}@${FTP_IP}:${FTP_PORT}" -e "mirror -e -x .thumbnails -x saved \"${DISTANT_DIR}\" \"${DESTINATION}${LOCAL_DIR}\" ; quit" ; then + echo "Success :)" + else + echo 'Failed !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!' + fi + done +} + +# ============================================================================= +# Run sync for phone and card +# ============================================================================= +sync_ftp PHONE +sync_ftp CARD