File: quickget

package info (click to toggle)
quickemu 4.9.7-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 776 kB
  • sloc: sh: 4,978; python: 56; makefile: 41
file content (3640 lines) | stat: -rwxr-xr-x 141,351 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
#!/usr/bin/env bash
# SC2317: Command appears to be unreachable. Check usage (or ignore if invoked indirectly).
#  - https://www.shellcheck.net/wiki/SC2317
#  - Disable globally because many functions are called indirectly
# shellcheck disable=SC2317
export LC_ALL=C

function cleanup() {
    if [ -n "$(jobs -p)" ]; then
        kill "$(jobs -p)" 2>/dev/null
    fi
}

function os_info() {
    local SIMPLE_NAME=""
    local INFO=""
    SIMPLE_NAME="${1}"
    case ${SIMPLE_NAME} in
        #name)            INFO="PrettyName|Credentials|Homepage|Info";;
        alma)             INFO="AlmaLinux|-|https://almalinux.org/|Community owned and governed, forever-free enterprise Linux distribution, focused on long-term stability, providing a robust production-grade platform. AlmaLinux OS is binary compatible with RHEL®.";;
        alpine)           INFO="Alpine Linux|-|https://alpinelinux.org/|Security-oriented, lightweight Linux distribution based on musl libc and busybox.";;
        android)          INFO="Android x86|-|https://www.android-x86.org/|Port Android Open Source Project to x86 platform.";;
        antix)            INFO="Antix|-|https://antixlinux.com/|Fast, lightweight and easy to install systemd-free linux live CD distribution based on Debian Stable for Intel-AMD x86 compatible systems.";;
        archcraft)        INFO="Archcraft|-|https://archcraft.io/|Yet another minimal Linux distribution, based on Arch Linux.";;
        archlinux)        INFO="Arch Linux|-|https://archlinux.org/|Lightweight and flexible Linux® distribution that tries to Keep It Simple.";;
        arcolinux)        INFO="Arco Linux|-|https://arcolinux.com/|Is all about becoming an expert in linux.";;
        artixlinux)       INFO="Artix Linux|-|https://artixlinux.org/|The Art of Linux. Simple. Fast. Systemd-free.";;
        athenaos)         INFO="Athena OS|-|https://athenaos.org/|Offer a different experience than the most used pentesting distributions by providing only tools that fit with the user needs and improving the access to hacking resources and learning materials.";;
        batocera)         INFO="Batocera|-|https://batocera.org/|Retro-gaming distribution with the aim of turning any computer/nano computer into a gaming console during a game or permanently.";;
        bazzite)          INFO="Bazzite|-|https://github.com/ublue-os/bazzite/|Container native gaming and a ready-to-game SteamOS like.";;
        biglinux)         INFO="BigLinux|-|https://www.biglinux.com.br/|Is the right choice if you want to have an easy and enriching experience with Linux. It has been perfected over more than 19 years, following our motto: 'In search of the perfect system'.";;
        blendos)          INFO="BlendOS|-|https://blendos.co/|A seamless blend of all Linux distributions. Allows you to have an immutable, atomic and declarative Arch Linux system, with application support from several Linux distributions & Android.";;
        bodhi)            INFO="Bodhi|-|https://www.bodhilinux.com/|Lightweight distribution featuring the fast & fully customizable Moksha Desktop.";;
        bunsenlabs)       INFO="BunsenLabs|-|https://www.bunsenlabs.org/|Light-weight and easily customizable Openbox desktop. The project is a community continuation of CrunchBang Linux.";;
        cachyos)          INFO="CachyOS|-|https://cachyos.org/|Designed to deliver lightning-fast speeds and stability, ensuring a smooth and enjoyable computing experience every time you use it.";;
        centos-stream)    INFO="CentOS Stream|-|https://www.centos.org/centos-stream/|Continuously delivered distro that tracks just ahead of Red Hat Enterprise Linux (RHEL) development, positioned as a midstream between Fedora Linux and RHEL.";;
        chimeralinux)     INFO="Chimera Linux|anon:chimera root:chimera|https://chimera-linux.org/|Modern, general-purpose non-GNU Linux distribution.";;
        crunchbang++)     INFO="Crunchbangplusplus|-|https://www.crunchbangplusplus.org/|The classic minimal crunchbang feel, now with debian 12 bookworm.";;
        debian)           INFO="Debian|-|https://www.debian.org/|Complete Free Operating System with perfect level of ease of use and stability.";;
        deepin)           INFO="Deepin|-|https://www.deepin.org/|Beautiful UI design, intimate human-computer interaction, and friendly community environment make you feel at home.";;
        devuan)           INFO="Devuan|-|https://www.devuan.org/|Fork of Debian without systemd that allows users to reclaim control over their system by avoiding unnecessary entanglements and ensuring Init Freedom.";;
        dragonflybsd)     INFO="DragonFlyBSD|-|https://www.dragonflybsd.org/|Provides an opportunity for the BSD base to grow in an entirely different direction from the one taken in the FreeBSD, NetBSD, and OpenBSD series.";;
        easyos)           INFO="EasyOS|-|https://easyos.org/|Experimental distribution designed from scratch to support containers.";;
        edubuntu)         INFO="Edubuntu|-|https://www.edubuntu.org/|Stable, secure and privacy concious option for schools.";;
        elementary)       INFO="elementary OS|-|https://elementary.io/|Thoughtful, capable, and ethical replacement for Windows and macOS.";;
        endeavouros)      INFO="EndeavourOS|-|https://endeavouros.com/|Provides an Arch experience without the hassle of installing it manually for both x86_64 and ARM systems.";;
        endless)          INFO="Endless OS|-|https://www.endlessos.org/os|Completely Free, User-Friendly Operating System Packed with Educational Tools, Games, and More.";;
        fedora)           INFO="Fedora|-|https://www.fedoraproject.org/|Innovative platform for hardware, clouds, and containers, built with love by you.";;
        freebsd)          INFO="FreeBSD|-|https://www.freebsd.org/|Operating system used to power modern servers, desktops, and embedded platforms.";;
        freedos)          INFO="FreeDOS|-|https://freedos.org/|DOS-compatible operating system that you can use to play classic DOS games, run legacy business software, or develop embedded systems.";;
        garuda)           INFO="Garuda Linux|-|https://garudalinux.org/|Feature rich and easy to use Linux distribution.";;
        gentoo)           INFO="Gentoo|-|https://www.gentoo.org/|Highly flexible, source-based Linux distribution.";;
        ghostbsd)         INFO="GhostBSD|-|https://www.ghostbsd.org/|Simple, elegant desktop BSD Operating System.";;
        gnomeos)          INFO="GNOME OS|-|https://os.gnome.org/|Alpha nightly bleeding edge distro of GNOME";;
        guix)             INFO="Guix|-|https://guix.gnu.org/|Distribution of the GNU operating system developed by the GNU Project—which respects the freedom of computer users.";;
        haiku)            INFO="Haiku|-|https://www.haiku-os.org/|Specifically targets personal computing. Inspired by the BeOS, Haiku is fast, simple to use, easy to learn and yet very powerful.";;
        holoiso)          INFO="HoloISO|-|https://github.com/HoloISO/holoiso|Bring the Steam Decks SteamOS Holo redistribution and provide a close-to-official SteamOS experience.";;
        kali)             INFO="Kali|-|https://www.kali.org/|The most advanced Penetration Testing Distribution.";;
        kdeneon)          INFO="KDE Neon|-|https://neon.kde.org/|Latest and greatest of KDE community software packaged on a rock-solid base.";;
        kolibrios)        INFO="KolibriOS|-|https://kolibrios.org/en/|Tiny yet incredibly powerful and fast operating system.";;
        kubuntu)          INFO="Kubuntu|-|https://kubuntu.org/|Free, complete, and open-source alternative to Microsoft Windows and Mac OS X which contains everything you need to work, play, or share.";;
        linuxlite)        INFO="Linux Lite|-|https://www.linuxliteos.com/|Your first simple, fast and free stop in the world of Linux.";;
        linuxmint)        INFO="Linux Mint|-|https://linuxmint.com/|Designed to work out of the box and comes fully equipped with the apps most people need.";;
        lmde)             INFO="Linux Mint Debian Edition|-|https://www.linuxmint.com/download_lmde.php|Aims to be as similar as possible to Linux Mint, but without using Ubuntu. The package base is provided by Debian instead.";;
        lubuntu)          INFO="Lubuntu|-|https://lubuntu.me/|Complete Operating System that ships the essential apps and services for daily use: office applications, PDF reader,  image editor, music and video players, etc. Using lightwave lxde/lxqt.";;
        maboxlinux)       INFO="Mabox Linux|-|https://maboxlinux.org/|Lightweight, functional and easy to customize Openbox desktop";;
        mageia)           INFO="Mageia|-|https://www.mageia.org/|Stable, secure operating system for desktop & server.";;
        manjaro)          INFO="Manjaro|-|https://manjaro.org/|Versatile, free, and open-source Linux operating system designed with a strong focus on safeguarding user privacy and offering extensive control over hardware.";;
        mxlinux)          INFO="MX Linux|-|https://mxlinux.org/|Designed to combine elegant and efficient desktops with high stability and solid performance.";;
        netboot)          INFO="netboot.xyz|-|https://netboot.xyz/|Your favorite operating systems in one place.";;
        netbsd)           INFO="NetBSD|-|https://www.netbsd.org/|Free, fast, secure, and highly portable Unix-like Open Source operating system. It is available for a wide range of platforms, from large-scale servers and powerful desktop systems to handheld and embedded devices.";;
        nitrux)           INFO="Nitrux|-|https://nxos.org/|Powered by Debian, KDE Plasma and Frameworks, and AppImages.";;
        nixos)            INFO="NixOS|-|https://nixos.org/|Linux distribution based on Nix package manager, tool that takes a unique approach to package management and system configuration.";;
        nwg-shell)        INFO="nwg-shell|nwg:nwg|https://nwg-piotr.github.io/nwg-shell/|Arch Linux ISO with nwg-shell for sway and Hyprland";;
        macos)            INFO="macOS|-|https://www.apple.com/macos/|Work and play on your Mac are even more powerful. Elevate your presence on video calls. Access information in all-new ways. Boost gaming performance. And discover even more ways to personalize your Mac.";;
        openbsd)          INFO="OpenBSD|-|https://www.openbsd.org/|FREE, multi-platform 4.4BSD-based UNIX-like operating system. Our efforts emphasize portability, standardization, correctness, proactive security and integrated cryptography.";;
        openindiana)      INFO="OpenIndiana|-|https://www.openindiana.org/|Community supported illumos-based operating system.";;
        opensuse)         INFO="openSUSE|-|https://www.opensuse.org/|The makers choice for sysadmins, developers and desktop users.";;
        oraclelinux)      INFO="Oracle Linux|-|https://www.oracle.com/linux/|Linux with everything required to deploy, optimize, and manage applications on-premises, in the cloud, and at the edge.";;
        parrotsec)        INFO="Parrot Security|parrot:parrot|https://www.parrotsec.org/|Provides a huge arsenal of tools, utilities and libraries that IT and security professionals can use to test and assess the security of their assets in a reliable, compliant and reproducible way.";;
        peppermint)       INFO="PeppermintOS|-|https://peppermintos.com/|Provides a user with the opportunity to build the system that best fits their needs. While at the same time providing a functioning OS with minimum hassle out of the box.";;
        popos)            INFO="Pop!_OS|-|https://pop.system76.com/|Operating system for STEM and creative professionals who use their computer as a tool to discover and create.";;
        porteus)          INFO="Porteus|-|http://www.porteus.org/|Complete linux operating system that is optimized to run from CD, USB flash drive, hard drive, or other bootable storage media.";;
        primtux)          INFO="PrimTux|-|https://primtux.fr/|A complete and customizable GNU/Linux operating system intended for primary school students and suitable even for older hardware.";;
        proxmox-ve)       INFO="Proxmox VE|-|https://proxmox.com/en/proxmox-virtual-environment/|Proxmox Virtual Environment is a complete, open-source server management platform for enterprise virtualization.";;
        pureos)           INFO="PureOS|-|https://www.pureos.net/|A fully free/libre and open source GNU/Linux operating system, endorsed by the Free Software Foundation.";;
        reactos)          INFO="ReactOS|-|https://reactos.org/|Imagine running your favorite Windows applications and drivers in an open-source environment you can trust.";;
        rebornos)         INFO="RebornOS|-|https://rebornos.org/|Aiming to make Arch Linux as user friendly as possible by providing interface solutions to things you normally have to do in a terminal.";;
        rockylinux)       INFO="Rocky Linux|-|https://rockylinux.org/|Open-source enterprise operating system designed to be 100% bug-for-bug compatible with Red Hat Enterprise Linux®.";;
        siduction)        INFO="Siduction|-|https://siduction.org/|Operating system based on the Linux kernel and the GNU project. In addition, there are applications and libraries from Debian.";;
        slackware)        INFO="Slackware|-|http://www.slackware.com/|Advanced Linux operating system, designed with the twin goals of ease of use and stability as top priorities.";;
        slax)             INFO="Slax|-|https://www.slax.org/|Compact, fast, and modern Linux operating system that combines sleek design with modular approach. With the ability to run directly from a USB flash drive without the need for installation, Slax is truly portable and fits easily in your pocket.";;
        slint)            INFO="Slint|-|https://slint.fr/|Slint is an easy-to-use, versatile, blind-friendly Linux distribution for 64-bit computers. Slint is based on Slackware and borrows tools from Salix. Maintainer: Didier Spaier.";;
        slitaz)           INFO="SliTaz|-|https://www.slitaz.org/en/|Simple, fast and low resource Linux OS for servers & desktops.";;
        solus)            INFO="Solus|-|https://getsol.us/|Designed for home computing. Every tweak enables us to deliver a cohesive computing experience.";;
        sparkylinux)      INFO="SparkyLinux|-|https://sparkylinux.org/|Fast, lightweight and fully customizable operating system which offers several versions for different use cases.";;
        spirallinux)      INFO="SpiralLinux|-|https://spirallinux.github.io/|Selection of Linux spins built from Debian GNU/Linux, with a focus on simplicity and out-of-the-box usability across all the major desktop environments.";;
        tails)            INFO="Tails|-|https://tails.net/|Portable operating system that protects against surveillance and censorship.";;
        tinycore)         INFO="Tiny Core Linux|-|http://www.tinycorelinux.net/|Highly modular based system with community build extensions.";;
        trisquel)         INFO="Trisquel-|https://trisquel.info/|Fully free operating system for home users, small enterprises and educational centers.";;
        truenas-core)     INFO="TrueNAS Core|-|https://www.truenas.com/truenas-core/|World’s most popular storage OS because it gives you the power to build your own professional-grade storage system to use in a variety of data-intensive applications without any software costs.";;
        truenas-scale)    INFO="TrueNAS Scale|-|https://www.truenas.com/truenas-scale/|Open Source Hyperconverged Infrastructure (HCI) solution. In addition to powerful scale-out storage capabilities, SCALE adds Linux Containers and VMs (KVM) so apps run closer to data.";;
        tuxedo-os)        INFO="Tuxedo OS|-|https://www.tuxedocomputers.com/en/|KDE Ubuntu LTS designed to go with their Linux hardware.";;
        ubuntu)           INFO="Ubuntu|-|https://ubuntu.com/|Complete desktop Linux operating system, freely available with both community and professional support.";;
        ubuntu-budgie)    INFO="Ubuntu Budgie|-|https://ubuntubudgie.org/|Community developed distribution, integrating the Budgie Desktop Environment with Ubuntu at its core.";;
        ubuntucinnamon)   INFO="Ubuntu Cinnamon|-|https://ubuntucinnamon.org/|Community-driven, featuring Linux Mint’s Cinnamon Desktop with Ubuntu at the core, packed fast and full of features, here is the most traditionally modern desktop you will ever love.";;
        ubuntukylin)      INFO="Ubuntu Kylin|-|https://ubuntukylin.com/|Universal desktop operating system for personal computers, laptops, and embedded devices. It is dedicated to bringing a smarter user experience to users all over the world.";;
        ubuntu-mate)      INFO="Ubuntu MATE|-|https://ubuntu-mate.org/|Stable, easy-to-use operating system with a configurable desktop environment. It is ideal for those who want the most out of their computers and prefer a traditional desktop metaphor. Using Mate desktop.";;
        ubuntu-server)    INFO="Ubuntu Server|-|https://ubuntu.com/server|Brings economic and technical scalability to your datacentre, public or private. Whether you want to deploy an OpenStack cloud, a Kubernetes cluster or a 50,000-node render farm, Ubuntu Server delivers the best value scale-out performance available.";;
        ubuntustudio)     INFO="Ubuntu Studio|-|https://ubuntustudio.org/|Comes preinstalled with a selection of the most common free multimedia applications available, and is configured for best performance for various purposes: Audio, Graphics, Video, Photography and Publishing.";;
        ubuntu-unity)     INFO="Ubuntu Unity|-|https://ubuntuunity.org/|Flavor of Ubuntu featuring the Unity7 desktop environment (the default desktop environment used by Ubuntu from 2010-2017).";;
        vanillaos)        INFO="Vanilla OS|-|https://vanillaos.org/|Designed to be a reliable and productive operating system for your daily work.";;
        void)             INFO="Void Linux|anon:voidlinux|https://voidlinux.org/|General purpose operating system. Its package system allows you to quickly install, update and remove software; software is provided in binary packages or can be built directly from sources.";;
        vxlinux)          INFO="VX Linux|-|https://vxlinux.org/|Pre-configured, secure systemd-free Plasma desktop with focus on convenience, performance and simplicity. Based on the excellent Void Linux.";;
        windows)          INFO="Windows|-|https://www.microsoft.com/en-us/windows/|Whether you’re gaming, studying, running a business, or running a household, Windows helps you get it done.";;
        windows-server)   INFO="Windows Server|-|https://www.microsoft.com/en-us/windows-server/|Platform for building an infrastructure of connected applications, networks, and web services.";;
        xubuntu)          INFO="Xubuntu|-|https://xubuntu.org/|Elegant and easy to use operating system. Xubuntu comes with Xfce, which is a stable, light and configurable desktop environment.";;
        zorin)            INFO="Zorin OS|-|https://zorin.com/os/|Alternative to Windows and macOS designed to make your computer faster, more powerful, secure, and privacy-respecting.";;
    esac
    echo "${INFO}"
}

function show_os_info() {
    echo
    echo -e "$(os_info "${1}" | cut -d'|' -f 1)"
    echo -e " - Credentials:\t$(os_info "${1}" | cut -d'|' -f 2)"
    echo -e " - Website:\t$(os_info "${1}" | cut -d'|' -f 3)"
    echo -e " - Description:\t$(os_info "${1}" | cut -d'|' -f 4)"
}

function pretty_name() {
    os_info "${1}" | cut -d'|' -f 1
}

# Just in case quickget want use it
function os_homepage() {
    os_info "${1}" | cut -d'|' -f 3
}

function error_specify_os() {
    echo "ERROR! You must specify an operating system."
    echo "- Supported Operating Systems:"
    os_support | fmt -w 80
    echo -e "\nTo see all possible arguments, use:\n   quickget -h  or  quickget --help"
    exit 1
}

function os_supported() {
    if [[ ! "$(os_support)" =~ ${OS} ]]; then
        echo -e "ERROR! ${OS} is not a supported OS.\n"
        os_support | fmt -w 80
        exit 1
    fi
}

function error_specify_release() {
    show_os_info "${OS}"
    case ${OS} in
        *ubuntu-server*)
            echo -en " - Releases:\t"
            releases_ubuntu-server
            ;;
        *ubuntu*)
            echo -en " - Releases:\t"
            releases_ubuntu
            ;;
        *windows*)
            echo -en " - Releases:\t"
            "releases_${OS}"
            echo -en " - Languages:\t"
            "languages_${OS}"
            echo "${I18NS[@]}"
            ;;
        *)
            echo -en " - Releases:\t"
            "releases_${OS}" | fmt -w 80
            if [[ $(type -t "editions_${OS}") == function ]]; then
                echo -en " - Editions:\t"
                "editions_${OS}" | fmt -w 80
            fi
            ;;
    esac
    echo -e "\nERROR! You must specify a release."
    exit 1
}

