Back Midas Rome Roody Rootana
  Midas DAQ System  Not logged in ELOG logo
Entry  09 Jan 2026, Stefan Ritt, Forum, MIDAS installation midas_setup.sh
    Reply  10 Jan 2026, Marius Koeppel, Forum, MIDAS installation 
       Reply  13 Jan 2026, Stefan Ritt, Forum, MIDAS installation install.sh
Message ID: 3190     Entry time: 13 Jan 2026     In reply to: 3189
Author: Stefan Ritt 
Topic: Forum 
Subject: MIDAS installation 
Thanks for your feedback. I reworked the installation script, and now also called it "install.sh" since it includes also the git clone. I modeled it after 
homebrew a mit (https://brew.sh). This means you can now run the script on a prison linux system with:

  /bin/bash -c "$(curl -sS https://bitbucket.org/tmidas/midas/raw/HEAD/install.sh)"

It contains three defaults for MIDASSYS, MIDAS_DIR and MIDAS_EXPT_NAME, but when you run in, you can overwrite these
defaults interactively. The script creates all directories, clones midas, compiles and installs it, installs and runs mhttpd as a system
service, then starts the logger and the example frontend. I also added your PYTHONPATH variable. The RC file is now automatically
detected.

Yes one could add more config files, but I want to have this basic install as simple as possible. If more things are needed, they
should be added as separate scripts or .ODB files.

Please have a look and let me know what you think about. I tested it on a RaspberryPi, but not yet on other systems.

Stefan
Attachment 1: install.sh  3 kB  | Hide | Hide all
#!/bin/sh

#
# This is a MIDAS install script which installes MIDAS and sets up
# a proper environment for a simple experiment
#
# On a new system you can execut it with
#
# /bin/bash -c "$(curl -sS https://bitbucket.org/tmidas/midas/raw/HEAD/install.sh)"
#

#
# Default directories
#
DEFAULT_MIDASSYS="$HOME/midas"
DEFAULT_MIDAS_DIR="$HOME/online"
DEFAULT_MIDAS_EXPT_NAME="Online"

#
# Query directories
#

# ---- MIDASSYS ----
printf "Clone MIDAS into directory [%s]: " "$DEFAULT_MIDASSYS"
read USER_MIDASSYS

# If user entered something, it must start with a /
if [ -n "$USER_MIDASSYS" ] && [ "${USER_MIDASSYS#/}" = "$USER_MIDASSYS" ]; then
   echo "Error: directory must be an absolute path starting with '/'"
   exit 1
fi

# Use default if user input is emtpy
MIDASSYS=${USER_MIDASSYS:-$DEFAULT_MIDASSYS}

# ---- MIDAS_DIR ----
printf "MIDAS experiment directory [%s]: " "$DEFAULT_MIDAS_DIR"
read USER_MIDAS_DIR

# If user entered something, it must start with a /
if [ -n "$USER_MIDAS_DIR" ] && [ "${USER_MIDAS_DIR#/}" = "$USER_MIDASDIR" ]; then
   echo "Error: directory must be an absolute path starting with '/'"
   exit 1
fi

# Use default if user input is emtpy
MIDAS_DIR=${USER_MIDAS_DIR:-$DEFAULT_MIDAS_DIR}

# ---- MIDAS_EXPT_NAME ----
printf "MIDAS experiment name [%s]: " "$DEFAULT_MIDAS_EXPT_NAME"
read USER_MIDAS_EXPT_NAME

# Use default if user input is emtpy
MIDAS_EXPT_NAME=${USER_MIDAS_EXPT_NAME:-$DEFAULT_MIDAS_EXPT_NAME}

echo "\n---------------------------------------------------------------"
printf '\033[1;33m*\033[0m %s\n' "MIDAS system directory            : $MIDASSYS"
printf '\033[1;33m*\033[0m %s\n' "MIDAS experiment directory        : $MIDAS_DIR"
printf '\033[1;33m*\033[0m %s\n' "MIDAS experiment name             : $MIDAS_EXPT_NAME"

#
# Change environment
#

detect_rc_file() {
    # $SHELL is usually reliable
    case "$(basename "$SHELL")" in
	bash)
	    [ -f "$HOME/.bashrc" ] && echo "$HOME/.bashrc" || echo "$HOME/.bash_profile"
	    ;;
	zsh)
	    # zsh always reads .zshenv
	    echo "$HOME/.zshenv"
	    ;;
	fish)
	    # fish is not POSIX, but handle gracefully
	    echo "$HOME/.config/fish/config.fish"
	    ;;
	*)
	    # fallback for sh, dash, etc.
	    echo "$HOME/.profile"
	    ;;
    esac
}

RC_FILE=$(detect_rc_file)

grep -q '>>> MIDAS >>>' "$RC_FILE" 2>/dev/null || cat >>"$RC_FILE" <<'EOF'

# >>> MIDAS >>>
export PATH="__MIDASSYS__/bin:$PATH"
export MIDASSYS="__MIDASSYS__"
export MIDAS_DIR="__MIDAS_DIR__"
export MIDAS_EXPT_NAME="__MIDAS_EXPT_NAME__"
export PYTHONPATH="$PYTHONPATH:__MIDASSYS__/python"
# <<< MIDAS <<<
EOF

# substitue placeholders
sed -i.bak \
    -e "s|__MIDASSYS__|$MIDASSYS|g" \
    -e "s|__MIDAS_DIR__|$MIDAS_DIR|g" \
    -e "s|__MIDAS_EXPT_NAME__|$MIDAS_EXPT_NAME|g" \
    "$RC_FILE"

# source environment file
. "$RC_FILE"

printf '\033[1;33m*\033[0m %s\n' "Environment variables written to  : $RC_FILE"
echo "---------------------------------------------------------------\n"
printf '\033[1;33m*\033[0m %s\n\n' "Cloning and compiling MIDAS..."

# create experiment directory
mkdir -p "$MIDAS_DIR"

# clone MIDAS
git clone https://bitbucket.org/tmidas/midas.git "$MIDASSYS" --recurse-submodules

# compile MIDAS
mkdir -p "$MIDASSYS/build"
cd "$MIDASSYS/build"
cmake .. -DCMAKE_BUILD_TYPE=RelWithDebInfo
make install

#
# Load initial ODB, opens port 8081 for mhttpd
#
printf '\n\033[1;33m*\033[0m %s\n' "Loading initial ODB"

cd "$MIDASSYS"
odbedit -c "load install.odb" > /dev/null

# start example frontend and logger
printf '\033[1;33m*\033[0m %s\n' "Starting frontend and logger"
$MIDASSYS/build/examples/experiment/frontend -D 1>/dev/null
$MIDASSYS/bin/mlogger -D 1>/dev/null

#
# Installing mhttpd servcice
#
printf '\033[1;33m*\033[0m %s\n' "Installing mhttpd service"
sudo cp mhttpd.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable mhttpd

printf '\033[1;33m*\033[0m %s\n' "Starting mhttpd service"
sudo systemctl start mhttpd

printf '\033[1;33m*\033[0m %s\n' "Finished MIDAS setup"


ELOG V3.1.4-2e1708b5