mirror of https://github.com/vitalif/grive2
Merge pull request #246 from jankatins/add-main-systemd-unit
Add systemd unit to enable both timer and changes based syncspull/308/head
commit
dedb762b74
13
README.md
13
README.md
|
@ -90,15 +90,18 @@ Prepare a Google Drive folder in your $HOME directory with `grive -a`.
|
|||
|
||||
```bash
|
||||
# 'google-drive' is the name of your Google Drive folder in your $HOME directory
|
||||
systemctl --user enable grive-timer@$(systemd-escape google-drive).timer
|
||||
systemctl --user start grive-timer@$(systemd-escape google-drive).timer
|
||||
systemctl --user enable grive-changes@$(systemd-escape google-drive).service
|
||||
systemctl --user start grive-changes@$(systemd-escape google-drive).service
|
||||
systemctl --user enable grive@$(systemd-escape google-drive).service
|
||||
systemctl --user start grive@$(systemd-escape google-drive).service
|
||||
```
|
||||
|
||||
You can enable and start these two units for multiple folders in your `$HOME`
|
||||
You can enable and start this unit for multiple folders in your `$HOME`
|
||||
directory if you need to sync with multiple google accounts.
|
||||
|
||||
You can also only enable the time based syncing or the changes based syncing
|
||||
by only directly enabling and starting the corresponding unit:
|
||||
`grive-changes@$(systemd-escape google-drive).service` or
|
||||
`grive-timer@$(systemd-escape google-drive).timer`.
|
||||
|
||||
### Shared files
|
||||
|
||||
Files and folders which are shared with you don't automatically show up in
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
SET(GRIVE_SYNC_SH_BINARY "${CMAKE_INSTALL_PREFIX}/lib/grive/grive-sync.sh")
|
||||
SET(GRIVE_SYNC_SH_BINARY "${CMAKE_INSTALL_FULL_LIBEXECDIR}/grive/grive-sync.sh")
|
||||
|
||||
CONFIGURE_FILE(grive-changes@.service.in grive-changes@.service @ONLY)
|
||||
CONFIGURE_FILE(grive-timer@.service.in grive-timer@.service @ONLY)
|
||||
|
||||
install(
|
||||
FILES
|
||||
grive@.service
|
||||
${CMAKE_BINARY_DIR}/systemd/grive-changes@.service
|
||||
${CMAKE_BINARY_DIR}/systemd/grive-timer@.service
|
||||
DESTINATION
|
||||
|
@ -22,5 +23,5 @@ install(
|
|||
PROGRAMS
|
||||
grive-sync.sh
|
||||
DESTINATION
|
||||
lib/grive
|
||||
)
|
||||
${CMAKE_INSTALL_FULL_LIBDIR}/grive
|
||||
)
|
||||
|
|
|
@ -62,22 +62,24 @@ unlock() { _lock u; } # drop a lock
|
|||
|
||||
sync_directory() {
|
||||
_directory="${1}"
|
||||
|
||||
reset_timer_and_exit() { echo "Retriggered google drive sync ('${_directory}')" && touch -m $LOCKFILE && exit; }
|
||||
|
||||
exlock_now || reset_timer_and_exit
|
||||
|
||||
if ping -c1 -W1 -q accounts.google.com >/dev/null 2>&1; then
|
||||
true
|
||||
# pass
|
||||
else
|
||||
echo "Google drive server not reachable..."
|
||||
echo "Google drive server not reachable, NOT syncing..."
|
||||
unlock
|
||||
exit 0
|
||||
fi
|
||||
|
||||
reset_timer_and_exit() { echo "Retriggered google drive sync" && touch -m "$LOCKFILE" && exit; }
|
||||
|
||||
exlock_now || reset_timer_and_exit
|
||||
|
||||
TIME_AT_START=0
|
||||
TIME_AT_END=1
|
||||
while [[ "${TIME_AT_START}" -lt "${TIME_AT_END}" ]]; do
|
||||
echo "Syncing "${_directory}"..."
|
||||
echo "Syncing '${_directory}'..."
|
||||
TIME_AT_START="$(stat -c %Y "$LOCKFILE")"
|
||||
# exclude symlinks from sync
|
||||
cat "${_directory}"/.griveignore 2>/dev/null | sed '/#LINKS-EDIT_BEFORE_THIS$/,$d' > /tmp/.griveignore.base
|
||||
|
@ -87,14 +89,15 @@ sync_directory() {
|
|||
( cd "${_directory}" && find . -type l | sed 's/^.\///g'; ) >> "${_directory}"/.griveignore
|
||||
grive -p "${_directory}" 2>&1 | grep -v -E "^Reading local directories$|^Reading remote server file list$|^Synchronizing files$|^Finished!$"
|
||||
TIME_AT_END="$(stat -c %Y "$LOCKFILE")"
|
||||
echo "Sync of "${_directory}" done."
|
||||
echo "Sync of '${_directory}' done."
|
||||
done
|
||||
|
||||
# always exit ok, so that we never go into a wrong systemd state
|
||||
unlock
|
||||
exit 0
|
||||
}
|
||||
|
||||
### LISTEN TO DIRECTORY CHANGES ###
|
||||
### LISTEN TO CHANGES IN DIRECTORY ###
|
||||
|
||||
|
||||
listen_directory() {
|
||||
|
@ -102,7 +105,7 @@ listen_directory() {
|
|||
|
||||
type inotifywait >/dev/null 2>&1 || { echo >&2 "I require inotifywait but it's not installed. Aborting."; exit 1; }
|
||||
|
||||
echo "Listening for changes in ~/"${_directory}""
|
||||
echo "Listening for changes in '${_directory}'"
|
||||
|
||||
while true #run indefinitely
|
||||
do
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
[Unit]
|
||||
Description=Google drive sync
|
||||
Description=Google drive sync (executed by timer unit)
|
||||
After=network-online.target
|
||||
|
||||
[Service]
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
[Unit]
|
||||
Description=Google drive sync (main)
|
||||
Requires=grive-timer@%i.timer grive-changes@%i.service
|
||||
|
||||
# dummy service
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/bin/true
|
||||
# This service shall be considered active after start
|
||||
RemainAfterExit=yes
|
||||
|
||||
[Install]
|
||||
WantedBy=default.target
|
Loading…
Reference in New Issue