NAME

Setup - Global Customize functions


SYNOPSIS

        use vars qw(@ISA);
        use Setup;
        @ISA = qw(Setup);


DESCRIPTION

This module implements standard customize functions, both functions that should be used in modules and internal customize functions.

First description of the arguments that are being used in the functions.

        FILE, SRCFILE, DSTFILE  are filenames.
        DATA            is the data that is going to be inserted.
        PERM            is if the file should have any specific
                        permissions and its entered in an octal number.
        COMMENTSIGN is the commentsign to use when modifying a file.
                        '#' is default.
        NOBACKUP        set it to 1 if you don't want the function to
                        take a backup for later uninstall

Listing of customize public functions

add_to_file FILE, DATA, PERM, COMMENTSIGN, DONT_TRUST_CHKSUM
Set DONT_TRUST_CHKSUM to 1 if you want it to not only check the checksum if the DATA is correct or not.
        add_to_file('/etc/testfil','Testar',0755,'',1);
        $DATA = "set noexec_user_stack = 1\n";
        $DATA .= "set noexec_user_stack_log = 1\n";
        add_to_file('/etc/system',$DATA,'*');

The second exampel will give you this in your /etc/system

        * BEGIN: setup_etc_system Checksum: 5139
        set noexec_user_stack = 1
        set noexec_user_stack_log = 1
        * END: setup_etc_system Checksum: 5139

It returns 0 if an error accured, 1 if the file was changed and 2 if it didn't need to do anything.

prepend_to_file FILE, DATA, PERM, COMMENTSIGN, DONT_TRUST_CHKSUM
prepend_to_file is does exactly the same as append_to_file except that it always put itself in the top of the file instead of in the bottom.

verify_file FILE, DATA, PERM, COMMENTSIGN, DONT_TRUST_CHKSUM
Checks if an add_to_file needs to be done or not.
        verify_file('/etc/system',$DATA,'','*');

remove_from_file FILE, COMMENTSIGN, REMOVE_IF_EMPTY
Set REMOVE_IF_EMPTY to one if you wish to remove the file its nothing left of it after remove_from_file is finished.
        remove_from_file('/etc/testfil','',1);
        remove_from_file('/etc/system','*');

Returns 0 if an error accured, 1 if the file was changed and 2 if it didn't need to do anything

create_file FILE, DATA, perm
Creates a file and inserts DATA into it.
        create_file($ypservers, $YPDATA, 0600);

create_tmp_file FILE, DATA, perm
Does exactly the same thing as create_file. When I first created create_tmp_file I was thinking that it should return a temporary filename but that was never implemented.

verify_create_file FILE, DATA, perm
Checks if create_file needs to be run or not
        verify_create_file($ypservers, $YPDATA, 0600);

symlink_file SRCFILE, DSTFILE, NOBACKUP
It first runs rm_file on DSTFILE and then symlink(SRCFILE, DSTFILE);.
        symlink_file('/usr/src/tfil','/tfil');

verify_symlink_file SRCFILE, DSTFILE
Checks if symlink_file needs to be run or not
        verify_symlink_file('/opt/sendmail/8.10/sendmail','/usr/lib/sendmail');

restore_symlink_file FILE
Just runs rmrestore_file FILE
        restore_symlink_file('/usr/lib/sendmail');

copy_file SRCFILE, DSTFILE, PERM, USER, GROUP, NOBACKUP
First it gets the SRCFILE by running get_datafile(SRCFILE) If DSTFILE is a directory basename(SRCFILE) is added to the path. Then it checks if DSTFILE exists, size and its mtime. It compares it with the SRCFILE and if its differs it will copy SRCFILE to DSTFILE. The DSTFILE will be chown:ed if USER and GROUP is set. If only a user is specified that users gid will be used. It is not allowed to specify a group and not a user.
        copy_file('rwhod','/etc/init.d/rwhod',0755,'root','sys');
        copy_file('sendmail.cf','/etc/mail/sendmail.cf');

verify_copy_file SRCFILE, DSTFILE, PERM, USER, GROUP
Checks if copy_file needs to be run or not
        verify_copy_file('rwhod','/etc/init.d/',0755,'root','sys');
        verify_copy_file('sendmail.cf','/etc/mail/sendmail.cf');

copy_template_file SRCFILE, DSTFILE, PERM, NOBACKUP
First it gets the SRCFILE by running get_datafile(SRCFILE) Then it copies it to the customize tempdirectory and searches for @Custom::VAR_NAME@ and replaces it with the value of $Custom::VAR_NAME. If the size or content diffs with the DSTFILE it will replace it.
        copy_template_file('customize','/usr/sbin/customize',0755);

verify_template_file srcfile, dstfile, perm
Checks if copy_template_file needs to be run or not
        verify_template_file('customize','/usr/sbin/customize',0755);

restore_file FILE
Restore_file copies back a file that has been backedup by other customize functions.
        restore_file('/etc/mail/sendmail.cf');

rmrestore_file FILE
It first removes FILE and then runs restore_file FILE.

rm_file FILE, NOBACKUP
Takes a backup of the file (unless NOBACKUP is set) and then unlinks it.
        rm_file('/etc/printers.conf');

verify_rm_file FILE
Check if the file is removed or not.
        verify_rm_file('/etc/printers.conf');

ch_file FILE, REGEX, NOBACKUP
Takes a backup of the file (unless NOBACKUP is set) and then it reads the file, runs the regular expression on it and saves it.
        ch_file('/etc/init.d/sendmail','s/MODE=\"-bd\"/MODE=\"\"/');

verify_ch_file FILE, REGEX, TRUE_IF_FOUND
Checks if ch_file needs to be done. TRUE_IF_FOUND says if...
        verify_ch_file('/etc/init.d/sendmail','MODE=\"-bd\"');

verify_link FILE1, FILE2
Verifies that both the inodes points to the same file
        verify_link("/usr/sbin/identd","/usr/lib/isaexec");

get_datafile FILE
Search for the file in the following order and returns the first match.
        /custom/data/Local/<script name>/<OS>/filename
        /custom/data/Local/<script name>/filename
        /custom/data/<Category>/<script name>/<OS>/filename
        /custom/data/<Category>/<script name>/filename
        get_datafile("${VER}/Driver.sis");

read_datafile FILE
Gets the filename with get_datafile and reads it and return the data as an array.

read_file FILE
Reads FILE and returns its data as an array.
        read_file("${Setup::TMPDIR}/sunrayinst.$$");

add_to_cron DATA
Adds DATA to roots crontab
        add_to_cron($CRONTAB);

verify_cron DATA
Verifies that the DATA is in the crontab.
        verify_cron($CRONTAB);

remove_from_cron
Removes everything this script has added to the crontab. No argument is needed because it only removes what the script that calls it has entered in it.
        remove_from_cron();

is_workhour
UNIMPLEMENTED

Returns true if its workhour. It can be usefull to know in scripts if we should start a process that can take several hours to complete or not. (Like patching Solaris machines).


COPYRIGHT

Copyright (c) 2000-2001 Ericsson Erisoft AB. All rights reserved. Copyright (c) 2001-2003 Joacim Häggmark. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.


AUTHOR

Joacim Häggmark <joacim@ludd.luth.se>