bsdinstall: Use TMPDIR if set

Submitted by:	Ryan Moeller <ryan@freqlabs.com>
Reviewed by:	bcran, Nick Wolff <darkfiberiru@gmail.com>
Differential Revision:	https://reviews.freebsd.org/D22979/
This commit is contained in:
Rebecca Cran 2020-01-15 00:45:05 +00:00
parent 0297c1384a
commit a107ddbb83
10 changed files with 50 additions and 22 deletions

View File

@ -40,13 +40,15 @@ BSDCFG_SHARE="/usr/share/bsdconfig"
############################################################ GLOBALS
: ${BSDINSTALL_TMPETC="/tmp/bsdinstall_etc"}; export BSDINSTALL_TMPETC
: ${BSDINSTALL_TMPBOOT="/tmp/bsdinstall_boot"}; export BSDINSTALL_TMPBOOT
: ${TMPDIR:="/tmp"}; export TMPDIR
: ${BSDINSTALL_TMPETC="${TMPDIR}/bsdinstall_etc"}; export BSDINSTALL_TMPETC
: ${BSDINSTALL_TMPBOOT="${TMPDIR}/bsdinstall_boot"}; export BSDINSTALL_TMPBOOT
: ${PATH_FSTAB="$BSDINSTALL_TMPETC/fstab"}; export PATH_FSTAB
: ${BSDINSTALL_DISTDIR="/usr/freebsd-dist"}; export BSDINSTALL_DISTDIR
: ${BSDINSTALL_CHROOT="/mnt"}; export BSDINSTALL_CHROOT
export debugFile="${debugFile-${BSDINSTALL_LOG-/tmp/bsdinstall_log}}"
export debugFile="${debugFile-${BSDINSTALL_LOG-${TMPDIR}/bsdinstall_log}}"
############################################################ MAIN

View File

@ -259,6 +259,10 @@ for most installation scenarios.
Others are set by various interactive user prompts, and can be usefully
overridden when making scripted or customized installers.
.Bl -tag -width ".Ev BSDINSTALL_DISTSITE"
.It Ev TMPDIR
The directory to use for temporary files.
Default:
.Dq Pa /tmp
.It Ev DISTRIBUTIONS
The set of distributions to install, e.g., "base.txz kernel.txz ports.txz".
Default: unset
@ -291,7 +295,7 @@ Default:
.It Ev BSDINSTALL_LOG
Path to a log file for the installation.
Default:
.Dq Pa /tmp/bsdinstall_log
.Dq Pa $TMPDIR/bsdinstall_log
.It Ev BSDINSTALL_TMPETC
Directory where files destined for the new system's
.Pa /etc
@ -300,7 +304,7 @@ will be stored until the
target is executed.
If this directory does not already exist, it will be created.
Default:
.Dq Pa /tmp/bsdinstall_etc
.Dq Pa $TMPDIR/bsdinstall_etc
.It Ev BSDINSTALL_TMPBOOT
Directory where files destined for the new system's
.Pa /boot
@ -309,7 +313,7 @@ will be stored until the
target is executed.
If this directory does not already exist, it will be created.
Default:
.Dq Pa /tmp/bsdinstall_boot
.Dq Pa $TMPDIR/bsdinstall_boot
.It Ev ZFSBOOT_POOL_NAME
Name for the pool containing the base system.
Default:

View File

