From b3bb956b195f2d6b908a18fecc0f106f7fa91eb6 Mon Sep 17 00:00:00 2001
From: Hugo Lefeuvre <hugo.lefeuvre@savoirfairelinux.com>
Date: Mon, 16 Jul 2018 13:36:52 -0400
Subject: [PATCH] make-ring: use ID field instead of NAME

ID field of os-release is much easier/safer to parse.

In order to stay compatible with scripts calling make-ring, we
convert --distribution args to lower case. This will ensure a smooth
transition (only Arch Linux scripts might break, sorry for that).

Also, add support for Linux Mint and Raspbian, both use apt and have
an important enough user base to be supported.

Change-Id: I13bf44b741a983656dab512ca95e89255efbd30d
Gitlab:#452
Reviewed-by: Philippe Gorley <philippe.gorley@savoirfairelinux.com>
---
 make-ring.py | 30 +++++++++++++++++-------------
 1 file changed, 17 insertions(+), 13 deletions(-)

diff --git a/make-ring.py b/make-ring.py
index 01c108eb..93fa49b2 100755
--- a/make-ring.py
+++ b/make-ring.py
@@ -15,25 +15,27 @@ import platform
 import multiprocessing
 import shutil
 
-IOS_DISTRIBUTION_NAME="iOS"
-OSX_DISTRIBUTION_NAME="OSX"
-ANDROID_DISTRIBUTION_NAME="Android"
+IOS_DISTRIBUTION_NAME="ios"
+OSX_DISTRIBUTION_NAME="osx"
+ANDROID_DISTRIBUTION_NAME="android"
 
 APT_BASED_DISTROS = [
-    'Debian',
-    'Ubuntu',
+    'debian',
+    'ubuntu',
+    'linuxmint',
+    'raspbian',
 ]
 
 DNF_BASED_DISTROS = [
-    'Fedora',
+    'fedora',
 ]
 
 PACMAN_BASED_DISTROS = [
-    'Arch Linux',
+    'arch',
 ]
 
 ZYPPER_BASED_DISTROS = [
-    'openSUSE',
+    'opensuse',
 ]
 
 APT_INSTALL_SCRIPT = [
@@ -416,7 +418,7 @@ def parse_args():
         '--stop', action='store_true',
         help='Stop the Ring processes')
 
-    ap.add_argument('--distribution', default='Automatic')
+    ap.add_argument('--distribution')
     ap.add_argument('--static', default=False, action='store_true')
     ap.add_argument('--global-install', default=False, action='store_true')
     ap.add_argument('--debug', default=False, action='store_true')
@@ -424,11 +426,13 @@ def parse_args():
 
     parsed_args = ap.parse_args()
 
-    if parsed_args.distribution == 'Automatic':
+    if (parsed_args.distribution is not None):
+        parsed_args.distribution = parsed_args.distribution.lower()
+    else:
         parsed_args.distribution = choose_distribution()
 
     if parsed_args.distribution in ['mingw32', 'mingw64']:
-        if choose_distribution() != "Fedora":
+        if choose_distribution() != "fedora":
             print('Windows version must be built on a Fedora distribution (>=23)')
             sys.exit(1)
 
@@ -440,11 +444,11 @@ def choose_distribution():
     system = platform.system().lower()
     if system == "linux" or system == "linux2":
         if os.path.isfile("/etc/arch-release"):
-            return "Arch Linux"
+            return "arch"
         with open("/etc/os-release") as f:
             for line in f:
                 k,v = line.split("=")
-                if k.strip() == 'NAME':
+                if k.strip() == 'ID':
                     return v.strip().replace('"','').split(' ')[0]
     elif system == "darwin":
         return OSX_DISTRIBUTION_NAME
-- 
GitLab