File: make-sqldeveloper-package

package info (click to toggle)
sqldeveloper-package 0.5.4
  • links: PTS, VCS
  • area: contrib
  • in suites: bookworm, bullseye, buster, sid
  • size: 188 kB
  • sloc: sh: 2,783; makefile: 2
file content (3327 lines) | stat: -rwxr-xr-x 115,704 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
#!/bin/sh
set -e

# make-sqldeveloper-package

# (2018-01-11)

# Copyright © 2009-2018 Lazarus Long <lazarus (dot) long (at) sapo (dot) pt>

##########################################################################
#  This program is free software: you can redistribute it and/or modify  #
#  it under the terms of the GNU General Public License as published by  #
#  the Free Software Foundation, either version 3 of the License, or     #
#  (at your option) any later version.                                   #
#                                                                        #
#  This program is distributed in the hope that it will be useful,       #
#  but WITHOUT ANY WARRANTY; without even the implied warranty of        #
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         #
#  GNU General Public License for more details.                          #
#                                                                        #
#  You should have received a copy of the GNU General Public License     #
#  along with this program.  If not, see <http://www.gnu.org/licenses/>. #
##########################################################################

# Debian package builder and installer for Oracle SQL Developer

#DEBUG=1
#VERBOSE=1

PATH="/usr/bin:/bin:/usr/sbin:/sbin"

if [ ${DEBUG:=0} -ne 0 ] ; then
	trap
	set -x
fi

VERSION="0.5.4"
DESC="Debian package builder and installer for Oracle SQL Developer"
AUTHOR="Lazarus Long"
COPYRIGHT="2009-2018"

ITP=515233
PROGNAME="sqldeveloper"
HOMEPAGE="http://www.oracle.com/technetwork/developer-tools/sql-developer/"


BASENAME="basename"
BUNZIP2="bunzip2"
CAT="cat"
CHMOD="chmod"
CONVERT="convert"
CP="cp"
CUT="cut"
DATE="date"
DEBUILD="debuild"
DPKG="dpkg"
DPKG_ARCHITECTURE="dpkg-architecture"
DPKG_QUERY="dpkg-query"
EXPR="expr"
FILE="file"
FIND="find"
FOLD="fold"
FROMDOS="fromdos"
GETOPT="getopt"
GREP="grep"
GUNZIP="gunzip"
HOSTNAME="hostname"
LN="ln"
LS="ls"
MKDIR="mkdir"
MKTEMP="mktemp"
MV="mv"
OBJDUMP="objdump"
RM="rm"
RMDIR="rmdir"
SED="sed"
TAR="tar"
TOUCH="touch"
TR="tr"
TRUE="true"
UNXZ="unxz"
UNZIP="unzip"
XARGS="xargs"

GREP_OPTS="-E"
MKDIR_OPTS="-p"
SED_OPTS="-e"

DEBFULLNAME=${DEBFULLNAME:=""}
DEBEMAIL=${DEBEMAIL:="${USER}@$(${HOSTNAME})"}
STANDARDS="4.1.3"

USRDIR="usr"
INSTDIR="${USRDIR}/share"
LIBSDIR="${USRDIR}/lib"
CURDIR="${PWD}"
HOSTARCH="$(${DPKG_ARCHITECTURE} -qDEB_HOST_ARCH)"
INVOCATION="$(${BASENAME} "${0}")"

SILENT=0

RM_OPTS_FUNC_TRAP="-rf"

# Cleanup at exit
#
func_exit() {
	if [ ${DEBUG} -ne 0 ] ; then
		trap
		set +x
	fi
}

# Trap interrupt signals
#
func_break() {
	func_exit
}

# Trap events
#
func_trap() {
	trap func_exit 0

	if [ ${DEBUG} -eq 0 ] ; then
		trap func_break HUP INT QUIT ABRT
	fi
}

# Display a header for the program
#
func_header() {
	if [ ${SILENT} -eq 0 ] ; then
		printf "%s %s Copyright © %s %s\n%s\n\n" "${INVOCATION}" "${VERSION}" "${COPYRIGHT}" "${AUTHOR}" "${DESC}"
	fi

	return 0
}

# Display the program version
#
func_version() {
	printf "%s %s\n" "${INVOCATION}" "${VERSION}"

	if [ ${SILENT} -eq 0 ] ; then
		printf "\nCopyright © %s %s\nLicense GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.\nThis is free software: you are free to change and redistribute it.\nThere is NO WARRANTY, to the extent permitted by law.\n\nWritten by %s.\n" "${COPYRIGHT}" "${AUTHOR}" "${AUTHOR}"
	fi

	return 0
}

# Display the program help
#
func_help() {
	func_header
	HELP_MSG="Usage:\t${INVOCATION} [options] <file>\n\nOptions:\n\t-b|--build-dir <dir>\n\t\tbase directory to build package(s) (autogenerated)\n\t-e|--email <email>\n\t\tlocal maintainer email (use DEBEMAIL or auto-generate)\n\t-i|--install\n\t\tinstall the generated package(s) - needs root privilege (no)\n\t-k|--keep-dir\n\t\tkeep the build directory (no)\n\t-l|--revision <number>\n\t\tlocal revision to append to package version (1)\n\t-m|--maintainer <name>\n\t\tlocal maintainer name (use DEBFULLNAME or leave empty)\n\t-q|--quiet\n\t\tsuppress normal output (no)\n\t-r|--root-command <command>\n\t\tcommand to gain root privilege for package build (fakeroot)\n\t-s|--skip-libraries\n\t\tskip building the shared libraries package(s) (no)\n\t-u|--upstream-version <version>\n\t\tforce the upstream version (autodetected)\n\t-x|--extract-only\n\t\tprepare build tree, do not build package(s) [implies -k|--keep-dir] (no)\n\t-h|--help\n\t\tdisplay this help screen\n\t-v|--version\n\t\tshow the program version (${VERSION})\n\n\t<file>\n\t\tthe \"Oracle SQL Developer for other platforms\" archive\n\t\tfrom <${HOMEPAGE}>"
	printf "%b\n" "${HELP_MSG}"
	return 0
}

