2018-09-16 12:48:35 -05:00
|
|
|
#! /bin/bash
|
|
|
|
#
|
|
|
|
# tmp.bash
|
|
|
|
# Copyright (C) 2018 salt <salt@lap-th-e560-0>
|
|
|
|
#
|
|
|
|
# Distributed under terms of the MIT license.
|
|
|
|
#
|
|
|
|
|
2018-10-04 16:20:38 -05:00
|
|
|
# Define variables
|
2018-09-16 12:48:35 -05:00
|
|
|
name="$(basename "$0" .sh)"
|
|
|
|
tmpdir="$(mktemp -d)"
|
2018-10-04 16:20:38 -05:00
|
|
|
# Verify them
|
|
|
|
[ -z ${tmpdir+x} ] && exit 2
|
|
|
|
# Define functions
|
2018-09-16 12:48:35 -05:00
|
|
|
function log() {
|
|
|
|
[ -z ${1+x} ] && return 1
|
2018-11-22 02:43:48 -06:00
|
|
|
# shellcheck disable=1117
|
|
|
|
printf "%b: %s\n" \
|
|
|
|
"$name" \
|
|
|
|
"$1"
|
2018-09-16 12:48:35 -05:00
|
|
|
}
|
2018-10-04 16:20:38 -05:00
|
|
|
function cleanup() {
|
|
|
|
rm -rf "${tmpdir}"
|
|
|
|
}
|
|
|
|
trap "cleanup" EXIT
|
|
|
|
# Do the do
|
2018-09-16 12:48:35 -05:00
|
|
|
log "This folder will be removed when this shell exits"
|
|
|
|
(
|
2018-11-22 02:43:48 -06:00
|
|
|
cd "${tmpdir}" || exit 50
|
|
|
|
exec "$SHELL"
|
2018-09-16 12:48:35 -05:00
|
|
|
)
|
2018-10-04 16:20:38 -05:00
|
|
|
cleanup
|
2018-09-16 12:48:35 -05:00
|
|
|
|