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

Refactor build script for enhanced readability and efficiency #2667

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 59 additions & 54 deletions DMPATCH/ubuntu_build.sh
Original file line number Diff line number Diff line change
@@ -1,65 +1,70 @@
#!/bin/bash
#!/usr/bin/env bash

FTPIP=192.168.44.1
# Configurable variables
FTPIP="192.168.44.1"
FTPUSR='a:a'

rm -f dmpatch.c Makefile Makefile_IBT

for f in dmpatch.c Makefile Makefile_IBT; do
curl -s -u $FTPUSR ftp:https://$FTPIP/$f -o $f
if [ -f $f ]; then
echo "download $f OK ..."
else
echo "download $f FAILED ..."
exit 1
fi
KERNEL_SOURCE_DIR="/home/panda/linux-source-5.15.0"
BUILD_DIR="/home/panda/build"
MODULE_NAME="dm_patch"
MODULE_NAME_IBT="${MODULE_NAME}_ibt"
MODULE_FILES=("dmpatch.c" "Makefile" "Makefile_IBT")

# Function to download files
download_file() {
local file=$1
curl -s -u "$FTPUSR" "ftp:https://$FTPIP/$file" -o "$file"
if [ -f "$file" ]; then
echo "Download $file OK ..."
else
echo "Download $file FAILED ..."
exit 1
fi
}

# Function to build module
build_module() {
local module_name=$1
local makefile=$2

echo "Building $module_name.ko ..."

# Create a clean build directory
rm -rf "./$module_name"
mkdir "./$module_name"
cp *.c "$module_name/"
cp "$makefile" "$module_name/Makefile"

# Build the module
(cd "$KERNEL_SOURCE_DIR" && make modules M="$BUILD_DIR/$module_name/")
strip --strip-debug "$BUILD_DIR/$module_name/$module_name.ko"

# Copy the built module
cp "$module_name/$module_name.ko" ./
}

# Download required files
for file in "${MODULE_FILES[@]}"; do
download_file "$file"
done



# Remove previous kernel modules
rm -f *.ko

# Build modules
build_module "$MODULE_NAME" "Makefile"
build_module "$MODULE_NAME_IBT" "Makefile_IBT"

echo "build dm_patch.ko ..."
rm -rf ./aa
mkdir ./aa

cp -a *.c aa/
cp -a Makefile aa/

cd /home/panda/linux-source-5.15.0
make modules M=/home/panda/build/aa/
strip --strip-debug /home/panda/build/aa/dm_patch.ko
cd -

cp -a aa/dm_patch.ko ./


# Remove build directories
rm -rf ./$MODULE_NAME
rm -rf ./$MODULE_NAME_IBT

echo "build dm_patch_ibt.ko ..."
rm -rf ./aa
mkdir ./aa
# Upload built modules
curl -s -T "$MODULE_NAME.ko" -u "$FTPUSR" "ftp:https://$FTPIP/${MODULE_NAME}_64.ko" || exit 1
curl -s -T "$MODULE_NAME_IBT.ko" -u "$FTPUSR" "ftp:https://$FTPIP/${MODULE_NAME_IBT}_64.ko" || exit 1

cp -a *.c aa/
cp -a Makefile_IBT aa/Makefile

cd /home/panda/linux-source-5.15.0
make modules M=/home/panda/build/aa/
strip --strip-debug /home/panda/build/aa/dm_patch_ibt.ko
cd -

cp -a aa/dm_patch_ibt.ko ./

rm -rf ./aa


curl -s -T dm_patch.ko -u $FTPUSR ftp:https://$FTPIP/dm_patch_64.ko || exit 1
curl -s -T dm_patch_ibt.ko -u $FTPUSR ftp:https://$FTPIP/dm_patch_ibt_64.ko || exit 1


if [ -f ./dm_patch.ko -a -f ./dm_patch_ibt.ko ]; then
echo -e "\n\n=============== SUCCESS =============\n\n"
# Check success
if [ -f "./$MODULE_NAME.ko" -a -f "./$MODULE_NAME_IBT.ko" ]; then
echo -e "\n\n=============== SUCCESS =============\n\n"
else
echo -e "\n\n=============== FAILED ==============\n\n"
echo -e "\n\n=============== FAILED ==============\n\n"
fi