# Parse the command line options
#
func_opts() {
	local GETOPT_OPTS="-o hb:e:ikl:m:qr:su:vx -l help,build-dir:,email:,install,keep-dir,revision:,maintainer:,quiet,root-command:,skip-libraries,upstream-version:,version,extract-only -s sh"
	local GETOPT_RUN="$(${GETOPT} ${GETOPT_OPTS} -n ${INVOCATION} -- "${@}")"
	INSTALL=0
	KEEPDIR=0
	NOBUILD=0
	SKIPLIB=0

	if [ ${?} -ne 0 ] ; then
		func_header >&2

		if [ ${SILENT} -eq 0 ] ; then
			printf  "Error parsing command line, terminating...\n" >&2
		else
			printf  "%s: Error parsing command line, terminating...\n" "${INVOCATION}" >&2
		fi

		exit 1
	fi
	eval set -- "${GETOPT_RUN}"

	while $(${TRUE}) ; do
		case "${1}" in
			-h|--help)
				func_help
				exit 0
			;;
			-b|--build-dir)
				WORKDIR="${2}"
				shift 2
			;;
			-e|--email)
				DEBEMAIL="${2}"
				shift 2
			;;
			-i|--install)
				INSTALL=1
				shift
			;;
			-k|--keep-dir)
				KEEPDIR=1
				shift
			;;
			-l|--revision)
				LOCALVER="${2}"
				shift 2
			;;
			-m|--maintainer)
				DEBFULLNAME="${2}"
				shift 2
			;;
			-q|--quiet)
				SILENT=1
				shift
			;;
			-r|--root-command)
				ROOTCMD="${2}"
				shift 2
			;;
			-s|--skip-libraries)
				SKIPLIB=1
				shift
			;;
			-u|--upstream-version)
				UPSTREAMVER="${2}"
				shift 2
			;;
			-v|--version)
				func_version
				exit 0
			;;
			-x|--extract-only)
				KEEPDIR=1
				NOBUILD=1
				shift
			;;
			--)
				shift
				break
			;;
			*)
				func_header >&2

				if [ ${SILENT} -eq 0 ] ; then
					printf  "Unknown option \"%s\" or internal error, terminating...\n" "${1}" >&2
				else
					printf  "%s: Unknown option \"%s\" or internal error, terminating...\n" "${INVOCATION}" "${1}" >&2
				fi

				exit 1
			;;
		esac
	done

	if [ ${#} -lt 1 ] ; then
		func_header >&2

		if [ ${SILENT} -eq 0 ] ; then
			printf "Missing command line parameter, use \"-h\" or \"--help\" for syntax, terminating...\n" >&2
		else
			printf "%s: Missing command line parameter, use \"-h\" or \"--help\" for syntax, terminating...\n" "${INVOCATION}" >&2
		fi

		exit 1
	elif [ ${#} -gt 1 ] ; then
		func_header >&2

		if [ ${SILENT} -eq 0 ] ; then
			printf "Extra command line parameter, use \"-h\" or \"--help\" for syntax, terminating...\n" >&2
		else
			printf "%s: Extra command line parameter, use \"-h\" or \"--help\" for syntax, terminating...\n" "${INVOCATION}" >&2
		fi

		exit 1
	else
		ARCHIVE="${1}"

		if ! [ -f "${ARCHIVE}" ] ; then
			func_header

			if [ ${SILENT} -eq 0 ] ; then
				printf "\"%s\" not found, aborting...\n" "${ARCHIVE}" >&2
			else
				printf "%s: \"%s\" not found, aborting...\n" "${INVOCATION}" "${ARCHIVE}" >&2
			fi

			exit 1
		fi
	fi

	return 0
}

# Indicate active flags
#
func_flags() {
	if [ ${SILENT} -eq 0 ] ; then
		local COUNT=0
		printf "Environment variables are:\n\tDEBFULLNAME=\"%s\"\n\tDEBEMAIL=\"%s\"\nActive flags are:" "${DEBFULLNAME}" "${DEBEMAIL}"

		if [ ${INSTALL} -ne 0 ] ; then
			COUNT=$((${COUNT} + 1))
			printf " -i|--install"
		fi

		if [ ${KEEPDIR} -ne 0 ] ; then
			COUNT=$((${COUNT} + 1))
			printf " -k|--keep-dir"
		fi

		if [ ${SKIPLIB} -ne 0 ] ; then
			COUNT=$((${COUNT} + 1))
			printf " -s|--skip-libraries"
		fi

		if [ ${NOBUILD} -ne 0 ] ; then
			COUNT=$((${COUNT} + 1))
			printf " -x|--extract-only"
		fi

		if [ ${COUNT} -eq 0 ] ; then
			printf " (none)"
		fi

		printf "\n"
	fi

	return 0
}

# Setup the work directory
#
func_workdir() {
	if [ -z "${WORKDIR}" ] ; then
		local MKTEMP_OPTS_FUNC_WORKDIR="-d"

		WORKDIR="$(${MKTEMP} ${MKTEMP_OPTS_FUNC_WORKDIR})" || {
			if [ ${SILENT} -eq 0 ] ; then
				printf "\nUnable to create the work directory, aborting...\n" >&2
			else
				printf "%s: Unable to create the work directory, aborting...\n" "${INVOCATION}" >&2
			fi

			exit 1
		}

		if [ ${SILENT} -eq 0 ] ; then
			printf "Creating work directory \"%s\" ... " "${WORKDIR}"
		fi
	else
		if [ ${SILENT} -eq 0 ] ; then
			printf "Creating work directory \"%s\" ... " "${WORKDIR}"
		fi

		if ! [ -d "${WORKDIR}" ] ; then
			if [ -e "${WORKDIR}" ] ; then
				if [ ${SILENT} -eq 0 ] ; then
					printf "\n\"%s\" already exists and isn't a directory, aborting...\n" "${WORKDIR}" >&2
				else
					printf "%s: \"%s\" already exists and isn't a directory, aborting...\n" "${INVOCATION}" "${WORKDIR}" >&2
				fi

				exit 1
			fi

			${MKDIR} ${MKDIR_OPTS} "${WORKDIR}"
		else
			local DIRTEST="$(${LS} "${WORKDIR}")"

			if [ ${#DIRTEST} -ne 0 ] ; then
				if [ ${SILENT} -eq 0 ] ; then
					printf "\n\"%s\" is not empty, aborting...\n" "${WORKDIR}" >&2
				else
					printf "%s: \"%s\" is not empty, aborting...\n" "${INVOCATION}" "${WORKDIR}" >&2
				fi

				exit 1
			fi
		fi
	fi

	if [ ${KEEPDIR} -ne 1 ] ; then
		trap "${RM} ${RM_OPTS_FUNC_TRAP} ${WORKDIR}" EXIT HUP INT TRAP TERM
	fi

	WORKDIR="${WORKDIR}/${PROGNAME}"

	if [ ${SILENT} -eq 0 ] ; then
		printf "done!\n"
		printf "Creating build installation directory \"%s\" ... " "${WORKDIR}/${INSTDIR}"
	fi

	${MKDIR} ${MKDIR_OPTS} "${WORKDIR}/${INSTDIR}"

	if [ ${SILENT} -eq 0 ] ; then
		printf "done!\n"
	fi

	return 0
}

# Extract the archive to the work directory
#
func_extract() {
	if [ ${#} -ne 2 ] ; then
		printf "Usage: func_extract() <archive> <path for extraction>\n"
		return 1
	fi

	local BUNZIP2_OPTS_QUIET="-q ${1}"
	local BUNZIP2_OPTS_STDOUT="-c"
	local FILE_OPTS_FUNC_EXTRACT="-b -"
	local GUNZIP_OPTS_QUIET="${BUNZIP2_OPTS_QUIET}"
	local GUNZIP_OPTS_STDOUT="${BUNZIP2_OPTS_STDOUT}"
	local TAR_OPTS_FUNC_EXTRACT="xaf ${1} -C ${2}"
	local UNXZ_OPTS_QUIET="${BUNZIP2_OPTS_QUIET}"
	local UNXZ_OPTS_STDOUT="${BUNZIP2_OPTS_STDOUT}"
	local UNZIP_OPTS_FUNC_EXTRACT="-Xq ${1} -d ${2}"

	local EXTRACT=""
	local EXTRACT_OPTS=""
	local EXTRACT_OPTS_TST4TAR=""

	if [ ${SILENT} -eq 0 ] ; then
		printf "Extracting upstream archive \"%s\" to \"%s\" ... " "${1}" "${2}"
	fi

	local FILETYPE="$(${FILE} ${FILE_OPTS} "${1}")"

	printf "%s\n" "${FILETYPE}" |${GREP} ${GREP_OPTS} "Zip archive data" >/dev/null 2>&1 && {
		EXTRACT="${UNZIP}"
		EXTRACT_OPTS="${UNZIP_OPTS_FUNC_EXTRACT}"
	} || {
		printf "%s\n" "${FILETYPE}" |${GREP} ${GREP_OPTS} "gzip compressed data" >/dev/null 2>&1 && {
			EXTRACT="${GUNZIP}"
			EXTRACT_OPTS="${GUNZIP_OPTS_QUIET}"
			EXTRACT_OPTS_TST4TAR="${GUNZIP_OPTS_STDOUT}"
		} || {
			printf "%s\n" "${FILETYPE}" |${GREP} ${GREP_OPTS} "bzip2 compressed data" >/dev/null 2>&1 && {
				EXTRACT="${BUNZIP2}"
				EXTRACT_OPTS="${BUNZIP2_OPTS_QUIET}"
				EXTRACT_OPTS_TST4TAR="${BUNZIP2_OPTS_STDOUT}"
			} || {
				printf "%s\n" "${FILETYPE}" |${GREP} ${GREP_OPTS} "XZ compressed data" >/dev/null 2>&1 && {
					EXTRACT="${UNXZ}"
					EXTRACT_OPTS="${UNXZ_OPTS_QUIET}"
					EXTRACT_OPTS_TST4TAR="${UNXZ_OPTS_STDOUT}"
				} || {
					if [ ${SILENT} -eq 0 ] ; then
						printf "\nfunc_extract(): Unknown archive format for \"%s\", aborting...\n" "${1}" >&2
					else
						printf "%s - func_extract(): Unknown archive format for \"%s\" , aborting...\n" "${INVOCATION}" "${1}" >&2
					fi

					exit 1
				}
			}
		}
	}

	if [ ${#EXTRACT_OPTS_TST4TAR} -ne 0 ] ; then
		${EXTRACT} ${EXTRACT_OPTS_TST4TAR} "${1}" |${FILE} ${FILE_OPTS_FUNC_EXTRACT} |${GREP} ${GREP_OPTS} "tar archive" >/dev/null 2>&1 && {
			EXTRACT="${TAR}"
			EXTRACT_OPTS="${TAR_OPTS_FUNC_EXTRACT}"
		}
	fi

	${EXTRACT} ${EXTRACT_OPTS}

	if [ ${SILENT} -eq 0 ] ; then
		printf "done!\n"
	fi

	return 0
}

# Set the program version and modifies paths accordingly
#
func_upstreamversion() {
	if [ ${#} -ne 1 ] ; then
		printf "Usage: func_upstreamversion() <directory>\n"
		return 1
	fi

	local MV_OPTS_FUNC_UPVER="--strip-trailing-slashes"

	if [ ${SILENT} -eq 0 ] ; then
		printf "Obtaining upstream full version: "
	fi

	if ! [ -d "${1}" ] ; then
		if [ ${SILENT} -eq 0 ] ; then
			printf "\nfunc_upstreamversion(): Directory \"%s\" not found, aborting...\n" "${1}" >&2
		else
			printf "%s - func_upstreamversion(): Directory \"%s\" not found, aborting...\n" "${INVOCATION}" "${1}" >&2
		fi

		exit 1
	fi

	if [ -z "${UPSTREAMVER}" ] ; then
		local CUT_OPTS_FUNC_UPVER="-d = -f 2"
		local TR_OPTS_FUNC_UPVER="-d [[:space:]]"
		local VERSIONFILE="${1}/${INSTDIR}/${PROGNAME}/${PROGNAME}/bin/version.properties"

		if ! [ -e "${VERSIONFILE}" ] ; then
			VERSIONFILE="${1}/${INSTDIR}/${PROGNAME}/jdev/bin/version.properties"

			if ! [ -e "${VERSIONFILE}" ] ; then
				if [ ${SILENT} -eq 0 ] ; then
					printf "\nfunc_upstreamversion(): File \"%s\" not found, aborting...\n" "${VERSIONFILE}" >&2
				else
					printf "%s - func_upstreamversion(): File \"%s\" not found, aborting...\n" "${INVOCATION}" "${VERSIONFILE}" >&2
				fi

				exit 1
			fi
		fi

		UPSTREAMVER="$(${GREP} ${GREP_OPTS} "VER_FULL" "${VERSIONFILE}" |${CUT} ${CUT_OPTS_FUNC_UPVER} |${TR} ${TR_OPTS_FUNC_UPVER})"
	fi

	if [ ${SILENT} -eq 0 ] ; then
		printf "\"%s\" ... " "${UPSTREAMVER}"
	fi

	UPSTREAMVERMAJ="${UPSTREAMVER%%.*}"
	UPSTREAMVERMIN="${UPSTREAMVER#*.}"
	UPSTREAMVERREV="${UPSTREAMVERMIN#*.}"
	UPSTREAMVERMIN="${UPSTREAMVERMIN%%.*}"
	UPSTREAMVERREV="${UPSTREAMVERREV%%.*}"

	if [ -z "${LOCALVER}" ] ; then
		LOCALVER=1
	fi

	local OLDNAME="${WORKDIR}"
	WORKDIR="${WORKDIR}-${UPSTREAMVER}"

	if [ ${SILENT} -eq 0 ] ; then
		printf "done!\n"
		printf "Renaming the work directory \"%s\" to \"%s\" ... " "${OLDNAME}" "${WORKDIR}"
	fi

	${MV} ${MV_OPTS_FUNC_UPVER} "${OLDNAME}" "${WORKDIR}"

	if [ ${SILENT} -eq 0 ] ; then
		printf "done!\n"
	fi

	return 0
}

# Special case for SQL Developer first released version
#
func_firstver() {
	if [ ${#} -ne 1 ] ; then
		printf "Usage: func_firstver() <directory>\n"
		return 1
	fi

	if [ ${SILENT} -eq 0 ] ; then
		"Doing some first version special case house keeping ... "
	fi

	local CHMOD_OPTS_FUNC_1STVER="755"
	local MV_OPTS_FUNC_1STVER="--strip-trailing-slashes"
	local RM_OPTS_FUNC_1STVER="-rf"
	local TOUCH_OPTS_FUNC_1STVER="-r"
	local OPTDIR="${1}"

	if ! [ -d "${1}" ] ; then
		if [ ${SILENT} -eq 0 ] ; then
			printf "\nfunc_firstver(): Directory \"%s\" not found, aborting...\n" "${1}" >&2
		else
			printf "%s - func_firstver(): Directory \"%s\" not found, aborting...\n" "${INVOCATION}" "${1}" >&2
		fi

		exit 1
	fi

	if ! [ -f "${1}/${PROGNAME}" ] ; then
		if [ ${SILENT} -eq 0 ] ; then
			printf "\nfunc_firstver(): File \"%s/%s\" not found, this doesn't seem the first version, aborting...\n" "${1}" "${PROGNAME}" >&2
		else
			printf "%s - func_firstver(): File \"%s/%s\" not found, this doesn't seem the first version, aborting...\n" "${INVOCATION}" "${1}" "${PROGNAME}" >&2
		fi

		exit 1
	fi


	printf "%s\n" '#!/bin/sh' >"${OPTDIR}/${PROGNAME}.sh"
	${CAT} ${CAT_OPTS} "${OPTDIR}/${PROGNAME}" >>"${OPTDIR}/${PROGNAME}.sh" && ${CHMOD} ${CHMOD_OPTS_FUNC_1STVER} "${OPTDIR}/${PROGNAME}.sh"
	${TOUCH} ${TOUCH_OPTS_FUNC_1STVER} "${OPTDIR}/${PROGNAME}" "${OPTDIR}/${PROGNAME}.sh"
	${RM} ${RM_OPTS_FUNC_1STVER} "${OPTDIR}/${PROGNAME}"

	# Place holders
	${TOUCH} ${TOUCH_OPTS_FUNC_1STVER} "${OPTDIR}/jdev/lib/ext/README.TXT" "${OPTDIR}/jdev/lib/ext/.placeholder"
	${MV} ${MV_OPTS_FUNC_1STVER} "${OPTDIR}/jdev/lib/ext/README.TXT" "${WORKDIR}/usr/share/doc/${PROGNAME}/extensions.README.TXT"
	${TOUCH} ${TOUCH_OPTS_FUNC_1STVER} "${OPTDIR}/jdev/lib/patches/README.TXT" "${OPTDIR}/jdev/lib/patches/.placeholder"
	${MV} ${MV_OPTS_FUNC_1STVER} "${OPTDIR}/jdev/lib/patches/README.TXT" "${WORKDIR}/usr/share/doc/${PROGNAME}/patches.README.TXT"

	if [ ${SILENT} -eq 0 ] ; then
		printf "done!\n"
	fi

	return 0
}

# Reorganizes the work directory to comply with FHS
#
func_reorganize() {
	if [ ${#} -ne 1 ] ; then
		printf "Usage: func_reorganize() <directory>\n"
		return 1
	fi

	local CUT_OPTS_FN="-d : -f 1"
	local CUT_OPTS_LIB="-d - -f 2-"
	local GREP_OPTS_COUNT="${GREP_OPTS} -c"
	local LN_OPTS_FUNC_REORG="-s"
	local MV_OPTS_FUNC_REORG="--strip-trailing-slashes"
	local OBJDUMP_OPTS_FUNC_REORG="-p"

	if [ ${SILENT} -eq 0 ] ; then
		printf "Reorganizing the work directory \"%s\" to generate FSH compliant package(s) ... " "${1}"
	fi

	local OPTDIR="${1}/${INSTDIR}/${PROGNAME}"

	if ! [ -d "${OPTDIR}" ] ; then
		if [ ${SILENT} -eq 0 ] ; then
			printf "\nfunc_reorganize(): Directory \"%s\" not found, aborting...\n" "${OPTDIR}" >&2
		else
			printf "%s - func_reorganize(): Directory \"%s\" not found, aborting...\n" "${INVOCATION}" "${OPTDIR}" >&2
		fi

		exit 1
	fi

	if [ ${SKIPLIB} -eq 0 ] ; then
		local LIBWORKDIR="${1}/${LIBSDIR}"

		for Library in $(${FIND} "${OPTDIR}" ! \( -type d -o -name "*.jar" \) |${XARGS} ${XARGS_OPTS} ${FILE} ${FILE_OPTS} |${GREP} ${GREP_OPTS} "ELF (32|64)-bit LSB shared object" |${CUT} ${CUT_OPTS_FN}) ; do
			local ARCH="$(${OBJDUMP} ${OBJDUMP_OPTS_FUNC_REORG} ${Library} |${GREP} ${GREP_OPTS} "file format" |${SED} ${SED_OPTS} 's/^.*file format //' |${CUT} ${CUT_OPTS_LIB} |${TR} ${TR_OPTS} - _)"
			local SONAME="$(${OBJDUMP} ${OBJDUMP_OPTS_FUNC_REORG} ${Library} |${GREP} ${GREP_OPTS} "SONAME" |${SED} ${SED_OPTS} 's/^[[:space:]]*SONAME[[:space:]]*//')"
			SONAME=${SONAME##*/}
			local SERIAL="$(printf ${Library##*/} |${SED} ${SED_OPTS} 's/\.so*$//' |${CUT} ${CUT_OPTS_LIB})"
			local SOVERSION=""

			# Hack to avoid expr returning errorlevel 1 when substr finds a '0'
			if [ ${SERIAL} -eq 410 ] ; then
				SOVERSION=".4.1.0"
			elif [ ${SERIAL} -eq 422 ] ; then
				SOVERSION=".4.2.2"
			else
				local SIZE=0

				while [ ${SIZE} -lt ${#SERIAL} ] ; do
					SIZE=$((${SIZE}+1))
					SOVERSION="${SOVERSION}.$(${EXPR} ${EXPR_OPTS} substr ${SERIAL} ${SIZE} 1)"
				done
			fi

			if ! [ -d "${LIBWORKDIR}/${ARCH}-linux-gnu/${PROGNAME}/${UPSTREAMVER}" ] ; then
				${MKDIR} ${MKDIR_OPTS} "${LIBWORKDIR}/${ARCH}-linux-gnu/${PROGNAME}/${UPSTREAMVER}"
			fi

			${MV} ${MV_OPTS_FUNC_REORG} "${Library}" "${LIBWORKDIR}/${ARCH}-linux-gnu/${PROGNAME}/${UPSTREAMVER}/${SONAME}${SOVERSION}" && ${LN} ${LN_OPTS_FUNC_REORG} "${SONAME}${SOVERSION}" "${LIBWORKDIR}/${ARCH}-linux-gnu/${PROGNAME}/${UPSTREAMVER}/${SONAME}"

			if [ "${ARCH}" = "x86_64" ] ; then
				ARCH="amd64"
			fi

			if [ "${ARCH}" != "${HOSTARCH}" ] ; then
				LIBALTARCH="${ARCH}"
			fi

			if [ -f "${1}/libraries.csv" ] ; then
				if [ $(${GREP} ${GREP_OPTS_COUNT} "${SONAME}" "${1}/libraries.csv") -lt 1 ] ; then
					printf "${SONAME};${SOVERSION}\n" >>"${1}/libraries.csv"
				fi
			else
				printf "${SONAME};${SOVERSION}\n" >>"${1}/libraries.csv"
			fi
		done
	fi

	${MV} ${MV_OPTS_FUNC_REORG} "${OPTDIR}" "${1}/${INSTDIR}/${UPSTREAMVER}"
	${MKDIR} ${MKDIR_OPTS} "${OPTDIR}"
	${MV} ${MV_OPTS_FUNC_REORG} "${1}/${INSTDIR}/${UPSTREAMVER}" "${OPTDIR}"

	if [ ${SILENT} -eq 0 ] ; then
		printf "done!\n"
	fi

	return 0
}

# Cleans up the work direcory from cruft and binaries from other OS
#
func_cleanup() {
	if [ ${#} -ne 1 ] ; then
		printf "Usage: func_cleanup() <directory>\n"
		return 1
	fi

	if [ ${SILENT} -eq 0 ] ; then
		printf "Cleaning up work directory \"%s\" for compliant package(s) generation:\n" "${1}"
	fi

	local CHMOD_OPTS_EXEC="755"
	local CHMOD_OPTS_NOEXEC="644"
	local CUT_OPTS_FUNC_CLEAN="-d : -f 1"
	local MV_OPTS_FUNC_CLEAN="--strip-trailing-slashes"
	local RM_OPTS_FUNC_CLEAN="-rf"
	local RMDIR_OPTS_FUNC_CLEAN="-p --ignore-fail-on-non-empty"
	local SED_OPTS_INLINE="-i ${SED_OPTS}"
	local OPTDIR="${1}/${INSTDIR}/${PROGNAME}/${UPSTREAMVER}"
	FUNC_CLEAN_DOCS=""

	if ! [ -d "${OPTDIR}" ] ; then
		if [ ${SILENT} -eq 0 ] ; then
			printf "func_cleanup(): Directory \"%s\" not found, aborting...\n" "${OPTDIR}" >&2
		else
			printf "%s - func_cleanup(): Directory \"%s\" not found, aborting...\n" "${INVOCATION}" "${OPTDIR}" >&2
		fi

		exit 1
	fi

	# Deletes
	#
	if [ ${SILENT} -eq 0 ] ; then
		printf "\tdeleting foreign binaries"
	fi

	# Binaries from other OSs and Zip archives
	${FIND} "${OPTDIR}" ! \( -type d -o -iname "*.jar" \) |${XARGS} ${XARGS_OPTS} ${FILE} ${FILE_OPTS} |${GREP} ${GREP_OPTS} "PE32\+ executable|PE32 executable|MS-DOS batch|Zip archive data" |${CUT} ${CUT_OPTS_FUNC_CLEAN} |${XARGS} ${XARGS_OPTS} ${RM} ${RM_OPTS_FUNC_CLEAN}
	${FIND} "${OPTDIR}" ! -type d \( -iname "*.bat" \) |${XARGS} ${XARGS_OPTS} ${RM} ${RM_OPTS_FUNC_CLEAN}

	if [ ${SILENT} -eq 0 ] ; then
		printf ", image thumbnails and caches"
	fi

	# Image thumbnails and caches
	${FIND} "${OPTDIR}" ! -type d \( -iname "Thumbs.db" \) |${XARGS} ${XARGS_OPTS} ${RM} ${RM_OPTS_FUNC_CLEAN}

	if [ ${SILENT} -eq 0 ] ; then
		printf ", foreign configuration files"
	fi

	# Configuration files from other OSs
	${RM} ${RM_OPTS_FUNC_CLEAN} "${OPTDIR}/${PROGNAME}/bin/sqldeveloper-Darwin.conf"

	if [ ${SILENT} -eq 0 ] ; then
		printf ", source code"
	fi

	# Source-code
	${RM} ${RM_OPTS_FUNC_CLEAN} "${OPTDIR}/jdev/extensions/oracle.jdeveloper.subversion/svnClientAdapter-src.jar"

	if [ ${SILENT} -eq 0 ] ; then
		printf ", empty directories"
	fi

	# Empty directories
	${FIND} "${OPTDIR}" -type d -empty |${XARGS} ${XARGS_OPTS} ${RMDIR} ${RMDIR_OPTS_FUNC_CLEAN}

	if [ ${SILENT} -eq 0 ] ; then
		printf ", done!\n"
	fi

	# Fixes
	#
	if [ ${SILENT} -eq 0 ] ; then
		printf "\tfixing shebang lines"
	fi

	# Remove spaces and fix path from shebang line
	for f in $(${FIND} "${OPTDIR}" ! \( -type d -o -iname "*.jar" \) |${XARGS} ${XARGS_OPTS} ${FILE} ${FILE_OPTS} |${GREP} ${GREP_OPTS} "ASCII|Perl script" |${CUT} ${CUT_OPTS_FUNC_CLEAN} |${SED} ${SED_OPTS} 's/[[:space:]]/#/g') ; do
		${SED} ${SED_OPTS_INLINE} 's%^ #!%#!%1;s%^#!/usr/bin%#!/bin%1;s%^#!/usr/local%#!/usr%1' "$(printf "${f}\n" |${SED} ${SED_OPTS} 's/#/ /g')"
	done

	if [ ${SILENT} -eq 0 ] ; then
		printf ", executable bit"
	fi

	# Set executable bit
	${FIND} "${OPTDIR}" ! -type d -iname "*.jar" |${XARGS} ${XARGS_OPTS} ${CHMOD} ${CHMOD_OPTS_NOEXEC}
	${FIND} "${OPTDIR}" ! \( -type d -o -iname "*.jar" \) |${XARGS} ${XARGS_OPTS} ${FILE} ${FILE_OPTS} |${GREP} ${GREP_OPTS} "text executable" |${GREP} ${GREP_OPTS} "Perl script|shell script|/bin/ksh"|${CUT} ${CUT_OPTS_FUNC_CLEAN} |${XARGS} ${XARGS_OPTS} ${CHMOD} ${CHMOD_OPTS_EXEC}

	if [ ${SILENT} -eq 0 ] ; then
		printf ", done!\n"
	fi

	# Documentation
	#
	if [ ${SILENT} -eq 0 ] ; then
		printf "\tdocumenting demo files"
	fi

	${MKDIR} ${MKDIR_OPTS} "${WORKDIR}/usr/share/doc/${PROGNAME}-${UPSTREAMVER}"

	# Demo files
	if [ -d "${OPTDIR}/${PROGNAME}/demo" ] ; then
		${MV} ${MV_OPTS_FUNC_CLEAN} "${OPTDIR}/${PROGNAME}/demo" "${WORKDIR}/usr/share/doc/${PROGNAME}-${UPSTREAMVER}"
		FUNC_CLEAN_DOCS="demos ${FUNC_CLEAN_DOCS}"
	fi

	if [ ${SILENT} -eq 0 ] ; then
		printf ", theme templates"
	fi

	# Theme files
	if [ -d "${OPTDIR}/ide/themes" ] ; then
		${MKDIR} ${MKDIR_OPTS} "${WORKDIR}/usr/share/doc/${PROGNAME}-${UPSTREAMVER}/themes"
		${MV} ${MV_OPTS_FUNC_CLEAN} "${OPTDIR}/ide/themes/"*.html "${OPTDIR}/ide/themes/"*.png "${WORKDIR}/usr/share/doc/${PROGNAME}-${UPSTREAMVER}/themes"
		FUNC_CLEAN_DOCS="themes ${FUNC_CLEAN_DOCS}"
	fi

	if [ ${SILENT} -eq 0 ] ; then
		printf ", application notes"
	fi

	# Application notes
	for note in $( ${FIND} "${OPTDIR}" -maxdepth 1 -mindepth 1 ! -type d \( -iname "readme.*" -o -iname "relnotes.*" \)) ; do
		${MV} ${MV_OPTS_FUNC_CLEAN} "${note}" "${WORKDIR}/usr/share/doc/${PROGNAME}-${UPSTREAMVER}"
		FUNC_CLEAN_DOCS="notes ${FUNC_CLEAN_DOCS}"
	done

	if [ ${SILENT} -eq 0 ] ; then
		printf ", done!\n"
	fi

	if [ "${UPSTREAMVER}" = "1.0.0" ] ; then
		func_firstver ${OPTDIR}
	fi

	return 0
}

# Setup the debian directory
#
func_debianize() {
	if [ ${#} -ne 1 ] ; then
		printf "Usage: func_debianize() <directory>\n"
		return 1
	fi

	if [ ${SILENT} -eq 0 ] ; then
		printf "Populating the \"%s/debian\" package control directory:\n" "${1}"
	fi

	if ! [ -d "${1}" ] ; then
		if [ ${SILENT} -eq 0 ] ; then
			printf "func_debianize(): Directory \"%s\" not found, aborting...\n" "${1}" >&2
		else
			printf "%s - func_debianize(): Directory \"%s\" not found, aborting...\n" "${INVOCATION}" "${1}" >&2
		fi

		exit 1
	fi

	local CUT_OPTS_LIB="-d ; -f"
	local CUT_OPTS_LIBCVER="-d _ -f 2"
	local CHMOD_OPTS_FUNC_DEB="755"
	local DATE_OPTS_FUNC_DEB="-R"
	local DPKG_QUERY_OPTS_VERSION="--showformat=\${Version} --show"
	local FOLD_OPTS_FUNC_DEB="-w 79 -s"
	local GREP_OPTS_COUNT="${GREP_OPTS} -c"
	local GREP_OPTS_LIBCVER="${GREP_OPTS} -m 1"
	local MV_OPTS_FUNC_DEB="--strip-trailing-slashes"
	local OBJDUMP_OPTS_FUNC_DEB="-p"
	local RM_OPTS_FUNC_DEB="-rf"
	local RMDIR_OPTS_FUNC_DEB="-p --ignore-fail-on-non-empty"
	CSVLIBS=0
	LIBJNIDISPATCH=0
	local BINSDIR="${USRDIR}/bin"
	local DEBIAN_WORKDIR="${1}/debian"
	local POSTINST_PRIO=$(printf "%02u%02u%02u" ${UPSTREAMVERMAJ} ${UPSTREAMVERMIN} ${UPSTREAMVERREV})
	POSTINST_PRIO="$(printf "%0${#POSTINST_PRIO}u" "$(${EXPR} ${EXPR_OPTS} ${POSTINST_PRIO} - 1)" )"
	local SDCLI=0
	local SQLCL=0
	${MKDIR} ${MKDIR_OPTS} "${DEBIAN_WORKDIR}"

	if [ -x "${1}/${INSTDIR}/${PROGNAME}/${UPSTREAMVER}/${PROGNAME}/bin/sdcli" ] ; then
		SDCLI=1
	fi

	if [ -x "${1}/${INSTDIR}/${PROGNAME}/${UPSTREAMVER}/${PROGNAME}/bin/sql" ] ; then
		SQLCL=1
	fi

	if [ ${SKIPLIB} -eq 0 ] ; then
		if [ ${SILENT} -eq 0 ] ; then
			printf "\tfinding libraries to build ... "
		fi

		if [ -f "${1}/libraries.csv" ] ; then
			${MV} ${MV_OPTS_FUNC_DEB} "${1}/libraries.csv" "${DEBIAN_WORKDIR}"
			CSVLIBS=1

			if [ $(${GREP} ${GREP_OPTS_COUNT} "libjnidispatch" "${DEBIAN_WORKDIR}/libraries.csv" ) -gt 0 ] ; then
				LIBJNIDISPATCH=1
				local LINE="$(${GREP} ${GREP_OPTS} "libjnidispatch" "${DEBIAN_WORKDIR}/libraries.csv")"
				local JNISONAME="$(printf ${LINE} |${CUT} ${CUT_OPTS_LIB} 1)"
				JNISOVERSION="$(printf ${LINE} |${CUT} ${CUT_OPTS_LIB} 2)"
				JNISOVERSION="${JNISOVERSION#\.}"
				JNILIBNAME="${JNISONAME%\.so}"
			fi
		fi

		if [ ${SILENT} -eq 0 ] ; then
			printf "done!\n"
		fi
	fi

	if [ ${SILENT} -eq 0 ] ; then
		printf "\tdebian/changelog ... "
	fi

	(
	${CAT} <<EOF
${PROGNAME}-${UPSTREAMVER} (${UPSTREAMVER}+${VERSION}-${LOCALVER}) unstable; urgency=low

  * Built with ${INVOCATION} ${VERSION} (Closes: #${ITP})
  * Multiple versions can coexist so "sqldeveloper.[upstream version]" will
    invoke a specific version of Oracle SQL Developer while "sqldeveloper"
    takes advantage of Debian's alternatives system and, when left in auto
    mode, will always invoke the highest version installed
EOF
	) >"${DEBIAN_WORKDIR}/changelog"

	if [ ${SDCLI} -ne 0 ] ; then
		(
		${CAT} <<EOF
  * The same will apply to Oracle CLI for SQL Developer with
    "sdcli.[upstream version]" and "sdcli"
EOF
		) >>"${DEBIAN_WORKDIR}/changelog"
	fi

	if [ ${SQLCL} -ne 0 ] ; then
		(
		${CAT} <<EOF
  * Since version 4.2 Oracle started to bundle Oracle SQL Developer
    Command-Line (SQLcl) with Oracle SQL Developer. When available, and as an
    alternative to the standalone package (see "sqlcl-package"),
    "sql.[upstream version].bundled" will invoke a specific version of SQLcl
    while "sqlcl.bundled" takes advantage of Debian's alternatives system and,
    when left in auto mode, will always invoke the highest bundled version
    installed, and "sqlcl" will invoke the highest version installed (either
    standalone or bundled (in this order)
EOF
		) >>"${DEBIAN_WORKDIR}/changelog"
	fi

	printf "\n -- %s <%s>  %s\n" "${DEBFULLNAME}" "${DEBEMAIL}" "$(${DATE} ${DATE_OPTS_FUNC_DEB})" >>"${DEBIAN_WORKDIR}/changelog"

	if [ ${SILENT} -eq 0 ] ; then
		printf "done!\n"
		printf "\tdebian/compat ... "
	fi

	printf "11\n" >"${DEBIAN_WORKDIR}/compat"

	if [ ${SILENT} -eq 0 ] ; then
		printf "done!\n"
		printf "\tdebian/control ... "
	fi

	(
	${CAT} <<EOF
Source: ${PROGNAME}-${UPSTREAMVER}
Section: non-free/misc
Priority: optional
Maintainer: ${DEBFULLNAME} <${DEBEMAIL}>
Build-Depends: debhelper (>= $(${DPKG_QUERY} ${DPKG_QUERY_OPTS_VERSION} debhelper))
Standards-Version: ${STANDARDS}
Homepage: ${HOMEPAGE}

Package: ${PROGNAME}-${UPSTREAMVER}
Architecture: all
EOF
	) >"${DEBIAN_WORKDIR}/control"

	if [ ${SKIPLIB} -eq 0 -a ${CSVLIBS} -eq 1 ] ; then
		printf "Multi-Arch: foreign\n" >>"${DEBIAN_WORKDIR}/control"
	fi

	printf "Depends: \${misc:Depends}, xterm | x-terminal-emulator\n" >>"${DEBIAN_WORKDIR}/control"
	printf "Recommends: " >>"${DEBIAN_WORKDIR}/control"
	[ ${UPSTREAMVERMAJ} -gt 3 ] && {
		[ ${UPSTREAMVERMAJ} -gt 4 ] && {
			printf "java8-sdk | java9-sdk" >>"${DEBIAN_WORKDIR}/control"
		} || {
			[ ${UPSTREAMVERMIN} -gt 0 ] && {
				printf "java8-sdk | java9-sdk" >>"${DEBIAN_WORKDIR}/control"
			} || {
				printf "java7-sdk" >>"${DEBIAN_WORKDIR}/control"
			}
		}
	} || {
		printf "java6-sdk" >>"${DEBIAN_WORKDIR}/control"
		[ ${UPSTREAMVERMAJ} -lt 2 ] && printf " | java5-sdk" >>"${DEBIAN_WORKDIR}/control"
	}

	if [ ${SKIPLIB} -eq 0 -a ${CSVLIBS} -eq 1 -a ${LIBJNIDISPATCH} -eq 1 ] ; then
		printf ", ${JNILIBNAME} (= ${JNISOVERSION}+${VERSION})" >>"${DEBIAN_WORKDIR}/control"
	fi

	printf "\n" >>"${DEBIAN_WORKDIR}/control"
	printf "Provides: oracle-sql-client, oracle-sql-client-gui," >>"${DEBIAN_WORKDIR}/control"

	if [ ${SQLCL} -ne 0 ] ; then
		printf " oracle-sql-client-cli," >>"${DEBIAN_WORKDIR}/control"
	fi

	printf "\n %s" "${PROGNAME}" >>"${DEBIAN_WORKDIR}/control"

	if [ ${SQLCL} -ne 0 ] ; then
		printf ", sqlcl.bundled, sqlcl" >>"${DEBIAN_WORKDIR}/control"
	fi

	printf "\n" >>"${DEBIAN_WORKDIR}/control"

	(
	${CAT} <<EOF
Description: Oracle SQL Developer
 Oracle SQL Developer is a free integrated development environment that
 simplifies the development and management of Oracle Database in both
 traditional and Cloud deployments.  SQL Developer offers complete end-to-end
 development of your PL/SQL applications, a worksheet for running queries and
 scripts, a DBA console for managing the database, a reports interface, a
 complete data modeling solution, and a migration platform for moving your
 3rd party databases to Oracle.
 .
 Oracle SQL Developer is a Java application and requires a full Java SDK.  The
 minimum JDK you should use is as follows:
 .
 Oracle SQL Developer versions up to 1.5.5 require a minimum JDK of 1.5.0_06,
 or if you use JDK 1.6 (JDK6.0), the minimum you should use is JDK 1.6.0_03.
 Oracle SQL Developer versions 2.1 up to 3.1 require a minimum JDK of 1.6.0_11.
 Oracle SQL Developer version 3.2 requires a minimum JDK of 1.6.0_04.
 Oracle SQL Developer version 4.0 requires a minimum JDK of 1.7 (JDK7.0).
 Oracle SQL Developer versions 4.1 up to 17.3  require a minimum  JDK  of  1.8
 (JDK8.0).
 .
 Note that JDK1.7 (JDK7.0) or newer is not supported  by  Oracle SQL Developer
 prior to version 4.0 and that JDK1.8 (JDK8.0) or newer is not supported prior
 to version 4.1.
EOF
	) >>"${DEBIAN_WORKDIR}/control"

	if [ ${SILENT} -eq 0 ] ; then
		printf "done!\n"
		printf "\tdebian/rules ... "
	fi

	(
	${CAT} <<EOF
#!/usr/bin/make -f

# verbose mode
#export DH_VERBOSE=1

DEB_HOST_MULTIARCH ?= \$(shell ${DPKG_ARCHITECTURE} -qDEB_HOST_MULTIARCH)

PREPROCESS_FILES := \$(wildcard debian/*.in)

\$(PREPROCESS_FILES:.in=): %: %.in
	${SED} ${SED_OPTS} 's,/@DEB_HOST_MULTIARCH@,\$(DEB_HOST_MULTIARCH:%=/%),g' \$< > \$@

override_dh_auto_clean:
	dh_auto_clean
	${RM} ${RM_OPTS_FUNC_DEB} \$(PREPROCESS_FILES:.in=)

override_dh_auto_install: \$(PREPROCESS_FILES:.in=)
	dh_auto_install

override_dh_builddeb:
	dh_builddeb --destdir="${CURDIR}"

override_dh_shlibdeps:
	dh_shlibdeps -- --warnings=2

override_dh_strip_nondeterminism:

%:
	dh \$@
EOF
	) >"${DEBIAN_WORKDIR}/rules" && ${CHMOD} ${CHMOD_OPTS_FUNC_DEB} "${DEBIAN_WORKDIR}/rules"

	if [ ${SILENT} -eq 0 ] ; then
		printf "done!\n"
		printf "\tdebian/%s.copyright ... " "${PROGNAME}-${UPSTREAMVER}"
	fi

	(
	${CAT} <<EOF
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: Oracle SQL Developer
Upstream-Contact: https://www.oracle.com/corporate/contact/index.html
Source: ${HOMEPAGE}
Disclaimer:
 This package is not part of the Debian GNU/Linux distribution. It falls into
 category 2.2.3 of the Debian Policy Manual ("... not compliant with the DFSG
 or are encumbered by patents or other legal issues that make their
 distribution problematic.").
Comment:
 This package was debianized by ${DEBFULLNAME} <${DEBEMAIL}> on
 $(${DATE} ${DATE_OPTS_FUNC_DEB}).

Files: *
Copyright: Copyright © 2009-2017 Oracle USA, Inc.
License: OracleSQLDeveloper

Files: debian/*
Copyright: Copyright © 2009-2018 Lazarus Long <lazarus.long@sapo.pt>
License: GPL-3+

License: OracleSQLDeveloper
 Oracle SQL Developer License Terms
 Oracle SQL Developer Data Modeler License Terms
 .
 Export Controls on the Programs
 Selecting the "Accept License Agreement" button is a confirmation of
 your agreement that you comply, now and during the trial term, with
 each of the following statements:
 .
 -You are not a citizen, national, or resident of, and are not under
  control of, the government of Cuba, Iran, Sudan, Libya, North Korea,
  Syria, nor any country to which the United States has prohibited export.
 -You will not download or otherwise export or re-export the Programs,
  directly or indirectly, to the above mentioned countries nor to citizens,
  nationals or residents of those countries.
 -You are not listed on the United States Department of Treasury lists
  of Specially Designated Nationals, Specially Designated Terrorists,
  and Specially Designated Narcotic Traffickers, nor are you listed on
  the United States Department of Commerce Table of Denial Orders.
 .
 You will not download or otherwise export or re-export the Programs,
 directly or indirectly, to persons on the above mentioned lists.
 .
 You will not use the Programs for, and will not allow the Programs to
 be used for, any purposes prohibited by United States law, including,
 without limitation, for the development, design, manufacture or production
 of nuclear, chemical or biological weapons of mass destruction.
 .
 EXPORT RESTRICTIONS
 You agree that U.S. export control laws and other applicable export
 and import laws govern your use of the programs, including technical
 data; additional information can be found on Oracle®'s Global Trade
 Compliance web site (http://www.oracle.com/products/export).
 .
 You agree that neither the programs nor any direct product thereof will
 be exported, directly, or indirectly, in violation of these laws, or
 will be used for any purpose prohibited by these laws including, without
 limitation, nuclear, chemical, or biological weapons proliferation.
 .
 Oracle Employees: Under no circumstances are Oracle Employees
 authorized to download software for the purpose of distributing it to
 customers. Oracle products are available to employees for internal
 use or demonstration purposes only. In keeping with Oracle's trade
 compliance obligations under U.S. and applicable multilateral law,
 failure to comply with this policy could result in disciplinary action
 up to and including termination.
 .
 Note: You are bound by the Oracle Technology Network ("OTN") License
 Agreement terms. The OTN License Agreement terms also apply to all
 updates you receive under your Technology Track subscription.
 .
 The OTN License Agreement terms below supersede any shrinkwrap license
 on the OTN Technology Track software CDs and previous OTN License terms
 (including the Oracle Program License as modified by the OTN Program
 Use Certificate).
 .
 Oracle SQL Developer License Agreement
 Oracle SQL Developer Data Modeler License Agreement
 .
 "We," "us," and "our" refers to Oracle America, Inc., for and on behalf of
 itself and its subsidiaries and affiliates under common control. "You" and
 "your" refers to the individual or entity that wishes to use the programs
 from Oracle. "Programs" refers to the Oracle software product you wish to
 download and use and program documentation. "License" refers to your right
 to use the programs under the terms of this agreement. This agreement
 is governed by the substantive and procedural laws of California. You
 and Oracle agree to submit to the exclusive jurisdiction of, and venue
 in, the courts of San Francisco, San Mateo, or Santa Clara counties in
 California in any dispute arising out of or relating to this agreement.
 .
 We are willing to license the programs to you only upon the condition
 that you accept all of the terms contained in this agreement. Read the
 terms carefully and select the "Accept" button at the bottom of the
 page to confirm your acceptance. If you are not willing to be bound
 by these terms, select the "Do Not Accept" button and the registration
 process will not continue.
 .
 LICENSE RIGHTS
 We grant you a nonexclusive, nontransferable limited license to use
 the programs solely for your business operations and any third party
 training as part of such business operations. We may audit your use
 of the programs. Program documentation may be accessed online at
 http://www.oracle.com/technetwork/indexes/documentation/index.html.
 .
 Ownership and Restrictions
 We retain all ownership and intellectual property rights in the
 programs. You may make a sufficient number of copies of the programs
 for the licensed use and one copy of the programs for backup purposes.
 .
 You may not:
 - remove or modify any program markings or any notice of our proprietary
   rights;
 - make the programs available in any manner to any third party, other
   than as specified above;
 - use the programs for any purpose other than as provided above;
 - assign this agreement or give or transfer the programs or an interest
   in them to another individual or entity;
 - cause or permit reverse engineering (unless required by law for
   interoperability), disassembly or decompilation of the programs;
 - disclose results of any program benchmark tests without our prior
   consent.
 .
 Export
 You agree that U.S. export control laws and other applicable
 export and import laws govern your use of the programs,
 including technical data; additional information can be
 found on Oracle's Global Trade Compliance web site located at
 http://www.oracle.com/products/export/index.html?content.html. You
 agree that neither the programs nor any direct product thereof will be
 exported, directly, or indirectly, in violation of these laws, or will
 be used for any purpose prohibited by these laws including, without
 limitation, nuclear, chemical, or biological weapons proliferation.
 .
 Disclaimer of Warranty and Exclusive Remedies
 THE PROGRAMS ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. WE
 FURTHER DISCLAIM ALL WARRANTIES, EXPRESS AND IMPLIED, INCLUDING WITHOUT
 LIMITATION, ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
 PARTICULAR PURPOSE OR NONINFRINGEMENT.
 .
 IN NO EVENT SHALL WE BE LIABLE FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
 PUNITIVE OR CONSEQUENTIAL DAMAGES, OR DAMAGES FOR LOSS OF PROFITS,
 REVENUE, DATA OR DATA USE, INCURRED BY YOU OR ANY THIRD PARTY, WHETHER
 IN AN ACTION IN CONTRACT OR TORT, EVEN IF WE HAVE BEEN ADVISED OF THE
 POSSIBILITY OF SUCH DAMAGES. OUR ENTIRE LIABILITY FOR DAMAGES HEREUNDER
 SHALL IN NO EVENT EXCEED ONE THOUSAND DOLLARS (U.S. \$1,000).
 .
 Trial Programs Included With Orders
 We may include additional programs with an order which may be used for
 trial purposes only. You will have 30 days from the delivery date to
 evaluate these programs. Any use of these programs after the 30 day
 trial period requires you to obtain the applicable license. Programs
 licensed for trial purposes are provided "as is" and we do not provide
 technical support or any warranties for these programs.
 .
 Technical Support
 Our technical support organization does not provide technical support,
 phone support, or updates specifically for the programs licensed under
 this agreement. However, if you have a supported license of an Oracle
 database program, then the technical support organization will provide
 technical support, phone support for the program licensed hereunder in
 conjunction with the Oracle database program license.
 .
 End of Agreement
 You may terminate this agreement by destroying all copies of the
 programs. We have the right to terminate your right to use the programs
 if you fail to comply with any of the terms of this agreement, in which
 case you shall destroy all copies of the programs.
 .
 Relationship Between the Parties
 The relationship between you and us is that of licensee/licensor. Neither
 party will represent that it has any authority to assume or create
 any obligation, express or implied, on behalf of the other party,
 nor to represent the other party as agent, employee, franchisee, or
 in any other capacity. Nothing in this agreement shall be construed
 to limit either party's right to independently develop or distribute
 software that is functionally similar to the other party's products,
 so long as proprietary information of the other party is not included
 in such software.
 .
 Open Source
 Third party technology that may be appropriate or necessary for use with
 the program may be specified in the program documentation. To the extent
 stated in the program documentation, such third party technology is
 licensed to you under the terms of the third party technology license
 agreement specified in the program documentation and not under the
 terms of this agreement. Nothing in this agreement should be construed
 as modifying or limiting your rights to use such third party technology
 under the terms of the specified third party license.
 .
 Entire Agreement
 You agree that this agreement is the complete agreement for the programs
 and licenses, and this agreement supersedes all prior or contemporaneous
 agreements or representations. If any term of this agreement is found
 to be invalid or unenforceable, the remaining provisions will remain
 effective.
 .
 Last updated: 09/17/10 (jlr)
 .
 Should you have any questions concerning this License Agreement, or if
 you desire to contact Oracle for any reason, please write:
 .
 Oracle America, Inc.
 500 Oracle Parkway,
 Redwood City, CA 94065
 .
 Oracle may contact you to ask if you had a satisfactory experience
 installing and using this OTN software download.
EOF
	) >"${DEBIAN_WORKDIR}/${PROGNAME}-${UPSTREAMVER}.copyright"

	if [ -f "${1}/${INSTDIR}/${PROGNAME}/${UPSTREAMVER}/${PROGNAME}/extensions/oracle.sqldeveloper.onsd/LICENSE.txt" ] ; then
		(
		${CAT} <<EOF

Files: ${PROGNAME}/${UPSTREAMVER}/${PROGNAME}/extensions/oracle.sqldeveloper.onsd*
Copyright: Copyright © 2009-2017 Oracle USA, Inc.
License: Apache-2.0
EOF
		) >>"${DEBIAN_WORKDIR}/${PROGNAME}-${UPSTREAMVER}.copyright"

		${RM} ${RM_OPTS_FUNC_DEB} "${1}/${INSTDIR}/${PROGNAME}/${UPSTREAMVER}/${PROGNAME}/extensions/oracle.sqldeveloper.onsd/LICENSE.txt"
	fi

	if [ -d "${1}/${INSTDIR}/${PROGNAME}/${UPSTREAMVER}/jdev/extensions/oracle.jdeveloper.git/license" ] ; then
		(
		${CAT} <<EOF

Files: ${PROGNAME}/${UPSTREAMVER}/jdev/extensions/oracle.jdeveloper.git*
Copyright: Copyright (c) 2007, Eclipse Foundation, Inc. and its licensors.
License: Eclipse-1.0

License: Eclipse-1.0
EOF
		) >>"${DEBIAN_WORKDIR}/${PROGNAME}-${UPSTREAMVER}.copyright"

		for l in ${1}/${INSTDIR}/${PROGNAME}/${UPSTREAMVER}/jdev/extensions/oracle.jdeveloper.git/license/* ; do
			LICFILE="$(${BASENAME} ${l})"

			${CAT} "${l}" | ${FROMDOS} |${SED} ${SED_OPTS} 's/^[[:space:]]*//g' |${FOLD} ${FOLD_OPTS_FUNC_DEB} |${SED} ${SED_OPTS} 's/^$/./g;s/^/ /g' >>"${DEBIAN_WORKDIR}/${PROGNAME}-${UPSTREAMVER}.copyright"
		done

		${RM} ${RM_OPTS_FUNC_DEB} ${1}/${INSTDIR}/${PROGNAME}/${UPSTREAMVER}/jdev/extensions/oracle.jdeveloper.git/license/*
		${RMDIR} ${RMDIR_OPTS_FUNC_DEB} "${1}/${INSTDIR}/${PROGNAME}/${UPSTREAMVER}/jdev/extensions/oracle.jdeveloper.git/license"
	fi


	if [ -d "${1}/${INSTDIR}/${PROGNAME}/${UPSTREAMVER}/jdev/extensions/oracle.jdeveloper.subversion/licenses" ] ; then
		(
		${CAT} <<EOF

Files: ${PROGNAME}/${UPSTREAMVER}/jdev/extensions/oracle.jdeveloper.subversion*
Copyright: Copyright (c) 2004-2009 TMate Software. All rights reserved.
License: Apache-2.0 or TMate

License: TMate
EOF
		) >>"${DEBIAN_WORKDIR}/${PROGNAME}-${UPSTREAMVER}.copyright"

		for l in ${1}/${INSTDIR}/${PROGNAME}/${UPSTREAMVER}/jdev/extensions/oracle.jdeveloper.subversion/licenses/* ; do
			LICFILE="$(${BASENAME} ${l})"

			if [ "${LICFILE}" = "license.txt" ] ; then
				continue
			fi

			${CAT} "${l}" | ${FROMDOS} |${SED} ${SED_OPTS} 's/^[[:space:]]*//g' |${FOLD} ${FOLD_OPTS_FUNC_DEB} |${SED} ${SED_OPTS} 's/^$/./g;s/^/ /g;s/explictly/explicitly/g' >>"${DEBIAN_WORKDIR}/${PROGNAME}-${UPSTREAMVER}.copyright"
		done

		${RM} ${RM_OPTS_FUNC_DEB} ${1}/${INSTDIR}/${PROGNAME}/${UPSTREAMVER}/jdev/extensions/oracle.jdeveloper.subversion/licenses/*
		${RMDIR} ${RMDIR_OPTS_FUNC_DEB} "${1}/${INSTDIR}/${PROGNAME}/${UPSTREAMVER}/jdev/extensions/oracle.jdeveloper.subversion/licenses"
	fi

	if [ -d "${1}/${INSTDIR}/${PROGNAME}/${UPSTREAMVER}/svnkit/licenses" ] ; then
		(
		${CAT} <<EOF

Files: ${PROGNAME}/${UPSTREAMVER}/svnkit/svnClientAdapter.jar
Copyright: Copyright (c) 2004-2009 TMate Software. All rights reserved.
License: Apache-2.0 or TMate

Files: ${PROGNAME}/${UPSTREAMVER}/svnkit/sqljet.jar
Copyright: Copyright (C) 2009-2010 TMate Software Ltd
License: GPL-2 or TMate

Files: ${PROGNAME}/${UPSTREAMVER}/svnkit/antlr-runtime.jar
Copyright: Copyright (c) 2003-2008 Terence Parr
License: BSD-3-clause

Files: ${PROGNAME}/${UPSTREAMVER}/svnkit/svnjavahl.jar
Copyright: Copyright (c) 2000-2005 CollabNet.  All rights reserved.
License: CollabNet-1

Files: ${PROGNAME}/${UPSTREAMVER}/svnkit/sequence.jar
Copyright: Copyright (c) 2000-2008 SyntEvo GmbH, Ainring, GERMANY.
License: SyntEvo

Files: ${PROGNAME}/${UPSTREAMVER}/svnkit/trilead.jar
Copyright: Copyright (c) 2007-2008 Trilead AG (http://www.trilead.com)
           Copyright (c) 2005 - 2006 Swiss Federal Institute of Technology
            (ETH Zurich), Department of Computer Science
            (http://www.inf.ethz.ch), Christian Plattner. All rights reserved.
           Copyright (c) 2000 - 2004 The Legion Of The Bouncy Castle
            (http://www.bouncycastle.org)
License: TriLead-ETHZurich-TheLegionOfTheBouncyCastle

Files: ${PROGNAME}/${UPSTREAMVER}/svnkit/svnkit.jar
Copyright: Copyright (c) 2004-2009 TMate Software. All rights reserved.
License: TMate
EOF
		) >>"${DEBIAN_WORKDIR}/${PROGNAME}-${UPSTREAMVER}.copyright"

		for l in ${1}/${INSTDIR}/${PROGNAME}/${UPSTREAMVER}/svnkit/licenses/* ; do
			LICFILE="$(${BASENAME} ${l})"

			case "${LICFILE}" in
				"COPYING")
					LICNAME="TMate" ;;
				"JAVAHL-LICENSE")
					LICNAME="CollabNet-1" ;;
				"SEQUENCE-LICENSE")
					LICNAME="SyntEvo" ;;
				"TRILEAD-LICENSE")
					LICNAME="TriLead-ETHZurich-TheLegionOfTheBouncyCastle" ;;
				*)
					continue ;;
			esac

			if [ $(${GREP} ${GREP_OPTS_COUNT} "^License: ${LICNAME}$" "${DEBIAN_WORKDIR}/${PROGNAME}-${UPSTREAMVER}.copyright") -gt 1 ] ; then
				continue
			fi

			printf "\nLicense: %s\n" "${LICNAME}" >>"${DEBIAN_WORKDIR}/${PROGNAME}-${UPSTREAMVER}.copyright"
			${CAT} "${l}" | ${FROMDOS} |${SED} ${SED_OPTS} 's/^[[:space:]]*//g' |${FOLD} ${FOLD_OPTS_FUNC_DEB} |${SED} ${SED_OPTS} 's/^$/./g;s/^/ /g;s/explictly/explicitly/g' >>"${DEBIAN_WORKDIR}/${PROGNAME}-${UPSTREAMVER}.copyright"
		done

		${RM} ${RM_OPTS_FUNC_DEB} ${1}/${INSTDIR}/${PROGNAME}/${UPSTREAMVER}/svnkit/licenses/*
		${RMDIR} ${RMDIR_OPTS_FUNC_DEB} "${1}/${INSTDIR}/${PROGNAME}/${UPSTREAMVER}/svnkit/licenses"
	fi

	if [ ${SILENT} -eq 0 ] ; then
		printf "done!\n"
	fi

	if [ $(printf "${FUNC_CLEAN_DOCS}" |${GREP} ${GREP_OPTS_COUNT} "themes" )  -ne 0 ] ; then
	
		if [ ${SILENT} -eq 0 ] ; then
			printf "\tdebian/%s.doc-base ... " "${PROGNAME}-${UPSTREAMVER}"
		fi

		(
		${CAT} <<EOF
Document: ${PROGNAME}-${UPSTREAMVER}-creating-themes
Title: Defining Visual Themes
Author: Oracle USA, Inc.
Abstract: The focus of this document is on theme providers - those who are
 defining the visual characteristics of the product by creating or modifying
 theme definitions. A separate document, Implementing Visual Themes is of
 interest to extension developers who want to use the theme engine to allow
 the visual design of their components to be customized.
Section: Programming

Format: HTML
Index: /usr/share/doc/${PROGNAME}-${UPSTREAMVER}/themes/creating_themes.html
FIles: /usr/share/doc/${PROGNAME}-${UPSTREAMVER}/themes/creating_themes.html
EOF
		) >"${DEBIAN_WORKDIR}/${PROGNAME}-${UPSTREAMVER}.doc-base"

		if [ ${SILENT} -eq 0 ] ; then
			printf "done!\n"
		fi
	fi

	if [ ${SKIPLIB} -eq 0 -a ${CSVLIBS} -eq 1 -a ${LIBJNIDISPATCH} -eq 1 ] ; then
		for Arch in x86_64 i386 ; do
			local JNISOFILE="${1}/${LIBSDIR}/${Arch}-linux-gnu/${PROGNAME}/${UPSTREAMVER}/${JNISONAME}.${JNISOVERSION}"
			local JNIARCHNAME="${Arch}"

			if [ "${JNIARCHNAME}" = "x86_64" ] ; then
				JNIARCHNAME="amd64"
			fi

			if [ -f "${JNISOFILE}" ] ; then
				if [ ${SILENT} -eq 0 ] ; then
					printf "\tdebian/%s.shlibs.%s ... " "${JNILIBNAME}-${UPSTREAMVER}" "${JNIARCHNAME}"
				fi

				local JNIREALSONAME="$(${OBJDUMP} ${OBJDUMP_OPTS_FUNC_DEB} "${JNISOFILE}" |${GREP} ${GREP_OPTS} "SONAME" |${SED} ${SED_OPTS} 's/^[[:space:]]*SONAME[[:space:]]*//')"
				eval "local JNILIBCVER${JNIARCHNAME}=\"\$(\${OBJDUMP} \${OBJDUMP_OPTS_FUNC_DEB} \"\${JNISOFILE}\" |\${GREP} \${GREP_OPTS_LIBCVER} \"GLIBC\" |\${CUT} \${CUT_OPTS_LIBCVER})\""
				printf "${JNIREALSONAME%\.so} #MINVER# ${JNILIBNAME}-${UPSTREAMVER} (>= ${JNISOVERSION}+${VERSION}-${LOCALVER})\n" >"${DEBIAN_WORKDIR}/${JNILIBNAME}-${UPSTREAMVER}.shlibs.${JNIARCHNAME}"

				if [ ${SILENT} -eq 0 ] ; then
					printf "done!\n"
				fi
			fi
		done

		if [ ${SILENT} -eq 0 ] ; then
			printf "\tdebian/%s.changelog ... " "${PROGNAME}-${UPSTREAMVER}"
		fi

		(
		${CAT} <<EOF
${PROGNAME}-${UPSTREAMVER} (${JNISOVERSION}+${VERSION}-${LOCALVER}) unstable; urgency=low

  * Built with ${INVOCATION} ${VERSION} (Closes: #${ITP})
  * Since SQL Developer v4.1, Oracle has started to include i386 and amd64
    shared libraries in NetBeans Platform modules. Due to this, converted
    make-sqldeveloper-package to both generate multiple packages and to be
    Multi-Arch compatible

 -- ${DEBFULLNAME} <${DEBEMAIL}>  $(${DATE} ${DATE_OPTS_FUNC_DEB})
EOF
		) >"${DEBIAN_WORKDIR}/${JNILIBNAME}-${UPSTREAMVER}.changelog"

		if [ ${SILENT} -eq 0 ] ; then
			printf "done!\n"
			printf "\tdebian/control ... "
		fi

		(
		${CAT} <<EOF

Package: ${JNILIBNAME}-${UPSTREAMVER}
Architecture: amd64 i386
Multi-Arch: same
Section: non-free/libs
Pre-Depends: \${misc:Pre-Depends}
Depends: \${misc:Depends}, libc6 (>= ${JNILIBCVERi386}) [i386] | libc6 (>= ${JNILIBCVERamd64}) [amd64]
Recommends: ${PROGNAME}-${UPSTREAMVER} (= ${UPSTREAMVER}+${VERSION}-${LOCALVER})
Provides: ${JNILIBNAME}
Homepage: http://www.netbeans.org
Description: NetBeans Platform JNI dispatch library
 This package is part of, and intended to work with, the Oracle SQL Developer
 package.
 .
 Oracle SQL Developer is a free graphical tool that enhances productivity and
 simplifies database development tasks.  With SQL Developer, you can browse
 database objects, run SQL statements and SQL scripts, and edit and debug
 PL/SQL statements.  You can also run any number of provided reports, as well
 as create and save your own.  You can connect to and migrate 3rd party
 databases to an Oracle database.
 .
 Oracle SQL Developer is a Java application and requires a full Java SDK.
 .
 This is the NetBeans Platform JNI dispatch library used to connect Oracle SQL
 Developer with the NetBeans Platform and IDE, which is already included in
 Oracle SQL Developer.
EOF
		) >>"${DEBIAN_WORKDIR}/control"

		if [ ${SILENT} -eq 0 ] ; then
			printf "updated!\n"
			printf "\tdebian/%s.copyright ... " "${PROGNAME}-${UPSTREAMVER}"
		fi

		(
		${CAT} <<EOF
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: NetBeans Platform
Upstream-Contact: http://www.netbeans.org
Source: http://netbeans.org/features/platform/download.html
Disclaimer:
 This package is not part of the Debian GNU/Linux distribution. It falls into
 category 2.2.3 of the Debian Policy Manual ("... not compliant with the DFSG
 or are encumbered by patents or other legal issues that make their
 distribution problematic.").
Comment:
 This package was debianized by ${DEBFULLNAME} <${DEBEMAIL}> on
 $(${DATE} ${DATE_OPTS_FUNC_DEB}).

Files: *
Copyright: Copyright © 1997-2010 Oracle and/or its affiliates
License: CDDL-1.0 or GPL-2 with Classpath exception

Files: debian/*
Copyright: Copyright © 2009-2018 Lazarus Long <lazarus.long@sapo.pt>
License: GPL-3+

License: CDDL-1.0
 COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL)
 .
 Version 1.0
 1. Definitions.
 .
 1.1. “Contributor” means each individual or entity that creates or 
 contributes to the creation of Modifications.
 .
 1.2. “Contributor Version” means the combination of the Original Software, 
 prior Modifications used by a Contributor (if any), and the Modifications made 
 by that particular Contributor.
 .
 1.3. “Covered Software” means (a) the Original Software, or (b) 
 Modifications, or (c) the combination of files containing Original Software 
 with files containing Modifications, in each case including portions thereof.
 .
 1.4. “Executable” means the Covered Software in any form other than Source 
 Code.
 .
 1.5. “Initial Developer” means the individual or entity that first makes 
 Original Software available under this License.
 .
 1.6. “Larger Work” means a work which combines Covered Software or 
 portions thereof with code not governed by the terms of this License.
 .
 1.7. “License” means this document.
 .
 1.8. “Licensable” means having the right to grant, to the maximum extent 
 possible, whether at the time of the initial grant or subsequently acquired, 
 any and all of the rights conveyed herein.
 .
 1.9. “Modifications” means the Source Code and Executable form of any of 
 the following:
 .
   A. Any file that results from an addition to, deletion from or 
   modification of the contents of a file containing Original Software or 
   previous Modifications;
 .
   B. Any new file that contains any part of the Original Software or 
   previous Modification; or
 .
   C. Any new file that is contributed or otherwise made available under the 
   terms of this License.
 .
 1.10. “Original Software” means the Source Code and Executable form of 
 computer software code that is originally released under this License.
 .
 1.11. “Patent Claims” means any patent claim(s), now owned or hereafter 
 acquired, including without limitation, method, process, and apparatus claims, 
 in any patent Licensable by grantor.
 .
 1.12. “Source Code” means (a) the common form of computer software code in 
 which modifications are made and (b) associated documentation included in or 
 with such code.
 .
 1.13. “You” (or “Your”) means an individual or a legal entity 
 exercising rights under, and complying with all of the terms of, this License. 
 For legal entities, “You” includes any entity which controls, is 
 controlled by, or is under common control with You. For purposes of this 
 definition, “control” means (a) the power, direct or indirect, to cause 
 the direction or management of such entity, whether by contract or otherwise, 
 or (b) ownership of more than fifty percent (50%) of the outstanding shares or 
 beneficial ownership of such entity.
 .
 2. License Grants.
 .
 2.1. The Initial Developer Grant.
 .
 Conditioned upon Your compliance with Section 3.1 below and subject to third
 party intellectual property claims, the Initial Developer hereby grants You a
 world-wide, royalty-free, non-exclusive license:
 .
   (a) under intellectual property rights (other than patent or trademark) 
   Licensable by Initial Developer, to use, reproduce, modify, display,
   perform, sublicense and distribute the Original Software (or portions
   thereof), with or without Modifications, and/or as part of a Larger Work;
   and
 .
   (b) under Patent Claims infringed by the making, using or selling of 
   Original Software, to make, have made, use, practice, sell, and offer for 
   sale, and/or otherwise dispose of the Original Software (or portions
   thereof).
 .
   (c) The licenses granted in Sections 2.1(a) and (b) are effective on the 
   date Initial Developer first distributes or otherwise makes the Original 
   Software available to a third party under the terms of this License.
 .
   (d) Notwithstanding Section 2.1(b) above, no patent license is granted: 
   (1) for code that You delete from the Original Software, or (2) for 
   infringements caused by: (i) the modification of the Original Software, or 
   (ii) the combination of the Original Software with other software or
    devices.
 .
 2.2. Contributor Grant.
 .
 Conditioned upon Your compliance with Section 3.1 below and subject to third 
 party intellectual property claims, each Contributor hereby grants You a 
 world-wide, royalty-free, non-exclusive license:
 .
   (a) under intellectual property rights (other than patent or trademark) 
   Licensable by Contributor to use, reproduce, modify, display, perform, 
   sublicense and distribute the Modifications created by such Contributor (or 
   portions thereof), either on an unmodified basis, with other Modifications,
   as Covered Software and/or as part of a Larger Work; and
 .
   (b) under Patent Claims infringed by the making, using, or selling of 
   Modifications made by that Contributor either alone and/or in combination
   with its Contributor Version (or portions of such combination), to make,
   use, sell, offer for sale, have made, and/or otherwise dispose of: (1)
   Modifications made by that Contributor (or portions thereof); and (2) the
   combination of Modifications made by that Contributor with its Contributor
   Version (or portions of such combination).
 .
   (c) The licenses granted in Sections 2.2(a) and 2.2(b) are effective on 
   the date Contributor first distributes or otherwise makes the Modifications 
   available to a third party.
 .
   (d) Notwithstanding Section 2.2(b) above, no patent license is granted: 
   (1) for any code that Contributor has deleted from the Contributor Version; 
   (2) for infringements caused by: (i) third party modifications of
   Contributor Version, or (ii) the combination of Modifications made by that
   Contributor with other software (except as part of the Contributor Version)
   or other devices; or (3) under Patent Claims infringed by Covered Software
   in the absence of Modifications made by that Contributor.
 .
 3. Distribution Obligations.
 .
 3.1. Availability of Source Code.
 .
 Any Covered Software that You distribute or otherwise make available in 
 Executable form must also be made available in Source Code form and that 
 Source Code form must be distributed only under the terms of this License. You 
 must include a copy of this License with every copy of the Source Code form of 
 the Covered Software You distribute or otherwise make available. You must 
 inform recipients of any such Covered Software in Executable form as to how 
 they can obtain such Covered Software in Source Code form in a reasonable 
 manner on or through a medium customarily used for software exchange.
 .
 3.2. Modifications.
 .
 The Modifications that You create or to which You contribute are governed by 
 the terms of this License. You represent that You believe Your Modifications 
 are Your original creation(s) and/or You have sufficient rights to grant the 
 rights conveyed by this License.
 .
 3.3. Required Notices.
 .
 You must include a notice in each of Your Modifications that identifies You as 
 the Contributor of the Modification. You may not remove or alter any 
 copyright, patent or trademark notices contained within the Covered Software, 
 or any notices of licensing or any descriptive text giving attribution to any 
 Contributor or the Initial Developer.
 .
 3.4. Application of Additional Terms.
 .
 You may not offer or impose any terms on any Covered Software in Source Code 
 form that alters or restricts the applicable version of this License or the 
 recipients’ rights hereunder. You may choose to offer, and to charge a fee 
 for, warranty, support, indemnity or liability obligations to one or more 
 recipients of Covered Software. However, you may do so only on Your own 
 behalf, and not on behalf of the Initial Developer or any Contributor. You 
 must make it absolutely clear that any such warranty, support, indemnity or 
 liability obligation is offered by You alone, and You hereby agree to 
 indemnify the Initial Developer and every Contributor for any liability 
 incurred by the Initial Developer or such Contributor as a result of warranty, 
 support, indemnity or liability terms You offer.
 .
 3.5. Distribution of Executable Versions.
 .
 You may distribute the Executable form of the Covered Software under the terms 
 of this License or under the terms of a license of Your choice, which may 
 contain terms different from this License, provided that You are in compliance 
 with the terms of this License and that the license for the Executable form 
 does not attempt to limit or alter the recipient’s rights in the Source Code 
 form from the rights set forth in this License. If You distribute the Covered 
 Software in Executable form under a different license, You must make it 
 absolutely clear that any terms which differ from this License are offered by 
 You alone, not by the Initial Developer or Contributor. You hereby agree to 
 indemnify the Initial Developer and every Contributor for any liability 
 incurred by the Initial Developer or such Contributor as a result of any such 
 terms You offer.
 .
 3.6. Larger Works.
 .
 You may create a Larger Work by combining Covered Software with other code not 
 governed by the terms of this License and distribute the Larger Work as a 
 single product. In such a case, You must make sure the requirements of this 
 License are fulfilled for the Covered Software.
 .
 4. Versions of the License.
 .
 4.1. New Versions.
 .
 Sun Microsystems, Inc. is the initial license steward and may publish revised 
 and/or new versions of this License from time to time. Each version will be 
 given a distinguishing version number. Except as provided in Section 4.3, no 
 one other than the license steward has the right to modify this License.
 .
 4.2. Effect of New Versions.
 .
 You may always continue to use, distribute or otherwise make the Covered 
 Software available under the terms of the version of the License under which 
 You originally received the Covered Software. If the Initial Developer 
 includes a notice in the Original Software prohibiting it from being 
 distributed or otherwise made available under any subsequent version of the 
 License, You must distribute and make the Covered Software available under the 
 terms of the version of the License under which You originally received the 
 Covered Software. Otherwise, You may also choose to use, distribute or 
 otherwise make the Covered Software available under the terms of any 
 subsequent version of the License published by the license steward.
 .
 4.3. Modified Versions.
 .
 When You are an Initial Developer and You want to create a new license for 
 Your Original Software, You may create and use a modified version of this 
 License if You: (a) rename the license and remove any references to the name 
 of the license steward (except to note that the license differs from this 
 License); and (b) otherwise make it clear that the license contains terms 
 which differ from this License.
 .
 5. DISCLAIMER OF WARRANTY.
 .
 COVERED SOFTWARE IS PROVIDED UNDER THIS LICENSE ON AN “AS IS” BASIS, 
 WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT 
 LIMITATION, WARRANTIES THAT THE COVERED SOFTWARE IS FREE OF DEFECTS, 
 MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE OR NON-INFRINGING. THE ENTIRE RISK 
 AS TO THE QUALITY AND PERFORMANCE OF THE COVERED SOFTWARE IS WITH YOU. SHOULD 
 ANY COVERED SOFTWARE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT THE INITIAL 
 DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY 
 SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN 
 ESSENTIAL PART OF THIS LICENSE. NO USE OF ANY COVERED SOFTWARE IS AUTHORIZED 
 HEREUNDER EXCEPT UNDER THIS DISCLAIMER.
 .
 6. TERMINATION.
 .
 6.1. This License and the rights granted hereunder will terminate 
 automatically if You fail to comply with terms herein and fail to cure such 
 breach within 30 days of becoming aware of the breach. Provisions which, by 
 their nature, must remain in effect beyond the termination of this License 
 shall survive.
 .
 6.2. If You assert a patent infringement claim (excluding declaratory judgment 
 actions) against Initial Developer or a Contributor (the Initial Developer or 
 Contributor against whom You assert such claim is referred to as 
 “Participant”) alleging that the Participant Software (meaning the 
 Contributor Version where the Participant is a Contributor or the Original 
 Software where the Participant is the Initial Developer) directly or 
 indirectly infringes any patent, then any and all rights granted directly or 
 indirectly to You by such Participant, the Initial Developer (if the Initial 
 Developer is not the Participant) and all Contributors under Sections 2.1 
 and/or 2.2 of this License shall, upon 60 days notice from Participant 
 terminate prospectively and automatically at the expiration of such 60 day 
 notice period, unless if within such 60 day period You withdraw Your claim 
 with respect to the Participant Software against such Participant either 
 unilaterally or pursuant to a written agreement with Participant.
 .
 6.3. In the event of termination under Sections 6.1 or 6.2 above, all end user 
 licenses that have been validly granted by You or any distributor hereunder 
 prior to termination (excluding licenses granted to You by any distributor) 
 shall survive termination.
 .
 7. LIMITATION OF LIABILITY.
 .
 UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, WHETHER TORT (INCLUDING 
 NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL YOU, THE INITIAL DEVELOPER, ANY 
 OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF COVERED SOFTWARE, OR ANY SUPPLIER OF 
 ANY OF SUCH PARTIES, BE LIABLE TO ANY PERSON FOR ANY INDIRECT, SPECIAL, 
 INCIDENTAL, OR CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT 
 LIMITATION, DAMAGES FOR LOST PROFITS, LOSS OF GOODWILL, WORK STOPPAGE, 
 COMPUTER FAILURE OR MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR 
 LOSSES, EVEN IF SUCH PARTY SHALL HAVE BEEN INFORMED OF THE POSSIBILITY OF SUCH 
 DAMAGES. THIS LIMITATION OF LIABILITY SHALL NOT APPLY TO LIABILITY FOR DEATH 
 OR PERSONAL INJURY RESULTING FROM SUCH PARTY’S NEGLIGENCE TO THE EXTENT 
 APPLICABLE LAW PROHIBITS SUCH LIMITATION. SOME JURISDICTIONS DO NOT ALLOW THE 
 EXCLUSION OR LIMITATION OF INCIDENTAL OR CONSEQUENTIAL DAMAGES, SO THIS 
 EXCLUSION AND LIMITATION MAY NOT APPLY TO YOU.
 .
 8. U.S. GOVERNMENT END USERS.
 .
 The Covered Software is a “commercial item,” as that term is defined in 48 
 C.F.R. 2.101 (Oct. 1995), consisting of “commercial computer software” (as 
 that term is defined at 48 C.F.R. § 252.227-7014(a)(1)) and “commercial 
 computer software documentation” as such terms are used in 48 C.F.R. 12.212 
 (Sept. 1995). Consistent with 48 C.F.R. 12.212 and 48 C.F.R. 227.7202-1 
 through 227.7202-4 (June 1995), all U.S. Government End Users acquire Covered 
 Software with only those rights set forth herein. This U.S. Government Rights 
 clause is in lieu of, and supersedes, any other FAR, DFAR, or other clause or 
 provision that addresses Government rights in computer software under this 
 License.
 .
 9. MISCELLANEOUS.
 .
 This License represents the complete agreement concerning subject matter 
 hereof. If any provision of this License is held to be unenforceable, such 
 provision shall be reformed only to the extent necessary to make it 
 enforceable. This License shall be governed by the law of the jurisdiction 
 specified in a notice contained within the Original Software (except to the 
 extent applicable law, if any, provides otherwise), excluding such 
 jurisdiction’s conflict-of-law provisions. Any litigation relating to this 
 License shall be subject to the jurisdiction of the courts located in the 
 jurisdiction and venue specified in a notice contained within the Original 
 Software, with the losing party responsible for costs, including, without 
 limitation, court costs and reasonable attorneys’ fees and expenses. The 
 application of the United Nations Convention on Contracts for the 
 International Sale of Goods is expressly excluded. Any law or regulation which 
 provides that the language of a contract shall be construed against the 
 drafter shall not apply to this License. You agree that You alone are 
 responsible for compliance with the United States export administration 
 regulations (and the export control laws and regulation of any other 
 countries) when You use, distribute or otherwise make available any Covered 
 Software.
 .
 10. RESPONSIBILITY FOR CLAIMS.
 .
 As between Initial Developer and the Contributors, each party is responsible 
 for claims and damages arising, directly or indirectly, out of its utilization 
 of rights under this License and You agree to work with Initial Developer and 
 Contributors to distribute such responsibility on an equitable basis. Nothing 
 herein is intended or shall be deemed to constitute any admission of liability.
EOF
		) >"${DEBIAN_WORKDIR}/${JNILIBNAME}-${UPSTREAMVER}.copyright"

		if [ ${SILENT} -eq 0 ] ; then
			printf "done!\n"
			printf "\tdebian/%s.install.in ... " "${PROGNAME}-${UPSTREAMVER}"
		fi

		printf "%s/@DEB_HOST_MULTIARCH@/%s/%s* %s/@DEB_HOST_MULTIARCH@/%s/\n" "${LIBSDIR}" "${PROGNAME}/${UPSTREAMVER}" "${JNISONAME}" "${LIBSDIR}" "${PROGNAME}/${UPSTREAMVER}" >"${DEBIAN_WORKDIR}/${JNILIBNAME}-${UPSTREAMVER}.install.in"

		if [ ${SILENT} -eq 0 ] ; then
			printf "done!\n"
			printf "\tdebian/%s.lintian-overrides.amd64 ... " "${PROGNAME}-${UPSTREAMVER}"
		fi

		(
		${CAT} << EOF
hardening-no-bindnow
hardening-no-fortify-functions
hardening-no-relro
no-upstream-changelog
package-has-unnecessary-activation-of-ldconfig-trigger
unused-shlib-entry-in-control-file
EOF
		) >"${DEBIAN_WORKDIR}/${JNILIBNAME}-${UPSTREAMVER}.lintian-overrides.amd64"


		if [ ${SILENT} -eq 0 ] ; then
			printf "done!\n"
			printf "\tdebian/%s.lintian-overrides.i386 ... " "${PROGNAME}-${UPSTREAMVER}"
		fi

		(
		${CAT} << EOF
binary-file-built-without-LFS-support
hardening-no-bindnow
hardening-no-fortify-functions
hardening-no-relro
no-upstream-changelog
pkg-has-shlibs-control-file-but-no-actual-shared-libs
EOF
		) >"${DEBIAN_WORKDIR}/${JNILIBNAME}-${UPSTREAMVER}.lintian-overrides.i386"

		if [ ${SILENT} -eq 0 ] ; then
			printf "done!\n"
		fi
	fi

	for Copyright in "${DEBIAN_WORKDIR}"/*.copyright ; do
		if [ ${SILENT} -eq 0 ] ; then
			printf "\tdebian/%s ... " "$(${BASENAME} "${Copyright}")"
		fi

		if [ $(${GREP} ${GREP_OPTS} "^License:" "${Copyright}" |${GREP} ${GREP_OPTS_COUNT} "Apache-2") -gt 0 ] ; then
			(
			${CAT} <<EOF

License: Apache-2.0
 Licensed to the Apache Software Foundation (ASF) under one or more
 contributor license agreements.  See the NOTICE file distributed with
 this work for additional information regarding copyright ownership.
 The ASF licenses this file to You under the Apache License, Version 2.0
 (the "License"); you may not use this file except in compliance with
 the License.  You may obtain a copy of the License at
 .
      http://www.apache.org/licenses/LICENSE-2.0
 .
 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
 .
 On Debian systems, the full text of the Apache Software License version 2 can
 be found in the file \`/usr/share/common-licenses/Apache-2.0'.
EOF
			) >>"${Copyright}"
		fi

		if [ $(${GREP} ${GREP_OPTS} "^License:" "${Copyright}" |${GREP} ${GREP_OPTS_COUNT} "GPL-3\+") -gt 0 ] ; then
			(
			${CAT} <<EOF

License: GPL-3+
 This package is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free Software
 Foundation; either version 3 of the License, or (at your option) any later
 version.
 .
 This package is distributed in the hope that it will be useful, but WITHOUT
 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 details.
 .
 You should have received a copy of the GNU General Public License along with
 this package; if not, write to the Free Software Foundation, Inc., 51
 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
 .
 On Debian systems, the complete text of the GNU General Public License
 version 3, can be found in \`/usr/share/common-licenses/GPL-3'.
EOF
			) >>"${Copyright}"
		fi

		if [ $(${GREP} ${GREP_OPTS} "^License:" "${Copyright}" |${GREP} ${GREP_OPTS_COUNT} "GPL-2\+") -gt 0 ] ; then
			(
			${CAT} <<EOF

License: GPL-2+
 This package is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free Software
 Foundation; either version 2 of the License, or (at your option) any later
 version.
 .
 This package is distributed in the hope that it will be useful, but WITHOUT
 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 details.
 .
 You should have received a copy of the GNU General Public License along with
 this package; if not, write to the Free Software Foundation, Inc., 51
 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
 .
 On Debian systems, the complete text of the GNU General Public License
 version 2, can be found in \`/usr/share/common-licenses/GPL-2'.
EOF
			) >>"${Copyright}"
		elif [ $(${GREP} ${GREP_OPTS} "^License:" "${Copyright}" |${GREP} ${GREP_OPTS_COUNT} "GPL-2 with Classpath exception") -gt 0 ] ; then
			(
			${CAT} <<EOF

License: GPL-2 with Classpath exception
 This package is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free Software
 Foundation; specifically version 2 of the License.
 .
 As a special exception, the copyright holders of this library give you
 permission to link this library with independent modules to produce an
 executable, regardless of the license terms of these independent modules, and
 to copy and distribute the resulting executable under terms of your choice,
 provided that you also meet, for each linked independent module, the terms
 and conditions of the license of that module. An independent module is a
 module which is not derived from or based on this library. If you modify this
 library, you may extend this exception to your version of the library, but
 you are not obligated to do so. If you do not wish to do so, delete this
 exception statement from your version.
 .
 This package is distributed in the hope that it will be useful, but WITHOUT
 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 details.
 .
 You should have received a copy of the GNU General Public License along with
 this package; if not, write to the Free Software Foundation, Inc., 51
 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
 .
 On Debian systems, the complete text of the GNU General Public License
 version 2, can be found in \`/usr/share/common-licenses/GPL-2'.
EOF
			) >>"${Copyright}"
		elif [ $(${GREP} ${GREP_OPTS} "^License:" "${Copyright}" |${GREP} ${GREP_OPTS_COUNT} "GPL-2") -gt 0 ] ; then
			(
			${CAT} <<EOF

License: GPL-2
 This package is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free Software
 Foundation; specifically version 2 of the License.
 .
 This package is distributed in the hope that it will be useful, but WITHOUT
 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 details.
 .
 You should have received a copy of the GNU General Public License along with
 this package; if not, write to the Free Software Foundation, Inc., 51
 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
 .
 On Debian systems, the complete text of the GNU General Public License
 version 2, can be found in \`/usr/share/common-licenses/GPL-2'.
EOF
			) >>"${Copyright}"
		fi

		if [ $(${GREP} ${GREP_OPTS} "^License:" "${Copyright}" |${GREP} ${GREP_OPTS_COUNT} "BSD-3-clause") -gt 0 ] ; then
			(
			${CAT} <<EOF

License: BSD-3-clause
 All rights reserved.
 .
 Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions
 are met:
 1. Redistributions of source code must retain the above copyright
    notice, this list of conditions and the following disclaimer.
 2. Redistributions in binary form must reproduce the above copyright
    notice, this list of conditions and the following disclaimer in the
    documentation and/or other materials provided with the distribution.
 3. Neither the name of the University nor the names of its contributors
    may be used to endorse or promote products derived from this software
    without specific prior written permission.
 .
 THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 SUCH DAMAGE.
EOF
			) >>"${Copyright}"
		fi

		if [ ${SILENT} -eq 0 ] ; then
			printf "updated!\n"
		fi
	done

	if [ ${SILENT} -eq 0 ] ; then
		printf "\tdebian/%s.install ... " "${PROGNAME}-${UPSTREAMVER}"
	fi

	(
	${CAT} <<EOF
#!/usr/bin/dh-exec
debian/${PROGNAME}.${UPSTREAMVER}.bash => usr/bin/${PROGNAME}.${UPSTREAMVER}
debian/${PROGNAME}.${UPSTREAMVER}.desktop usr/share/applications
debian/${PROGNAME}.${UPSTREAMVER}.xpm usr/share/pixmaps
${INSTDIR}/* ${INSTDIR}
EOF
	) >"${DEBIAN_WORKDIR}/${PROGNAME}-${UPSTREAMVER}.install" && ${CHMOD} ${CHMOD_OPTS_FUNC_DEB} "${DEBIAN_WORKDIR}/${PROGNAME}-${UPSTREAMVER}.install"

	if [ ${SILENT} -eq 0 ] ; then
		printf "done!\n"
	fi

	if [ ${SDCLI} -ne 0 -o ${SQLCL} -ne 0 ] ; then
		if [ ${SILENT} -eq 0 ] ; then
			printf "\tdebian/%s.links ... " "${PROGNAME}-${UPSTREAMVER}"
		fi

		if [ ${SDCLI} -ne 0 ] ; then
			printf "%s %s\n" "${INSTDIR}/${PROGNAME}/${UPSTREAMVER}/${PROGNAME}/bin/sdcli" "${BINSDIR}/sdcli.${UPSTREAMVER}" >>"${DEBIAN_WORKDIR}/${PROGNAME}-${UPSTREAMVER}.links"
		fi

		if [ ${SQLCL} -ne 0 ] ; then
			printf "%s %s\n" "${INSTDIR}/${PROGNAME}/${UPSTREAMVER}/${PROGNAME}/bin/sql" "${BINSDIR}/sql.${UPSTREAMVER}.bundled" >>"${DEBIAN_WORKDIR}/${PROGNAME}-${UPSTREAMVER}.links"
		fi

		if [ ${SILENT} -eq 0 ] ; then
			printf "done!\n"
		fi
	fi

	if [ ${SILENT} -eq 0 ] ; then
		printf "\tdebian/%s.lintian-overrides ... " "${PROGNAME}-${UPSTREAMVER}"
	fi

	(
	${CAT} <<EOF
codeless-jar
classpath-contains-relative-path
missing-manifest
no-upstream-changelog
EOF
	) >"${DEBIAN_WORKDIR}/${PROGNAME}-${UPSTREAMVER}.lintian-overrides"

	if [ ${SILENT} -eq 0 ] ; then
		printf "done!\n"
		printf "\tdebian/%s.manpages ... " "${PROGNAME}-${UPSTREAMVER}"
	fi

	printf "debian/${PROGNAME}.${UPSTREAMVER}.1\n" >"${DEBIAN_WORKDIR}/${PROGNAME}-${UPSTREAMVER}.manpages"

	if [ ${SDCLI} -ne 0 ] ; then
		printf "debian/sdcli.${UPSTREAMVER}.1\n" >>"${DEBIAN_WORKDIR}/${PROGNAME}-${UPSTREAMVER}.manpages"
	fi

	if [ ${SQLCL} -ne 0 ] ; then
		printf "debian/sql.${UPSTREAMVER}.bundled.1\n" >>"${DEBIAN_WORKDIR}/${PROGNAME}-${UPSTREAMVER}.manpages"
	fi

	if [ ${SILENT} -eq 0 ] ; then
		printf "done!\n"
		printf "\tdebian/%s.NEWS ... " "${PROGNAME}-${UPSTREAMVER}"
	fi

	(
	${CAT} <<EOF
${PROGNAME}-${UPSTREAMVER} (${UPSTREAMVER}+${VERSION}-${LOCALVER}) unstable; urgency=low

    Multiple versions can coexist so "sqldeveloper.[upstream version]" will
    invoke a specific version of Oracle SQL Developer while "sqldeveloper"
    takes advantage of Debian's alternatives system and, when left in auto
    mode, will always invoke the highest version installed.
EOF
	) >"${DEBIAN_WORKDIR}/${PROGNAME}-${UPSTREAMVER}.NEWS"

	if [ ${SDCLI} -ne 0 ] ; then
		(
		${CAT} <<EOF
    The same will apply to Oracle CLI for SQL Developer with
    "sdcli.[upstream version]" and "sdcli"
EOF
		) >>"${DEBIAN_WORKDIR}/${PROGNAME}-${UPSTREAMVER}.NEWS"
	fi

	if [ ${SQLCL} -ne 0 ] ; then
		(
		${CAT} <<EOF
    Since version 4.2 Oracle started to bundle Oracle SQL Developer
    Command-Line (SQLcl) with Oracle SQL Developer. When available, and as an
    alternative to the standalone package (see "sqlcl-package"),
    "sql.[upstream version].bundled" will invoke a specific version of SQLcl
    while "sqlcl.bundled" takes advantage of Debian's alternatives system and,
    when left in auto mode, will always invoke the highest bundled version
    installed, and "sqlcl" will invoke the highest version installed (either
    standalone or bundled, in this order)
EOF
		) >>"${DEBIAN_WORKDIR}/${PROGNAME}-${UPSTREAMVER}.NEWS"
	fi

	printf "\n -- %s <%s>  %s\n" "${DEBFULLNAME}" "${DEBEMAIL}" "$(${DATE} ${DATE_OPTS_FUNC_DEB})" >>"${DEBIAN_WORKDIR}/${PROGNAME}-${UPSTREAMVER}.NEWS"

	if [ ${SILENT} -eq 0 ] ; then
		printf "done!\n"
		printf "\tdebian/%s.postinst ... " "${PROGNAME}-${UPSTREAMVER}"
	fi

	(
	${CAT} <<EOF
#!/bin/sh
set -e

MANSECTION=1
COMPRESS=".gz"
PROG_PRIO=50

PRIO=${POSTINST_PRIO}

INSTBINDIR="/${BINSDIR}"
INSTMANDIR="/${INSTDIR}/man/man\${MANSECTION}"

UPDALT="update-alternatives"

UPDALT_SLAVE="--slave"

RET=0

# Invoke update-alternatives --install on the package
#
func_updalt_install() {
	local RET=0
	local UPDALT_ACTION="--install"

	\${UPDALT} \\
		\${UPDALT_ACTION} \${INSTBINDIR}/${PROGNAME} ${PROGNAME} \${INSTBINDIR}/${PROGNAME}.${UPSTREAMVER} \${PRIO} \\
		\${UPDALT_SLAVE} \${INSTMANDIR}/${PROGNAME}.\${MANSECTION}\${COMPRESS} ${PROGNAME}.\${MANSECTION}\${COMPRESS} \${INSTMANDIR}/${PROGNAME}.${UPSTREAMVER}.\${MANSECTION}\${COMPRESS}

	RET=\${?}

	if [ \${RET} -ne 0 ] ; then
		printf "%s postinst - unexpected return code \"%d\"\n" "${INVOCATION}" \${RET} >&2
		return \${RET}
	fi
EOF
	) >"${DEBIAN_WORKDIR}/${PROGNAME}-${UPSTREAMVER}.postinst"

	if [ ${SDCLI} -ne 0 ] ; then
		(
		${CAT} <<EOF

	\${UPDALT} \\
		\${UPDALT_ACTION} \${INSTBINDIR}/sdcli sdcli \${INSTBINDIR}/sdcli.${UPSTREAMVER} \${PRIO} \\
		\${UPDALT_SLAVE} \${INSTMANDIR}/sdcli.\${MANSECTION}\${COMPRESS} sdcli.\${MANSECTION}\${COMPRESS} \${INSTMANDIR}/sdcli.${UPSTREAMVER}.\${MANSECTION}\${COMPRESS}

	RET=\${?}

	if [ \${RET} -ne 0 ] ; then
		printf "%s postinst - unexpected return code \"%d\"\n" "${INVOCATION}" \${RET} >&2
		return \${RET}
	fi
EOF
		) >>"${DEBIAN_WORKDIR}/${PROGNAME}-${UPSTREAMVER}.postinst"
	fi

	if [ ${SQLCL} -ne 0 ] ; then
		(
		${CAT} <<EOF

	\${UPDALT} \\
		\${UPDALT_ACTION} \${INSTBINDIR}/sql.${UPSTREAMVER} sql.${UPSTREAMVER} \${INSTBINDIR}/sql.${UPSTREAMVER}.bundled \${PRIO} \\
		\${UPDALT_SLAVE} \${INSTMANDIR}/sql.${UPSTREAMVER}.\${MANSECTION}\${COMPRESS} sql.${UPSTREAMVER}.\${MANSECTION}\${COMPRESS} \${INSTMANDIR}/sql.${UPSTREAMVER}.bundled.\${MANSECTION}\${COMPRESS}

	RET=\${?}

	if [ \${RET} -ne 0 ] ; then
		printf "%s postinst - unexpected return code \"%d\"\n" "${INVOCATION}" \${RET} >&2
		return \${RET}
	fi

	\${UPDALT} \\
		\${UPDALT_ACTION} \${INSTBINDIR}/sqlcl.bundled sqlcl.bundled \${INSTBINDIR}/sql.${UPSTREAMVER}.bundled \${PRIO} \\
		\${UPDALT_SLAVE} \${INSTMANDIR}/sqlcl.bundled.\${MANSECTION}\${COMPRESS} sqlcl.bundled.\${MANSECTION}\${COMPRESS} \${INSTMANDIR}/sql.${UPSTREAMVER}.bundled.\${MANSECTION}\${COMPRESS}

	RET=\${?}

	if [ \${RET} -ne 0 ] ; then
		printf "%s postinst - unexpected return code \"%d\"\n" "${INVOCATION}" \${RET} >&2
		return \${RET}
	fi

	if [ -f "\${INSTBINDIR}/sqlcl.bundled" ] ; then
		\${UPDALT} \\
			\${UPDALT_ACTION} \${INSTBINDIR}/sqlcl sqlcl \${INSTBINDIR}/sqlcl.bundled \${PROG_PRIO} \\
			\${UPDALT_SLAVE} \${INSTMANDIR}/sqlcl.\${MANSECTION}\${COMPRESS} sqlcl.\${MANSECTION}\${COMPRESS} \${INSTMANDIR}/sqlcl.bundled.\${MANSECTION}\${COMPRESS}

		RET=\${?}

		if [ \${RET} -ne 0 ] ; then
			printf "%s postinst - unexpected return code \"%d\"\n" "${INVOCATION}" \${RET} >&2
			return \${RET}
		fi
	fi
EOF
		) >>"${DEBIAN_WORKDIR}/${PROGNAME}-${UPSTREAMVER}.postinst"
	fi

	(
	${CAT} <<EOF

	return \${RET}
}

case "\${1}" in
	configure|abort-upgrade|abort-remove|abort-deconfigure)
		func_updalt_install
		RET=\${?}
	;;
	*)
		printf "%s postinst - called with an unknown parameter\"%s\"\n" "make-sqlcl-package" "\${1}" >&2
		RET=1
	;;
esac

exit \${RET}
EOF
	) >>"${DEBIAN_WORKDIR}/${PROGNAME}-${UPSTREAMVER}.postinst" && ${CHMOD} ${CHMOD_OPTS_FUNC_DEB} "${DEBIAN_WORKDIR}/${PROGNAME}-${UPSTREAMVER}.postinst"

	if [ ${SILENT} -eq 0 ] ; then
		printf "done!\n"
		printf "\tdebian/%s.prerm ... " "${PROGNAME}-${UPSTREAMVER}"
	fi

	(
	${CAT} <<EOF
#!/bin/sh
set -e

INSTBINDIR="/usr/bin"

UPDALT="update-alternatives"

RET=0

# Invoke update-alternatives --remove on the package
#
func_updalt_remove() {
	local RET=0
	local UPDALT_ACTION="--remove"

	\${UPDALT} \\
		\${UPDALT_ACTION} ${PROGNAME} \${INSTBINDIR}/${PROGNAME}.${UPSTREAMVER}

	RET=\${?}

	if [ \${RET} -ne 0 ] ; then
		printf "%s prerm - unexpected return code \"%d\"\n" "make-sqlcl-package" \${RET} >&2
		return \${RET}
	fi
EOF
	) >"${DEBIAN_WORKDIR}/${PROGNAME}-${UPSTREAMVER}.prerm"

	if [ ${SDCLI} -ne 0 ] ; then
		(
		${CAT} <<EOF

	\${UPDALT} \\
		\${UPDALT_ACTION} sdcli \${INSTBINDIR}/sdcli.${UPSTREAMVER}

	RET=\${?}

	if [ \${RET} -ne 0 ] ; then
		printf "%s prerm - unexpected return code \"%d\"\n" "make-sqlcl-package" \${RET} >&2
		return \${RET}
	fi
EOF
		) >>"${DEBIAN_WORKDIR}/${PROGNAME}-${UPSTREAMVER}.prerm"
	fi

	if [ ${SQLCL} -ne 0 ] ; then
		(
		${CAT} <<EOF

	\${UPDALT} \\
		\${UPDALT_ACTION} sql.${UPSTREAMVER} \${INSTBINDIR}/sql.${UPSTREAMVER}.bundled

	RET=\${?}

	if [ \${RET} -ne 0 ] ; then
		printf "%s prerm - unexpected return code \"%d\"\n" "make-sqlcl-package" \${RET} >&2
		return \${RET}
	fi

	\${UPDALT} \\
		\${UPDALT_ACTION} sqlcl.bundled \${INSTBINDIR}/sql.${UPSTREAMVER}.bundled

	RET=\${?}

	if [ \${RET} -ne 0 ] ; then
		printf "%s prerm - unexpected return code \"%d\"\n" "make-sqlcl-package" \${RET} >&2
		return \${RET}
	fi

	if ! [ -f "\${INSTBINDIR}/sqlcl.bundled" ] ; then
		\${UPDALT} \\
			\${UPDALT_ACTION} sqlcl \${INSTBINDIR}/sqlcl.bundled

		RET=\${?}

		if [ \${RET} -ne 0 ] ; then
			printf "%s prerm - unexpected return code \"%d\"\n" "make-sqlcl-package" \${RET} >&2
			return \${RET}
		fi
	fi
EOF
		) >>"${DEBIAN_WORKDIR}/${PROGNAME}-${UPSTREAMVER}.prerm"
	fi

	(
	${CAT} <<EOF

	return \${RET}
}

case "\${1}" in
	remove|upgrade|deconfigure|failed-upgrade)
		func_updalt_remove
		RET=\${?}
	;;
	*)
		printf "%s prerm - called with an unknown parameter\"%s\"\n" "make-sqlcl-package" "\${1}" >&2
		RET=1
	;;
esac

exit \${RET}
EOF
	) >>"${DEBIAN_WORKDIR}/${PROGNAME}-${UPSTREAMVER}.prerm" && ${CHMOD} ${CHMOD_OPTS_FUNC_DEB} "${DEBIAN_WORKDIR}/${PROGNAME}-${UPSTREAMVER}.prerm"

	if [ ${SILENT} -eq 0 ] ; then
		printf "done!\n"
		printf "\tdebian/%s.README.Debian ... " "${PROGNAME}-${UPSTREAMVER}"
	fi

	(
	${CAT} <<EOF
${PROGNAME} for Debian
-----------------------

In order to run Oracle SQL Developer you'll need a full working JDK. The
versions that are compatible with SQL Developer are any JDK 1.5.0_06 or above
or JDK 1.6.0_03 or above for SQL Developer versions up to 1.5.5. SQL Developer
versions from 2.1 to 3.1 are compatible with JDK 1.6.0_11 or above and SQL
Developer version 3.2 is compatible with JDK 1.6.0_04 or above. SQL Developer
version 4.0 is compatible with JDK 1.7 (JDK7.0) series and SQL Developer
versions from 4.1 to 17.3 are compatible with JDK 1.8 (JDK8.0) series or
newer.

Note that Oracle SQL Developer prior to version 4.0 is not compatible with JDK
1.7 (JDK7.0) or newer and prior to version 4.1 is not compatible with.JDK 1.8
(JDK8.0) or newer.

There are several ways to obtain a compatible JDK:

- install default-jdk (java), making sure it depends on the required JDK
  version
- install one of the required openjdk-6-jdk, openjdk-7-jdk, openjdk-8-jdk or
  openjdk-9-jdk (java)
- install the meta-package java-sdk, making sure that it installs the required
  JDK version as dependency
- install one of the meta-packages java6-sdk, java7-sdk, java8-sdk or
  java9-sdk, making sure that it installs the required JDK version as
  dependency
- download and run the installer for the version you wish to install from
  Oracle <http://www.oracle.com/technetwork/java/javase/downloads/>
- install java-package (contrib/misc) and generate a Debian package from the
  above installer

After installing a compatible JDK simply launch SQL Developer through the
graphical interface or by invoking /usr/bin/${PROGNAME}/${UPSTREAMVER} and
supply the path where the JDK was installed when prompted.

 -- Lazarus Long <lazarus.long@sapo.pt>  $(${DATE} ${DATE_OPTS_FUNC_DEB})
EOF
	) >"${DEBIAN_WORKDIR}/${PROGNAME}-${UPSTREAMVER}.README.Debian"

	if [ ${SILENT} -eq 0 ] ; then
		printf "done!\n"
		printf "\tdebian/%s.1 ... " "${PROGNAME}.${UPSTREAMVER}"
	fi

	(
	${CAT} <<EOF
.\\" ${PROGNAME}.${UPSTREAMVER}.1
.\\"
.\\" (2018-01-11)
.\\"
.\\" Copyright © 2009-2018 Lazarus Long <lazarus (dot) long (at) sapo (dot) pt>
.\\"
.\\".\\".\\".\\".\\".\\".\\".\\".\\".\\".\\".\\".\\".\\".\\".\\".\\".\\".\\".\\".\\".\\".\\".\\".\\".\\"
.\\"  This program is free software: you can redistribute it and/or modify  .\\"
.\\"  it under the terms of the GNU General Public License as published by  .\\"
.\\"  the Free Software Foundation, either version 3 of the License, or     .\\"
.\\"  (at your option) any later version.                                   .\\"
.\\"                                                                        .\\"
.\\"  This program is distributed in the hope that it will be useful,       .\\"
.\\"  but WITHOUT ANY WARRANTY; without even the implied warranty of        .\\"
.\\"  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         .\\"
.\\"  GNU General Public License for more details.                          .\\"
.\\"                                                                        .\\"
.\\"  You should have received a copy of the GNU General Public License     .\\"
.\\"  along with this program.  If not, see <http://www.gnu.org/licenses/>. .\\"
.\\".\\".\\".\\".\\".\\".\\".\\".\\".\\".\\".\\".\\".\\".\\".\\".\\".\\".\\".\\".\\".\\".\\".\\".\\".\\"
.\\"
.\\" Debian package builder and installer for Oracle SQL Developer
.\\"
.\\"
.TH SQLDEVELOPER.${UPSTREAMVER} 1 2018-01-11 Oracle "Oracle SQL Developer"
.\\"
.SH NAME
${PROGNAME}.${UPSTREAMVER} \\- Oracle SQL Developer
.\\"
.SH SYNOPSIS
.B ${PROGNAME},${UPSTREAMVER}
.RI [options]\\  [[file]\\ \\...]
.PP
.B ${PROGNAME}
.RI [options]\\  [[file]\\ \\...]
.\\"
.SH DESCRIPTION
\\fB${PROGNAME}.${UPSTREAMVER}\\fP is a \\fIJava\\fP utility that allows one
to develop for and administer \\fIOracle\\fP databases.
.PP
The \\fIOracle SQL Developer\\fP program is governed by the copyright holder
(\\fIOracle USA, Inc.\\fP), it is your responsibility to use it accordingly to
the OTN license, a copy of which is included in "\\fI/usr/share/doc/sqldeveloper\\fP".
.\\"
.SH OPTIONS
.PP
.B The following commands must appear first:
.TP
\\fB\\-verbose\\fP
Show java command line options
.TP
\\fB\\-conf[igure]\\fP \\fI<fname>\\fP
Use the specified configuration file
.PP
.B The following commands must appear last:
.TP
\\fB\\-classic\\fP
Use Classic as the Java VM
.TP
\\fB\\-hotspot\\fP
Use Hotspot client as the Java VM
.TP
\\fB\\-server\\fP
Use Hotspot server as the Java VM
.TP
\\fB\\-client\\fP
Use Hotspot client as the Java VM
.TP
\\fB\\-\\-<directive>=\\fP\\fI<value>\\fP
Override a directive from the configuration file
.TP
\\fB\\-J\\fP\\fI<flag>\\fP
Pass <flag> directly to the runtime system
.TP
\\fB\\-migrate\\fP
Migrate user settings from a previous installation
.PP
.B The following commands must appear by themselves:
.TP
\\fB\\-help\\fP
Show the help screen
.TP
\\fB\\-version\\fP
Display SQL Developer version
.PP
.TP
\\fB[[file] ...]\\fP
One or more SQL files specified with their full pathname(s)
.\\"
.SH AUTHOR
\\fBOracle SQL Developer\\fP is copyright by \\fIOracle USA, Inc.\\fP
.PP
The \\fB${PROGNAME}.${UPSTREAMVER}\\fP wrapper for the Debian package was written by \\fILazarus
Long <lazarus.long@sapo.pt>\\fP.
.PP
This manual page was written by \\fILazarus Long <lazarus.long@sapo.pt>\\fP,
for the Debian project (but may be used by others).
EOF
	) >"${DEBIAN_WORKDIR}/${PROGNAME}.${UPSTREAMVER}.1"

	if [ ${SILENT} -eq 0 ] ; then
		printf "done!\n"
	fi

	if [ ${SDCLI} -ne 0 ] ; then
		if [ ${SILENT} -eq 0 ] ; then
			printf "\tdebian/%s.1 ... " "sdcli.${UPSTREAMVER}"
		fi

		(
		${CAT} <<EOF
.\\" sdcli.${UPSTREAMVER}.1
.\\"
.\\" (2018-01-11)
.\\"
.\\" Copyright © 2017-2018 Lazarus Long <lazarus (dot) long (at) sapo (dot) pt>
.\\"
.\\".\\".\\".\\".\\".\\".\\".\\".\\".\\".\\".\\".\\".\\".\\".\\".\\".\\".\\".\\".\\".\\".\\".\\".\\".\\"
.\\"  This program is free software: you can redistribute it and/or modify  .\\"
.\\"  it under the terms of the GNU General Public License as published by  .\\"
.\\"  the Free Software Foundation, either version 3 of the License, or     .\\"
.\\"  (at your option) any later version.                                   .\\"
.\\"                                                                        .\\"
.\\"  This program is distributed in the hope that it will be useful,       .\\"
.\\"  but WITHOUT ANY WARRANTY; without even the implied warranty of        .\\"
.\\"  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         .\\"
.\\"  GNU General Public License for more details.                          .\\"
.\\"                                                                        .\\"
.\\"  You should have received a copy of the GNU General Public License     .\\"
.\\"  along with this program.  If not, see <http://www.gnu.org/licenses/>. .\\"
.\\".\\".\\".\\".\\".\\".\\".\\".\\".\\".\\".\\".\\".\\".\\".\\".\\".\\".\\".\\".\\".\\".\\".\\".\\".\\"
.\\"
.\\" Debian package builder and installer for Oracle SQL Developer
.\\"
.\\"
.TH SDCLI.${UPSTREAMVER} 1 2018-01-11 Oracle "Oracle CLI for SQL Developer"
.\\"
.SH NAME
sdcli.${UPSTREAMVER} \\- Oracle CLI for SQL Developer
.\\"
.SH SYNOPSIS
.B sdcli.${UPSTREAMVER}
.RI [options]\\ <feature>\\ [<command>]\\ [[\\-h|\\-help]|argument\\ \\...]
.\\"
.SH DESCRIPTION
\\fB${PROGNAME}\\fP is a \\fIJava\\fP utility that allows one to develop for
and administer \\fIOracle\\fP databases.
.PP
\\fBsdcli\\fP is a command line utility that exposes several internal\\fIOracle
SQL Developer\\fP commands , to interact either with a new or already existing
\\fI Oracle SQl Developer\\fP instance, for example, on headless systems of for
scripting purposes.
.PP
The \\fIOracle SQL Developer\\fP program is governed by the copyright holder
(\\fIOracle USA, Inc.\\fP), it is your responsibility to use it accordingly to
the OTN license, a copy of which is included in "\\fI/usr/share/doc/sqldeveloper\\fP".
.\\"
.SH OPTIONS
.PP
.B The following options must appear first:
.TP
\\fB\\-verbose\\fP
Show java command line options
.TP
\\fB\\-conf[igure]\\fP \\fI<fname>\\fP
Use the specified configuration file
.PP
.B The following options must appear last:
.TP
\\fB\\-classic\\fP
Use Classic as the Java VM
.TP
\\fB\\-hotspot\\fP
Use Hotspot client as the Java VM
.TP
\\fB\\-server\\fP
Use Hotspot server as the Java VM
.TP
\\fB\\-client\\fP
Use Hotspot client as the Java VM
.TP
\\fB\\-\\-<directive>=\\fP\\fI<value>\\fP
Override a directive from the configuration file
.TP
\\fB\\-J\\fP\\fI<flag>\\fP
Pass <flag> directly to the runtime system
.TP
\\fB\\-migrate\\fP
Migrate user settings from a previous installation
.PP
.B The following features are available:
.TP
\\fBcart\\fP
Database cart batch tasks
.TP
\\fBdba\\fP
Basic batch DBA tasks
.TP
\\fBformat\\fP
Format Task
.TP
\\fBmigration\\fP
Database migration tasks
.TP
\\fBreports\\fP
Basic batch reporting tasks
.TP
\\fBunittest\\fP
Unit testing batch tasks
.TP
\\fButility\\fP
Utility import task
.PP
Feature \\fBCART\\fP usage:
.PP
\\fBcart\\fP \\fI<command>\\fP \\fB-h\\fP|\\fB-help\\fP
.PP
\\fBcart\\fP \\fI<command>\\fP \\fI<arguments>\\fP
.PP
Supported commands: \\fBexport\\fP | \\fBcloud\\fP | \\fBcopy\\fP
.PP
Feature \\fBDBA\\fP usage:
.PP
\\fBdba\\fP \\fI<command>\\fP \\fB-h\\fP|\\fB-help\\fP
.PP
\\fBdba\\fP \\fI<command>\\fP \\fI<arguments>\\fP
.PP
Supported commands: \\fBdbcopy\\fP
.PP
Feature \\fBFORMAT\\fP usage:
.PP
\\fBformat\\fP
.PP
Feature \\fBMIGRATION\\fP usage:
.PP
\\fBmigration\\fP \\fB-h\\fP|\\fB-help\\fP=\\fI<command> [,<command> ...]\\fP
.PP
\\fBmigration\\fP \\fB-actions=\\fP\\fI<command> [,<command> ...]\\fP \\fI<arguments>\\fP
.PP
Supported commands: \\fBcapture\\fP | \\fBconvert\\fP | \\fBdatamove\\fP | \\fBdelcaptured\\fP | \\fBdelconn\\fP | \\fBdelconverted\\fP | \\fBdriver\\fP | \\fBgenerate\\fP | \\fBguide\\fP | \\fBidmap\\fP | \\fBinfo\\fP | \\fBinit\\fP | \\fBlscaptured\\fP | \\fBlsconn\\fP | \\fBlsconverted\\fP | \\fBmkconn\\fP | \\fBqm\\fP | \\fBrunsql\\fP | \\fBscan\\fP | \\fBtranslate\\fP
.PP
Feature \\fBREPORTS\\fP usage:
.PP
\\fBcart\\fP \\fI<command>\\fP \\fI<arguments>\\fP
.PP
Supported commands: \\fBgenerate\\fP
.PP
Feature \\fBUNITTEST\\fP usage:
.PP
\\fBunittest\\fP \\fI?\\fP | [\\fI<command>\\fP \\fB?\\fP]
.PP
\\fBunittest\\fP \\fI<command>\\fP \\fI<arguments>\\fP
.PP
Supported commands: \\fB-run\\fP | \\fB-exp\\fP | \\fB-imp\\fP
.PP
Feature \\fBUTILITY\\fP usage:
.PP
\\fBcart\\fP \\fI<command>\\fP \\fB-h\\fP|\\fB-help\\fP
.PP
\\fBcart\\fP \\fI<command>\\fP \\fI<arguments>\\fP
.PP
Supported commands: \\fBimport\\fP
.\\"
.SH AUTHOR
\\fBOracle SQL Developer\\fP is copyright by \\fIOracle USA, Inc.\\fP
.PP
This manual page was written by \\fILazarus Long <lazarus.long@sapo.pt>\\fP,
for the Debian project (but may be used by others).
EOF
		) >"${DEBIAN_WORKDIR}/sdcli.${UPSTREAMVER}.1"

		if [ ${SILENT} -eq 0 ] ; then
			printf "done!\n"
		fi
	fi

	if [ ${SQLCL} -ne 0 ] ; then
		if [ ${SILENT} -eq 0 ] ; then
			printf "\tdebian/%s.1 ... " "sql.${UPSTREAMVER}.bundled"
		fi

		(
		${CAT} <<EOF
.\\" sql.${UPSTREAMVER}.bundled.1
.\\"
.\\" (2018-01-11)
.\\"
.\\" Copyright © 2017-2018 Lazarus Long <lazarus (dot) long (at) sapo (dot) pt>
.\\"
.\\".\\".\\".\\".\\".\\".\\".\\".\\".\\".\\".\\".\\".\\".\\".\\".\\".\\".\\".\\".\\".\\".\\".\\".\\".\\"
.\\"  This program is free software: you can redistribute it and/or modify  .\\"
.\\"  it under the terms of the GNU General Public License as published by  .\\"
.\\"  the Free Software Foundation, either version 3 of the License, or     .\\"
.\\"  (at your option) any later version.                                   .\\"
.\\"                                                                        .\\"
.\\"  This program is distributed in the hope that it will be useful,       .\\"
.\\"  but WITHOUT ANY WARRANTY; without even the implied warranty of        .\\"
.\\"  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         .\\"
.\\"  GNU General Public License for more details.                          .\\"
.\\"                                                                        .\\"
.\\"  You should have received a copy of the GNU General Public License     .\\"
.\\"  along with this program.  If not, see <http://www.gnu.org/licenses/>. .\\"
.\\".\\".\\".\\".\\".\\".\\".\\".\\".\\".\\".\\".\\".\\".\\".\\".\\".\\".\\".\\".\\".\\".\\".\\".\\".\\"
.\\"
.\\" Debian package builder and installer for Oracle SQL Developer Command-Line
.\\"
.\\"
.TH SQL.${UPSTREAMVER}.BUNDLED 1 2018-01-11 Oracle "Oracle SQL Developer Command-Line"
.\\"
.SH NAME
sql.${UPSTREAMVER}.bundled \\- Oracle SQL Developer Command-Line
.\\"
.SH SYNOPSIS
.PP
\\fIUsage 1:\\fP
.PP
.B sql.${UPSTREAMVER}.bundled
.RI -H\\  |\\  -V
.PP
.B sqlcl
.RI -H\\  |\\  -V
.PP
\\fIUsage 2:\\fP
.PP
.B sql.${UPSTREAMVER}.bundled
.RI [\\fB<option>\\fP] \\  [{\\fB<logon>\\fP\\  |\\  /nolog}]\\  [\\fB<start>\\fP]
.PP
.B sqlcl
.RI [\\fB<option>\\fP] \\  [{\\fB<logon>\\fP\\  |\\  /nolog}]\\  [\\fB<start>\\fP]
.\\"
.SH DESCRIPTION
\\fBsql.${UPSTREAMVER}.bundled\\fP is a \\fIJava\\fP utility that allows one to develop
for and administer \\fIOracle\\fP databases.
.PP
\\fIOracle SQL Developer Command-Line\\fP (\\fISQLcl\\fP) is a free command
line interface for \\fIOracle Database\\fP. It allows you to interactively or
batch execute \\fISQL\\fP and \\fIPL/SQL\\fP. \\fISQLcl\\fP provides in-line
editing, statement completion, and command recall for a feature-rich
experience, all while also supporting your previously written \\fISQL*Plus\\fP
scripts.
.PP
The \\fIOracle SQL Developer Command-Line \\fP program is governed by the
copyright holder (\\fIOracle USA, Inc.\\fP), it is your responsibility to use
it accordingly to the \\fI\\fBOTN\\fP license\\fP, a copy of which is included
in "\\fI/usr/share/doc/${PROGNAME}-${UPSTREAMVER}\\fP".
.\\"
.SH OPTIONS
.TP
\\fB\\-H\\fP
Displays the SQLcl version and the usage help.
.TP
\\fB\\-V\\fP
Displays the SQLcl version.
.PP
\\fB<option>\\fP is:
.RI [-R\\  <level>]\\  [-S]\\  [-verbose]\\  [-oci]\\  [-L[OGON]]a
.TP
\\fB\\-R\\fP \\fI<level>\\fP
Sets restricted mode to disable \\fISQLcl\\fP commands that interact with the
file system. The level can be \\fB1\\fP, \\fB2\\fP, \\fB3\\fP or \\fB4\\fP. The
most restrictive is -R 4 which disables all user commands interacting with the
file system.
.TP
\\fB-S\\fP
Sets silent mode which suppresses the display of the \\fISQLcl\\fP banner,
prompts, and echoing of commands.
.TP
\\fB-verbose\\fP
Set this to show logging messages inline. By default these messages are
suppressed.
.TP
\\fB-nohistory\\fP
Switch off history logging.
.TP
\\fB-noupdates\\fP
Do not check update site for newer versions available.
.TP
\\fB-oci\\fP
Set this to use an \\fIOracle Instant Client\\fP installation. If this option
is set, then \\fISQLcl\\fP will use the drivers from the first Installation on
the path.
.TP
\\fB-L\\fP[OGON]
Specifies not to reprompt for username or password if the initial connection
does not succeed.
.PP
\\fB<logon>\\fP is:
.RI {<username>[/<password>][@<connect_identifier>]\\  |\\  /}\\  [AS\\  
{SYSDBA\\  |\\  SYSOPER\\  |\\  SYSASM}]
.PP
Specifies the database account \\fBusername\\fP, \\fBpassword\\fP and
\\fBconnect identifier\\fP for the database connection. Without a connect
identifier, \\fISQLcl\\fP connects to the default database.
.PP
The \\fBAS SYSDBA\\fP, \\fBAS SYSOPER\\fP and \\fBAS SYSASM\\fP options are
database administration privileges.
.PP
\\fB<connect_identifier>\\fP can be in the form of \\fINet Service Name\\fP or
\\fIEasy Connect\\fP.
.PP
\\fB@\\fP[\\fB<net_service_name>\\fP\\ |\\ [//]\\fBHost\\fP[\\fB:Port\\fP]/\\fB<service_name>\\fP]
.PP
\\fI<net_service_name>\\fP is a simple name for a service that resolves to a
connect descriptor.
.PP
\\fBExample\\fP: Connect to database using \\fINet Service Name\\fP and the
database net service name is \\fBORCL\\fP.
.PP
\\fBsql.${UPSTREAMVER}.bundled\\fP myusername/mypassword@ORCL
.PP
\\fIHost\\fP specifies the host name or IP address of the database server
computer.
.PP
\\fIPort\\fP specifies the listening port on the database server.
.PP
\\fI<service_name>\\fP specifies the service name of the database you want to
access.
.PP
\\fBExample\\fP: Connect to database using \\fIEasy Connect\\fP and the Service
name is \\fBORCL\\fP.
.PP
\\fBsql.${UPSTREAMVER}.bundled\\fP myusername/mypassword@Host/ORCL
.PP
The \\fB/NOLOG\\fP option starts \\fISQLcl\\fP without connecting to a database.
.PP
\\fB<start>\\fP is:
.RI @<URL>\\ |\\ <filename>[.<ext>]\\  [<parameter>\\  \\...]
.PP
Runs the specified \\fISQLc\\fPl script from a web server (\\fBURL\\fP) or the
local file system (\\fBfilename.ext\\fP) with specified parameters that will be
assigned to substitution variables in the script.
.PP
When \\fISQLcl\\fP starts, and after \\fBCONNECT\\fP commands, the site profile
(e.g. \\fI\$ORACLE_HOME/sqlplus/admin/glogin.sql\\fP) and the user profile (e.g.
\\fIlogin.sql\\fP in the working directory) are run. The files may contain
\\fISQLcl\\fP commands.
.PP
Refer to the \\fISQLDeveloper User's Guide and Reference\\fP for more information.
.\\"
.SH AUTHOR
\\fBOracle SQL Developer Command-Line\\fP is copyright by \\fIOracle USA, Inc.\\fP
.PP
This manual page was written by \\fILazarus Long <lazarus.long@sapo.pt>\\fP,
for the Debian project (but may be used by others).
EOF
		) >"${DEBIAN_WORKDIR}/sql.${UPSTREAMVER}.bundled.1"

		if [ ${SILENT} -eq 0 ] ; then
			printf "done!\n"
		fi
	fi

	if [ ${SILENT} -eq 0 ] ; then
		printf "\tdebian/%s.bash ... " "${PROGNAME}.${UPSTREAMVER}"
	fi

	(
	${CAT} <<EOF
#!/bin/sh
set -e

# ${PROGNAME}.${UPSTREAMVER}

# (2018-01-11)

##########################################################################
#  This program is free software: you can redistribute it and/or modify  #
#  it under the terms of the GNU General Public License as published by  #
#  the Free Software Foundation, either version 3 of the License, or     #
#  (at your option) any later version.                                   #
#                                                                        #
#  This program is distributed in the hope that it will be useful,       #
#  but WITHOUT ANY WARRANTY; without even the implied warranty of        #
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         #
#  GNU General Public License for more details.                          #
#                                                                        #
#  You should have received a copy of the GNU General Public License     #
#  along with this program.  If not, see <http://www.gnu.org/licenses/>. #
##########################################################################

# Launcher for Oracle SQL Developer

# Copyright: © 2009-2018 Lazarus Long <lazarus (dot) long (at) sapo (dot) pt>

PATH="/usr/bin:/bin:/${INSTDIR}/${PROGNAME}/${UPSTREAMVER}:/${INSTDIR}/${PROGNAME}/${UPSTREAMVER}/${PROGNAME}/bin:/${INSTDIR}/${PROGNAME}/${UPSTREAMVER}/jdev/bin"

BASENAME="basename"
CAT="cat"
CUT="cut"
GREP="grep"
MKDIR="mkdir"
RM="rm"
SED="sed"
TR="tr"
XTERM="x-terminal-emulator"

GREP_OPTS="-E"
MKDIR_OPTS="-p"
RM_OPTS="-f"
TR_OPTS="[[:upper:]] [[:lower:]]"
XTERM_OPTS="-e"

INVOCATION="\$(\${BASENAME} "\${0}")"
SQLDEVHOME="\${HOME}/.${PROGNAME}"
SQLDEVDIR="/${INSTDIR}/${PROGNAME}/${UPSTREAMVER}"
SQLDEVELOPER="\${SQLDEVDIR}/${PROGNAME}.sh"

func_version() {
	CUT_OPTS_FUNC_VER="-d = -f 2"

	VERSIONFILE="\${SQLDEVDIR}/${PROGNAME}/bin/version.properties"
	VERSION="0.0.0"

	if [ -e "\${VERSIONFILE}" ] ; then
		VERSION="\$(\${GREP} \${GREP_OPTS} "VER_FULL" "\${VERSIONFILE}" |\${CUT} \${CUT_OPTS_FUNC_VER})"
	else
		VERSIONFILE="\${SQLDEVDIR}/jdev/bin/version.properties"

		if [ -e "\${VERSIONFILE}" ] ; then
			VERSION="\$(\${GREP} \${GREP_OPTS} "VER_FULL" "\${VERSIONFILE}" |\${CUT} \${CUT_OPTS_FUNC_VER})"
		else
			printf "\${INVOCATION} - func_version(): File \\"%s\\" not found, returning...\\n" "\${VERSIONFILE}" >&2
			return 1
		fi
	fi

	VERSIONMAJ="\${VERSION%%.*}"
	VERSIONMIN="\${VERSION#*.}"
	VERSIONREV="\${VERSIONMIN#*.}"
	VERSIONMIN="\${VERSIONMIN%%.*}"
	VERSIONREV="\${VERSIONREV%%.*}"
}

func_setenv() {
	local WORKPATH="\${HOME}/.instantclient:\${HOME}/.sqldeveloper:/etc/instantclient:"
EOF
	) >"${DEBIAN_WORKDIR}/${PROGNAME}.${UPSTREAMVER}.bash"

	if [ ${SKIPLIB} -eq 0 -a ${CSVLIBS} -eq 1 -a ${LIBJNIDISPATCH} -eq 1 ] ; then
		local ARCH=${HOSTARCH}

		if [ ${HOSTARCH} = "amd64" ] ; then
			ARCH="x86_64"
		fi

		printf "\tLD_LIBRARY_PATH=\"${LIBSDIR}/${ARCH}-linux-gnu/${PROGNAME}/${UPSTREAMVER}:\${LD_LIBRARY_PATH%%:}:\"\n" >>"${DEBIAN_WORKDIR}/${PROGNAME}.${UPSTREAMVER}.bash"
	else
		printf "\tLD_LIBRARY_PATH=\${LD_LIBRARY_PATH%%:}:\"\n" >>"${DEBIAN_WORKDIR}/${PROGNAME}.${UPSTREAMVER}.bash"
	fi

	(
	${CAT} <<EOF
	ORACLE_PATH="\${WORKPATH}\${ORACLE_PATH%:}:"
	SQLPATH="\${WORKPATH}\${SQLPATH%:}:"

	export LD_LIBRARY_PATH ORACLE_PATH SQLPATH
	
	[ \${#ORACLE_HOME} -gt 0 ] && export ORACLE_HOME

	[ \${#TNS_ADMIN} -gt 0 ] && export TNS_ADMIN

	return 0
}

func_checkjdkpath() {
		CUT_OPTS_FUNC_CHKJDK="-f 2-"
		SED_OPTS_FUNC_CHKJDK="-i -e"

	if [ \${VERSIONMAJ} -lt 4 ] ; then
		JDKPATH="\${SQLDEVHOME}/jdk"
	else
		if [ \${VERSIONMAJ} -eq 17  -a \${VERSIONMIN} -lt 3 ] ; then
			JDKPATH="\${SQLDEVHOME}/4.2.0/product.conf"
		else
			JDKPATH="\${SQLDEVHOME}/\${VERSIONMAJ}.\${VERSIONMIN}.\${VERSIONREV}/product.conf"
		fi
	fi

	if ! [ -f "\${JDKPATH}" ] ; then
		\${MKDIR} \${MKDIR_OPTS} "\${SQLDEVHOME}"
		RUN="\${XTERM} \${XTERM_OPTS} \${SQLDEVELOPER}"
	else
		if [ \${VERSIONMAJ} -lt 4 ]  ; then 
			if ! [ -x "\$(\${CAT} \${JDKPATH})/bin/javac" ] ; then
				\${RM} \${RM_OPTS} "\${JDKPATH}"
				RUN="\${XTERM} \${XTERM_OPTS} \${SQLDEVELOPER}"
			else
				RUN="\${SQLDEVELOPER}"
			fi
		else
			if ! [ -x "\$(\${GREP} \${GREP_OPTS} "^SetJavaHome" \${JDKPATH} |\${CUT} \${CUT_OPTS_FUNC_CHKJDK} -d\\  )/bin/javac" ] ; then
				\${SED} \${SED_OPTS_FUNC_CHKJDK} 's/^SetJavaHome.*$//g' "\${JDKPATH}"
				RUN="\${XTERM} \${XTERM_OPTS} \${SQLDEVELOPER}"
			else
				RUN="\${SQLDEVELOPER}"
			fi
		fi
	fi
}

func_help() {
	\${@}
	printf "%b\\n" "The following commands must appear by themselves:\\n-help                  Show this screen\\n-version               Display SQL Developer version"
}

func_parseopts() {
	while [ \${#} -gt 0 ] ; do
		case "\$(printf "%s" \${1} |\${TR} \${TR_OPTS})" in
			-help|--help)
				func_help \${RUN} \${1}
				exit 0
			;;
			-version|--version)
				printf "\\nOracle SQL Developer: Release %s\\n" "\${VERSION}"
				exit 0
			;;
		esac

		shift
	done
}

func_main() {
	func_version
	func_setenv
	func_checkjdkpath
	func_parseopts "\${@}"
	\${RUN} "\${@}"
}

func_main "\${@}"

# EOF sqldeveloper
EOF
	) >>"${DEBIAN_WORKDIR}/${PROGNAME}.${UPSTREAMVER}.bash" && ${CHMOD} ${CHMOD_OPTS_FUNC_DEB} "${DEBIAN_WORKDIR}/${PROGNAME}.${UPSTREAMVER}.bash"

	if [ ${SILENT} -eq 0 ] ; then
		printf "done!\n"
		printf "\tdebian/%s.desktop ... " "${PROGNAME}.${UPSTREAMVER}"
	fi

	(
	${CAT} <<EOF
[Desktop Entry]
Version=1.0
Name=SQL Developer (${UPSTREAMVER})
Exec=/usr/bin/${PROGNAME}.${UPSTREAMVER}
Icon=/usr/share/pixmaps/${PROGNAME}.${UPSTREAMVER}.xpm
Type=Application
Comment=Oracle SQL Developer (${UPSTREAMVER})
X-KDE-StartupNotify=true
Terminal=false
Categories=Database;Office;Development;KDE;Qt
Keywords=Oracle,SQL,Development,DBA,Editor
EOF
	) >"${DEBIAN_WORKDIR}/${PROGNAME}.${UPSTREAMVER}.desktop"

	if [ ${SILENT} -eq 0 ] ; then
		printf "done!\n"
		printf "\tdebian/%s.xpm ... " "${PROGNAME}.${UPSTREAMVER}"
	fi

	${CONVERT} ${CONVERT_OPTS} "${1}/${INSTDIR}/${PROGNAME}/${UPSTREAMVER}/icon.png" "${DEBIAN_WORKDIR}/${PROGNAME}.${UPSTREAMVER}.xpm"

	if [ ${SILENT} -eq 0 ] ; then
		printf "done!\n"
	fi

	return 0
}

# Generate the Debian package
#
func_builddeb() {
	if [ ${#} -ne 1 ] ; then
		printf "Usage: func_builddeb() <directory>\n"
		return 1
	fi

	if [ ${NOBUILD} -ne 0 ] ; then
		return 0
	fi

	if [ ${SILENT} -eq 0 ] ; then
		printf "Building debian package(s) from %s v%s in \"%s\":\n" "${PROGNAME}" "${UPSTREAMVER}" "${CURDIR}"
	fi

	if ! [ -d "${1}/debian" ] ; then
		if [ ${SILENT} -eq 0 ] ; then
			printf "func_builddeb(): Directory \"%s/debian\" not found, aborting...\n" "${1}" >&2
		else
			printf "%s - func_builddeb(): Directory \"%s/debian\" not found, aborting...\n" "${INVOCATION}" "${1}" >&2
		fi

		exit 1
	fi

	local DEBUILD_OPTS="--no-lintian --no-tgz-check"

	if [ -n "${ROOTCMD}" ] ; then
		DEBUILD_OPTS="--rootcmd=${ROOTCMD} ${DEBUILD_OPTS}"
	fi

	local DEBUILD_OPTS_INDEP="${DEBUILD_OPTS} -- binary-indep"
	cd "${WORKDIR}"

	if [ ${SILENT} -eq 0 ] ; then
		printf "\t%s ... " "${PROGNAME}-${UPSTREAMVER}_${UPSTREAMVER}+${VERSION}-${LOCALVER}_all.deb"
	fi

	${DEBUILD} ${DEBUILD_OPTS_INDEP} >/dev/null 2>&1
	local RET=${?}

	if [ ${RET} -eq 0 ] ; then
		if [ ${SILENT} -eq 0 ] ; then
			printf "done!\n"
		fi
	else
		if [ ${SILENT} -eq 0 ] ; then
			printf "FAILED!\n"
		fi

		exit ${RET}
	fi

	if [ ${SKIPLIB} -eq 0 -a ${CSVLIBS} -eq 1 -a ${LIBJNIDISPATCH} -eq 1 ] ; then
		if [ "${HOSTARCH}" = "amd64" -o "${HOSTARCH}" = "i386" ] ; then
			if [ ${SILENT} -eq 0 ] ; then
				printf "\t%s ... " "${JNILIBNAME}-${UPSTREAMVER}_${JNISOVERSION}+${VERSION}-${LOCALVER}_${HOSTARCH}.deb"
			fi

			local DEBUILD_OPTS_HOSTARCH="${DEBUILD_OPTS} -- clean,binary-arch"
			local CP_OPTS_FUNC_BUILD="-a"
			local RM_OPTS_FUNC_BUILD="-rf"

			if [ -f "${1}/debian/${JNILIBNAME}-${UPSTREAMVER}.lintian-overrides.${HOSTARCH}" ] ; then
				${CP} ${CP_OPTS_FUNC_BUILD} "${1}/debian/${JNILIBNAME}-${UPSTREAMVER}.lintian-overrides.${HOSTARCH}" "${1}/debian/${JNILIBNAME}-${UPSTREAMVER}.lintian-overrides"
			fi

			${DEBUILD} ${DEBUILD_OPTS_HOSTARCH} >/dev/null 2>&1
			RET=${?}

			if [ ${RET} -eq 0 ] ; then
				if [ ${SILENT} -eq 0 ] ; then
					printf "done!\n"
				fi
			else
				if [ ${SILENT} -eq 0 ] ; then
					printf "FAILED!\n"
				fi

				exit ${RET}
			fi

			if [ -f "${1}/debian/${JNILIBNAME}-${UPSTREAMVER}.lintian-overrides" ] ; then
				${RM} ${RM_OPTS_FUNC_BUILD} "${1}/debian/${JNILIBNAME}-${UPSTREAMVER}.lintian-overrides"
			fi
		fi
	fi

	cd "${CURDIR}"

	if [ ${INSTALL} -eq 1 ] ; then
		local DPKG_OPTS_FUNC_BUILD="-i"

		if [ ${SILENT} -eq 0 ] ; then
			printf "Installing generated package(s):\n\t%s\n" "${PROGNAME}-${UPSTREAMVER}_${UPSTREAMVER}-${LOCALVER}_all.deb"
		fi

		${DPKG} ${DPKG_OPTS_FUNC_BUILD} "${CURDIR}/${PROGNAME-${UPSTREAMVER}}_${UPSTREAMVER}+${VERSION}-${LOCALVER}_all.deb"

		if [ ${SKIPLIB} -eq 0 -a ${CSVLIBS} -eq 1 -a ${LIBJNIDISPATCH} -eq 1 ] ; then
			if [ -f "${JNILIBNAME}-${UPSTREAMVER}_${JNISOVERSION}+${VERSION}-${LOCALVER}_${HOSTARCH}.deb" ] ; then
				if [ ${SILENT} -eq 0 ] ; then
					printf "\t%s\n" "${JNILIBNAME}-${UPSTREAMVER}_${JNISOVERSION}+${VERSION}-${LOCALVER}_${HOSTARCH}.deb"
				fi

				${DPKG} ${DPKG_OPTS_FUNC_BUILD} "${CURDIR}/${JNILIBNAME}-${UPSTREAMVER}_${JNISOVERSION}+${VERSION}-${LOCALVER}_${HOSTARCH}.deb"
			fi
		fi
	fi

	return 0
}

# Run the script
#
func_run() {
	func_trap
	func_opts "${@}"
	func_header
	func_flags
	func_workdir
	func_extract "${ARCHIVE}" "${WORKDIR}/${INSTDIR}"
	func_upstreamversion "${WORKDIR}"
	func_reorganize "${WORKDIR}"
	func_cleanup "${WORKDIR}"
	func_debianize "${WORKDIR}"
	func_builddeb "${WORKDIR}"

	return 0
}

func_run "${@}"

# EOF make-sqldeveloper-package