NAME
MDK::Common::System - system-related useful functions
SYNOPSIS
use MDK::Common::System qw(:all);
EXPORTS
- %compat_arch
-
architecture compatibility mapping (eg: k6 => i586, k7 => k6 ...)
- %printable_chars
-
7 bit ascii characters
- $sizeof_int
-
sizeof(int)
- $bitof_int
-
$sizeof_int * 8
- arch()
-
return the architecture (eg: i686, ppc, ia64, k7...)
- typeFromMagic(FILENAME, LIST)
-
find the first corresponding magic in FILENAME. eg of LIST:
[ 'empty', 0, "\0\0\0\0" ], [ 'grub', 0, "\xEBG", 0x17d, "stage1 \0" ], [ 'lilo', 0x2, "LILO" ], sub { my ($F) = @_; #- standard grub has no good magic (Mageia's grub is patched to have "GRUB" at offset 6) #- so scanning a range of possible places where grub can have its string my ($min, $max, $magic) = (0x176, 0x181, "GRUB \0"); my $tmp; sysseek($F, 0, 0) && sysread($F, $tmp, $max + length($magic)) or return; substr($tmp, 0, 2) eq "\xEBH" or return; index($tmp, $magic, $min) >= 0 && "grub"; },
where each entry is [ magic_name, offset, string, offset, string, ... ].
- list_passwd()
-
return the list of users as given by
getpwent
(see perlfunc) - is_real_user()
-
checks whether or not the user is a system user or a real user
- is_real_group()
-
checks whether or not the group is a system group or a real group
- list_home()
-
return the list of home (eg: /home/foo, /home/pixel, ...)
- list_skels()
-
return the directories where we can find dot files: homes, /root and /etc/skel
- list_users()
-
return the list of unprivilegied users (uses the is_real_user function to filter out system users from the full list)
- syscall_(NAME, PARA)
-
calls the syscall NAME
- psizeof(STRING)
-
useful to know the length of a
pack
format string.psizeof("I I I C C S") = 4 + 4 + 4 + 1 + 1 + 2 = 16
- availableMemory()
-
size of swap + memory
- availableRamMB()
-
size of RAM as reported by the BIOS (it is a round number that can be displayed or given as "mem=128M" to the kernel)
- gettimeofday()
-
returns the epoch in microseconds
- unix2dos(STRING)
-
takes care of CR/LF translation
- whereis_binary(STRING)
-
return the first absolute file in $PATH (similar to which(1) and whereis(1))
- getVarsFromSh(FILENAME)
-
returns a hash associating shell variables to their value. useful for config files such as /etc/sysconfig files
- setVarsInSh(FILENAME, HASH REF)
-
write file in shell format association a shell variable + value for each key/value
- setVarsInSh(FILENAME, HASH REF, LIST)
-
restrict the fields that will be printed to LIST
- setVarsInShMode(FILENAME, INT, HASH REF, LIST)
-
like setVarsInSh with INT being the chmod value for the config file
- addVarsInSh(FILENAME, HASH REF)
-
like setVarsInSh but keeping the entries in the file
- addVarsInSh(FILENAME, HASH REF, LIST)
-
like setVarsInSh but keeping the entries in the file
- addVarsInShMode(FILENAME, INT, HASH REF, LIST)
-
like addVarsInShMode but keeping the entries in the file
- setExportedVarsInCsh(FILENAME, HASH REF, LIST)
-
same as
setExportedVarsInSh
for csh format - template2file(FILENAME_IN, FILENAME_OUT, HASH)
-
read in a template file, replace keys @@@key@@@ with value, save it in out file
- template2userfile(PREFIX, FILENAME_IN, FILENAME_OUT, BOOL, HASH)
-
read in a template file, replace keys @@@key@@@ with value, save it in every homes. If BOOL is true, overwrite existing files. FILENAME_OUT must be a relative filename
- read_gnomekderc(FILENAME, STRING)
-
reads GNOME-like and KDE-like config files (aka windows-like). You must give a category. eg:
read_gnomekderc("/etc/skels/.kderc", 'KDE')
- update_gnomekderc(FILENAME, STRING, HASH)
-
modifies GNOME-like and KDE-like config files (aka windows-like). If the category doesn't exist, it creates it. eg:
update_gnomekderc("/etc/skels/.kderc", 'KDE', kfmIconStyle => "Large")
- fuzzy_pidofs(REGEXP)
-
return the list of process ids matching the regexp
OTHER
- better_arch(ARCH1, ARCH2)
-
is ARCH1 compatible with ARCH2?
better_arch('i386', 'ia64') and better_arch('ia64', 'i386') are false
better_arch('k7', 'k6') is true and better_arch('k6', 'k7') is false
- compat_arch(STRING)
-
test the architecture compatibility. eg:
compat_arch('i386') is false on a ia64
compat_arch('k6') is true on a k6 and k7 but false on a i386 and i686