forked from finn/tinyboard
onboard-spoke.sh: add upstream access mode prompt (ro, nc, writeback) when creating or joining a union remote
This commit is contained in:
@@ -140,6 +140,44 @@ EOF
|
||||
info "Remote [${SPOKE_NAME}-remote] added to $RCLONE_CONF."
|
||||
fi
|
||||
|
||||
header "Union Remote (optional)"
|
||||
read -rp "Add this spoke to a union remote for redundancy? [y/N]: " ADD_UNION
|
||||
ADD_UNION="${ADD_UNION:-n}"
|
||||
if [[ "${ADD_UNION,,}" == "y" ]]; then
|
||||
read -rp "Union remote name [shared-union]: " UNION_NAME
|
||||
UNION_NAME="${UNION_NAME:-shared-union}"
|
||||
read -rp "Subfolder path on this spoke (e.g. books, leave blank for root): " UNION_PATH
|
||||
echo ""
|
||||
echo "Upstream access mode for this spoke:"
|
||||
echo " 0) None - full read/write (default)"
|
||||
echo " 1) :ro - read only"
|
||||
echo " 2) :nc - no create (read/write existing, no new files)"
|
||||
echo " 3) :writeback - writeback cache"
|
||||
echo ""
|
||||
read -rp "Choose [0-3]: " UNION_MODE
|
||||
UNION_MODE="${UNION_MODE:-0}"
|
||||
case "$UNION_MODE" in
|
||||
0) UPSTREAM_TAG="" ;;
|
||||
1) UPSTREAM_TAG=":ro" ;;
|
||||
2) UPSTREAM_TAG=":nc" ;;
|
||||
3) UPSTREAM_TAG=":writeback" ;;
|
||||
*) warn "Invalid choice, defaulting to full read/write."; UPSTREAM_TAG="" ;;
|
||||
esac
|
||||
UPSTREAM="${SPOKE_NAME}-remote:${UNION_PATH}${UPSTREAM_TAG}"
|
||||
if grep -q "^\[${UNION_NAME}\]" "$RCLONE_CONF" 2>/dev/null; then
|
||||
if grep -A5 "^\[${UNION_NAME}\]" "$RCLONE_CONF" | grep -qF "${SPOKE_NAME}-remote:"; then
|
||||
warn "Upstream for ${SPOKE_NAME}-remote already in union remote [${UNION_NAME}], skipping."
|
||||
else
|
||||
sed -i "/^\[${UNION_NAME}\]/,/^\[/{s|^upstreams = \(.*\)|upstreams = \1 ${UPSTREAM}|}" "$RCLONE_CONF"
|
||||
info "Added '$UPSTREAM' to union remote [${UNION_NAME}]."
|
||||
fi
|
||||
else
|
||||
[ -s "$RCLONE_CONF" ] && tail -c1 "$RCLONE_CONF" | grep -qv $'\n' && echo "" >> "$RCLONE_CONF"
|
||||
printf '\n[%s]\ntype = union\nupstreams = %s\n' "$UNION_NAME" "$UPSTREAM" >> "$RCLONE_CONF"
|
||||
info "Union remote [${UNION_NAME}] created with upstream '$UPSTREAM'."
|
||||
fi
|
||||
fi
|
||||
|
||||
header "Testing rclone Connection"
|
||||
if rclone lsd "${SPOKE_NAME}-remote:" --config "$RCLONE_CONF" 2>/dev/null; then
|
||||
info "rclone connection to $SPOKE_NAME successful."
|
||||
|
||||
Reference in New Issue
Block a user