Merge pull request #564 from linuxserver/mods-script-with-contenv

Create with-contenv alias
This commit is contained in:
Eric Nemchik
2023-01-28 11:17:01 -06:00
committed by GitHub
2 changed files with 35 additions and 11 deletions
+1
View File
@@ -2,5 +2,6 @@
These files are used by Linuxserver build processes to handle mods in our images. Not for end-user consumption.
* **21.01.23:** - Create with-contenv alias.
* **01.01.23:** - Remove support for legacy custom script/service locations.
* **25.09.22:** - Initial Release.
+34 -11
View File
@@ -1,10 +1,12 @@
#!/usr/bin/with-contenv bash
#!/command/with-contenv bash
# shellcheck shell=bash
# Version 3
# 2022-09-25
MOD_SCRIPT_VER="3"
# Use /command/with-contenv shebang because /usr/bin/with-contenv is created in this script
# Define custom folder paths
SCRIPTS_DIR="/custom-cont-init.d"
SERVICES_DIR="/custom-services.d"
@@ -18,7 +20,7 @@ set_legacy_executable_bits() {
}
tamper_check() {
#Tamper check custom service locations
# Tamper check custom service locations
if [[ -d "${SERVICES_DIR}" ]] && [[ -n "$(find ${SERVICES_DIR}/* ! -user root 2>/dev/null)" ]]; then
echo "[custom-init] **** Some of the contents of the folder '${SERVICES_DIR}' are not owned by root, which is a security risk. ****"
echo "[custom-init] **** Please review the permissions of this folder and its contents to make sure they are owned by root, and can only be modified by root. ****"
@@ -26,7 +28,7 @@ tamper_check() {
echo "[custom-init] **** Some of the contents of the folder '${SERVICES_DIR}' have write permissions for others, which is a security risk. ****"
echo "[custom-init] **** Please review the permissions of this folder and its contents to make sure they are owned by root, and can only be modified by root. ****"
fi
#Tamper check custom script locations
# Tamper check custom script locations
if [[ -d "${SCRIPTS_DIR}" ]] && [[ -n "$(find ${SCRIPTS_DIR}/* ! -user root 2>/dev/null)" ]]; then
echo "[custom-init] **** Some of the contents of the folder '${SCRIPTS_DIR}' are not owned by root, which is a security risk. ****"
echo "[custom-init] **** Please review the permissions of this folder and its contents to make sure they are owned by root, and can only be modified by root. ****"
@@ -68,16 +70,35 @@ process_custom_services() {
fi
}
#Create our noisy chown alias to handle read-only/remote volumes
# Create our noisy chown alias to handle read-only/remote volumes
create_lsiown_alias() {
cat <<- EOF > /usr/bin/lsiown
# intentional tabs in the heredoc
cat <<-EOF >/usr/bin/lsiown
#!/bin/bash
chown "\$@" || printf '**** Permissions could not be set. This is probably because your volume mounts are remote or read-only. ****\n**** The app may not work properly and we will not provide support for it. ****\n'
EOF
chmod +x /usr/bin/lsiown
}
chmod +x /usr/bin/lsiown
# Create our with-contenv alias with umask support
create_with_contenv_alias() {
if [[ ! -f /command/with-contenv ]]; then
echo "[mod-init] /command/with-contenv not found, skipping alias creation"
return
fi
rm -rf /usr/bin/with-contenv
# intentional tabs in the heredoc
cat <<-EOF >/usr/bin/with-contenv
#!/bin/bash
if [[ -f /run/s6/container_environment/UMASK ]] &&
{ [[ "\$(pwdx \$\$)" =~ "/run/s6/legacy-services/" ]] ||
[[ "\$(pwdx \$\$)" =~ "/run/s6/services/" ]] ||
[[ "\$(pwdx \$\$)" =~ "/servicedirs/svc-" ]]; }; then
umask "\$(cat /run/s6/container_environment/UMASK)"
fi
exec /command/with-contenv "\$@"
EOF
chmod +x /usr/bin/with-contenv
}
# Check for curl
@@ -85,7 +106,7 @@ curl_check() {
if [[ ! -f /usr/bin/curl ]] || [[ ! -f /usr/bin/jq ]]; then
echo "[mod-init] Curl/JQ was not found on this system for Docker mods installing"
if [[ -f /usr/bin/apt ]]; then
## Ubuntu
# Ubuntu
export DEBIAN_FRONTEND="noninteractive"
apt-get update
apt-get install --no-install-recommends -y \
@@ -217,6 +238,10 @@ run_mods() {
done
}
# Run alias creation functions
create_lsiown_alias
create_with_contenv_alias
# Main script loop
if [[ ${S6_VERBOSITY} -ge 2 ]]; then
@@ -236,5 +261,3 @@ fi
# Set executable bit on legacy cont-init and services built into the image and anything legacy unpacked by mods
set_legacy_executable_bits
create_lsiown_alias