Index: etc/rc.d/pkg_bootstrap =================================================================== --- /dev/null +++ etc/rc.d/pkg_bootstrap @@ -0,0 +1,80 @@ +#!/bin/sh +# +# Copyright (c) 2018 Jonathan Anderson +# All rights reserved. +# +# This software was developed by BAE Systems, the University of Cambridge +# Computer Laboratory, and Memorial University under DARPA/AFRL contract +# FA8650-15-C-7558 ("CADETS"), as part of the DARPA Transparent Computing +# (TC) research program. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ +# + +# +# This script allows a system to bootstrap the package system and a set of +# initial packages on first boot. To enable pkg(8) bootstrapping, add the +# following to /etc/rc.conf: +# +# pkg_bootstrap_enable="YES" +# +# A list of packages to be installed at bootstrap time can be specified with: +# +# pkg_bootstrap_list="sudo tmux git kyua" +# +# The environment for the pkg(8) bootstrap commands can be influenced using the +# pkg_bootstrap_env variable. This can be helpful for overriding environment +# variables such as ABI or OSVERSION: +# +# pkg_bootstrap_env="OSVERSION=1200056" +# + +# PROVIDE: pkg-bootstrap +# REQUIRE: NETWORKING growfs +# BEFORE: local +# KEYWORD: firstboot + +. /etc/rc.subr + +name="pkg-bootstrap" +desc="Bootstrap pkg(8) and an (optional) set of packages" +start_cmd="pkg_bootstrap_start" +stop_cmd=":" +rcvar="pkg_bootstrap_enable" + +pkg_bootstrap_start() +{ + # Bootstrap pkg(8) + env ASSUME_ALWAYS_YES=yes ${pkg_bootstrap_env} pkg bootstrap || exit 1 + + # Install any requested packages + if [ -n "${pkg_bootstrap_list}" ] + then + env ${pkg_bootstrap_env} pkg install -y ${pkg_bootstrap_list} \ + || exit 1 + fi +} + +load_rc_config $name +run_rc_command "$1"