Added startup API on OSX
authorJamie Cameron <jcameron@webmin.com>
Wed, 12 Mar 2008 20:48:58 +0000 (20:48 +0000)
committerJamie Cameron <jcameron@webmin.com>
Wed, 12 Mar 2008 20:48:58 +0000 (20:48 +0000)
init/CHANGELOG
init/atboot.pl
init/init-lib.pl

index d15371a..7b7fe82 100644 (file)
@@ -16,3 +16,5 @@ Added support for Unbuntu, which has not /etc/inittab file.
 Added start_action and stop_action functions for starting and stopping services in an OS-independent manner.
 ---- Changes since 1.390 ----
 Re-wrote all user interface code to use the new Webmin UI library, for a more consistent look.
+---- Changes since 1.400 ----
+Updated the API used by other modules to allow new actions to be created on MacOS X systems, such as the firewall startup script.
index 7050d7d..b2b939a 100755 (executable)
@@ -9,47 +9,9 @@ $ucproduct = ucfirst($product);
 
 if ($init_mode eq "osx") {
        # Darwin System
-       &open_tempfile(LOCAL, ">>$config{'hostconfig'}");
-       &print_tempfile(LOCAL, "WEBMIN=-YES-\n");
-       &close_tempfile(LOCAL);
-       
-       $paramlist = "$config{'darwin_setup'}/$ucproduct/$config{'plist'}";
-       $scriptfile = "$config{'darwin_setup'}/$ucproduct/$ucproduct";
-       
-       # On a Virgin darwin system, $config{'darwin_setup'} may not yet exist
-       -d "$config{'darwin_setup'}/$ucproduct" || do {
-               if ( -d "$config{'darwin_setup'}" ) {
-                       mkdir ("$config{'darwin_setup'}/$ucproduct", 0755);
-                       } else {
-                       mkdir ("$config{'darwin_setup'}", 0755);
-                       mkdir ("$config{'darwin_setup'}/$ucproduct",0755);
-                       }
-               } until -d "$config{'darwin_setup'}/$ucproduct";
-
-       &open_tempfile(PLIST, ">$paramlist");
-       &print_tempfile(PLIST, "{\n");
-       &print_tempfile(PLIST, "\t\tDescription\t\t= \"$ucproduct system administration daemon\";\n");
-       &print_tempfile(PLIST, "\t\tProvides\t\t= (\"$ucproduct\");\n");
-       &print_tempfile(PLIST, "\t\tRequires\t\t= (\"Resolver\");\n");
-       &print_tempfile(PLIST, "\t\tOrderPreference\t\t= \"None\";\n");
-       &print_tempfile(PLIST, "\t\tMessages =\n");
-       &print_tempfile(PLIST, "\t\t{\n");
-       &print_tempfile(PLIST, "\t\t\tstart\t= \"Starting $ucproduct Server\";\n");
-       &print_tempfile(PLIST, "\t\t\tstop\t= \"Stopping $ucproduct Server\";\n");
-       &print_tempfile(PLIST, "\t\t};\n");
-       &print_tempfile(PLIST, "}\n");
-       &close_tempfile(PLIST);
-
-       # Create Bootup Script
-       &open_tempfile(STARTUP, ">$scriptfile");
-       &print_tempfile(STARTUP, "#!/bin/sh\n\n");
-       &print_tempfile(STARTUP, ". /etc/rc.common\n\n");
-       &print_tempfile(STARTUP, "if [ \"\${WEBMIN:=-NO-}\" = \"-YES-\" ]; then\n");
-       &print_tempfile(STARTUP, "\tConsoleMessage \"Starting $ucproduct\"\n");
-       &print_tempfile(STARTUP, "\t$config_directory/start >/dev/null 2>&1 </dev/null\n");
-       &print_tempfile(STARTUP, "fi\n");
-       &close_tempfile(STARTUP);
-       chmod(0750, $scriptfile);
+       &enable_at_boot("webmin", "Webmin administration server",
+                       "/etc/webmin/start >/dev/null 2>&1 </dev/null",
+                       "/etc/webmin/stop");
        }
 elsif ($init_mode eq "local") {
        # Add to the boot time rc script
index ef76800..12f889e 100755 (executable)
@@ -430,6 +430,14 @@ elsif ($init_mode eq "rc") {
        return !$rc ? 0 :
               $rc->{'enabled'} ? 2 : 1;
        }
+elsif ($init_mode eq "osx") {
+       # Look for a hostconfig entry
+       local $ucname = uc($_[0]);
+       local %hc;
+       &read_env_file($config{'hostconfig'}, \%hc);
+       return $hc{$ucname} eq '-YES-' ? 2 :
+              $hc{$ucname} eq '-NO-' ? 1 : 0;
+       }
 }
 
 # enable_at_boot(action, description, startcode, stopcode, statuscode)
