xref: /freebsd/release/scripts/pkg-stage.sh (revision 8ccc0d235c226d84112561d453c49904398d085c)
1#!/bin/sh
2#
3#
4
5set -e
6
7unset NO_ROOT
8
9export ASSUME_ALWAYS_YES="YES"
10export PKG_DBDIR="/tmp/pkg"
11export PERMISSIVE="YES"
12export REPO_AUTOUPDATE="NO"
13export ROOTDIR="$PWD/dvd"
14export PORTSDIR="${PORTSDIR:-/usr/ports}"
15
16_DVD_PACKAGES="
17devel/git@lite
18editors/emacs
19editors/vim
20misc/freebsd-doc-all
21net/mpd5
22net/rsync
23net/wifi-firmware-kmod@release
24ports-mgmt/pkg
25shells/bash
26shells/zsh
27security/sudo@default
28sysutils/screen
29sysutils/seatd
30sysutils/tmux
31www/firefox
32www/links
33x11/gnome
34x11/sddm
35x11/xorg
36x11-wm/sway
37"
38
39# If NOPORTS is set for the release, do not attempt to build pkg(8).
40if [ ! -f ${PORTSDIR}/Makefile ]; then
41	echo "*** ${PORTSDIR} is missing!    ***"
42	echo "*** Skipping pkg-stage.sh     ***"
43	echo "*** Unset NOPORTS to fix this ***"
44	exit 0
45fi
46
47usage()
48{
49	echo "usage: $0 [-N]"
50	exit 0
51}
52
53while getopts N opt; do
54	case "$opt" in
55	N)	NO_ROOT=1 ;;
56	*)	usage ;;
57	esac
58done
59
60PKG_ARGS="-d --rootdir ${ROOTDIR}"
61if [ $NO_ROOT ]; then
62	PKG_ARGS="$PKG_ARGS -o INSTALL_AS_USER=1"
63fi
64PKGCMD="/usr/sbin/pkg ${PKG_ARGS}"
65
66if [ ! -x /usr/local/sbin/pkg ]; then
67	/etc/rc.d/ldconfig restart
68	/usr/bin/make -C ${PORTSDIR}/ports-mgmt/pkg install clean
69fi
70
71export PKG_ABI=$(pkg --rootdir ${ROOTDIR} config ABI)
72export PKG_ALTABI=$(pkg --rootdir ${ROOTDIR} config ALTABI 2>/dev/null)
73export PKG_REPODIR="packages/${PKG_ABI}"
74
75/bin/mkdir -p ${ROOTDIR}/${PKG_REPODIR}
76if [ -n "${PKG_ALTABI}" ]; then
77	ln -s ${PKG_ABI} ${ROOTDIR}/packages/${PKG_ALTABI}
78fi
79
80# Ensure the ports listed in _DVD_PACKAGES exist to sanitize the
81# final list.
82for _P in ${_DVD_PACKAGES}; do
83	if [ -d "${PORTSDIR}/${_P%%@*}" ]; then
84		DVD_PACKAGES="${DVD_PACKAGES} ${_P}"
85	else
86		echo "*** Skipping nonexistent port: ${_P%%@*}"
87	fi
88done
89
90# Make sure the package list is not empty.
91if [ -z "${DVD_PACKAGES}" ]; then
92	echo "*** The package list is empty."
93	echo "*** Something is very wrong."
94	# Exit '0' so the rest of the build process continues
95	# so other issues (if any) can be addressed as well.
96	exit 0
97fi
98
99# Print pkg(8) information to make debugging easier.
100${PKGCMD} -vv
101${PKGCMD} update -f
102${PKGCMD} fetch -o ${PKG_REPODIR} -d ${DVD_PACKAGES}
103
104# Create the 'Latest/pkg.pkg' symlink so 'pkg bootstrap' works
105# using the on-disc packages.
106export LATEST_DIR="${ROOTDIR}/${PKG_REPODIR}/Latest"
107mkdir -p ${LATEST_DIR}
108ln -s ../All/$(${PKGCMD} rquery %n-%v pkg).pkg ${LATEST_DIR}/pkg.pkg
109
110${PKGCMD} repo ${PKG_REPODIR}
111
112if [ $NO_ROOT ]; then
113	mtree -c -p $ROOTDIR | mtree -C -k type,mode,link,size | \
114	    grep '^./packages[/ ]' >> $ROOTDIR/METALOG
115fi
116
117# Always exit '0', even if pkg(8) complains about conflicts.
118exit 0
119