Skip to content

Instantly share code, notes, and snippets.

@paulc
Last active April 8, 2021 22:16
Show Gist options
  • Save paulc/239e55303082b90e8d1d to your computer and use it in GitHub Desktop.
Save paulc/239e55303082b90e8d1d to your computer and use it in GitHub Desktop.
jail_menu.rc
#!/usr/local/bin/rc
fn get_jail_id {
if ( !{ jls jid | grep $1 } ) {
/usr/sbin/jls name jid | !awk -v 'name=' ^ $1 '$1 == name { print $2; exit 1 }'
}
}
if ( ~ $#SSH_ORIGINAL_COMMAND 0 ) {
/usr/sbin/jls
echo -n 'JID: '
jid = `{ get_jail_id `{ head -1 /dev/tty }}
} else {
eval '* = (' ^ $SSH_ORIGINAL_COMMAND ^ ')'
jid = `{ get_jail_id $1 }
shift
}
if ( ~ $bqstatus 0 ) {
if ( ~ $#* 0 ) {
exec sudo /usr/sbin/jexec $jid login -f jail
} else {
exec sudo /usr/sbin/jexec -U jail $jid sh -c $^*
}
} else {
echo 'ERROR: Jail not found'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment