Rewrote icloudsync to handle start,stop,attach,status
This commit is contained in:
parent
584d85ef90
commit
131232c5cf
1 changed files with 59 additions and 14 deletions
|
@ -1,26 +1,71 @@
|
|||
#!/bin/sh
|
||||
# Sync icloud photos to machine using a
|
||||
# simple wrapper for tmux and icloudpd
|
||||
session="icloudsync"
|
||||
|
||||
# Check if icloudpd is available
|
||||
if ! type icloudpd >/dev/null; then
|
||||
echo "please install icloud photo downloader."
|
||||
echo "See: https://github.com/icloud-photos-downloader/icloud_photos_downloader"
|
||||
exit 1
|
||||
echo "please install icloud photo downloader."
|
||||
echo "See: https://github.com/icloud-photos-downloader/icloud_photos_downloader"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
tmux has-session -t $session 2>/dev/null
|
||||
# tmux session name
|
||||
session="icloudsync"
|
||||
|
||||
if [ $? != 0 ]; then
|
||||
tmux new-session -d -s $session
|
||||
tmux send-keys -t $session "icloudpd --directory=$HOME/Pictures --username \$ICLOUD_USERNAME" C-m
|
||||
echo "icloudsync started"
|
||||
else
|
||||
if [[ $1 == "attach" ]]; then
|
||||
tmux attach-session -t $session
|
||||
else
|
||||
echo "icloudsync already active: use icloudsync attach to view progress"
|
||||
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
|
||||
tmux send-keys -t $session 'icloudpd --directory=$HOME/Pictures --username $ICLOUD_USERNAME --watch-with-interval 3600' C-m
|
||||
echo started
|
||||
else
|
||||
echo already active
|
||||
fi
|
||||
}
|
||||
|
||||
stop_sync () {
|
||||
tmux send-keys -t $session C-c exit C-m
|
||||
echo stopped
|
||||
}
|
||||
|
||||
status () {
|
||||
if check_session 0; then
|
||||
echo inactive
|
||||
else
|
||||
tmux capture-pane -t icloudsync -p -S -1 | tail -1
|
||||
fi
|
||||
}
|
||||
|
||||
if [[ $# -eq 0 ]]; then
|
||||
echo "Available commands are: start, stop, attach, status"
|
||||
fi
|
||||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case $1 in
|
||||
start)
|
||||
start_sync
|
||||
;;
|
||||
stop)
|
||||
stop_sync
|
||||
;;
|
||||
attach)
|
||||
attach
|
||||
;;
|
||||
status)
|
||||
status
|
||||
;;
|
||||
esac
|
||||
exit
|
||||
done
|
||||
|
|
Loading…
Reference in a new issue