summaryrefslogtreecommitdiff
path: root/setup.pl
blob: 81d9b244135be1e5250abda8d080f8cfbee25250 (plain)
  1. #!/usr/bin/perl
  2. #
  3. ######################################################################
  4. # LedgerSMB Small Medium Business Accounting Software Installer
  5. # Copyright (C) 2006
  6. # This work contains copyrighted information from a number of sources all used
  7. # with permission.
  8. #
  9. # This file contains source code included with or based on SQL-Ledger which
  10. # is Copyright Dieter Simader and DWS Systems Inc. 2000-2005 and licensed
  11. # under the GNU General Public License version 2 or, at your option, any later
  12. # version. For a full list including contact information of contributors,
  13. # maintainers, and copyright holders, see the CONTRIBUTORS file.
  14. #
  15. # Original Copyright Notice from SQL-Ledger 2.6.17 (before the fork):
  16. # Copyright (c) 2002, Dieter Simader
  17. #
  18. # Web: http://www.sql-ledger.org
  19. #
  20. #######################################################################
  21. $| = 1;
  22. if ($ENV{HTTP_USER_AGENT}) {
  23. print "
  24. This does not work yet!
  25. use $0 from the command line";
  26. exit;
  27. }
  28. $lynx = `lynx -version`; # if LWP is not installed use lynx
  29. $gzip = `gzip -V 2>&1`; # gz decompression utility
  30. $tar = `tar --version 2>&1`; # tar archiver
  31. $latex = `latex -version`;
  32. %checkversion = ( www => 3, abacus => 4, pluto => 5, neptune => 8 );
  33. %source = (
  34. 1 => { url => "http://voxel.dl.sourceforge.net/sourceforge/sql-ledger", site => "New York, U.S.A", locale => us },
  35. 2 => { url => "http://easynews.dl.sourceforge.net/sourceforge/sql-ledger", site => "Arizona, U.S.A", locale => us },
  36. 3 => { url => "http://www.sql-ledger.com/source", site => "California, U.S.A", locale => us },
  37. 4 => { url => "http://abacus.sql-ledger.com/source", site => "Toronto, Canada", locale => ca },
  38. 5 => { url => "http://pluto.sql-ledger.com/source", site => "Edmonton, Canada", locale => ca },
  39. 6 => { url => "http://ufpr.dl.sourceforge.net/sourceforge/sql-ledger", site =>"Brazil", locale => br },
  40. 7 => { url => "http://surfnet.dl.sourceforge.net/sourceforge/sql-ledger", site => "The Netherlands", locale => nl },
  41. 8 => { url => "http://neptune.sql-ledger.com/source", site => "Ireland", locale => ie },
  42. 9 => { url => "http://kent.dl.sourceforge.net/sourceforge/sql-ledger", site => "U.K", locale => uk },
  43. 10 => { url => "http://ovh.dl.sourceforge.net/sourceforge/sql-ledger", site => "France", locale => fr },
  44. 11 => { url => "http://mesh.dl.sourceforge.net/sourceforge/sql-ledger", site => "Germany", locale => de },
  45. 12 => { url => "http://citkit.dl.sourceforge.net/sourceforge/sql-ledger", site => "Russia", locale => ru },
  46. 13 => { url => "http://optusnet.dl.sourceforge.net/sourceforge/sql-ledger", site => "Sydney, Australia", locale => au },
  47. 14 => { url => "http://nchc.dl.sourceforge.net/sourceforge/sql-ledger", site => "Taiwan", locale => tw },
  48. 15 => { url => "http://jaist.dl.sourceforge.net/sourceforge/sql-ledger", site => "Japan", locale => jp }
  49. );
  50. $userspath = "users"; # default for new installation
  51. eval { require "sql-ledger.conf"; };
  52. $filename = shift;
  53. chomp $filename;
  54. $newinstall = 1;
  55. # is LWP installed
  56. eval { require LWP::Simple; };
  57. $lwp = !($@);
  58. unless ($lwp || $lynx || $filename) {
  59. die "You must have either lynx or LWP installed or specify a filename.
  60. perl $0 <filename>\n";
  61. }
  62. if ($filename) {
  63. # extract version
  64. die "Not a SQL-Ledger archive\n" if ($filename !~ /^sql-ledger/);
  65. $version = $filename;
  66. $version =~ s/sql-ledger-(\d+\.\d+\.\d+).*$/$1/;
  67. }
  68. if (-f "VERSION") {
  69. # get installed version from VERSION file
  70. open(FH, "VERSION");
  71. @a = <FH>;
  72. close(FH);
  73. $version = $a[0];
  74. chomp $version;
  75. $newinstall = !$version;
  76. if (! -f "sql-ledger.conf") {
  77. $newinstall = 1;
  78. }
  79. }
  80. $webowner = "nobody";
  81. $webgroup = "nogroup";
  82. if ($httpd = `find /etc /usr/local/etc -type f -name 'httpd.conf'`) {
  83. chomp $httpd;
  84. $webowner = `grep "^User " $httpd`;
  85. $webgroup = `grep "^Group " $httpd`;
  86. chomp $webowner;
  87. chomp $webgroup;
  88. ($null, $webowner) = split / /, $webowner;
  89. ($null, $webgroup) = split / /, $webgroup;
  90. }
  91. if ($confd = `find /etc /usr/local/etc -type d -name 'apache*/conf.d'`) {
  92. chomp $confd;
  93. }
  94. system("tput clear");
  95. if ($filename) {
  96. $install = "\ninstall $version from (f)ile\n";
  97. }
  98. # check for latest version
  99. &get_latest_version;
  100. chomp $latest_version;
  101. if (!$newinstall) {
  102. $install .= "\n(r)einstall $version\n";
  103. }
  104. if ($version && $latest_version) {
  105. if ($version lt $latest_version) {
  106. $install .= "\n(u)pgrade to $latest_version\n";
  107. }
  108. }
  109. $install .= "\n(i)nstall $latest_version (from Internet)\n" if $latest_version;
  110. $install .= "\n(d)ownload $latest_version (no installation)" unless $filename;
  111. print qq|
  112. LedgerSMB Accounting and ERP Installation
  113. $install
  114. Enter: |;
  115. $a = <STDIN>;
  116. chomp $a;
  117. exit unless $a;
  118. $a = lc $a;
  119. if ($a !~ /d/) {
  120. print qq|\nEnter httpd owner [$webowner] : |;
  121. $web = <STDIN>;
  122. chomp $web;
  123. $webowner = $web if $web;
  124. print qq|\nEnter httpd group [$webgroup] : |;
  125. $web = <STDIN>;
  126. chomp $web;
  127. $webgroup = $web if $web;
  128. }
  129. if ($a ne 'f') {
  130. system("tput clear");
  131. # choose site
  132. foreach $item (sort { $a <=> $b } keys %source) {
  133. $i++;
  134. print qq|$i. $source{$item}{site}\n|;
  135. }
  136. $site = "1";
  137. print qq|\nChoose Location [$site] : |;
  138. $b = <STDIN>;
  139. chomp $b;
  140. $site = $b if $b;
  141. }
  142. if ($a eq 'd') {
  143. &download;
  144. }
  145. if ($a =~ /(i|u)/) {
  146. &install;
  147. }
  148. if ($a eq 'r') {
  149. $latest_version = $version;
  150. &install;
  151. }
  152. if ($a eq 'f') {
  153. &install;
  154. }
  155. exit;
  156. # end main
  157. sub download {
  158. &get_source_code;
  159. }
  160. sub get_latest_version {
  161. print "Checking for latest version number .... ";
  162. if ($filename) {
  163. print "skipping, filename supplied\n";
  164. return;
  165. }
  166. if ($lwp) {
  167. foreach $source (qw(pluto www abacus neptune)) {
  168. $url = $source{$checkversion{$source}}{url};
  169. print "\n$source{$checkversion{$source}}{site} ... ";
  170. $latest_version = LWP::Simple::get("$url/latest_version");
  171. if ($latest_version) {
  172. last;
  173. } else {
  174. print "not found";
  175. }
  176. }
  177. } else {
  178. if (!$lynx) {
  179. print "\nYou must have either lynx or LWP installed";
  180. exit 1;
  181. }
  182. foreach $source (qw(pluto www abacus neptune)) {
  183. $url = $source{$checkversion{$source}}{url};
  184. print "\n$source{$checkversion{$source}}{site} ... ";
  185. $ok = `lynx -dump -head $url/latest_version`;
  186. if ($ok = ($ok =~ s/HTTP.*?200 //)) {
  187. $latest_version = `lynx -dump $url/latest_version`;
  188. last;
  189. } else {
  190. print "not found";
  191. }
  192. }
  193. die unless $ok;
  194. }
  195. if ($latest_version) {
  196. print "ok\n";
  197. 1;
  198. }
  199. }
  200. sub get_source_code {
  201. $err = 0;
  202. @order = ();
  203. push @order, $site;
  204. for (sort { $a <=> $b } keys %source) {
  205. push @order, $_;
  206. }
  207. if ($latest_version) {
  208. # download it
  209. chomp $latest_version;
  210. $latest_version = "sql-ledger-${latest_version}.tar.gz";
  211. print "\nStatus\n";
  212. print "Downloading $latest_version .... ";
  213. foreach $key (@order) {
  214. print "\n$source{$key}{site} .... ";
  215. if ($lwp) {
  216. $err = LWP::Simple::getstore("$source{$key}{url}/$latest_version", "$latest_version");
  217. $err -= 200;
  218. } else {
  219. $ok = `lynx -dump -head $source{$key}{url}/$latest_version`;
  220. $err = !($ok =~ s/HTTP.*?200 //);
  221. if (!$err) {
  222. $err = system("lynx -dump $source{$key}{url}/$latest_version > $latest_version");
  223. }
  224. }
  225. if ($err) {
  226. print "failed!";
  227. } else {
  228. last;
  229. }
  230. }
  231. } else {
  232. $err = -1;
  233. }
  234. if ($err) {
  235. die "Cannot get $latest_version";
  236. } else {
  237. print "ok!\n";
  238. }
  239. $latest_version;
  240. }
  241. sub install {
  242. if ($filename) {
  243. $latest_version = $filename;
  244. } else {
  245. $latest_version = &get_source_code;
  246. }
  247. &decompress;
  248. if ($newinstall) {
  249. open(FH, "sql-ledger.conf.default");
  250. @f = <FH>;
  251. close(FH);
  252. unless ($latex) {
  253. grep { s/^\$latex.*/\$latex = 0;/ } @f;
  254. }
  255. open(FH, ">sql-ledger.conf");
  256. print FH @f;
  257. close(FH);
  258. $alias = $absolutealias = $ENV{'PWD'};
  259. $alias =~ s/.*\///g;
  260. $httpddir = `dirname $httpd`;
  261. if ($confd) {
  262. $httpddir = $confd;
  263. }
  264. chomp $httpddir;
  265. $filename = "sql-ledger-httpd.conf";
  266. # do we have write permission?
  267. if (!open(FH, ">>$httpddir/$filename")) {
  268. open(FH, ">$filename");
  269. $norw = 1;
  270. }
  271. $directives = qq|
  272. Alias /$alias $absolutealias/
  273. <Directory $absolutealias>
  274. AllowOverride All
  275. AddHandler cgi-script .pl
  276. Options ExecCGI Includes FollowSymlinks
  277. Order Allow,Deny
  278. Allow from All
  279. </Directory>
  280. <Directory $absolutealias/users>
  281. Order Deny,Allow
  282. Deny from All
  283. </Directory>
  284. |;
  285. print FH $directives;
  286. close(FH);
  287. print qq|
  288. This is a new installation.
  289. |;
  290. if ($norw) {
  291. print qq|
  292. Webserver directives were written to $filename
  293. Copy $filename to $httpddir
  294. |;
  295. if (!$confd) {
  296. print qq| and add
  297. # SQL-Ledger
  298. Include $httpddir/$filename
  299. to $httpd
  300. |;
  301. }
  302. print qq| and restart your webserver!\n|;
  303. if (!$permset) {
  304. print qq|
  305. WARNING: permissions for templates, users, css and spool directory
  306. could not be set. Login as root and set permissions
  307. # chown -hR :$webgroup users templates css spool
  308. # chmod 771 users templates css spool
  309. |;
  310. }
  311. } else {
  312. print qq|
  313. Webserver directives were written to
  314. $httpddir/$filename
  315. |;
  316. if (!$confd) {
  317. if (!(`grep "^# SQL-Ledger" $httpd`)) {
  318. open(FH, ">>$httpd");
  319. print FH qq|
  320. # SQL-Ledger
  321. Include $httpddir/$filename
  322. |;
  323. close(FH);
  324. }
  325. }
  326. if (!$>) {
  327. # send SIGHUP to httpd
  328. if ($f = `find /var -type f -name 'httpd.pid'`) {
  329. $pid = `cat $f`;
  330. chomp $pid;
  331. if ($pid) {
  332. system("kill -s HUP $pid");
  333. }
  334. }
  335. }
  336. }
  337. }
  338. # if this is not root, check if user is part of $webgroup
  339. if ($>) {
  340. if ($permset = ($) =~ getgrnam $webgroup)) {
  341. `chown -hR :$webgroup users templates css spool`;
  342. chmod 0771, 'users', 'templates', 'css', 'spool';
  343. `chown :$webgroup sql-ledger.conf`;
  344. }
  345. } else {
  346. # root
  347. `chown -hR 0:0 *`;
  348. `chown -hR $webowner:$webgroup users templates css spool`;
  349. chmod 0771, 'users', 'templates', 'css', 'spool';
  350. `chown $webowner:$webgroup sql-ledger.conf`;
  351. }
  352. chmod 0644, 'sql-ledger.conf';
  353. unlink "sql-ledger.conf.default";
  354. &cleanup;
  355. while ($a !~ /(Y|N)/) {
  356. print qq|\nDisplay README (Y/n) : |;
  357. $a = <STDIN>;
  358. chomp $a;
  359. $a = ($a) ? uc $a : 'Y';
  360. if ($a eq 'Y') {
  361. @args = ("more", "doc/README");
  362. system(@args);
  363. }
  364. }
  365. }
  366. sub decompress {
  367. die "Error: gzip not installed\n" unless ($gzip);
  368. die "Error: tar not installed\n" unless ($tar);
  369. &create_lockfile;
  370. # ungzip and extract source code
  371. print "Decompressing $latest_version ... ";
  372. if (system("gzip -df $latest_version")) {
  373. print "Error: Could not decompress $latest_version\n";
  374. &remove_lockfile;
  375. exit;
  376. } else {
  377. print "done\n";
  378. }
  379. # strip gz from latest_version
  380. $latest_version =~ s/\.gz//;
  381. # now untar it
  382. print "Unpacking $latest_version ... ";
  383. if (system("tar -xf $latest_version")) {
  384. print "Error: Could not unpack $latest_version\n";
  385. &remove_lockfile;
  386. exit;
  387. } else {
  388. # now we have a copy in sql-ledger
  389. if (system("tar -cf $latest_version -C sql-ledger .")) {
  390. print "Error: Could not create archive for $latest_version\n";
  391. &remove_lockfile;
  392. exit;
  393. } else {
  394. if (system("tar -xf $latest_version")) {
  395. print "Error: Could not unpack $latest_version\n";
  396. &remove_lockfile;
  397. exit;
  398. } else {
  399. print "done\n";
  400. print "cleaning up ... ";
  401. `rm -rf sql-ledger`;
  402. print "done\n";
  403. }
  404. }
  405. }
  406. }
  407. sub create_lockfile {
  408. if (-d "$userspath") {
  409. open(FH, ">$userspath/nologin");
  410. close(FH);
  411. }
  412. }
  413. sub cleanup {
  414. unlink "$latest_version";
  415. unlink "$userspath/members.default" if (-f "$userspath/members.default");
  416. &remove_lockfile;
  417. }
  418. sub remove_lockfile { unlink "$userspath/nologin" if (-f "$userspath/nologin") };
  419. #
  420. # Web: http://sourceforge.net/projects/ledger-smb/
  421. #
  422. #######################################################################
  423. # This script is awaiting rewriting to work with LedgerSMB
  424. #
  425. print "This script should not be used with LedgerSMB in this release.\n\n";
  426. exit;
  427. $| = 1;
  428. if ($ENV{HTTP_USER_AGENT}) {
  429. print "
  430. This does not work yet!
  431. use $0 from the command line";
  432. exit;
  433. }
  434. $lynx = `lynx -version`; # if LWP is not installed use lynx
  435. $gzip = `gzip -V 2>&1`; # gz decompression utility
  436. $tar = `tar --version 2>&1`; # tar archiver
  437. $latex = `latex -version`;
  438. %checkversion = ( www => 3, abacus => 4, pluto => 5, neptune => 8 );
  439. %source = (
  440. 1 => { url => "http://voxel.dl.sourceforge.net/sourceforge/sql-ledger", site => "New York, U.S.A", locale => us },
  441. 2 => { url => "http://easynews.dl.sourceforge.net/sourceforge/sql-ledger", site => "Arizona, U.S.A", locale => us },
  442. 3 => { url => "http://www.sql-ledger.com/source", site => "California, U.S.A", locale => us },
  443. 4 => { url => "http://abacus.sql-ledger.com/source", site => "Toronto, Canada", locale => ca },
  444. 5 => { url => "http://pluto.sql-ledger.com/source", site => "Edmonton, Canada", locale => ca },
  445. 6 => { url => "http://ufpr.dl.sourceforge.net/sourceforge/sql-ledger", site =>"Brazil", locale => br },
  446. 7 => { url => "http://surfnet.dl.sourceforge.net/sourceforge/sql-ledger", site => "The Netherlands", locale => nl },
  447. 8 => { url => "http://neptune.sql-ledger.com/source", site => "Ireland", locale => ie },
  448. 9 => { url => "http://kent.dl.sourceforge.net/sourceforge/sql-ledger", site => "U.K", locale => uk },
  449. 10 => { url => "http://ovh.dl.sourceforge.net/sourceforge/sql-ledger", site => "France", locale => fr },
  450. 11 => { url => "http://mesh.dl.sourceforge.net/sourceforge/sql-ledger", site => "Germany", locale => de },
  451. 12 => { url => "http://citkit.dl.sourceforge.net/sourceforge/sql-ledger", site => "Russia", locale => ru },
  452. 13 => { url => "http://optusnet.dl.sourceforge.net/sourceforge/sql-ledger", site => "Sydney, Australia", locale => au },
  453. 14 => { url => "http://nchc.dl.sourceforge.net/sourceforge/sql-ledger", site => "Taiwan", locale => tw },
  454. 15 => { url => "http://jaist.dl.sourceforge.net/sourceforge/sql-ledger", site => "Japan", locale => jp }
  455. );
  456. $userspath = "users"; # default for new installation
  457. eval { require "ledger-smb.conf"; };
  458. $filename = shift;
  459. chomp $filename;
  460. $newinstall = 1;
  461. # is LWP installed
  462. eval { require LWP::Simple; };
  463. $lwp = !($@);
  464. unless ($lwp || $lynx || $filename) {
  465. die "You must have either lynx or LWP installed or specify a filename.
  466. perl $0 <filename>\n";
  467. }
  468. if ($filename) {
  469. # extract version
  470. die "Not a LedgerSMB archive\n" if ($filename !~ /^sql-ledger/);
  471. $version = $filename;
  472. $version =~ s/sql-ledger-(\d+\.\d+\.\d+).*$/$1/;
  473. }
  474. if (-f "VERSION") {
  475. # get installed version from VERSION file
  476. open(FH, "VERSION");
  477. @a = <FH>;
  478. close(FH);
  479. $version = $a[0];
  480. chomp $version;
  481. $newinstall = !$version;
  482. if (! -f "ledger-smb.conf") {
  483. $newinstall = 1;
  484. }
  485. }
  486. $webowner = "nobody";
  487. $webgroup = "nogroup";
  488. if ($httpd = `find /etc /usr/local/etc -type f -name 'httpd.conf'`) {
  489. chomp $httpd;
  490. $webowner = `grep "^User " $httpd`;
  491. $webgroup = `grep "^Group " $httpd`;
  492. chomp $webowner;
  493. chomp $webgroup;
  494. ($null, $webowner) = split / /, $webowner;
  495. ($null, $webgroup) = split / /, $webgroup;
  496. }
  497. if ($confd = `find /etc /usr/local/etc -type d -name 'apache*/conf.d'`) {
  498. chomp $confd;
  499. }
  500. system("tput clear");
  501. if ($filename) {
  502. $install = "\ninstall $version from (f)ile\n";
  503. }
  504. # check for latest version
  505. &get_latest_version;
  506. chomp $latest_version;
  507. if (!$newinstall) {
  508. $install .= "\n(r)einstall $version\n";
  509. }
  510. if ($version && $latest_version) {
  511. if ($version lt $latest_version) {
  512. $install .= "\n(u)pgrade to $latest_version\n";
  513. }
  514. }
  515. $install .= "\n(i)nstall $latest_version (from Internet)\n" if $latest_version;
  516. $install .= "\n(d)ownload $latest_version (no installation)" unless $filename;
  517. print qq|
  518. LedgerSMB Accounting and ERP Installation
  519. $install
  520. Enter: |;
  521. $a = <STDIN>;
  522. chomp $a;
  523. exit unless $a;
  524. $a = lc $a;
  525. if ($a !~ /d/) {
  526. print qq|\nEnter httpd owner [$webowner] : |;
  527. $web = <STDIN>;
  528. chomp $web;
  529. $webowner = $web if $web;
  530. print qq|\nEnter httpd group [$webgroup] : |;
  531. $web = <STDIN>;
  532. chomp $web;
  533. $webgroup = $web if $web;
  534. }
  535. if ($a ne 'f') {
  536. system("tput clear");
  537. # choose site
  538. foreach $item (sort { $a <=> $b } keys %source) {
  539. $i++;
  540. print qq|$i. $source{$item}{site}\n|;
  541. }
  542. $site = "1";
  543. print qq|\nChoose Location [$site] : |;
  544. $b = <STDIN>;
  545. chomp $b;
  546. $site = $b if $b;
  547. }
  548. if ($a eq 'd') {
  549. &download;
  550. }
  551. if ($a =~ /(i|u)/) {
  552. &install;
  553. }
  554. if ($a eq 'r') {
  555. $latest_version = $version;
  556. &install;
  557. }
  558. if ($a eq 'f') {
  559. &install;
  560. }
  561. exit;
  562. # end main
  563. sub download {
  564. &get_source_code;
  565. }
  566. sub get_latest_version {
  567. print "Checking for latest version number .... ";
  568. if ($filename) {
  569. print "skipping, filename supplied\n";
  570. return;
  571. }
  572. if ($lwp) {
  573. foreach $source (qw(pluto www abacus neptune)) {
  574. $url = $source{$checkversion{$source}}{url};
  575. print "\n$source{$checkversion{$source}}{site} ... ";
  576. $latest_version = LWP::Simple::get("$url/latest_version");
  577. if ($latest_version) {
  578. last;
  579. } else {
  580. print "not found";
  581. }
  582. }
  583. } else {
  584. if (!$lynx) {
  585. print "\nYou must have either lynx or LWP installed";
  586. exit 1;
  587. }
  588. foreach $source (qw(pluto www abacus neptune)) {
  589. $url = $source{$checkversion{$source}}{url};
  590. print "\n$source{$checkversion{$source}}{site} ... ";
  591. $ok = `lynx -dump -head $url/latest_version`;
  592. if ($ok = ($ok =~ s/HTTP.*?200 //)) {
  593. $latest_version = `lynx -dump $url/latest_version`;
  594. last;
  595. } else {
  596. print "not found";
  597. }
  598. }
  599. die unless $ok;
  600. }
  601. if ($latest_version) {
  602. print "ok\n";
  603. 1;
  604. }
  605. }
  606. sub get_source_code {
  607. $err = 0;
  608. @order = ();
  609. push @order, $site;
  610. for (sort { $a <=> $b } keys %source) {
  611. push @order, $_;
  612. }
  613. if ($latest_version) {
  614. # download it
  615. chomp $latest_version;
  616. $latest_version = "sql-ledger-${latest_version}.tar.gz";
  617. print "\nStatus\n";
  618. print "Downloading $latest_version .... ";
  619. foreach $key (@order) {
  620. print "\n$source{$key}{site} .... ";
  621. if ($lwp) {
  622. $err = LWP::Simple::getstore("$source{$key}{url}/$latest_version", "$latest_version");
  623. $err -= 200;
  624. } else {
  625. $ok = `lynx -dump -head $source{$key}{url}/$latest_version`;
  626. $err = !($ok =~ s/HTTP.*?200 //);
  627. if (!$err) {
  628. $err = system("lynx -dump $source{$key}{url}/$latest_version > $latest_version");
  629. }
  630. }
  631. if ($err) {
  632. print "failed!";
  633. } else {
  634. last;
  635. }
  636. }
  637. } else {
  638. $err = -1;
  639. }
  640. if ($err) {
  641. die "Cannot get $latest_version";
  642. } else {
  643. print "ok!\n";
  644. }
  645. $latest_version;
  646. }
  647. sub install {
  648. if ($filename) {
  649. $latest_version = $filename;
  650. } else {
  651. $latest_version = &get_source_code;
  652. }
  653. &decompress;
  654. if ($newinstall) {
  655. open(FH, "ledger-smb.conf.default");
  656. @f = <FH>;
  657. close(FH);
  658. unless ($latex) {
  659. grep { s/^\$latex.*/\$latex = 0;/ } @f;
  660. }
  661. open(FH, ">ledger-smb.conf");
  662. print FH @f;
  663. close(FH);
  664. $alias = $absolutealias = $ENV{'PWD'};
  665. $alias =~ s/.*\///g;
  666. $httpddir = `dirname $httpd`;
  667. if ($confd) {
  668. $httpddir = $confd;
  669. }
  670. chomp $httpddir;
  671. $filename = "sql-ledger-httpd.conf";
  672. # do we have write permission?
  673. if (!open(FH, ">>$httpddir/$filename")) {
  674. open(FH, ">$filename");
  675. $norw = 1;
  676. }
  677. $directives = qq|
  678. Alias /$alias $absolutealias/
  679. <Directory $absolutealias>
  680. AllowOverride All
  681. AddHandler cgi-script .pl
  682. Options ExecCGI Includes FollowSymlinks
  683. Order Allow,Deny
  684. Allow from All
  685. </Directory>
  686. <Directory $absolutealias/users>
  687. Order Deny,Allow
  688. Deny from All
  689. </Directory>
  690. |;
  691. print FH $directives;
  692. close(FH);
  693. print qq|
  694. This is a new installation.
  695. |;
  696. if ($norw) {
  697. print qq|
  698. Webserver directives were written to $filename
  699. Copy $filename to $httpddir
  700. |;
  701. if (!$confd) {
  702. print qq| and add
  703. # SQL-Ledger
  704. Include $httpddir/$filename
  705. to $httpd
  706. |;
  707. }
  708. print qq| and restart your webserver!\n|;
  709. if (!$permset) {
  710. print qq|
  711. WARNING: permissions for templates, users, css and spool directory
  712. could not be set. Login as root and set permissions
  713. # chown -hR :$webgroup users templates css spool
  714. # chmod 771 users templates css spool
  715. |;
  716. }
  717. } else {
  718. print qq|
  719. Webserver directives were written to
  720. $httpddir/$filename
  721. |;
  722. if (!$confd) {
  723. if (!(`grep "^# SQL-Ledger" $httpd`)) {
  724. open(FH, ">>$httpd");
  725. print FH qq|
  726. # SQL-Ledger
  727. Include $httpddir/$filename
  728. |;
  729. close(FH);
  730. }
  731. }
  732. if (!$>) {
  733. # send SIGHUP to httpd
  734. if ($f = `find /var -type f -name 'httpd.pid'`) {
  735. $pid = `cat $f`;
  736. chomp $pid;
  737. if ($pid) {
  738. system("kill -s HUP $pid");
  739. }
  740. }
  741. }
  742. }
  743. }
  744. # if this is not root, check if user is part of $webgroup
  745. if ($>) {
  746. if ($permset = ($) =~ getgrnam $webgroup)) {
  747. `chown -hR :$webgroup users templates css spool`;
  748. chmod 0771, 'users', 'templates', 'css', 'spool';
  749. `chown :$webgroup ledger-smb.conf`;
  750. }
  751. } else {
  752. # root
  753. `chown -hR 0:0 *`;
  754. `chown -hR $webowner:$webgroup users templates css spool`;
  755. chmod 0771, 'users', 'templates', 'css', 'spool';
  756. `chown $webowner:$webgroup ledger-smb.conf`;
  757. }
  758. chmod 0644, 'ledger-smb.conf';
  759. unlink "ledger-smb.conf.default";
  760. &cleanup;
  761. while ($a !~ /(Y|N)/) {
  762. print qq|\nDisplay README (Y/n) : |;
  763. $a = <STDIN>;
  764. chomp $a;
  765. $a = ($a) ? uc $a : 'Y';
  766. if ($a eq 'Y') {
  767. @args = ("more", "doc/README");
  768. system(@args);
  769. }
  770. }
  771. }
  772. sub decompress {
  773. die "Error: gzip not installed\n" unless ($gzip);
  774. die "Error: tar not installed\n" unless ($tar);
  775. &create_lockfile;
  776. # ungzip and extract source code
  777. print "Decompressing $latest_version ... ";
  778. if (system("gzip -df $latest_version")) {
  779. print "Error: Could not decompress $latest_version\n";
  780. &remove_lockfile;
  781. exit;
  782. } else {
  783. print "done\n";
  784. }
  785. # strip gz from latest_version
  786. $latest_version =~ s/\.gz//;
  787. # now untar it
  788. print "Unpacking $latest_version ... ";
  789. if (system("tar -xf $latest_version")) {
  790. print "Error: Could not unpack $latest_version\n";
  791. &remove_lockfile;
  792. exit;
  793. } else {
  794. # now we have a copy in sql-ledger
  795. if (system("tar -cf $latest_version -C sql-ledger .")) {
  796. print "Error: Could not create archive for $latest_version\n";
  797. &remove_lockfile;
  798. exit;
  799. } else {
  800. if (system("tar -xf $latest_version")) {
  801. print "Error: Could not unpack $latest_version\n";
  802. &remove_lockfile;
  803. exit;
  804. } else {
  805. print "done\n";
  806. print "cleaning up ... ";
  807. `rm -rf sql-ledger`;
  808. print "done\n";
  809. }
  810. }
  811. }
  812. }
  813. sub create_lockfile {
  814. if (-d "$userspath") {
  815. open(FH, ">$userspath/nologin");
  816. close(FH);
  817. }
  818. }
  819. sub cleanup {
  820. unlink "$latest_version";
  821. unlink "$userspath/members.default" if (-f "$userspath/members.default");
  822. &remove_lockfile;
  823. }
  824. sub remove_lockfile { unlink "$userspath/nologin" if (-f "$userspath/nologin") };