From 3842ad29a0106134696eb3da91dde6eba3b7e9be Mon Sep 17 00:00:00 2001
From: Jordon Bedwell <jordon@envygeeks.io>
Date: Sat, 2 May 2020 18:46:14 -0500
Subject: [PATCH] Try to work around most gem/bundle permission errors the easy
 way.

---
 repos/jekyll/copy/all/usr/jekyll/bin/bundle          | 12 +-----------
 .../copy/all/usr/jekyll/bin/default-gem-permissions  |  8 ++++++++
 repos/jekyll/copy/all/usr/jekyll/bin/gem             |  7 +++++++
 3 files changed, 16 insertions(+), 11 deletions(-)
 create mode 100755 repos/jekyll/copy/all/usr/jekyll/bin/default-gem-permissions
 create mode 100644 repos/jekyll/copy/all/usr/jekyll/bin/gem

diff --git a/repos/jekyll/copy/all/usr/jekyll/bin/bundle b/repos/jekyll/copy/all/usr/jekyll/bin/bundle
index f53b3f0..fdfc098 100755
--- a/repos/jekyll/copy/all/usr/jekyll/bin/bundle
+++ b/repos/jekyll/copy/all/usr/jekyll/bin/bundle
@@ -1,6 +1,7 @@
 #!/bin/bash
 [ "$DEBUG" = "true" ] && set -x
 exe=/usr/local/bin/bundle
+default-gem-permissions
 set -e
 
 #
@@ -12,17 +13,6 @@ if [[ ! -f "Gemfile" ]] || [ "$(id -u)" != "0" ]; then
    exec $exe "$@"
 fi
 
-#
-# Make sure we have permissions.
-#
-
-if [ "$1" = "install" ] || [ "$1" = "clean" ] || [ "$1" = "update" ]; then
-  if [ "$(stat -c '%U' "$BUNDLE_HOME")" != "jekyll" ]; then
-    chown -R jekyll:jekyll "$BUNDLE_HOME"
-    chown -R jekyll:jekyll /usr/gem
-  fi
-fi
-
 if [ "$1" = "install" ] || [ "$1" = "update" ]; then
   # There is no need to report that we are using check.
   if [ "$1" = "update" ] || ! su-exec jekyll $exe check 1>/dev/null 2>&1; then
diff --git a/repos/jekyll/copy/all/usr/jekyll/bin/default-gem-permissions b/repos/jekyll/copy/all/usr/jekyll/bin/default-gem-permissions
new file mode 100755
index 0000000..33e09bd
--- /dev/null
+++ b/repos/jekyll/copy/all/usr/jekyll/bin/default-gem-permissions
@@ -0,0 +1,8 @@
+#!/bin/bash
+[ "$DEBUG" = "true" ] && set -x
+set -e
+
+if [ "$(id -u)" = "0" ]; then
+  chown -R jekyll:jekyll "$BUNDLE_HOME"
+  chown -R jekyll:jekyll /usr/gem
+fi
diff --git a/repos/jekyll/copy/all/usr/jekyll/bin/gem b/repos/jekyll/copy/all/usr/jekyll/bin/gem
new file mode 100644
index 0000000..62d6868
--- /dev/null
+++ b/repos/jekyll/copy/all/usr/jekyll/bin/gem
@@ -0,0 +1,7 @@
+#!/bin/bash
+[ "$DEBUG" = "true" ] && set -x
+default-gem-permissions
+exe=/usr/local/bin/gem
+set -e
+
+exec $exe "$@"
-- 
GitLab