-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenswu.sh
More file actions
95 lines (82 loc) · 2.34 KB
/
genswu.sh
File metadata and controls
95 lines (82 loc) · 2.34 KB
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
89
90
91
92
93
94
95
#!/bin/bash
# Set variables
APP_VERSION="0.0.19-dev"
APP_NAME="FileSyncApp"
APP_DIR="/opt/$APP_NAME"
SERVICE_FILE="$APP_NAME.service"
SW_DESCRIPTION="sw-description"
OUTPUT_DIR="FileSyncAppPackage"
PUBLISH_DIR="publish"
dotnet publish -o $PUBLISH_DIR -c Release -p:PublishSingleFile=true -p:PublishTrimmed=false -p:Version=$APP_VERSION -r linux-x64 --self-contained ./FileSyncApp.csproj
# Create directory structure
mkdir -p ${OUTPUT_DIR}
mount -t ramfs ramfs ${OUTPUT_DIR}
# Create systemd service file
cat <<EOL > ${OUTPUT_DIR}/${SERVICE_FILE}
[Unit]
Description=FileSyncApp - Datei-Synchronisation
After=network.target
[Service]
ExecStart=$APP_DIR/$APP_NAME
WorkingDirectory=$APP_DIR
Restart=on-failure
User=root
Environment=DOTNET_EnableDiagnostics=0
[Install]
WantedBy=multi-user.target
EOL
# Create sw-description filex
cat <<EOL > ${OUTPUT_DIR}/${SW_DESCRIPTION}
software =
{
version = "$APP_VERSION";
description = "FileSyncApp Deployment";
bootloader_transaction_marker = false;
bootloader_state_marker = false;
hardware-compatibility: [ "#RE:.*" ];
files: (
{
filename = "$APP_NAME";
path = "$APP_DIR/$APP_NAME";
},
{
filename = "$APP_NAME.service";
path = "/etc/systemd/system/$SERVICE_FILE";
}
);
scripts: (
{
filename = "update.sh";
type = "shellscript";
}
);
preinstall = " || true && mkdir -p /opt/$APP_NAME";
postinstall = "systemctl daemon-reexec && systemctl daemon-reload && systemctl enable --now $APP_NAME.service";
};
EOL
cat <<\EOFUPDATE > ${OUTPUT_DIR}/update.sh
#!/bin/sh
if [ $# -lt 1 ]; then
exit 0;
fi
if [ $1 = "preinst" ]; then
systemctl stop FileSyncApp.service
mkdir -p /opt/FileSyncApp
echo "PREINST -> directory created"
fi
if [ $1 = "postinst" ]; then
chmod +x /opt/FileSyncApp/FileSyncApp
systemctl daemon-reexec
systemctl daemon-reload
systemctl enable --now FileSyncApp.service
fi
EOFUPDATE
# Copy the compiled binary to the package directory
cp ${PUBLISH_DIR}/$APP_NAME ${OUTPUT_DIR}
# Create CPIO archive
cd $OUTPUT_DIR
cpio -H crc -o < <(printf '%s\n' sw-description; find . ! -name sw-description -type f | sort) > ../$APP_NAME-$APP_VERSION.swu
cd ..
umount ${OUTPUT_DIR}
rm -r ${OUTPUT_DIR}
echo "SWUpdate package created: $APP_NAME-$APP_VERSION.swu"