function error_not_supported_release() {
    if [[ ! "${RELEASES[*]}" =~ ${RELEASE} ]]; then
        echo -e "ERROR! ${DISPLAY_NAME} ${RELEASE} is not a supported release.\n"
        echo -n ' - Supported releases: '
        "releases_${OS}"
        exit 1
    fi
}

function error_not_supported_lang() {
    echo -e "ERROR! ${I18N} is not a supported $(pretty_name "${OS}") language\n"
    echo -n ' - Editions: '
    for I18N in "${I18NS[@]}"; do
        echo -n "${I18N} "
    done
    exit 1
}

function error_not_supported_argument() {
    echo "ERROR! Not supported argument"
    echo "To see all possible arguments, use:"
    echo "   quickget -h  or  quickget --help"
    exit 1
}

function handle_missing() {
    # Handle odd missing Fedora combinations
    case "${OS}" in
        fedora)
            # First we need to handle the Beta naming kludge
            if [[ "${RELEASE}" == *"_Beta" ]]; then
                NRELEASE="${RELEASE/_Beta/}"
                else
                NRELEASE="${RELEASE}"
            fi
            if [[ "${NRELEASE}" -lt 40 && "${EDITION}" == "Onyx" ]] || [[ "${NRELEASE}" -lt 40 && "${EDITION}" == "Sericea" ]]; then
                echo "ERROR! Unsupported combination"
                echo "       Fedora ${RELEASE} ${EDITION} is not available, please choose another Release or Edition"
                exit 1
            fi;;
    esac
}

function validate_release() {
    local DISPLAY_NAME=""
    local RELEASE_GENERATOR=""
    local RELEASES=""

    DISPLAY_NAME="$(pretty_name "${OS}")"
    case ${OS} in
        *ubuntu-server*) RELEASE_GENERATOR="releases_ubuntu-server";;
        *ubuntu*) RELEASE_GENERATOR="releases_ubuntu";;
        *) RELEASE_GENERATOR="${1}";;
    esac
    RELEASES=$(${RELEASE_GENERATOR})
    error_not_supported_release
}

function list_json() {
    # Reference: https://stackoverflow.com/a/67359273
    list_csv | jq -R 'split(",") as $h|reduce inputs as $in ([]; . += [$in|split(",")|. as $a|reduce range(0,length) as $i ({};.[$h[$i]]=$a[$i])])'
    exit 0
}

function list_csv() {
    CSV_DATA="$(csv_data)"

    echo "Display Name,OS,Release,Option,Downloader,PNG,SVG"
    sort -t',' -k2,2 <<<"${CSV_DATA}"

    exit 0
}

function csv_data() {
    local DISPLAY_NAME
    local DL=""
    local DOWNLOADER
    local FUNC
    local OPTION
    local OS
    local PNG
    local RELEASE
    local SVG
    local HAS_ZSYNC=0

    # Check if zsync is available
    if command -v zsync &>/dev/null; then
        HAS_ZSYNC=1
    fi

    for OS in $(os_support); do
        local EDITIONS=""
        DISPLAY_NAME="$(pretty_name "${OS}")"

        case ${OS} in
            *ubuntu-server*) FUNC="ubuntu-server";;
            *ubuntu*) FUNC="ubuntu";;
            *) FUNC="${OS}";;
        esac

        PNG="https://quickemu-project.github.io/quickemu-icons/png/${FUNC}/${FUNC}-quickemu-white-pinkbg.png"
        SVG="https://quickemu-project.github.io/quickemu-icons/svg/${FUNC}/${FUNC}-quickemu-white-pinkbg.svg"

        if [[ $(type -t "editions_${OS}") == function ]]; then
            EDITIONS=$(editions_"${OS}")
        fi

        for RELEASE in $("releases_${FUNC}"); do
            if [[ "${OS}" == *"ubuntu"* ]] && [[ ${RELEASE} == *"daily"*  ]] && [ ${HAS_ZSYNC} -eq 1 ]; then
                DOWNLOADER="zsync"
            else
                DOWNLOADER="${DL}"
            fi

            # If the OS has an editions_() function, use it.
            if [[ ${EDITIONS} ]]; then
                for OPTION in ${EDITIONS}; do
                    echo "${DISPLAY_NAME},${OS},${RELEASE},${OPTION},${DOWNLOADER},${PNG},${SVG}"
                done
            elif [[ "${OS}" == "windows"* ]]; then
                "languages_${OS}"
                for I18N in "${I18NS[@]}"; do
                    echo "${DISPLAY_NAME},${OS},${RELEASE},${I18N},${DOWNLOADER},${PNG},${SVG}"
                done
            else
                echo "${DISPLAY_NAME},${OS},${RELEASE},,${DOWNLOADER},${PNG},${SVG}"
            fi
        done &
    done
    wait
}

function list_supported() {
    list_csv | cut -d ',' -f2,3,4 | tr ',' ' '
    exit 0
}

function test_result() {
    local OS="${1}"
    local RELEASE="${2}"
    local EDITION="${3:-}"
    local URL="${4:-}"
    local RESULT="${5:-}"
    if [ -n "${EDITION}" ]; then
        OS="${OS}-${RELEASE}-${EDITION}"
    else
        OS="${OS}-${RELEASE}"
    fi

    if [ -n "${RESULT}" ]; then
        # Pad the OS string for consistent output
        OS=$(printf "%-35s" "${OS}")
        echo -e "${RESULT}: ${OS} ${URL}"
    else
        OS=$(printf "%-36s" "${OS}:")
        echo -e "${OS} ${URL}"
    fi
}

function test_all() {
    OS="${1}"
    os_supported

    local CHECK=""
    local FUNC="${OS}"
    if [[ "${OS}" == *ubuntu* && "${OS}" != "ubuntu-server" ]]; then
        FUNC="ubuntu"
    fi
    local URL=""

    for RELEASE in $("releases_${FUNC}"); do
        if [[ $(type -t "editions_${OS}") == function ]]; then
            for EDITION in $(editions_"${OS}"); do
                validate_release releases_"${OS}"
                URL=$(get_"${OS}" | cut -d' ' -f1 | head -n 1)
                if [ "${OPERATION}" == "show" ]; then
                    test_result "${OS}" "${RELEASE}" "${EDITION}" "${URL}"
                elif [ "${OPERATION}" == "test" ]; then
                    CHECK=$(web_check "${URL}" && echo "PASS" || echo "FAIL")
                    test_result "${OS}" "${RELEASE}" "${EDITION}" "${URL}" "${CHECK}"
                fi
            done
        elif [[ "${OS}" == "windows"* ]]; then
            "languages_${OS}"
            for I18N in "${I18NS[@]}"; do
                validate_release releases_"${OS}"
                if [ "${OPERATION}" == "show" ]; then
                    test_result "${OS}" "${RELEASE}" "${I18N}" ""
                elif [ "${OPERATION}" == "test" ]; then
                    test_result "${OS}" "${RELEASE}" "${I18N}" "${URL}" "SKIP"
                fi
            done
        elif [[ "${OS}" == "macos" ]]; then
            validate_release releases_macos
            (get_macos)
        elif [ "${OS}" == "ubuntu-server" ]; then
            validate_release releases_ubuntu-server
            (get_ubuntu-server)
        elif [[ "${OS}" == *ubuntu* ]]; then
            validate_release releases_ubuntu
            (get_ubuntu)
        else
            validate_release releases_"${OS}"
            URL=$(get_"${OS}" | cut -d' ' -f1 | head -n 1)
            if [ "${OPERATION}" == "show" ]; then
                test_result "${OS}" "${RELEASE}" "${EDITION}" "${URL}"
            elif [ "${OPERATION}" == "test" ]; then
                CHECK=$(web_check "${URL}" && echo "PASS" || echo "FAIL")
                test_result "${OS}" "${RELEASE}" "${EDITION}" "${URL}" "${CHECK}"
            fi
        fi
    done
}

function os_support() {
    echo alma \
    alpine \
    android \
    antix \
    archcraft \
    archlinux \
    arcolinux \
    artixlinux \
    athenaos \
    batocera \
    bazzite \
    biglinux \
    blendos \
    bodhi \
    bunsenlabs \
    cachyos \
    centos-stream \
    chimeralinux \
    crunchbang++ \
    debian \
    deepin \
    devuan \
    dragonflybsd \
    easyos \
    edubuntu \
    elementary \
    endeavouros \
    endless \
    fedora \
    freebsd \
    freedos \
    garuda \
    gentoo \
    ghostbsd \
    gnomeos \
    guix \
    haiku \
    holoiso \
    kali \
    kdeneon \
    kolibrios \
    kubuntu \
    linuxlite \
    linuxmint \
    lmde \
    lubuntu \
    maboxlinux \
    macos \
    mageia \
    manjaro \
    mxlinux \
    netboot \
    netbsd \
    nitrux \
    nixos \
    nwg-shell \
    openbsd \
    openindiana \
    opensuse \
    oraclelinux \
    parrotsec \
    peppermint \
    popos \
    porteus \
    primtux \
    proxmox-ve \
    pureos \
    reactos \
    rebornos \
    rockylinux \
    siduction \
    slackware \
    slax \
    slint \
    slitaz \
    solus \
    sparkylinux \
    spirallinux \
    tails \
    tinycore \
    trisquel \
    truenas-core \
    truenas-scale \
    tuxedo-os \
    ubuntu \
    ubuntu-budgie \
    ubuntu-mate \
    ubuntu-server \
    ubuntu-unity \
    ubuntucinnamon \
    ubuntukylin \
    ubuntustudio \
    vanillaos \
    void \
    vxlinux \
    windows \
    windows-server \
    xubuntu \
    zorin
}

function releases_alma() {
    echo 9 8
}

function editions_alma() {
    echo boot minimal dvd
}

function releases_alpine() {
    local REL=""
    local RELS=""
    RELS=$(web_pipe "https://dl-cdn.alpinelinux.org/alpine/" | grep '"v' | cut -d'"' -f2 | tr -d / | sort -Vr | head -n 10)
    for REL in ${RELS}; do
        if web_check "https://dl-cdn.alpinelinux.org/alpine/${REL}/releases/x86_64/"; then
            echo -n "${REL} "
        fi
    done
}

function releases_android() {
    echo 9.0 8.1 7.1
}

function editions_android() {
    echo x86_64 x86
}

function releases_antix() {
    echo 23.1 23 22 21
}

function editions_antix() {
    echo net-sysv core-sysv base-sysv full-sysv net-runit core-runit base-runit full-runit
}

function releases_archcraft() {
    echo latest
}

function releases_archlinux() {
    echo latest
}

function releases_arcolinux() {
    #shellcheck disable=SC2046,SC2005
    # breaking change in v24.05
    # v24.05.1 is the first release with the new naming scheme and too complex to parse old and new so just show the new
    echo $(web_pipe "https://mirror.accum.se/mirror/arcolinux.info/iso/" | grep -o -E -e "v24.0[5-9].[[:digit:]]{2}"  -e "v24.1[0-2].[[:digit:]]{2}" | sort -ru | head -n 5)
}

function editions_arcolinux() {
    echo net plasma pro
}

function releases_artixlinux() {
    #shellcheck disable=SC2046,SC2005
    echo $(web_pipe "https://mirror1.artixlinux.org/iso/" | grep "artix-" | cut -d'"' -f2 | grep -v sig | cut -d'-' -f 4 | sort -ru | tail -n 1)
}

function editions_artixlinux() {
    #shellcheck disable=SC2046,SC2005
    echo $(web_pipe "https://mirror1.artixlinux.org/iso/" | grep "artix-" | cut -d'"' -f2 | grep -v sig | cut -d'-' -f2-3 | sort -u)
}

function releases_athenaos() {
    #shellcheck disable=SC2046,SC2005
    echo $(web_pipe "https://api.github.com/repos/Athena-OS/athena/releases" | grep 'download_url' | grep rolling | cut -d'/' -f8 | sort -u)
}

function releases_batocera() {
    #shellcheck disable=SC2046,SC2005
    echo $(web_pipe "https://mirrors.o2switch.fr/batocera/x86_64/stable/" | grep ^\<a | cut -d'"' -f2 | cut -d '/' -f1 | grep -v '\.' | sort -ru | tail -n +2 | head -n 5)
}

function releases_bazzite() {
    echo latest
}

function editions_bazzite() {
    echo gnome kde
}

function releases_biglinux() {
    #shellcheck disable=SC2046,SC2005
    echo $(web_pipe "https://iso.biglinux.com.br" | grep -Eo 'biglinux_[0-9]{4}(-[0-9]{2}){2}_k[0-9]{2,3}.iso' | cut -d'_' -f2 | sort -ru | head -n 1)
}

function editions_biglinux() {
    #shellcheck disable=SC2046,SC2005
    echo $(web_pipe "https://iso.biglinux.com.br" | grep -Eo "biglinux_$(releases_biglinux)_k[0-9]{2,3}.iso" | cut -d'_' -f3 | cut -d'.' -f1 | sort -Vru)
}

function releases_blendos() {
    # there is now just a single latest iso
    echo latest
}

function releases_bodhi() {
    echo 7.0.0
}

function editions_bodhi() {
    echo standard hwe s76
}

function releases_bunsenlabs() {
    echo boron
}

function releases_cachyos() {
    # new cdn setup 10/2024
    echo latest
}

function editions_cachyos() {
    # desktop version now installs different desktop environments
    echo desktop handheld
}

function releases_centos-stream() {
    #shellcheck disable=SC2046,SC2005
    echo $(web_pipe "https://linuxsoft.cern.ch/centos-stream/" | grep "\-stream" | cut -d'"' -f 6 | cut -d'-' -f 1)
}

function editions_centos-stream() {
    echo boot dvd1
}

function releases_chimeralinux() {
    echo latest
}

function editions_chimeralinux() {
    echo base gnome
}

function releases_crunchbang++() {
    #shellcheck disable=SC2046,SC2005
    echo $(web_pipe "https://api.github.com/repos/CBPP/cbpp/releases" | grep 'download_url' | cut -d'-' -f2 | grep '^[0-9]' | sort -gru)
}

function releases_debian() {
    local ARCHIVE=""
    local MAJ=""
    local NEW=""
    local OLD=""
    NEW=$(web_pipe "https://cdimage.debian.org/debian-cd/" | grep '\.[0-9]/' | cut -d'>' -f 9 | cut -d'/' -f 1)
    echo -n "${NEW}"
    MAJ=$(echo "${NEW}" | cut -d'.' -f 1)
    ARCHIVE="$(web_pipe "https://cdimage.debian.org/cdimage/archive/" | grep folder | grep -v NEVER | cut -d'"' -f 6)"
    for i in {1..2}; do
        CUR=$((MAJ - i))
        OLD=$(grep ^"${CUR}"  <<< "${ARCHIVE}" | tail -n 1 | tr -d '/')
        echo -n " ${OLD}"
    done
    echo
}

function editions_debian() {
    echo standard cinnamon gnome kde lxde lxqt mate xfce netinst
}

function releases_deepin() {
    #shellcheck disable=SC2046,SC2005
    echo $(web_pipe "https://mirrors.kernel.org/deepin-cd/" | grep "href=" | cut -d'"' -f2 | grep -v "\.\." | grep -v nightly | grep -v preview | sed 's|/||g' | tail -n 10 | sort -r)
}

function releases_devuan() {
    echo daedalus chimaera beowulf
}

function releases_dragonflybsd() {
    # If you remove "".bz2" from the end of the searched URL, you will get only the current release - currently 6.4.0
    # We could add a variable so this behaviour is optional/switchable (maybe from option or env)
    #shellcheck disable=SC2046,SC2005
    echo $(web_pipe "https://mirror-master.dragonflybsd.org/iso-images/" | grep -E -o '"dfly-x86_64-.*_REL.iso.bz2"' | grep -o -E '[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+')
}

