## HiPi::Utils

This module provides some utilities for common calls in the HiPi modules code.

You may find them useful in your own code.

### Example Usage

    use HiPi::Utils qw(
        get_groups
        create_system_group
        create_user_group
        group_add_user
        group_remove_user
        home_directory
        is_windows
        is_unix
        is_raspberry
        is_mac
    );

### Functions

##### HiPi::Utils::is_raspberry();

        I like to be able to run my code on none-raspberry
        platforms during development.
        This gives me a quick and consistent way of
        checking if the code is running on a Raspberry Pi.

        For the same reason the following are implemented

        is_windows
        is_unix
        is_raspberry
        is_mac

##### HiPi::Utils::home_directory();

        In the same spirit as is_raspberry, is_windows etc.,
        this gives me a correct home directory on any platform.

##### HiPi::Utils::get_groups();

        returns a hash reference where the keys
        are all the groups on the system and the
        values are a reference to a hash containing
        the gid and an array reference of member names.

        i.e.

        return {
           groupname1 => { gid => $gid1, members => \@members1 },
           groupname2 => { gid => $gid2, members => \@members2 },
           .......
        };

##### HiPi::Utils::create_system_group($groupname, $gid);

        A thin wrapper around
        groupadd -f -r -g $gid $groupname
        if $gid is undefined calls
        groupadd -f -r $groupname

##### HiPi::Utils::create_user_group($groupname, $gid);

        A thin wrapper around
        groupadd -f -g $gid $groupname
        if $gid is undefined calls
        groupadd -f $groupname

##### HiPi::Utils::group_add_user($groupname, $username);

        A thin wrapper around
        gpasswd -a $username $groupname

##### HiPi::Utils::group_remove_user($groupname, $username);

        A thin wrapper around
        gpasswd -d $username $groupname

##### HiPi::Utils::drop_permissions_name($username,$groupname);

        Changes uid, effective uid, gid and effective gid of the
        running process to the $username and $groupname specified.
        This is very useful if you are using a module or methods
        ( such as HiPi::BCM2835 ) which require root level permissions
        during initialisation. Once you have initialised you can
        reduce to a less privileged user and group greatly enhancing
        the security of your process.

HiPi Modules Copyright © 2013 Mark Dootson