Skip to content

Commit

Permalink
added VM specific code
Browse files Browse the repository at this point in the history
  • Loading branch information
lhhunghimself committed Nov 12, 2024
1 parent f561a49 commit ea871fb
Show file tree
Hide file tree
Showing 6 changed files with 292 additions and 14 deletions.
122 changes: 122 additions & 0 deletions VM/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
#!/bin/bash
DOCKER_GPG=/etc/apt/keyrings/docker.gpg
apt-get install -y --no-install-recommends \
curl \
dbus-x11 \
feh \
firefox \
fluxbox \
fonts-wqy-microhei \
geany \
gtk2-engines-murrine \
gvfs-backends \
jq \
language-pack-gnome-zh-hant \
language-pack-zh-hant \
libbz2-dev \
libgl1-mesa-dri \
liblzma-dev \
libssl1.0 \
libwebkit2gtk-4.0 \
mesa-utils \
nano \
nemo \
net-tools \
openssh-server \
pwgen \
python3-pyqt5 \
python3-pyqt5.qtsvg \
python3-pyqt5.qtwebkit \
rsync \
ttf-ubuntu-font-family \
wget \
xdg-utils \
lxterminal \
xvfb \
zlib1g-dev \
zenity
git clone https://github.com/Biodepot/Biodepot-workflow-builder
cp -r Biodepot-workflow-builder/orange3 /orange3
cp -r Biodepot-workflow-builder/orangePatches /orangePatches
apt-get install -y \
build-essential \
python3-dev \
python3-pip \
&& python3 -m pip install --upgrade \
pip==20.0.1 \
setuptools \
wheel
cd / && pip3 install -r orange3/requirements-gui.txt
beautifulsoup4 \
docker \
pysam
pip3 install -e orange3

apt-get install -y --no-install-recommends gnupg
mkdir -p /etc/apt/keyrings && curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o $DOCKER_GPG
arch=$(dpkg --print-architecture) \
&& codename=$(awk -F= '/CODENAME/ {print $2;exit}' /etc/os-release) \
&& echo "deb [arch=$arch signed-by=$DOCKER_GPG] https://download.docker.com/linux/ubuntu $codename stable" > \
/etc/apt/sources.list.d/docker.list \
&& apt-get update \
&& apt-get install -y --no-install-recommends \
containerd.io \
docker-ce \
docker-ce-cli
pip3 install --user jsonpickle
cp -r Biodepot-workflow-builder/widgets widgets
cp -r Biodepot-workflow-builder/biodepot biodepot
cp -r Biodepot-workflow-builder/coreutils coreutils

