Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build_{rust,dpkg}.sh - scripts rework fixes/simplifications #505

Open
wants to merge 9 commits into
base: develop
Choose a base branch
from
138 changes: 69 additions & 69 deletions src/build_dpkg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# This is all GPL2.

BUILD_DATE=`date +%Y%m%d%H%M`
if [ $1 = "--nostamp" ]
if [[ "$1" == "--nostamp" ]]
then
BUILD_DATE=""
fi
Expand All @@ -17,10 +17,10 @@ PKGVERSION+=$VERSION
DPKG_DIR=dist/$PKGVERSION-1_amd64
APT_DEPENDENCIES="python3-pip, nano, graphviz, curl"
DEBIAN_DIR=$DPKG_DIR/DEBIAN
LQOS_DIR=$DPKG_DIR/opt/libreqos/src
LQOS_DIR=`pwd`/$DPKG_DIR/opt/libreqos/src
ETC_DIR=$DPKG_DIR/etc
MOTD_DIR=$DPKG_DIR/etc/update-motd.d
LQOS_FILES="graphInfluxDB.py influxDBdashboardTemplate.json integrationCommon.py integrationPowercode.py integrationRestHttp.py integrationSonar.py integrationSplynx.py integrationUISP.py integrationSonar.py LibreQoS.py lqos.example lqTools.py mikrotikFindIPv6.py network.example.json pythonCheck.py README.md scheduler.py ShapedDevices.example.csv lqos.example ../requirements.txt"
LQOS_FILES="graphInfluxDB.py influxDBdashboardTemplate.json integrationCommon.py integrationPowercode.py integrationRestHttp.py integrationSonar.py integrationSplynx.py integrationUISP.py LibreQoS.py lqos.example lqTools.py mikrotikFindIPv6.py network.example.json pythonCheck.py README.md scheduler.py ShapedDevices.example.csv ../requirements.txt"
LQOS_BIN_FILES="lqos_scheduler.service.example lqosd.service.example"
RUSTPROGS="lqosd lqtop xdp_iphash_to_cpu_cmdline xdp_pping lqusers lqos_setup lqos_map_perf uisp_integration lqos_support_tool"

Expand All @@ -35,87 +35,87 @@ rm -rf dist
# The Debian Packaging Bit

# Create the basic directory structure
mkdir -p $DEBIAN_DIR

# Build the chroot directory structure
mkdir -p $LQOS_DIR
mkdir -p $LQOS_DIR/bin/static2
mkdir -p $ETC_DIR
mkdir -p $MOTD_DIR
mkdir -p $DEBIAN_DIR $LQOS_DIR/bin/static2 $ETC_DIR $MOTD_DIR

# Create the Debian control file
pushd $DEBIAN_DIR > /dev/null || exit
touch control
echo "Package: $PACKAGE" >> control
echo "Version: $VERSION" >> control
echo "Architecture: amd64" >> control
echo "Maintainer: Herbert Wolverson <[email protected]>" >> control
echo "Description: CAKE-based traffic shaping for ISPs" >> control
echo "Depends: $APT_DEPENDENCIES" >> control
cat << EOF > control
Package: $PACKAGE
Version: $VERSION
Architecture: amd64
Maintainer: Herbert Wolverson <[email protected]>
Description: CAKE-based traffic shaping for ISPs
Depends: $APT_DEPENDENCIES
EOF
popd > /dev/null || exit

# Create the post-installation file
pushd $DEBIAN_DIR > /dev/null || exit
touch postinst
echo "#!/bin/bash" >> postinst
echo "# Install Python Dependencies" >> postinst
echo "pushd /opt/libreqos" >> postinst

cat << 'EOF' > postinst
#!/bin/bash
# Install Python Dependencies
pushd /opt/libreqos > /dev/null || exit

# - Setup Python dependencies as a post-install task
echo "PIP_BREAK_SYSTEM_PACKAGES=1 python3 -m pip install -r src/requirements.txt" >> postinst
echo "PIP_BREAK_SYSTEM_PACKAGES=1 sudo python3 -m pip install -r src/requirements.txt" >> postinst

# - Run lqsetup
echo "/opt/libreqos/src/bin/lqos_setup" >> postinst
/opt/libreqos/src/bin/lqos_setup