function releases_easyos() {
    local ALL_RELEASES=""
    local YEAR=""
    # get the latest 2 years of releases so that when we hit next year we still have the latest 2 years
    TWO_YEARS=$(web_pipe https://distro.ibiblio.org/easyos/amd64/releases/kirkstone/ | grep -o -E '[[:digit:]]{4}/' | sort -nr | tr -d /  | head -n 2 )
    for YEAR in ${TWO_YEARS} ; do
        ALL_RELEASES="${ALL_RELEASES} $(web_pipe https://distro.ibiblio.org/easyos/amd64/releases/kirkstone/${YEAR}/ | grep -o -E '[[:digit:]]+(\.[[:digit:]])+/' | tr -d / | sort -nr)"
    done
    echo ${ALL_RELEASES}
}


function releases_elementary() {
    echo 8.0 7.1 7.0
}

function releases_endeavouros() {
    local ENDEAVOUR_RELEASES=""
    ENDEAVOUR_RELEASES="$(web_pipe "https://mirror.alpix.eu/endeavouros/iso/" | grep -o '<a href="[^"]*.iso">' | sed 's/^<a href="//;s/.iso">.*//' | grep -v 'x86_64' | LC_ALL="en_US.UTF-8" sort -Mr | cut -c 13- | head -n 5 | tr '\n' ' ')"
    echo "${ENDEAVOUR_RELEASES,,}"
}

function releases_endless() {
    echo 6.0.4
}

function editions_endless() {
    echo base en fr pt_BR es
}

function releases_fedora() {
    #shellcheck disable=SC2046,SC2005
    echo $(web_pipe "https://getfedora.org/releases.json" | jq -r 'map(.version) | unique | .[]' | sed 's/ /_/g' | sort -r)
}

function editions_fedora() {
    #shellcheck disable=SC2046,SC2005
    if [[ -z ${RELEASE} ]]; then
          echo $(web_pipe "https://getfedora.org/releases.json" | jq -r "map(select(.arch==\"x86_64\" and .variant!=\"Labs\" and .variant!=\"IoT\" and .variant!=\"Container\" and .variant!=\"Cloud\" and .variant!=\"Everything\"  and .subvariant!=\"Security\" and .subvariant!=\"Server_KVM\" and .subvariant!=\"SoaS\")) | map(.subvariant) | unique | .[]")
    else
        echo $(web_pipe "https://getfedora.org/releases.json" | jq -r "map(select(.arch==\"x86_64\" and .version==\"${RELEASE/_/ }\" and .variant!=\"Labs\" and .variant!=\"IoT\" and .variant!=\"Container\" and .variant!=\"Cloud\" and .variant!=\"Everything\"  and .subvariant!=\"Security\" and .subvariant!=\"Server_KVM\" and .subvariant!=\"SoaS\")) | map(.subvariant) | unique | .[]")
    fi
}

function releases_freebsd() {
    #shellcheck disable=SC2046,SC2005
    echo $(web_pipe "https://download.freebsd.org/ftp/releases/amd64/amd64/" | grep -Eo "href=\"[0-9\.]+-RELEASE" | grep -oE '[0-9\.]+' | sort -r)
}

function editions_freebsd() {
    echo disc1 dvd1
}

function releases_freedos() {
    echo 1.3 1.2
}

function releases_garuda() {
    echo latest
}

function editions_garuda() {
    echo cinnamon dr460nized dr460nized-gaming gnome i3 kde-git kde-lite lxqt-kwin mate qtile sway wayfire xfce
}

function releases_gentoo() {
    echo latest
}

function editions_gentoo() {
    echo minimal livegui
}

function releases_ghostbsd() {
    #shellcheck disable=SC2046,SC2005
    echo $(web_pipe "https://download.ghostbsd.org/releases/amd64/" | grep "href" | cut -d'"' -f2 | cut -d'/' -f1 | sort -r | tail -n +3 | head -n 3)
}

function editions_ghostbsd() {
    echo mate xfce
}

function releases_gnomeos() {
    #shellcheck disable=SC2046,SC2005
    echo "nightly" $(web_pipe "https://download.gnome.org/gnomeos/" | grep "title=" | awk -F'"' '{print $4}' | tr -d '/' | sort -nr)
}

function releases_guix() {
    echo 1.4.0 1.3.0
}

function releases_haiku() {
    echo r1beta5 r1beta4 r1beta3
}

function editions_haiku() {
    echo x86_64 x86_gcc2h
}

function releases_holoiso() {
    echo "latest"
}

function releases_kali() {
    echo current kali-weekly
}

function releases_kdeneon() {
    echo user testing unstable developer
}

function releases_kolibrios() {
    echo latest
}

function editions_kolibrios() {
    echo en_US  ru_RU  it_IT  es_ES
}

function releases_linuxlite() {
    echo 6.6 6.4 6.2 6.0
}

function releases_linuxmint() {
    echo 22 21.3 21.2 21.1 21 20.3 20.2
}

function editions_linuxmint() {
    echo cinnamon mate xfce
}

function editions_lmde() {
    echo cinnamon
}

function releases_lmde() {
    echo 6
}

function releases_maboxlinux() {
    echo latest
}

function releases_macos() {
    echo mojave catalina big-sur monterey ventura sonoma
}

function releases_mageia() {
    echo 9 8
}

function editions_mageia() {
    echo Plasma GNOME Xfce
}

function editions_manjaro() {
    echo full minimal
}

function releases_manjaro() {
    echo xfce gnome plasma cinnamon i3 sway
}

function releases_mxlinux() {
    # needs header, so not web_pipe:
    curl -Ils "https://sourceforge.net/projects/mx-linux/files/latest/download" | grep -i 'location:' | cut -d? -f1 | cut -d_ -f1 | cut -d- -f3
}

function editions_mxlinux() {
    echo Xfce KDE Fluxbox
}

function releases_netboot() {
    echo latest
}

function releases_netbsd() {
    # V8 is EOL so filter it out
    #shellcheck disable=SC2046,SC2005
    echo $(web_pipe "https://cdn.netbsd.org/pub/NetBSD/iso/" | grep -o -E '"[[:digit:]]+\.[[:digit:]]+/"' | tr -d '"/' | grep -v ^8 | sort -nr | head -n 4)
}

function releases_nitrux() {
    echo latest
}

function releases_nixos() {
    # Lists unstable plus the two most recent releases
    #shellcheck disable=SC2046
    echo unstable $(web_pipe "https://nix-channels.s3.amazonaws.com/?delimiter=/" | grep -o -E 'nixos-[[:digit:]]+\.[[:digit:]]+' | cut -d- -f2 | sort -nru | head -n +2)
}

function editions_nixos() {
    echo minimal plasma gnome
}

function releases_nwg-shell() {
    #shellcheck disable=SC2046,SC2005
    echo $(web_pipe "https://sourceforge.net/projects/nwg-iso/rss?path=/" | grep 'url=' | grep '64.iso' | cut -d'/' -f12 | cut -d'-' -f3)
}

function releases_openbsd() {
    #shellcheck disable=SC2046,SC2005
    echo $(web_pipe "https://mirror.leaseweb.com/pub/OpenBSD/" | grep -e '6\.[8-9]/' -e '[7-9]\.' | cut -d\" -f4 | tr -d '/' | sort -r)
}

function releases_openindiana() {
    #shellcheck disable=SC2046,SC2005
    echo $(web_pipe "https://dlc.openindiana.org/isos/hipster/" | grep link | cut -d'/' -f 1 | cut -d '"' -f4 | sort -r | tail -n +2 | head -n 5)
}

function editions_openindiana() {
    echo gui text minimal
}

function releases_opensuse() {
    #shellcheck disable=SC2046,SC2005
    echo $(web_pipe "https://download.opensuse.org/distribution/leap/" | grep 'class="name"' | cut -d '/' -f2 | grep -v 42 | sort -r) aeon microos tumbleweed
}

function releases_oraclelinux() {
    echo 9.3 9.2 9.1 9.0 8.9 8.8 8.7 8.6 8.5 8.4 7.9 7.8 7.7
}

function releases_parrotsec() {
    #shellcheck disable=SC2046,SC2005
    echo $(web_pipe "https://download.parrot.sh/parrot/iso/" |  grep -o -E 'href="[[:digit:]]\.[[:digit:]]+' | sort -nr | head -n 3 | cut -d\" -f 2 )
}

function editions_parrotsec() {
    echo home htb security
}

function releases_peppermint() {
    echo latest
}

function editions_peppermint() {
    echo devuan-xfce devuan-gnome debian-xfce debian-gnome
}

function releases_popos() {
    echo 22.04 20.04
}

function editions_popos() {
    echo intel nvidia
}

function releases_porteus() {
    echo 5.01
}

function editions_porteus() {
    echo cinnamon gnome kde lxde lxqt mate openbox xfce
}

function releases_primtux() {
    echo 7
}

function editions_primtux() {
    echo 2022-10
}

function releases_proxmox-ve() {
    #shellcheck disable=SC2046,SC2005
    echo $(web_pipe https://enterprise.proxmox.com/iso/ | grep proxmox-ve | grep -E -o '[0-9]+\.[0-9]+-[0-9]\.iso' | uniq | sort -ru | cut -d'.' -f 1-2)
}

function releases_pureos() {
    web_pipe "https://www.pureos.net/download/" | grep -m 1 "downloads.puri" | cut -d '"' -f 2 | cut -d '-' -f 4
}

function editions_pureos() {
    echo gnome plasma
}

function releases_reactos() {
    echo latest
}

function releases_rebornos() {
    echo latest
}

function releases_rockylinux() {
    #shellcheck disable=SC2046,SC2005
    echo $(web_pipe "http://dl.rockylinux.org/vault/rocky/" | grep "^<a href" | grep -v full | grep -v RC | grep -v ISO | cut -d'"' -f2 | tr -d / | sort -ru)
}

function editions_rockylinux() {
    echo minimal dvd boot
}

function releases_siduction() {
    echo latest
}

function editions_siduction() {
    #shellcheck disable=SC2046,SC2005
    echo $(web_pipe "https://mirror.math.princeton.edu/pub/siduction/iso/Standing_on_the_Shoulders_of_Giants/" | grep folder | cut -d'"' -f8 | tr -d '/' | sort -u)
}

function releases_slackware() {
    #shellcheck disable=SC2046,SC2005
    echo $(web_pipe "https://slackware.nl/slackware/slackware-iso/" | grep "slackware-" | cut -d'<' -f7 | cut -d'-' -f2 | sort -ru | head -n 5)
}

function releases_slax() {
    echo latest
}

function editions_slax() {
    echo debian slackware
}

function releases_slint() {
    echo "15.0-5"
}

function releases_slitaz() {
    #shellcheck disable=SC2046,SC2005
    echo $(web_pipe "https://mirror.slitaz.org/iso/rolling/" | grep "class='iso'" | cut -d"'" -f4 | cut -d'-' -f3- | grep iso | cut -d'.' -f1 | sort -u)
}

function releases_solus() {
    #shellcheck disable=SC2046,SC2005
    echo $(web_pipe_json "https://downloads.getsol.us/isos/" | jq -r '.[].name[:-1]' | grep -E "^[0-9-]+$" | sort -u)
}

function editions_solus() {
    #shellcheck disable=SC2046,SC2005
    echo $(web_pipe_json "https://downloads.getsol.us/isos/$(releases_solus | tail -n1)/" | jq -r '.[].name | sub("Solus-(?<e>.*)-Release-.*"; "\(.e)")' | sort -u)
}

function releases_sparkylinux() {
    #shellcheck disable=SC2046,SC2005
    echo $(web_pipe "https://sparkylinux.org/download/stable/" |  grep -E -o "sparkylinux-.*\.iso\"" | cut -d'-' -f2 | sort -ru)
}

function editions_sparkylinux() {
    #shellcheck disable=SC2046,SC2005
    if [ -z "${RELEASE}" ]; then
        echo $(web_pipe "https://sparkylinux.org/download/stable/" | grep -E -o "sparkylinux-.*\.iso\"" | cut -d'-' -f4 | cut -d'.' -f1 | sort -u)
    else
        echo $(web_pipe "https://sparkylinux.org/download/stable/" | grep -E -o "sparkylinux-${RELEASE}-.*\.iso\"" | cut -d'-' -f4 | cut -d'.' -f1 | sort -u)
    fi

}

function releases_spirallinux() {
    echo latest
}

function editions_spirallinux() {
    echo Plasma XFCE Mate LXQt Gnome Budgie Cinnamon Builder
}

function releases_tails() {
    echo stable
}

function releases_tinycore() {
    echo 15 14
}

function editions_tinycore() {
    echo Core TinyCore CorePlus CorePure64 TinyCorePure64
}

function releases_trisquel() {
    echo 11.0 10.0.1
}

function editions_trisquel() {
    echo mate lxde kde sugar
}

function releases_truenas() {
    if [[ ${OS} == truenas ]] ; then
        echo "ERROR! The supported TrueNAS OS values are truenas-core or truenas-scale"
        exit 1;
    fi
}

function releases_truenas-core() {
    echo 13
}

function releases_truenas-scale() {
    echo 24
}

function releases_tuxedo-os() {
    echo current
}

function releases_ubuntu() {
    local VERSION_DATA=""
    local SUPPORTED_VERSIONS=()
    VERSION_DATA="$(IFS=$'\n' web_pipe https://api.launchpad.net/devel/ubuntu/series | jq -r '.entries[]')"
    # shellcheck disable=SC2207
    SUPPORTED_VERSIONS=($(IFS=$'\n' jq -r 'select(.status=="Supported" or .status=="Current Stable Release") | .version' <<<"${VERSION_DATA}" | sort))
    case "${OS}" in
        ubuntu)
            echo "${SUPPORTED_VERSIONS[@]}" daily-live;;
        kubuntu|lubuntu|ubuntukylin|ubuntu-mate|ubuntustudio|xubuntu)
            # after 16.04
            echo "${SUPPORTED_VERSIONS[@]:1}" daily-live;;
        ubuntu-budgie)
            # after 18.04
            echo "${SUPPORTED_VERSIONS[@]:2}" daily-live;;
        edubuntu|ubuntu-unity|ubuntucinnamon)
            # after 23.10
            echo "${SUPPORTED_VERSIONS[@]:5}" daily-live;;
    esac
}

function releases_ubuntu-server() {
    local ALL_VERSIONS=()
    # shellcheck disable=SC2207
    ALL_VERSIONS=($(IFS=$'\n' web_pipe http://releases.ubuntu.com/streams/v1/com.ubuntu.releases:ubuntu-server.json | jq -r '.products[] | select(.arch=="amd64") | .version' | sort -rV))
    echo daily-live "${ALL_VERSIONS[@]}"
}

function releases_vanillaos() {
    #shellcheck disable=SC2046,SC2005
    echo $(web_pipe "https://api.github.com/repos/Vanilla-OS/live-iso/releases" | grep 'download_url' | cut -d'/' -f8 | sort -ru)
}

function releases_void() {
    #shellcheck disable=SC2046,SC2005
    echo $(web_pipe "https://repo-default.voidlinux.org/live/" | grep "^<a href=\"2" | cut -d'"' -f2 | tr -d '/' | sort -ru | head -n 3)
}

function editions_void() {
    echo glibc musl xfce-glibc xfce-musl
}

function releases_vxlinux() {
    #shellcheck disable=SC2046,SC2005
    echo $(web_pipe "https://github.com/VX-Linux/main/releases/latest" | grep -o -e 'releases/tag/[[:digit:]]\+\.[[:digit:]]\+\.[[:digit:]]' | sort -u | cut -d'/' -f 3)
}

function releases_windows() {
    echo 11 10
}

function languages_windows() {
    I18NS=("Arabic" "Brazilian Portuguese" "Bulgarian" "Chinese (Simplified)" "Chinese (Traditional)" "Croatian" "Czech" "Danish" "Dutch" \
    "English (United States)" "English International" "Estonian" "Finnish" "French" "French Canadian" "German" "Greek" "Hebrew" "Hungarian" \
    "Italian" "Japanese" "Korean" "Latvian" "Lithuanian" "Norwegian" "Polish" "Portuguese" "Romanian" "Russian" "Serbian Latin" "Slovak" \
    "Slovenian" "Spanish" "Spanish (Mexico)" "Swedish" "Thai" "Turkish" "Ukrainian")
}

function releases_windows-server() {
    echo 2022 2019 2016
}

function languages_windows-server() {
    I18NS=("English (United States)" "Chinese (Simplified)" "French" "German" "Italian" "Japanese" "Russian" "Spanish")
}

function releases_zorin() {
    echo 17 16
}

function editions_zorin() {
    echo core64 lite64 education64
}

function check_hash() {
    local iso=""
    local hash=""
    local hash_algo=""
    if [ "${OPERATION}" == "download" ]; then
        iso="${1}"
    else
        iso="${VM_PATH}/${1}"
    fi
    hash="${2}"
    # Guess the hash algorithm by the hash length
    case ${#hash} in
        32) hash_algo=md5sum;;
        40) hash_algo=sha1sum;;
        64) hash_algo=sha256sum;;
        128) hash_algo=sha512sum;;
        *) echo "WARNING! Can't guess hash algorithm, not checking ${iso} hash."
            return;;
    esac
    echo -n "Checking ${iso} with ${hash_algo}... "
    if ! echo "${hash} ${iso}" | ${hash_algo} --check --status; then
        echo "ERROR!"
        echo "${iso} doesn't match ${hash}. Try running 'quickget' again."
        exit 1
    else
        echo "Good!"
    fi
}

# Download a file from the web and pipe it to stdout
function web_pipe() {
    curl --silent --location "${1}"
}

# Download a JSON file from the web and pipe it to stdout
function web_pipe_json() {
     curl --silent --location --header "Accept: application/json" "${1}"
}

# Download a file from the web
function web_get() {
    local CHECK=""
    local HEADERS=()
    local URL="${1}"
    local DIR="${2}"
    local FILE=""
    local USER_AGENT="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36"

    if [ -n "${3}" ]; then
        FILE="${3}"
    else
        FILE="${URL##*/}"
    fi

    # Process any URL redirections after the file name has been extracted
    URL=$(web_redirect "${URL}")

    # Process any headers
    while (( "$#" )); do
        if [ "${1}" == "--header" ]; then
            HEADERS+=("${1}" "${2}")
            shift 2
        else
            shift
        fi
    done

    # Test mode for ISO
    if [ "${OPERATION}" == "show" ]; then
        test_result "${OS}" "${RELEASE}" "${EDITION}" "${URL}"
        exit 0
    elif [ "${OPERATION}" == "test" ]; then
        CHECK=$(web_check "${URL}" && echo "PASS" || echo "FAIL")
        test_result "${OS}" "${RELEASE}" "${EDITION}" "${URL}" "${CHECK}"
        exit 0
    elif [ "${OPERATION}" == "download" ]; then
        DIR="$(pwd)"
    fi

    if [ "${DIR}" != "$(pwd)" ] && ! mkdir -p "${DIR}" 2>/dev/null; then
        echo "ERROR! Unable to create directory ${DIR}"
        exit 1
    fi

    if [[ ${OS} != windows && ${OS} != macos && ${OS} != windows-server ]]; then
        echo "Downloading $(pretty_name "${OS}") ${RELEASE} ${EDITION}"
        echo "- URL: ${URL}"
    fi

    if ! curl --progress-bar --location --output "${DIR}/${FILE}" --continue-at - --user-agent "${USER_AGENT}" "${HEADERS[@]}" -- "${URL}"; then
        echo "ERROR! Failed to download ${URL} with curl."
        rm -f "${DIR}/${FILE}"
    fi
}

# checks if a URL needs to be redirected and returns the final URL
function web_redirect() {
    local REDIRECT_URL=""
    local URL="${1}"
    # Check for URL redirections
    # Output to nonexistent directory so the download fails fast
    REDIRECT_URL=$(curl --silent --location --fail --write-out '%{url_effective}' --output /var/cache/${RANDOM}/${RANDOM} "${URL}" )
    if [ "${REDIRECT_URL}" != "${URL}" ]; then
        echo "${REDIRECT_URL}"
    else
        echo "${URL}"
    fi
}

# checks if a URL is reachable
function web_check() {
    local HEADERS=()
    local URL="${1}"
    # Process any headers
    while (( "$#" )); do
        if [ "${1}" == "--header" ]; then
            HEADERS+=("${1}" "${2}")
            shift 2
        else
            shift
        fi
    done
    curl --silent --location --head --output /dev/null --fail --connect-timeout 30 --max-time 30 --retry 3 "${HEADERS[@]}" "${URL}"
}

function zsync_get() {
    local CHECK=""
    local DIR="${2}"
    local FILE="${1##*/}"
    local OUT=""
    local URL="${1}"
    # Test mode for ISO
    if [ "${OPERATION}" == "show" ]; then
        test_result "${OS}" "${RELEASE}" "${EDITION}" "${URL}"
        exit 0
    elif [ "${OPERATION}" == "test" ]; then
        CHECK=$(web_check "${URL}" && echo "PASS" || echo "FAIL")
        test_result "${OS}" "${RELEASE}" "${EDITION}" "${URL}" "${CHECK}"
        exit 0
    elif command -v zsync &>/dev/null; then
        if [ -n "${3}" ]; then
            OUT="${3}"
        else
            OUT="${FILE}"
        fi

        if ! mkdir -p "${DIR}" 2>/dev/null; then
            echo "ERROR! Unable to create directory ${DIR}"
            exit 1
        fi
        echo "Downloading $(pretty_name "${OS}") ${RELEASE} ${EDITION} from ${URL}"
        # Only force http for zsync - not earlier because we might fall through here
        if ! zsync "${URL/https/http}.zsync" -i "${DIR}/${OUT}" -o "${DIR}/${OUT}" 2>/dev/null; then
            echo "ERROR! Failed to download ${URL/https/http}.zsync"
            exit 1
        fi

        if [ -e "${DIR}/${OUT}.zs-old" ]; then
            rm "${DIR}/${OUT}.zs-old"
        fi
    else
        echo "INFO: zsync not found, falling back to curl"
        if [ -n "${3}" ]; then
            web_get "${1}" "${2}" "${3}"
        else
            web_get "${1}" "${2}"
        fi
    fi
}

function make_vm_config() {
    local CONF_FILE=""
    local IMAGE_FILE=""
    local ISO_FILE=""
    local IMAGE_TYPE=""
    local GUEST=""
    if [ "${OPERATION}" == "download" ]; then
        exit 0
    fi
    IMAGE_FILE="${1}"
    ISO_FILE="${2}"
    case "${OS}" in
        batocera)
            GUEST="batocera"
            IMAGE_TYPE="img";;
        custom)
            GUEST="${CUSTOM_OS}"
            IMAGE_TYPE="${CUSTOM_IMAGE_TYPE}";;
        dragonflybsd)
            GUEST="dragonflybsd"
            IMAGE_TYPE="iso";;
        easyos)
            GUEST="linux"
            IMAGE_TYPE="img";;
        freebsd|ghostbsd)
            GUEST="freebsd"
            IMAGE_TYPE="iso";;
        haiku)
            GUEST="haiku"
            IMAGE_TYPE="iso";;
        freedos)
            GUEST="freedos"
            IMAGE_TYPE="iso";;
        kolibrios)
            GUEST="kolibrios"
            IMAGE_TYPE="iso";;
        macos)
            GUEST="macos"
            IMAGE_TYPE="img";;
        netbsd)
            GUEST="netbsd"
            IMAGE_TYPE="iso";;
        openbsd)
            GUEST="openbsd"
            IMAGE_TYPE="iso";;
        openindiana)
            GUEST="solaris"
            IMAGE_TYPE="iso";;
        reactos)
            GUEST="reactos"
            IMAGE_TYPE="iso";;
        truenas*)
            GUEST="truenas"
            IMAGE_TYPE="iso";;
        ubuntu*)
            GUEST="linux"
            IMAGE_TYPE="iso"
            # If there is a point in the release, check if it is less than 16.04
            if [[ "${RELEASE}" != *"daily"* ]]; then
                if [ "${RELEASE//./}" -lt 1604 ]; then
                    GUEST="linux_old"
                fi
            fi
            ;;
        windows)
            GUEST="windows"
            IMAGE_TYPE="iso";;
        windows-server)
            GUEST="windows-server"
            IMAGE_TYPE="iso";;
        *)
            GUEST="linux"
            IMAGE_TYPE="iso";;
    esac

    CONF_FILE="${VM_PATH}.conf"

    if [ ! -e "${CONF_FILE}" ]; then
        echo "Making ${CONF_FILE}"
        cat << EOF > "${CONF_FILE}"
#!${QUICKEMU} --vm
guest_os="${GUEST}"
disk_img="${VM_PATH}/disk.qcow2"
${IMAGE_TYPE}="${VM_PATH}/${IMAGE_FILE}"
EOF
        echo " - Setting ${CONF_FILE} executable"
        chmod u+x "${CONF_FILE}"
        if [ -n "${ISO_FILE}" ]; then
            echo "fixed_iso=\"${VM_PATH}/${ISO_FILE}\"" >> "${CONF_FILE}"
        fi

        # OS specific tweaks
        case ${OS} in
            alma|athenaos|centos-stream|endless|garuda|gentoo|kali|nixos|oraclelinux|popos|rockylinux)
                echo "disk_size=\"32G\"" >> "${CONF_FILE}";;
            openindiana)
                echo "boot=\"legacy\"" >> "${CONF_FILE}"
                echo "disk_size=\"32G\"" >> "${CONF_FILE}";;
            batocera)
                echo "disk_size=\"8G\"" >> "${CONF_FILE}";;
            bazzite)
                echo "disk_size=\"64G\"" >> "${CONF_FILE}";;
            dragonflybsd|haiku|openbsd|netbsd|slackware|slax|tails|tinycore)
                echo "boot=\"legacy\"" >> "${CONF_FILE}";;
            deepin)
                echo "disk_size=\"64G\"" >> "${CONF_FILE}"
                echo "ram=\"4G\"" >> "${CONF_FILE}"
                ;;
            freedos)
                echo "boot=\"legacy\"" >> "${CONF_FILE}"
                echo "disk_size=\"4G\"" >> "${CONF_FILE}"
                echo "ram=\"256M\"" >> "${CONF_FILE}"
                ;;
            kolibrios)
                echo "boot=\"legacy\"" >> "${CONF_FILE}"
                echo "disk_size=\"2G\"" >> "${CONF_FILE}"
                echo "ram=\"128M\"" >> "${CONF_FILE}"
                ;;
            slint)
                echo "disk_size=\"50G\"" >> "${CONF_FILE}"
                ;;
            slitaz)
                echo "boot=\"legacy\"" >> "${CONF_FILE}"
                echo "disk_size=\"4G\"" >> "${CONF_FILE}"
                echo "ram=\"512M\"" >> "${CONF_FILE}"
                ;;
            truenas-scale|truenas-core)
                echo "boot=\"legacy\"" >> "${CONF_FILE}"
                # the rest is non-functional
                # echo "bootdrive_size=\"5G\"" >> "${CONF_FILE}" # boot drive
                # echo "1stdrive_size=\"20G\"" >> "${CONF_FILE}" # for testing
                # echo "2nddrive_size=\"20G\"" >> "${CONF_FILE}" # again, for testing
                ;;
            ubuntu-server)
                # 22.04+ fails on LVM build if disk size is < 10G
                # 22.04.1 fails on auto-install if TPM is disabled
                echo "disk_size=\"10G\"" >> "${CONF_FILE}"
                echo "ram=\"4G\"" >> "${CONF_FILE}"
                if [[ "${RELEASE}" == *"22.04"* ]]; then
                    echo "tpm=\"on\"" >> "${CONF_FILE}"
                fi
                ;;
            vanillaos)
                ## Minimum is 50G for abroot, but a 64GB is allocated to give some headroom
                echo "disk_size=\"64G\"" >> "${CONF_FILE}"
                ;;
            zorin)
                case ${EDITION} in
                    education64|edulite64) echo "disk_size=\"32G\"" >> "${CONF_FILE}";;
                esac;;
            reactos)
                echo "boot=\"legacy\"" >> "${CONF_FILE}"
                echo "disk_size=\"12G\"" >> "${CONF_FILE}"
                echo "ram=\"2048M\"" >> "${CONF_FILE}"
                ;;
            macos)
                echo "disk_size=\"128G\"" >> "${CONF_FILE}"
                echo "macos_release=\"${RELEASE}\"" >> "${CONF_FILE}"
                # https://github.com/quickemu-project/quickemu/issues/438
                if [ "${RELEASE}" == "monterey" ]; then
                    echo "cpu_cores=2" >> "${CONF_FILE}"
                fi
                ;;
            proxmox-ve)
                echo "disk_size=\"20G\"" >> "${CONF_FILE}"
                echo "ram=\"4G\"" >> "${CONF_FILE}"
                ;;
        esac

        if [ "${OS}" == "ubuntu" ] && [[ ${RELEASE} == *"daily"*  ]]; then
            # Minimum to install lobster testing is 18GB but 32GB are allocated for headroom
            echo "disk_size=\"32G\"" >> "${CONF_FILE}"
        fi

        if [[ "${OS}" == "windows"* ]]; then
            echo "disk_size=\"64G\"" >> "${CONF_FILE}"
        fi

        # Enable TPM for Windows 11 and Windows Server 2022
        if [[ "${OS}" == "windows" && "${RELEASE}" == "11" || "${OS}" == "windows-server" && "${RELEASE}" == "2022" ]]; then
            echo "tpm=\"on\"" >> "${CONF_FILE}"
            echo "secureboot=\"off\"" >> "${CONF_FILE}"
        fi
    fi
    echo -e "\nTo start your $(pretty_name "${OS}") virtual machine run:"
    if [ "${OS}" == "slint" ]; then
        echo -e "    quickemu --vm ${CONF_FILE}\nTo start Slint with braille support run:\n    quickemu --vm --braille --display sdl ${CONF_FILE}"
    else
        echo "    quickemu --vm ${CONF_FILE}"
    fi

    echo
    exit 0
}

function get_alma() {
    local HASH=""
    local ISO="AlmaLinux-${RELEASE}-latest-x86_64-${EDITION}.iso"
    local URL="https://repo.almalinux.org/almalinux/${RELEASE}/isos/x86_64"
    HASH="$(web_pipe "${URL}/CHECKSUM" | grep "(${ISO}" | cut -d' ' -f4)"
    echo "${URL}/${ISO} ${HASH}"
}

function get_alpine() {
    local HASH=""
    local ISO=""
    local URL="https://dl-cdn.alpinelinux.org/alpine/${RELEASE}/releases/x86_64"
    local VERSION=""
    VERSION=$(web_pipe "${URL}/latest-releases.yaml" | awk '/"Xen"/{found=0} {if(found) print} /"Virtual"/{found=1}' | grep 'version:' | awk '{print $2}')
    ISO="alpine-virt-${VERSION}-x86_64.iso"
    HASH=$(web_pipe "${URL}/latest-releases.yaml" | awk '/"Xen"/{found=0} {if(found) print} /"Virtual"/{found=1}' | grep 'sha256:' | awk '{print $2}')
    echo "${URL}/${ISO} ${HASH}"
}

function get_android() {
    local HASH=""
    local ISO=""
    local JSON_ALL=""
    local JSON_REL=""
    local URL="https://mirrors.gigenet.com/OSDN/android-x86"
    JSON_ALL=$(web_pipe "https://www.fosshub.com/Android-x86-old.html" | grep "var settings =" | cut -d'=' -f2-)
    JSON_REL=$(echo "${JSON_ALL}" | jq --arg ver "${OS}-${EDITION}-${RELEASE}" 'first(.pool.f[] | select((.n | startswith($ver)) and (.n | endswith(".iso"))))')
    ISO=$(echo "${JSON_REL}" | jq -r .n)
    HASH=$(echo "${JSON_REL}" | jq -r .hash.sha256)
    # Traverse the directories to find the .iso location
    for DIR in $(web_pipe "${URL}" | grep -o -E '[0-9]{5}' | sort -ur); do
        if web_pipe "${URL}/${DIR}" | grep "${ISO}" &>/dev/null; then
            URL="${URL}/${DIR}"
            break
        fi
    done
    echo "${URL}/${ISO} ${HASH}"
}

function get_antix() {
    local HASH=""
    local ISO="antiX-${RELEASE}"
    local README="README"
    local URL="https://sourceforge.net/projects/antix-linux/files/Final/antiX-${RELEASE}"

    # antiX uses a different URL and ISO naming for runit editions
    if [[ "${EDITION}" == *"runit"* ]];then
        ISO+="-runit"
        README="README2"
        case ${RELEASE} in
            21) URL+="/runit-bullseye";;
            *)  URL+="/runit-antiX-${RELEASE}";;
        esac
    fi
    case ${EDITION} in
        base-*) ISO+="_x64-base.iso";;
        core-*) ISO+="_x64-core.iso";;
        full-*) ISO+="_x64-full.iso";;
        net-*)  ISO+="-net_x64-net.iso";;
    esac
    HASH=$(web_pipe "${URL}/${README}.txt" | grep "${ISO}" | cut -d' ' -f1 | head -n 1)
    echo "${URL}/${ISO} ${HASH}"
}

function get_archcraft() {
    local HASH=""
    local URL=""
    URL="https://sourceforge.net/projects/archcraft/files/${RELEASE}/download"
    URL="$(web_redirect "${URL}" | cut -d? -f1)"
    echo "${URL} ${HASH}"
}

function get_archlinux() {
    local HASH=""
    local ISO=""
    local URL="https://mirror.rackspace.com/archlinux"
    ISO=$(web_pipe "https://archlinux.org/releng/releases/json/" | jq -r '.releases[0].iso_url')
    HASH=$(web_pipe "https://archlinux.org/releng/releases/json/" | jq -r '.releases[0].sha256_sum')
    echo "${URL}${ISO} ${HASH}"
}

function get_arcolinux() {
    local HASH=""
    local ISO=""
    local URL=""
    URL="https://mirror.accum.se/mirror/arcolinux.info/iso/${RELEASE}"
    ISO="arco${EDITION}-${RELEASE}-x86_64.iso"
    HASH=$(web_pipe "${URL}/${ISO}.sha256" | cut -d' ' -f1)
    echo "${URL}/${ISO} ${HASH}"
}

function get_artixlinux() {
    local HASH=""
    local ISO=""
    local URL="https://iso.artixlinux.org/iso"
    ISO="artix-${EDITION}-${RELEASE}-x86_64.iso"
    HASH=$(web_pipe "${URL}/sha256sums" | grep "${ISO}")
    echo "${URL}/${ISO} ${HASH}"
}

function get_athenaos() {
    local HASH=""
    local URL="https://github.com/Athena-OS/athena/releases/download/${RELEASE}"
    local ISO="athena-rolling-x86_64.iso"
    HASH=$(web_pipe "${URL}/${ISO}.sha256" | cut -d' ' -f1)
    echo "${URL}/${ISO} ${HASH}"
}

function get_batocera() {
    local HASH=""
    local ISO=""
    local URL="https://mirrors.o2switch.fr/batocera/x86_64/stable/${RELEASE}"
    ISO="$(web_pipe "${URL}/" | grep -e 'batocera.*img.gz'| cut -d'"' -f2)"
    echo "${URL}/${ISO} ${HASH}"
}

function get_bazzite() {
    local HASH=""
    local ISO=""
    local URL="https://download.bazzite.gg"
    case ${EDITION} in
        gnome) ISO="bazzite-gnome-stable.iso";;
        kde)  ISO="bazzite-stable.iso";;
    esac
    HASH=$(web_pipe "${URL}/${ISO}-CHECKSUM" | cut -d' ' -f1)
    echo "${URL}/${ISO} ${HASH}"
}

function get_biglinux() {
    local HASH=""
    local ISO="biglinux_${RELEASE}_${EDITION}.iso"
    local URL="https://iso.biglinux.com.br"
    HASH=$(web_pipe "${URL}/${ISO}.md5" | grep -Eo '[[:alnum:]]{32}')
    echo "${URL}/${ISO} ${HASH}"
}

function get_blendos() {
    local HASH=""
    local ISO="blendOS.iso"
    local URL="https://kc1.mirrors.199693.xyz/blend/isos/testing"
    echo "${URL}/${ISO} ${HASH}"
}

function get_bodhi() {
    local HASH=""
    local ISO=""
    local URL="https://sourceforge.net/projects/bodhilinux/files/${RELEASE}"
    case ${EDITION} in
        standard) ISO="bodhi-${RELEASE}-64.iso";;
        *) ISO="bodhi-${RELEASE}-64-${EDITION}.iso";;
    esac
    HASH=$(web_pipe "${URL}/${ISO}.sha256" | cut -d' ' -f1)
    echo "${URL}/${ISO} ${HASH}"
}

function get_bunsenlabs() {
    local HASH=""
    local ISO="boron-1-240123-amd64.hybrid.iso"
    local URL="https://ddl.bunsenlabs.org/ddl"
    HASH=$(web_pipe "${URL}/release.sha256.txt" | head -n 1 | cut -d' ' -f1)
    echo "${URL}/${ISO} ${HASH}"
}

function get_cachyos() {
    local HASH=""
    local URL=""
    URL="$(web_pipe "https://cachyos.org/download/" | tr '&' '\n' | grep "ISO/${EDITION}" | grep -v 'iso.sha' | grep -v 'iso.sig' | cut -d';' -f2)"
    HASH=$(web_pipe "${URL}.sha256" | cut -d' ' -f1)
    echo "${URL} ${HASH}"
}

function get_centos-stream() {
    local HASH=""
    local ISO="CentOS-Stream-${RELEASE}-latest-x86_64-${EDITION}.iso"
    local URL="https://linuxsoft.cern.ch/centos-stream/${RELEASE}-stream/BaseOS/x86_64/iso"
    HASH=$(web_pipe "${URL}/${ISO}.SHA256SUM" | grep "SHA256 (${ISO}" | cut -d' ' -f4)
    echo "${URL}/${ISO} ${HASH}"
}

function get_chimeralinux() {
    local DATE=""
    local HASH=""
    local URL="https://repo.chimera-linux.org/live/${RELEASE}"
    DATE=$(web_pipe "${URL}/sha256sums.txt" | head -n1 | cut -d'-' -f5)
    local ISO="chimera-linux-x86_64-LIVE-${DATE}-${EDITION}.iso"
    HASH=$(web_pipe "${URL}/sha256sums.txt" | grep 'x86_64-LIVE' | grep "${EDITION}" | cut -d' ' -f1)
    echo "${URL}/${ISO} ${HASH}"
}

function get_crunchbang++() {
    local HASH=""
    local ISO=""
    ISO=$(web_pipe "https://api.github.com/repos/CBPP/cbpp/releases" | grep 'download_url' | grep amd64 | grep "${RELEASE}" | cut -d'"' -f4)
    echo "${ISO} ${HASH}"
}

function get_debian() {
    local DEBCURRENT=""
    local HASH=""
    local ISO="debian-live-${RELEASE}-amd64-${EDITION}.iso"
    local URL="https://cdimage.debian.org/cdimage/archive/${RELEASE}-live/amd64/iso-hybrid"
    DEBCURRENT=$(web_pipe "https://cdimage.debian.org/debian-cd/" | grep '\.[0-9]/' | cut -d'>' -f 9 | cut -d'/' -f 1)
    case "${RELEASE}" in
        "${DEBCURRENT}") URL="https://cdimage.debian.org/debian-cd/${RELEASE}-live/amd64/iso-hybrid";;
    esac
    if [ "${EDITION}" == "netinst" ]; then
        URL="${URL/-live/}"
        URL="${URL/hybrid/cd}"
        ISO="${ISO/-live/}"
    fi
    HASH=$(web_pipe "${URL}/SHA512SUMS" | grep "${ISO}" | cut -d' ' -f1 | head -n 1)
    echo "${URL}/${ISO} ${HASH}"
}

function get_deepin() {
    local HASH=""
    local REV=${RELEASE}
    # deepin-desktop-community-20.3-amd64.iso
    local URL="https://cdimage.deepin.com/releases/"${RELEASE}
    # Correct URL for 23-RC onwards which has architecture directories
    if [ "${RELEASE}" != "20.9" ]; then
        URL+="/amd64"
    fi
    local ISO="deepin-desktop-community-${REV}-amd64.iso"
    HASH=$(web_pipe "${URL}/SHA256SUMS" | grep "${ISO}" | cut -d' ' -f1)
    echo "${URL}/${ISO} ${HASH}"
}

function get_devuan() {
    local HASH=""
    local ISO=""
    local URL="https://files.devuan.org/devuan_${RELEASE}/desktop-live"
    local VER=""
    case ${RELEASE} in
        beowulf)  VER="3.1.1";;
        chimaera) VER="4.0.3";;
        daedalus) VER="5.0.0";;
    esac
    ISO="devuan_${RELEASE}_${VER}_amd64_desktop-live.iso"
    HASH=$(web_pipe "${URL}/SHASUMS.txt" | grep "${ISO}" | cut -d' ' -f1)
    echo "${URL}/${ISO} ${HASH}"
}

function get_dragonflybsd() {
    local HASH=""
    local ISO="dfly-x86_64-${RELEASE}_REL.iso.bz2"
    local URL="http://mirror-master.dragonflybsd.org/iso-images"
    HASH=$(web_pipe "${URL}/md5.txt" | grep "(${ISO})" | cut -d' ' -f4)
    echo "${URL}/${ISO} ${HASH}"
}

function get_easyos() {
    local HASH=""
    local URL=""
    local ISO=""
    local YEAR=""
    ISO="easy-${RELEASE}-amd64.img"
    TWO_YEARS=$(web_pipe https://distro.ibiblio.org/easyos/amd64/releases/kirkstone/ | grep -o -E '[[:digit:]]{4}/' | sort -nr | tr -d /  | head -n 2 )
    for YEAR in ${TWO_YEARS} ; do
        if web_check "https://distro.ibiblio.org/easyos/amd64/releases/kirkstone/${YEAR}/${RELEASE}/" ; then
            URL="https://distro.ibiblio.org/easyos/amd64/releases/kirkstone/${YEAR}/${RELEASE}"
            HASH=$(web_pipe "${URL}/md5.sum.txt" | cut -d' ' -f1)
            break
        fi
    done
    echo "${URL}/${ISO} ${HASH}"
}

function get_elementary() {
    local HASH=""
    case ${RELEASE} in
        7.0) STAMP="20230129rc";;
        7.1) STAMP="20230926rc";;
        8.0) STAMP="20241122rc";;
    esac
    local ISO="elementaryos-${RELEASE}-stable.${STAMP}.iso"
    local URL="https://ams3.dl.elementary.io/download"
    echo "${URL}/$(date +%s | base64)/${ISO} ${HASH}"
}

function get_endeavouros() {
    local ENDEAVOUR_RELEASES=""
    local HASH=""
    local ISO=""
    local URL="https://mirror.alpix.eu/endeavouros/iso"
    # Find EndeavourOS releases from mirror, pick one matching release
    ENDEAVOUR_RELEASES="$(web_pipe "${URL}/" | grep -o '<a href="[^"]*.iso">' | sed 's/^<a href="//;s/.iso">.*//' | grep -v 'x86_64')"
    ISO="$(echo "${ENDEAVOUR_RELEASES}" | grep -i "${RELEASE}").iso"
    HASH=$(web_pipe "${URL}/${ISO}.sha512sum" | cut -d' ' -f1)
    echo "${URL}/${ISO} ${HASH}"
}

function get_endless() {
    local HASH="" # No hash - there is a signature in .asc signed by
    #https://d1anzknqnc1kmb.cloudfront.net/eos-image-keyring.gpg
    # (4096R: CB50 0F7B C923 3FAD 32B4 E720 9E0C 1250 587A 279C)
    local FILE_TS=""
    # https://support.endlessos.org/en/installation/direct-download gives the info but computes the URLS in js
    # so parsing out the useful info is not happening tonight
    # Endless edition names are "base" for the small minimal one or the Language for the large full release
    # The isos are stamped as they are finished so ....
    case ${EDITION} in
        base)  FILE_TS="241023-183516";;
        en)    FILE_TS="241023-200926";;
        es)    FILE_TS="241023-184649";;
        fr)    FILE_TS="241023-191212";;
        pt_BR) FILE_TS="241023-191427";;
    esac
    URL="https://images-dl.endlessm.com/release/${RELEASE}/eos-amd64-amd64/${EDITION}"
    ISO="eos-eos${RELEASE:0:3}-amd64-amd64.${FILE_TS}.${EDITION}.iso"
    echo "${URL}/${ISO} ${HASH}"
}

