Sysadm-Install

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN


        Sysadm::Install comes with a script "one-liner" (installed in bin),
        which takes arbitrary perl code on STDIN and transforms it into a
        one-liner:

            $ one-liner
            Type perl code, terminate by CTRL-D
            print "hello\n";
            print "world\n";
            ^D
            perl -e "print \"hello\\n\"; print \"world\\n\"; "

    "$quoted_string = quote($string, [$metachars])"
        Similar to "qquote()", just puts a string in single quotes and
        escapes what needs to be escaped.

        Note that shells typically don't support escaped single quotes
        within single quotes, which means that

            $ echo 'foo\'bar'
            >

        is invalid and the shell waits until it finds a closing quote.
        Instead, there is an evil trick which gives the desired result:

            $ echo 'foo'\''bar'  # foo, single quote, \, 2 x single quote, bar
            foo'bar

        It uses the fact that shells interpret back-to-back strings as one.
        The construct above consists of three back-to-back strings:

            (1) 'foo'
            (2) '
            (3) 'bar'

        which all get concatenated to a single

            foo'bar

        If you call "quote()" with $metachars set to ":shell", it will
        perform that magic behind the scenes:

            print quote("foo'bar");
              # prints: 'foo'\''bar'

    "perm_cp($src, $dst, ...)"
        Read the $src file's user permissions and modify all $dst files to
        reflect the same permissions.

    "owner_cp($src, $dst, ...)"
        Read the $src file/directory's owner uid and group gid and apply it
        to $dst.

        For example: copy uid/gid of the containing directory to a file
        therein:

            use File::Basename;

            owner_cp( dirname($file), $file );

        Usually requires root privileges, just like chown does.

    "$perms = perm_get($filename)"
        Read the $filename's user permissions and owner/group. Returns an
        array ref to be used later when calling "perm_set($filename,
        $perms)".

    "perm_set($filename, $perms)"
        Set file permissions and owner of $filename according to $perms,
        which was previously acquired by calling "perm_get($filename)".

    "sysrun($cmd)"
        Run a shell command via "system()" and die() if it fails. Also works
        with a list of arguments, which are then interpreted as program name
        plus arguments, just like "system()" does it.

    "hammer($cmd, $arg, ...)"
        Run a command in the shell and simulate a user hammering the ENTER
        key to accept defaults on prompts.

    "say($text, ...)"
        Alias for "print ..., "\n"", just like Perl6 is going to provide it.

    "sudo_me()"
        Check if the current script is running as root. If yes, continue. If
        not, restart the current script with all command line arguments is
        restarted under sudo:

            sudo scriptname args ...

        Make sure to call this before any @ARGV-modifying functions like
        "getopts()" have kicked in.

    "bin_find($program)"
        Search all directories in $PATH (the ENV variable) for an executable
        named $program and return the full path of the first hit. Returns
        "undef" if the program can't be found.

    "fs_read_open($dir)"
        Opens a file handle to read the output of the following process:

            cd $dir; find ./ -xdev -print0 | cpio -o0 |

        This can be used to capture a file system structure.

    "fs_write_open($dir)"
        Opens a file handle to write to a

            | (cd $dir; cpio -i0)

        process to restore a file system structure. To be used in
        conjunction with *fs_read_open*.

    "pipe_copy($in, $out, [$bufsize])"
        Reads from $in and writes to $out, using sysread and syswrite. The
        buffer size used defaults to 4096, but can be set explicitly.

    "snip($data, $maxlen)"
        Format the data string in $data so that it's only (roughly) $maxlen
        characters long and only contains printable characters.



( run in 1.307 second using v1.01-cache-2.11-cpan-5511b514fd6 )