-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Michal Czyz <[email protected]>
- Loading branch information
1 parent
2782e5d
commit 1713d8c
Showing
3 changed files
with
160 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
#!/bin/bash | ||
|
||
# Base file is from devcontainers/features/desktop-lite/install.sh | ||
# Original file is licensed as MIT | ||
# Applied modifications to the script 2024 | ||
|
||
user_name="root" | ||
group_name="root" | ||
LOG=/tmp/container-init.log | ||
|
||
export DBUS_SESSION_BUS_ADDRESS="autolaunch:" | ||
export DISPLAY=":1" | ||
export VNC_RESOLUTION="1920x1080x32" | ||
export LANG="en_US.UTF-8" | ||
export LANGUAGE="en_US.UTF-8" | ||
|
||
# Execute the command it not already running | ||
startInBackgroundIfNotRunning() | ||
{ | ||
log "Starting $1." | ||
echo -e "\n** $(date) **" | sudoIf tee -a /tmp/$1.log > /dev/null | ||
if ! pgrep -x $1 > /dev/null; then | ||
keepRunningInBackground "$@" | ||
while ! pgrep -x $1 > /dev/null; do | ||
sleep 1 | ||
done | ||
log "$1 started." | ||
else | ||
echo "$1 is already running." | sudoIf tee -a /tmp/$1.log > /dev/null | ||
log "$1 is already running." | ||
fi | ||
} | ||
|
||
# Keep command running in background | ||
keepRunningInBackground() | ||
{ | ||
($2 bash -c "while :; do echo [\$(date)] Process started.; $3; echo [\$(date)] Process exited!; sleep 5; done 2>&1" | sudoIf tee -a /tmp/$1.log > /dev/null & echo "$!" | sudoIf tee /tmp/$1.pid > /dev/null) | ||
} | ||
|
||
# Use sudo to run as root when required | ||
sudoIf() | ||
{ | ||
if [ "$(id -u)" -ne 0 ]; then | ||
sudo "$@" | ||
else | ||
"$@" | ||
fi | ||
} | ||
|
||
# Use sudo to run as non-root user if not already running | ||
sudoUserIf() | ||
{ | ||
if [ "$(id -u)" -eq 0 ] && [ "${user_name}" != "root" ]; then | ||
sudo -u ${user_name} "$@" | ||
else | ||
"$@" | ||
fi | ||
} | ||
|
||
# Log messages | ||
log() | ||
{ | ||
echo -e "[$(date)] $@" | sudoIf tee -a $LOG > /dev/null | ||
} | ||
|
||
log "** SCRIPT START **" | ||
|
||
# Start dbus. | ||
log 'Running "/etc/init.d/dbus start".' | ||
if [ -f "/var/run/dbus/pid" ] && ! pgrep -x dbus-daemon > /dev/null; then | ||
sudoIf rm -f /var/run/dbus/pid | ||
fi | ||
sudoIf /etc/init.d/dbus start 2>&1 | sudoIf tee -a /tmp/dbus-daemon-system.log > /dev/null | ||
while ! pgrep -x dbus-daemon > /dev/null; do | ||
sleep 1 | ||
done | ||
|
||
# Startup tigervnc server and fluxbox | ||
sudoIf rm -rf /tmp/.X11-unix /tmp/.X*-lock | ||
mkdir -p /tmp/.X11-unix | ||
sudoIf chmod 1777 /tmp/.X11-unix | ||
sudoIf chown root:${group_name} /tmp/.X11-unix | ||
if [ "$(echo "${VNC_RESOLUTION}" | tr -cd 'x' | wc -c)" = "1" ]; then VNC_RESOLUTION=${VNC_RESOLUTION}x16; fi | ||
screen_geometry="${VNC_RESOLUTION%*x*}" | ||
screen_depth="${VNC_RESOLUTION##*x}" | ||
startInBackgroundIfNotRunning "Xtigervnc" sudoUserIf "tigervncserver ${DISPLAY} -geometry ${screen_geometry} -depth ${screen_depth} -rfbport 5901 -dpi ${VNC_DPI:-96} -localhost -desktop fluxbox -fg" | ||
# -passwd /usr/local/etc/vscode-dev-containers/vnc-passwd | ||
|
||
# Spin up noVNC if installed and not running. | ||
if [ -d "/usr/local/novnc" ] && [ "$(ps -ef | grep /usr/local/novnc/noVNC*/utils/launch.sh | grep -v grep)" = "" ]; then | ||
keepRunningInBackground "noVNC" sudoIf "/usr/local/novnc/noVNC*/utils/launch.sh --listen 6080 --vnc localhost:5901" | ||
log "noVNC started." | ||
else | ||
log "noVNC is already running or not installed." | ||
fi | ||
|
||
# Run whatever was passed in | ||
log "Executing \"$@\"." | ||
exec "$@" | ||
log "** SCRIPT EXIT **" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#!/bin/bash | ||
|
||
source common.sh | ||
|
||
# Attempt to change default shell | ||
chsh -s /bin/bash | ||
|
||
# Install Konsole | ||
|
||
sudo apt-get -y install konsole | ||
|
||
# Update fluxbox config | ||
|
||
fluxbox_apps="$(cat \ | ||
<< 'EOF' | ||
[transient] (role=GtkFileChooserDialog) | ||
[Dimensions] {100% 100%} | ||
[Position] (CENTER) {0 0} | ||
[end] | ||
EOF | ||
)" | ||
|
||
echo "${fluxbox_apps}" > "~/.fluxbox/apps" | ||
|
||
fluxbox_menu="$(cat \ | ||
<< 'EOF' | ||
[begin] ( Application Menu ) | ||
[exec] (File Manager) { nautilus ~ } <> | ||
[exec] (Text Editor) { mousepad } <> | ||
[exec] (Terminal) { konsole -e /bin/bash } <> | ||
[exec] (Web Browser) { x-www-browser --disable-dev-shm-usage } <> | ||
[submenu] (System) {} | ||
[exec] (Set Resolution) { tilix -t "Set Resolution" -e bash /usr/local/bin/set-resolution } <> | ||
[exec] (Edit Application Menu) { mousepad ~/.fluxbox/menu } <> | ||
[exec] (Passwords and Keys) { seahorse } <> | ||
[exec] (Top Processes) { tilix -t "Top" -e htop } <> | ||
[exec] (Disk Utilization) { tilix -t "Disk Utilization" -e ncdu / } <> | ||
[exec] (Editres) {editres} <> | ||
[exec] (Xfontsel) {xfontsel} <> | ||
[exec] (Xkill) {xkill} <> | ||
[exec] (Xrefresh) {xrefresh} <> | ||
[end] | ||
[config] (Configuration) | ||
[workspaces] (Workspaces) | ||
[end] | ||
EOF | ||
)" | ||
|
||
echo "${fluxbox_menu}" > "~/.fluxbox/menu" | ||
|
||
# Try to kill existing tigervncserver | ||
PIDS_TO_KILL=$(ps axjf | grep tigervncserver | awk '{print $2}') | ||
pkill -9 "${PIDS_TO_KILL[0]}" | ||
|
||
# Try to kill existing novnc | ||
PIDS_TO_KILL=$(ps axjf | grep novnc | awk '{print $2}') | ||
pkill -9 "${PIDS_TO_KILL[0]}" | ||
|
||
bash desktop-update.sh |