Skip to content

Commit c11a42e

Browse files
committed
Make temp paths configurable and removed on interrupt
1 parent 5a3e1ac commit c11a42e

File tree

1 file changed

+40
-25
lines changed

1 file changed

+40
-25
lines changed

deploy_dqmgui.sh

Lines changed: 40 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@ SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)
3737
# based on the version of the package (DMWM and DQMGUI).
3838
source $SCRIPT_DIR/config.sh
3939

40+
## Internal temporary paths
41+
TMP_BASE_PATH=/tmp
42+
ROOT_TMP_DIR="${TMP_BASE_PATH}/root"
43+
ROOT_TMP_BUILD_DIR="${TMP_BASE_PATH}/root_build"
44+
ROTOGLUP_TMP_DIR="${TMP_BASE_PATH}/rotoglup"
45+
CLASSLIB_TMP_DIR="${TMP_BASE_PATH}/classlib-3.1.3"
46+
DMWM_TMP_DIR="${TMP_BASE_PATH}/dmwm"
47+
NUMERIC_TMP_DIR="${TMP_BASE_PATH}/numeric"
48+
DQMGUI_TMP_DIR="${TMP_BASE_PATH}/dqmgui"
49+
4050
# Preliminary checks to do before installing the GUI
4151
preliminary_checks() {
4252
# Make sure we don't have superuser privileges
@@ -93,7 +103,7 @@ check_dependencies() {
93103
# Instead of doing a 'yum list' per package, it may be faster to just
94104
# ask all of them at once, and dump to file. Then grep the file.
95105
echo -n "Getting system packages..."
96-
tmp_yum_list=/tmp/yum_list.txt
106+
tmp_yum_list="${TMP_BASE_PATH}/yum_list.txt"
97107
eval "yum list ${required_packages[*]}" >$tmp_yum_list
98108
echo "Done"
99109

@@ -204,9 +214,8 @@ create_directories() {
204214
}
205215

206216
install_rotoglup() {
207-
ROTOGLUP_TMP_DIR=/tmp/rotoglup
208217
mkdir -p $ROTOGLUP_TMP_DIR
209-
tar -xzf "$SCRIPT_DIR/rotoglup/rotoglup.tar.gz" -C /tmp
218+
tar -xzf "$SCRIPT_DIR/rotoglup/rotoglup.tar.gz" -C "$TMP_BASE_PATH"
210219

211220
cd $ROTOGLUP_TMP_DIR
212221
#patch -p1 < $SCRIPT_DIR/rotoglup/patches/01.patch
@@ -232,9 +241,9 @@ compile_classlib() {
232241
# Classlib is needed both as a shared object and for its header files for DQMGUI compilation.
233242
install_classlib() {
234243
# Temporary directory to extract to
235-
CLASSLIB_TMP_DIR=/tmp/classlib-3.1.3
244+
236245
mkdir -p $CLASSLIB_TMP_DIR
237-
tar -xf "$SCRIPT_DIR/classlib/classlib-3.1.3.tar.bz2" -C /tmp
246+
tar -xf "$SCRIPT_DIR/classlib/classlib-3.1.3.tar.bz2" -C "${TMP_BASE_PATH}"
238247

239248
# Apply code patches I found on cmsdist. The 7th one is ours, and has some extra needed fixes.
240249
cd $CLASSLIB_TMP_DIR
@@ -268,15 +277,15 @@ install_classlib() {
268277

269278
install_boost_gil() {
270279
mkdir -p $INSTALLATION_DIR/$DMWM_GIT_TAG/sw/external/src/
271-
tar -xzf "$SCRIPT_DIR/boost_gil/boost_gil.tar.gz" -C /tmp
280+
tar -xzf "$SCRIPT_DIR/boost_gil/boost_gil.tar.gz" -C "${TMP_BASE_PATH}"
272281

273282
rm -rf "$INSTALLATION_DIR/$DMWM_GIT_TAG/sw/external/src/boost" # Cleanup dir if exists
274-
mv /tmp/boost_gil/include/boost "$INSTALLATION_DIR/$DMWM_GIT_TAG/sw/external/src/boost"
283+
mv "${TMP_BASE_PATH}/boost_gil/include/boost" "$INSTALLATION_DIR/$DMWM_GIT_TAG/sw/external/src/boost"
275284
}
276285

277286
install_gil_numeric() {
278-
NUMERIC_TMP_DIR=/tmp/numeric
279-
tar -xzf "$SCRIPT_DIR/numeric/numeric.tar.gz" -C /tmp
287+
288+
tar -xzf "$SCRIPT_DIR/numeric/numeric.tar.gz" -C "${TMP_BASE_PATH}"
280289
mkdir -p "$INSTALLATION_DIR/$DMWM_GIT_TAG/sw/external/src/boost/gil/extension/"
281290

282291
rm -rf "$INSTALLATION_DIR/$DMWM_GIT_TAG/sw/external/src/boost/gil/extension/numeric" # Cleanup dir if exists
@@ -285,9 +294,9 @@ install_gil_numeric() {
285294

286295
install_dmwm() {
287296
# Temporary directory to clone DMWM deployment scripts into
288-
DMWM_TMP_DIR=/tmp/dmwm
297+
289298
mkdir -p $DMWM_TMP_DIR
290-
tar -xzf "$SCRIPT_DIR/dmwm/dmwm.tar.gz" -C /tmp
299+
tar -xzf "$SCRIPT_DIR/dmwm/dmwm.tar.gz" -C "${TMP_BASE_PATH}"
291300
# Move dqmgui-related scripts from DMWM to the config folder
292301
rm -rf "$INSTALLATION_DIR/$DMWM_GIT_TAG/config/dqmgui" # Cleanup dir if exists
293302
mv "$DMWM_TMP_DIR/dqmgui" "$INSTALLATION_DIR/$DMWM_GIT_TAG/config/dqmgui"
@@ -351,7 +360,7 @@ _create_python_venv() {
351360
mkdir -p "$python_venv_dir"
352361

353362
# Extract the downloaded python packages
354-
tar -xzf "$SCRIPT_DIR/pypi/pypi.tar.gz" -C /tmp
363+
tar -xzf "$SCRIPT_DIR/pypi/pypi.tar.gz" -C "${TMP_BASE_PATH}"
355364
echo -n "INFO: Creating virtual environment at $python_venv_dir"
356365
$python_exe -m venv "$python_venv_dir"
357366

@@ -366,21 +375,21 @@ _create_python_venv() {
366375
export PYTHON_LIB_DIR_NAME
367376

368377
# Install pip
369-
unzip -u /tmp/pip/pip*whl -d /tmp/pip/pip
378+
unzip -u ${TMP_BASE_PATH}/pip/pip*whl -d "${TMP_BASE_PATH}/pip/pip"
370379
if [ -d "$python_venv_dir/$PYTHON_LIB_DIR_NAME/pip" ]; then
371380
rm -rf "$python_venv_dir/$PYTHON_LIB_DIR_NAME/pip"
372381
fi
373382

374383
# pipipipi
375-
mv /tmp/pip/pip/pip "$python_venv_dir/$PYTHON_LIB_DIR_NAME/pip"
376-
rm -rf /tmp/pip/pip
384+
mv "${TMP_BASE_PATH}/pip/pip/pip" "$python_venv_dir/$PYTHON_LIB_DIR_NAME/pip"
385+
rm -rf "${TMP_BASE_PATH}/pip/pip"
377386

378387
# Install wheels
379-
eval "${python_venv_exe} -m pip install --no-index --find-links /tmp/pip /tmp/pip/*"
388+
eval "${python_venv_exe} -m pip install --no-index --find-links ${TMP_BASE_PATH}/pip ${TMP_BASE_PATH}/pip/*"
380389
eval "${python_venv_exe} -m pip install $INSTALLATION_DIR/$DMWM_GIT_TAG/sw/cms/dqmgui/$DQMGUI_GIT_TAG/128"
381390

382391
cd "$INSTALLATION_DIR/$DMWM_GIT_TAG/sw/cms/dqmgui/$DQMGUI_GIT_TAG/128/"
383-
rm -rf /tmp/pip
392+
rm -rf "${TMP_BASE_PATH}/pip"
384393
echo "Done"
385394
}
386395

@@ -409,10 +418,10 @@ compile_dqmgui() {
409418
fi
410419

411420
# python3-config is not always in a predictable place
412-
python_config_cmd=$(which python3-config) || python_config_cmd=$(find /usr/bin -name "python3*-config" | head -1)
421+
python_config_cmd=$(which python${PYTHON_VERSION}-config) || python_config_cmd=$(find /usr/bin -name "python3*-config" | head -1)
413422

414423
if [ -z "$python_config_cmd" ]; then
415-
echo "ERROR: Could not find python3-config"
424+
echo "ERROR: Could not find python${PYTHON_VERSION}-config"
416425
exit 1
417426
fi
418427
# The actual build command. Uses the makefile in the DQMGUI's repo.
@@ -448,8 +457,7 @@ install_dqmgui() {
448457
source "$INSTALLATION_DIR/root/bin/thisroot.sh"
449458

450459
# Temporary directory to clone GUI into
451-
DQMGUI_TMP_DIR=/tmp/dqmgui
452-
tar -xzf "$SCRIPT_DIR/dqmgui/dqmgui.tar.gz" -C /tmp
460+
tar -xzf "$SCRIPT_DIR/dqmgui/dqmgui.tar.gz" -C "${TMP_BASE_PATH}"
453461

454462
# Move dqmgui source and bin files to appropriate directory
455463
if [ -d "$INSTALLATION_DIR/$DMWM_GIT_TAG/sw/cms/dqmgui/$DQMGUI_GIT_TAG" ]; then
@@ -511,7 +519,7 @@ install_jsroot() {
511519

512520
# Extract the ROOT tar to a tmp folder for compilation
513521
install_root() {
514-
tar -xzf "$SCRIPT_DIR/root/root.tar.gz" -C /tmp
522+
tar -xzf "$SCRIPT_DIR/root/root.tar.gz" -C "${TMP_BASE_PATH}"
515523
#if [ -d $INSTALLATION_DIR/$DMWM_GIT_TAG/sw/external/root ]; then
516524
# rm -rf $INSTALLATION_DIR/$DMWM_GIT_TAG/sw/external/src/root
517525
#fi
@@ -520,8 +528,6 @@ install_root() {
520528
}
521529

522530
compile_root() {
523-
ROOT_TMP_DIR=/tmp/root
524-
ROOT_TMP_BUILD_DIR=/tmp/root_build
525531
if [ ! -d $ROOT_TMP_DIR ]; then
526532
echo "ERROR: ROOT source was not found in $ROOT_TMP_DIR"
527533
exit 1
@@ -533,12 +539,21 @@ compile_root() {
533539
fi
534540
mkdir -p $ROOT_TMP_BUILD_DIR
535541
cd $ROOT_TMP_BUILD_DIR
536-
cmake -DCMAKE_INSTALL_PREFIX=$ROOT_INSTALLATION_DIR $ROOT_TMP_DIR -DPython3_ROOT_DIR=$(which python3) -Dtesting=OFF -Dbuiltin_gtest=OFF
542+
cmake -DCMAKE_INSTALL_PREFIX=$ROOT_INSTALLATION_DIR $ROOT_TMP_DIR -DPython3_ROOT_DIR="$(which python${PYTHON_VERSION})" -Dtesting=OFF -Dbuiltin_gtest=OFF
537543
cmake --build . --target install -j $(nproc)
538544
cd $INSTALLATION_DIR
539545
rm -rf $ROOT_TMP_DIR $ROOT_TMP_BUILD_DIR
540546
}
541547

548+
# Cleanup temporary directories, remove cronjobs
549+
function _cleanup() {
550+
rm -rf $ROOT_TMP_DIR $ROOT_TMP_BUILD_DIR $ROTOGLUP_TMP_DIR $CLASSLIB_TMP_DIR $DMWM_TMP_DIR $NUMERIC_TMP_DIR $DQMGUI_TMP_DIR
551+
clean_crontab
552+
clean_acrontab
553+
}
554+
555+
trap _cleanup SIGINT
556+
542557
### Main script ###
543558

544559
# Declare each step of the installation procedure here. Steps

0 commit comments

Comments
 (0)