Browse code

Print header and variables in a table

Robert Cranston authored on 22/05/2026 23:24:09
Showing 2 changed files

... ...
@@ -1,6 +1,6 @@
1 1
 # [`distro-url`][]
2 2
 
3
-Print [Linux][] [distro][] [image][] [URL][]s.
3
+Print [Linux][] [distro][] info, including [image][] [URL][]s.
4 4
 
5 5
 Note that the latest versions are hard coded, which means they will need to be
6 6
 manually updated, which means they may be out of date.
... ...
@@ -27,6 +27,7 @@ distro-url [<distro> [<variant> [<arch> [<codename> [<version> [<mirror>]]]]]]
27 27
 ## Dependencies
28 28
 
29 29
 -   [POSIX][] [shell][].
30
+-   `column`, optional, for formatting.
30 31
 
31 32
 [POSIX]: https://en.wikipedia.org/wiki/POSIX
32 33
 [shell]: https://en.wikipedia.org/wiki/Unix_shell
... ...
@@ -35,13 +36,16 @@ distro-url [<distro> [<variant> [<arch> [<codename> [<version> [<mirror>]]]]]]
35 36
 
36 37
 ```sh
37 38
 $ distro-url debian
38
-https://cdimage.debian.org/debian-cd/13.5.0-live/amd64/iso-hybrid/debian-live-13.5.0-amd64-gnome.iso
39
+DISTRO  VARIANT  ARCH   CODENAME  VERSION  URL
40
+debian  gnome    amd64  trixie    13.5.0   https://cdimage.debian.org/debian-cd/13.5.0-live/amd64/iso-hybrid/debian-live-13.5.0-amd64-gnome.iso
39 41
 
40 42
 $ distro-url debian netinst
41
-https://cdimage.debian.org/debian-cd/13.5.0/amd64/iso-cd/debian-13.5.0-amd64-netinst.iso
43
+DISTRO  VARIANT  ARCH   CODENAME  VERSION  URL
44
+debian  netinst  amd64  trixie    13.5.0   https://cdimage.debian.org/debian-cd/13.5.0/amd64/iso-cd/debian-13.5.0-amd64-netinst.iso
42 45
 
43 46
 $ distro-url debian inst arm64 unknown 99.0.0
44
-https://cdimage.debian.org/debian-cd/99.0.0/arm64/iso-dvd/debian-99.0.0-arm64-DVD-1.iso
47
+DISTRO  VARIANT  ARCH   CODENAME  VERSION  URL
48
+debian  inst     arm64  unknown   99.0.0   https://cdimage.debian.org/debian-cd/99.0.0/arm64/iso-dvd/debian-99.0.0-arm64-DVD-1.iso
45 49
 ```
46 50
 
47 51
 ## License
... ...
@@ -5,7 +5,15 @@ set -euC
5 5
 
6 6
 main()
7 7
 {
8
-  guess "$@"
8
+  {
9
+    echo 'DISTRO' 'VARIANT' 'ARCH' 'CODENAME' 'VERSION' 'URL'
10
+    guess "$@"
11
+  } \
12
+  | {
13
+    [ "$(command -v column)" ] \
14
+      && column -t \
15
+      || cat
16
+  }
9 17
 }
10 18
 
11 19
 guess()
... ...
@@ -15,6 +23,7 @@ guess()
15 23
   arch="${3:-}"
16 24
   codename="${4:-}"
17 25
   version="${5:-}"
26
+  vars()  { printf '%s ' "$distro" "$variant" "$arch" "$codename" "$version"; }
18 27
   lower() { printf '%s\n' "$1" | tr 'A-Z' 'a-z'; }
19 28
   upper() { printf '%s\n' "$1" | tr 'a-z' 'A-Z'; }
20 29
   case "$distro/$variant" in
... ...
@@ -26,6 +35,7 @@ guess()
26 35
       : ${variant:="gnome"}
27 36
       : ${codename:="trixie"}
28 37
       : ${version:="13.5.0"}
38
+      vars
29 39
       case "$variant" in
30 40
         raspi)
31 41
           # : ${mirror:="https://get.debian.org/images/cloud"}
... ...
@@ -58,6 +68,7 @@ guess()
58 68
       : ${codename:="trixie"}
59 69
       : ${version:="2026-04-21"}
60 70
       : ${mirror:="https://downloads.raspberrypi.com"}
71
+      vars
61 72
       case "$variant" in
62 73
         default) name="${distro}_${arch}";            suffix='';          ;;
63 74
         *)       name="${distro}_${variant}_${arch}"; suffix="-$variant"; ;;
... ...
@@ -73,6 +84,7 @@ guess()
73 84
       : ${variant:="desktop"}
74 85
       : ${codename:="resolute"}
75 86
       : ${version:="26.04"}
87
+      vars
76 88
       if [ "$distro/$arch" = 'ubuntu/amd64' ]
77 89
       then : ${mirror:="https://releases.ubuntu.com"};                 dir="$codename";
78 90
       else : ${mirror:="https://cdimage.ubuntu.com/$distro/releases"}; dir="$codename/release";
... ...
@@ -89,6 +101,7 @@ guess()
89 101
       : ${codename:="zena"}
90 102
       : ${version:="22.3"}
91 103
       : ${mirror:="https://pub.linuxmint.io"}
104
+      vars
92 105
       case "$arch" in
93 106
         amd64) arch='64bit' ;;
94 107
       esac
... ...
@@ -100,6 +113,7 @@ guess()
100 113
       : ${codename:="tumbleweed"}
101 114
       : ${version:="-"}
102 115
       : ${mirror:="https://download.opensuse.org"}
116
+      vars
103 117
       distro='openSUSE'
104 118
       case "$codename" in
105 119
         tumbleweed) codename='Tumbleweed' ;;