From f69e9fa2001add1cca49ac595f9761281d26f91f Mon Sep 17 00:00:00 2001
From: Maxim Cournoyer <maxim.cournoyer@savoirfairelinux.com>
Date: Mon, 8 Mar 2021 15:10:11 -0500
Subject: [PATCH] build.py: Allow skipping the operating system check.

While it's not possible to automatically check and configure the
dependencies for unknown/unsupported distributions, build.py
still provides a convenient experience to checkout the sources and
install Jami locally.  In this mode of operation, the user is expected
to configure their environment by their own means.

* build.py: Rename Ring to Jami in the document string.  Remove
unused 'signal' import.
(choose_distribution): Do not crash when the '/etc/os-release' does
not exist; return 'Unknown' instead.
(validate_args): Allow disabling the distribution check when the user
provides 'no-check' as the value of the --distribution argument, or
defines the JAMI_BUILD_NO_CHECK environment variable.  Update the
help documentation.
* scripts/install.sh (priv_install): Document the arguments.

Change-Id: I41ba2da05771feb6e3f9bc7c087206596063ba81
---
 build.py           | 29 ++++++++++++++++++++---------
 scripts/install.sh |  2 ++
 2 files changed, 22 insertions(+), 9 deletions(-)

diff --git a/build.py b/build.py
index a09beda8..958de431 100755
--- a/build.py
+++ b/build.py
@@ -15,7 +15,6 @@ import platform
 import multiprocessing
 import shlex
 import shutil
-import signal
 
 IOS_DISTRIBUTION_NAME = "ios"
 OSX_DISTRIBUTION_NAME = "osx"
@@ -529,10 +528,18 @@ def validate_args(parsed_args):
     ] + APT_BASED_DISTROS + DNF_BASED_DISTROS + PACMAN_BASED_DISTROS \
       + ZYPPER_BASED_DISTROS + FLATPAK_BASED_RUNTIMES
 
+    if (parsed_args.distribution == 'no-check'
+            or 'JAMI_BUILD_NO_CHECK' in os.environ):
+        return
+
     if parsed_args.distribution not in supported_distros:
-        print('WARNING: Distribution \'{0}\' not supported.\nChoose one of: {1}'.format(
-            parsed_args.distribution, ', '.join(supported_distros)
-        ), file=sys.stderr)
+        print(f'WARNING: Distribution \'{parsed_args.distribution}\' is not '
+              f'supported. Choose one of: {", ".join(supported_distros)}. '
+              'Alternatively, you may force execution of this script '
+              'by providing the \'--distribution=no-check\' argument or by '
+              'exporting the JAMI_BUILD_NO_CHECK environment variable.',
+              file=sys.stderr)
+        sys.exit(1)
 
     # The Qt client support will be added incrementally.
     if parsed_args.qt is not None:
@@ -591,6 +598,7 @@ def parse_args():
                     help='Sets the Qt version to build with')
 
     dist = choose_distribution()
+
     if dist == WIN32_DISTRIBUTION_NAME:
         ap.add_argument('--toolset', default=win_toolset_default, type=str,
                         help='Windows use only, specify Visual Studio toolset version')
@@ -615,11 +623,14 @@ def choose_distribution():
     if system == "linux" or system == "linux2":
         if os.path.isfile("/etc/arch-release"):
             return "arch"
-        with open("/etc/os-release") as f:
-            for line in f:
-                k, v = line.split("=")
-                if k.strip() == 'ID':
-                    return v.strip().replace('"', '').split(' ')[0]
+        try:
+            with open("/etc/os-release") as f:
+                for line in f:
+                    k, v = line.split("=")
+                    if k.strip() == 'ID':
+                        return v.strip().replace('"', '').split(' ')[0]
+        except FileNotFoundError:
+            return 'Unknown'
     elif system == "darwin":
         return OSX_DISTRIBUTION_NAME
     elif system == "windows":
diff --git a/scripts/install.sh b/scripts/install.sh
index be2b9de1..7c4f90c0 100755
--- a/scripts/install.sh
+++ b/scripts/install.sh
@@ -55,6 +55,8 @@ while getopts gsc:q:Q:P:p:u OPT; do
   esac
 done
 
+# $1: global-install?
+# $2: private-install?
 make_install() {
   if [ "$1" = "true" ] && [ "$2" != "false" ]; then
     sudo make install
-- 
GitLab