Created
August 25, 2014 08:56
-
-
Save kunst1080/83acaed352bdf31b71e0 to your computer and use it in GitHub Desktop.
Create FreeBSD Jail with qjail(8)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| USAGE(){ | |
| cat <<++EOS >&2 | |
| USAGE:`basename $0` jail_name ip_address flavor [ -y root_password default_user default_user_password ] | |
| ++EOS | |
| } | |
| # Const | |
| NIC=em1 | |
| if [ "_$3" = "_" ] ; then | |
| USAGE | |
| exit 9 | |
| fi | |
| jail_name=$1 | |
| ip_address=$2 | |
| flavor=$3 | |
| if [ "_$4" = "_-y" ] ; then | |
| if [ "_$7" = "_" ] ; then | |
| USAGE | |
| exit 9 | |
| fi | |
| is_silent=$4 | |
| root_password=$5 | |
| default_user=$6 | |
| default_user_password=$7 | |
| else | |
| is_silent="" | |
| echo -n "Input root password: " | |
| read root_password | |
| echo -n "Input default username: " | |
| read default_user | |
| echo -n "Input default user password: " | |
| read default_user_password | |
| fi | |
| cat <<++EOS | |
| I will create a Jail with the following. | |
| jail_name :${jail_name} | |
| ip_address :${ip_address} | |
| flavor :${flavor} | |
| root_password :${root_password} | |
| default_user :${default_user} | |
| default_user_password:${default_user_password} | |
| ++EOS | |
| if [ "${is_silent}" != "-y" ] ; then | |
| echo -n 'create? [y/n]: ' | |
| read YN | |
| if [ "$YN" != "y" -a "$YN" != "yes" ]; then | |
| exit 9 | |
| fi | |
| fi | |
| echo | |
| echo "########### SETUP START ###########" | |
| set -v | |
| # create Jail | |
| sudo qjail create -n $NIC -4 $ip_address -f $flavor $jail_name | |
| sudo qjail config -k $jail_name | |
| sudo qjail start $jail_name | |
| # user settings | |
| sudo jexec $jail_name sh -c "echo ${root_password} | pw usermod -n root -h 0" | |
| sudo jexec $jail_name sh -c "echo ${default_user_password} | pw useradd -n ${default_user} -G wheel -m -h 0" | |
| set +v | |
| echo "########### SETUP END ###########" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment