slightly more robust
authorIan Kelling <iank@fsf.org>
Mon, 20 May 2024 22:07:09 +0000 (18:07 -0400)
committerIan Kelling <iank@fsf.org>
Mon, 20 May 2024 22:07:09 +0000 (18:07 -0400)
src/identify-distros

index fa661721cfa3882dd9cd006e95688e334e7d1896..88b31fc738405afd73138ca6f09041cb6d089ad1 100644 (file)
@@ -53,15 +53,15 @@ distro-name-ver() {
 }
 
 distro-num() {
-  # Subshell keeps environment clean.
-  ( . /etc/os-release
-    # in ubuntu the .x matters, trisquel it doesnt
-    if [[ $ID == ubuntu ]]; then
-      echo $VERSION_ID
-    else
-      echo ${VERSION_ID%%.*}
-    fi
-  )
+  local os_id ver_id
+  os_id=$(awk -F = '$1 == "ID" { print $2 }' /etc/os-release)
+  ver_id=$(awk -F = '$1 == "VERSION_ID" { print $2 }' /etc/os-release | sed 's/"//g')
+  # of VERSION_ID.x, the x matters in ubuntu but not trisquel
+  if [[ $os_id == ubuntu ]]; then
+    printf "%s\n" "$ver_id"
+  else
+    printf "%s\n" "$ver_id" | sed 's/\..*//'
+  fi
 }
 
 debian-archive() {