Skip to content

Commit

Permalink
Merge pull request #563 from dOpensource/bug/debian12-fixes-vultr-test
Browse files Browse the repository at this point in the history
Bug/debian12 fixes vultr test
  • Loading branch information
mackhendricks authored Apr 4, 2024
2 parents 89da112 + aa2789a commit 14eff0d
Show file tree
Hide file tree
Showing 3 changed files with 152 additions and 2 deletions.
131 changes: 131 additions & 0 deletions dnsmasq/debian/12.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
#!/usr/bin/env bash

# Debug this script if in debug mode
(( $DEBUG == 1 )) && set -x

# Import dsip_lib utility / shared functions if not already
if [[ "$DSIP_LIB_IMPORTED" != "1" ]]; then
. ${DSIP_PROJECT_DIR}/dsiprouter/dsip_lib.sh
fi

function install() {

# mask the service before running package manager to avoid faulty startup errors
systemctl mask dnsmasq.service

apt-get install -y dnsmasq

if (( $? != 0 )); then
printerr 'Failed installing new dns stack'
return 1
fi

# make sure we unmask before configuring the service ourselves
systemctl unmask dnsmasq.service

# configure dnsmasq systemd service
#cp -f ${DSIP_PROJECT_DIR}/dnsmasq/systemd/dnsmasq-v1.service /lib/systemd/system/dnsmasq.service
#chmod 644 /lib/systemd/system/dnsmasq.service
#systemctl daemon-reload
systemctl enable dnsmasq

# backup the original resolv.conf
[[ ! -e "${BACKUPS_DIR}/etc/resolv.conf" ]] && {
mkdir -p ${BACKUPS_DIR}/etc/
cp -df /etc/resolv.conf ${BACKUPS_DIR}/etc/resolv.conf
}

# make dnsmasq the DNS provider
rm -f /etc/resolv.conf
cp -f ${DSIP_PROJECT_DIR}/dnsmasq/configs/resolv.conf /etc/resolv.conf

# for some reason the defaults on systemd-networkd are not followed after changing the above
# so we give the interfaces explicit rules to make sure DNS servers are resolved via DHCP on the ifaces
# see systemd.network and systemd.networkd for more information
mkdir -p /etc/systemd/network/
cp -f ${DSIP_PROJECT_DIR}/dnsmasq/configs/systemd.network /etc/systemd/network/99-dsiprouter.network

# restart systemd network services
systemctl restart systemd-networkd
if (( $? != 0 )); then
printerr 'failed loading new systemd network configurations..'
printwarn 'reverting network changes'
rm -f /etc/systemd/network/99-dsiprouter.network
systemctl restart systemd-networkd
return 1
fi

# Reload resolvconf if it's installed
systemctl is-active resolvconf
if (( $? != 0 )); then
printwarn 'resolvconf is not installed'

else
printwarn 'resolvconf is installed'
# copy the DNS servers from the orig /etc/resolv.conf
#cp -df ${BACKUPS_DIR}/etc/resolv.conf /run/resolvconf/resolv.conf
# tell dnsmasq to grab dns servers from resolvconf
#export DNSMASQ_RESOLV_FILE="/run/resolvconf/resolv.conf"
fi

# Reload systemctl-resolved if it's installed
systemctl is-active systemctl-resolved
if (( $? != 0 )); then
printwarn 'systemctl-resolved is not installed'
else
# we only need the dhcp dynamic dns servers feature of systemd-resolved, everything else is turned off
mkdir -p /etc/systemd/resolved.conf.d/
cp -f ${DSIP_PROJECT_DIR}/dnsmasq/configs/systemdresolved.conf /etc/systemd/resolved.conf.d/99-dsiprouter.conf
systemctl restart systemctl-resolved
# tell dnsmasq to grab dns servers from systemd-resolved
export DNSMASQ_RESOLV_FILE="/run/systemd/resolve/resolv.conf"
fi


envsubst <${DSIP_PROJECT_DIR}/dnsmasq/configs/dnsmasq_sh.conf >/etc/dnsmasq.conf

return 0
}