@@ -661,6 +669,59 @@ elsif ($init_mode eq "rc") {
                }
        &unlock_rc_files();
        }
+elsif ($init_mode eq "osx") {
+       # Add hostconfig file entry
+       local $ucname = uc($_[0]);
+       local %hc;
+       &lock_file($config{'hostconfig'});
+       &read_env_file($config{'hostconfig'}, \%hc);
+       if (!$hc{$ucname}) {
+               # Need to create action
+               local $ucfirst = ucfirst($_[0]);
+               local $dir = "$config{'darwin_setup'}/$ucfirst";
+               local $paramlist = "$dir/$config{'plist'}";
+               local $scriptfile = "$dir/$ucfirst";
+
+               # Create dirs if missing
+               if (!-d $config{'darwin_setup'}) {
+                       &make_dir($config{'darwin_setup'}, 0755);
+                       }
+               if (!-d $dir) {
+                       &make_dir($dir, 0755);
+                       }
+
+               # Make params list file
+               &open_lock_tempfile(PLIST, ">$paramlist");
+               &print_tempfile(PLIST, "{\n");
+               &print_tempfile(PLIST, "\t\tDescription\t\t= \"$_[1]\";\n");
+               &print_tempfile(PLIST, "\t\tProvides\t\t= (\"$ucfirst\");\n");
+               &print_tempfile(PLIST, "\t\tRequires\t\t= (\"Resolver\");\n");
+               &print_tempfile(PLIST, "\t\tOrderPreference\t\t= \"None\";\n");
+               &print_tempfile(PLIST, "\t\tMessages =\n");
+               &print_tempfile(PLIST, "\t\t{\n");
+               &print_tempfile(PLIST, "\t\t\tstart\t= \"Starting $ucfirst\";\n");
+               &print_tempfile(PLIST, "\t\t\tstop\t= \"Stopping $ucfirst\";\n");
+               &print_tempfile(PLIST, "\t\t};\n");
+               &print_tempfile(PLIST, "}\n");
+               &close_tempfile(PLIST);
+
+               # Create Bootup Script
+               &open_lock_tempfile(STARTUP, ">$scriptfile");
+               &print_tempfile(STARTUP, "#!/bin/sh\n\n");
+               &print_tempfile(STARTUP, ". /etc/rc.common\n\n");
+               &print_tempfile(STARTUP, "if [ \"\${$ucname:=-NO-}\" = \"-YES-\" ]; then\n");
+               &print_tempfile(STARTUP, "\tConsoleMessage \"Starting $ucfirst\"\n");
+               &print_tempfile(STARTUP, "\t$_[2]\n");
+               &print_tempfile(STARTUP, "fi\n");
+               &close_tempfile(STARTUP);
+               &set_ownership_permissions(undef, undef, 0750, $scriptfile);
+               }
+
+       # Update hostconfig file
+       $hc{$ucname} = '-YES-';
+       &write_env_file($config{'hostconfig'}, \%hc);
+       &unlock_file($config{'hostconfig'});
+       }
 }
 
 # disable_at_boot(action)
@@ -739,6 +800,18 @@ elsif ($init_mode eq "rc") {
        &disable_rc_script($_[0]);
        &unlock_rc_files();
        }
+elsif ($init_mode eq "osx") {
+       # Disable in hostconfig
+       local $ucname = uc($_[0]);
+       local %hc;
+       &lock_file($config{'hostconfig'});
+       &read_env_file($config{'hostconfig'}, \%hc);
+       if ($hc{$ucname} eq '-YES-' || $hc{$ucname} eq '-AUTOMATIC-') {
+               $hc{$ucname} = '-NO-';
+               &write_env_file($config{'hostconfig'}, \%hc);
+               }
+       &unlock_file($config{'hostconfig'});
+       }
 }
 
 # start_action(name)