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