Commit 01a85736 authored by Mattia Rizzolo's avatar Mattia Rizzolo

move code under a subshell

Signed-off-by: Mattia Rizzolo's avatarMattia Rizzolo <mapreri@ubuntu.com>
parent fb685486
...@@ -10,15 +10,14 @@ if [[ "$(whoami)" != "ubuntu-it" ]]; then ...@@ -10,15 +10,14 @@ if [[ "$(whoami)" != "ubuntu-it" ]]; then
exit 1 exit 1
fi fi
run_script() (
# Try to deploy all the websites
for script in "${base}/scripts/"*; do
if [[ ! -x "${script}" ]]; then if [[ ! -x "${script}" ]]; then
continue echo "$(basename "$script"): not executable, skipping"
return
fi fi
# Create a temporary build directory # Create a temporary build directory
build_dir="$(mktemp -d deploy-XXXXXXXXX -p /tmp)" build_dir="$(mktemp -d deploy-XXXXXXXXX -p /tmp)"
trap 'rm -rfv "$build_dir"' RETURN
# Switch to the temporary build directory # Switch to the temporary build directory
cd "${build_dir}" cd "${build_dir}"
...@@ -29,8 +28,10 @@ for script in "${base}/scripts/"*; do ...@@ -29,8 +28,10 @@ for script in "${base}/scripts/"*; do
# Execute the deploy script # Execute the deploy script
# Capture the output and print it only if the script fails # Capture the output and print it only if the script fails
"$script" > "$output" "$script" > "$output"
if [[ $? -ne 0 ]]; then ret=$?
if [[ "$ret" -ne 0 ]]; then
echo "Deploy script $(basename "${script}") failed!" echo "Deploy script $(basename "${script}") failed!"
echo "Return code: $?"
echo "Script output" echo "Script output"
echo "=============" echo "============="
cat "${output}" cat "${output}"
...@@ -40,8 +41,10 @@ for script in "${base}/scripts/"*; do ...@@ -40,8 +41,10 @@ for script in "${base}/scripts/"*; do
# Restore the old home # Restore the old home
cd "${base}" cd "${base}"
export HOME="${base}" export HOME="${base}"
)
# Remove the temporary directory
rm -rf "${build_dir}"
done # Try to deploy all the websites
for script in "${base}/scripts/"*; do
run_script "$script"
done
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment