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
|
/*
* "$Id: portable.c 833 2010-12-30 00:00:50Z mike $"
*
* Portable package gateway for the ESP Package Manager (EPM).
*
* Copyright 1999-2010 by Easy Software Products.
*
* 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 2, 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.
*
* Contents:
*
* make_portable() - Make a portable software distribution package.
* clean_distfiles() - Remove temporary software distribution files...
* write_combined() - Write all of the distribution files in tar files.
* write_commands() - Write commands.
* write_common() - Write the common shell script header.
* write_confcheck() - Write the echo check to find the right echo options.
* write_depends() - Write dependencies.
* write_distfiles() - Write a software distribution...
* write_install() - Write the installation script.
* write_instfiles() - Write the installer files to the tar file...
* write_patch() - Write the patch script.
* write_remove() - Write the removal script.
* write_space_checks() - Write disk space checks for the installer.
*/
/*
* Include necessary headers...
*/
#include "epm.h"
/*
* Local functions...
*/
static void clean_distfiles(const char *directory, const char *prodname,
const char *platname, dist_t *dist,
const char *subpackage);
static int write_combined(const char *title, const char *directory,
const char *prodname, const char *platname,
dist_t *dist, const char **files,
time_t deftime, const char *setup,
const char *types);
static int write_commands(dist_t *dist, FILE *fp, int type,
const char *subpackage);
static FILE *write_common(dist_t *dist, const char *title,
int rootsize, int usrsize,
const char *filename, const char *subpackage);
static int write_confcheck(FILE *fp);
static int write_depends(const char *prodname, dist_t *dist, FILE *fp,
const char *subpackage);
static int write_distfiles(const char *directory, const char *prodname,
const char *platname, dist_t *dist,
time_t deftime, const char *subpackage);
static int write_install(dist_t *dist, const char *prodname,
int rootsize, int usrsize,
const char *directory,
const char *subpackage);
static int write_instfiles(tarf_t *tarfile, const char *directory,
const char *prodname, const char *platname,
const char **files, const char *destdir,
const char *subpackage);
static int write_patch(dist_t *dist, const char *prodname,
int rootsize, int usrsize,
const char *directory,
const char *subpackage);
static int write_remove(dist_t *dist, const char *prodname,
int rootsize, int usrsize,
const char *directory,
const char *subpackage);
static int write_space_checks(const char *prodname, FILE *fp,
const char *sw, const char *ss,
int rootsize, int usrsize);
/*
* 'make_portable()' - Make a portable software distribution package.
*/
int /* O - 1 = success, 0 = fail */
make_portable(const char *prodname, /* I - Product short name */
const char *directory,/* I - Directory for distribution files */
const char *platname, /* I - Platform name */
dist_t *dist, /* I - Distribution information */
struct utsname *platform, /* I - Platform information */
const char *setup, /* I - Setup GUI image */
const char *types) /* I - Setup GUI install types */
{
int i; /* Looping var */
int havepatchfiles; /* 1 if we have patch files, 0 otherwise */
time_t deftime; /* File creation time */
file_t *file; /* Software file */
static const char *distfiles[] = /* Distribution files */
{
"install",
"license",
"readme",
"remove",
"ss",
"sw",
NULL
};
static const char *patchfiles[] = /* Patch files */
{
"patch",
"license",
"pss",
"psw",
"readme",
"remove",
NULL
};
REF(platform);
if (Verbosity)
puts("Creating PORTABLE distribution...");
/*
* See if we need to make a patch distribution...
*/
for (i = dist->num_files, file = dist->files; i > 0; i --, file ++)
if (isupper((int)file->type))
break;
havepatchfiles = i > 0;
deftime = time(NULL);
/*
* Build the main package and all of the subpackages...
*/
if (write_distfiles(directory, prodname, platname, dist, deftime, NULL))
return (1);
for (i = 0; i < dist->num_subpackages; i ++)
if (write_distfiles(directory, prodname, platname, dist, deftime,
dist->subpackages[i]))
return (1);
/*
* Create the distribution archives...
*/
if (write_combined("distribution", directory, prodname, platname, dist,
distfiles, deftime, setup, types))
return (1);
if (havepatchfiles)
if (write_combined("patch", directory, prodname, platname, dist,
patchfiles, deftime, setup, types))
return (1);
/*
* Cleanup...
*/
if (!KeepFiles)
{
clean_distfiles(directory, prodname, platname, dist, NULL);
for (i = 0; i < dist->num_subpackages; i ++)
clean_distfiles(directory, prodname, platname, dist,
dist->subpackages[i]);
}
/*
* Return!
*/
return (0);
}
/*
* 'clean_distfiles()' - Remove temporary software distribution files...
*/
static void
clean_distfiles(const char *directory, /* I - Directory */
const char *prodname, /* I - Product name */
const char *platname, /* I - Platform name */
dist_t *dist, /* I - Distribution */
const char *subpackage) /* I - Subpackage */
{
char prodfull[255], /* Full name of product */
filename[1024]; /* Name of temporary file */
/*
* Figure out the full name of the distribution...
*/
if (subpackage)
snprintf(prodfull, sizeof(prodfull), "%s-%s", prodname, subpackage);
else
strlcpy(prodfull, prodname, sizeof(prodfull));
/*
* Remove the distribution files...
*/
if (Verbosity)
printf("Removing %s temporary files...\n", prodfull);
snprintf(filename, sizeof(filename), "%s/%s.install", directory, prodfull);
unlink(filename);
snprintf(filename, sizeof(filename), "%s/%s.license", directory, prodfull);
unlink(filename);
snprintf(filename, sizeof(filename), "%s/%s.patch", directory, prodfull);
unlink(filename);
snprintf(filename, sizeof(filename), "%s/%s.psw", directory, prodfull);
unlink(filename);
snprintf(filename, sizeof(filename), "%s/%s.psw", directory, prodfull);
unlink(filename);
snprintf(filename, sizeof(filename), "%s/%s.readme", directory, prodfull);
unlink(filename);
snprintf(filename, sizeof(filename), "%s/%s.remove", directory, prodfull);
unlink(filename);
snprintf(filename, sizeof(filename), "%s/%s.ss", directory, prodfull);
unlink(filename);
snprintf(filename, sizeof(filename), "%s/%s.sw", directory, prodfull);
unlink(filename);
}
/*
* 'write_combined()' - Write all of the distribution files in tar files.
*/
static int /* O - 0 on success, -1 on failure */
write_combined(const char *title, /* I - Title */
const char *directory, /* I - Output directory */
const char *prodname, /* I - Base product name */
const char *platname, /* I - Platform name */
dist_t *dist, /* I - Distribution */
const char **files, /* I - Files */
time_t deftime, /* I - Default timestamp */
const char *setup, /* I - Setup program */
const char *types) /* I - Setup types file */
{
int i; /* Looping var */
tarf_t *tarfile; /* Distribution tar file */
char tarfilename[1024], /* Name of tar file */
filename[1024]; /* Name of temporary file */
#ifdef __APPLE__
FILE *fp; /* Plist file... */
#endif /* __APPLE__ */
struct stat srcstat; /* Source file information */
const char *destdir; /* Destination directory */
const char *setup_img; /* Setup image name */
/*
* Figure out the filename...
*/
if (dist->release[0])
snprintf(tarfilename, sizeof(tarfilename), "%s/%s-%s-%s", directory,
prodname, dist->version, dist->release);
else
snprintf(tarfilename, sizeof(tarfilename), "%s/%s-%s", directory, prodname,
dist->version);
if (!strcmp(title, "patch"))
strlcat(tarfilename, "-patch", sizeof(tarfilename));
if (platname[0])
{
strlcat(tarfilename, "-", sizeof(tarfilename));
strlcat(tarfilename, platname, sizeof(tarfilename));
}
strlcat(tarfilename, ".tar.gz", sizeof(tarfilename));
/*
* Open output file...
*/
if ((tarfile = tar_open(tarfilename, 1)) == NULL)
{
fprintf(stderr, "epm: Unable to create output pipe to gzip -\n %s\n",
strerror(errno));
return (-1);
}
if (Verbosity)
printf("Writing %s archive:\n", title);
#ifdef __APPLE__
if (setup)
{
/*
* Create directories for the setup application...
*/
if (tar_header(tarfile, TAR_DIR, (mode_t)0755, (size_t)0, deftime, "root", "root",
"Install.app", NULL) < 0)
{
fprintf(stderr, "epm: Error writing directory header - %s\n",
strerror(errno));
tar_close(tarfile);
return (-1);
}
if (tar_header(tarfile, TAR_DIR, (mode_t)0755, (size_t)0, deftime, "root", "root",
"Install.app/Contents", NULL) < 0)
{
fprintf(stderr, "epm: Error writing directory header - %s\n",
strerror(errno));
tar_close(tarfile);
return (-1);
}
if (tar_header(tarfile, TAR_DIR, (mode_t)0755, (size_t)0, deftime, "root", "root",
"Install.app/Contents/MacOS", NULL) < 0)
{
fprintf(stderr, "epm: Error writing directory header - %s\n",
strerror(errno));
tar_close(tarfile);
return (-1);
}
if (tar_header(tarfile, TAR_DIR, (mode_t)0755, (size_t)0, deftime, "root", "root",
"Install.app/Contents/Resources", NULL) < 0)
{
fprintf(stderr, "epm: Error writing directory header - %s\n",
strerror(errno));
tar_close(tarfile);
return (-1);
}
/*
* Then copy the data files...
*/
snprintf(filename, sizeof(filename), "%s/setup.icns", DataDir);
stat(filename, &srcstat);
if (tar_header(tarfile, TAR_NORMAL, srcstat.st_mode & (~0222),
srcstat.st_size, srcstat.st_mtime, "root", "root",
"Install.app/Contents/Resources/setup.icns", NULL) < 0)
{
fprintf(stderr, "epm: Error writing file header - %s\n",
strerror(errno));
tar_close(tarfile);
return (-1);
}
if (tar_file(tarfile, filename) < 0)
{
fprintf(stderr, "epm: Error writing file data for setup.icns -\n %s\n",
strerror(errno));
tar_close(tarfile);
return (-1);
}
if (Verbosity)
printf(" %7.0fk setup.icns\n", (srcstat.st_size + 1023) / 1024.0);
snprintf(filename, sizeof(filename), "%s/setup.info", DataDir);
stat(filename, &srcstat);
if (tar_header(tarfile, TAR_NORMAL, srcstat.st_mode & (~0222),
srcstat.st_size, srcstat.st_mtime, "root", "root",
"Install.app/Contents/PkgInfo", NULL) < 0)
{
fprintf(stderr, "epm: Error writing file header - %s\n",
strerror(errno));
tar_close(tarfile);
return (-1);
}
if (tar_file(tarfile, filename) < 0)
{
fprintf(stderr, "epm: Error writing file data for PkgInfo -\n %s\n",
strerror(errno));
tar_close(tarfile);
return (-1);
}
if (Verbosity)
printf(" %7.0fk PkgInfo\n", (srcstat.st_size + 1023) / 1024.0);
snprintf(filename, sizeof(filename), "%s/%s.setup.plist", directory,
prodname);
if ((fp = fopen(filename, "w")) == NULL)
{
fprintf(stderr, "epm: Error writing %s -\n %s\n", filename,
strerror(errno));
tar_close(tarfile);
return (-1);
}
fprintf(fp, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"<plist version=\"0.9\">\n"
" <dict>\n"
" <key>CFBundleInfoDictionaryVersion</key>\n"
" <string>6.0</string>\n"
" <key>CFBundleExecutable</key>\n"
" <string>setup</string>\n"
" <key>CFBundleIdentifier</key>\n"
" <string>com.easysw.epm.setup</string>\n"
" <key>CFBundleVersion</key>\n"
" <string>%s</string>\n"
" <key>CFBundleDevelopmentRegion</key>\n"
" <string>English</string>\n"
" <key>NSHumanReadableCopyright</key>\n"
" <string>Copyright %s</string>\n"
" <key>CFAppleHelpAnchor</key>\n"
" <string>help</string>\n"
" <key>CFBundleName</key>\n"
" <string>Installer for %s</string>\n"
" <key>CFBundlePackageType</key>\n"
" <string>APPL</string>\n"
" <key>CFBundleSignature</key>\n"
" <string>FLTK</string>\n"
" <key>CFBundleIconFile</key>\n"
" <string>setup.icns</string>\n"
" <key>CFBundleShortVersionString</key>\n"
" <string>%s</string>\n"
" <key>CFBundleGetInfoString</key>\n"
" <string>%s, Copyright %s</string>\n"
" </dict>\n"
"</plist>\n",
dist->version,
dist->copyright,
dist->product,
dist->version,
dist->version, dist->copyright);
fclose(fp);
stat(filename, &srcstat);
if (tar_header(tarfile, TAR_NORMAL, srcstat.st_mode & (~0222),
srcstat.st_size, srcstat.st_mtime, "root", "root",
"Install.app/Contents/Info.plist", NULL) < 0)
{
fprintf(stderr, "epm: Error writing file header - %s\n",
strerror(errno));
tar_close(tarfile);
return (-1);
}
if (tar_file(tarfile, filename) < 0)
{
fprintf(stderr, "epm: Error writing file data for Info.plist -\n %s\n",
strerror(errno));
tar_close(tarfile);
return (-1);
}
if (!KeepFiles)
unlink(filename);
if (Verbosity)
printf(" %7.0fk Info.plist\n", (srcstat.st_size + 1023) / 1024.0);
}
destdir = "Install.app/Contents/Resources/";
#else /* !__APPLE__ */
destdir = "";
#endif /* __APPLE__ */
/*
* Write installer files...
*/
if (write_instfiles(tarfile, directory, prodname, platname, files, destdir,
NULL))
{
tar_close(tarfile);
return (-1);
}
for (i = 0; i < dist->num_subpackages; i ++)
if (write_instfiles(tarfile, directory, prodname, platname, files, destdir,
dist->subpackages[i]))
{
tar_close(tarfile);
return (-1);
}
/*
* Now the setup files...
*/
if (setup)
{
/*
* Include the ESP Software Installation Wizard (setup)...
*/
if (stat(SetupProgram, &srcstat))
{
fprintf(stderr, "epm: Unable to stat GUI setup program %s - %s\n",
SetupProgram, strerror(errno));
tar_close(tarfile);
return (-1);
}
#ifdef __APPLE__
if (tar_header(tarfile, TAR_NORMAL, 0555, srcstat.st_size,
srcstat.st_mtime, "root", "root",
"Install.app/Contents/MacOS/setup", NULL) < 0)
#else
if (tar_header(tarfile, TAR_NORMAL, 0555, srcstat.st_size,
srcstat.st_mtime, "root", "root", "setup", NULL) < 0)
#endif /* __APPLE__ */
{
fprintf(stderr, "epm: Error writing file header - %s\n",
strerror(errno));
tar_close(tarfile);
return (-1);
}
if (tar_file(tarfile, SetupProgram) < 0)
{
fprintf(stderr, "epm: Error writing file data for setup -\n %s\n",
strerror(errno));
tar_close(tarfile);
return (-1);
}
if (Verbosity)
printf(" %7.0fk setup\n", (srcstat.st_size + 1023) / 1024.0);
/*
* And the image file...
*/
stat(setup, &srcstat);
if (strlen(setup) > 4 && !strcmp(setup + strlen(setup) - 4, ".gif"))
setup_img = "setup.gif";
else
setup_img = "setup.xpm";
snprintf(filename, sizeof(filename), "%s%s", destdir, setup_img);
if (tar_header(tarfile, TAR_NORMAL, 0444, srcstat.st_size,
srcstat.st_mtime, "root", "root", filename, NULL) < 0)
{
fprintf(stderr, "epm: Error writing file header - %s\n",
strerror(errno));
tar_close(tarfile);
return (-1);
}
if (tar_file(tarfile, setup) < 0)
{
fprintf(stderr, "epm: Error writing file data for %s -\n %s\n",
setup_img, strerror(errno));
tar_close(tarfile);
return (-1);
}
if (Verbosity)
printf(" %7.0fk %s\n", (srcstat.st_size + 1023) / 1024.0, setup_img);
/*
* And the types file...
*/
if (types)
{
stat(types, &srcstat);
snprintf(filename, sizeof(filename), "%ssetup.types", destdir);
if (tar_header(tarfile, TAR_NORMAL, 0444, srcstat.st_size,
srcstat.st_mtime, "root", "root", filename, NULL) < 0)
{
fprintf(stderr, "epm: Error writing file header - %s\n",
strerror(errno));
tar_close(tarfile);
return (-1);
}
if (tar_file(tarfile, types) < 0)
{
fprintf(stderr, "epm: Error writing file data for setup.types -\n %s\n",
strerror(errno));
tar_close(tarfile);
return (-1);
}
if (Verbosity)
printf(" %7.0fk setup.types\n", (srcstat.st_size + 1023) / 1024.0);
}
/*
* And finally the uninstall stuff...
*/
#ifdef __APPLE__
if (tar_header(tarfile, TAR_DIR, 0755, 0, deftime, "root", "root",
"Uninstall.app", NULL) < 0)
{
fprintf(stderr, "epm: Error writing directory header - %s\n",
strerror(errno));
tar_close(tarfile);
return (-1);
}
if (tar_header(tarfile, TAR_DIR, 0755, 0, deftime, "root", "root",
"Uninstall.app/Contents", NULL) < 0)
{
fprintf(stderr, "epm: Error writing directory header - %s\n",
strerror(errno));
tar_close(tarfile);
return (-1);
}
if (tar_header(tarfile, TAR_DIR, 0755, 0, deftime, "root", "root",
"Uninstall.app/Contents/MacOS", NULL) < 0)
{
fprintf(stderr, "epm: Error writing directory header - %s\n",
strerror(errno));
tar_close(tarfile);
return (-1);
}
if (tar_header(tarfile, TAR_DIR, 0755, 0, deftime, "root", "root",
"Uninstall.app/Contents/Resources", NULL) < 0)
{
fprintf(stderr, "epm: Error writing directory header - %s\n",
strerror(errno));
tar_close(tarfile);
return (-1);
}
/*
* Then copy the data files...
*/
snprintf(filename, sizeof(filename), "%s/uninst.icns", DataDir);
stat(filename, &srcstat);
if (tar_header(tarfile, TAR_NORMAL, srcstat.st_mode & (~0222),
srcstat.st_size, srcstat.st_mtime, "root", "root",
"Uninstall.app/Contents/Resources/uninst.icns", NULL) < 0)
{
fprintf(stderr, "epm: Error writing file header - %s\n",
strerror(errno));
tar_close(tarfile);
return (-1);
}
if (tar_file(tarfile, filename) < 0)
{
fprintf(stderr, "epm: Error writing file data for uninst.icns -\n %s\n",
strerror(errno));
tar_close(tarfile);
return (-1);
}
if (Verbosity)
printf(" %7.0fk uninst.icns\n", (srcstat.st_size + 1023) / 1024.0);
snprintf(filename, sizeof(filename), "%s/uninst.info", DataDir);
stat(filename, &srcstat);
if (tar_header(tarfile, TAR_NORMAL, srcstat.st_mode & (~0222),
srcstat.st_size, srcstat.st_mtime, "root", "root",
"Uninstall.app/Contents/PkgInfo", NULL) < 0)
{
fprintf(stderr, "epm: Error writing file header - %s\n",
strerror(errno));
tar_close(tarfile);
return (-1);
}
if (tar_file(tarfile, filename) < 0)
{
fprintf(stderr, "epm: Error writing file data for PkgInfo -\n %s\n",
strerror(errno));
tar_close(tarfile);
return (-1);
}
if (Verbosity)
printf(" %7.0fk PkgInfo\n", (srcstat.st_size + 1023) / 1024.0);
snprintf(filename, sizeof(filename), "%s/%s.uninst.plist", directory,
prodname);
if ((fp = fopen(filename, "w")) == NULL)
{
fprintf(stderr, "epm: Error writing %s -\n %s\n", filename,
strerror(errno));
tar_close(tarfile);
return (-1);
}
fprintf(fp, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"<plist version=\"0.9\">\n"
" <dict>\n"
" <key>CFBundleInfoDictionaryVersion</key>\n"
" <string>6.0</string>\n"
" <key>CFBundleExecutable</key>\n"
" <string>uninst</string>\n"
" <key>CFBundleIdentifier</key>\n"
" <string>com.easysw.epm.uninst</string>\n"
" <key>CFBundleVersion</key>\n"
" <string>%s</string>\n"
" <key>CFBundleDevelopmentRegion</key>\n"
" <string>English</string>\n"
" <key>NSHumanReadableCopyright</key>\n"
" <string>Copyright %s</string>\n"
" <key>CFAppleHelpAnchor</key>\n"
" <string>help</string>\n"
" <key>CFBundleName</key>\n"
" <string>Uninstaller for %s</string>\n"
" <key>CFBundlePackageType</key>\n"
" <string>APPL</string>\n"
" <key>CFBundleSignature</key>\n"
" <string>FLTK</string>\n"
" <key>CFBundleIconFile</key>\n"
" <string>uninst.icns</string>\n"
" <key>CFBundleShortVersionString</key>\n"
" <string>%s</string>\n"
" <key>CFBundleGetInfoString</key>\n"
" <string>%s, Copyright %s</string>\n"
" </dict>\n"
"</plist>\n",
dist->version,
dist->copyright,
dist->product,
dist->version,
dist->version, dist->copyright);
fclose(fp);
stat(filename, &srcstat);
if (tar_header(tarfile, TAR_NORMAL, srcstat.st_mode & (~0222),
srcstat.st_size, srcstat.st_mtime, "root", "root",
"Uninstall.app/Contents/Info.plist", NULL) < 0)
{
fprintf(stderr, "epm: Error writing file header - %s\n",
strerror(errno));
tar_close(tarfile);
return (-1);
}
if (tar_file(tarfile, filename) < 0)
{
tar_close(tarfile);
fprintf(stderr, "epm: Error writing file data for Info.plist -\n %s\n",
strerror(errno));
return (-1);
}
if (!KeepFiles)
unlink(filename);
if (Verbosity)
printf(" %7.0fk Info.plist\n", (srcstat.st_size + 1023) / 1024.0);
#endif /* __APPLE__ */
/*
* Include the ESP Software Removal Wizard (uninst)...
*/
if (stat(UninstProgram, &srcstat))
{
fprintf(stderr, "epm: Unable to stat GUI uninstall program %s - %s\n",
UninstProgram, strerror(errno));
tar_close(tarfile);
return (-1);
}
#ifdef __APPLE__
if (tar_header(tarfile, TAR_NORMAL, 0555, srcstat.st_size,
srcstat.st_mtime, "root", "root",
"Uninstall.app/Contents/MacOS/uninst", NULL) < 0)
#else
if (tar_header(tarfile, TAR_NORMAL, 0555, srcstat.st_size,
srcstat.st_mtime, "root", "root", "uninst", NULL) < 0)
#endif /* __APPLE__ */
{
fprintf(stderr, "epm: Error writing file header - %s\n",
strerror(errno));
tar_close(tarfile);
return (-1);
}
if (tar_file(tarfile, UninstProgram) < 0)
{
fprintf(stderr, "epm: Error writing file data for uninst -\n %s\n",
strerror(errno));
tar_close(tarfile);
return (-1);
}
if (Verbosity)
printf(" %7.0fk uninst\n", (srcstat.st_size + 1023) / 1024.0);
#ifdef __APPLE__
/*
* And the image file...
*/
stat(setup, &srcstat);
snprintf(filename, sizeof(filename), "Uninstall.app/Contents/Resources/%s",
setup_img);
if (tar_header(tarfile, TAR_NORMAL, 0444, srcstat.st_size,
srcstat.st_mtime, "root", "root", filename, NULL) < 0)
{
fprintf(stderr, "epm: Error writing file header - %s\n",
strerror(errno));
tar_close(tarfile);
return (-1);
}
if (tar_file(tarfile, setup) < 0)
{
fprintf(stderr, "epm: Error writing file data for %s -\n %s\n",
setup_img, strerror(errno));
tar_close(tarfile);
return (-1);
}
if (Verbosity)
printf(" %7.0fk %s\n", (srcstat.st_size + 1023) / 1024.0, setup_img);
#endif /* __APPLE__ */
}
if (Verbosity)
{
puts(" ------- ----------------------------------------");
printf(" %7.0fk %s-%s", tarfile->blocks * 0.5f, prodname, dist->version);
if (dist->release[0])
printf("-%s", dist->release);
if (!strcmp(title, "patch"))
fputs("-patch", stdout);
if (platname[0])
printf("-%s", platname);
puts(".tar");
}
tar_close(tarfile);
if (Verbosity)
{
stat(tarfilename, &srcstat);
puts(" ------- ----------------------------------------");
printf(" %7.0fk %s\n", (srcstat.st_size + 1023) / 1024.0,
tarfilename);
}
#ifdef __APPLE__
{
char dmgfilename[1024]; /* Disk image filename */
/*
* Make a disk image containing the package files...
*/
if (dist->release[0])
snprintf(filename, sizeof(filename), "%s/%s-%s-%s", directory, prodname,
dist->version, dist->release);
else
snprintf(filename, sizeof(filename), "%s/%s-%s", directory, prodname,
dist->version);
if (!strcmp(title, "patch"))
strlcat(filename, "-patch", sizeof(filename));
if (platname[0])
{
strlcat(filename, "-", sizeof(filename));
strlcat(filename, platname, sizeof(filename));
}
snprintf(dmgfilename, sizeof(dmgfilename), "%s.dmg", filename);
mkdir(filename, 0777);
if (run_command(filename, "tar xvzf ../%s", strrchr(tarfilename, '/') + 1))
{
fputs("epm: Unable to create disk image template folder!\n", stderr);
return (1);
}
if (run_command(NULL, "hdiutil create -ov -srcfolder %s %s",
filename, dmgfilename))
{
fputs("epm: Unable to create disk image!\n", stderr);
return (1);
}
if (!KeepFiles)
unlink_directory(filename);
if (Verbosity)
{
stat(dmgfilename, &srcstat);
printf(" %7.0fk %s\n", (srcstat.st_size + 1023) / 1024.0,
dmgfilename);
}
}
#endif /* __APPLE__ */
return (0);
}
/*
* 'write_commands()' - Write commands.
*/
static int /* O - 0 on success, -1 on failure */
write_commands(dist_t *dist, /* I - Distribution */
FILE *fp, /* I - File pointer */
int type, /* I - Type of commands to write */
const char *subpackage) /* I - Subsystem */
{
int i; /* Looping var */
command_t *c; /* Current command */
static const char *commands[] = /* Command strings */
{
"pre-install",
"post-install",
"pre-patch",
"post-patch",
"pre-remove",
"post-remove"
};
for (i = dist->num_commands, c = dist->commands; i > 0; i --, c ++)
if (c->type == type && c->subpackage == subpackage)
break;
if (i)
{
fprintf(fp, "echo Running %s commands...\n", commands[type]);
for (; i > 0; i --, c ++)
if (c->type == type && c->subpackage == subpackage)
if (fprintf(fp, "%s\n", c->command) < 1)
{
perror("epm: Error writing command");
return (-1);
}
}
return (0);
}
/*
* 'write_common()' - Write the common shell script header.
*/
static FILE * /* O - File pointer */
write_common(dist_t *dist, /* I - Distribution */
const char *title, /* I - "Installation", etc... */
int rootsize, /* I - Size of root files in kbytes */
int usrsize, /* I - Size of /usr files in kbytes */
const char *filename, /* I - Script to create */
const char *subpackage) /* I - Subpackage name */
{
int i; /* Looping var */
FILE *fp; /* File pointer */
char line[1024], /* Line buffer */
*start, /* Start of line */
*ptr; /* Pointer into line */
/*
* Remove any existing copy of the file...
*/
unlink(filename);
/*
* Create the script file...
*/
if ((fp = fopen(filename, "w")) == NULL)
return (NULL);
/*
* Update the permissions on the file...
*/
fchmod(fileno(fp), 0755);
/*
* Write the standard header...
*/
fputs("#!/bin/sh\n", fp);
fprintf(fp, "# %s script for %s version %s.\n", title,
dist->product, dist->version);
fputs("# Produced using " EPM_VERSION "; report problems to epm@easysw.com.\n",
fp);
fprintf(fp, "#%%product %s", dist->product);
if (subpackage)
{
for (i = 0; i < dist->num_descriptions; i ++)
if (dist->descriptions[i].subpackage == subpackage)
break;
if (i < dist->num_descriptions)
{
strlcpy(line, dist->descriptions[i].description, sizeof(line));
if ((ptr = strchr(line, '\n')) != NULL)
*ptr = '\0';
fprintf(fp, " - %s", line);
}
}
fputs("\n", fp);
fprintf(fp, "#%%vendor %s\n", dist->vendor);
fprintf(fp, "#%%copyright %s\n", dist->copyright);
fprintf(fp, "#%%version %s %d\n", dist->version, dist->vernumber);
for (i = 0; i < dist->num_descriptions; i ++)
if (dist->descriptions[i].subpackage == subpackage)
break;
if (i < dist->num_descriptions)
{
/*
* Just do descriptions for this subpackage...
*/
for (; i < dist->num_descriptions; i ++)
if (dist->descriptions[i].subpackage == subpackage)
{
strlcpy(line, dist->descriptions[i].description, sizeof(line));
for (start = line; start; start = ptr)
{
if ((ptr = strchr(start, '\n')) != NULL)
*ptr++ = '\0';
fprintf(fp, "#%%description %s\n", start);
}
}
}
else
{
/*
* Just do descriptions for the main package...
*/
for (i = 0; i < dist->num_descriptions; i ++)
if (dist->descriptions[i].subpackage == NULL)
{
strlcpy(line, dist->descriptions[i].description, sizeof(line));
for (start = line; start; start = ptr)
{
if ((ptr = strchr(start, '\n')) != NULL)
*ptr++ = '\0';
fprintf(fp, "#%%description %s\n", start);
}
}
}
fprintf(fp, "#%%rootsize %d\n", rootsize);
fprintf(fp, "#%%usrsize %d\n", usrsize);
fputs("#\n", fp);
fputs("PATH=/usr/xpg4/bin:/bin:/usr/bin:/usr/ucb:${PATH}\n", fp);
fputs("SHELL=/bin/sh\n", fp);
fputs("case \"`uname`\" in\n", fp);
fputs("\tDarwin*)\n", fp);
fputs("\tcase \"`id -un`\" in\n", fp);
fputs("\t\troot)\n", fp);
fputs("\t\t;;\n", fp);
fputs("\t\t*)\n", fp);
fprintf(fp, "\t\techo Sorry, you must have administrative priviledges to %s this software.\n",
title[0] == 'I' ? "install" : title[0] == 'R' ? "remove" : "patch");
fputs("\t\texit 1\n", fp);
fputs("\t\t;;\n", fp);
fputs("\tesac\n", fp);
fputs("\t;;\n", fp);
fputs("\t*)\n", fp);
fputs("\tcase \"`id`\" in\n", fp);
fputs("\t\tuid=0*)\n", fp);
fputs("\t\t;;\n", fp);
fputs("\t\t*)\n", fp);
fprintf(fp, "\t\techo Sorry, you must be root to %s this software.\n",
title[0] == 'I' ? "install" : title[0] == 'R' ? "remove" : "patch");
fputs("\t\texit 1\n", fp);
fputs("\t\t;;\n", fp);
fputs("\tesac\n", fp);
fputs("\t;;\n", fp);
fputs("esac\n", fp);
qprintf(fp, "echo Copyright %s\n", dist->copyright);
fprintf(fp, "# Reset umask for %s...\n",
title[0] == 'I' ? "install" : title[0] == 'R' ? "remove" : "patch");
fputs("umask 002\n", fp);
write_confcheck(fp);
/*
* Return the file pointer...
*/
return (fp);
}
/*
* 'write_confcheck()' - Write the echo check to find the right echo options.
*/
static int /* O - -1 on error, 0 on success */
write_confcheck(FILE *fp) /* I - Script file */
{
/*
* This is a simplified version of the autoconf test for echo; basically
* we ignore the Stardent Vistra SVR4 case, since 1) we've never heard of
* this OS, and 2) it doesn't provide the same functionality, specifically
* the omission of a newline when prompting the user for some text.
*/
fputs("# Determine correct echo options...\n", fp);
fputs("if (echo \"testing\\c\"; echo 1,2,3) | grep c >/dev/null; then\n", fp);
fputs(" ac_n=-n\n", fp);
fputs(" ac_c=\n", fp);
fputs("else\n", fp);
fputs(" ac_n=\n", fp);
fputs(" ac_c='\\c'\n", fp);
fputs("fi\n", fp);
/*
* This is a check for the correct options to use with the "tar"
* command.
*/
fputs("# Determine correct extract options for the tar command...\n", fp);
fputs("if test `uname` = Darwin; then\n", fp);
fputs(" ac_tar=\"tar -xpPf\"\n", fp);
fputs("else if test \"`tar --help 2>&1 | grep GNU`\" = \"\"; then\n", fp);
fputs(" ac_tar=\"tar -xpf\"\n", fp);
fputs("else\n", fp);
fputs(" ac_tar=\"tar -xpPf\"\n", fp);
fputs("fi fi\n", fp);
return (0);
}
/*
* 'write_depends()' - Write dependencies.
*/
static int /* O - 0 on success, - 1 on failure */
write_depends(const char *prodname, /* I - Product name */
dist_t *dist, /* I - Distribution */
FILE *fp, /* I - File pointer */
const char *subpackage) /* I - Subpackage */
{
int i; /* Looping var */
depend_t *d; /* Current dependency */
const char *product; /* Product/file to depend on */
static const char *depends[] = /* Dependency strings */
{
"requires",
"incompat",
"replaces",
"provides"
};
for (i = 0, d = dist->depends; i < dist->num_depends; i ++, d ++)
if (d->subpackage == subpackage)
{
if (!strcmp(d->product, "_self"))
product = prodname;
else
product = d->product;
fprintf(fp, "#%%%s %s %d %d\n", depends[(int)d->type], product,
d->vernumber[0], d->vernumber[1]);
switch (d->type)
{
case DEPEND_REQUIRES :
if (product[0] == '/')
{
/*
* Require a file...
*/
qprintf(fp, "if test ! -r %s -a ! -h %s; then\n",
product, product);
qprintf(fp, " echo Sorry, you must first install \\'%s\\'!\n",
product);
fputs(" exit 1\n", fp);
fputs("fi\n", fp);
}
else
{
/*
* Require a product...
*/
fprintf(fp, "if test ! -x %s/%s.remove; then\n",
SoftwareDir, product);
fprintf(fp, " if test -x %s.install; then\n",
product);
fprintf(fp, " echo Installing required %s software...\n",
product);
fprintf(fp, " ./%s.install now\n", product);
fputs(" else\n", fp);
fprintf(fp, " echo Sorry, you must first install \\'%s\\'!\n",
product);
fputs(" exit 1\n", fp);
fputs(" fi\n", fp);
fputs("fi\n", fp);
if (d->vernumber[0] > 0 || d->vernumber[1] < INT_MAX)
{
/*
* Do version number checking...
*/
fprintf(fp, "installed=`grep \'^#%%version\' "
"%s/%s.remove | awk \'{print $3}\'`\n",
SoftwareDir, product);
fputs("if test x$installed = x; then\n", fp);
fputs(" installed=0\n", fp);
fputs("fi\n", fp);
fprintf(fp, "if test $installed -lt %d -o $installed -gt %d; then\n",
d->vernumber[0], d->vernumber[1]);
fprintf(fp, " if test -x %s.install; then\n",
product);
fprintf(fp, " echo Installing required %s software...\n",
product);
fprintf(fp, " ./%s.install now\n", product);
fputs(" else\n", fp);
fprintf(fp, " echo Sorry, you must first install \\'%s\\' version %s to %s!\n",
product, d->version[0], d->version[1]);
fputs(" exit 1\n", fp);
fputs(" fi\n", fp);
fputs("fi\n", fp);
}
}
break;
case DEPEND_INCOMPAT :
if (product[0] == '/')
{
/*
* Incompatible with a file...
*/
qprintf(fp, "if test -r %s -o -h %s; then\n",
product, product);
qprintf(fp, " echo Sorry, this software is incompatible with \\'%s\\'!\n",
product);
fputs(" echo Please remove it first.\n", fp);
fputs(" exit 1\n", fp);
fputs("fi\n", fp);
}
else
{
/*
* Incompatible with a product...
*/
fprintf(fp, "if test -x %s/%s.remove; then\n",
SoftwareDir, product);
if (d->vernumber[0] > 0 || d->vernumber[1] < INT_MAX)
{
/*
* Do version number checking...
*/
fprintf(fp, " installed=`grep \'^#%%version\' "
"%s/%s.remove | awk \'{print $3}\'`\n",
SoftwareDir, product);
fputs(" if test x$installed = x; then\n", fp);
fputs(" installed=0\n", fp);
fputs(" fi\n", fp);
fprintf(fp, " if test $installed -ge %d -a $installed -le %d; then\n",
d->vernumber[0], d->vernumber[1]);
fprintf(fp, " echo Sorry, this software is incompatible with \\'%s\\' version %s to %s!\n",
product, d->version[0], d->version[1]);
fprintf(fp, " echo Please remove it first by running \\'%s/%s.remove\\'.\n",
SoftwareDir, product);
fputs(" exit 1\n", fp);
fputs(" fi\n", fp);
}
else
{
fprintf(fp, " echo Sorry, this software is incompatible with \\'%s\\'!\n",
product);
fprintf(fp, " echo Please remove it first by running \\'%s/%s.remove\\'.\n",
SoftwareDir, product);
fputs(" exit 1\n", fp);
}
fputs("fi\n", fp);
}
break;
case DEPEND_REPLACES :
fprintf(fp, "if test -x %s/%s.remove; then\n", SoftwareDir,
product);
if (d->vernumber[0] > 0 || d->vernumber[1] < INT_MAX)
{
/*
* Do version number checking...
*/
fprintf(fp, " installed=`grep \'^#%%version\' "
"%s/%s.remove | awk \'{print $3}\'`\n",
SoftwareDir, product);
fputs(" if test x$installed = x; then\n", fp);
fputs(" installed=0\n", fp);
fputs(" fi\n", fp);
fprintf(fp, " if test $installed -ge %d -a $installed -le %d; then\n",
d->vernumber[0], d->vernumber[1]);
fprintf(fp, " echo Automatically replacing \\'%s\\'...\n",
product);
fprintf(fp, " %s/%s.remove now\n",
SoftwareDir, product);
fputs(" fi\n", fp);
}
else
{
fprintf(fp, " echo Automatically replacing \\'%s\\'...\n",
product);
fprintf(fp, " %s/%s.remove now\n",
SoftwareDir, product);
}
fputs("fi\n", fp);
break;
}
}
return (0);
}
/*
* 'write_distfiles()' - Write a software distribution...
*/
static int /* O - -1 on error, 0 on success */
write_distfiles(const char *directory, /* I - Directory */
const char *prodname, /* I - Product name */
const char *platname, /* I - Platform name */
dist_t *dist, /* I - Distribution */
time_t deftime, /* I - Default file time */
const char *subpackage) /* I - Subpackage */
{
int i; /* Looping var */
int havepatchfiles; /* 1 if we have patch files, 0 otherwise */
tarf_t *tarfile; /* Distribution tar file */
char prodfull[255], /* Full name of product */
swname[255], /* Name of distribution tar file */
pswname[255], /* Name of patch tar file */
filename[1024]; /* Name of temporary file */
struct stat srcstat; /* Source file information */
file_t *file; /* Software file */
int rootsize, /* Size of files in root partition */
usrsize; /* Size of files in /usr partition */
int prootsize, /* Size of patch files in root partition */
pusrsize; /* Size of patch files in /usr partition */
/*
* Figure out the full name of the distribution...
*/
if (subpackage)
snprintf(prodfull, sizeof(prodfull), "%s-%s", prodname, subpackage);
else
strlcpy(prodfull, prodname, sizeof(prodfull));
/*
* See if we need to make a patch distribution...
*/
for (i = dist->num_files, file = dist->files; i > 0; i --, file ++)
if (isupper((int)file->type) && file->subpackage == subpackage)
break;
havepatchfiles = i > 0;
/*
* Copy the license and readme files...
*/
if (Verbosity)
printf("Copying %s license and readme files...\n", prodfull);
if (dist->license[0])
{
snprintf(filename, sizeof(filename), "%s/%s.license", directory, prodfull);
if (copy_file(filename, dist->license, 0444, getuid(), getgid()))
return (1);
}
if (dist->readme[0])
{
snprintf(filename, sizeof(filename), "%s/%s.readme", directory, prodfull);
if (copy_file(filename, dist->readme, 0444, getuid(), getgid()))
return (1);
}
/*
* Create the non-shared software distribution file...
*/
if (Verbosity)
puts("Creating non-shared software distribution file...");
snprintf(swname, sizeof(swname), "%s.sw", prodfull);
snprintf(filename, sizeof(filename), "%s/%s", directory, swname);
unlink(filename);
if ((tarfile = tar_open(filename, CompressFiles)) == NULL)
{
fprintf(stderr, "epm: Unable to create file \"%s\" -\n %s\n",
filename, strerror(errno));
return (1);
}
for (i = dist->num_files, file = dist->files, rootsize = 0, prootsize = 0;
i > 0;
i --, file ++)
if (strncmp(file->dst, "/usr", 4) != 0 && file->subpackage == subpackage)
switch (tolower(file->type))
{
case 'f' : /* Regular file */
case 'c' : /* Config file */
case 'i' : /* Init script */
if (stat(file->src, &srcstat))
{
fprintf(stderr, "epm: Cannot stat %s - %s\n", file->src,
strerror(errno));
tar_close(tarfile);
return (1);
}
rootsize += (srcstat.st_size + 1023) / 1024;
if (isupper(file->type & 255))
prootsize += (srcstat.st_size + 1023) / 1024;
/*
* Configuration files are extracted to the config file name with
* .N appended; add a bit of script magic to check if the config
* file already exists, and if not we copy the .N to the config
* file location...
*/
if (tolower(file->type) == 'c')
snprintf(filename, sizeof(filename), "%s.N", file->dst);
else if (tolower(file->type) == 'i')
snprintf(filename, sizeof(filename), "%s/init.d/%s", SoftwareDir,
file->dst);
else
strcpy(filename, file->dst);
if (Verbosity > 1)
printf("%s -> %s...\n", file->src, filename);
if (tar_header(tarfile, TAR_NORMAL, file->mode, srcstat.st_size,
srcstat.st_mtime, file->user, file->group,
filename, NULL) < 0)
{
fprintf(stderr, "epm: Error writing file header - %s\n",
strerror(errno));
tar_close(tarfile);
return (1);
}
if (tar_file(tarfile, file->src) < 0)
{
fprintf(stderr, "epm: Error writing file data - %s\n",
strerror(errno));
tar_close(tarfile);
return (1);
}
break;
case 'd' : /* Create directory */
if (Verbosity > 1)
printf("Directory %s...\n", file->dst);
rootsize ++;
if (isupper(file->type & 255))
prootsize ++;
break;
case 'l' : /* Link file */
if (Verbosity > 1)
printf("%s -> %s...\n", file->src, file->dst);
if (tar_header(tarfile, TAR_SYMLINK, file->mode, 0, deftime,
file->user, file->group, file->dst, file->src) < 0)
{
fprintf(stderr, "epm: Error writing link header - %s\n",
strerror(errno));
tar_close(tarfile);
return (1);
}
rootsize ++;
if (isupper(file->type & 255))
prootsize ++;
break;
}
tar_close(tarfile);
/*
* Create the shared software distribution file...
*/
if (Verbosity)
puts("Creating shared software distribution file...");
snprintf(swname, sizeof(swname), "%s.ss", prodfull);
snprintf(filename, sizeof(filename), "%s/%s", directory, swname);
unlink(filename);
if ((tarfile = tar_open(filename, CompressFiles)) == NULL)
{
fprintf(stderr, "epm: Unable to create file \"%s\" -\n %s\n",
filename, strerror(errno));
return (1);
}
for (i = dist->num_files, file = dist->files, usrsize = 0, pusrsize = 0;
i > 0;
i --, file ++)
if (strncmp(file->dst, "/usr", 4) == 0 && file->subpackage == subpackage)
switch (tolower(file->type))
{
case 'f' : /* Regular file */
case 'c' : /* Config file */
case 'i' : /* Init script */
if (stat(file->src, &srcstat))
{
fprintf(stderr, "epm: Cannot stat %s - %s\n", file->src,
strerror(errno));
tar_close(tarfile);
return (1);
}
usrsize += (srcstat.st_size + 1023) / 1024;
if (isupper(file->type & 255))
pusrsize += (srcstat.st_size + 1023) / 1024;
/*
* Configuration files are extracted to the config file name with
* .N appended; add a bit of script magic to check if the config
* file already exists, and if not we copy the .N to the config
* file location...
*/
if (tolower(file->type) == 'c')
snprintf(filename, sizeof(filename), "%s.N", file->dst);
else if (tolower(file->type) == 'i')
snprintf(filename, sizeof(filename), "%s/init.d/%s", SoftwareDir,
file->dst);
else
strcpy(filename, file->dst);
if (Verbosity > 1)
printf("%s -> %s...\n", file->src, filename);
if (tar_header(tarfile, TAR_NORMAL, file->mode, srcstat.st_size,
srcstat.st_mtime, file->user, file->group,
filename, NULL) < 0)
{
fprintf(stderr, "epm: Error writing file header - %s\n",
strerror(errno));
tar_close(tarfile);
return (1);
}
if (tar_file(tarfile, file->src) < 0)
{
fprintf(stderr, "epm: Error writing file data - %s\n",
strerror(errno));
tar_close(tarfile);
return (1);
}
break;
case 'd' : /* Create directory */
if (Verbosity > 1)
printf("%s...\n", file->dst);
usrsize ++;
if (isupper(file->type & 255))
pusrsize ++;
break;
case 'l' : /* Link file */
if (Verbosity > 1)
printf("%s -> %s...\n", file->src, file->dst);
if (tar_header(tarfile, TAR_SYMLINK, file->mode, 0, deftime,
file->user, file->group, file->dst, file->src) < 0)
{
fprintf(stderr, "epm: Error writing link header - %s\n",
strerror(errno));
tar_close(tarfile);
return (1);
}
usrsize ++;
if (isupper(file->type & 255))
pusrsize ++;
break;
}
tar_close(tarfile);
/*
* Create the patch distribution files...
*/
if (havepatchfiles)
{
if (Verbosity)
puts("Creating non-shared software patch file...");
snprintf(pswname, sizeof(pswname), "%s.psw", prodfull);
snprintf(filename, sizeof(filename), "%s/%s", directory, pswname);
unlink(filename);
if ((tarfile = tar_open(filename, CompressFiles)) == NULL)
{
fprintf(stderr, "epm: Unable to create file \"%s\" -\n %s\n",
filename, strerror(errno));
return (1);
}
for (i = dist->num_files, file = dist->files; i > 0; i --, file ++)
if (strncmp(file->dst, "/usr", 4) != 0 && file->subpackage == subpackage)
switch (file->type)
{
case 'C' : /* Config file */
case 'F' : /* Regular file */
case 'I' : /* Init script */
if (stat(file->src, &srcstat))
{
fprintf(stderr, "epm: Cannot stat %s - %s\n", file->src,
strerror(errno));
tar_close(tarfile);
return (1);
}
/*
* Configuration files are extracted to the config file name with
* .N appended; add a bit of script magic to check if the config
* file already exists, and if not we copy the .N to the config
* file location...
*/
if (file->type == 'C')
snprintf(filename, sizeof(filename), "%s.N", file->dst);
else if (file->type == 'I')
snprintf(filename, sizeof(filename), "%s/init.d/%s", SoftwareDir,
file->dst);
else
strcpy(filename, file->dst);
if (Verbosity > 1)
printf("%s -> %s...\n", file->src, filename);
if (tar_header(tarfile, TAR_NORMAL, file->mode, srcstat.st_size,
srcstat.st_mtime, file->user, file->group,
filename, NULL) < 0)
{
fprintf(stderr, "epm: Error writing file header - %s\n",
strerror(errno));
tar_close(tarfile);
return (1);
}
if (tar_file(tarfile, file->src) < 0)
{
fprintf(stderr, "epm: Error writing file data - %s\n",
strerror(errno));
tar_close(tarfile);
return (1);
}
break;
case 'd' : /* Create directory */
if (Verbosity > 1)
printf("%s...\n", file->dst);
break;
case 'L' : /* Link file */
if (Verbosity > 1)
printf("%s -> %s...\n", file->src, file->dst);
if (tar_header(tarfile, TAR_SYMLINK, file->mode, 0, deftime,
file->user, file->group, file->dst, file->src) < 0)
{
fprintf(stderr, "epm: Error writing link header - %s\n",
strerror(errno));
tar_close(tarfile);
return (1);
}
break;
}
tar_close(tarfile);
if (Verbosity)
puts("Creating shared software patch file...");
snprintf(pswname, sizeof(pswname), "%s.pss", prodfull);
snprintf(filename, sizeof(filename), "%s/%s", directory, pswname);
unlink(filename);
if ((tarfile = tar_open(filename, CompressFiles)) == NULL)
{
fprintf(stderr, "epm: Unable to create file \"%s\" -\n %s\n",
filename, strerror(errno));
return (1);
}
for (i = dist->num_files, file = dist->files; i > 0; i --, file ++)
if (strncmp(file->dst, "/usr", 4) == 0 && file->subpackage == subpackage)
switch (file->type)
{
case 'C' : /* Config file */
case 'F' : /* Regular file */
case 'I' : /* Init script */
if (stat(file->src, &srcstat))
{
fprintf(stderr, "epm: Cannot stat %s - %s\n", file->src,
strerror(errno));
tar_close(tarfile);
return (1);
}
/*
* Configuration files are extracted to the config file name with
* .N appended; add a bit of script magic to check if the config
* file already exists, and if not we copy the .N to the config
* file location...
*/
if (file->type == 'C')
snprintf(filename, sizeof(filename), "%s.N", file->dst);
else if (file->type == 'I')
snprintf(filename, sizeof(filename), "%s/init.d/%s",
SoftwareDir, file->dst);
else
strcpy(filename, file->dst);
if (Verbosity > 1)
printf("%s -> %s...\n", file->src, filename);
if (tar_header(tarfile, TAR_NORMAL, file->mode, srcstat.st_size,
srcstat.st_mtime, file->user, file->group,
filename, NULL) < 0)
{
fprintf(stderr, "epm: Error writing file header - %s\n",
strerror(errno));
tar_close(tarfile);
return (1);
}
if (tar_file(tarfile, file->src) < 0)
{
fprintf(stderr, "epm: Error writing file data - %s\n",
strerror(errno));
tar_close(tarfile);
return (1);
}
break;
case 'd' : /* Create directory */
if (Verbosity > 1)
printf("%s...\n", file->dst);
break;
case 'L' : /* Link file */
if (Verbosity > 1)
printf("%s -> %s...\n", file->src, file->dst);
if (tar_header(tarfile, TAR_SYMLINK, file->mode, 0, deftime,
file->user, file->group, file->dst, file->src) < 0)
{
fprintf(stderr, "epm: Error writing link header - %s\n",
strerror(errno));
tar_close(tarfile);
return (1);
}
break;
}
tar_close(tarfile);
}
/*
* Create the scripts...
*/
if (write_install(dist, prodname, rootsize, usrsize, directory, subpackage))
return (1);
if (havepatchfiles)
if (write_patch(dist, prodname, prootsize, pusrsize, directory, subpackage))
return (1);
if (write_remove(dist, prodname, rootsize, usrsize, directory, subpackage))
return (1);
/*
* Return...
*/
return (0);
}
/*
* 'write_install()' - Write the installation script.
*/
static int /* O - -1 on error, 0 on success */
write_install(dist_t *dist, /* I - Software distribution */
const char *prodname, /* I - Product name */
int rootsize, /* I - Size of root files in kbytes */
int usrsize, /* I - Size of /usr files in kbytes */
const char *directory, /* I - Directory */
const char *subpackage) /* I - Subpackage */
{
int i; /* Looping var */
int col; /* Column in the output */
FILE *scriptfile; /* Install script */
char prodfull[255]; /* Full product name */
char filename[1024]; /* Name of temporary file */
file_t *file; /* Software file */
const char *runlevels; /* Run levels */
int number; /* Start/stop number */
if (Verbosity)
puts("Writing installation script...");
if (subpackage)
snprintf(prodfull, sizeof(prodfull), "%s-%s", prodname, subpackage);
else
strlcpy(prodfull, prodname, sizeof(prodfull));
snprintf(filename, sizeof(filename), "%s/%s.install", directory, prodfull);
if ((scriptfile = write_common(dist, "Installation", rootsize, usrsize,
filename, subpackage)) == NULL)
{
fprintf(stderr, "epm: Unable to create installation script \"%s\" -\n"
" %s\n", filename, strerror(errno));
return (-1);
}
fputs("if test \"$*\" = \"now\"; then\n", scriptfile);
fputs(" echo Software license silently accepted via command-line option.\n", scriptfile);
fputs("else\n", scriptfile);
fputs(" echo \"\"\n", scriptfile);
qprintf(scriptfile, " echo This installation script will install the %s\n",
dist->product);
qprintf(scriptfile, " echo software version %s on your system.\n",
dist->version);
fputs(" echo \"\"\n", scriptfile);
fputs(" while true ; do\n", scriptfile);
fputs(" echo $ac_n \"Do you wish to continue? $ac_c\"\n", scriptfile);
fputs(" read yesno\n", scriptfile);
fputs(" case \"$yesno\" in\n", scriptfile);
fputs(" y | yes | Y | Yes | YES)\n", scriptfile);
fputs(" break\n", scriptfile);
fputs(" ;;\n", scriptfile);
fputs(" n | no | N | No | NO)\n", scriptfile);
fputs(" exit 1\n", scriptfile);
fputs(" ;;\n", scriptfile);
fputs(" *)\n", scriptfile);
fputs(" echo Please enter yes or no.\n", scriptfile);
fputs(" ;;\n", scriptfile);
fputs(" esac\n", scriptfile);
fputs(" done\n", scriptfile);
if (dist->license[0])
{
fprintf(scriptfile, " more %s.license\n", prodfull);
fputs(" echo \"\"\n", scriptfile);
fputs(" while true ; do\n", scriptfile);
fputs(" echo $ac_n \"Do you agree with the terms of this license? $ac_c\"\n", scriptfile);
fputs(" read yesno\n", scriptfile);
fputs(" case \"$yesno\" in\n", scriptfile);
fputs(" y | yes | Y | Yes | YES)\n", scriptfile);
fputs(" break\n", scriptfile);
fputs(" ;;\n", scriptfile);
fputs(" n | no | N | No | NO)\n", scriptfile);
fputs(" exit 1\n", scriptfile);
fputs(" ;;\n", scriptfile);
fputs(" *)\n", scriptfile);
fputs(" echo Please enter yes or no.\n", scriptfile);
fputs(" ;;\n", scriptfile);
fputs(" esac\n", scriptfile);
fputs(" done\n", scriptfile);
}
fputs("fi\n", scriptfile);
fprintf(scriptfile, "if test -x %s/%s.remove; then\n", SoftwareDir, prodfull);
fprintf(scriptfile, " echo Removing old versions of %s software...\n",
prodfull);
fprintf(scriptfile, " %s/%s.remove now\n", SoftwareDir, prodfull);
fputs("fi\n", scriptfile);
write_space_checks(prodfull, scriptfile, rootsize ? "sw" : NULL,
usrsize ? "ss" : NULL, rootsize, usrsize);
write_depends(prodname, dist, scriptfile, subpackage);
write_commands(dist, scriptfile, COMMAND_PRE_INSTALL, subpackage);
for (i = dist->num_files, file = dist->files; i > 0; i --, file ++)
if ((tolower(file->type) == 'f' || tolower(file->type) == 'l') &&
strncmp(file->dst, "/usr", 4) != 0 && file->subpackage == subpackage)
break;
if (i)
{
fputs("echo Backing up old versions of non-shared files to be installed...\n", scriptfile);
col = fputs("for file in", scriptfile);
for (; i > 0; i --, file ++)
if ((tolower(file->type) == 'f' || tolower(file->type) == 'l') &&
strncmp(file->dst, "/usr", 4) != 0 && file->subpackage == subpackage)
{
if (col > 80)
col = qprintf(scriptfile, " \\\n%s", file->dst) - 2;
else
col += qprintf(scriptfile, " %s", file->dst);
}
fputs("; do\n", scriptfile);
fputs(" if test -d \"$file\" -o -f \"$file\" -o -h \"$file\"; then\n", scriptfile);
fputs(" mv -f \"$file\" \"$file.O\"\n", scriptfile);
fputs(" fi\n", scriptfile);
fputs("done\n", scriptfile);
}
for (i = dist->num_files, file = dist->files; i > 0; i --, file ++)
if ((tolower(file->type) == 'f' || tolower(file->type) == 'l') &&
strncmp(file->dst, "/usr", 4) == 0 && file->subpackage == subpackage)
break;
if (i)
{
fputs("if test -w /usr ; then\n", scriptfile);
fputs(" echo Backing up old versions of shared files to be installed...\n", scriptfile);
col = fputs(" for file in", scriptfile);
for (; i > 0; i --, file ++)
if ((tolower(file->type) == 'f' || tolower(file->type) == 'l') &&
strncmp(file->dst, "/usr", 4) == 0 && file->subpackage == subpackage)
{
if (col > 80)
col = qprintf(scriptfile, " \\\n%s", file->dst) - 2;
else
col += qprintf(scriptfile, " %s", file->dst);
}
fputs("; do\n", scriptfile);
fputs(" if test -d \"$file\" -o -f \"$file\" -o -h \"$file\"; then\n", scriptfile);
fputs(" mv -f \"$file\" \"$file.O\"\n", scriptfile);
fputs(" fi\n", scriptfile);
fputs(" done\n", scriptfile);
fputs("fi\n", scriptfile);
}
for (i = dist->num_files, file = dist->files; i > 0; i --, file ++)
if (tolower(file->type) == 'd' && file->subpackage == subpackage)
break;
if (i)
{
fputs("echo Creating installation directories...\n", scriptfile);
for (; i > 0; i --, file ++)
if (tolower(file->type) == 'd' && file->subpackage == subpackage)
{
qprintf(scriptfile, "if test ! -d %s -a ! -f %s -a ! -h %s; then\n",
file->dst, file->dst, file->dst);
qprintf(scriptfile, " mkdir -p %s\n", file->dst);
fputs("else\n", scriptfile);
qprintf(scriptfile, " if test -f %s; then\n", file->dst);
qprintf(scriptfile, " echo Error: %s already exists as a regular file!\n",
file->dst);
fputs(" exit 1\n", scriptfile);
fputs(" fi\n", scriptfile);
fputs("fi\n", scriptfile);
qprintf(scriptfile, "chown %s %s\n", file->user, file->dst);
qprintf(scriptfile, "chgrp %s %s\n", file->group, file->dst);
qprintf(scriptfile, "chmod %o %s\n", file->mode, file->dst);
}
}
fputs("echo Installing software...\n", scriptfile);
if (rootsize)
{
if (CompressFiles)
fprintf(scriptfile, "gzip -dc %s.sw | $ac_tar -\n", prodfull);
else
fprintf(scriptfile, "$ac_tar %s.sw\n", prodfull);
}
if (usrsize)
{
fputs("if echo Write Test >/usr/.writetest 2>/dev/null; then\n", scriptfile);
if (CompressFiles)
fprintf(scriptfile, " gzip -dc %s.ss | $ac_tar -\n", prodfull);
else
fprintf(scriptfile, " $ac_tar %s.ss\n", prodfull);
fputs("fi\n", scriptfile);
}
fprintf(scriptfile, "if test -d %s; then\n", SoftwareDir);
fprintf(scriptfile, " rm -f %s/%s.remove\n", SoftwareDir, prodfull);
fputs("else\n", scriptfile);
fprintf(scriptfile, " mkdir -p %s\n", SoftwareDir);
fputs("fi\n", scriptfile);
fprintf(scriptfile, "cp %s.remove %s\n", prodfull, SoftwareDir);
fprintf(scriptfile, "chmod 544 %s/%s.remove\n", SoftwareDir, prodfull);
for (i = dist->num_files, file = dist->files; i > 0; i --, file ++)
if (tolower(file->type) == 'c' && file->subpackage == subpackage)
break;
if (i)
{
fputs("echo Checking configuration files...\n", scriptfile);
col = fputs("for file in", scriptfile);
for (; i > 0; i --, file ++)
if (tolower(file->type) == 'c' && file->subpackage == subpackage)
{
if (col > 80)
col = qprintf(scriptfile, " \\\n%s", file->dst) - 2;
else
col += qprintf(scriptfile, " %s", file->dst);
}
fputs("; do\n", scriptfile);
fputs(" if test ! -f \"$file\"; then\n", scriptfile);
fputs(" cp \"$file.N\" \"$file\"\n", scriptfile);
fputs(" fi\n", scriptfile);
fputs("done\n", scriptfile);
}
fputs("echo Updating file permissions...\n", scriptfile);
for (i = dist->num_files, file = dist->files; i > 0; i --, file ++)
if (strncmp(file->dst, "/usr", 4) != 0 &&
strcmp(file->user, "root") != 0 && file->subpackage == subpackage)
switch (tolower(file->type))
{
case 'c' :
qprintf(scriptfile, "chown %s %s.N\n", file->user, file->dst);
qprintf(scriptfile, "chgrp %s %s.N\n", file->group, file->dst);
case 'f' :
qprintf(scriptfile, "chown %s %s\n", file->user, file->dst);
qprintf(scriptfile, "chgrp %s %s\n", file->group, file->dst);
break;
}
fputs("if test -f /usr/.writetest; then\n", scriptfile);
fputs(" rm -f /usr/.writetest\n", scriptfile);
for (i = dist->num_files, file = dist->files; i > 0; i --, file ++)
if (strncmp(file->dst, "/usr", 4) == 0 &&
strcmp(file->user, "root") != 0 && file->subpackage == subpackage)
switch (tolower(file->type))
{
case 'c' :
qprintf(scriptfile, " chown %s %s.N\n", file->user, file->dst);
qprintf(scriptfile, " chgrp %s %s.N\n", file->group, file->dst);
case 'f' :
qprintf(scriptfile, " chown %s %s\n", file->user, file->dst);
qprintf(scriptfile, " chgrp %s %s\n", file->group, file->dst);
break;
}
fputs("fi\n", scriptfile);
for (i = dist->num_files, file = dist->files; i > 0; i --, file ++)
if (tolower(file->type) == 'i' && file->subpackage == subpackage)
break;
if (i)
{
fputs("echo Setting up init scripts...\n", scriptfile);
/*
* Find where the frigging init scripts go...
*/
fputs("rcdir=\"\"\n", scriptfile);
fputs("for dir in /sbin/rc.d /sbin /etc/rc.d /etc ; do\n", scriptfile);
fputs(" if test -d $dir/rc2.d -o -h $dir/rc2.d -o "
"-d $dir/rc3.d -o -h $dir/rc3.d; then\n", scriptfile);
fputs(" rcdir=\"$dir\"\n", scriptfile);
fputs(" fi\n", scriptfile);
fputs("done\n", scriptfile);
fputs("if test \"$rcdir\" = \"\" ; then\n", scriptfile);
fputs(" if test -d /usr/local/etc/rc.d; then\n", scriptfile);
fputs(" for file in", scriptfile);
for (; i > 0; i --, file ++)
if (tolower(file->type) == 'i' && file->subpackage == subpackage)
qprintf(scriptfile, " %s", file->dst);
fputs("; do\n", scriptfile);
fputs(" rm -f /usr/local/etc/rc.d/$file.sh\n", scriptfile);
qprintf(scriptfile, " ln -s %s/init.d/$file "
"/usr/local/etc/rc.d/$file.sh\n",
SoftwareDir);
fputs(" done\n", scriptfile);
fputs(" else\n", scriptfile);
fputs(" echo Unable to determine location of startup scripts!\n", scriptfile);
fputs(" fi\n", scriptfile);
fputs("else\n", scriptfile);
for (i = dist->num_files, file = dist->files; i > 0; i --, file ++)
if (tolower(file->type) == 'i' && file->subpackage == subpackage)
{
fputs(" if test -d $rcdir/init.d; then\n", scriptfile);
qprintf(scriptfile, " /bin/rm -f $rcdir/init.d/%s\n", file->dst);
qprintf(scriptfile, " /bin/ln -s %s/init.d/%s "
"$rcdir/init.d/%s\n", SoftwareDir, file->dst, file->dst);
fputs(" else\n", scriptfile);
fputs(" if test -d /etc/init.d; then\n", scriptfile);
qprintf(scriptfile, " /bin/rm -f /etc/init.d/%s\n", file->dst);
qprintf(scriptfile, " /bin/ln -s %s/init.d/%s "
"/etc/init.d/%s\n", SoftwareDir, file->dst, file->dst);
fputs(" fi\n", scriptfile);
fputs(" fi\n", scriptfile);
for (runlevels = get_runlevels(dist->files + i, "0235");
isdigit(*runlevels & 255);
runlevels ++)
{
if (*runlevels == '0')
number = get_stop(file, 0);
else
number = get_start(file, 99);
fprintf(scriptfile, " if test -d $rcdir/rc%c.d; then\n", *runlevels);
qprintf(scriptfile, " /bin/rm -f $rcdir/rc%c.d/%c%02d%s\n",
*runlevels, *runlevels == '0' ? 'K' : 'S', number, file->dst);
qprintf(scriptfile, " /bin/ln -s %s/init.d/%s "
"$rcdir/rc%c.d/%c%02d%s\n",
SoftwareDir, file->dst, *runlevels,
*runlevels == '0' ? 'K' : 'S', number, file->dst);
fputs(" fi\n", scriptfile);
}
#ifdef __sgi
fputs(" if test -x /etc/chkconfig; then\n", scriptfile);
qprintf(scriptfile, " /etc/chkconfig -f %s on\n", file->dst);
fputs(" fi\n", scriptfile);
#endif /* __sgi */
}
fputs("fi\n", scriptfile);
}
write_commands(dist, scriptfile, COMMAND_POST_INSTALL, subpackage);
for (i = dist->num_files, file = dist->files; i > 0; i --, file ++)
if (tolower(file->type) == 'i' && file->subpackage == subpackage)
qprintf(scriptfile, "%s/init.d/%s start\n", SoftwareDir, file->dst);
fputs("echo Installation is complete.\n", scriptfile);
fclose(scriptfile);
return (0);
}
/*
* 'write_instfiles()' - Write the installer files to the tar file...
*/
static int /* O - 0 = success, -1 on failure */
write_instfiles(tarf_t *tarfile, /* I - Distribution tar file */
const char *directory, /* I - Output directory */
const char *prodname, /* I - Base product name */
const char *platname, /* I - Platform name */
const char **files, /* I - Files */
const char *destdir, /* I - Destination directory in tar file */
const char *subpackage) /* I - Subpackage */
{
int i; /* Looping var */
char srcname[1024], /* Name of source file in distribution */
dstname[1024], /* Name of destination file in distribution */
prodfull[255]; /* Full name of product */
struct stat srcstat; /* Source file information */
if (subpackage)
snprintf(prodfull, sizeof(prodfull), "%s-%s", prodname, subpackage);
else
strlcpy(prodfull, prodname, sizeof(prodfull));
for (i = 0; files[i] != NULL; i ++)
{
snprintf(srcname, sizeof(srcname), "%s/%s.%s", directory, prodfull, files[i]);
snprintf(dstname, sizeof(dstname), "%s%s.%s", destdir, prodfull, files[i]);
if (stat(srcname, &srcstat))
{
if (!i)
break;
else
continue;
}
if (srcstat.st_size == 0)
continue;
if (tar_header(tarfile, TAR_NORMAL, srcstat.st_mode & 07555,
srcstat.st_size, srcstat.st_mtime, "root", "root",
dstname, NULL) < 0)
{
fprintf(stderr, "epm: Error writing file header - %s\n",
strerror(errno));
return (-1);
}
if (tar_file(tarfile, srcname) < 0)
{
fprintf(stderr, "epm: Error writing file data for %s -\n %s\n",
dstname, strerror(errno));
return (-1);
}
if (Verbosity)
printf(" %7.0fk %s.%s\n", (srcstat.st_size + 1023) / 1024.0,
prodfull, files[i]);
}
return (0);
}
/*
* 'write_patch()' - Write the patch script.
*/
static int /* O - -1 on error, 0 on success */
write_patch(dist_t *dist, /* I - Software distribution */
const char *prodname, /* I - Product name */
int rootsize, /* I - Size of root files in kbytes */
int usrsize, /* I - Size of /usr files in kbytes */
const char *directory, /* I - Directory */
const char *subpackage) /* I - Subpackage */
{
int i; /* Looping var */
FILE *scriptfile; /* Patch script */
char filename[1024]; /* Name of temporary file */
char prodfull[255]; /* Full product name */
file_t *file; /* Software file */
const char *runlevels; /* Run levels */
int number; /* Start/stop number */
if (Verbosity)
puts("Writing patch script...");
if (subpackage)
snprintf(prodfull, sizeof(prodfull), "%s-%s", prodname, subpackage);
else
strlcpy(prodfull, prodname, sizeof(prodfull));
snprintf(filename, sizeof(filename), "%s/%s.patch", directory, prodfull);
if ((scriptfile = write_common(dist, "Patch", rootsize, usrsize,
filename, subpackage)) == NULL)
{
fprintf(stderr, "epm: Unable to create patch script \"%s\" -\n"
" %s\n", filename, strerror(errno));
return (-1);
}
fputs("if test \"$*\" = \"now\"; then\n", scriptfile);
fputs(" echo Software license silently accepted via command-line option.\n", scriptfile);
fputs("else\n", scriptfile);
fputs(" echo \"\"\n", scriptfile);
qprintf(scriptfile, " echo This installation script will patch the %s\n",
dist->product);
qprintf(scriptfile, " echo software to version %s on your system.\n", dist->version);
fputs(" echo \"\"\n", scriptfile);
fputs(" while true ; do\n", scriptfile);
fputs(" echo $ac_n \"Do you wish to continue? $ac_c\"\n", scriptfile);
fputs(" read yesno\n", scriptfile);
fputs(" case \"$yesno\" in\n", scriptfile);
fputs(" y | yes | Y | Yes | YES)\n", scriptfile);
fputs(" break\n", scriptfile);
fputs(" ;;\n", scriptfile);
fputs(" n | no | N | No | NO)\n", scriptfile);
fputs(" exit 1\n", scriptfile);
fputs(" ;;\n", scriptfile);
fputs(" *)\n", scriptfile);
fputs(" echo Please enter yes or no.\n", scriptfile);
fputs(" ;;\n", scriptfile);
fputs(" esac\n", scriptfile);
fputs(" done\n", scriptfile);
if (dist->license[0])
{
fprintf(scriptfile, " more %s.license\n", prodfull);
fputs(" echo \"\"\n", scriptfile);
fputs(" while true ; do\n", scriptfile);
fputs(" echo $ac_n \"Do you agree with the terms of this license? $ac_c\"\n", scriptfile);
fputs(" read yesno\n", scriptfile);
fputs(" case \"$yesno\" in\n", scriptfile);
fputs(" y | yes | Y | Yes | YES)\n", scriptfile);
fputs(" break\n", scriptfile);
fputs(" ;;\n", scriptfile);
fputs(" n | no | N | No | NO)\n", scriptfile);
fputs(" exit 1\n", scriptfile);
fputs(" ;;\n", scriptfile);
fputs(" *)\n", scriptfile);
fputs(" echo Please enter yes or no.\n", scriptfile);
fputs(" ;;\n", scriptfile);
fputs(" esac\n", scriptfile);
fputs(" done\n", scriptfile);
}
fputs("fi\n", scriptfile);
write_space_checks(prodfull, scriptfile, rootsize ? "psw" : NULL,
usrsize ? "pss" : NULL, rootsize, usrsize);
write_depends(prodname, dist, scriptfile, subpackage);
fprintf(scriptfile, "if test ! -x %s/%s.remove; then\n",
SoftwareDir, prodfull);
fputs(" echo You do not appear to have the base software installed!\n",
scriptfile);
fputs(" echo Please install the full distribution instead.\n", scriptfile);
fputs(" exit 1\n", scriptfile);
fputs("fi\n", scriptfile);
for (i = dist->num_files, file = dist->files; i > 0; i --, file ++)
if (tolower(file->type) == 'i' && file->subpackage == subpackage)
qprintf(scriptfile, "%s/init.d/%s stop\n", SoftwareDir, file->dst);
write_commands(dist, scriptfile, COMMAND_PRE_PATCH, subpackage);
for (i = dist->num_files, file = dist->files; i > 0; i --, file ++)
if (file->type == 'D' && file->subpackage == subpackage)
break;
if (i)
{
fputs("echo Creating new installation directories...\n", scriptfile);
for (; i > 0; i --, file ++)
if (file->type == 'D' && file->subpackage == subpackage)
{
qprintf(scriptfile, "if test ! -d %s -a ! -f %s -a ! -h %s; then\n",
file->dst, file->dst, file->dst);
qprintf(scriptfile, " mkdir -p %s\n", file->dst);
fputs("else\n", scriptfile);
qprintf(scriptfile, " if test -f %s; then\n", file->dst);
qprintf(scriptfile, " echo Error: %s already exists as a regular file!\n",
file->dst);
fputs(" exit 1\n", scriptfile);
fputs(" fi\n", scriptfile);
fputs("fi\n", scriptfile);
qprintf(scriptfile, "chown %s %s\n", file->user, file->dst);
qprintf(scriptfile, "chgrp %s %s\n", file->group, file->dst);
qprintf(scriptfile, "chmod %o %s\n", file->mode, file->dst);
}
}
fputs("echo Patching software...\n", scriptfile);
if (rootsize)
{
if (CompressFiles)
fprintf(scriptfile, "gzip -dc %s.psw | $ac_tar -\n", prodfull);
else
fprintf(scriptfile, "$ac_tar %s.psw\n", prodfull);
}
if (usrsize)
{
fputs("if echo Write Test >/usr/.writetest 2>/dev/null; then\n", scriptfile);
if (CompressFiles)
fprintf(scriptfile, " gzip -dc %s.pss | $ac_tar -\n", prodfull);
else
fprintf(scriptfile, " $ac_tar %s.pss\n", prodfull);
fputs("fi\n", scriptfile);
}
fprintf(scriptfile, "rm -f %s/%s.remove\n", SoftwareDir, prodfull);
fprintf(scriptfile, "cp %s.remove %s\n", prodfull, SoftwareDir);
fprintf(scriptfile, "chmod 544 %s/%s.remove\n", SoftwareDir, prodfull);
fputs("echo Updating file permissions...\n", scriptfile);
for (i = dist->num_files, file = dist->files; i > 0; i --, file ++)
if (strncmp(file->dst, "/usr", 4) != 0 &&
strcmp(file->user, "root") != 0 && file->subpackage == subpackage)
switch (file->type)
{
case 'C' :
case 'F' :
qprintf(scriptfile, "chown %s %s\n", file->user, file->dst);
qprintf(scriptfile, "chgrp %s %s\n", file->group, file->dst);
break;
}
fputs("if test -f /usr/.writetest; then\n", scriptfile);
fputs(" rm -f /usr/.writetest\n", scriptfile);
for (i = dist->num_files, file = dist->files; i > 0; i --, file ++)
if (strncmp(file->dst, "/usr", 4) == 0 &&
strcmp(file->user, "root") != 0 && file->subpackage == subpackage)
switch (file->type)
{
case 'C' :
case 'F' :
qprintf(scriptfile, " chown %s %s\n", file->user, file->dst);
qprintf(scriptfile, " chgrp %s %s\n", file->group, file->dst);
break;
}
fputs("fi\n", scriptfile);
for (i = dist->num_files, file = dist->files; i > 0; i --, file ++)
if (file->type == 'C' && file->subpackage == subpackage)
break;
if (i)
{
fputs("echo Checking configuration files...\n", scriptfile);
fputs("for file in", scriptfile);
for (; i > 0; i --, file ++)
if (file->type == 'C' && file->subpackage == subpackage)
qprintf(scriptfile, " %s", file->dst);
fputs("; do\n", scriptfile);
fputs(" if test ! -f \"$file\"; then\n", scriptfile);
fputs(" cp \"$file.N\" \"$file\"\n", scriptfile);
fputs(" fi\n", scriptfile);
fputs("done\n", scriptfile);
}
for (i = dist->num_files, file = dist->files; i > 0; i --, file ++)
if (file->type == 'R' && file->subpackage == subpackage)
break;
if (i)
{
fputs("echo Removing files that are no longer used...\n", scriptfile);
fputs("for file in", scriptfile);
for (; i > 0; i --, file ++)
if (file->type == 'R' && file->subpackage == subpackage)
qprintf(scriptfile, " %s", file->dst);
fputs("; do\n", scriptfile);
fputs(" rm -f \"$file\"\n", scriptfile);
fputs(" if test -d \"$file.O\" -o -f \"$file.O\" -o -h \"$file.O\"; then\n", scriptfile);
fputs(" mv -f \"$file.O\" \"$file\"\n", scriptfile);
fputs(" fi\n", scriptfile);
fputs("done\n", scriptfile);
}
for (i = dist->num_files, file = dist->files; i > 0; i --, file ++)
if (file->type == 'I' && file->subpackage == subpackage)
break;
if (i)
{
fputs("echo Setting up init scripts...\n", scriptfile);
/*
* Find where the frigging init scripts go...
*/
fputs("rcdir=\"\"\n", scriptfile);
fputs("for dir in /sbin/rc.d /sbin /etc/rc.d /etc ; do\n", scriptfile);
fputs(" if test -d $dir/rc2.d -o -h $dir/rc2.d -o "
"-d $dir/rc3.d -o -h $dir/rc3.d; then\n", scriptfile);
fputs(" rcdir=\"$dir\"\n", scriptfile);
fputs(" fi\n", scriptfile);
fputs("done\n", scriptfile);
fputs("if test \"$rcdir\" = \"\" ; then\n", scriptfile);
fputs(" if test -d /usr/local/etc/rc.d; then\n", scriptfile);
fputs(" for file in", scriptfile);
for (; i > 0; i --, file ++)
if (tolower(file->type) == 'I' && file->subpackage == subpackage)
qprintf(scriptfile, " %s", file->dst);
fputs("; do\n", scriptfile);
fputs(" rm -f /usr/local/etc/rc.d/$file.sh\n", scriptfile);
qprintf(scriptfile, " ln -s %s/init.d/$file "
"/usr/local/etc/rc.d/$file.sh\n",
SoftwareDir);
fputs(" done\n", scriptfile);
fputs(" else\n", scriptfile);
fputs(" echo Unable to determine location of startup scripts!\n", scriptfile);
fputs(" fi\n", scriptfile);
fputs("else\n", scriptfile);
for (i = dist->num_files, file = dist->files; i > 0; i --, file ++)
if (tolower(file->type) == 'i' && file->subpackage == subpackage)
{
fputs(" if test -d $rcdir/init.d; then\n", scriptfile);
qprintf(scriptfile, " /bin/rm -f $rcdir/init.d/%s\n", file->dst);
qprintf(scriptfile, " /bin/ln -s %s/init.d/%s "
"$rcdir/init.d/%s\n", SoftwareDir, file->dst, file->dst);
fputs(" else\n", scriptfile);
fputs(" if test -d /etc/init.d; then\n", scriptfile);
qprintf(scriptfile, " /bin/rm -f /etc/init.d/%s\n", file->dst);
qprintf(scriptfile, " /bin/ln -s %s/init.d/%s "
"/etc/init.d/%s\n", SoftwareDir, file->dst, file->dst);
fputs(" fi\n", scriptfile);
fputs(" fi\n", scriptfile);
for (runlevels = get_runlevels(dist->files + i, "0235");
isdigit(*runlevels & 255);
runlevels ++)
{
if (*runlevels == '0')
number = get_stop(file, 0);
else
number = get_start(file, 99);
fprintf(scriptfile, " if test -d $rcdir/rc%c.d; then\n", *runlevels);
qprintf(scriptfile, " /bin/rm -f $rcdir/rc%c.d/%c%02d%s\n",
*runlevels, *runlevels == '0' ? 'K' : 'S', number, file->dst);
qprintf(scriptfile, " /bin/ln -s %s/init.d/%s "
"$rcdir/rc%c.d/%c%02d%s\n",
SoftwareDir, file->dst, *runlevels,
*runlevels == '0' ? 'K' : 'S', number, file->dst);
fputs(" fi\n", scriptfile);
}
#ifdef __sgi
fputs(" if test -x /etc/chkconfig; then\n", scriptfile);
qprintf(scriptfile, " /etc/chkconfig -f %s on\n", file->dst);
fputs(" fi\n", scriptfile);
#endif /* __sgi */
}
fputs("fi\n", scriptfile);
}
write_commands(dist, scriptfile, COMMAND_POST_PATCH, subpackage);
for (i = dist->num_files, file = dist->files; i > 0; i --, file ++)
if (tolower(file->type) == 'i' && file->subpackage == subpackage)
qprintf(scriptfile, "%s/init.d/%s start\n", SoftwareDir, file->dst);
fputs("echo Patching is complete.\n", scriptfile);
fclose(scriptfile);
return (0);
}
/*
* 'write_remove()' - Write the removal script.
*/
static int /* O - -1 on error, 0 on success */
write_remove(dist_t *dist, /* I - Software distribution */
const char *prodname, /* I - Product name */
int rootsize, /* I - Size of root files in kbytes */
int usrsize, /* I - Size of /usr files in kbytes */
const char *directory, /* I - Directory */
const char *subpackage) /* I - Subpackage */
{
int i; /* Looping var */
int col; /* Current column */
FILE *scriptfile; /* Remove script */
char filename[1024]; /* Name of temporary file */
char prodfull[255]; /* Full product name */
file_t *file; /* Software file */
const char *runlevels; /* Run levels */
int number; /* Start/stop number */
if (Verbosity)
puts("Writing removal script...");
if (subpackage)
snprintf(prodfull, sizeof(prodfull), "%s-%s", prodname, subpackage);
else
strlcpy(prodfull, prodname, sizeof(prodfull));
snprintf(filename, sizeof(filename), "%s/%s.remove", directory, prodfull);
if ((scriptfile = write_common(dist, "Removal", rootsize, usrsize,
filename, subpackage)) == NULL)
{
fprintf(stderr, "epm: Unable to create removal script \"%s\" -\n"
" %s\n", filename, strerror(errno));
return (-1);
}
fputs("if test ! \"$*\" = \"now\"; then\n", scriptfile);
fputs(" echo \"\"\n", scriptfile);
qprintf(scriptfile, " echo This removal script will remove the %s\n",
dist->product);
qprintf(scriptfile, " echo software version %s from your system.\n",
dist->version);
fputs(" echo \"\"\n", scriptfile);
fputs(" while true ; do\n", scriptfile);
fputs(" echo $ac_n \"Do you wish to continue? $ac_c\"\n", scriptfile);
fputs(" read yesno\n", scriptfile);
fputs(" case \"$yesno\" in\n", scriptfile);
fputs(" y | yes | Y | Yes | YES)\n", scriptfile);
fputs(" break\n", scriptfile);
fputs(" ;;\n", scriptfile);
fputs(" n | no | N | No | NO)\n", scriptfile);
fputs(" exit 1\n", scriptfile);
fputs(" ;;\n", scriptfile);
fputs(" *)\n", scriptfile);
fputs(" echo Please enter yes or no.\n", scriptfile);
fputs(" ;;\n", scriptfile);
fputs(" esac\n", scriptfile);
fputs(" done\n", scriptfile);
fputs("fi\n", scriptfile);
/*
* Find any removal commands in the list file...
*/
for (i = dist->num_files, file = dist->files; i > 0; i --, file ++)
if (tolower(file->type) == 'i' && file->subpackage == subpackage)
qprintf(scriptfile, "%s/init.d/%s stop\n", SoftwareDir, file->dst);
write_commands(dist, scriptfile, COMMAND_PRE_REMOVE, subpackage);
for (i = dist->num_files, file = dist->files; i > 0; i --, file ++)
if (tolower(file->type) == 'i' && file->subpackage == subpackage)
break;
if (i)
{
fputs("echo Cleaning up init scripts...\n", scriptfile);
/*
* Find where the frigging init scripts go...
*/
fputs("rcdir=\"\"\n", scriptfile);
fputs("for dir in /sbin/rc.d /sbin /etc/rc.d /etc ; do\n", scriptfile);
fputs(" if test -d $dir/rc2.d -o -h $dir/rc2.d -o "
"-d $dir/rc3.d -o -h $dir/rc3.d; then\n", scriptfile);
fputs(" rcdir=\"$dir\"\n", scriptfile);
fputs(" fi\n", scriptfile);
fputs("done\n", scriptfile);
fputs("if test \"$rcdir\" = \"\" ; then\n", scriptfile);
fputs(" if test -d /usr/local/etc/rc.d; then\n", scriptfile);
fputs(" for file in", scriptfile);
for (; i > 0; i --, file ++)
if (tolower(file->type) == 'i' && file->subpackage == subpackage)
qprintf(scriptfile, " %s", file->dst);
fputs("; do\n", scriptfile);
fputs(" rm -f /usr/local/etc/rc.d/$file.sh\n", scriptfile);
fputs(" done\n", scriptfile);
fputs(" else\n", scriptfile);
fputs(" echo Unable to determine location of startup scripts!\n", scriptfile);
fputs(" fi\n", scriptfile);
fputs("else\n", scriptfile);
for (i = dist->num_files, file = dist->files; i > 0; i --, file ++)
if (tolower(file->type) == 'i' && file->subpackage == subpackage)
{
qprintf(scriptfile, " %s/init.d/%s stop\n", SoftwareDir, file->dst);
fputs(" if test -d $rcdir/init.d; then\n", scriptfile);
qprintf(scriptfile, " /bin/rm -f $rcdir/init.d/%s\n", file->dst);
fputs(" else\n", scriptfile);
fputs(" if test -d /etc/init.d; then\n", scriptfile);
qprintf(scriptfile, " /bin/rm -f /etc/init.d/%s\n", file->dst);
fputs(" fi\n", scriptfile);
fputs(" fi\n", scriptfile);
for (runlevels = get_runlevels(dist->files + i, "0235");
isdigit(*runlevels & 255);
runlevels ++)
{
if (*runlevels == '0')
number = get_stop(file, 0);
else
number = get_start(file, 99);
fprintf(scriptfile, " if test -d $rcdir/rc%c.d; then\n", *runlevels);
qprintf(scriptfile, " /bin/rm -f $rcdir/rc%c.d/%c%02d%s\n",
*runlevels, *runlevels == '0' ? 'K' : 'S', number, file->dst);
fputs(" fi\n", scriptfile);
}
#ifdef __sgi
fputs(" if test -x /etc/chkconfig; then\n", scriptfile);
qprintf(scriptfile, " rm -f /etc/config/%s\n", file->dst);
fputs(" fi\n", scriptfile);
#endif /* __sgi */
}
fputs("fi\n", scriptfile);
}
fputs("echo Removing/restoring installed files...\n", scriptfile);
for (i = dist->num_files, file = dist->files; i > 0; i --, file ++)
if ((tolower(file->type) == 'f' || tolower(file->type) == 'l') &&
strncmp(file->dst, "/usr", 4) != 0 && file->subpackage == subpackage)
break;
if (i)
{
col = fputs("for file in", scriptfile);
for (; i > 0; i --, file ++)
if ((tolower(file->type) == 'f' || tolower(file->type) == 'l') &&
strncmp(file->dst, "/usr", 4) != 0 && file->subpackage == subpackage)
{
if (col > 80)
col = qprintf(scriptfile, " \\\n%s", file->dst) - 2;
else
col += qprintf(scriptfile, " %s", file->dst);
}
fputs("; do\n", scriptfile);
fputs(" rm -f \"$file\"\n", scriptfile);
fputs(" if test -d \"$file.O\" -o -f \"$file.O\" -o -h \"$file.O\"; then\n", scriptfile);
fputs(" mv -f \"$file.O\" \"$file\"\n", scriptfile);
fputs(" fi\n", scriptfile);
fputs("done\n", scriptfile);
}
for (i = dist->num_files, file = dist->files; i > 0; i --, file ++)
if ((tolower(file->type) == 'f' || tolower(file->type) == 'l') &&
strncmp(file->dst, "/usr", 4) == 0 && file->subpackage == subpackage)
break;
if (i)
{
fputs("if test -w /usr ; then\n", scriptfile);
col = fputs(" for file in", scriptfile);
for (; i > 0; i --, file ++)
if ((tolower(file->type) == 'f' || tolower(file->type) == 'l') &&
strncmp(file->dst, "/usr", 4) == 0 && file->subpackage == subpackage)
{
if (col > 80)
col = qprintf(scriptfile, " \\\n%s", file->dst) - 2;
else
col += qprintf(scriptfile, " %s", file->dst);
}
fputs("; do\n", scriptfile);
fputs(" rm -f \"$file\"\n", scriptfile);
fputs(" if test -d \"$file.O\" -o -f \"$file.O\" -o -h \"$file.O\"; then\n", scriptfile);
fputs(" mv -f \"$file.O\" \"$file\"\n", scriptfile);
fputs(" fi\n", scriptfile);
fputs(" done\n", scriptfile);
fputs("fi\n", scriptfile);
}
fputs("echo Checking configuration files...\n", scriptfile);
for (i = dist->num_files, file = dist->files; i > 0; i --, file ++)
if (tolower(file->type) == 'c' && file->subpackage == subpackage)
break;
if (i)
{
col = fputs("for file in", scriptfile);
for (; i > 0; i --, file ++)
if (tolower(file->type) == 'c' && file->subpackage == subpackage)
{
if (col > 80)
col = qprintf(scriptfile, " \\\n%s", file->dst) - 2;
else
col += qprintf(scriptfile, " %s", file->dst);
}
fputs("; do\n", scriptfile);
fputs(" if cmp -s \"$file\" \"$file.N\"; then\n", scriptfile);
fputs(" # Config file not changed\n", scriptfile);
fputs(" rm -f \"$file\"\n", scriptfile);
fputs(" fi\n", scriptfile);
fputs(" rm -f \"$file.N\"\n", scriptfile);
fputs("done\n", scriptfile);
}
for (i = dist->num_files, file = dist->files + i - 1; i > 0; i --, file --)
if (tolower(file->type) == 'd' && file->subpackage == subpackage)
break;
if (i)
{
fputs("echo Removing empty installation directories...\n", scriptfile);
for (; i > 0; i --, file --)
if (tolower(file->type) == 'd' && file->subpackage == subpackage)
{
qprintf(scriptfile, "if test -d %s; then\n", file->dst);
qprintf(scriptfile, " rmdir %s >/dev/null 2>&1\n", file->dst);
fputs("fi\n", scriptfile);
}
}
write_commands(dist, scriptfile, COMMAND_POST_REMOVE, subpackage);
fprintf(scriptfile, "rm -f %s/%s.remove\n", SoftwareDir, prodfull);
fputs("echo Removal is complete.\n", scriptfile);
fclose(scriptfile);
return (0);
}
/*
* 'write_space_checks()' - Write disk space checks for the installer.
*/
static int /* O - 0 on success, -1 on error */
write_space_checks(const char *prodname,/* I - Distribution name */
FILE *fp, /* I - File to write to */
const char *sw, /* I - / archive */
const char *ss, /* I - /usr archive */
int rootsize, /* I - / install size in kbytes */
int usrsize) /* I - /usr install size in kbytes */
{
fputs("case `uname` in\n", fp);
fputs(" AIX)\n", fp);
fputs(" dfroot=`df -k / | tr '\\n' ' '`\n", fp);
fputs(" dfusr=`df -k /usr | tr '\\n' ' '`\n", fp);
fputs(" fsroot=`echo $dfroot | awk '{print $15}'`\n", fp);
fputs(" sproot=`echo $dfroot | awk '{print $11}'`\n", fp);
fputs(" fsusr=`echo $dfusr | awk '{print $15}'`\n", fp);
fputs(" spusr=`echo $dfusr | awk '{print $11}'`\n", fp);
fputs(" ;;\n\n", fp);
fputs(" HP-UX)\n", fp);
fputs(" dfroot=`df -k / | tr '\\n' ' '`\n", fp);
fputs(" dfusr=`df -k /usr | tr '\\n' ' '`\n", fp);
fputs(" fsroot=`echo $dfroot | awk '{print $1}'`\n", fp);
fputs(" sproot=`echo $dfroot | awk '{print $9}'`\n", fp);
fputs(" fsusr=`echo $dfusr | awk '{print $1}'`\n", fp);
fputs(" spusr=`echo $dfusr | awk '{print $9}'`\n", fp);
fputs(" ;;\n\n", fp);
fputs(" IRIX*)\n", fp);
fputs(" dfroot=`df -k / | tr '\\n' ' '`\n", fp);
fputs(" dfusr=`df -k /usr | tr '\\n' ' '`\n", fp);
fputs(" fsroot=`echo $dfroot | awk '{print $15}'`\n", fp);
fputs(" sproot=`echo $dfroot | awk '{print $13}'`\n", fp);
fputs(" fsusr=`echo $dfusr | awk '{print $15}'`\n", fp);
fputs(" spusr=`echo $dfusr | awk '{print $13}'`\n", fp);
fputs(" ;;\n\n", fp);
fputs(" SCO*)\n", fp);
fputs(" dfroot=`df -k -B / | tr '\\n' ' '`\n", fp);
fputs(" dfusr=`df -k -B /usr | tr '\\n' ' '`\n", fp);
fputs(" fsroot=`echo $dfroot | awk '{print $13}'`\n", fp);
fputs(" sproot=`echo $dfroot | awk '{print $11}'`\n", fp);
fputs(" fsusr=`echo $dfusr | awk '{print $13}'`\n", fp);
fputs(" spusr=`echo $dfusr | awk '{print $11}'`\n", fp);
fputs(" ;;\n\n", fp);
fputs(" *)\n", fp);
fputs(" dfroot=`df -k / | tr '\\n' ' '`\n", fp);
fputs(" dfusr=`df -k /usr | tr '\\n' ' '`\n", fp);
fputs(" fsroot=`echo $dfroot | awk '{print $13}'`\n", fp);
fputs(" sproot=`echo $dfroot | awk '{print $11}'`\n", fp);
fputs(" fsusr=`echo $dfusr | awk '{print $13}'`\n", fp);
fputs(" spusr=`echo $dfusr | awk '{print $11}'`\n", fp);
fputs(" ;;\n", fp);
fputs("esac\n", fp);
fputs("\n", fp);
fputs("if test x$sproot = x -o x$spusr = x; then\n", fp);
fputs(" echo WARNING: Unable to determine available disk space\\; "
"installing blindly...\n", fp);
fputs("else\n", fp);
fputs(" if test x$fsroot = x$fsusr; then\n", fp);
fprintf(fp, " if test %d -gt $sproot; then\n", rootsize + usrsize);
fputs(" echo Not enough free disk space for "
"software:\n", fp);
fprintf(fp, " echo You need %d kbytes but only have "
"$sproot kbytes available.\n", rootsize + usrsize);
fputs(" exit 1\n", fp);
fputs(" fi\n", fp);
fputs(" else\n", fp);
fprintf(fp, " if test %d -gt $sproot; then\n", rootsize);
fputs(" echo Not enough free disk space for "
"software:\n", fp);
fprintf(fp, " echo You need %d kbytes in / but only have "
"$sproot kbytes available.\n", rootsize);
fputs(" exit 1\n", fp);
fputs(" fi\n", fp);
fputs("\n", fp);
fprintf(fp, " if test %d -gt $spusr; then\n", usrsize);
fputs(" echo Not enough free disk space for "
"software:\n", fp);
fprintf(fp, " echo You need %d kbytes in /usr but only have "
"$spusr kbytes available.\n", usrsize);
fputs(" exit 1\n", fp);
fputs(" fi\n", fp);
fputs(" fi\n", fp);
fputs("fi\n", fp);
return (0);
}
/*
* End of "$Id: portable.c 833 2010-12-30 00:00:50Z mike $".
*/
|