apt-get install -y xorg
cp -r Biodepot-workflow-builder/scripts/generate_setup.sh /usr/local/bin/generate_setup.sh
chmod +x /usr/local/bin/generate_setup.sh
pip3 install -e /biodepot
curl -L "https://github.com/docker/compose/releases/download/1.23.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose \
&& chmod +x /usr/local/bin/docker-compose
sed -i 's/"Orange Canvas"/"Bwb"/' /orange3/Orange/canvas/config.py
rm -rf ~/.fluxbox
cp -r Biodepot-workflow-builder/fluxbox_config ~/.fluxbox
cp -r Biodepot-workflow-builder/user_config/* ~/.
cp /orangePatches/schemeedit.py /orange3/Orange/canvas/document/schemeedit.py
cp /orangePatches/canvasmain.py /orange3/Orange/canvas/application/canvasmain.py
cp /orangePatches/widgetsscheme.py /orange3/Orange/canvas/scheme/widgetsscheme.py
cp /orangePatches/signalmanager.py /orange3/Orange/canvas/scheme/signalmanager.py
cp /orangePatches/link.py /orange3/Orange/canvas/scheme/link.py
cp /orangePatches/signals.py /orange3/Orange/widgets/utils/signals.py
cp /orangePatches/linkitem.py /orange3/Orange/canvas/canvas/items/linkitem.py
cp /orangePatches/__main__.py /orange3/Orange/canvas/__main__.py
cp /orangePatches/discovery.py /orange3/Orange/canvas/registry/discovery.py

cp Biodepot-workflow-builder/scripts/startBwb.sh /usr/local/bin/startBwb.sh
cp Biodepot-workflow-builder/scripts/startSingleBwb.sh /usr/local/bin/startSingleBwb.sh
cp Biodepot-workflow-builder/scripts/runDockerJob.sh /usr/local/bin/runDockerJob.sh
cp Biodepot-workflow-builder/scripts/startScheduler.sh /usr/local/bin/startScheduler.sh
cp Biodepot-workflow-builder/scripts/build_workflow_containers.sh /usr/local/bin/build_workflow_containers.sh
cp Biodepot-workflow-builder/scripts/whiteListToolDock.py /usr/local/bin/whiteListToolDock.py
cp Biodepot-workflow-builder/scripts/addWorkflowsToToolDock.py /usr/local/bin/addWorkflowsToToolDock.py
cp Biodepot-workflow-builder/scripts/addWidgetToToolDock.sh /usr/local/bin/addWidgetToToolDock.sh
cp Biodepot-workflow-builder/scripts/removeWidgetFromToolDock.sh /usr/local/bin/removeWidgetFromToolDock.sh
cp Biodepot-workflow-builder/scripts/generate_setup.sh /usr/local/bin/generate_setup.sh
cp -r Biodepot-workflow-builder/executables /usr/local/bin/executables
groupadd ftpaccess
cp Biodepot-workflow-builder/sshd_config /etc/ssh/sshd_config
cp Biodepot-workflow-builder/startSftp.sh /usr/local/bin/startSftp.sh
cp Biodepot-workflow-builder/scripts/findResolution.sh /usr/local/bin/findResolution.sh

cp -r Biodepot-workflow-builder/workflows /workflows
cp -r Biodepot-workflow-builder/notebooks /notebooks
cp -r Biodepot-workflow-builder/templates /templates
cp -r Biodepot-workflow-builder/icons /icons
cp -r Biodepot-workflow-builder/tutorialFiles /tutorialFiles
cp Biodepot-workflow-builder/serverSettings.json /biodepot

cp Biodepot-workflow-builder/startup.sh /
cp Biodepot-workflow-builder/nginx.conf /etc/nginx/sites-enabled/default

#cp Biodepot-workflow-builder/ config files for dev tools
cp -r Biodepot-workflow-builder/dev-files/geany/ /root/.config/
cp -r Biodepot-workflow-builder/VM/xorg.conf /etc/X11/xorg.conf
cp -r Biodepot-workflow-builder/VM/*.sh /usr/local/bin/
cp Biodepot-workflow-builder/VM/menu /root/.fluxbox/menu
cp .fluxbox/bwb.svg /orange3/Orange/canvas/icons/.
28 changes: 28 additions & 0 deletions VM/menu
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Generated by fluxbox-generate_menu
#
# If you read this it means you want to edit this file manually, so here
# are some useful tips:
#
# - You can add your own menu-entries to ~/.fluxbox/usermenu
#
# - If you miss apps please let me know and I will add them for the next
# release.
#
# - The -r option prevents removing of empty menu entries and lines which
# makes things much more readable.
#
# - To prevent any other app from overwriting your menu
# you can change the menu name in ~/.fluxbox/init to:
# session.menuFile: ~/.fluxbox/my-menu
[begin] (Applications)
[encoding] {UTF-8}
[exec] (Bwb) {/usr/local/bin/startBwb.sh} </root/.fluxbox/bwb256.png>
[exec] (Bwb-debug) {/bin/bash -c 'export XENVIRONMENT=.Xresources; lxterminal -e startBwb.sh orange-canvas -l 4'} </root/.fluxbox/bwb256.png>
[exec] (Files) {dbus-launch nemo}
[exec] (Resize) {/usr/local/bin/resize.sh}
[exec] (Terminal) {/bin/bash -c 'export XENVIRONMENT=.Xresources; lxterminal'}
[exec] (geany) {geany}
[exec] (firefox) {firefox}
[exec] (Quit) {quit_desktop.sh}
[endencoding]
[end]
28 changes: 28 additions & 0 deletions VM/quit_desktop.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash

# Find the Xorg process for the current user
XORG_PID=$(ps -u "$USER" -o pid,cmd | grep -E 'Xorg|X ' | grep -v grep | awk '{print $1}')

# Check if Xorg process was found
if [ -z "$XORG_PID" ]; then
zenity --info --text="No Xorg process found for user $USER. Exiting."
exit 1
fi

# Prompt the user for confirmation using zenity
if zenity --question --text="Are you sure you want to terminate your X11 session?"; then
# User clicked "Yes"
zenity --info --text="Terminating Xorg process (PID: $XORG_PID)..."
kill "$XORG_PID"

# Verify if the process is still running, and if so, forcefully kill it
if ps -p "$XORG_PID" > /dev/null; then
zenity --warning --text="Process did not terminate gracefully. Forcing termination..."
kill -9 "$XORG_PID"
fi
zenity --info --text="Xorg process terminated."
stty echo
else
# User clicked "No"
zenity --info --text="Operation canceled by the user."
fi
57 changes: 57 additions & 0 deletions VM/resize.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/bin/bash

# Get all unique modes (resolutions) from the first column of xrandr output
modes=$(xrandr | awk '{ print $1 }' | grep '^[0-9]*x[0-9]*$' | sort -u)

# Check if we found any modes
if [ -z "$modes" ]; then
zenity --error --text="No available screen resolutions found."
exit 1
fi

# Display the unique list of available modes in zenity
selected_mode=$(echo "$modes" | zenity --list --title="Select Screen Resolution" \
--text="Choose a screen resolution" \
--column="Resolution" --width=300 --height=400)

# Check if the user pressed cancel or didn't select a mode
if [ -z "$selected_mode" ]; then
echo "No resolution selected. Exiting."
exit 1
fi

# Prompt the user to select an output if multiple displays are connected
outputs=$(xrandr | grep " connected" | awk '{ print $1 }')
output_count=$(echo "$outputs" | wc -l)

if [ "$output_count" -gt 1 ]; then
# Let the user choose an output if more than one is connected
selected_output=$(echo "$outputs" | zenity --list --title="Select Display Output" \
--text="Choose a display output to apply the resolution" \
--column="Output" --width=300 --height=200)

# Check if the user pressed cancel or didn't select an output
if [ -z "$selected_output" ]; then
echo "No display output selected. Exiting."
exit 1
fi
else
# Use the single output if only one display is connected
selected_output="$outputs"
fi

# Apply the selected resolution to the chosen output using xrandr
if xrandr --output "$selected_output" --mode "$selected_mode" 2>/dev/null; then
zenity --info --text="Resolution set to $selected_mode on $selected_output successfully."
else
zenity --error --text="Failed to set resolution. $selected_mode may not be supported on $selected_output."
exit 1
fi

# Check if the background image path is stored in ~/.fehbg
if [ -f ~/.fehbg ]; then
# Source ~/.fehbg to reapply the same background image
source ~/.fehbg
else
zenity --warning --text="No existing background image found to reapply."
fi
18 changes: 18 additions & 0 deletions VM/xorg.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Section "Monitor"
Identifier "Monitor0"
Option "PreferredMode" "1920x1080"
EndSection

Section "Screen"
Identifier "Screen0"
Device "Card0"
Monitor "Monitor0"
SubSection "Display"
Modes "1920x1080"
EndSubSection
EndSection

Section "Device"
Identifier "Card0"
Driver "intel" # or "modesetting" or your specific driver
EndSection
53 changes: 39 additions & 14 deletions coreutils/DockerClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,21 @@
import time
from pathlib import Path
#runScheduler.sh ['b2b72d36270f4200a9e', '/tmp/docker.b2b72d36270f4200a9e.json', '8', '8096']
def detect_container():
# Check for Docker-specific markers
if (os.path.isfile("/.dockerenv")):
return True

# Check for Apptainer/Singularity-specific markers
if (
os.environ.get("APPTAINER_NAME") or
os.environ.get("SINGULARITY_NAME") or
os.path.isdir("/.singularity.d") or
os.path.isfile("/.apptainer")
):
return True
return False

def breakpoint(title=None, message=None):
QtGui.QMessageBox.warning(title,'',message)
class ConsoleProcess:
Expand Down Expand Up @@ -259,21 +274,25 @@ def __init__(self, url, name):
self.url = url
self.name = name
self.cli = APIClient(base_url=url)
command = "awk -F'/containers/|/resolv.conf' '$2!=\"\" {print $2; exit}' /proc/self/mountinfo"
outputString=str(subprocess.check_output(
command,
shell=True,
universal_newlines=True,
))
if outputString:
self.bwb_instance_id = outputString.splitlines()[0]
else:
self.isContainer = detect_container()
self.bwb_instance_id = None
if(self.isContainer):
command = "awk -F'/containers/|/resolv.conf' '$2!=\"\" {print $2; exit}' /proc/self/mountinfo"
outputString=str(subprocess.check_output(
"cat /proc/self/mountinfo | grep -oP '(?<=docker/containers/).*?(?=/resolv)'",
shell=True,
universal_newlines=True,
))
self.bwb_instance_id = outputString.strip()
command,
shell=True,
universal_newlines=True,
))
if outputString:
self.bwb_instance_id = outputString.splitlines()[0]
else:
outputString=str(subprocess.check_output(
"cat /proc/self/mountinfo | grep -oP '(?<=docker/containers/).*?(?=/resolv)'",
shell=True,
universal_newlines=True,
))
self.bwb_instance_id = outputString.strip()

print(self.bwb_instance_id)
self.bwbMounts = {}
self.shareMountPoint={};
Expand All @@ -283,6 +302,7 @@ def __init__(self, url, name):
self.logFile = None
self.schedulerStarted = False


def getClient(self):
return self.cli

Expand Down Expand Up @@ -510,6 +530,9 @@ def findShareMountPoint(self,overwrite=False):

#check if mountpoint variable exists
def findVolumeMappings(self):
if not self.isContainer:
self.bwbMounts["/data"] = "/data"
return
for c in self.cli.containers():
container_id = c["Id"]
if container_id == self.bwb_instance_id:
Expand All @@ -527,6 +550,8 @@ def findNextFlowSelfMounts(self):
return mountString

def to_best_host_directory(self, path, returnNone=False):
if not detect_container():
return path
sys.stderr.write("bwbMounts are {}\n".format(self.bwbMounts))
if self.bwbMounts == {}:
self.findVolumeMappings()
Expand Down

0 comments on commit ea871fb

Please sign in to comment.