2024-10-14 10:02:22 +03:00
|
|
|
#!/bin/sh
|
|
|
|
# Sync icloud photos to machine using a
|
|
|
|
# simple wrapper for tmux and icloudpd
|
|
|
|
|
|
|
|
# Check if icloudpd is available
|
|
|
|
if ! type icloudpd >/dev/null; then
|
2024-10-14 10:46:34 +03:00
|
|
|
echo "please install icloud photo downloader."
|
|
|
|
echo "See: https://github.com/icloud-photos-downloader/icloud_photos_downloader"
|
|
|
|
exit 1
|
2024-10-14 10:02:22 +03:00
|
|
|
fi
|
|
|
|
|
2024-10-14 10:56:58 +03:00
|
|
|
# Ensure environment variables are set
|
|
|
|
if [[ -z "$ICLOUD_DIR" ]]; then
|
|
|
|
echo 'please set $ICLOUD_DIR'
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ -z "$ICLOUD_USERNAME" ]]; then
|
|
|
|
echo 'please set $ICLOUD_USERNAME'
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2024-10-14 11:03:07 +03:00
|
|
|
# Set tmux session name
|
2024-10-14 10:46:34 +03:00
|
|
|
session="icloudsync"
|
|
|
|
|
|
|
|
attach () {
|
|
|
|
tmux attach-session -t $session
|
|
|
|
}
|
|
|
|
|
|
|
|
check_session () {
|
|
|
|
tmux has-session -t $session 2>/dev/null
|
|
|
|
if [ $? == 0 ]; then
|
|
|
|
return 1
|
|
|
|
else
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
start_sync () {
|
|
|
|
if check_session 0; then
|
|
|
|
tmux new-session -d -s $session
|
2024-10-14 10:48:11 +03:00
|
|
|
tmux send-keys -t $session 'icloudpd --directory=$ICLOUD_DIR --username $ICLOUD_USERNAME --watch-with-interval 3600' C-m
|
2024-10-14 10:46:34 +03:00
|
|
|
echo started
|
|
|
|
else
|
|
|
|
echo already active
|
2024-10-14 10:02:22 +03:00
|
|
|
fi
|
2024-10-14 10:46:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
stop_sync () {
|
2024-10-14 10:50:45 +03:00
|
|
|
if check_session 0; then
|
|
|
|
echo inactive
|
|
|
|
else
|
|
|
|
tmux send-keys -t $session C-c exit C-m
|
|
|
|
echo stopped
|
|
|
|
fi
|
2024-10-14 10:46:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
status () {
|
|
|
|
if check_session 0; then
|
|
|
|
echo inactive
|
|
|
|
else
|
|
|
|
tmux capture-pane -t icloudsync -p -S -1 | tail -1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2024-10-14 11:03:07 +03:00
|
|
|
msg="available commands are: start, stop, attach, status"
|
2024-10-14 10:46:34 +03:00
|
|
|
if [[ $# -eq 0 ]]; then
|
2024-10-14 11:03:07 +03:00
|
|
|
echo $msg
|
2024-10-14 10:02:22 +03:00
|
|
|
fi
|
|
|
|
|
2024-10-14 10:46:34 +03:00
|
|
|
while [[ $# -gt 0 ]]; do
|
|
|
|
case $1 in
|
|
|
|
start)
|
|
|
|
start_sync
|
|
|
|
;;
|
|
|
|
stop)
|
|
|
|
stop_sync
|
|
|
|
;;
|
|
|
|
attach)
|
|
|
|
attach
|
|
|
|
;;
|
|
|
|
status)
|
|
|
|
status
|
|
|
|
;;
|
|
|
|
esac
|
2024-10-14 11:03:07 +03:00
|
|
|
echo $msg
|
2024-10-14 10:46:34 +03:00
|
|
|
exit
|
|
|
|
done
|
2024-10-14 11:03:07 +03:00
|
|
|
|