Improvements to the init process
Move some files to locations that make more sense... Downloads go to Downloads Init scripts go to an "init" directory Add a script for clearing up some memory - May or may not use it.
This commit is contained in:
31
overlay/etc/cont-init.d/10-setup_user.sh
Normal file
31
overlay/etc/cont-init.d/10-setup_user.sh
Normal file
@@ -0,0 +1,31 @@
|
||||
|
||||
PUID=${PUID:-99}
|
||||
PGID=${PGID:-100}
|
||||
UMASK=${UMASK:-000}
|
||||
USER_PASSWORD=${USER_PASSWORD:-password}
|
||||
|
||||
echo "**** Configure default user ****"
|
||||
|
||||
echo "Setting run user uid=${PGID}(${USER}) gid=${PUID}(${USER})"
|
||||
groupmod -o -g "${PGID}" ${USER}
|
||||
usermod -o -u "${PUID}" ${USER}
|
||||
|
||||
|
||||
echo "Setting umask to ${UMASK}";
|
||||
umask ${UMASK}
|
||||
|
||||
|
||||
# Setup home directory and permissions
|
||||
echo "Adding default home directory template"
|
||||
mkdir -p ${USER_HOME}
|
||||
chown -R ${PUID}:${PGID} /etc/home_directory_template
|
||||
rsync -aq /etc/home_directory_template/ ${USER_HOME}/
|
||||
|
||||
|
||||
# Set the root and user password
|
||||
echo "Setting root password"
|
||||
echo "root:${USER_PASSWORD}" | chpasswd
|
||||
echo "Setting user password"
|
||||
echo "${USER}:${USER_PASSWORD}" | chpasswd
|
||||
|
||||
echo "DONE"
|
||||
10
overlay/etc/cont-init.d/20-configre_sshd.sh
Normal file
10
overlay/etc/cont-init.d/20-configre_sshd.sh
Normal file
@@ -0,0 +1,10 @@
|
||||
|
||||
# Generate new SSH host keys if they dont exist
|
||||
if [[ ! -f /etc/ssh/ssh_host_rsa_key ]]; then
|
||||
echo "**** Generating SSH keys ****";
|
||||
/usr/bin/ssh-keygen -A
|
||||
fi
|
||||
mkdir -p /run/sshd
|
||||
chmod 744 /run/sshd
|
||||
|
||||
echo "DONE"
|
||||
26
overlay/etc/cont-init.d/30-configure_dbus.sh
Normal file
26
overlay/etc/cont-init.d/30-configure_dbus.sh
Normal file
@@ -0,0 +1,26 @@
|
||||
|
||||
# Configure dbus
|
||||
echo "**** Configure container dbus ****";
|
||||
if [[ "${HOST_DBUS}" == "true" ]]; then
|
||||
echo "Container configured to use the host dbus";
|
||||
# Disable supervisord script
|
||||
sed -i 's|^autostart.*=.*$|autostart=false|' /etc/supervisor/conf.d/dbus.conf
|
||||
else
|
||||
echo "Container configured to run its own dbus";
|
||||
# Enable supervisord script
|
||||
sed -i 's|^autostart.*=.*$|autostart=true|' /etc/supervisor/conf.d/dbus.conf
|
||||
# Configure dbus to run as USER
|
||||
sed -i "/ <user>/c\ <user>${USER}</user>" /usr/share/dbus-1/system.conf
|
||||
# Remove old dbus session
|
||||
rm -rf ${USER_HOME}/.dbus/session-bus/* 2> /dev/null
|
||||
# Remove old dbus pids
|
||||
mkdir -p /var/run/dbus
|
||||
chown -R ${PUID}:${PGID} /var/run/dbus/
|
||||
chmod -R 770 /var/run/dbus/
|
||||
# Generate a dbus machine ID
|
||||
dbus-uuidgen > /var/lib/dbus/machine-id
|
||||
# Remove old lockfiles
|
||||
find /var/run/dbus -name "pid" -exec rm -f {} \;
|
||||
fi
|
||||
|
||||
echo "DONE"
|
||||
19
overlay/etc/cont-init.d/40-setup_locale.sh
Normal file
19
overlay/etc/cont-init.d/40-setup_locale.sh
Normal file
@@ -0,0 +1,19 @@
|
||||
|
||||
current_local=$(head -n 1 /etc/locale.gen)
|
||||
user_local=$(echo ${USER_LOCALES} | cut -d ' ' -f 1)
|
||||
|
||||
if [ "${current_local}" != "${USER_LOCALES}" ]; then
|
||||
echo "**** Configuring Locales to ${USER_LOCALES} ****";
|
||||
rm /etc/locale.gen
|
||||
echo -e "${USER_LOCALES}\nen_US.UTF-8 UTF-8" > "/etc/locale.gen"
|
||||
export LANGUAGE="${user_local}"
|
||||
export LANG="${user_local}"
|
||||
export LC_ALL="${user_local}" 2> /dev/null
|
||||
sleep 2
|
||||
locale-gen
|
||||
update-locale LC_ALL="${user_local}"
|
||||
else
|
||||
echo "**** Locales already set correctly to ${USER_LOCALES} ****";
|
||||
fi
|
||||
|
||||
echo "DONE"
|
||||
20
overlay/etc/cont-init.d/50-configure_audio.sh
Normal file
20
overlay/etc/cont-init.d/50-configure_audio.sh
Normal file
@@ -0,0 +1,20 @@
|
||||
|
||||
echo "**** Configure pulseaudio socket ****"
|
||||
sed -i 's|^; default-server.*$|default-server = unix:/tmp/pulseaudio.socket|' /etc/pulse/client.conf
|
||||
sed -i 's|^load-module module-native-protocol-unix.*$|load-module module-native-protocol-unix socket=/tmp/pulseaudio.socket auth-anonymous=1|' \
|
||||
/etc/pulse/default.pa
|
||||
chown -R ${USER} /etc/pulse
|
||||
|
||||
# Credits for this audio patch:
|
||||
# - https://github.com/novnc/noVNC/issues/302
|
||||
# - https://github.com/vexingcodes/dwarf-fortress-docker
|
||||
# - https://github.com/calebj/noVNC
|
||||
if [ -f /opt/noVNC/audio.patch ]; then
|
||||
echo "**** Patching noVNC with audio websocket ****"
|
||||
pushd /opt/noVNC/ &> /dev/null
|
||||
patch -p1 --input=/opt/noVNC/audio.patch --batch --quiet
|
||||
popd &> /dev/null
|
||||
rm /opt/noVNC/audio.patch
|
||||
fi
|
||||
|
||||
echo "DONE"
|
||||
65
overlay/etc/cont-init.d/80-configure_nvidia_driver.sh
Normal file
65
overlay/etc/cont-init.d/80-configure_nvidia_driver.sh
Normal file
@@ -0,0 +1,65 @@
|
||||
|
||||
# Fech NVIDIA GPU device (if one exists)
|
||||
if [ "$NVIDIA_VISIBLE_DEVICES" == "all" ]; then
|
||||
export gpu_select=$(nvidia-smi --format=csv --query-gpu=uuid 2> /dev/null | sed -n 2p)
|
||||
elif [ -z "$NVIDIA_VISIBLE_DEVICES" ]; then
|
||||
export gpu_select=$(nvidia-smi --format=csv --query-gpu=uuid 2> /dev/null | sed -n 2p)
|
||||
else
|
||||
export gpu_select=$(nvidia-smi --format=csv --id=$(echo "$NVIDIA_VISIBLE_DEVICES" | cut -d ',' -f1) --query-gpu=uuid | sed -n 2p)
|
||||
if [ -z "$gpu_select" ]; then
|
||||
export gpu_select=$(nvidia-smi --format=csv --query-gpu=uuid 2> /dev/null | sed -n 2p)
|
||||
fi
|
||||
fi
|
||||
|
||||
export nvidia_pci_address="$(nvidia-smi --format=csv --query-gpu=pci.bus_id --id="${gpu_select}" 2> /dev/null | sed -n 2p | cut -d ':' -f2,3)"
|
||||
export nvidia_gpu_name=$(nvidia-smi --format=csv --query-gpu=name --id="${gpu_select}" | sed -n 2p 2> /dev/null)
|
||||
export nvidia_host_driver_version="$(nvidia-smi 2> /dev/null | grep NVIDIA-SMI | cut -d ' ' -f3)"
|
||||
|
||||
function download_driver {
|
||||
mkdir -p ${USER_HOME}/Downloads
|
||||
chown -R ${USER} ${USER_HOME}/Downloads
|
||||
|
||||
if [[ ! -f "${USER_HOME}/Downloads/NVIDIA_${nvidia_host_driver_version}.run" ]]; then
|
||||
echo "Downloading driver v${nvidia_host_driver_version}"
|
||||
wget -q --show-progress --progress=bar:force:noscroll \
|
||||
-O /tmp/NVIDIA.run \
|
||||
http://download.nvidia.com/XFree86/Linux-x86_64/${nvidia_host_driver_version}/NVIDIA-Linux-x86_64-${nvidia_host_driver_version}.run
|
||||
[[ $? -gt 0 ]] && echo "Error downloading driver. Exit!" && return 1
|
||||
|
||||
mv /tmp/NVIDIA.run ${USER_HOME}/Downloads/NVIDIA_${nvidia_host_driver_version}.run
|
||||
fi
|
||||
}
|
||||
|
||||
function install_driver {
|
||||
# Check here if the currently installed version matches using nvidia-settings
|
||||
nvidia_settings_version=$(nvidia-settings --version 2> /dev/null | grep version | cut -d ' ' -f 4)
|
||||
[[ "${nvidia_settings_version}x" == "${nvidia_host_driver_version}x" ]] && return 0;
|
||||
|
||||
# Download the driver (if it does not yet exist locally)
|
||||
download_driver
|
||||
|
||||
echo "Installing driver v${nvidia_host_driver_version} to match what is running on the host"
|
||||
chmod +x ${USER_HOME}/Downloads/NVIDIA_${nvidia_host_driver_version}.run
|
||||
${USER_HOME}/Downloads/NVIDIA_${nvidia_host_driver_version}.run \
|
||||
--silent \
|
||||
--accept-license \
|
||||
--no-kernel-module \
|
||||
--install-compat32-libs \
|
||||
--no-nouveau-check \
|
||||
--no-nvidia-modprobe \
|
||||
--no-rpms \
|
||||
--no-backup \
|
||||
--no-check-for-alternate-installs \
|
||||
--no-libglx-indirect \
|
||||
--no-install-libglvnd \
|
||||
> ${USER_HOME}/Downloads/nvidia_gpu_install.log 2>&1
|
||||
}
|
||||
|
||||
if [[ -z ${nvidia_pci_address} ]]; then
|
||||
echo "**** No NVIDIA device found ****";
|
||||
else
|
||||
echo "**** Found NVIDIA device '${nvidia_gpu_name}' ****";
|
||||
install_driver
|
||||
fi
|
||||
|
||||
echo "DONE"
|
||||
82
overlay/etc/cont-init.d/90-configure_xorg.sh
Normal file
82
overlay/etc/cont-init.d/90-configure_xorg.sh
Normal file
@@ -0,0 +1,82 @@
|
||||
|
||||
# Fech NVIDIA GPU device (if one exists)
|
||||
if [ "$NVIDIA_VISIBLE_DEVICES" == "all" ]; then
|
||||
export gpu_select=$(nvidia-smi --format=csv --query-gpu=uuid 2> /dev/null | sed -n 2p)
|
||||
elif [ -z "$NVIDIA_VISIBLE_DEVICES" ]; then
|
||||
export gpu_select=$(nvidia-smi --format=csv --query-gpu=uuid 2> /dev/null | sed -n 2p)
|
||||
else
|
||||
export gpu_select=$(nvidia-smi --format=csv --id=$(echo "$NVIDIA_VISIBLE_DEVICES" | cut -d ',' -f1) --query-gpu=uuid | sed -n 2p)
|
||||
if [ -z "$gpu_select" ]; then
|
||||
export gpu_select=$(nvidia-smi --format=csv --query-gpu=uuid 2> /dev/null | sed -n 2p)
|
||||
fi
|
||||
fi
|
||||
|
||||
export nvidia_gpu_hex_id=$(nvidia-smi --format=csv --query-gpu=pci.bus_id --id="${gpu_select}" 2> /dev/null | sed -n 2p)
|
||||
|
||||
# Fech current configuration (if modified in UI)
|
||||
if [ -f "${USER_HOME}/.config/xfce4/xfconf/xfce-perchannel-xml/displays.xml" ]; then
|
||||
new_display_sizew=$(cat ${USER_HOME}/.config/xfce4/xfconf/xfce-perchannel-xml/displays.xml | grep Resolution | head -n1 | grep -oP '(?<=value=").*?(?=")' | cut -d'x' -f1)
|
||||
new_display_sizeh=$(cat ${USER_HOME}/.config/xfce4/xfconf/xfce-perchannel-xml/displays.xml | grep Resolution | head -n1 | grep -oP '(?<=value=").*?(?=")' | cut -d'x' -f2)
|
||||
if [ "${new_display_sizew}x" != "x" ] && [ "${new_display_sizeh}x" != "x" ]; then
|
||||
export DISPLAY_SIZEW="${new_display_sizew}"
|
||||
export DISPLAY_SIZEH="${new_display_sizeh}"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Configure a NVIDIA X11 config
|
||||
function configure_nvidia_x_server {
|
||||
echo "Configuring X11 with GPU ID: '${gpu_select}'"
|
||||
nvidia_gpu_hex_id=$(nvidia-smi --format=csv --query-gpu=pci.bus_id --id="${gpu_select}" 2> /dev/null | sed -n 2p)
|
||||
IFS=":." ARR_ID=(${nvidia_gpu_hex_id})
|
||||
unset IFS
|
||||
bus_id=PCI:$((16#${ARR_ID[1]})):$((16#${ARR_ID[2]})):$((16#${ARR_ID[3]}))
|
||||
echo "Configuring X11 with PCI bus ID: '${bus_id}'"
|
||||
export MODELINE=$(cvt -r "${DISPLAY_SIZEW}" "${DISPLAY_SIZEH}" "${DISPLAY_REFRESH}" | sed -n 2p)
|
||||
echo "Writing X11 config with ${MODELINE}"
|
||||
nvidia-xconfig --virtual="${DISPLAY_SIZEW}x${DISPLAY_SIZEH}" --depth="${DISPLAY_CDEPTH}" --mode=$(echo "${MODELINE}" | awk '{print $2}' | tr -d '"') --allow-empty-initial-configuration --no-probe-all-gpus --busid="${bus_id}" --only-one-x-screen --connected-monitor="${DISPLAY_VIDEO_PORT}"
|
||||
sed -i '/Driver\s\+"nvidia"/a\ Option "ModeValidation" "NoMaxPClkCheck, NoEdidMaxPClkCheck, NoMaxSizeCheck, NoHorizSyncCheck, NoVertRefreshCheck, NoVirtualSizeCheck, NoExtendedGpuCapabilitiesCheck, NoTotalSizeCheck, NoDualLinkDVICheck, NoDisplayPortBandwidthCheck, AllowNon3DVisionModes, AllowNonHDMI3DModes, AllowNonEdidModes, NoEdidHDMI2Check, AllowDpInterlaced"' /etc/X11/xorg.conf
|
||||
sed -i '/Section\s\+"Monitor"/a\ '"${MODELINE}" /etc/X11/xorg.conf
|
||||
}
|
||||
|
||||
# Allow anybody for running x server
|
||||
function configure_x_server {
|
||||
# Configure x to be run by anyone
|
||||
if grep -Fxq "allowed_users=console" /etc/X11/Xwrapper.config; then
|
||||
echo "Configure Xwrapper.config"
|
||||
sed -i "s/allowed_users=console/allowed_users=anybody/" /etc/X11/Xwrapper.config
|
||||
fi
|
||||
|
||||
# Ensure the X socket path exists
|
||||
if [ ! -d /tmp/.X11-unix ]; then
|
||||
mkdir -p /tmp/.X11-unix
|
||||
fi
|
||||
|
||||
# Check if this container is being run as a secondary instance
|
||||
if [ "${MODE}" == "p" ] | [ "${MODE}" == "primary" ]; then
|
||||
echo "Configure container as primary the X server"
|
||||
# Enable supervisord script
|
||||
sed -i 's|^autostart.*=.*$|autostart=true|' /etc/supervisor/conf.d/xorg.conf
|
||||
elif [ "${MODE}" == "fb" ] | [ "${MODE}" == "framebuffer" ]; then
|
||||
echo "Configure container to use a virtual framebuffer as the X server"
|
||||
# Disable supervisord script
|
||||
sed -i 's|^autostart.*=.*$|autostart=false|' /etc/supervisor/conf.d/xorg.conf
|
||||
else
|
||||
echo "Configure container as secondary and do not run an X server"
|
||||
# Disable supervisord script
|
||||
sed -i 's|^autostart.*=.*$|autostart=false|' /etc/supervisor/conf.d/xorg.conf
|
||||
fi
|
||||
# Make startup script executable
|
||||
chmod +x /usr/bin/start-xorg.sh
|
||||
}
|
||||
|
||||
|
||||
if [[ -z ${nvidia_gpu_hex_id} ]]; then
|
||||
echo "**** Generate default xorg.conf ****";
|
||||
configure_x_server
|
||||
else
|
||||
echo "**** Generate NVIDIA xorg.conf ****";
|
||||
configure_x_server
|
||||
configure_nvidia_x_server
|
||||
fi
|
||||
|
||||
echo "DONE"
|
||||
Reference in New Issue
Block a user