function get_fedora() {
    local HASH=""
    local ISO=""
    local JSON=""
    local URL=""
    local VARIANT=""
    case ${EDITION} in
        Server|Kinoite|Onyx|Silverblue|Sericea|Workstation) VARIANT="${EDITION}";;
        *) VARIANT="Spins";;
    esac
    # The naming of 41 Beta with a space is problematic so we replaced it with an underscore
    # but we need to convert it back to a space for the URL search in the JSON
    #shellcheck disable=SC2086
    # if RELEASE contains an underscore, replace it with a space
     if [[ "${RELEASE}" == *"_"* ]]; then
        RELEASE="${RELEASE/_/ }"
    fi



    # shellcheck disable=SC2086
    JSON=$(web_pipe "https://getfedora.org/releases.json" | jq '.[] | select(.variant=="'${VARIANT}'" and .subvariant=="'"${EDITION}"'" and .arch=="x86_64" and .version=="'"${RELEASE}"'" and (.link | endswith(".iso")))')
    URL=$(echo "${JSON}" | jq -r '.link' | head -n1)
    HASH=$(echo "${JSON}" | jq -r '.sha256' | head -n1)
    echo "${URL} ${HASH}"
}

function get_freebsd() {
    local HASH=""
    local ISO="FreeBSD-${RELEASE}-RELEASE-amd64-${EDITION}.iso"
    local URL="https://download.freebsd.org/ftp/releases/amd64/amd64/ISO-IMAGES/${RELEASE}"
    HASH=$(web_pipe "${URL}/CHECKSUM.SHA256-FreeBSD-${RELEASE}-RELEASE-amd64" | grep "${ISO}" | grep -v ".xz" | cut -d' ' -f4)
    echo "${URL}/${ISO} ${HASH}"
}

function get_freedos() {
    local HASH=""
    local ISO=""
    local URL="https://www.ibiblio.org/pub/micro/pc-stuff/freedos/files/distributions/${RELEASE}/official"
    case ${RELEASE} in
        1.2) ISO="FD12CD.iso"
             HASH=$(web_pipe "${URL}/FD12.sha" | grep "${ISO}" | cut -d' ' -f1);;
        1.3) ISO="FD13-LiveCD.zip"
             HASH=$(web_pipe "${URL}/verify.txt" | grep -A 8 "sha256sum" | grep "${ISO}" | cut -d' ' -f1);;
    esac
    echo "${URL}/${ISO} ${HASH}"
}

function get_garuda() {
    local HASH=""
    local ISO=""
    local URL="https://iso.builds.garudalinux.org/iso/latest/garuda"
    ISO=${EDITION}/latest.iso
    HASH="$(web_pipe "${URL}/${ISO}.sha256" | cut -d' ' -f1)"
    echo "${URL}/${ISO} ${HASH}"
}

function get_gentoo() {
    local HASH=""
    local ISO=""
    local URL="https://mirror.bytemark.co.uk/gentoo/releases/amd64/autobuilds"
    case ${EDITION} in
        minimal) ISO=$(web_pipe "${URL}/${RELEASE}-iso.txt" | grep install | cut -d' ' -f1);;
        livegui) ISO=$(web_pipe "${URL}/${RELEASE}-iso.txt" | grep livegui | cut -d' ' -f1);;
    esac
    HASH=$(web_pipe "${URL}/${ISO}.DIGESTS" | grep -A 1 SHA512 | grep iso | grep -v CONTENTS | cut -d' ' -f1)
    echo "${URL}/${ISO} ${HASH}"
}

function get_ghostbsd() {
    local ISO=""
    local URL="https://download.ghostbsd.org/releases/amd64/${RELEASE}"
    local HASH=""
    case ${EDITION} in
        mate) ISO="GhostBSD-${RELEASE}.iso";;
        xfce) ISO="GhostBSD-${RELEASE}-XFCE.iso";;
    esac
    HASH=$(web_pipe "${URL}/${ISO}.sha256" | grep "${ISO}" | cut -d' ' -f4)
    echo "${URL}/${ISO} ${HASH}"
}

function get_gnomeos() {
    local HASH=""
    local ISO="gnome_os_installer_${RELEASE}.iso"
    local URL="https://download.gnome.org/gnomeos/${RELEASE}"
    case ${RELEASE} in
        nightly)
            ISO="gnome_os_installer.iso"
            URL="https://os.gnome.org/download/latest";;
        46.0) ISO="gnome_os_installer_46.iso";;
        3*) ISO="gnome_os_installer.iso";;
    esac
    # Process the URL redirections; required for GNOME
    ISO=$(web_redirect "${URL}/${ISO}")
    echo "${ISO} ${HASH}"
}

function get_guix() {
    local HASH=""
    local ISO="guix-system-install-${RELEASE}.x86_64-linux.iso"
    local URL="https://ftpmirror.gnu.org/gnu/guix/"
    echo "${URL}/${ISO} ${HASH}"
}

function get_haiku() {
    local ISO="haiku-${RELEASE}-${EDITION}-anyboot.iso"
    local URL="http://mirror.rit.edu/haiku/${RELEASE}"
    HASH=$(web_pipe "${URL}/${ISO}.sha256" | grep "${ISO}" | cut -d' ' -f4)
    echo "${URL}/${ISO} ${HASH}"
}

function get_holoiso() {
    local HASH=""
    local URL=""
    RELEASE="$(web_pipe "https://github.com/HoloISO/releases/releases" | grep -o -e 'releases/tag/[[:digit:]]\+\(\.[[:digit:]]\+\)*' | head -n 1 | cut -d'/' -f 3)"
    URL=$(web_pipe "https://api.github.com/repos/HoloISO/releases/releases" | jq -r ".[] | select(.tag_name==\"${RELEASE}\") | .body" | sed -n 's/.*\(https:\/\/[^ ]*holoiso\.ru\.eu\.org\/[^ ]*\.iso\).*/\1/p' | head -n 1)
    echo "${URL} ${HASH}"
}

function get_kali() {
    local HASH=""
    local ISO=""
    local URL="https://cdimage.kali.org/${RELEASE}"
    ISO=$(web_pipe "${URL}/?C=M;O=D" | grep -o ">kali-linux-.*-installer-amd64.iso" | head -n 1 | cut -c 2-)
    HASH=$(web_pipe "${URL}/SHA256SUMS" | grep -v torrent | grep "${ISO}" | cut -d' ' -f1)
    echo "${URL}/${ISO} ${HASH}"
}

function get_kdeneon() {
    local HASH=""
    local ISO=""
    local URL="https://files.kde.org/neon/images/${RELEASE}/current"
    ISO=$(web_pipe "${URL}/neon-${RELEASE}-current.sha256sum" | cut -d' ' -f3-)
    HASH=$(web_pipe "${URL}/neon-${RELEASE}-current.sha256sum" | cut -d' ' -f1)
    echo "${URL}/${ISO} ${HASH}"
}

function get_kolibrios() {
    local HASH=""
    local ISO="latest-iso.7z"
    local URL="http://builds.kolibrios.org/${EDITION}"
    echo "${URL}/${ISO} ${HASH}"
}

function get_linuxlite() {
    local HASH=""
    local ISO="linux-lite-${RELEASE}-64bit.iso"
    local URL="https://sourceforge.net/projects/linux-lite/files/${RELEASE}"
    HASH=$(web_pipe "${URL}/${ISO}.sha256" | cut -d' ' -f1)
    echo "${URL}/${ISO} ${HASH}"
}

function get_linuxmint() {
    local HASH=""
    local ISO="linuxmint-${RELEASE}-${EDITION}-64bit.iso"
    local URL="https://mirror.bytemark.co.uk/linuxmint/stable/${RELEASE}"
    HASH=$(web_pipe "${URL}/sha256sum.txt" | grep "${ISO}" | cut -d' ' -f1)
    echo "${URL}/${ISO} ${HASH}"
}

function get_lmde() {
    local HASH=""
    local ISO="lmde-${RELEASE}-${EDITION}-64bit.iso"
    local URL="https://mirror.bytemark.co.uk/linuxmint/debian"
    HASH=$(web_pipe "${URL}/sha256sum.txt" | grep "${ISO}" | cut -d' ' -f1)
    echo "${URL}/${ISO} ${HASH}"
}

function get_maboxlinux() {
    local HASH=""
    local URL=""
    URL="https://sourceforge.net/projects/mabox-linux/files/${RELEASE}/download"
    URL="$(web_redirect "${URL}" | cut -d? -f1)"
    echo "${URL} ${HASH}"
}

function generate_id() {
    local macRecoveryID=""
    local TYPE="${1}"
    local valid_chars=("0" "1" "2" "3" "4" "5" "6" "7" "8" "9" "A" "B" "C" "D" "E" "F")
    for ((i=0; i<TYPE; i++)); do
        macRecoveryID+="${valid_chars[$((RANDOM % 16))]}"
    done
    echo "${macRecoveryID}"
}

function get_macos() {
    local appleSession=""
    local info=""
    local downloadLink=""
    local downloadSession=""
    local chunkListLink=""
    local chunkListSession=""
    local BOARD_ID=""
    local CWD=""
    local CHECK=""
    local CHUNKCHECK=""
    local MLB="00000000000000000"
    local OS_TYPE="default"

    case ${RELEASE} in
        lion|10.7)
            BOARD_ID="Mac-2E6FAB96566FE58C"
            MLB="00000000000F25Y00";;
        mountainlion|10.8)
            BOARD_ID="Mac-7DF2A3B5E5D671ED"
            MLB="00000000000F65100";;
        mavericks|10.9)
            BOARD_ID="Mac-F60DEB81FF30ACF6"
            MLB="00000000000FNN100";;
        yosemite|10.10)
            BOARD_ID="Mac-E43C1C25D4880AD6"
            MLB="00000000000GDVW00";;
        elcapitan|10.11)
            BOARD_ID="Mac-FFE5EF870D7BA81A"
            MLB="00000000000GQRX00";;
        sierra|10.12)
            BOARD_ID="Mac-77F17D7DA9285301"
            MLB="00000000000J0DX00";;
        high-sierra|10.13)
            BOARD_ID="Mac-BE088AF8C5EB4FA2"
            MLB="00000000000J80300";;
        mojave|10.14)
            BOARD_ID="Mac-7BA5B2DFE22DDD8C"
            MLB="00000000000KXPG00";;
        catalina|10.15)
            BOARD_ID="Mac-00BE6ED71E35EB86";;
        big-sur|11)
            BOARD_ID="Mac-42FD25EABCABB274";;
        monterey|12)
            BOARD_ID="Mac-E43C1C25D4880AD6";;
        ventura|13)
            BOARD_ID="Mac-BE088AF8C5EB4FA2";;
        sonoma|14)
            BOARD_ID="Mac-53FDB3D8DB8CA971";;
        *) echo "ERROR! Unknown release: ${RELEASE}"
           releases_macos
           exit 1;;
    esac

    CWD="$(dirname "${0}")"
    if [ -x "${CWD}/chunkcheck" ]; then
        CHUNKCHECK="${CWD}/chunkcheck"
    elif [ -x "$(command -v chunkcheck)" ]; then
        CHUNKCHECK="$(command -v chunkcheck)"
    fi

    appleSession=$(curl -v -H "Host: osrecovery.apple.com" \
                           -H "Connection: close" \
                           -A "InternetRecovery/1.0" https://osrecovery.apple.com/ 2>&1 | tr ';' '\n' | awk -F'session=|;' '{print $2}' | grep 1)
    info=$(curl -s -X POST -H "Host: osrecovery.apple.com" \
                           -H "Connection: close" \
                           -A "InternetRecovery/1.0" \
                           -b "session=\"${appleSession}\"" \
                           -H "Content-Type: text/plain" \
                           -d $'cid='"$(generate_id 16)"$'\nsn='${MLB}$'\nbid='${BOARD_ID}$'\nk='"$(generate_id 64)"$'\nfg='"$(generate_id 64)"$'\nos='${OS_TYPE} \
                           https://osrecovery.apple.com/InstallationPayload/RecoveryImage | tr ' ' '\n')
    downloadLink=$(echo "$info" | grep 'oscdn' | grep 'dmg')
    downloadSession=$(echo "$info" | grep 'expires' | grep 'dmg')
    chunkListLink=$(echo "$info" | grep 'oscdn' | grep 'chunklist')
    chunkListSession=$(echo "$info" | grep 'expires' | grep 'chunklist')

    if [ "${OPERATION}" == "show" ]; then
        test_result "${OS}" "${RELEASE}" "" "${downloadLink}"
        exit 0
    elif [ "${OPERATION}" == "test" ]; then
        CHECK=$(web_check "${downloadLink}" --header "Host: oscdn.apple.com" --header "Connection: close" --header "User-Agent: InternetRecovery/1.0" --header "Cookie: AssetToken=${downloadSession}" && echo "PASS" || echo "FAIL")
        test_result "${OS}" "${RELEASE}" "" "${downloadLink}" "${CHECK}"
        exit 0
    elif [ "${OPERATION}" == "download" ]; then
        echo "Downloading macOS (${RELEASE^}) RecoveryImage"
        echo " - URL: ${downloadLink}"
        web_get "${downloadLink}" "${VM_PATH}" RecoveryImage.dmg --header "Host: oscdn.apple.com" --header "Connection: close" --header "User-Agent: InternetRecovery/1.0" --header "Cookie: AssetToken=${downloadSession}"
        web_get "${chunkListLink}" "${VM_PATH}" RecoveryImage.chunklist --header "Host: oscdn.apple.com" --header "Connection: close" --header "User-Agent: InternetRecovery/1.0" --header "Cookie: AssetToken=${chunkListSession}"
        VM_PATH="$(pwd)"
    else
        if [ ! -e "${VM_PATH}/RecoveryImage.chunklist" ]; then
            echo "Downloading macOS (${RELEASE^}) RecoveryImage"
            echo " - URL: ${downloadLink}"
            web_get "${downloadLink}" "${VM_PATH}" RecoveryImage.dmg --header "Host: oscdn.apple.com" --header "Connection: close" --header "User-Agent: InternetRecovery/1.0" --header "Cookie: AssetToken=${downloadSession}"
            web_get "${chunkListLink}" "${VM_PATH}" RecoveryImage.chunklist --header "Host: oscdn.apple.com" --header "Connection: close" --header "User-Agent: InternetRecovery/1.0" --header "Cookie: AssetToken=${chunkListSession}"
            if ! "${CHUNKCHECK}" "${VM_PATH}" 2> /dev/null; then
                echo " - WARNING! Verification failed, continuing anyway"
            else
                echo " - Verification passed"
            fi

            if [ -e "${VM_PATH}/RecoveryImage.dmg" ] && [ ! -e "${VM_PATH}/RecoveryImage.img" ]; then
                echo " - Converting RecoveryImage.dmg"
                ${QEMU_IMG} convert "${VM_PATH}/RecoveryImage.dmg" -O raw "${VM_PATH}/RecoveryImage.img" 2>/dev/null
            fi
            rm "${VM_PATH}/RecoveryImage.dmg" "${VM_PATH}/RecoveryImage.chunklist"
            echo " - RecoveryImage.img is ready."
        fi
        echo "Downloading OpenCore & UEFI firmware"
        web_get "https://github.com/kholia/OSX-KVM/raw/master/OpenCore/OpenCore.qcow2" "${VM_PATH}"
        web_get "https://github.com/kholia/OSX-KVM/raw/master/OVMF_CODE.fd" "${VM_PATH}"
        if [ ! -e "${VM_PATH}/OVMF_VARS-1920x1080.fd" ]; then
            web_get "https://github.com/kholia/OSX-KVM/raw/master/OVMF_VARS-1920x1080.fd" "${VM_PATH}"
        fi
    fi
    make_vm_config RecoveryImage.img
}

function get_mageia() {
    local HASH=""
    local ISO=""
    ISO=$(web_pipe https://www.mageia.org/en/downloads/get/?q="Mageia-${RELEASE}-Live-${EDITION}-x86_64.iso" | grep 'click here'| grep -o 'href=.*\.iso'|cut -d\" -f2)
    HASH=$(web_pipe "${ISO}.sha512" | cut -d' ' -f1)
    echo "${ISO} ${HASH}"
}

function get_manjaro() {
    local HASH=""
    local ISO=""
    local MANIFEST=""
    local URL=""
    local TYPE="official"
    MANIFEST="$(web_pipe https://gitlab.manjaro.org/web/iso-info/-/raw/master/file-info.json)"
    case "${RELEASE}" in
        sway)
            MANIFEST="$(web_pipe https://mirror.manjaro-sway.download/manjaro-sway/release.json)"
            TYPE="sway"
            ;;
        cinnamon|i3) TYPE="community";;
    esac

    if [ "${EDITION}" == "minimal" ] && [ "${TYPE}" != "sway" ]; then
        EDITION=".minimal"
    else
        EDITION=""
    fi

    if [ "${RELEASE}" == "sway" ]; then
        URL=$(echo "${MANIFEST}" | jq -r '.[] | select(.name|test("^manjaro-sway-.*[.]iso$")) | .url')
    else
        URL="$(echo "${MANIFEST}" | jq -r ."${TYPE}.${RELEASE}${EDITION}".image)"
    fi
    HASH=$(web_pipe "${URL}.sha512" | cut -d' ' -f1)
    echo "${URL} ${HASH}"
}

function get_mxlinux() {
    local HASH=""
    local ISO=""
    local URL="https://sourceforge.net/projects/mx-linux/files/Final/${EDITION}"
    case ${EDITION} in
        Xfce) ISO="MX-${RELEASE}_x64.iso";;
        KDE) ISO="MX-${RELEASE}_KDE_x64.iso";;
        Fluxbox) ISO="MX-${RELEASE}_fluxbox_x64.iso";;
    esac
    HASH=$(web_pipe "${URL}/${ISO}.sha256" | cut -d' ' -f1)
    echo "${URL}/${ISO} ${HASH}"
}

function get_netboot() {
    local HASH=""
    local ISO="netboot.xyz.iso"
    local URL="https://boot.netboot.xyz/ipxe"
    HASH=$(web_pipe "${URL}/netboot.xyz-sha256-checksums.txt" | grep "${ISO}" | cut -d' ' -f1)
    echo "${URL}/${ISO} ${HASH}"
}

function get_netbsd() {
    local HASH=""
    local ISO="NetBSD-${RELEASE}-amd64.iso"
    local URL="https://cdn.netbsd.org/pub/NetBSD/NetBSD-${RELEASE}/images"
    HASH=$(web_pipe "${URL}/MD5" | grep "${ISO}" | cut -d' ' -f4)
    echo "${URL}/${ISO} ${HASH}"
}

function get_nitrux() {
    local HASH=""
    local URLBASE=""
    local URL=""
    local ISO=""
    URLBASE="https://sourceforge.net/projects/nitruxos/files/Release"
    URL="${URLBASE}/ISO"
    ISO=$(web_pipe 'https://sourceforge.net/projects/nitruxos/rss?path=/Release/ISO' | grep '.iso' | head -n 1 | cut -d']' -f1 | cut -d '/' -f4)
    HASH=$(web_pipe "${URLBASE}/MD5/${ISONAME}.md5sum" | grep "${ISO}" | cut -d' ' -f1)
    echo "${URL}/${ISO} ${HASH}"
}

