sylpheed-switcher 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. #!/usr/bin/perl
  2. # * Copyright © 2001 Paul Mangan <claws@thewildbeast.co.uk>
  3. # *
  4. # * This file is free software; you can redistribute it and/or modify it
  5. # * under the terms of the GNU General Public License as published by
  6. # * the Free Software Foundation; either version 2 of the License, or
  7. # * (at your option) any later version.
  8. # *
  9. # * This program is distributed in the hope that it will be useful, but
  10. # * WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. # * General Public License for more details.
  13. # *
  14. # * You should have received a copy of the GNU General Public License
  15. # * along with this program; if not, write to the Free Software
  16. # * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  17. # *
  18. # Script Name: The Nasnas
  19. # Script Version: 0.4
  20. ######################################################
  21. ######################################################
  22. ### ###
  23. ### FOR USAGE INSTRUCTIONS RUN THIS SCRIPT WITH ###
  24. ### THE FOLLOWING OPTION: ###
  25. ### ###
  26. ### ./sylpheed-switcher --help ###
  27. ### ###
  28. ######################################################
  29. ######################################################
  30. use File::Path;
  31. use Getopt::Long;
  32. my $sylpheed = 0;
  33. my $claws = 0;
  34. my $sylphpath = '';
  35. my $clawspath = '';
  36. my $debug = 0;
  37. my $YouWantHelp = 0;
  38. GetOptions("main" => \$sylpheed,
  39. "claws" => \$claws,
  40. "main-path=s" => \$sylphpath,
  41. "claws-path=s" => \$clawspath,
  42. "debug" => \$debug,
  43. "help" => \$YouWantHelp);
  44. chdir; ## use $HOME for the working directory
  45. unless (-e ".sylpheed") { ## check for the .sylpheed directory
  46. print "Your '.sylpheed' directory is missing. This probably means that ";
  47. print "you have never run sylpheed before.\n";
  48. print "Before running sylpheed-switcher run sylpheed normally at least once.\n";
  49. exit;
  50. }
  51. open (SYLSWIT, "<.sylpheed-switcher"); ## read the config file
  52. @conf_file = <SYLSWIT>;
  53. close SYLSWIT;
  54. if ($sylphpath && $clawspath) { ## this is the initial set-up part
  55. ## write the config file
  56. $PATH_INFO = "$clawspath\n$sylphpath";
  57. open (CONFFILE, ">.sylpheed-switcher");
  58. print CONFFILE $PATH_INFO;
  59. close CONFFILE;
  60. ## it appears that you'd run this script before, but the config file was missing
  61. $DIR_CHECK = opendir(CHECKDIR, ".sylpheed-claws");
  62. closedir(CHECKDIR);
  63. if ($DIR_CHECK == 1) {
  64. print "\nNow you can run either the main branch or the claws\n";
  65. print "branch by using one of the following options:\n\n";
  66. print "./sylpheed-switcher --main\n./sylpheed-switcher --claws\n\n";
  67. exit;
  68. }
  69. ## copy the directory tree
  70. system "cp -R .sylpheed .sylpheed-main";
  71. system "cp -R .sylpheed .sylpheed-claws";
  72. ## when setting-up is done print a little message
  73. print "\nNow you can run either the main branch or the claws\n";
  74. print "branch by using one of the following options:\n\n";
  75. print "./sylpheed-switcher --main\n./sylpheed-switcher --claws\n\n";
  76. exit;
  77. }
  78. ## the --help option stuff
  79. if ($YouWantHelp) {
  80. print "\n The SYLPHEED<->CLAWS SWITCHER\n\n";
  81. print "If you are running this script for the first time you will need \n";
  82. print "to set up the configuration. Here is an example, adjust the paths\n";
  83. print "to suit your set-up, but remember you need the full path with the\n";
  84. print "executable included:\n";
  85. print "./sylpheed-switcher --main-path=/usr/local/bin/sylpheed --claws-path=/usr/bin/sylpheed\n\n";
  86. print "When you have done the initial set-up, you run either the main branch\n";
  87. print "or the claws branch by using one of the following switches:\n\n";
  88. print "./sylpheed-switcher --main\n./sylpheed-switcher --claws\n\n";
  89. print "Add --debug to run sylpheed in debug mode\n\n";
  90. exit;
  91. }
  92. ## if the config file doesn't exist...
  93. if (!@conf_file) {
  94. print "Use the following set-up options first, or --help for more info:\n";
  95. print "--claws-path=PATH # path to (and including) the claws sylpheed executable\n";
  96. print "--main-path=PATH # path to (and including) the main sylpheed executable\n";
  97. exit;
  98. }
  99. ## check that the chosen execuatble exists
  100. ## get rid of the old symbolic link, make a new one, and run the required executable
  101. if ($claws) {
  102. chomp $conf_file[0];
  103. unless (-e $conf_file[0]) {
  104. print "\n$conf_file[0] does not exist\n\n";
  105. exit;
  106. }
  107. rmtree(".sylpheed");
  108. symlink(".sylpheed-claws",".sylpheed");
  109. if ($debug eq 1) {
  110. exec "$conf_file[0] --debug";
  111. } else {
  112. exec "$conf_file[0]";
  113. }
  114. exit;
  115. } elsif ($sylpheed) {
  116. chomp $conf_file[1];
  117. unless (-e $conf_file[1]) {
  118. print "\n$conf_file[1] does not exist\n\n";
  119. exit;
  120. }
  121. rmtree(".sylpheed");
  122. symlink(".sylpheed-main",".sylpheed");
  123. if ($debug eq 1) {
  124. exec "$conf_file[1] --debug";
  125. } else {
  126. exec "$conf_file[1]";
  127. }
  128. exit;
  129. } elsif (!$claws && !$sylpheed && @conf_file) { ## you've got the config file but haven't said
  130. print "\nUse one of the following switches:\n"; ## which version you want to run
  131. print " --main # to run sylpheed main\n";
  132. print " --claws # to run sylpheed claws\n";
  133. print " --help # to view the help message\n";
  134. print "Optionally, you can also use:\n";
  135. print " --debug # to run in debug mode [optional]\n\n";
  136. exit;
  137. }
  138. ###############################