102 lines
3.1 KiB
Bash
Executable File
102 lines
3.1 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# rclone-dropbox-bisync Linux setup
|
|
# Dual-boot: DataStorage already mounted at ~/DataStorage
|
|
# Paste: curl -fsSL https://git.denkena-consulting.com/f-denkena/rclone-dropbox-bisync/raw/branch/master/linux/install.sh | bash
|
|
|
|
set -euo pipefail
|
|
GIT_BASE='https://git.denkena-consulting.com/f-denkena'
|
|
PACK_REPO="$GIT_BASE/rclone-dropbox-bisync.git"
|
|
RCLONE_REPO="$GIT_BASE/rclone.git"
|
|
SRC="${XDG_CACHE_HOME:-$HOME/.cache}/rclone-dropbox-bisync/src"
|
|
BIN="$HOME/.local/bin"
|
|
CFG_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/rclone-dropbox-bisync"
|
|
UNIT_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/systemd/user"
|
|
|
|
need() {
|
|
command -v "$1" >/dev/null 2>&1
|
|
}
|
|
|
|
if ! need git; then
|
|
echo "install git first" >&2
|
|
exit 1
|
|
fi
|
|
if ! need go; then
|
|
echo "install go first (needed to build the forked rclone)" >&2
|
|
exit 1
|
|
fi
|
|
|
|
VOL="$HOME/DataStorage"
|
|
DROPBOX="$VOL/Dropbox"
|
|
WORKDIR="$VOL/rclone-bisync"
|
|
[ -d "$VOL" ] || {
|
|
echo "expected DataStorage already mounted at $VOL" >&2
|
|
exit 1
|
|
}
|
|
[ -d "$DROPBOX" ] || {
|
|
echo "missing $DROPBOX" >&2
|
|
exit 1
|
|
}
|
|
mkdir -p "$WORKDIR" "$SRC" "$BIN" "$CFG_DIR" "$UNIT_DIR" "$HOME/.config/autostart"
|
|
[ -f "$DROPBOX/RCLONE_TEST" ] || : >"$DROPBOX/RCLONE_TEST"
|
|
|
|
if [ ! -d "$SRC/packaging/.git" ]; then
|
|
git clone --depth 1 "$PACK_REPO" "$SRC/packaging"
|
|
else
|
|
git -C "$SRC/packaging" pull --ff-only
|
|
fi
|
|
if [ ! -d "$SRC/rclone/.git" ]; then
|
|
git clone --depth 1 --branch bisync-delta-list "$RCLONE_REPO" "$SRC/rclone"
|
|
else
|
|
git -C "$SRC/rclone" fetch origin bisync-delta-list
|
|
git -C "$SRC/rclone" checkout bisync-delta-list
|
|
git -C "$SRC/rclone" pull --ff-only
|
|
fi
|
|
|
|
export CGO_ENABLED=0
|
|
echo "building rclone..."
|
|
(cd "$SRC/rclone" && go build -trimpath -o "$BIN/rclone" .)
|
|
echo "building rclone-bisyncd..."
|
|
(cd "$SRC/packaging/cmd/rclone-bisyncd" && go build -trimpath -o "$BIN/rclone-bisyncd" .)
|
|
|
|
ENABLED=false
|
|
if "$BIN/rclone" lsf dropbox: --include RCLONE_TEST 2>/dev/null | grep -q RCLONE_TEST; then
|
|
ENABLED=true
|
|
fi
|
|
cat >"$CFG_DIR/config.json" <<EOF
|
|
{
|
|
"enabled": $ENABLED,
|
|
"path1": "$DROPBOX",
|
|
"path2": "dropbox:",
|
|
"workdir": "$WORKDIR",
|
|
"interval_minutes": 15,
|
|
"rclone": "$BIN/rclone",
|
|
"check_filename": "RCLONE_TEST",
|
|
"session_name": "datastorage-dropbox"
|
|
}
|
|
EOF
|
|
|
|
install -m 644 "$SRC/packaging/linux/systemd/rclone-bisync.service" "$UNIT_DIR/rclone-bisync.service"
|
|
sed -i "s|^ExecStart=.*|ExecStart=$BIN/rclone-bisyncd|" "$UNIT_DIR/rclone-bisync.service"
|
|
|
|
cat >"$HOME/.config/autostart/rclone-bisync.desktop" <<EOF
|
|
[Desktop Entry]
|
|
Type=Application
|
|
Name=rclone Dropbox bisync
|
|
Exec=systemctl --user start rclone-bisync.service
|
|
X-GNOME-Autostart-enabled=true
|
|
Terminal=false
|
|
EOF
|
|
|
|
systemctl --user daemon-reload
|
|
systemctl --user enable --now rclone-bisync.service || true
|
|
|
|
case ":$PATH:" in
|
|
*:$BIN:*) ;;
|
|
*) echo "Add $BIN to PATH (e.g. export PATH=\"$BIN:\$PATH\" in ~/.profile)" ;;
|
|
esac
|
|
|
|
echo "Configured path1=$DROPBOX workdir=$WORKDIR (~/DataStorage)"
|
|
echo "Startup: looping systemd --user service (sleeps 15 min after each run)"
|
|
echo "If listings are empty: dry-run --resync only. Then: rclone-bisyncd --accept-resync"
|
|
echo "enabled=$ENABLED (true only if dropbox: already has RCLONE_TEST)"
|