Skip to content

Commit

Permalink
Add bootstrap-sel.sh and selrc
Browse files Browse the repository at this point in the history
Set up some housekeeping to run on every domain start.  Only do the minimal
still for a usable SEL environment
* install additional packages
* install the current /etc/selrc
  * Include work-around for microsoft/WSL#4189
  * set hostname to WSL distro name
  * run /etc/rc.local

Signed-off-by: Dean Troyer <[email protected]>
  • Loading branch information
dtroyer-salad committed Apr 4, 2024
1 parent 7ef0597 commit bd0c017
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 2 deletions.
43 changes: 43 additions & 0 deletions bootstrap-sel.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/bin/bash
# bootstrap-sel.sh - Boostrap new SEL (development)
#
# * install minimal packages
#
# Run bootstrap-sel.sh without a local repo:
#
# curl https://raw.githubusercontent.com/dtroyer-salad/wsl-ansible/main/bootstrap-sel.sh | bash -s

set -o errexit
set -o xtrace

# Keep track of the current script directory.
TOP_DIR=$(cd $(dirname "$0") && pwd)

# Ensure we have the basics
if [[ -r /etc/os-release ]]; then
source /etc/os-release
ID_LIKE=${ID_LIKE:-$ID}
case "$ID_LIKE" in
debian)
# Debian/Ubuntu
sudo apt-get update
sudo apt-get -y install curl git gpg make screen vim wget
;;
fedora)
# Fedora/RHEL/OEL
sudo dnf -y install curl git gpg make screen vim wget
;;
esac
fi

BOOT=$(grep "[boot]" /etc/wsl.conf)
if [[ -z $BOOT ]]; then
# Add boot section to wsl.conf to run rc.local
echo -e "[boot]\ncommand = \"/etc/selrc\n\"" >>/etc/wsl.conf
fi

# Get current selrc
curl -R https://raw.githubusercontent.com/dtroyer-salad/wsl-ansible/main/selrc -o /etc/selrc
chmod 755 /etc/selrc

. /etc/selrc
4 changes: 2 additions & 2 deletions scripts/install-cuda.sh
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,10 @@ curl -s -L https://nvidia.github.io/libnvidia-container/$distribution/libnvidia-
sudo apt-get update
sudo apt-get install -y nvidia-docker2

sudo /etc/init.d/docker start
sudo /etc/init.d/docker restart

# Hack-around a difference in Ubuntu and Debian
if [[ ! -x /sbin/ldconfig.real ]]; then
if [[ ! -r /sbin/ldconfig.real ]]; then
# nvidia-container-cli expects to find ldconfig.real which doesn't exist on Debian
sudo ln /sbin/ldconfig /sbin/ldconfig.real
fi
31 changes: 31 additions & 0 deletions selrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/sh -e
#
# selrc
#
# This iscript is traditionally executed at the end of each multiuser
# runlevel, however in WSL there is no SysVInit or systemd by default.
# This incarnation is launched via /etc/wsl.conf:
#
# [boot]
# command="/etc/selrc"
#

set -x

# cgroups work-around
# This is a work-around for https://github.com/microsoft/WSL/issues/4189
# that is still open as of 2024-04
mkdir -p /sys/fs/cgroup/systemd
mount -t cgroup -o none,name=systemd cgroup /sys/fs/cgroup/systemd

# Fixup hosts
if [[ -n $WSL_DISTRO_NAME ]]; then
echo $WSL_DISTRO_NAME >/etc/hostname
hostname -F /etc/hostname
fi
sed -i "s/^\(127.0.1.1[[:space:]]*\).*$/\1 $WSL_DISTRO_NAME.\t$WSL_DISTRO_NAME/" /etc/hosts

# Run rc.local
if [[ -x /etc/rc.local ]]; then
. /etc/rc.local
fi

0 comments on commit bd0c017

Please sign in to comment.