useful_scripts/sd-script.sh
2025-03-23 10:03:54 +01:00

99 lines
2.9 KiB
Bash
Executable file

#!/bin/bash
#Config file
cfg="$HOME/.config/sd-script.config"
if [ ! -f $cfg ]; then
touch $cfg
read -p "Where do you want to save your photos? [directory]: " destprompt
echo "destdir='$destprompt'" >> $cfg
read -p "Do you use sudo or doas?: " admin
echo "doso='$admin'" >> $cfg
fi
source $cfg
#Constant vars
sd_uuid="3735-3761"
mntpoint="/mnt/nikon"
srcdir="$mntpoint/DCIM/100_____"
#Colors
GREEN="\e[32m"
RED="\e[31m"
YELLOW="\e[33m"
ENDCOLOR="\e[0m"
#Copying locally
$doso mkdir $mntpoint #&> /dev/null
if $doso mount -U $sd_uuid $mntpoint; then
echo -e "[✅]$GREEN Mounted SD successfully$ENDCOLOR"
else echo -e "[❌] $RED Failed to mount SD$ENDCOLOR" && exit 1;
fi
mkdir $destdir &> /dev/null
echo -e "You have $YELLOW$(ls -l $srcdir/*.JPG | wc -l) JPG files$ENDCOLOR and $YELLOW$(ls -l $srcdir/*.NEF | wc -l) NEF files$ENDCOLOR."
if rsync -rvu --ignore-existing --info=progress2 $srcdir/ $destdir/pics-$(date '+%d-%b-%Y')/; then
echo -e "[✅]$GREEN Copying successful.$ENDCOLOR"
else echo -e "[❌] $RED Operation failed.$ENDCOLOR" && exit 1; fi
echo -e "Files from SD card will be removed in 3 seconds. If you don't want to delete files, press ctrl+C now."
sleep 3
$doso chown -R $USER:$USER $srcdir/
rm -fv $srcdir/*
#Copying to other PCS
while true; do
printf "[✅]All good. We can now send the files to other PCs. These are some presets:
1)
Host: Waffelo's Pinephone
IP: 192.168.0.148
User: alarm
dir: .local/usr/Pictures/nikon
2)
Host: Waffelo's PC
IP: 192.168.0.203
User: waffelo
dir: /media/hdd/Pictures/nikon
3)
Host: Jacob's Pinephone
IP: 192.168.0.157
User: alarm
dir: .local/usr/Pictures/nikon
4)
Host: Jacob's PC
IP: 192.168.0.184
User: jacob
dir: /mnt/hdd/nikon
5)
Quit script."
read -p "Choose a number (or 'all'): " num
case $num in
1) if rsync -rvu --ignore-existing $destdir/ alarm@192.168.0.148:$HOME/.local/usr/Pictures/nikon/pics-$(date '+%d-%b-%Y')/ ; then
echo -e "[✅]$GREEN Copying successful.$ENDCOLOR"
else echo -e "[❌] $RED Copying failed. Check IP in settings.$ENDCOLOR"; fi;;
2) if rsync -rvu --ignore-existing $destdir/ waffelo@192.168.0.203:/media/hdd/Pictures/nikon/pics-$(date '+%d-%b-%Y')/ ; then
echo -e "[✅]$GREEN Copying successful.$ENDCOLOR"
else echo -e "[❌] $RED Copying failed. Check IP in settings.$ENDCOLOR"; fi;;
3) if rsync -rvu --ignore-existing $destdir/ alarm@192.168.0.157:/home/alarm/.local/usr/Pictures/nikon/pics-$(date '+%d-%b-%Y')/ ; then
echo -e "[✅]$GREEN Copying successful.$ENDCOLOR"
else echo -e "[❌] $RED Copying failed. Check IP in settings.$ENDCOLOR"; fi;;
4) if rsync -rvu --ignore-existing $destdir/ jacob@192.168.0.184:/mnt/hdd/nikon/pics-$(date '+%d-%b-%Y')/ ; then
echo -e "[✅]$GREEN Copying successful.$ENDCOLOR"
else echo -e "[❌] $RED Copying failed. Check IP in settings.$ENDCOLOR"; fi;;
5) exit 0;;
*) echo "Invalid response."
esac
done
exit 0