etch
#variables
SHELL="/bin/ksh"
#platform-specific
[ -z "$EDGEBSD_BOOTSTRAP" ] && EDGEBSD_BOOTSTRAP="pkgtools/libkver pkgtools/pkg_chk security/gnupg sysutils/fakeroot"
[ -z "$EDGEBSD_PKGSRC" ] && EDGEBSD_PKGSRC="pkgsrc_2015Q2"
[ -z "$EDGEBSD_REPOSITORY" ] && EDGEBSD_REPOSITORY="http://git.edgebsd.org/EdgeBSD"
EDGEBSD_PACKAGES=
EDGEBSD_SETS="base comp etc text"
#executables
CHROOT="/usr/sbin/chroot"
GIT="$PREFIX/bin/git"
SH="/bin/sh"
SU="/usr/bin/su"
#extras
HOMEDIR="/home/$USERNAME"
PKGSRCDIR="/usr/pkgsrc"
DISTFILES="$HOMEDIR/pkgsrc/distfiles"
PACKAGES="$HOMEDIR/pkgsrc/packages"
SIGNAS="root@edgebsd.org"
TIMEZONE="UTC"
WORKDIR="$HOMEDIR/pkgsrc/work"
#functions
#chroot
_chroot()
{
cmd="$SUDO $CHROOT -- $DESTDIR $SH -c"
while getopts "u:" name; do
case "$name" in
u)
cmd="$SUDO $CHROOT -- $DESTDIR $SU - $OPTARG -c"
;;
*)
return 1
;;
esac
done
shift $((OPTIND - 1))
$cmd "$@"
}
#install_kernel
_install_kernel()
{
#no need to install any kernel
:
}
#install_packages
_install_packages()
{
#populate /dev
_info "Creating the device nodes..."
(cd "$DESTDIR/dev" && $DEBUG $SUDO ./MAKEDEV all) || return 2
#create the default user early
_install_configure_user || return 2
#bootstrap the necessary tools
if [ ! -d "$DESTDIR$PKGSRCDIR" ]; then
_info "Cloning the repository..."
$DEBUG $SUDO $MKDIR -m 0755 -- "$DESTDIR$PKGSRCDIR" \
|| return 2
#XXX hard-coded the UID
$DEBUG $SUDO $CHOWN -- 1000 "$DESTDIR$PKGSRCDIR" \
|| return 2
$DEBUG $GIT clone --single-branch -b "$EDGEBSD_PKGSRC" \
"$EDGEBSD_REPOSITORY/edgebsd-pkgsrc.git" \
"$DESTDIR$PKGSRCDIR" || return 2
fi
if [ ! -d "$DESTDIR$WORKDIR" ]; then
_info "Bootstrapping pkgsrc..."
_chroot -u "$USERNAME" "cd '$PKGSRCDIR/bootstrap' &&
./bootstrap --unprivileged \
--prefix '/home/$USERNAME' \
--workdir '$WORKDIR'" || return 2
fi
_info "Fetching the vulnerabilities list..."
_chroot -u "$USERNAME" "$HOMEDIR/sbin/pkg_admin \
-K $HOMEDIR/var/db/pkg fetch-pkg-vulnerabilities" \
|| return 2
_info "Configuring the bootstrap..."
$DEBUG $SUDO $CP -- "$DESTDIR/$WORKDIR/mk.conf.example" \
"$DESTDIR$HOMEDIR/etc/mk.conf" || return 2
_file_append "$HOMEDIR/etc/mk.conf" << EOF
.ifdef BSD_PKG_MK
DISTDIR=$DISTFILES
MASTER_SORT=.de .org
MASTER_SORT_REGEX=berlin
PACKAGES=/tmp/pkgsrc/packages
WRKOBJDIR=$WORKDIR/wrk
.endif
EOF
[ $? -eq 0 ] || return 2
uid=$(_user_get_id "$USERNAME")
[ $? -eq 0 -a -n "$uid" ] || return 2
gid=$(_group_get_id "$USERNAME")
[ $? -eq 0 -a -n "$gid" ] || return 2
$DEBUG $SUDO $CHOWN "$uid:$gid" "$DESTDIR$HOMEDIR/etc/mk.conf" \
|| return 2
for b in $EDGEBSD_BOOTSTRAP; do
#FIXME - detect when each package is already installed
# - this does not seem to work
_info "Bootstrapping $b..."
_chroot -u "$USERNAME" "cd '$PKGSRCDIR/$b' &&
$HOMEDIR/bin/bmake install \
clean-depends clean" || return 2
done
#configure the build environment
_info "Configuring pkgsrc..."
$DEBUG $SUDO $MKDIR -m 0755 -- "$DESTDIR/etc" || return 2
_file_create "/etc/mk.conf" << EOF
.ifdef BSD_PKG_MK
DISTDIR=$DISTFILES
MASTER_SORT=.de .org
MASTER_SORT_REGEX=berlin
PACKAGES=$PACKAGES
PKGCHK_UPDATE_CONF=/tmp/pkgchk_update.conf
SIGN_PACKAGES=gpg
SU_CMD=$HOMEDIR/bin/fakeroot -- sh -c
WRKOBJDIR=$WORKDIR/wrk
ACCEPTABLE_LICENSES+= dbz-ttf-license
ACCEPTABLE_LICENSES+= lame-license
ACCEPTABLE_LICENSES+= vim-license
IRCD_HYBRID_NICLEN=15
IRCD_HYBRID_TOPICLEN=380
.endif
EOF
[ $? -eq 0 ] || return 2
_file_create "/etc/pkg_install.conf" << EOF
GPG=$HOMEDIR/bin/gpg
GPG_SIGN_AS=$SIGNAS
VERIFIED_INSTALLATION=always
EOF
[ $? -eq 0 ] || return 2
#import the GPG key
_import_gpg_key || return 2
#prepare the package installation directories
for i in "$PACKAGES" "$DESTDIR$PREFIX" "$DESTDIR/var/cache" \
"$DESTDIR/var/db/pkg" "$DESTDIR/var/db/pkg.refcount"; do
$DEBUG $SUDO $MKDIR -- "$i" || return 2
$DEBUG $SUDO $CHOWN -- "$uid:$gid" "$i" || return 2
done
}