function get_nixos() {
    local HASH=""
    # Adapt the plasma edition according to the NixOS release
    case "${EDITION}" in
        plasma)
            if [ "${RELEASE}" == "23.11" ]; then
                EDITION+="5"
            else
                EDITION+="6"
            fi
            ;;
    esac
    local ISO="latest-nixos-${EDITION}-x86_64-linux.iso"
    local URL="https://channels.nixos.org/nixos-${RELEASE}"
    HASH=$(web_pipe "${URL}/${ISO}.sha256" | cut -d' ' -f1)
    echo "${URL}/${ISO} ${HASH}"
}

function get_nwg-shell() {
    local HASH=""
    local ISO="nwg-live-${RELEASE}-x86_64.iso"
    local URL="https://sourceforge.net/projects/nwg-iso/files"
    HASH="$(web_pipe "https://sourceforge.net/projects/nwg-iso/rss?path=/" | grep "${ISO}" | cut -d'>' -f3 | cut -d'<' -f1 | tail -n 1)"
    echo "${URL}/${ISO} ${HASH}"
}

function get_openbsd() {
    local HASH=""
    local ISO="install${RELEASE//\./}.iso"
    local URL="https://mirror.leaseweb.com/pub/OpenBSD/${RELEASE}/amd64"
    HASH=$(web_pipe "${URL}/SHA256" | grep "${ISO}" | cut -d' ' -f4)
    echo "${URL}/${ISO} ${HASH}"
}

function get_openindiana() {
    local HASH=""
    local ISO=""
    local URL=""
    URL="https://dlc.openindiana.org/isos/hipster/${RELEASE}"
    ISO="OI-hipster-${EDITION}-${RELEASE}.iso"
    HASH=$(web_pipe "${URL}/${ISO}.sha256" |cut -d' ' -f1)
    echo "${URL}/${ISO} ${HASH}"
}

function get_opensuse() {
    local HASH=""
    local ISO=""
    local URL=""
    if [ "${RELEASE}" == "tumbleweed" ]; then
        ISO="openSUSE-Tumbleweed-DVD-x86_64-Current.iso"
        URL="https://download.opensuse.org/tumbleweed/iso"
    elif [ "${RELEASE}" == "microos" ]; then
        ISO="openSUSE-MicroOS-DVD-x86_64-Current.iso"
        URL="https://download.opensuse.org/tumbleweed/iso"
    elif [ "${RELEASE}" == "aeon" ]; then
        ISO="opensuse-aeon.x86_64.iso"
        URL="https://mirrorcache.opensuse.org/tumbleweed/appliances/iso"
    elif [ "${RELEASE}" == 15.0 ] || [ "${RELEASE}" == 15.1 ]; then
        ISO="openSUSE-Leap-${RELEASE}-DVD-x86_64.iso"
        URL="https://download.opensuse.org/distribution/leap/${RELEASE}/iso"
    else
        ISO="openSUSE-Leap-${RELEASE}-DVD-x86_64-Current.iso"
        URL="https://download.opensuse.org/distribution/leap/${RELEASE}/iso"
    fi
    HASH=$(web_pipe "${URL}/${ISO}.sha256" | awk '{if(NR==4) print $0}' | cut -d' ' -f1)
    echo "${URL}/${ISO} ${HASH}"
}

function get_oraclelinux() {
    local HASH=""
    local ISO=""
    local VER_MAJ=${RELEASE::1}
    local VER_MIN=${RELEASE:2:1}
    local URL="https://yum.oracle.com/ISOS/OracleLinux/OL${VER_MAJ}/u${VER_MIN}/x86_64"
    case ${VER_MAJ} in
        7) ISO="OracleLinux-R${VER_MAJ}-U${VER_MIN}-Server-x86_64-dvd.iso";;
        *) ISO="OracleLinux-R${VER_MAJ}-U${VER_MIN}-x86_64-dvd.iso";;
    esac
    HASH=$(web_pipe "https://linux.oracle.com/security/gpg/checksum/OracleLinux-R${VER_MAJ}-U${VER_MIN}-Server-x86_64.checksum" | grep "${ISO}" | cut -d' ' -f1)
    echo "${URL}/${ISO} ${HASH}"
}

function get_parrotsec() {
    local HASH=""
    local ISO=""
    local URL=""
    ISO="Parrot-${EDITION}-${RELEASE}_amd64.iso"
    URL="https://download.parrot.sh/parrot/iso/${RELEASE}"
    HASH="$(web_pipe "${URL}/signed-hashes.txt" | grep "${ISO}" | cut -d' ' -f1)"
    echo "${URL}/${ISO} ${HASH}"
}

function get_peppermint() {
    local HASH=""
    local ISO=""
    local URL="https://sourceforge.net/projects/peppermintos/files/isos"
    case ${EDITION} in
        devuan-xfce)
            ISO="PeppermintOS-devuan_64_xfce.iso"
            URL="${URL}/XFCE";;
        debian-xfce)
            ISO="PeppermintOS-Debian-64.iso"
            URL="${URL}/XFCE";;
        devuan-gnome)
            ISO="PeppermintOS-devuan_64_gfb.iso"
            URL="${URL}/Gnome_FlashBack";;
        debian-gnome)
            ISO="PeppermintOS-Debian_64_gfb.iso"
            URL="${URL}/Gnome_FlashBack";;
    esac
    HASH=$(web_pipe "${URL}/${ISO}-sha512.checksum" | grep "${ISO}" | cut -d' ' -f1)
    echo "${URL}/${ISO} ${HASH}"
}

function get_popos() {
    local HASH=""
    local ISO=""
    local URL=""
    URL=$(web_pipe "https://api.pop-os.org/builds/${RELEASE}/${EDITION}" | jq -r .url)
    HASH=$(web_pipe "https://api.pop-os.org/builds/${RELEASE}/${EDITION}" | jq -r .sha_sum)
    echo "${URL} ${HASH}"
}

function get_porteus() {
    local HASH=""
    local ISO=""
    local URL=""
    edition="${EDITION~~}"
    ISO="Porteus-${edition}-v${RELEASE}-x86_64.iso"
    URL="https://mirrors.dotsrc.org/porteus/x86_64/Porteus-v${RELEASE}"
    HASH=$(web_pipe "${URL}/sha256sums.txt" | grep "${ISO}" | cut -d' ' -f1)
    echo "${URL}/${ISO} ${HASH}"
}

function get_primtux() {
    local HASH=""
    local URL=""
    local ISO=""
    ISO="PrimTux${RELEASE}-amd64-${EDITION}.iso"
    URL="https://sourceforge.net/projects/primtux/files/Distribution"
    HASH=$(web_pipe "${URL}/${ISO}.md5" | grep "${ISO}" | cut -d' ' -f1)
    echo "${URL}/${ISO} ${HASH}"
}

function get_proxmox-ve() {
    local HASH=""
    local ISO=""
    local URL=""
    ISO="proxmox-ve_${RELEASE}.iso"
    URL="https://enterprise.proxmox.com/iso"
    HASH=$(web_pipe "${URL}/SHA256SUMS" | grep "${ISO}" | cut -d' ' -f1)
    echo "${URL}/${ISO} ${HASH}"

}

function get_pureos() {
    local HASH=""
    local ISO=""
    local URL=""
    local PureName=
    PureName="$(web_pipe "https://www.pureos.net/download/" | grep -m 1 "downloads.puri" | cut -d '/' -f 4)"
    local PureDate=
    PureDate="$(web_pipe "https://www.pureos.net/download/" | grep -m 1 "downloads.puri" | cut -d '/' -f 6)"
    local PureDateSquashed="${PureDate//'-'/}"
    edition="${EDITION,,}"
    URL="https://downloads.puri.sm/${PureName}/${edition}/${PureDate}"
    ISO="pureos-${RELEASE}-${edition}-live-${PureDateSquashed}_amd64.iso"
    local IsoTrimmed=
    IsoTrimmed="${ISO%.*}"
    HASH="$(web_pipe "${URL}/${IsoTrimmed}.checksums_sha256.txt" | grep -m 1 '.iso' | cut -d '.' -f 1)"
    echo "${URL}/${ISO} ${HASH}"
}

function get_reactos() {
    local HASH=""
    local URL=""
    URL="$(web_redirect "https://sourceforge.net/projects/reactos/files/latest/download")"
    echo "${URL} ${HASH}"
}

function get_rebornos() {
    local HASH=""
    local ISO=""
    ISO=$(web_pipe "https://meta.cdn.soulharsh007.dev/RebornOS-ISO?format=json" | jq -r ".url")
    HASH=$(web_pipe "https://meta.cdn.soulharsh007.dev/RebornOS-ISO?format=json" | jq -r ".md5")
    echo "${ISO} ${HASH}"
}

function get_rockylinux() {
    if [[ "${RELEASE}" =~ ^8. ]] && [[ "${EDITION}" == "dvd" ]]; then
        EDITION="dvd1"
    fi
    local HASH=""
    local ISO="Rocky-${RELEASE}-x86_64-${EDITION}.iso"
    local URL=""
    URL="https://dl.rockylinux.org/vault/rocky/${RELEASE}/isos/x86_64"
    HASH=$(web_pipe "${URL}/CHECKSUM" | grep "SHA256" | grep "${ISO})" | cut -d' ' -f4)
    echo "${URL}/${ISO} ${HASH}"
}

function get_siduction() {
    local HASH=""
    local DATE=""
    local ISO=""
    local URL="https://mirrors.dotsrc.org/siduction/iso/Standing_on_the_Shoulders_of_Giants/${EDITION}"
    DATE=$(web_pipe "${URL}"| grep .iso.md5 | cut -d'-' -f6 | cut -d'.' -f1)
    HASH=$(web_pipe "${URL}/${ISO}.md5" | cut -d' ' -f1)
    ISO="siduction-2023.1.1-Standing_on_the_Shoulders_of_Giants-${EDITION}-amd64-${DATE}.iso"
    echo "${URL}/${ISO} ${HASH}"
}

function get_slackware() {
    local HASH=""
    local ISO="slackware64-${RELEASE}-install-dvd.iso"
    local URL="https://slackware.nl/slackware/slackware-iso/slackware64-${RELEASE}-iso"
    HASH=$(web_pipe "${URL}/${ISO}.md5" | cut -d' ' -f1)
    echo "${URL}/${ISO} ${HASH}"
}

function get_slax() {
    local HASH=""
    local ISO=""
    local URL=""
    case ${EDITION} in
        debian)
            URL="https://ftp.fi.muni.cz/pub/linux/slax/Slax-12.x"
            ISO=$(web_pipe "${URL}/md5.txt" | grep '64bit-' | cut -d' ' -f3 | tail -n1);;
        slackware)
            URL="https://ftp.fi.muni.cz/pub/linux/slax/Slax-15.x"
            ISO=$(web_pipe "${URL}/md5.txt" | grep '64bit-' | cut -d' ' -f3 | tail -n1);;
    esac
    HASH=$(web_pipe "${URL}/md5.txt" | grep '64bit-' | cut -d' ' -f1 | tail -n1)
    echo "${URL}/${ISO} ${HASH}"
}

function get_slint() {
    local HASH=""
    local MAJ_VER=""
    local ISO="slint64-${RELEASE}.iso"
    MAJ_VER="$(echo "${RELEASE}" | cut -d'-' -f 1)"
    local URL="https://slackware.uk/slint/x86_64/slint-${MAJ_VER}/iso"
    HASH=$(web_pipe "${URL}/${ISO}.sha256" | cut -d' ' -f4)
    echo "${URL}/${ISO}" "${HASH}"
}

function get_slitaz() {
    local HASH=""
    local ISO="slitaz-rolling-${RELEASE}"
    local URL="http://mirror.slitaz.org/iso/rolling"
    HASH=$(web_pipe "${URL}/${ISO}.md5" | cut -d' ' -f1)
    echo "${URL}/${ISO}.iso ${HASH}"
}

function get_solus() {
    local HASH=""
    local ISO="Solus-${EDITION}-Release-${RELEASE}.iso"
    local URL="https://downloads.getsol.us/isos/${RELEASE}"
    HASH=$(web_pipe "${URL}/${ISO}.sha256sum" | cut -d' ' -f1)
    echo "${URL}/${ISO} ${HASH}"
}

function get_sparkylinux() {
    local HASH=""
    local ISO=""
    local URL=""
    ISO="sparkylinux-${RELEASE}-x86_64-${EDITION}.iso"
    case ${EDITION} in
        minimalcli) URL="https://sourceforge.net/projects/sparkylinux/files/cli";;
        minimalgui) URL="https://sourceforge.net/projects/sparkylinux/files/base";;
        *) URL="https://sourceforge.net/projects/sparkylinux/files/${EDITION}";;
    esac
    HASH=$(web_pipe "${URL}/${ISO}.allsums.txt" | head -n 2 | grep 'iso' | cut -d' ' -f1)
    echo "${URL}/${ISO}" "${HASH}"
}

function get_spirallinux() {
    local HASH=""
    local ISO="SpiralLinux_${EDITION}_12.231005_x86-64.iso"
    local URL="https://sourceforge.net/projects/spirallinux/files/12.231005"
    HASH=$(web_pipe 'https://sourceforge.net/projects/spirallinux/rss?path=/' | grep "${ISO}" | grep 'md5' | cut -d'<' -f3 | cut -d'>' -f2)
    echo "${URL}/${ISO}" "${HASH}"
}

function get_tails() {
    local JSON=""
    local HASH=""
    local URL=""
    JSON="$(web_pipe "https://tails.boum.org/install/v2/Tails/amd64/${RELEASE}/latest.json")"
    URL=$(echo "${JSON}" | jq -r '.installations[0]."installation-paths"[]|select(.type=="iso")|."target-files"[0].url')
    HASH=$(echo "${JSON}" | jq -r '.installations[0]."installation-paths"[]|select(.type=="iso")|."target-files"[0].sha256')
    echo "${URL} ${HASH}"
}

function get_tinycore() {
    local ARCH="x86"
    local HASH=""
    local ISO="${EDITION}-${RELEASE}.0.iso"
    case "${EDITION}" in
        *Pure*) ARCH+="_64";;
    esac
    local URL="http://www.tinycorelinux.net/${RELEASE}.x/${ARCH}/release"
    HASH=$(web_pipe "${URL}/${ISO}.md5.txt" | cut -d' ' -f1)
    echo "${URL}/${ISO} ${HASH}"
}

function get_trisquel() {
    local HASH=""
    local ISO=""
    local URL="https://mirrors.ocf.berkeley.edu/trisquel-images"
    case ${EDITION} in
        mate) ISO="trisquel_${RELEASE}_amd64.iso";;
        lxde) ISO="trisquel-mini_${RELEASE}_amd64.iso";;
        kde) ISO="triskel_${RELEASE}_amd64.iso";;
        sugar) ISO="trisquel-sugar_${RELEASE}_amd64.iso";;
    esac
    HASH=$(web_pipe "${URL}/${ISO}.sha1" | grep "${ISO}" | cut -d' ' -f1)
    echo "${URL}/${ISO} ${HASH}"
}

function get_truenas-scale() {
    local HASH=""
    local ISO=""
    local URL=""
    local DLINFO="https://www.truenas.com/download-truenas-scale/"
    URL=$(web_pipe "${DLINFO}" | grep -o "\"https://.*${RELEASE}.*\.iso\"" | cut -d'"' -f 2)
    HASH=$(web_pipe "${URL}.sha256" | cut -d' ' -f1)
    echo "${URL} ${HASH}"
}

function get_truenas-core() {
    local ISO=""
    local URL=""
    local DLINFO="https://www.truenas.com/download-truenas-core/"
    URL=$(web_pipe "${DLINFO}" | grep -o "\"https://.*${RELEASE}.*\.iso\"" | cut -d'"' -f 2)
    HASH=$(web_pipe "${URL}".sha256 | cut -d' ' -f1)
    echo "${URL} ${HASH}"
}

function get_tuxedo-os() {
    local HASH=""
    local ISO=""
    local URL="https://os.tuxedocomputers.com"
    ISO="$(web_pipe "https://os.tuxedocomputers.com/" | grep -m 1 current.iso | cut -d '=' -f 4 | cut -d '"' -f 2)"
    HASH="$(web_pipe "https://os.tuxedocomputers.com/checksums/${ISO}.sha256" | cut -d ' ' -f 1)"
    echo "${URL}/${ISO} ${HASH}"
}

function get_ubuntu-server() {
    local HASH=""
    local ISO=""
    local NAME="live-server"
    local URL=""

    if [[ "${RELEASE}" == "daily"* ]]; then
        URL="https://cdimage.ubuntu.com/${OS}/${RELEASE}/current"
    else
        URL="https://releases.ubuntu.com/${RELEASE}"
    fi

    case "${RELEASE}" in
        14*|16*) NAME="server";;
    esac

    if web_check "${URL}/SHA256SUMS"; then
        DATA=$(web_pipe "${URL}/SHA256SUMS" | grep "${NAME}" | grep amd64 | grep iso)
        ISO=$(cut -d'*' -f2 <<<"${DATA}")
        HASH=$(cut -d' ' -f1 <<<"${DATA}")
    else
        DATA=$(web_pipe "${URL}/MD5SUMS" | grep "${NAME}" | grep amd64 | grep iso)
        ISO=$(cut -d' ' -f3 <<<"${DATA}")
        HASH=$(cut -d' ' -f1 <<<"${DATA}")
    fi
    if [[ "${RELEASE}" == "daily"* ]] || [ "${RELEASE}" == "dvd" ]; then
        zsync_get "${URL}/${ISO}" "${VM_PATH}" "${OS}-devel.iso"
        make_vm_config "${OS}-devel.iso"
    else
        web_get "${URL}/${ISO}" "${VM_PATH}"
        check_hash "${ISO}" "${HASH}"
        make_vm_config "${ISO}"
    fi
}

function get_ubuntu() {
    local ISO=""
    local HASH=""
    local URL=""
    local DATA=""

    if [[ "${RELEASE}" == "daily"* ]] && [ "${OS}" == "ubuntustudio" ]; then
        # Ubuntu Studio daily-live images are in the dvd directory
        RELEASE="dvd"
    fi
    if [[ "${RELEASE}" == "jammy-daily" ]]; then
        if [[ "${OS}" == "ubuntustudio" ]]; then
            URL="https://cdimage.ubuntu.com/${OS}/jammy/dvd/current"
        else
            URL="https://cdimage.ubuntu.com/${OS}/jammy/daily-live/current"
        fi
        VM_PATH="${OS}-jammy-live"
    elif [[ "${RELEASE}" == "daily"* ]] || [ "${RELEASE}" == "dvd" ]; then
        URL="https://cdimage.ubuntu.com/${OS}/${RELEASE}/current"
        VM_PATH="${OS}-${RELEASE}"
    elif [ "${OS}" == "ubuntu" ]; then
        URL="https://releases.ubuntu.com/${RELEASE}"
    else
        URL="https://cdimage.ubuntu.com/${OS}/releases/${RELEASE}/release"
    fi
    if web_check "${URL}/SHA256SUMS"; then
        DATA=$(web_pipe "${URL}/SHA256SUMS" | grep 'desktop\|dvd\|install' | grep amd64 | grep iso | grep -v "+mac")
        ISO=$(cut -d'*' -f2 <<<"${DATA}" | sed '1q;d')
        HASH=$(cut -d' ' -f1 <<<"${DATA}" | sed '1q;d')
    else
        DATA=$(web_pipe "${URL}/MD5SUMS" | grep 'desktop\|dvd\|install' | grep amd64 | grep iso | grep -v "+mac")
        ISO=$(cut -d'*' -f2 <<<"${DATA}")
        HASH=$(cut -d' ' -f1 <<<"${DATA}")
    fi
    if [ -z "${ISO}" ] || [ -z "${HASH}" ]; then
        echo "$(pretty_name "${OS}") ${RELEASE} is currently unavailable. Please select other OS/Release combination"
        exit 1
    fi
    if [[ "${RELEASE}" == "daily"* ]] || [ "${RELEASE}" == "dvd" ]; then
        zsync_get "${URL}/${ISO}" "${VM_PATH}" "${OS}-devel.iso"
        make_vm_config "${OS}-devel.iso"
    elif [[ "${RELEASE}" == "jammy-daily" ]]; then
        zsync_get "${URL}/${ISO}" "${VM_PATH}" "${OS}-jammy-live.iso"
        make_vm_config "${OS}-jammy-live.iso"
    else
        web_get "${URL}/${ISO}" "${VM_PATH}"
        check_hash "${ISO}" "${HASH}"
        make_vm_config "${ISO}"
    fi
}

