From bd0c017809a09ca1ab45da574a049f058c39f2b1 Mon Sep 17 00:00:00 2001 From: Dean Troyer Date: Thu, 4 Apr 2024 10:41:59 -0500 Subject: [PATCH] Add bootstrap-sel.sh and selrc 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 https://github.com/microsoft/WSL/issues/4189 * set hostname to WSL distro name * run /etc/rc.local Signed-off-by: Dean Troyer --- bootstrap-sel.sh | 43 +++++++++++++++++++++++++++++++++++++++++ scripts/install-cuda.sh | 4 ++-- selrc | 31 +++++++++++++++++++++++++++++ 3 files changed, 76 insertions(+), 2 deletions(-) create mode 100755 bootstrap-sel.sh create mode 100755 selrc diff --git a/bootstrap-sel.sh b/bootstrap-sel.sh new file mode 100755 index 0000000..11f58e6 --- /dev/null +++ b/bootstrap-sel.sh @@ -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 diff --git a/scripts/install-cuda.sh b/scripts/install-cuda.sh index b0ae535..85d53e2 100755 --- a/scripts/install-cuda.sh +++ b/scripts/install-cuda.sh @@ -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 diff --git a/selrc b/selrc new file mode 100755 index 0000000..7b588a1 --- /dev/null +++ b/selrc @@ -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