From 62004f283470c6fd0d35eb96778de75ce3f4f346 Mon Sep 17 00:00:00 2001
From: Alexander Schlarb <alexander@ninetailed.ninja>
Date: Fri, 13 Dec 2019 16:50:00 +0100
Subject: [PATCH] make-ring: Allow skipping the use of `sudo` for `make
 install`

Change-Id: I673232c637926622f07b4d792906941aff21994a
---
 make-ring.py       |  3 +++
 scripts/install.sh | 15 ++++++++++-----
 2 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/make-ring.py b/make-ring.py
index f6a29e83..585fc154 100755
--- a/make-ring.py
+++ b/make-ring.py
@@ -296,6 +296,8 @@ def run_install(args):
         install_args.append('-s')
     if args.global_install:
         install_args.append('-g')
+    if not args.priv_install:
+        install_args.append('-u')
 
     if args.distribution == OSX_DISTRIBUTION_NAME:
         # The `universal_newlines` parameter has been renamed to `text` in
@@ -453,6 +455,7 @@ def parse_args():
     ap.add_argument('--global-install', default=False, action='store_true')
     ap.add_argument('--debug', default=False, action='store_true')
     ap.add_argument('--background', default=False, action='store_true')
+    ap.add_argument('--no-priv-install', dest='priv_install', default=True, action='store_false')
 
     if choose_distribution() == WIN32_DISTRIBUTION_NAME:
         ap.add_argument('--toolset', default=win_toolset_default, type=str, help='Windows use only, specify Visual Studio toolset version')
diff --git a/scripts/install.sh b/scripts/install.sh
index e130f5d6..3b6593cd 100755
--- a/scripts/install.sh
+++ b/scripts/install.sh
@@ -9,6 +9,7 @@ export OSTYPE
   # -s: link everything statically, no D-Bus communication. More likely to work!
   # -c: client to build
   # -p: number of processors to use
+  # -u: disable use of privileges (sudo) during install
 
 set -ex
 
@@ -16,7 +17,8 @@ global=false
 static=''
 client=''
 proc='1'
-while getopts gsc:p: OPT; do
+priv_install=true
+while getopts gsc:p:u OPT; do
   case "$OPT" in
     g)
       global='true'
@@ -30,6 +32,9 @@ while getopts gsc:p: OPT; do
     p)
       proc="${OPTARG}"
     ;;
+    u)
+      priv_install='false'
+    ;;
     \?)
       exit 1
     ;;
@@ -37,7 +42,7 @@ while getopts gsc:p: OPT; do
 done
 
 make_install() {
-  if [ "$1" = "true" ]; then
+  if [ "$1" = "true" ] && [ "$2" != "false" ]; then
     sudo make install
     # Or else the next non-sudo install will fail, because this generates some
     # root owned files like install_manifest.txt under the build directory.
@@ -77,7 +82,7 @@ else
   ./configure $sharedLib $CONFIGURE_FLAGS --prefix="${INSTALL}/daemon"
 fi
 make -j"${proc}"
-make_install "${global}"
+make_install "${global}" "${priv_install}"
 
 cd "${TOP}/lrc"
 mkdir -p "${BUILDDIR}"
@@ -91,7 +96,7 @@ else
             -DRING_BUILD_DIR="${DAEMON}/src" $static
 fi
 make -j"${proc}"
-make_install "${global}"
+make_install "${global}"  "${priv_install}"
 
 cd "${TOP}/${client}"
 mkdir -p "${BUILDDIR}"
@@ -105,4 +110,4 @@ else
             -DLibRingClient_DIR="${INSTALL}/lrc/lib/cmake/LibRingClient" $static
 fi
 make -j"${proc}"
-make_install "${global}"
+make_install "${global}" "${priv_install}"
-- 
GitLab