|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Set variables |
| 4 | +APP_VERSION="0.0.19-dev" |
| 5 | +APP_NAME="FileSyncApp" |
| 6 | +APP_DIR="/opt/$APP_NAME" |
| 7 | +SERVICE_FILE="$APP_NAME.service" |
| 8 | +SW_DESCRIPTION="sw-description" |
| 9 | +OUTPUT_DIR="FileSyncAppPackage" |
| 10 | +PUBLISH_DIR="publish" |
| 11 | + |
| 12 | +dotnet publish -o $PUBLISH_DIR -c Release -p:PublishSingleFile=true -p:PublishTrimmed=false -p:Version=$APP_VERSION -r linux-x64 --self-contained ./FileSyncApp.csproj |
| 13 | +# Create directory structure |
| 14 | + |
| 15 | +mkdir -p ${OUTPUT_DIR} |
| 16 | +mount -t ramfs ramfs ${OUTPUT_DIR} |
| 17 | + |
| 18 | +# Create systemd service file |
| 19 | +cat <<EOL > ${OUTPUT_DIR}/${SERVICE_FILE} |
| 20 | +[Unit] |
| 21 | +Description=FileSyncApp - Datei-Synchronisation |
| 22 | +After=network.target |
| 23 | +
|
| 24 | +[Service] |
| 25 | +ExecStart=$APP_DIR/$APP_NAME |
| 26 | +WorkingDirectory=$APP_DIR |
| 27 | +Restart=on-failure |
| 28 | +User=root |
| 29 | +Environment=DOTNET_EnableDiagnostics=0 |
| 30 | +
|
| 31 | +[Install] |
| 32 | +WantedBy=multi-user.target |
| 33 | +EOL |
| 34 | + |
| 35 | +# Create sw-description filex |
| 36 | +cat <<EOL > ${OUTPUT_DIR}/${SW_DESCRIPTION} |
| 37 | +software = |
| 38 | +{ |
| 39 | + version = "$APP_VERSION"; |
| 40 | + description = "FileSyncApp Deployment"; |
| 41 | + bootloader_transaction_marker = false; |
| 42 | + bootloader_state_marker = false; |
| 43 | + hardware-compatibility: [ "#RE:.*" ]; |
| 44 | + files: ( |
| 45 | + { |
| 46 | + filename = "$APP_NAME"; |
| 47 | + path = "$APP_DIR/$APP_NAME"; |
| 48 | + }, |
| 49 | + { |
| 50 | + filename = "$APP_NAME.service"; |
| 51 | + path = "/etc/systemd/system/$SERVICE_FILE"; |
| 52 | + } |
| 53 | + ); |
| 54 | + scripts: ( |
| 55 | + { |
| 56 | + filename = "update.sh"; |
| 57 | + type = "shellscript"; |
| 58 | + } |
| 59 | + ); |
| 60 | + preinstall = " || true && mkdir -p /opt/$APP_NAME"; |
| 61 | + postinstall = "systemctl daemon-reexec && systemctl daemon-reload && systemctl enable --now $APP_NAME.service"; |
| 62 | +}; |
| 63 | +EOL |
| 64 | +cat <<\EOFUPDATE > ${OUTPUT_DIR}/update.sh |
| 65 | +#!/bin/sh |
| 66 | +
|
| 67 | +if [ $# -lt 1 ]; then |
| 68 | + exit 0; |
| 69 | +fi |
| 70 | +if [ $1 = "preinst" ]; then |
| 71 | + systemctl stop FileSyncApp.service |
| 72 | + mkdir -p /opt/FileSyncApp |
| 73 | + echo "PREINST -> directory created" |
| 74 | +fi |
| 75 | +
|
| 76 | +if [ $1 = "postinst" ]; then |
| 77 | + chmod +x /opt/FileSyncApp/FileSyncApp |
| 78 | + systemctl daemon-reexec |
| 79 | + systemctl daemon-reload |
| 80 | + systemctl enable --now FileSyncApp.service |
| 81 | +fi |
| 82 | +
|
| 83 | +EOFUPDATE |
| 84 | + |
| 85 | +# Copy the compiled binary to the package directory |
| 86 | +cp ${PUBLISH_DIR}/$APP_NAME ${OUTPUT_DIR} |
| 87 | + |
| 88 | +# Create CPIO archive |
| 89 | +cd $OUTPUT_DIR |
| 90 | +cpio -H crc -o < <(printf '%s\n' sw-description; find . ! -name sw-description -type f | sort) > ../$APP_NAME-$APP_VERSION.swu |
| 91 | +cd .. |
| 92 | +umount ${OUTPUT_DIR} |
| 93 | +rm -r ${OUTPUT_DIR} |
| 94 | + |
| 95 | +echo "SWUpdate package created: $APP_NAME-$APP_VERSION.swu" |
0 commit comments