Skip to content

Instantly share code, notes, and snippets.

@BBcan177
Created January 4, 2019 04:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BBcan177/b5d9506f9d1ca1ff2457f62bbaaaf878 to your computer and use it in GitHub Desktop.
Save BBcan177/b5d9506f9d1ca1ff2457f62bbaaaf878 to your computer and use it in GitHub Desktop.
pfSense python integration start-up code
// Mount lib and bin folders
$base_unbound = '/var/unbound';
$base_py = '/usr/local';
foreach (array('/bin', '/lib') as $dir) {
$validate = exec("/sbin/mount | {$pfb['grep']} '{$base_unbound}{$base_py}{$dir}' 2>&1");
if ($mode == 'enabled' && empty($validate)) {
if (!is_dir("{$base_unbound}{$base_py}{$dir}")) {
pfb_logger("\n Creating: {$base_unbound}{$base_py}{$dir}", 1);
exec("/bin/mkdir -p {$base_unbound}{$base_py}{$dir} 2>&1");
}
$pfbpython = TRUE;
pfb_logger("\n Mounting: /usr/local{$dir}", 1);
exec("/sbin/mount_nullfs -o ro /usr/local{$dir} {$base_unbound}{$base_py}{$dir} 2>&1", $output, $retval);
if ($retval != 0) {
pfb_logger("\n Failed to mount [ /usr/local{$dir} ] to [ {$base_unbound}{$base_py}{$dir} ]!", 1);
}
}
elseif ($mode == 'disabled' && !empty($validate)) {
$pfbpython = TRUE;
pfb_logger("\n Unmounting: /usr/local{$dir}", 1);
exec("/sbin/umount -t nullfs {$base_unbound}{$base_py}{$dir} 2>&1", $output, $retval;\
if ($retval != 0) {
pfb_logger("\n Failed to unmount [ {$base_unbound}{$base_py}{$dir} ]!", 1);
}
}
if ($mode == 'disabled') {
foreach (array( "/usr/local{$dir}", '/usr/local', '/usr') as $folder) {
if (is_dir("{$base_unbound}{$folder}")) {
pfb_logger("\n Removing: {$base_unbound}{$folder}", 1);
rmdir("{$base_unbound}{$folder}");
}
// Delete remaining subfolders on next loop
if ($dir == '/bin') {
break;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment