-
-
Notifications
You must be signed in to change notification settings - Fork 65
/
create_modules_dkms.sh
executable file
·89 lines (69 loc) · 2.44 KB
/
create_modules_dkms.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/bin/bash
PKG_BUILD=84
PKG_VERSION=1.0.$PKG_BUILD
function throw {
echo $1
exit 1
}
function run {
echo -n "$1 ... "
shift
ERR=`$* 2>&1` && RC=$? || RC=$?
if [ $RC -eq 0 ]; then
echo -e "\033[0;32mDone\033[0;0m"
else
echo -e "\033[1;91mFAILED\033[0;0m"
echo "$ERR"
exit 1
fi
}
CURRENT_DIR=$(pwd)
WORK_DIR=$(mktemp -d)
TARGET_DIR=$WORK_DIR/pivccu-modules-dkms-$PKG_VERSION
function create_package_dir {
mkdir -p $TARGET_DIR/usr/src/pivccu-$PKG_VERSION || throw "Could not create temporary directory"
}
function create_dkms_config {
DKMS_CONF_FILE=$TARGET_DIR/usr/src/pivccu-$PKG_VERSION/dkms.conf
cat <<EOF >> $DKMS_CONF_FILE
PACKAGE_NAME="pivccu"
PACKAGE_VERSION="$PKG_VERSION"
MAKE="make ARCH=\`uname -m | sed -e s/i.86/x86/ -e s/x86_64/x86/ -e s/arm.*/arm/ -e s/aarch64.*/arm64/\` all"
CLEAN="make ARCH=\`uname -m | sed -e s/i.86/x86/ -e s/x86_64/x86/ -e s/arm.*/arm/ -e s/aarch64.*/arm64/\` clean"
AUTOINSTALL="yes"
EOF
index=0
for file in $TARGET_DIR/usr/src/pivccu-$PKG_VERSION/*.c; do
modname=$(basename "$file" .c)
echo "BUILT_MODULE_NAME[$index]=\"$modname\"" >> $DKMS_CONF_FILE
echo "DEST_MODULE_LOCATION[$index]=\"/kernel/drivers/pivccu\"" >> $DKMS_CONF_FILE
index=$(expr $index + 1)
done
}
function copy_files {
cp $CURRENT_DIR/kernel/* $TARGET_DIR/usr/src/pivccu-$PKG_VERSION
mkdir -p $TARGET_DIR/lib/systemd/system/
cp -p $CURRENT_DIR/pivccu/dkms/*.service $TARGET_DIR/lib/systemd/system/
cp -p $CURRENT_DIR/pivccu/rtc/*.service $TARGET_DIR/lib/systemd/system/
cp -p $CURRENT_DIR/pivccu/rtc/*.timer $TARGET_DIR/lib/systemd/system/
mkdir -p $TARGET_DIR/var/lib/piVCCU/dkms
cp -p $CURRENT_DIR/pivccu/dkms/*.sh $TARGET_DIR/var/lib/piVCCU/dkms
mkdir -p $TARGET_DIR/lib/udev/rules.d
cp -p $CURRENT_DIR/pivccu/rtc/*.rules $TARGET_DIR/lib/udev/rules.d
}
function create_package_files {
mkdir -p $TARGET_DIR/DEBIAN
cp -p $CURRENT_DIR/package/pivccu-modules-dkms/* $TARGET_DIR/DEBIAN
for file in $TARGET_DIR/DEBIAN/*; do
sed -i "s/{PKG_VERSION}/$PKG_VERSION/g" $file
done
}
cd $WORK_DIR
run "Create package directory" create_package_dir
run "Copy files" copy_files
run "Create DKMS config file" create_dkms_config
run "Create package meta files" create_package_files
cd $WORK_DIR
run "Create deb package" dpkg-deb --build -Zxz pivccu-modules-dkms-$PKG_VERSION
run "Copy package to local directory" cp pivccu-modules-dkms-*.deb $CURRENT_DIR
run "Cleanup temporary files" rm -rf $WORK_DIR