Install pkg on fresh FreeBSD via shell script

Hi

I'm trying to install pkg via a shell script on a fresh install FreeBSD 10. I'm new to shell scripting and I tried to search the forum and elsewhere but no luck. My script is a simple one just to prepare the server with some basic set up. I want to use pkg to install but it needs to be install separately.

Code:
# pkg
The package management tool is not yet installed on your system.
Do you want to fetch and install it now? [y/N]:

I need to get this "y" pressed so I tried this.

Code:
if [ -f /usr/local/sbin/pkg ]; then
	/usr/local/sbin/pkg update
else
	pkg < /usr/bin/yes
fi

But doesn't work. How do I get that question answered with a "y"?

pkg() don't seem to give the answer.

Any help will be appreciated.

Cheers
 
olejak said:
How do I get that question answered with a "y"?
Use the -y option. You can also fetch the package for it, extract it and use the included pkg-static to register itself.
 
This is what I use in my NanoBSD build script. It will work even for the initial bootstrapping of pkg.
Code:
env ASSUME_ALWAYS_YES=YES pkg -c ${NANO_WORLDDIR} install ports-mgmt/pkg
env ASSUME_ALWAYS_YES=YES pkg -c ${NANO_WORLDDIR} install shells/bash
... # more packages follow ...
 
Back
Top