![]() ![]() ![]() ![]() |
|
This module provides some utilities for common calls in the HiPi modules code.
You may find them useful in your own code.
use HiPi::Utils qw( get_groups create_system_group create_user_group group_add_user group_remove_user cat_file echo_file home_directory is_windows is_unix is_raspberry is_mac is_raspberry_2 is_raspberry_3 uses_device_tree system_type ); # that is equivalent to use HiPi::Utils qw( :all );
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
returns true if this is a RPi 2
returns true if this is a RPi 3
In the same spirit as is_raspberry, is_windows etc., this gives me a correct home directory on any platform.
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 }, ....... };
A thin wrapper around groupadd -f -r -g $gid $groupname if $gid is undefined calls groupadd -f -r $groupname
A thin wrapper around groupadd -f -g $gid $groupname if $gid is undefined calls groupadd -f $groupname
A thin wrapper around gpasswd -a $username $groupname
A thin wrapper around gpasswd -d $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.
A thin wrapper around sudo /bin/cat $filename The call is made with PATH restricted to /bin:/usr/bin:/usr/local/bin
A thin wrapper around when $appendflag is false ( default ) sudo /bin/echo $message > $filename when $appendflag is true sudo /bin/echo $message >> $filename The call is made with PATH restricted to /bin:/usr/bin:/usr/local/bin
returns true if this system uses the device tree
returns 'wheezy' or 'current depending on your version of Raspbian