Skip to content
Snippets Groups Projects
installer.sh 2.89 KiB
Newer Older
Iblis Lin's avatar
Iblis Lin committed
#!/bin/sh

##############################################
#  variables
##############################################

# env
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin

# files and dirs
SSH_DIR='/etc/ssh'
RC_SCRIPT_FILE='/etc/rc.local'
RC_BACKUP_FILE='/etc/rc.local.bak'
RC_CONF='/etc/rc.conf'
LOADER_CONF='/boot/loader.conf'

# bsd cloudinit
Iblis Lin's avatar
Iblis Lin committed
BSDINIT_URL='https://github.com/pellaeon/bsd-cloudinit/archive/master.tar.gz'

# commands
VERIFY_PEER='--ca-cert=/usr/local/share/certs/ca-root-nss.crt'
FETCH="fetch ${VERIFY_PEER}"

Iblis Lin's avatar
Iblis Lin committed
INSTALL_PKGS='
	lang/python27
Pellaeon Lin's avatar
Pellaeon Lin committed
	security/sudo
	security/ca_root_nss

##############################################
#  utils
##############################################
	
echo_debug() {
	echo '[debug] '$1
}
echo_bsdinit_stamp() {
Iblis Lin's avatar
Iblis Lin committed
	echo '# Generated by bsd-cloudinit-installer '`date +'%Y/%m/%d %T'`

##############################################
#  main block
##############################################

# Get freebsd version
if uname -K > /dev/null 2>&1
then
	BSD_VERSION=`uname -K`
else
	_BSD_VERSION=`uname -r | cut -d'-' -f 1`
	BSD_VERSION=$(printf "%d%02d%03d" `echo ${_BSD_VERSION} | cut -d'.' -f 1` `echo ${_BSD_VERSION} | cut -d'.' -f 2` 0)
fi

if [ $BSDINIT_DEBUG ]
then
	echo_debug "BSD_VERSION = $BSD_VERSION"
fi

# Raise unsupport error
[ "$BSD_VERSION" -lt 903000 ] && {
	echo 'Oops! Your freebsd version is too old and not supported!'
	exit 1
# Install our prerequisites
Iblis Lin's avatar
Iblis Lin committed
export ASSUME_ALWAYS_YES=yes
Iblis Lin's avatar
Iblis Lin committed

[ ! `which python2.7` ] && {
	echo 'python2.7 Not Found !'
Iblis Lin's avatar
Iblis Lin committed
	exit 1
PYTHON=`which python2.7`
Iblis Lin's avatar
Iblis Lin committed

$FETCH -o - $BSDINIT_URL | tar -xzvf - -C '/root'
Iblis Lin's avatar
Iblis Lin committed

pip install -r '/root/bsd-cloudinit-master/requirements.txt'
Iblis Lin's avatar
Iblis Lin committed
rm -vf $SSH_DIR/ssh_host*

touch $RC_SCRIPT_FILE
cp -pf $RC_SCRIPT_FILE $RC_BACKUP_FILE
echo_bsdinit_stamp >> $RC_SCRIPT_FILE
Pellaeon Lin's avatar
Pellaeon Lin committed
echo "$PYTHON /root/bsd-cloudinit-master/run.py --log-file /tmp/cloudinit.log" >> $RC_SCRIPT_FILE
echo "cp -pf $RC_BACKUP_FILE $RC_SCRIPT_FILE " >> $RC_SCRIPT_FILE
Pellaeon Lin's avatar
Pellaeon Lin committed
# Output to OpenStack console log
echo_bsdinit_stamp >> $LOADER_CONF
echo 'console="comconsole,vidconsole"' >> $LOADER_CONF
Pellaeon Lin's avatar
Pellaeon Lin committed
# Bootloader menu delay
echo 'autoboot_delay="1"' >> $LOADER_CONF
echo_bsdinit_stamp >> $RC_CONF
# Get the active NIC and set it to use dhcp
for i in `ifconfig -u -l`
do
	case $i in
		'lo0')
			;;
		'plip0')
			;;
		'pflog0')
			;;
		*)
			echo 'ifconfig_'${i}'="DHCP"' >> $RC_CONF
			break;
			;;
	esac
done
# Enabel sshd in rc.conf
Iblis Lin's avatar
Iblis Lin committed
if ! /usr/bin/egrep '^sshd_enable' $RC_CONF > /dev/null
then
	echo 'sshd_enable="YES"' >> $RC_CONF
fi
Pellaeon Lin's avatar
Pellaeon Lin committed
# Allow %wheel to become root with no password
Pellaeon Lin's avatar
Pellaeon Lin committed
sed -i '' 's/# %wheel ALL=(ALL) NOPASSWD: ALL/%wheel ALL=(ALL) NOPASSWD: ALL/' /usr/local/etc/sudoers
Pellaeon Lin's avatar
Pellaeon Lin committed

# Readme - clean history
Iblis Lin's avatar
Iblis Lin committed
echo '==================================================='
echo 'If you want to clean the tcsh history, please issue'
echo '    # set history = 0'
echo '==================================================='