function uninstall() {

# stop and disable services
systemctl disable dnsmasq
systemctl stop dnsmasq

# uninstall packages
apt-get remove -y --purge dnsmasq

# remove our systemd-resolved configurations
rm -f /etc/systemd/resolved.conf.d/99-dsiprouter.conf

# remove the systemd.network rules
rm -f /etc/systemd/network/99-dsiprouter.network

# restore original resolv.conf
cp -df ${BACKUPS_DIR}/etc/resolv.conf /etc/resolv.conf

# restart systemd.networkd with the original rules
systemctl restart systemd-networkd

# update resolv.conf / restart systemd-resolved with new configs
systemctl restart systemd-resolved

# cleanup backup files
rm -f ${BACKUPS_DIR}/etc/resolv.conf

return 0
}

case "$1" in
install)
install && exit 0 || exit 1
;;
uninstall)
uninstall && exit 0 || exit 1
;;
*)
printerr "Usage: $0 [install | uninstall]"
exit 1
;;
esac
15 changes: 14 additions & 1 deletion dsiprouter.sh
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,15 @@ function setDynamicScriptSettings() {
# if external fqdn is not routable set it to the internal fqdn instead
export EXTERNAL_FQDN="$INTERNAL_FQDN"
fi

# set the external fqdn to the internal fqdn if the hostname contain vultrusercontent
# Kamailio doesn't like hostname names with dots and LetsEncrypt can't create certs for that domain
grep vultrusercontent <<< "$EXTERNAL_FQDN" >/dev/null
if (( $? == 0 ));then
export EXTERNAL_FQDN="$INTERNAL_FQDN"

fi

# network settings pulled from env variables or from config file
elif (( $NETWORK_MODE == 1 )); then
export INTERNAL_IP_ADDR=${INTERNAL_IP_ADDR:-$(getConfigAttrib 'INTERNAL_IP_ADDR' ${DSIP_CONFIG_FILE})}
Expand Down Expand Up @@ -2114,7 +2123,11 @@ function installDnsmasq() {
useradd --system --user-group --shell /bin/false --comment "DNSmasq DNS Resolver" dnsmasq &>/dev/null

printdbg "Attempting to install DNSmasq..."
${DSIP_PROJECT_DIR}/dnsmasq/${DISTRO}/install.sh install
if (( ${DISTRO_VER} == 12 )); then
${DSIP_PROJECT_DIR}/dnsmasq/${DISTRO}/${DISTRO_VER}.sh install
else
${DSIP_PROJECT_DIR}/dnsmasq/${DISTRO}/install.sh install
fi

if (( $? != 0 )); then
printerr "DNSmasq install failed - OS install script failure"
Expand Down
8 changes: 7 additions & 1 deletion kamailio/debian/12.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ function install() {
local KAM_SOURCES_LIST="/etc/apt/sources.list.d/kamailio.list"
local KAM_PREFS_CONF="/etc/apt/preferences.d/kamailio.pref"
local NPROC=$(nproc)

# Remove ufw if installed
apt-get remove -y ufw

# Install Dependencies
apt-get install -y curl wget sed gawk vim perl uuid-dev libssl-dev logrotate rsyslog \
Expand Down Expand Up @@ -60,6 +63,7 @@ EOF
# Update repo sources cache
apt-get update -y


# Install Kamailio packages
apt-get install -y kamailio kamailio-mysql-modules kamailio-extra-modules \
kamailio-tls-modules kamailio-websocket-modules kamailio-presence-modules \
Expand Down Expand Up @@ -124,16 +128,18 @@ EOF

# Enable and start firewalld if not already running
systemctl enable firewalld
systemctl start firewalld

# Setup firewall rules
firewall-cmd --zone=public --add-port=${KAM_SIP_PORT}/udp --permanent
firewall-cmd --zone=public --add-port=${KAM_SIP_PORT}/tcp --permanent
firewall-cmd --zone=public --add-port=${KAM_SIPS_PORT}/tcp --permanent
firewall-cmd --zone=public --add-port=${KAM_WSS_PORT}/tcp --permanent
firewall-cmd --zone=public --add-port=${KAM_DMQ_PORT}/udp --permanent
firewall-cmd --zone=public --add-port=22/tcp --permanent
firewall-cmd --reload

systemctl start firewalld

# Configure Kamailio systemd service
cp -f ${DSIP_PROJECT_DIR}/kamailio/systemd/kamailio-v2.service /lib/systemd/system/kamailio.service
chmod 644 /lib/systemd/system/kamailio.service
Expand Down

0 comments on commit 14eff0d

Please sign in to comment.