# - Setup the services
echo "cp /opt/libreqos/src/bin/lqosd.service.example /etc/systemd/system/lqosd.service" >> postinst
echo "cp /opt/libreqos/src/bin/lqos_scheduler.service.example /etc/systemd/system/lqos_scheduler.service" >> postinst
echo "/bin/systemctl daemon-reload" >> postinst
echo "/bin/systemctl stop lqos_node_manager" >> postinst # In case it's running from a previous release
echo "/bin/systemctl disable lqos_node_manager" >> postinst # In case it's running from a previous release
echo "/bin/systemctl enable lqosd lqos_scheduler" >> postinst
echo "/bin/systemctl start lqosd" >> postinst
echo "/bin/systemctl start lqos_scheduler" >> postinst
echo "popd" >> postinst
cp /opt/libreqos/src/bin/lqosd.service.example /etc/systemd/system/lqosd.service
cp /opt/libreqos/src/bin/lqos_scheduler.service.example /etc/systemd/system/lqos_scheduler.service

service_exists() {
local n=$1
if [[ $(systemctl list-units --all -t service --full --no-legend "$n.service" | sed 's/^\s*//g' | cut -f1 -d' ') == $n.service ]]; then
return 0
else
return 1
fi
}

if service_exists lqos_node_manager; then
/bin/systemctl disable --now lqos_node_manager # In case it's running from a previous release
rm -f /etc/systemd/system/lqosd_node_manager.service # In case it's running from a previous release
fi

/bin/systemctl daemon-reload
/bin/systemctl enable --now lqosd lqos_scheduler
popd > /dev/null || exit

# Attempting to fixup versioning issues with libpython.
# This requires that you already have LibreQoS installed.
LINKED_PYTHON=$(ldd /opt/libreqos/src/bin/lqosd | grep libpython | sed -e '/^[^\t]/ d' | sed -e 's/\t//' | sed -e 's/.*=..//' | sed -e 's/ (0.*)//')
echo "if ! test -f $LINKED_PYTHON; then" >> postinst
echo " if test -f /lib/x86_64-linux-gnu/libpython3.12.so.1.0; then" >> postinst
echo " ln -s /lib/x86_64-linux-gnu/libpython3.12.so.1.0 $LINKED_PYTHON" >> postinst
echo " fi" >> postinst
echo " if test -f /lib/x86_64-linux-gnu/libpython3.11.so.1.0; then" >> postinst
echo " ln -s /lib/x86_64-linux-gnu/libpython3.11.so.1.0 $LINKED_PYTHON" >> postinst
echo " fi" >> postinst
echo "fi" >> postinst
# End of symlink insanity
chmod a+x postinst
if ! test -f $LINKED_PYTHON; then
if test -f /lib/x86_64-linux-gnu/libpython3.12.so.1.0; then
ln -s /lib/x86_64-linux-gnu/libpython3.12.so.1.0 $LINKED_PYTHON
fi
if test -f /lib/x86_64-linux-gnu/libpython3.11.so.1.0; then
ln -s /lib/x86_64-linux-gnu/libpython3.11.so.1.0 $LINKED_PYTHON
fi
fi
EOF

# Uninstall Script
touch postrm
echo "#!/bin/bash" >> postrm
echo "/bin/systemctl stop lqosd" >> postrm
echo "/bin/systemctl stop lqos_scheduler" >> postrm
echo "/bin/systemctl disable lqosd lqos_scheduler" >> postrm
chmod a+x postrm
popd > /dev/null || exit
cat << EOF > postrm
#!/bin/bash
/bin/systemctl disable --now lqosd lqos_scheduler
/bin/systemctl daemon-reload
rm -f /etc/systemd/system/{lqosd,lqos_scheduler}.service
EOF

# Create the cleanup file
pushd $DEBIAN_DIR > /dev/null || exit
touch postrm
echo "#!/bin/bash" >> postrm
chmod a+x postrm
chmod a+x postrm postinst
popd > /dev/null || exit

# Copy files into the LibreQoS directory
for file in $LQOS_FILES
do
cp $file $LQOS_DIR
done
cp $LQOS_FILES $LQOS_DIR

