freebsd-ports/sysutils/firstboot-pkgs/files/firstboot_pkgs.in
Colin Percival 7b5782e2bf pkg uses "is stdin a terminal?" to decide if it's running interactively
and thereby whether it should display a progress bar during downloads.
While rc.d scripts have a terminal attached, for the common case of
unattended installation of servers, this script is not being used
interactively; so redirect stdin from /dev/null to silence the progress
bars and reduce console spew.

The -q option could be used to accomplish this, but that would also
eliminate other more useful information, such as the names and versions
of packages being installed.
2013-12-16 02:36:23 +00:00

54 lines
1.2 KiB
Bash

#!/bin/sh
# $FreeBSD$
# KEYWORD: firstboot
# PROVIDE: firstboot_pkgs
# REQUIRE: NETWORKING
# BEFORE: LOGIN
# Add the following lines to /etc/rc.conf.local or /etc/rc.conf (in the disk
# image, since this only runs on the first boot) to enable this:
#
# firstboot_pkgs_enable="YES"
#
# and place a list of packages in firstboot_pkgs_list, e.g.,
#
# firstboot_pkgs_list="apache22 php5 mysql56-server"
. /etc/rc.subr
: ${firstboot_pkgs_enable:="NO"}
name="firstboot_pkgs"
rcvar=firstboot_pkgs_enable
start_cmd="firstboot_pkgs_run"
stop_cmd=":"
firstboot_pkgs_run()
{
# Count rc.d scripts
nscriptso=`ls /usr/local/etc/rc.d | wc -l`
# Bootstrap if necessary
if ! pkg -N 2>/dev/null; then
env ASSUME_ALWAYS_YES=YES pkg bootstrap
fi
# Install requested packages, if any
if ! [ -z "$firstboot_pkgs_list" ]; then
env ASSUME_ALWAYS_YES=YES pkg install $firstboot_pkgs_list </dev/null
fi
# Count rc.d scripts again
nscriptsn=`ls /usr/local/etc/rc.d | wc -l`
# If we have more scripts, request a reboot
if [ $nscriptsn -ne $nscriptso ]; then
echo "Requesting reboot after installing packages with rc.d scripts."
touch ${firstboot_sentinel}-reboot
fi
}
load_rc_config $name
run_rc_command "$1"