Skip to content

Commit

Permalink
test: Use altered DNS servers
Browse files Browse the repository at this point in the history
This will be removed if test for FR guysoft/CustomPiOS#223
was successful and get merged to upstream

Signed-off-by: Stephan Wendel <[email protected]>
  • Loading branch information
KwadFan committed Aug 5, 2024
1 parent 97fa690 commit bc23b1b
Show file tree
Hide file tree
Showing 4 changed files with 459 additions and 0 deletions.
113 changes: 113 additions & 0 deletions src/modules/base/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
#!/bin/bash
###############################################################################
# All our config settings must start with BASE_

# CustomPiOS version
BASE_VERSION=1.5.0

[ -n "$BASE_PRESCRIPT" ] || BASE_PRESCRIPT=
[ -n "$BASE_POSTSCRIPT" ] || BASE_POSTSCRIPT=

#[ -n "$BASE_SCRIPT_PATH" ] || BASE_SCRIPT_PATH=$CONFIG_DIR
[ -n "$BASE_IMAGE_PATH" ] || BASE_IMAGE_PATH=${DIST_PATH}/image
[ -n "$BASE_IMAGE_RASPBIAN" ] || BASE_IMAGE_RASPBIAN=yes

# Distro
[ -n "$BASE_DISTRO" ] || BASE_DISTRO=raspbian

# Note: Set BASE_ZIP_IMG relative to the distro/src/workspace directory to pass a custom named file or an already extracted '.img'-file.
if [ "${BASE_DISTRO}" = "ubuntu" ]; then
# Default image ubuntu
[ -n "$BASE_ZIP_IMG" ] || BASE_ZIP_IMG=$(ls -t $BASE_IMAGE_PATH/ubuntu-*.xz | head -n 1)
# Default user ubuntu
[ -n "$BASE_USER" ] || BASE_USER=ubuntu

# Add base user if does not exist
[ -n "$BASE_ADD_USER" ] || BASE_ADD_USER=yes
# When adding a base user which password to use
[ -n "$BASE_USER_PASSWORD" ] || BASE_USER_PASSWORD=ubuntu
else
# Default image raspbian
if [ "${BASE_DISTRO}" = "raspios64" ]; then
[ -n "$BASE_ZIP_IMG" ] || BASE_ZIP_IMG=$(ls -t $BASE_IMAGE_PATH/*-{raspbian,raspios}-*-arm64-*.{zip,7z,xz} | head -n 1)
else
[ -n "$BASE_ZIP_IMG" ] || BASE_ZIP_IMG=$(ls -t $BASE_IMAGE_PATH/*-{raspbian,raspios}*.{zip,7z,xz} | head -n 1)
fi
# Default user raspbian
[ -n "$BASE_USER" ] || BASE_USER=pi
[ -n "$BASE_ADD_USER" ] || BASE_ADD_USER=yes
[ -n "$BASE_USER_PASSWORD" ] || BASE_USER_PASSWORD=raspberry
fi

# Release compression
[ -n "$BASE_RELEASE_COMPRESS" ] || BASE_RELEASE_COMPRESS=yes

[ -n "$BASE_RELEASE_IMG_NAME" ] || BASE_RELEASE_IMG_NAME=default
[ -n "$BASE_RELEASE_ZIP_NAME" ] || BASE_RELEASE_ZIP_NAME=default

[ -n "$BASE_WORKSPACE" ] || BASE_WORKSPACE=${DIST_PATH}/workspace$WORKSPACE_POSTFIX
# [ -n "$BASE_CHROOT_SCRIPT_PATH" ] || BASE_CHROOT_SCRIPT_PATH=$BASE_SCRIPT_PATH/chroot_script
[ -n "$BASE_MOUNT_PATH" ] || BASE_MOUNT_PATH=$BASE_WORKSPACE/mount

[ -n "${BASE_BOOT_MOUNT_PATH}" ] || BASE_BOOT_MOUNT_PATH=boot/firmware

# The root partition of the image filesystem, 2 for raspbian
[ -n "$BASE_ROOT_PARTITION" ] || BASE_ROOT_PARTITION=2

# if set will enlarge root partition prior to build by provided size in MB
[ -n "$BASE_IMAGE_ENLARGEROOT" ] || BASE_IMAGE_ENLARGEROOT=200

# if set will resize root partition on image after build to minimum size +
# provided size in MB
[ -n "$BASE_IMAGE_RESIZEROOT" ] || BASE_IMAGE_RESIZEROOT=200

# a local directory on the build server to bind mount under /var/cache/apt
[ -n "$BASE_APT_CACHE" ] || BASE_APT_CACHE=$BASE_WORKSPACE/aptcache

# a host:port combo for a apt-proxy (such as apt-cacher-ng) to use
[ -n "$BASE_APT_PROXY" ] || BASE_APT_PROXY=

[ -n "$BASE_APT_MIRROR" ] || BASE_APT_MIRROR=

# an alternative pypi index url to use, e.g. a proxy such as devpi
[ -n "$BASE_PYPI_INDEX" ] || BASE_PYPI_INDEX=

[ -n "$BASE_OVERRIDE_HOSTNAME" ] || BASE_OVERRIDE_HOSTNAME=${DIST_NAME,,}

# Alter DNS servers used during build (space seperated)
# e.g. BASE_USE_ALT_DNS="1.1.1.1 8.8.8.8"
[ -n "$BASE_USE_ALT_DNS" ] || BASE_USE_ALT_DNS=

# a git mirror to use for git clones instead of original remotes
[ -n "$BASE_BUILD_REPO_MIRROR" ] || BASE_BUILD_REPO_MIRROR=

# Enable ssh daemon
[ -n "$BASE_SSH_ENABLE" ] || BASE_SSH_ENABLE=yes

#Store the commit used for CustomPiOS
[ -n "$BASE_COMMIT" ] || BASE_COMMIT=$(git -C "${CUSTOM_PI_OS_PATH}" rev-parse HEAD) || true

#Memory split
[ -n "$BASE_CONFIG_MEMSPLIT" ] || BASE_CONFIG_MEMSPLIT=default

#Timezone
[ -n "$BASE_CONFIG_TIMEZONE" ] || BASE_CONFIG_TIMEZONE=default

#Locale
[ -n "$BASE_CONFIG_LOCALE" ] || BASE_CONFIG_LOCALE=default

#Keyboard
[ -n "$BASE_CONFIG_KEYBOARD" ] || BASE_CONFIG_KEYBOARD=default

# Arch for now either armv7l, arm64 or aarch64
[ -n "$BASE_ARCH" ] || BASE_ARCH=armv7l

# If you want your variant not to have the name appending, enable this
[ -n "$BASE_IGNORE_VARIANT_NAME" ] || BASE_IGNORE_VARIANT_NAME=no

# Enable uart console on boot
[ -n "$BASE_ENABLE_UART" ] || BASE_ENABLE_UART=no


# Clean apt-cache after all the work is done
: ${BASE_APT_CLEAN:=yes}
45 changes: 45 additions & 0 deletions src/modules/base/end_chroot_script
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/env bash
# Base script
# Basic and manditory settings for the base of a CustomPiOS build
# Written by Guy Sheffer <guysoft at gmail dot com>
# GPL V3
########
set -ex

if [ -n "$BASE_APT_PROXY" ]
then
rm -r /etc/apt/apt.conf.d/02octopi_build_proxy
fi

if [ -n "${BASE_APT_MIRROR}" ]; then
sed -i '1d' /etc/apt/sources.list
fi

if [ -n "$BASE_PYPI_INDEX" ]
then
rm -r /root/.pip
rm -r /root/.pydistutils.cfg
rm -r /home/"${BASE_USER}"/.pip/pip.conf
rm -r /home/"${BASE_USER}"/.pydistutils.cfg
fi

#reach device by name
if [ -f /etc/hostname ]; then
read FILE_HOST_NAME < /etc/hostname
FILE_HOST_NAME=${FILE_HOST_NAME//$'\n'/}
else
FILE_HOST_NAME=raspberrypi
fi

echo "$BASE_OVERRIDE_HOSTNAME" > /etc/hostname
sed -i -e "s@${FILE_HOST_NAME}@$BASE_OVERRIDE_HOSTNAME@g" /etc/hosts

if [ "${BASE_DISTRO}" == "ubuntu" ];then
echo "127.0.0.1 ${BASE_OVERRIDE_HOSTNAME}" > /etc/hosts
fi

#cleanup
if [ "${BASE_APT_CLEAN}" = "yes" ]; then
apt-get clean
fi
apt-get autoremove -y
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
# Start, reconfigure and stop wpa_supplicant per wireless interface.
# This is needed because wpa_supplicant lacks hotplugging of any kind
# and the user should not be expected to have to wire it into their system
# if the base system doesn't do this itself.

if [ -z "$wpa_supplicant_conf" ]; then
for x in \
/etc/wpa_supplicant/wpa_supplicant-"$interface".conf \
/etc/wpa_supplicant/wpa_supplicant.conf \
/etc/wpa_supplicant-"$interface".conf \
/etc/wpa_supplicant.conf \
; do
if [ -s "$x" ]; then
wpa_supplicant_conf="$x"
break
fi
done
fi
: ${wpa_supplicant_conf:=/etc/wpa_supplicant.conf}

wpa_supplicant_ctrldir()
{
dir=$(key_get_value "[[:space:]]*ctrl_interface=" \
"$wpa_supplicant_conf")
dir=$(trim "$dir")
case "$dir" in
DIR=*)
dir=${dir##DIR=}
dir=${dir%%[[:space:]]GROUP=*}
dir=$(trim "$dir")
;;
esac
printf %s "$dir"
}

wpa_supplicant_start()
{
# If the carrier is up, don't bother checking anything
[ "$ifcarrier" = "up" ] && return 0

# Pre flight checks
if [ ! -s "$wpa_supplicant_conf" ]; then
syslog warn \
"$wpa_supplicant_conf does not exist"
syslog warn "not interacting with wpa_supplicant(8)"
return 1
fi
dir=$(wpa_supplicant_ctrldir)
if [ -z "$dir" ]; then
syslog warn \
"ctrl_interface not defined in $wpa_supplicant_conf"
syslog warn "not interacting with wpa_supplicant(8)"
return 1
fi

wpa_cli -p "$dir" -i "$interface" status >/dev/null 2>&1 && return 0
syslog info "starting wpa_supplicant"
wpa_supplicant_driver="${wpa_supplicant_driver:-nl80211,wext}"
driver=${wpa_supplicant_driver:+-D}$wpa_supplicant_driver
err=$(wpa_supplicant -B -c"$wpa_supplicant_conf" -i"$interface" \
"$driver" 2>&1)
errn=$?
if [ $errn != 0 ]; then
syslog err "failed to start wpa_supplicant"
syslog err "$err"
fi
return $errn
}

wpa_supplicant_reconfigure()
{
dir=$(wpa_supplicant_ctrldir)
[ -z "$dir" ] && return 1
if ! wpa_cli -p "$dir" -i "$interface" status >/dev/null 2>&1; then
wpa_supplicant_start
return $?
fi
syslog info "reconfiguring wpa_supplicant"
err=$(wpa_cli -p "$dir" -i "$interface" reconfigure 2>&1)
errn=$?
if [ $errn != 0 ]; then
syslog err "failed to reconfigure wpa_supplicant"
syslog err "$err"
fi
return $errn
}

wpa_supplicant_stop()
{
dir=$(wpa_supplicant_ctrldir)
[ -z "$dir" ] && return 1
wpa_cli -p "$dir" -i "$interface" status >/dev/null 2>&1 || return 0
syslog info "stopping wpa_supplicant"
err=$(wpa_cli -i"$interface" terminate 2>&1)
errn=$?
if [ $errn != 0 ]; then
syslog err "failed to start wpa_supplicant"
syslog err "$err"
fi
return $errn
}

if [ "$ifwireless" = "1" ] && \
type wpa_supplicant >/dev/null 2>&1 && \
type wpa_cli >/dev/null 2>&1
then
case "$reason" in
PREINIT) wpa_supplicant_start;;
RECONFIGURE) wpa_supplicant_reconfigure;;
DEPARTED) wpa_supplicant_stop;;
esac
fi
Loading

0 comments on commit bc23b1b

Please sign in to comment.