@ -711,10 +711,11 @@ set_default_part_metadata(const char *name, const char *scheme,
if (strcmp(type, bootpart_type(scheme, &default_bootmount)) == 0) {
if (default_bootmount == NULL) {
int fd = open("/tmp/bsdinstall-esps", O_CREAT | O_WRONLY | O_APPEND,
0600);
int fd = openat(tmpdfd, "bsdinstall-esps",
O_CREAT | O_WRONLY | O_APPEND, 0600);
if (fd > 0) {
write(fd, md->name, strlen(md->name));
write(fd, "\n", 1);
close(fd);
}

View File

@ -32,17 +32,20 @@
#include <dialog.h>
#include <dlg_keys.h>
#include <err.h>
#include <errno.h>
#include <fstab.h>
#include <inttypes.h>
#include <libgeom.h>
#include <libutil.h>
#include <stdlib.h>
#include <sysexits.h>
#include "diskeditor.h"
#include "partedit.h"
struct pmetadata_head part_metadata;
int tmpdfd;
static int sade_mode = 0;
static int apply_changes(struct gmesh *mesh);
@ -66,6 +69,8 @@ sigint_handler(int sig)
end_dialog();
close(tmpdfd);
exit(1);
}
@ -73,7 +78,7 @@ int
main(int argc, const char **argv)
{
struct partition_metadata *md;
const char *progname, *prompt;
const char *progname, *prompt, *tmpdir;
struct partedit_item *items = NULL;
struct gmesh mesh;
int i, op, nitems, nscroll;
@ -85,6 +90,14 @@ main(int argc, const char **argv)
TAILQ_INIT(&part_metadata);
tmpdir = getenv("TMPDIR");
if (tmpdir == NULL)
tmpdir = "/tmp";
tmpdfd = open(tmpdir, O_RDWR | O_DIRECTORY);
if (tmpdfd < 0)
err(EX_OSERR, "%s", tmpdir);
unlinkat(tmpdfd, "bsdinstall-esps", 0);
init_fstab_metadata();
init_dialog(stdin, stdout);
@ -220,6 +233,7 @@ main(int argc, const char **argv)
geom_deletetree(&mesh);
free(items);
end_dialog();
close(tmpdfd);
return (error);
}

View File

@ -39,6 +39,8 @@ struct gprovider;
struct gmesh;
struct ggeom;
extern int tmpdfd;
TAILQ_HEAD(pmetadata_head, partition_metadata);
extern struct pmetadata_head part_metadata;

View File

@ -30,6 +30,8 @@
BSDCFG_SHARE="/usr/share/bsdconfig"
. $BSDCFG_SHARE/common.subr || exit 1
: ${TMPDIR:="/tmp"}
die() {
echo $*
exit 1
@ -50,8 +52,8 @@ if [ "$(uname -m)" = "amd64" ] || [ "$(uname -m)" = "i386" ]; then
fi
if [ "$(uname -m)" = "arm64" ] || [ "$X86_BOOTMETHOD" = "UEFI" ]; then
UFSBOOT_ESPS=$(cat /tmp/bsdinstall-esps 2>/dev/null)
ZFSBOOT_DISKS=$(cat /tmp/bsdinstall-zfsboot 2>/dev/null)
UFSBOOT_ESPS=$(cat $TMPDIR/bsdinstall-esps 2>/dev/null)
ZFSBOOT_DISKS=$(cat $TMPDIR/bsdinstall-zfsboot 2>/dev/null)
num_esps=0
if [ -n "$ZFSBOOT_DISKS" ]; then
@ -99,7 +101,7 @@ if [ "$(uname -m)" = "arm64" ] || [ "$X86_BOOTMETHOD" = "UEFI" ]; then
continue
fi
mntpt=$(mktemp -d /tmp/stand-test.XXXXXX)
mntpt=$(mktemp -d $TMPDIR/stand-test.XXXXXX)
if [ -e "/dev/${geom}p${index}" ]; then
dev=${geom}p${index}
elif [ -e "/dev/${geom}s${index}" ]; then
@ -129,7 +131,7 @@ if [ "$(uname -m)" = "arm64" ] || [ "$X86_BOOTMETHOD" = "UEFI" ]; then
die "Failed to format ESP $esp as FAT32"
fi
mntpt=$(mktemp -d /tmp/stand-test.XXXXXX)
mntpt=$(mktemp -d $TMPDIR/stand-test.XXXXXX)
f_dprintf "Mounting ESP /dev/${esp}"
mount -t msdosfs "/dev/${esp}" "${mntpt}"
if [ $? -ne 0 ]; then

View File

@ -26,7 +26,7 @@
#
# $FreeBSD$
TMP_FSTAB=/tmp/bsdinstall-tmp-fstab
TMP_FSTAB=${TMPDIR:-"/tmp"}/bsdinstall-tmp-fstab
cat $PATH_FSTAB | awk -v BSDINSTALL_CHROOT=$BSDINSTALL_CHROOT '{
if ($2 ~ "^/.*") {

View File

@ -49,6 +49,8 @@ f_include $BSDCFG_SHARE/variable.subr
############################################################ GLOBALS
: ${TMPDIR:="/tmp"}
#
# Strings that should be moved to an i18n file and loaded with f_include_lang()
#
@ -88,9 +90,9 @@ f_dprintf "Began Installation at %s" "$( date )"
rm -rf $BSDINSTALL_TMPETC
mkdir $BSDINSTALL_TMPETC
split -a 2 -p '^#!.*' "$SCRIPT" /tmp/bsdinstall-installscript-
split -a 2 -p '^#!.*' "$SCRIPT" $TMPDIR/bsdinstall-installscript-
. /tmp/bsdinstall-installscript-aa
. $TMPDIR/bsdinstall-installscript-aa
: ${DISTRIBUTIONS="kernel.txz base.txz"}; export DISTRIBUTIONS
export BSDINSTALL_DISTDIR
@ -135,8 +137,8 @@ if [ ! -f $BSDINSTALL_CHROOT/etc/resolv.conf -a -f /etc/resolv.conf ]; then
fi
# Run post-install script
if [ -f /tmp/bsdinstall-installscript-ab ]; then
cp /tmp/bsdinstall-installscript-ab $BSDINSTALL_CHROOT/tmp/installscript
if [ -f $TMPDIR/bsdinstall-installscript-ab ]; then
cp $TMPDIR/bsdinstall-installscript-ab $BSDINSTALL_CHROOT/tmp/installscript
chmod a+x $BSDINSTALL_CHROOT/tmp/installscript
mount -t devfs devfs "$BSDINSTALL_CHROOT/dev"
chroot $BSDINSTALL_CHROOT /tmp/installscript $@ 2>&1

View File

@ -26,7 +26,7 @@
#
# $FreeBSD$
TMP_FSTAB=/tmp/bsdinstall-tmp-fstab
TMP_FSTAB=${TMPDIR:-"/tmp"}/bsdinstall-tmp-fstab
cat $PATH_FSTAB | awk -v BSDINSTALL_CHROOT=$BSDINSTALL_CHROOT '{
if ($2 ~ "^/.*") {

View File

@ -1171,7 +1171,7 @@ zfs_create_boot()
f_dprintf "$funcname: For encrypted root disk..."
# Create parent directory for boot pool
f_eval_catch -d $funcname umount "$UMOUNT" /mnt
f_eval_catch -d $funcname umount "$UMOUNT" "$BSDINSTALL_CHROOT"
f_eval_catch $funcname mount "$MOUNT_TYPE" tmpfs none \
$BSDINSTALL_CHROOT || return $FAILURE
@ -1273,7 +1273,8 @@ zfs_create_boot()
# Clean up
f_eval_catch $funcname zfs "$ZFS_UNMOUNT" "$bootpool_name" ||
return $FAILURE
f_eval_catch -d $funcname umount "$UMOUNT" /mnt # tmpfs
# tmpfs
f_eval_catch -d $funcname umount "$UMOUNT" "$BSDINSTALL_CHROOT"
fi
#
@ -1657,7 +1658,7 @@ while :; do
"$vdev_type" $ZFSBOOT_DISKS || continue
# To be reused by bootconfig
echo "$ZFSBOOT_DISKS" > /tmp/bsdinstall-zfsboot
echo "$ZFSBOOT_DISKS" > ${TMPDIR:-"/tmp"}/bsdinstall-zfsboot
break # to success
;;