function get_vanillaos() {
    local HASH=""
    local HASH_URL=""
    local ISO=""
    ISO=$(web_pipe "https://api.github.com/repos/Vanilla-OS/live-iso/releases" | grep 'download_url' | grep "${RELEASE}" | head -n 1 | cut -d'"' -f4)
    HASH_URL="${ISO//.iso/.sha256.txt}"
    HASH=$(web_pipe "${HASH_URL}" | cut -d' ' -f1)
    echo "${ISO} ${HASH}"
}

function get_void() {
    local DATE=""
    local HASH=""
    local ISO=""
    local URL="https://repo-default.voidlinux.org/live"
    case ${EDITION} in
        glibc) ISO="void-live-x86_64-${RELEASE}-base.iso";;
        musl) ISO="void-live-x86_64-musl-${RELEASE}-base.iso";;
        xfce-glibc) ISO="void-live-x86_64-${RELEASE}-xfce.iso";;
        xfce-musl) ISO="void-live-x86_64-musl-${RELEASE}-xfce.iso";;
    esac
    HASH="$(web_pipe "${URL}/sha256sum.txt" | grep "${ISO}" | cut -d' ' -f4)"
    echo "${URL}/${RELEASE}/${ISO} ${HASH}"
}

function get_vxlinux() {
    local HASH=""
    local ISO="vx-${RELEASE}.iso"
    local URL="https://github.com/VX-Linux/main/releases/download/${RELEASE}"
    HASH=$(web_pipe "${URL}/vx-${RELEASE}.md5" | cut -d' ' -f1)
    echo "${URL}/${ISO} ${HASH}"
}

function get_zorin() {
    local HASH=""
    local ISO=""
    local URL=""
    # Process the URL redirections; required for Zorin
    URL=$(web_redirect "https://zrn.co/${RELEASE}${EDITION}")
    echo "${URL} ${HASH}"
}

function unattended_windows() {
    mkdir -p "${1}/unattended" 2>/dev/null

    cat << 'EOF' > "${1}/unattended/autounattend.xml"
<?xml version="1.0" encoding="utf-8"?>
<unattend xmlns="urn:schemas-microsoft-com:unattend"
  xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <!--
       For documentation on components:
       https://docs.microsoft.com/en-us/windows-hardware/customize/desktop/unattend/
  -->
  <settings pass="offlineServicing">
    <component name="Microsoft-Windows-LUA-Settings" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <EnableLUA>false</EnableLUA>
    </component>
    <component name="Microsoft-Windows-Shell-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <ComputerName>*</ComputerName>
    </component>
  </settings>

  <settings pass="generalize">
    <component name="Microsoft-Windows-PnPSysprep" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS">
      <PersistAllDeviceInstalls>true</PersistAllDeviceInstalls>
    </component>
    <component name="Microsoft-Windows-Security-SPP" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <SkipRearm>1</SkipRearm>
    </component>
  </settings>

  <settings pass="specialize">
    <component name="Microsoft-Windows-Security-SPP-UX" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <SkipAutoActivation>true</SkipAutoActivation>
    </component>
    <component name="Microsoft-Windows-Shell-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <ComputerName>*</ComputerName>
      <OEMInformation>
        <Manufacturer>Quickemu Project</Manufacturer>
        <Model>Quickemu</Model>
        <SupportHours>24/7</SupportHours>
        <SupportPhone></SupportPhone>
        <SupportProvider>Quickemu Project</SupportProvider>
        <SupportURL>https://github.com/quickemu-project/quickemu/issues</SupportURL>
      </OEMInformation>
      <OEMName>Quickemu Project</OEMName>
      <ProductKey>W269N-WFGWX-YVC9B-4J6C9-T83GX</ProductKey>
    </component>
    <component name="Microsoft-Windows-SQMApi" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <CEIPEnabled>0</CEIPEnabled>
    </component>
  </settings>

  <settings pass="windowsPE">
    <component name="Microsoft-Windows-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <Diagnostics>
        <OptIn>false</OptIn>
      </Diagnostics>
      <DiskConfiguration>
        <Disk wcm:action="add">
          <DiskID>0</DiskID>
          <WillWipeDisk>true</WillWipeDisk>
          <CreatePartitions>
            <!-- Windows RE Tools partition -->
            <CreatePartition wcm:action="add">
              <Order>1</Order>
              <Type>Primary</Type>
              <Size>256</Size>
            </CreatePartition>
            <!-- System partition (ESP) -->
            <CreatePartition wcm:action="add">
              <Order>2</Order>
              <Type>EFI</Type>
              <Size>128</Size>
            </CreatePartition>
            <!-- Microsoft reserved partition (MSR) -->
            <CreatePartition wcm:action="add">
              <Order>3</Order>
              <Type>MSR</Type>
              <Size>128</Size>
            </CreatePartition>
            <!-- Windows partition -->
            <CreatePartition wcm:action="add">
              <Order>4</Order>
              <Type>Primary</Type>
              <Extend>true</Extend>
            </CreatePartition>
          </CreatePartitions>
          <ModifyPartitions>
            <!-- Windows RE Tools partition -->
            <ModifyPartition wcm:action="add">
              <Order>1</Order>
              <PartitionID>1</PartitionID>
              <Label>WINRE</Label>
              <Format>NTFS</Format>
              <TypeID>DE94BBA4-06D1-4D40-A16A-BFD50179D6AC</TypeID>
            </ModifyPartition>
            <!-- System partition (ESP) -->
            <ModifyPartition wcm:action="add">
              <Order>2</Order>
              <PartitionID>2</PartitionID>
              <Label>System</Label>
              <Format>FAT32</Format>
            </ModifyPartition>
            <!-- MSR partition does not need to be modified -->
            <ModifyPartition wcm:action="add">
              <Order>3</Order>
              <PartitionID>3</PartitionID>
            </ModifyPartition>
            <!-- Windows partition -->
              <ModifyPartition wcm:action="add">
              <Order>4</Order>
              <PartitionID>4</PartitionID>
              <Label>Windows</Label>
              <Letter>C</Letter>
              <Format>NTFS</Format>
            </ModifyPartition>
          </ModifyPartitions>
        </Disk>
      </DiskConfiguration>
      <DynamicUpdate>
        <Enable>true</Enable>
        <WillShowUI>Never</WillShowUI>
      </DynamicUpdate>
      <ImageInstall>
        <OSImage>
          <InstallTo>
            <DiskID>0</DiskID>
            <PartitionID>4</PartitionID>
          </InstallTo>
          <InstallToAvailablePartition>false</InstallToAvailablePartition>
        </OSImage>
      </ImageInstall>
      <RunSynchronous>
        <RunSynchronousCommand wcm:action="add">
          <Order>1</Order>
          <Path>reg add HKLM\System\Setup\LabConfig /v BypassCPUCheck /t REG_DWORD /d 0x00000001 /f</Path>
        </RunSynchronousCommand>
        <RunSynchronousCommand wcm:action="add">
          <Order>2</Order>
          <Path>reg add HKLM\System\Setup\LabConfig /v BypassRAMCheck /t REG_DWORD /d 0x00000001 /f</Path>
        </RunSynchronousCommand>
        <RunSynchronousCommand wcm:action="add">
          <Order>3</Order>
          <Path>reg add HKLM\System\Setup\LabConfig /v BypassSecureBootCheck /t REG_DWORD /d 0x00000001 /f</Path>
        </RunSynchronousCommand>
        <RunSynchronousCommand wcm:action="add">
          <Order>4</Order>
          <Path>reg add HKLM\System\Setup\LabConfig /v BypassTPMCheck /t REG_DWORD /d 0x00000001 /f</Path>
        </RunSynchronousCommand>
      </RunSynchronous>
      <UpgradeData>
        <Upgrade>false</Upgrade>
        <WillShowUI>Never</WillShowUI>
      </UpgradeData>
      <UserData>
        <AcceptEula>true</AcceptEula>
        <FullName>Quickemu</FullName>
        <Organization>Quickemu Project</Organization>
        <!-- https://docs.microsoft.com/en-us/windows-server/get-started/kms-client-activation-keys -->
        <ProductKey>
          <Key>W269N-WFGWX-YVC9B-4J6C9-T83GX</Key>
          <WillShowUI>Never</WillShowUI>
        </ProductKey>
      </UserData>
    </component>

    <component name="Microsoft-Windows-PnpCustomizationsWinPE" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" processorArchitecture="amd64" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <!--
           This makes the VirtIO drivers available to Windows, assuming that
           the VirtIO driver disk is available as drive E:
           https://github.com/virtio-win/virtio-win-pkg-scripts/blob/master/README.md
      -->
      <DriverPaths>
        <PathAndCredentials wcm:action="add" wcm:keyValue="1">
          <Path>E:\qemufwcfg\w10\amd64</Path>
        </PathAndCredentials>
        <PathAndCredentials wcm:action="add" wcm:keyValue="2">
          <Path>E:\vioinput\w10\amd64</Path>
        </PathAndCredentials>
        <PathAndCredentials wcm:action="add" wcm:keyValue="3">
          <Path>E:\vioscsi\w10\amd64</Path>
        </PathAndCredentials>
        <PathAndCredentials wcm:action="add" wcm:keyValue="4">
          <Path>E:\viostor\w10\amd64</Path>
        </PathAndCredentials>
        <PathAndCredentials wcm:action="add" wcm:keyValue="5">
          <Path>E:\vioserial\w10\amd64</Path>
        </PathAndCredentials>
        <PathAndCredentials wcm:action="add" wcm:keyValue="6">
          <Path>E:\qxldod\w10\amd64</Path>
        </PathAndCredentials>
        <PathAndCredentials wcm:action="add" wcm:keyValue="7">
          <Path>E:\amd64\w10</Path>
        </PathAndCredentials>
        <PathAndCredentials wcm:action="add" wcm:keyValue="8">
          <Path>E:\viogpudo\w10\amd64</Path>
        </PathAndCredentials>
        <PathAndCredentials wcm:action="add" wcm:keyValue="9">
          <Path>E:\viorng\w10\amd64</Path>
        </PathAndCredentials>
        <PathAndCredentials wcm:action="add" wcm:keyValue="10">
          <Path>E:\NetKVM\w10\amd64</Path>
        </PathAndCredentials>
        <PathAndCredentials wcm:action="add" wcm:keyValue="11">
          <Path>E:\viofs\w10\amd64</Path>
        </PathAndCredentials>
        <PathAndCredentials wcm:action="add" wcm:keyValue="12">
          <Path>E:\Balloon\w10\amd64</Path>
        </PathAndCredentials>
      </DriverPaths>
    </component>
  </settings>

  <settings pass="oobeSystem">
    <component name="Microsoft-Windows-Shell-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <AutoLogon>
        <Password>
          <Value>quickemu</Value>
          <PlainText>true</PlainText>
        </Password>
        <Enabled>true</Enabled>
        <Username>Quickemu</Username>
      </AutoLogon>
      <DisableAutoDaylightTimeSet>false</DisableAutoDaylightTimeSet>
      <OOBE>
        <HideEULAPage>true</HideEULAPage>
        <HideLocalAccountScreen>true</HideLocalAccountScreen>
        <HideOEMRegistrationScreen>true</HideOEMRegistrationScreen>
        <HideOnlineAccountScreens>true</HideOnlineAccountScreens>
        <HideWirelessSetupInOOBE>true</HideWirelessSetupInOOBE>
        <NetworkLocation>Home</NetworkLocation>
        <ProtectYourPC>3</ProtectYourPC>
        <SkipUserOOBE>true</SkipUserOOBE>
        <SkipMachineOOBE>true</SkipMachineOOBE>
        <VMModeOptimizations>
          <SkipWinREInitialization>true</SkipWinREInitialization>
        </VMModeOptimizations>
      </OOBE>
      <UserAccounts>
        <LocalAccounts>
          <LocalAccount wcm:action="add">
            <Password>
              <Value>quickemu</Value>
              <PlainText>true</PlainText>
            </Password>
            <Description>Quickemu</Description>
            <DisplayName>Quickemu</DisplayName>
            <Group>Administrators</Group>
            <Name>Quickemu</Name>
          </LocalAccount>
        </LocalAccounts>
      </UserAccounts>
      <RegisteredOrganization>Quickemu Project</RegisteredOrganization>
      <RegisteredOwner>Quickemu</RegisteredOwner>
      <FirstLogonCommands>
        <SynchronousCommand wcm:action="add">
          <CommandLine>msiexec /i E:\guest-agent\qemu-ga-x86_64.msi /quiet /passive /qn</CommandLine>
          <Description>Install Virtio Guest Agent</Description>
          <Order>1</Order>
        </SynchronousCommand>
        <SynchronousCommand wcm:action="add">
          <CommandLine>msiexec /i F:\spice-webdavd-x64-latest.msi /quiet /passive /qn</CommandLine>
          <Description>Install spice-webdavd file sharing agent</Description>
          <Order>2</Order>
        </SynchronousCommand>
        <SynchronousCommand wcm:action="add">
          <CommandLine>msiexec /i F:\UsbDk_1.0.22_x64.msi /quiet /passive /qn</CommandLine>
          <Description>Install usbdk USB sharing agent</Description>
          <Order>3</Order>
        </SynchronousCommand>
        <SynchronousCommand wcm:action="add">
          <CommandLine>msiexec /i F:\spice-vdagent-x64-0.10.0.msi /quiet /passive /qn</CommandLine>
          <Description>Install spice-vdagent SPICE agent</Description>
          <Order>4</Order>
        </SynchronousCommand>
        <SynchronousCommand wcm:action="add">
          <CommandLine>Cmd /c POWERCFG -H OFF</CommandLine>
          <Description>Disable Hibernation</Description>
          <Order>5</Order>
        </SynchronousCommand>
      </FirstLogonCommands>
    </component>
  </settings>
</unattend>
EOF


echo "Downloading Spice drivers..."
web_get https://www.spice-space.org/download/windows/spice-webdavd/spice-webdavd-x64-latest.msi "${VM_PATH}/unattended"
web_get https://www.spice-space.org/download/windows/vdagent/vdagent-win-0.10.0/spice-vdagent-x64-0.10.0.msi "${VM_PATH}/unattended"
web_get https://www.spice-space.org/download/windows/usbdk/UsbDk_1.0.22_x64.msi "${VM_PATH}/unattended"

echo "Making unattended.iso"
mkisofs -quiet -l -o "${VM_PATH}/unattended.iso" "${VM_PATH}/unattended/"
}

function handle_curl_error() {
    local error_code="$1"
    local fatal_error_action=2
    case "$error_code" in
        6)
            echo "Failed to resolve Microsoft servers! Is there an Internet connection? Exiting..."
            return "$fatal_error_action"
            ;;
        7)
            echo "Failed to contact Microsoft servers! Is there an Internet connection or is the server down?"
            ;;
        8)
            echo "Microsoft servers returned a malformed HTTP response!"
            ;;
        22)
            echo "Microsoft servers returned a failing HTTP status code!"
            ;;
        23)
            echo "Failed at writing Windows media to disk! Out of disk space or permission error? Exiting..."
            return "$fatal_error_action"
            ;;
        26)
            echo "Ran out of memory during download! Exiting..."
            return "$fatal_error_action"
            ;;
        36)
            echo "Failed to continue earlier download!"
            ;;
        63)
            echo "Microsoft servers returned an unexpectedly large response!"
            ;;
            # POSIX defines exit statuses 1-125 as usable by us
            # https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_08_02
            $((error_code <= 125)))
            # Must be some other server or network error (possibly with this specific request/file)
            # This is when accounting for all possible errors in the curl manual assuming a correctly formed curl command and an HTTP(S) request, using only the curl features we're using, and a sane build
            echo "Miscellaneous server or network error!"
            ;;
        126 | 127 )
            echo "Curl command not found! Please install curl and try again. Exiting..."
            return "$fatal_error_action"
            ;;
        # Exit statuses are undefined by POSIX beyond this point
        *)
            case "$(kill -l "$error_code")" in
            # Signals defined to exist by POSIX:
            # https://pubs.opengroup.org/onlinepubs/009695399/basedefs/signal.h.html
            INT)
                echo "Curl was interrupted!"
                ;;
            # There could be other signals but these are most common
            SEGV | ABRT )
                echo "Curl crashed! Failed exploitation attempt? Please report any core dumps to curl developers. Exiting..."
                return "$fatal_error_action"
                ;;
            *)
                echo "Curl terminated due to a fatal signal!"
                ;;
            esac
    esac
    return 1
}

function download_windows_server() {
    local iso_download_page_html=""
    # Copyright (C) 2024 Elliot Killick <contact@elliotkillick.com>
    # This function is adapted from the Mido project:
    # https://github.com/ElliotKillick/Mido

    # Download enterprise evaluation Windows versions
    local windows_version="$1"
    local enterprise_type="$2"
    local PRETTY_RELEASE=""

    case "${RELEASE}" in
        *) PRETTY_RELEASE="${RELEASE}";;
    esac

    echo "Downloading $(pretty_name "${OS}") ${PRETTY_RELEASE} (${I18N})"

    local url="https://www.microsoft.com/en-us/evalcenter/download-$windows_version"

    echo " - Parsing download page: ${url}"
    iso_download_page_html="$(curl --silent --location --max-filesize 1M --fail --proto =https --tlsv1.2 --http1.1 -- "$url")" || {
        handle_curl_error $?
        return $?
    }

    if ! [ "$iso_download_page_html" ]; then
        # This should only happen if there's been some change to where this download page is located
        echo " - Windows server download page gave us an empty response"
        return 1
    fi

    local CULTURE=""
    local COUNTRY=""
    case "${I18N}" in
        "English (Great Britain)")
            CULTURE="en-gb"
            COUNTRY="GB";;
        "Chinese (Simplified)")
            CULTURE="zh-cn"
            COUNTRY="CN";;
        "Chinese (Traditional)")
            CULTURE="zh-tw"
            COUNTRY="TW";;
        "French")
            CULTURE="fr-fr"
            COUNTRY="FR";;
        "German")
            CULTURE="de-de"
            COUNTRY="DE";;
        "Italian")
            CULTURE="it-it"
            COUNTRY="IT";;
        "Japanese")
            CULTURE="ja-jp"
            COUNTRY="JP";;
        "Korean")
            CULTURE="ko-kr"
            COUNTRY="KR";;
        "Portuguese (Brazil)")
            CULTURE="pt-br"
            COUNTRY="BR";;
        "Spanish")
            CULTURE="es-es"
            COUNTRY="ES";;
        "Russian")
            CULTURE="ru-ru"
            COUNTRY="RU";;
        *)
            CULTURE="en-us"
            COUNTRY="US";;
    esac

    echo " - Getting download link.."
    iso_download_links="$(echo "$iso_download_page_html" | grep -o "https://go.microsoft.com/fwlink/p/?LinkID=[0-9]\+&clcid=0x[0-9a-z]\+&culture=${CULTURE}&country=${COUNTRY}")" || {
        # This should only happen if there's been some change to the download endpoint web address
        echo " - Windows server download page gave us no download link"
        return 1
    }

    # Limit untrusted size for input validation
    iso_download_links="$(echo "$iso_download_links" | head -c 1024)"

    case "$enterprise_type" in
        # Select x64 download link
        "enterprise") iso_download_link=$(echo "$iso_download_links" | head -n 2 | tail -n 1) ;;
        # Select x64 LTSC download link
        "ltsc") iso_download_link=$(echo "$iso_download_links" | head -n 4 | tail -n 1) ;;
        *) iso_download_link="$iso_download_links" ;;
    esac

    # Follow redirect so proceeding log message is useful
    # This is a request we make this Fido doesn't
    # We don't need to set "--max-filesize" here because this is a HEAD request and the output is to /dev/null anyway
    iso_download_link="$(curl --silent --location --output /dev/null --silent --write-out "%{url_effective}" --head --fail --proto =https --tlsv1.2 --http1.1 -- "$iso_download_link")" || {
        # This should only happen if the Microsoft servers are down
        handle_curl_error $?
        return $?
    }

    # Limit untrusted size for input validation
    iso_download_link="$(echo "$iso_download_link" | head -c 1024)"

    echo " - URL: $iso_download_link"

    # Download ISO
    FILE_NAME="${iso_download_link##*/}"
    web_get "${iso_download_link}" "${VM_PATH}" "${FILE_NAME}"
    OS="windows-server"
}

