Skip to content
This repository was archived by the owner on Jan 16, 2024. It is now read-only.

Commit 04d85b4

Browse files
ospalaxvholer
authored andcommitted
B #112: Move script location outside of /tmp
Introduce new OpenNebula directory /var/lib/one-context where a new tmp directory is located. This new one will not be mounted with noexec option on any system by default. Add cleanup handler on the script exit and ensure the correct return code for the init scripts (if one or more fail then return non-zero). Update onesysprep and set its version by generate.sh script. Signed-off-by: Petr Ospalý <pospaly@opennebula.io>
1 parent fccb01f commit 04d85b4

5 files changed

Lines changed: 65 additions & 32 deletions

File tree

generate.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,10 @@ else
174174
cat ${POSTUP} >"${_POSTUP}"
175175
fi
176176

177+
# set the package version of onesysprep
178+
sed -i "s/\<_PACKAGE_VERSION_\>/${VERSION}-${RELEASE_FULL}/" \
179+
"${BUILD_DIR}/usr/sbin/onesysprep"
180+
177181
fpm --name "${NAME}" --version "${VERSION}" --iteration "${RELEASE_FULL}" \
178182
--architecture all --license "${LICENSE}" \
179183
--vendor "${VENDOR}" --maintainer "${MAINTAINER}" \

src/etc/one-context.d/net-97-start-script

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env bash
22

33
# -------------------------------------------------------------------------- #
4-
# Copyright 2002-2020, OpenNebula Project, OpenNebula Systems #
4+
# Copyright 2002-2021, OpenNebula Project, OpenNebula Systems #
55
# #
66
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
77
# not use this file except in compliance with the License. You may obtain #
@@ -16,25 +16,33 @@
1616
# limitations under the License. #
1717
#--------------------------------------------------------------------------- #
1818

19+
set -e
20+
1921
MOUNT_DIR=${MOUNT_DIR:-/mnt}
20-
TMP_DIR=$(mktemp -d "/tmp/one-context.XXXXXX")
21-
TMP_FILE="${TMP_DIR}/one-start-script"
22+
TMP_DIR=$(mktemp -d "${TMP_DIR:-/var/lib/one-context/tmp}/one-context.XXXXXX")
2223
START_SCRIPT_AVAILABLE=no
2324

24-
chmod 700 "${TMP_DIR}"
25+
TMP_FILE="${TMP_DIR}/one-start-script"
26+
27+
cleanup()
28+
{
29+
rm -rf "${TMP_DIR}"
30+
}
2531

26-
if [ -n "$START_SCRIPT_BASE64" ]; then
27-
echo "${START_SCRIPT_BASE64}" | base64 -d > $TMP_FILE
32+
trap cleanup EXIT
33+
34+
chmod 0700 "${TMP_DIR}"
35+
36+
if [ -n "${START_SCRIPT_BASE64}" ]; then
37+
echo "${START_SCRIPT_BASE64}" | base64 -d > "${TMP_FILE}"
2838
START_SCRIPT_AVAILABLE=yes
29-
elif [ -n "$START_SCRIPT" ]; then
30-
echo "${START_SCRIPT}" > $TMP_FILE
39+
elif [ -n "${START_SCRIPT}" ]; then
40+
echo "${START_SCRIPT}" > "${TMP_FILE}"
3141
START_SCRIPT_AVAILABLE=yes
3242
fi
3343

34-
if [ "$START_SCRIPT_AVAILABLE" = "yes" ]; then
35-
cd $MOUNT_DIR
36-
chmod +x $TMP_FILE
37-
$TMP_FILE
44+
if [ "${START_SCRIPT_AVAILABLE}" = "yes" ]; then
45+
cd "${MOUNT_DIR}"
46+
chmod +x "${TMP_FILE}"
47+
"${TMP_FILE}"
3848
fi
39-
40-
rm -rf "${TMP_DIR}"
Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env bash
22

33
# -------------------------------------------------------------------------- #
4-
# Copyright 2002-2020, OpenNebula Project, OpenNebula Systems #
4+
# Copyright 2002-2021, OpenNebula Project, OpenNebula Systems #
55
# #
66
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
77
# not use this file except in compliance with the License. You may obtain #
@@ -16,23 +16,33 @@
1616
# limitations under the License. #
1717
#--------------------------------------------------------------------------- #
1818

19-
MOUNT_DIR=${MOUNT_DIR:-/mnt}
20-
TMP_DIR=$(mktemp -d "/tmp/one-context.XXXXXX")
19+
set -e
2120

22-
chmod 700 "${TMP_DIR}"
21+
MOUNT_DIR="${MOUNT_DIR:-/mnt}"
22+
TMP_DIR=$(mktemp -d "${TMP_DIR:-/var/lib/one-context/tmp}/one-context.XXXXXX")
2323

24-
if [ -z "$INIT_SCRIPTS" ]; then
25-
if [ -f "$MOUNT_DIR/init.sh" ]; then
24+
cleanup()
25+
{
26+
rm -rf "${TMP_DIR}"
27+
}
28+
29+
trap cleanup EXIT
30+
31+
chmod 0700 "${TMP_DIR}"
32+
33+
if [ -z "${INIT_SCRIPTS}" ]; then
34+
if [ -f "${MOUNT_DIR}/init.sh" ]; then
2635
INIT_SCRIPTS=init.sh
2736
fi
2837
fi
2938

30-
cd $MOUNT_DIR
39+
cd "${MOUNT_DIR}"
3140

41+
_result=0
3242
for f in $INIT_SCRIPTS; do
33-
cp "$f" "${TMP_DIR}/"
34-
chmod +x $TMP_DIR/$f
35-
$TMP_DIR/$f
43+
cp "${f}" "${TMP_DIR}/"
44+
chmod +x "${TMP_DIR}/${f}"
45+
"${TMP_DIR}/${f}" || _result=$?
3646
done
3747

38-
rm -rf "${TMP_DIR}"
48+
exit $_result

src/usr/sbin/one-contextd

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env bash
22

33
# -------------------------------------------------------------------------- #
4-
# Copyright 2002-2020, OpenNebula Project, OpenNebula Systems #
4+
# Copyright 2002-2021, OpenNebula Project, OpenNebula Systems #
55
# #
66
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
77
# not use this file except in compliance with the License. You may obtain #
@@ -21,13 +21,15 @@ set -e
2121
TYPE="${1:-all}" # local, network, all
2222
COMMAND="${2}" # reconfigure?
2323

24-
SCRIPTS_DIR=${SCRIPTS_DIR:-/etc/one-context.d}
25-
RUNTIME_DIR=${RUNTIME_DIR:-/var/run/one-context}
24+
SCRIPTS_DIR="${SCRIPTS_DIR:-/etc/one-context.d}"
25+
RUNTIME_DIR="${RUNTIME_DIR:-/var/run/one-context}"
26+
TMP_DIR="${TMP_DIR:-/var/lib/one-context/tmp}"
2627
LOCK_FILE="${RUNTIME_DIR}/one-context.lock"
2728
CONTEXT_BASE="${RUNTIME_DIR}/context.sh"
2829
SYSLOG_TAG="$(basename $0)"
2930

3031
[ -d "${RUNTIME_DIR}" ] || mkdir -m 0700 -p "${RUNTIME_DIR}"
32+
[ -d "${TMP_DIR}" ] || mkdir -m 0700 -p "${TMP_DIR}"
3133
CONTEXT_NEW=$(mktemp "${CONTEXT_BASE}.XXXXXX" 2>/dev/null)
3234
SYSLOG_FACILITY="${SYSLOG_FACILITY:-local3}"
3335

src/usr/sbin/onesysprep

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/sh
22

33
# ---------------------------------------------------------------------------- #
4-
# Copyright 2020, OpenNebula Project, OpenNebula Systems #
4+
# Copyright 2020-2021, OpenNebula Project, OpenNebula Systems #
55
# #
66
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
77
# not use this file except in compliance with the License. You may obtain #
@@ -33,7 +33,6 @@ set -e
3333

3434
CMD=$(basename "$0")
3535
CMDLINE="${0} ${*}"
36-
VERSION='5.13.80'
3736

3837
# here are declared all sysprep operations - keep the following format:
3938
# <operation>:<default>:<comment>
@@ -80,6 +79,7 @@ udev-persistent-net :1: Remove udev persistent net rules
8079
user-account :0: Remove the user accounts in the guest
8180
utmp :1: Remove the utmp file
8281
yum-uuid :1: Remove the yum UUID
82+
one-cleanup :1: Remove OpenNebula-owned working directories
8383
one-shell-history :1: Remove the .history file
8484
one-hostname :1: Remove hostname and fix hosts file
8585
one-resolvconf :1: Remove nameservers
@@ -1744,6 +1744,15 @@ op_yum_uuid()
17441744

17451745
# extra one operations
17461746

1747+
op_one_cleanup()
1748+
(
1749+
run_op() { echo "+ ${*}" ; "$@" ; }
1750+
1751+
run_op rm -vrf \
1752+
/var/lib/one-context/ \
1753+
;
1754+
)
1755+
17471756
op_one_shell_history()
17481757
(
17491758
run_op() { echo "+ ${*}" ; "$@" ; }
@@ -2046,8 +2055,8 @@ fi
20462055
cat <<EOF
20472056
___ _ __ ___
20482057
/ _ \ | '_ \ / _ \ OpenNebula System Preparation Tool
2049-
| (_) || | | || __/ (c) 2002-2020, OpenNebula Project, OpenNebula Systems
2050-
\___/ |_| |_| \___| Version ${VERSION}
2058+
| (_) || | | || __/ (c) 2002-2021, OpenNebula Project, OpenNebula Systems
2059+
\___/ |_| |_| \___| Version _PACKAGE_VERSION_
20512060
20522061
EOF
20532062

0 commit comments

Comments
 (0)