From: Paul Hänsch Date: Wed, 31 May 2023 20:27:12 +0000 (+0200) Subject: enable work without git revisioning X-Git-Url: https://git.plutz.net/?a=commitdiff_plain;h=08f0f74da3cd335f0acf58dc1f6370848dc1dbd8;p=shellwiki enable work without git revisioning --- diff --git a/handlers/60_edit.sh b/handlers/60_edit.sh index 6d4e1ea..9d1a404 100755 --- a/handlers/60_edit.sh +++ b/handlers/60_edit.sh @@ -43,7 +43,7 @@ elif [ "$edit_action" = update ]; then REDIRECT "${_BASE}${PATH_INFO%\[edit\]}/[edit]" fi - if [ "$(which git)" ]; then + if [ "$REV_PAGES" = true ]; then git -C "$_DATA" add \ -- "pages/$edit_page/#page.md" git -C "$_DATA" commit -qm \ diff --git a/handlers/60_move_rename_delete.sh b/handlers/60_move_rename_delete.sh index be84ca8..bbe994e 100755 --- a/handlers/60_move_rename_delete.sh +++ b/handlers/60_move_rename_delete.sh @@ -105,11 +105,14 @@ if [ "$action" = rename -a "$newname" ]; then printf 'Refresh: %i\r\n' 4 theme_error 403 return 0 - else + elif [ "$REV_PAGES" = true ]; then git -C "$_DATA" mv "pages/$oldname" "pages/$newname" git -C "$_DATA" commit -m 'Page # '"$oldname"' # renamed to # '"$newname"' # by user @ '"$USER_NAME"' @' \ -- "pages/$oldname" "pages/$newname" REDIRECT "$_BASE${newname}" + else + mv -- "$_DATA/pages/$oldname" "$_DATA/pages/$newname" + REDIRECT "$_BASE${newname}" fi elif [ "$action" = move -a "$newlocation" ]; then oldname="${PATH_INFO%\[*\]}" @@ -131,11 +134,14 @@ elif [ "$action" = move -a "$newlocation" ]; then printf 'Refresh: %i\r\n' 4 theme_error 403 return 0 - else + elif [ "$REV_PAGES" = true ]; then git -C "$_DATA" mv "pages/${oldname}" "pages/${newname}" git -C "$_DATA" commit -m 'Page # '"$oldname"' # moved to # '"$newname"' # by user @ '"$USER_NAME"' @' \ -- "pages/${oldname}" "pages/${newname}" REDIRECT "$_BASE${newname}" + else + mv -- "$_DATA/pages/$oldname" "$_DATA/pages/$newname" + REDIRECT "$_BASE${newname}" fi elif [ "$action" = delete ]; then oldname="${PATH_INFO%\[*\]}" @@ -143,13 +149,18 @@ elif [ "$action" = delete ]; then printf 'Refresh: %i\r\n' 4 theme_error 403 return 0 - else + elif [ "$REV_PAGES" = true ]; then git -C "$_DATA" rm "pages/${oldname}/#page.md" git -C "$_DATA" commit -m 'Page # '"$oldname"' # deleted by user @ '"$USER_NAME"' @' \ -- "pages/${oldname}/#page.md" rm -r -- "$_DATA/pages/${oldname}"/\#* rmdir -- "$_DATA/pages/${oldname}/" || true REDIRECT ./ + else + rm -- "$_DATA/pages/${oldname}/#page.md" + rm -r -- "$_DATA/pages/${oldname}"/\#* + rmdir -- "$_DATA/pages/${oldname}/" || true + REDIRECT ./ fi elif [ "$action" = cancel ]; then REDIRECT ./ diff --git a/index.cgi b/index.cgi index 8479bd9..61a8bb0 100755 --- a/index.cgi +++ b/index.cgi @@ -6,8 +6,13 @@ . "${_EXEC}/tools.sh" . "${_EXEC}/acl.sh" +REV_PAGES=${REV_PAGES:-true} REV_ATTACHMENTS=${REV_ATTACHMENTS:-false} WIKI_THEME="${WIKI_THEME:-default}" + +which git >/dev/null || REV_PAGES=false +[ "$REV_PAGES" != true ] && REV_ATTACHMENTS=false + . "${_EXEC}/themes/${WIKI_THEME}.sh" # Renew session cookie, only if cookie already set @@ -23,11 +28,10 @@ wiki_text() { cat -- "$mdfile" } -if [ "$(which git)" -a ! -f "$_DATA/.gitignore" ]; then +if [ "$REV_PAGES" = true -a ! -f "$_DATA/.gitignore" ]; then cat >"$_DATA/.gitignore" <<-EOF users.db serverkey - $([ "$REV_ATTACHMENTS" = true ] || printf %s "**/#attachments/") **/#cache/ **/#page.lock **/#page.*.cache @@ -35,6 +39,8 @@ if [ "$(which git)" -a ! -f "$_DATA/.gitignore" ]; then **/#page:*.*.cache **/#page:*.*.cache.* EOF + [ "$REV_ATTACHMENTS" != true ] \ + && printf '**/#attachments/\n' >>"$_DATA/.gitignore" git init "$_DATA" git -C "$_DATA" add .gitignore git -C "$_DATA" commit -m 'initialization' -- .gitignore @@ -43,7 +49,6 @@ fi 1>&2 for handler in "$_EXEC"/handlers/*; do . "$handler" && break done - if [ $? != 0 ]; then export ERROR_MSG="The presented URL schema cannot be handled" theme_error 400 diff --git a/macros/revisions b/macros/revisions index 9a5730f..4271149 100755 --- a/macros/revisions +++ b/macros/revisions @@ -9,7 +9,7 @@ page_abs="$(page_abs "$page")" if ! acl_read "$page_abs"; then return 0 -elif [ ! "$(which git)" ]; then +elif [ "$REV_PAGES" != true ]; then printf '
GIT is not available to handle revisioning.
' fi