function download_windows_workstation() {
    local HASH=""
    local session_id=""
    local iso_download_page_html=""
    local product_edition_id=""
    local language_skuid_table_json=""
    local sku_id=""
    local iso_download_link_json=""
    local iso_download_link=""

    echo "Downloading Windows ${RELEASE} (${I18N})"
    # This function is adapted from the Mido project:
    # https://github.com/ElliotKillick/Mido
    # Download newer consumer Windows versions from behind gated Microsoft API

    # Either 10, or 11
    local windows_version="$1"

    local url="https://www.microsoft.com/en-us/software-download/windows$windows_version"
    case "$windows_version" in
        10) url="${url}ISO";;
    esac

    local user_agent="Mozilla/5.0 (X11; Linux x86_64; rv:100.0) Gecko/20100101 Firefox/100.0"
    session_id="$(uuidgen)"

    # Get product edition ID for latest release of given Windows version
    # Product edition ID: This specifies both the Windows release (e.g. 22H2) and edition ("multi-edition" is default, either Home/Pro/Edu/etc., we select "Pro" in the answer files) in one number
    # This is the *only* request we make that Fido doesn't. Fido manually maintains a list of all the Windows release/edition product edition IDs in its script (see: $WindowsVersions array). This is helpful for downloading older releases (e.g. Windows 10 1909, 21H1, etc.) but we always want to get the newest release which is why we get this value dynamically
    # Also, keeping a "$WindowsVersions" array like Fido does would be way too much of a maintenance burden
    # Remove "Accept" header that curl sends by default
    echo " - Parsing download page: ${url}"
    iso_download_page_html="$(curl --silent --user-agent "$user_agent" --header "Accept:" --max-filesize 1M --fail --proto =https --tlsv1.2 --http1.1 -- "$url")" || {
        handle_curl_error $?
        return $?
    }

    echo -n " - Getting Product edition ID: "
    # tr: Filter for only numerics to prevent HTTP parameter injection
    # head -c was recently added to POSIX: https://austingroupbugs.net/view.php?id=407
    product_edition_id="$(echo "$iso_download_page_html" | grep -Eo '<option value="[0-9]+">Windows' | cut -d '"' -f 2 | head -n 1 | tr -cd '0-9' | head -c 16)"
    echo "$product_edition_id"

    echo " - Permit Session ID: $session_id"
    # Permit Session ID
    # "org_id" is always the same value
    curl --silent --output /dev/null --user-agent "$user_agent" --header "Accept:" --max-filesize 100K --fail --proto =https --tlsv1.2 --http1.1 -- "https://vlscppe.microsoft.com/tags?org_id=y6jn8c31&session_id=$session_id" || {
        # This should only happen if there's been some change to how this API works
        handle_curl_error $?
        return $?
    }

    local profile="606624d44113"

    echo -n " - Getting language SKU ID: "
    # Get language -> skuID association table
    language_skuid_table_json="$(curl -s --fail --max-filesize 100K --proto =https --tlsv1.2 --http1.1 "https://www.microsoft.com/software-download-connector/api/getskuinformationbyproductedition?profile=${profile}&ProductEditionId=${product_edition_id}&SKU=undefined&friendlyFileName=undefined&Locale=en-US&sessionID=${session_id}")" || {
        handle_curl_error $?
        return $?
    }

    sku_id="$(echo "${language_skuid_table_json}" | jq -r '.Skus[] | select(.LocalizedLanguage=="'"${I18N}"'").Id')"
    echo "$sku_id"

    echo " - Getting ISO download link..."
    # Get ISO download link
    # If any request is going to be blocked by Microsoft it's always this last one (the previous requests always seem to succeed)
    # --referer: Required by Microsoft servers to allow request
    iso_download_link_json="$(curl -s --fail --referer "$url" "https://www.microsoft.com/software-download-connector/api/GetProductDownloadLinksBySku?profile=${profile}&productEditionId=undefined&SKU=${sku_id}&friendlyFileName=undefined&Locale=en-US&sessionID=${session_id}")"

    local failed=0

    if ! [ "$iso_download_link_json" ]; then
        # This should only happen if there's been some change to how this API works
        echo " - Microsoft servers gave us an empty response to our request for an automated download."
        failed=1
    fi

    if echo "$iso_download_link_json" | grep -q "Sentinel marked this request as rejected."; then
        echo " - WARNING! Microsoft blocked the automated download request based on your IP address."
        failed=1
    fi

    if [ ${failed} -eq 1 ]; then
        echo "   Manually download the Windows ${windows_version} ISO using a web browser from: ${url}"
        echo "   Save the downloaded ISO to: $(realpath "${VM_PATH}")"
        echo "   Update the config file to reference the downloaded ISO: ./${VM_PATH}.conf"
        echo "   Continuing with the VM creation process..."
        return 1
    fi

    # Filter for 64-bit ISO download URL
    iso_download_link="$(echo "${iso_download_link_json}" | jq -r '.ProductDownloadOptions[].Uri' | grep x64)"

    if ! [ "$iso_download_link" ]; then
        # This should only happen if there's been some change to the download endpoint web address
        echo " - Microsoft servers gave us no download link to our request for an automated download. Please manually download this ISO in a web browser: $url"
        return 1
    fi

    echo " - URL: ${iso_download_link%%\?*}"

    # Download ISO
    FILE_NAME="$(echo "$iso_download_link" | cut -d'?' -f1 | cut -d'/' -f5)"
    web_get "${iso_download_link}" "${VM_PATH}" "${FILE_NAME}"
}

function get_windows() {
    if [ "${OS}" == "windows-server" ]; then
        download_windows_server "windows-server-${RELEASE}"
    else
        download_windows_workstation "${RELEASE}"
    fi

    if [ "${OPERATION}" == "download" ]; then
        exit 0
    fi

    echo "Downloading VirtIO drivers..."
    web_get "https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/stable-virtio/virtio-win.iso" "${VM_PATH}"

    rm -f "${VM_PATH}/unattended.iso"
    case ${RELEASE} in
        10|11)
            unattended_windows "${VM_PATH}"
            ;;
    esac

    if [ -n "${FILE_NAME}" ]; then
        make_vm_config "${FILE_NAME}" "virtio-win.iso"
    else
        make_vm_config "windows-${RELEASE}.iso" "virtio-win.iso"
    fi
}

function open_homepage() {
    local URL=""
    local XDG_OPEN=""
    if [ -z "$(os_info "${1}")" ]; then
        error_specify_os
    else
        URL="$(os_info "${1}" | cut -d'|' -f 3)"
        # shellcheck disable=SC2034
        XDG_OPEN=$(xdg-open "${URL}" || sensible-browser "${URL}" || x-www-browser "${URL}" || gnome-open "${URL}")
        exit 0
    fi
}

function create_vm() {
    # shellcheck disable=SC2206
    local URL_HASH=(${1// / })
    local URL="${URL_HASH[0]}"
    local HASH="${URL_HASH[1]}"
    local ISO="${URL##*/}"
    #echo "${URL}"
    #echo "${ISO}"
    #echo "${HASH}"
    web_get "${URL}" "${VM_PATH}"
    if [ -n "${HASH}" ]; then
        check_hash "${ISO}" "${HASH}"
    fi

    case "${OS}" in
        batocera)
            if [[ ${ISO} = *".gz"* ]]; then
                gzip -d "${VM_PATH}/${ISO}"
                ISO="${ISO/.gz/}"
            fi;;
        dragonflybsd)
            #  Could be other OS iso files compressed with bzip2 or gzip
            #  but for now we'll keep this to know cases
            if [[ ${ISO} = *".bz2"* ]]; then
                bzip2 -d  "${VM_PATH}/${ISO}"
                ISO="${ISO/.bz2/}"
            fi;;
        easyos)
            if [[ ${ISO} = *".img"* ]]; then
                ${QEMU_IMG} convert -f raw -O qcow2 "${VM_PATH}/${ISO}" "${VM_PATH}/disk.qcow2"
                ISO="${ISO/.img/}"
            fi;;
        freedos)
            if [[ ${ISO} = *".zip"* ]]; then
                unzip -qo "${VM_PATH}/${ISO}" -d "${VM_PATH}"
                rm -f "${VM_PATH}/${ISO}"
                ISO="$(ls -1 "${VM_PATH}/"*.iso)"
                ISO="$(basename "${ISO}")"
            fi;;
        kolibrios)
            if [[ ${ISO} = *".7z" ]]; then
                if [ -z "$(command -v 7z)" ]; then echo "ERROR! '7zip' needs installing. Unable to extract file."
                else
                    7z e "${VM_PATH}/${ISO}" -o"${VM_PATH}" >/dev/null 2>&1
                    rm -f "${VM_PATH}/${ISO}"
                    ISO="$(ls -1 "${VM_PATH}/"*.iso)"
                    ISO="$(basename "${ISO}")"
                fi
            fi;;
        reactos)
            if [[ ${ISO} = *".zip"* ]]; then
                unzip -qo "${VM_PATH}/${ISO}" -d "${VM_PATH}"
                rm -f "${VM_PATH}/${ISO}"
                ISO="$(ls -1 "${VM_PATH}/"*.iso)"
                ISO="$(basename "${ISO}")"
            fi;;
    esac
    make_vm_config "${ISO}"
}

function create_config() {
    local VM_PATH="${1}"
    local INPUT="${2}"
    local FIXED_ISO=""

    OS="custom"
    if ! mkdir "${VM_PATH}" 2>/dev/null; then
        echo "ERROR! Could not create directory: ${VM_PATH}. Please verify that it does not already exist"
        exit 1
    fi
    if [[ "${INPUT}" == "http://"* ]] || [[ "${INPUT}" == "https://"* ]]; then
        INPUT="$(web_redirect "${INPUT}")"
        if [[ "${INPUT}" == *".iso" ]] || [[ "${INPUT}" == *".img" ]]; then
            web_get "${INPUT}" "${VM_PATH}"
            INPUT="${INPUT##*/}"
        else
            echo "ERROR! Only ISO,IMG and QCOW2 file types are supported for --create-config"
            exit 1
        fi
    fi

    if [ ! -f "${INPUT}" ]; then
        echo "ERROR! The input must be a valid URL or path to an ISO, IMG, or QCOW2 file."
        exit 1
    elif [[ "${INPUT}" == *".iso" ]]; then
        echo "Moving image to VM dir" && mv "${INPUT}" "${VM_PATH}"
        CUSTOM_IMAGE_TYPE="iso"
    elif [[ "${INPUT}" == *".img" ]]; then
        echo "Moving image to VM dir" && mv "${INPUT}" "${VM_PATH}"
        CUSTOM_IMAGE_TYPE="img"
    elif [[ "${INPUT}" == *".qcow2" ]]; then
        echo "Moving image to VM dir" && mv "${INPUT}" "${VM_PATH}/disk.qcow2"
        CUSTOM_IMAGE_TYPE="qcow2"
    else
        echo "ERROR! Only ISO,IMG and QCOW2 file types are supported for --create-config"
        exit 1
    fi
    INPUT="$(basename "${INPUT}")"

    echo "Creating custom VM config for ${INPUT##*/}."
    case "${INPUT,,}" in
        *freebsd*) CUSTOM_OS="freebsd";;
        *kolibrios*) CUSTOM_OS="kolibrios";;
        *reactos*) CUSTOM_OS="reactos";;
        *windows-server*|*eval_oemret_x*|*eval_x*) CUSTOM_OS="windows-server";;
        *windows*|win*)
            CUSTOM_OS="windows"
            # Older windows 10 ISOs use the year followed by the month rather than the year & half). Match any text for language.
            if [ "${3}" != "--disable-unattended" ] && ( [ "${3}" == "--unattended" ] || grep -E -q 'Win(10|11)_([0-9]{2}H(1|2)|[0-9]{4})_[^.]*?(x64|x32)(v[0-9])?.iso' <<< "${INPUT}" ); then
                echo "Creating unattended Windows installation files. To disable, pass --disable-unattended"
                echo
                echo "Downloading VirtIO drivers..."
                web_get "https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/stable-virtio/virtio-win.iso" "${VM_PATH}"
                FIXED_ISO="virtio-win.iso"
                rm -f "${VM_PATH}/unattended.iso"
                unattended_windows "${VM_PATH}"
            fi
            ;;

        *) CUSTOM_OS="linux";;
    esac
    echo -e "Selecting OS: ${CUSTOM_OS}. If this is incorrect, please modify the config file to include the correct OS.\n"
    make_vm_config "${INPUT}" "${FIXED_ISO}"
}

# Use command -v command to check if quickemu is in the system's PATH and
# fallback to checking if quickemu is in the current directory.
function resolve_quickemu() {
    command -v quickemu || \
    if [ -x "./quickemu" ]; then
        echo "$(pwd)/quickemu"
    else
        echo "quickemu not found" >&2
        exit 1
    fi
}

function help_message() {
    #shellcheck disable=SC2016
    printf '
             _      _              _
  __ _ _   _(_) ___| | ____ _  ___| |_
 / _` | | | | |/ __| |/ / _` |/ _ \ __|
| (_| | |_| | | (__|   < (_| |  __/ |_
 \__, |\__,_|_|\___|_|\_\__, |\___|\__|
    |_|                 |___/ v%s, using curl %s
--------------------------------------------------------------------------------
 Project - https://github.com/quickemu-project/quickemu
 Discord - https://wimpysworld.io/discord
--------------------------------------------------------------------------------

Usage:
  quickget <os> <release> [edition]
  quickget ubuntu 22.04

Advanced usage:
  quickget <arg> [path] <os> [release] [edition]
  quickget --download ubuntu 22.04

Arguments:
  --download      <os> <release> [edition] : Download image; no VM configuration
  --create-config <os> [path/url] [flags]  : Create VM config for an OS image
  --open-homepage <os>                     : Open homepage for the OS
  --show          [os]                     : Show OS information
  --version                                : Show version
  --help                                   : Show this help message
------------------------------------ Flags -------------------------------------
--create-config:
  --disable-unattended                     : Force quickget not to set up an unattended installation
-------------------------- For testing & development ---------------------------
  --url           [os] [release] [edition] : Show image URL(s)
  --check         [os] [release] [edition] : Check image URL(s)
  --list                                   : List all supported systems
  --list-csv                               : List everything in csv format
  --list-json                              : List everything in json format
--------------------------------------------------------------------------------

Supported Operating Systems:\n\n' "$(${QUICKEMU} --version)" "${CURL_VERSION}"
    os_support | fmt -w 80
}

trap cleanup EXIT

if ((BASH_VERSINFO[0] < 4)); then
    echo "Sorry, you need bash 4.0 or newer to run this script."
    exit 1
fi

QUICKEMU=$(resolve_quickemu)
I18NS=()
OPERATION=""
CURL=$(command -v curl)
if [ ! -x "${CURL}" ]; then
    echo "ERROR! curl not found. Please install curl"
    exit 1
fi
CURL_VERSION=$("${CURL}" --version | head -n 1 | cut -d' ' -f2)

QEMU_IMG=$(command -v qemu-img)
if [ ! -x "${QEMU_IMG}" ]; then
    echo "ERROR! qemu-img not found. Please make sure qemu-img is installed."
    exit 1
fi

#TODO: Deprecate `list`, `list_csv`, and `list_json` in favor of `--list`, `--list-csv`, and `--list-json`
case "${1}" in
    --download|-download)
        OPERATION="download"
        shift
        ;;
    --create-config|-create-config)
        OPERATION="config"
        shift
        create_config "${@}"
        ;;
    --open-homepage|-open-homepage)
        shift
        open_homepage "${1}"
        ;;
    --show|-show)
        shift
        if [ -z "${1}" ]; then
            for OS in $(os_support); do
                show_os_info "${OS}"
            done
        else
            show_os_info "${1}"
        fi
        exit 0;;
    --version|-version)
        WHERE=$(dirname "${BASH_SOURCE[0]}")
        "${WHERE}/quickemu" --version
        exit 0;;
    --help|-help|--h|-h)
        help_message
        exit 0;;
    --url|-url)
        OPERATION="show"
        shift
        if [ -z "${1}" ]; then
            for OS in $(os_support); do
                (test_all "${OS}")
            done
            exit 0
        elif [ -z "${2}" ]; then
            test_all "${1}"
            exit 0
        fi;;
    --check|-check)
        OPERATION="test"
        shift
        if [ -z "${1}" ]; then
            for OS in $(os_support); do
                (test_all "${OS}")
            done
            exit 0
        elif [ -z "${2}" ]; then
            test_all "${1}"
            exit 0
        fi;;
    --list-csv|-list-csv|list|list_csv) list_csv;;
    --list-json|-list-json|list_json) list_json;;
    --list|-list) list_supported;;
    -*) error_not_supported_argument;;
esac

if [ -n "${1}" ]; then
    OS="${1,,}"
else
    error_specify_os
fi

os_supported

if [ -n "${2}" ]; then
    RELEASE="${2}"
    VM_PATH="${OS}-${RELEASE}"
    # If the OS has an editions_() function, use it.
    if [[ $(type -t "editions_${OS}") == function ]]; then
        validate_release "releases_${OS}"
        EDITIONS=("$(editions_"${OS}")")
        if [ -n "${3}" ]; then
            EDITION="${3}"
            if [[ ! "${EDITIONS[*]}" = *"${EDITION}"* ]]; then
                echo -e "ERROR! ${EDITION} is not a supported $(pretty_name "${OS}") edition\n"
                echo -n ' - Supported editions: '
                for EDITION in "${EDITIONS[@]}"; do
                    echo -n "${EDITION} "
                done
                echo ""
                exit 1
            fi
        else
            show_os_info "${OS}"
            echo -e " - Editions:\t$("editions_${OS}" | fmt -w 80)"
            echo -e "\nERROR! You must specify an edition."
            exit 1
        fi
        handle_missing
        VM_PATH="${OS}-${RELEASE}-${EDITION}"
        create_vm "$("get_${OS}" "${EDITION}")"
    elif [ "${OS}" == "macos" ]; then
        # macOS doesn't use create_vm()
        validate_release releases_macos
        get_macos
    elif [[ "${OS}" == *"ubuntu-server"* ]]; then
        # (Comes before regular Ubuntu, or the code tries to download the desktop) #
        # Ubuntu doesn't use create_vm()
        validate_release releases_ubuntu-server
        get_ubuntu-server
    elif [[ "${OS}" == *"ubuntu"* ]]; then
        # Ubuntu doesn't use create_vm()
        validate_release releases_ubuntu
        get_ubuntu
    elif [[ "${OS}" == "windows"* ]]; then
        I18N="English International"
        "languages_${OS}"
        if [ -n "${3}" ]; then
            I18N="${3}"
            if [[ ! "${I18NS[*]}" = *"${I18N}"* ]]; then
                error_not_supported_lang
            fi
            VM_PATH="$(echo "${OS}-${RELEASE}-${I18N// /-}" | tr -d '()')"
        fi
        validate_release "releases_${OS}"
        get_windows
    else
        validate_release "releases_${OS}"
        create_vm "$("get_${OS}")"
    fi
else
    error_specify_release
fi

# vim:tabstop=4:shiftwidth=4:expandtab