aboutsummaryrefslogtreecommitdiff
path: root/usr.sbin/bsdinstall
diff options
context:
space:
mode:
authorRebecca Cran <bcran@FreeBSD.org>2020-01-15 00:45:05 +0000
committerRebecca Cran <bcran@FreeBSD.org>2020-01-15 00:45:05 +0000
commita107ddbb83a7a93d3c4e40f5355e158d6976bf90 (patch)
tree63c29cb9b8cdcd133b18b747e6ec395d01ceafde /usr.sbin/bsdinstall
parent0297c1384ac831c774c901713912df4851242c05 (diff)
downloadsrc-a107ddbb83a7a93d3c4e40f5355e158d6976bf90.tar.gz
src-a107ddbb83a7a93d3c4e40f5355e158d6976bf90.zip
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/
Notes
Notes: svn path=/head/; revision=356740
Diffstat (limited to 'usr.sbin/bsdinstall')
-rwxr-xr-xusr.sbin/bsdinstall/bsdinstall8
-rw-r--r--usr.sbin/bsdinstall/bsdinstall.810
-rw-r--r--usr.sbin/bsdinstall/partedit/gpart_ops.c5
-rw-r--r--usr.sbin/bsdinstall/partedit/partedit.c16
-rw-r--r--usr.sbin/bsdinstall/partedit/partedit.h2
-rwxr-xr-xusr.sbin/bsdinstall/scripts/bootconfig10
-rwxr-xr-xusr.sbin/bsdinstall/scripts/mount2
-rwxr-xr-xusr.sbin/bsdinstall/scripts/script10
-rwxr-xr-xusr.sbin/bsdinstall/scripts/umount2
-rwxr-xr-xusr.sbin/bsdinstall/scripts/zfsboot7
10 files changed, 50 insertions, 22 deletions
diff --git a/usr.sbin/bsdinstall/bsdinstall b/usr.sbin/bsdinstall/bsdinstall
index a258e47cc2c7..1ca03f5c9593 100755
--- a/usr.sbin/bsdinstall/bsdinstall
+++ b/usr.sbin/bsdinstall/bsdinstall
@@ -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
diff --git a/usr.sbin/bsdinstall/bsdinstall.8 b/usr.sbin/bsdinstall/bsdinstall.8
index 90fae3c2c69c..f863ae66ad7f 100644
--- a/usr.sbin/bsdinstall/bsdinstall.8
+++ b/usr.sbin/bsdinstall/bsdinstall.8
@@ -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:
diff --git a/usr.sbin/bsdinstall/partedit/gpart_ops.c b/usr.sbin/bsdinstall/partedit/gpart_ops.c
index 87e45e348426..517972641134 100644
--- a/usr.sbin/bsdinstall/partedit/gpart_ops.c
+++ b/usr.sbin/bsdinstall/partedit/gpart_ops.c
@@ -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);
}
diff --git a/usr.sbin/bsdinstall/partedit/partedit.c b/usr.sbin/bsdinstall/partedit/partedit.c
index 80430c64ba1c..0fa03c99b369 100644
--- a/usr.sbin/bsdinstall/partedit/partedit.c
+++ b/usr.sbin/bsdinstall/partedit/partedit.c
@@ -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);
}
diff --git a/usr.sbin/bsdinstall/partedit/partedit.h b/usr.sbin/bsdinstall/partedit/partedit.h
index 1dccc653aea1..e989decc2359 100644
--- a/usr.sbin/bsdinstall/partedit/partedit.h
+++ b/usr.sbin/bsdinstall/partedit/partedit.h
@@ -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;
diff --git a/usr.sbin/bsdinstall/scripts/bootconfig b/usr.sbin/bsdinstall/scripts/bootconfig
index 417c8e7f27d4..944a2f10681a 100755
--- a/usr.sbin/bsdinstall/scripts/bootconfig
+++ b/usr.sbin/bsdinstall/scripts/bootconfig
@@ -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
diff --git a/usr.sbin/bsdinstall/scripts/mount b/usr.sbin/bsdinstall/scripts/mount
index acca94a8f52f..c7bc1aa5387d 100755
--- a/usr.sbin/bsdinstall/scripts/mount
+++ b/usr.sbin/bsdinstall/scripts/mount
@@ -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 ~ "^/.*") {
diff --git a/usr.sbin/bsdinstall/scripts/script b/usr.sbin/bsdinstall/scripts/script
index a633554b9433..4d0a91833644 100755
--- a/usr.sbin/bsdinstall/scripts/script
+++ b/usr.sbin/bsdinstall/scripts/script
@@ -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
diff --git a/usr.sbin/bsdinstall/scripts/umount b/usr.sbin/bsdinstall/scripts/umount
index 47d7f0bb9a16..ba4350f48ef6 100755
--- a/usr.sbin/bsdinstall/scripts/umount
+++ b/usr.sbin/bsdinstall/scripts/umount
@@ -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 ~ "^/.*") {
diff --git a/usr.sbin/bsdinstall/scripts/zfsboot b/usr.sbin/bsdinstall/scripts/zfsboot
index cc7972013264..eef482b806c5 100755
--- a/usr.sbin/bsdinstall/scripts/zfsboot
+++ b/usr.sbin/bsdinstall/scripts/zfsboot
@@ -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
;;