f6f11db8fbb782e3db845ecd80678cf530060906
[freeside.git] / install / rpm / freeside-install
1 #!/bin/sh
2 # This is based on the Fedora Core 3 INSTALL file, modified using the information in the Freeside Wiki
3 # It's intended to be a universal Freeside installation script, but it's nowhere near that yet.
4 #
5
6 # Primary domain - see the Wiki
7 DOMAIN=
8 # Package manager to use
9 PACKAGER=
10 # Main freeside user
11 USER=
12 # Name for database for this instance of freeside
13 DBNAME=freeside
14
15 # Parse the command line arguments
16 #parse_cli_arguments()
17 #{
18         while getopts "hd:n:p:u:" flag
19         do
20                 case $flag in
21                 d)
22                         NEWVAL=`echo $OPTARG | tr '[A-Z]' '[a-z]'`
23                         if [ "x$DOMAIN" -ne "x" ] ; then
24                                 echo STDERR "Domain already set to $DOMAIN.  Changing to $NEWVAL"
25                         fi
26                         DOMAIN=$NEWVAL;;
27                 h)
28                         usage;;
29                 n)
30                         # We don't lowercase the database name
31                         if [ "x$DBNAME" -ne "x" ] ; then
32                                 echo STDERR "Database name already set to $DBNAME.  Changing to $OPTARG"
33                         fi
34                         DBNAME=$OPTARG;;
35                 p)
36                         NEWVAL=`echo $OPTARG | tr '[A-Z]' '[a-z]'`
37                         if [ "x$PACKAGER" -ne "x" ] ; then
38                                 echo STDERR "Packager already set to $PACKAGER.  Changing to $NEWVAL"
39                         fi
40                         PACKAGER=$NEWVAL;;
41                 u)
42                         # We don't lowercase the user name
43                         if [ "x$USER" -ne "x" ] ; then
44                                 echo STDERR "Main freeside web user already set to $USER.  Changing to $OPTARG"
45                         fi
46                         USER=$OPTARG;;
47                 esac
48         done
49 #}
50
51 usage()
52 {
53         echo "freeside-install is a utility to install the Freeside ISP billing system."
54         echo "Usage:    freeside-install -d <domain> -n <database name> -p <packager> -u <first web user>"
55         echo "where:"
56         echo "  domain is the required first domain, usually the ISP's main customer domain"
57         echo "  database name is the name of the database for this instance of Freeside - defaults to freeside"
58         echo "  packager is the package management tool you want to use: RPM, CPAN, etc."
59         exit 1
60 }
61
62 apologize()
63 {
64         echo "Sorry, this version of freeside-install is non-functional.  Feel free to contribute fixes"
65         echo "See http://www.sisd.com/mediawiki/index.php/Freeside:1.7:Documentation:Installation for information on how to install Freeside"
66         exit 1
67 }
68
69 install_perl_module()
70 {
71         # We should do something smarter than this, checking to see if the module was installed
72         # and falling back to another package manager (or two) if not
73         echo "$MODULE: $CPAN"
74         case $PACKAGER in
75         apt)
76                 # apt-get install $CPAN;
77                 ;;
78         cpan)
79                 # cpan install $CPAN;
80                 ;;
81         cpan2rpm)
82                 # cpan2rpm $CPAN;
83                 # rpm -Uvh /usr/src/redhat/RPMS/*/perl-$CPAN*.rpm
84                 ;;
85         rpm)
86                 # Nothing to do; RPM should already be installed?
87                 ;;
88         yum)
89                 # yum install perl-$CPAN;
90                 ;;
91         esac
92 }
93
94 install_all_perl_modules()
95 {
96         while read MODULE CPAN
97         do
98                 install_perl_module $MODULE $CPAN;
99         done <<EOF
100 # Probably included in the distro
101 libnet          Net::Cmd
102 libwww-perl     Bundle::LWP
103 URI
104 HTML::Tagset
105 HTML::Parser 
106 HTML::Mason
107 Text::Template
108 DBI
109 DBD::Pg
110 MailTools       Mail::Internet
111 MIME::Tools
112 TimeDate        Date::Format
113 Locale-Codes    Locale::Country
114 DateTime 
115 # Less common modules
116 Chart   Chart::Base
117 Cache::Cache
118 NetAddr::IP
119 String::Approx
120 Locale::SubCountry
121 Frontier::RPC2
122 Term::ReadKey
123 Date::Manip
124 DateTime::Format::Strptime
125 Text::CSV_XS 
126 # Rare modules
127 Business::CreditCard
128 Net::Whois::Raw
129 DBIx::DBSchema
130 Tie::IxHash
131 Crypt::PasswdMD5
132 Time::Duration
133 File::CounterFile
134 IPC::Run3
135 Net::SSH
136 String::ShellQuote
137 JSON
138 HTML::Widgets::SelectLayers
139 Color::Scheme
140 Lingua::EN::NameParse
141 Lingua::EN::Inflect 
142 # Optional modules - we'll add them anyway
143 Fax::Hylafax::Client
144 Apache::DBI
145 EOF
146 }
147
148 # Create the freeside user account and create the database in PostgreSQL
149 add_freeside_user()
150 {
151         /usr/sbin/useradd freeside
152         chsh freeside -s /bin/bash
153 }
154
155 start_pg()
156 {
157         /sbin/chkconfig postgresql on
158         /etc/init.d/postgresql start
159 }
160
161 create_freeside_pg_user_and_db()
162 {
163         echo "Creating Freeside database user for Pg"
164         su postgres -c "createuser -P -A -d freeside"
165
166         echo "Creating the $DBNAME database"
167         su freeside -c "createdb -E sql_ascii $DBNAME"
168 }
169
170 # Install Freeside's Perl modules, create the configuration, and create the first user
171 install_freeside()
172 {
173 ##      cd ../../..
174         make install-perl-modules
175         make create-config
176 }
177
178 add_freeside_system_users()
179 {
180         echo "Creating Freeside system users"
181         for SYSUSER in fs_queue fs_daily fs_selfservice ; do
182                 su freeside -c "freeside-adduser -g 1 $SYSUSER"
183         done
184 }
185
186 add_first_freeside_user()
187 {
188         echo "Creating first Freeside application user"
189         su freeside -c "freeside-adduser -g 1 $USER"
190         su freeside -c "htpasswd -c /usr/local/etc/freeside/htpasswd $USER"
191 }
192
193 setup_freeside_database()
194 {
195         echo "Setting up Freeside for $DOMAIN"
196         su freeside -c "freeside-setup -d $DOMAIN"
197 }
198
199 # Should check that we're root...
200
201 #parse_cli_arguments;
202
203 if [ "x$USER" = "x" ]; then
204         usage;
205 fi
206
207 if [ "x$DOMAIN" = "x" ]; then
208         usage;
209 fi
210
211 if [ "$PACKAGER" -ne "rpm" ]; then
212         install_all_perl_modules;
213         install_freeside;
214 fi
215
216 start_pg;
217
218 create_freeside_pg_user_and_db;
219
220 setup_freeside_database;
221
222 add_freeside_system_users;
223
224 add_first_freeside_user;
225
226 exit 0;
227