# Copy files into the LibreQoS/bin directory
for file in $LQOS_BIN_FILES
do
cp bin/$file $LQOS_DIR/bin
done
cp bin/*service.example $LQOS_DIR/bin

####################################################
# Build the Rust programs
Expand All @@ -127,6 +127,7 @@ popd > /dev/null || exit
# Copy newly built Rust files
# - The Python integration Library
cp rust/target/release/liblqos_python.so $LQOS_DIR

# - The main executables
for prog in $RUSTPROGS
do
Expand All @@ -135,21 +136,20 @@ done

# Compile the website
pushd rust/lqosd > /dev/null || exit
./copy_files.sh
./copy_files.sh $LQOS_DIR/bin/static2
popd || exit
cp -r bin/static2/* $LQOS_DIR/bin/static2

####################################################
# Add Message of the Day
pushd $MOTD_DIR > /dev/null || exit
echo "#!/bin/bash" > 99-libreqos
echo "MY_IP=\'hostname -I | cut -d' ' -f1\'" >> 99-libreqos
echo "echo \"\"" >> 99-libreqos
echo "echo \"LibreQoS Traffic Shaper is installed on this machine.\"" >> 99-libreqos
echo "echo \"Point a browser at http://\$MY_IP:9123/ to manage it.\"" >> 99-libreqos
echo "echo \"\"" >> 99-libreqos
cat << 'EOF' > 99-libreqos
#!/bin/bash
MY_IP=`hostname -I | cut -d' ' -f1`
echo -e "\nLibreQoS Traffic Shaper is installed on this machine.
\nPoint a browser at http://$MY_IP:9123/ to manage it.\n"
EOF
chmod a+x 99-libreqos
popd || exit
popd > /dev/null || exit

####################################################
# Assemble the package
Expand Down
20 changes: 11 additions & 9 deletions src/build_rust.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ sudo apt install python3-pip clang gcc gcc-multilib llvm libelf-dev git nano gra

if ! rustup -V &> /dev/null
then
echo "rustup is not installed."
echo "Visit https://rustup.rs and install Rust from there"
echo "Usually, you can copy the following and follow the on-screen instructions."
echo "Please don't install Rust as root."
echo "curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh"
echo -e "rustup is not installed.\
\nVisit https://rustup.rs and install Rust from there\
\nUsually, you can copy the following and follow the on-screen instructions.\
\nPlease don't install Rust as root.\
\ncurl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh"
exit 1
else
echo "rustup found."
Expand Down Expand Up @@ -65,9 +65,9 @@ popd > /dev/null

# Copy the node manager's static web content
mkdir -p bin/static2/vendor
pushd rust/lqosd > /dev/null
pushd rust/lqosd > /dev/null || exit
./copy_files.sh
popd > /dev/null
popd > /dev/null || exit

# Copy the Python library for LibreQoS.py et al.
pushd rust/lqos_python > /dev/null
Expand All @@ -88,18 +88,20 @@ service_exists() {

if service_exists lqos_node_manager; then
echo "lqos_node_manager is running as a service. It's not needed anymore. Killing it."
sudo systemctl stop lqos_node_manager
sudo systemctl disable lqos_node_manager
sudo systemctl disable --now lqos_node_manager
fi

if service_exists lqosd; then
echo "lqosd is running as a service. Restarting it. You may need to enter your sudo password."
sudo systemctl restart lqosd
fi

if service_exists lqos_scheduler; then
echo "lqos_scheduler is running as a service. Restarting it. You may need to enter your sudo password."
sudo systemctl restart lqos_scheduler
fi


echo "-----------------------------------------------------------------"
echo "Don't forget to setup /etc/lqos.conf!"
echo "Template .service files can be found in bin/"
Expand Down
5 changes: 3 additions & 2 deletions src/rust/lqosd/copy_files.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#!/bin/bash
set -e
echo "Copying static"
cp -v -R src/node_manager/static2/* ../../bin/static2/
DSTDIR=$1
cp -v -R src/node_manager/static2/* ${DSTDIR}
echo "Done"
pushd src/node_manager/js_build || exit
./esbuild.sh
popd || exit
cp -R src/node_manager/js_build/out/* ../../bin/static2/
cp -R src/node_manager/js_build/out/* ${DSTDIR}
Loading