Skip to content

Instantly share code, notes, and snippets.

@Leask
Last active January 10, 2020 22:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Leask/03d4ca4424acc20743c8f080bb512df3 to your computer and use it in GitHub Desktop.
Save Leask/03d4ca4424acc20743c8f080bb512df3 to your computer and use it in GitHub Desktop.
BlackBox is a simple toolkit to backup my GoPro videos and my Blackberry phone records.
#!/bin/sh
# Flora BlackBox Utilities by LeaskH.com
# BlackBox is a simple toolkit to backup my GoPro videos and my Blackberry phone records.
initBlackBox() {
if [ -e "$basePath" ]; then
logFile="$basePath$logFile"
echoWithLog "<<<<<<< Flora BlackBox >>>>>>>\n"
else
logFile="/var/log$logFile"
errorNotify 'BlackBox Missing'
exit 1
fi
}
log() {
echo "`date '+%Y/%m/%d %H:%M:%S'` $1" >> $logFile
}
echoWithLog() {
echo "$1"
log "$1"
}
backupVideos() {
if [ -e "$heroPath" ]; then
echoWithLog "> Found GoPro Hero mounted at path: $heroPath"
else
errorNotify 'GoPro Hero is offline'
exit 1
fi
if [ -e "$videoPath" ]; then
echoWithLog "> Found Videos BlackBox at path: $videoPath"
else
errorNotify 'Videos BlackBox is missing'
exit 1
fi
folder=$videoPath/`date +%Y.%m.%d`
if [ ! -e "$folder" ]; then
mkdir "$folder"
fi
echoWithLog "> Backing up GoPro Videos to: $folder"
for subFolder in "$heroPath"/*GOPRO; do
if [ -e "$subFolder" ]; then
rsmv "$subFolder"/*.MP4 "$folder/"
fi
done
doneNotify 'Finished backing up videos'
cleanupGopro
}
backupPhotos() {
if [ -e "$heroPath" ]; then
echoWithLog "> Found GoPro Hero mounted at path: $heroPath"
else
errorNotify 'GoPro Hero is offline'
exit 1
fi
if [ -e "$photoPath" ]; then
echoWithLog "> Found Photos BlackBox at path: $photoPath"
else
errorNotify 'Photos BlackBox is missing'
exit 1
fi
folder=$photoPath/`date +%Y.%m.%d`
if [ ! -e "$folder" ]; then
mkdir "$folder"
fi
echoWithLog "> Backing up GoPro Photos to: $folder"
for subFolder in "$heroPath"/*GOPRO; do
if [ -e "$subFolder" ]; then
rsmv "$subFolder"/*.JPG "$folder/"
fi
done
doneNotify 'Finished backing up photos'
}
backupVoice() {
if [ -e "$tapeAPath" ]; then
echoWithLog "> Found SONY IC Recorder Tape A mounted at path: $tapeAPath"
else
errorNotify 'SONY IC Recorder Tape A is offline'
exit 1
fi
# if [ -e "$tapeBPath" ]; then
# echoWithLog "> Found SONY IC Recorder Tape B mounted at path: $tapeBPath"
# else
# errorNotify 'SONY IC Recorder Tape B is offline'
# exit 1
# fi
if [ -e "$voicePath" ]; then
echoWithLog "> Found Voice BlackBox at path: $voicePath"
else
errorNotify 'Voice BlackBox is missing'
exit 1
fi
folder=$voicePath/`date +%Y.%m`
if [ ! -e "$folder" ]; then
mkdir "$folder"
fi
echoWithLog "> Backing up SONY IC Recorder Voice to: $folder"
for subFolder in "$tapeAPath"/FOLDER*; do
if [ ! $(find "$subFolder" | wc -l) -eq 1 ]; then
rsmv "$subFolder"/* "$folder/"
fi
done
# for subFolder in "$tapeBPath"/FOLDER*; do
# if [ ! $(find "$subFolder" | wc -l) -eq 1 ]; then
# rsmv "$subFolder"/* "$folder/"
# fi
# done
unmount 'Tape-A'
# unmount 'Tape-B'
doneNotify 'Finished backing up voice'
}
backupFiles() {
if [ -e "$deskPath" ]; then
echoWithLog "> Found backup source: $deskPath"
else
errorNotify 'Backup source is missing'
exit 1
fi
if [ -e "$filesPath" ]; then
echoWithLog "> Found Files BlackBox at path: $filesPath"
else
errorNotify 'Files BlackBox is missing'
exit 1
fi
folder=$filesPath/`date +%Y.%m`
if [ ! -e "$folder" ]; then
mkdir "$folder"
fi
echoWithLog "> Backing up Files to: $folder"
rscp "$deskPath"/* "$folder/"
doneNotify 'Finished backing up files'
}
backupIDevice() {
if [ -e "$idevPath" ]; then
echoWithLog "> Found backup source: $idevPath"
else
errorNotify 'Backup source is missing'
exit 1
fi
if [ -e "$devbkPath" ]; then
echoWithLog "> Found iOS Devices BlackBox at path: $devbkPath"
else
errorNotify 'iOS Devices BlackBox is missing'
exit 1
fi
folder=$devbkPath/`date +%Y.%m`
if [ ! -e "$folder" ]; then
mkdir "$folder"
fi
echoWithLog "> Backing up iOS Devices to: $folder"
for subFolder in "$idevPath"/*; do
if [ -e "$subFolder" ]; then
devName=`defaults read "${subFolder}/Info.plist" 'Device Name'`
if [ "$devName" != '' ]; then
echo "> Backing up: ${devName}"
fi
rsmv "$subFolder" "$folder/"
if [ $(find "$subFolder" | wc -l) -eq 1 ]; then
echoWithLog Drop folder: "$subFolder"
rm -rf "$subFolder"
else
echoWithLog Leaved folder: "$subFolder"
fi
fi
done
doneNotify 'Finished backing up iOS Devices'
}
unmount() {
diskutil unmount /dev/`diskutil list | grep -i "$1" | awk '{print $6}'` &> $tmpSay
# diskutil unmount /dev/`diskutil list | grep -i "$1" | awk '{print $7}'` &> $tmpSay
strSay="`cat $tmpSay`"
echoWithLog "> $strSay"
notify "$strSay"
say -f $tmpSay
rm $tmpSay
}
doneNotify() {
strNote="$1 :)"
echoWithLog "> $strNote\n"
notify "$strNote"
say "$1"
}
errorNotify() {
strNote="Error: $1!"
echoWithLog "> $strNote\n"
notify "$strNote"
say "$strNote"
}
backupPhone() {
echoWithLog ''
}
backupGopro() {
backupPhotos
backupVideos
}
cleanupGopro() {
if [ -e "$heroPath" ]; then
echoWithLog "> Found GoPro Hero mounted at path: $heroPath"
else
errorNotify 'GoPro Hero is offline'
exit 1
fi
echoWithLog "> Cleaning up GoPro..."
for subFolder in "$heroPath"/*GOPRO; do
if [ -e "$subFolder" ]; then
rm -f "$subFolder"/*.THM
rm -f "$subFolder"/*.LRV
if [ $(find "$subFolder" | wc -l) -eq 1 ]; then
echoWithLog Drop folder: "$subFolder"
rm -rf "$subFolder"
else
echoWithLog Leaved folder: "$subFolder"
fi
fi
done
unmount 'Flora-HERO'
doneNotify 'Finished cleaning GoPro'
}
unknowCommand() {
errorNotify 'Unknow command'
showHelp
exit 1
}
showHelp() {
echoWithLog '- gopro: Backup GoPro'
echoWithLog '- video: Backup videos'
echoWithLog '- photo: Backup photos'
echoWithLog '- voice: Backup voice'
echoWithLog '- phone: Backup phone'
echoWithLog '- files: Backup files'
echoWithLog "- helps: Show this infos\n"
}
rscp() {
rsync -aPtv --log-file="$logFile" "$@"
}
rsmv() {
rsync -aPtv --remove-source-files --log-file="$logFile" "$@"
}
# BlackBox configurations
basePath=/Volumes/Phoenix/Leask/Black\ Box
videoPath=$basePath/Videos
photoPath=$basePath/Photos
phonePath=$basePath/Phone
voicePath=$basePath/Voice
filesPath=$basePath/Files
devbkPath=$basePath/iOS\ Devices
tmpSay=/tmp/blackbox.say
deskPath=~/Desktop
idevPath=~/Library/Application\ Support/MobileSync/Backup
heroPath=/Volumes/Flora-HERO/DCIM
tapeAPath=/Volumes/TAPE-A/VOICE
tapeBPath=/Volumes/TAPE-B/private/SONY/VOICE
berryPath=/Volumes/
logFile=/blackbox.log
# Main logic
initBlackBox
case "$1" in
'video') backupVideos;;
'photo') backupPhotos;;
'voice') backupVoice;;
'phone') backupPhone;;
'gopro') backupGopro;;
'files') backupFiles;;
'idev' ) backupIDevice;;
'help' ) showHelp;;
* ) unknowCommand;;
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment