diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index d0637a5344064c495683110ba1bb520153a158b4..e6b8632d3d11b7adcbd6615eb491eae537fdb396 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -74,6 +74,14 @@ linux-amd64-debian-buster-rwd: - ./prod_build/build.sh --target linux rwd -DBUILD_WITH_PYTHON_ENV=ON -DBUILD_DIAGTOOL=ON - ./prod_build/pack.sh --target linux rwd +linux-amd64-debian-buster-updtr: + extends: .build + image: demlabs/amd64/debian-buster:linuxbuilder + before_script: /opt/buildtools/prepare_environment.sh amd64-linux + script: + - ./prod_build/build.sh --target linux release -DBUILD_WITH_PYTHON_ENV=ON -DBUILD_DIAGTOOL=ON -DADD_UPDATER=ON + - ./prod_build/pack.sh --target linux release + linux-amd64-debian-buster: extends: .build image: demlabs/amd64/debian-buster:linuxbuilder @@ -108,6 +116,7 @@ publish: - linux-armhf-debian-bullseye - linux-arm64-debian-bullseye - linux-amd64-debian-buster-rwd + - linux-amd64-debian-buster-updtr - macos-amd64 script: diff --git a/CMakeLists.txt b/CMakeLists.txt index 2a1d256bb62ae82564e3a513e1b62d682b018b2c..cef610dae5336d105558bb7a2c9b93719955bb6a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -42,7 +42,7 @@ set(BUILD_WITH_GDB_DRIVER_MDBX ON) set(BUILD_WITH_ZIP OFF) option(SUPPORT_PYTHON_PLUGINS DEFAULT OFF) - +option(ADD_UPDATER OFF) #if(MACOS) # if(SUPPORT_PYTHON_PLUGINS) # set(BUILD_WITH_PYTHON_ENV ON) @@ -134,6 +134,12 @@ if(UNIX) if(CMAKE_BUILD_TYPE MATCHES RelWithDebInfo) SET( CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION}-rwd" ) endif() + + if(ADD_UPDATER) + SET( CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION}-updtr" ) + endif() + + SET( CPACK_DEBIAN_PACKAGE_MAINTAINER "Dmitriy Gerasimov <naeper@demlabs.net>" ) SET( CPACK_DEBIAN_PACKAGE_DESCRIPTION_SUMMARY "CellFrame Node software https://cellframe.net" ) SET( CPACK_DEBIAN_PACKAGE_DESCRIPTION "CellFrame Node" ) @@ -322,7 +328,13 @@ else() INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/dist/ DESTINATION ${CMAKE_INSTALL_PREFIX} FILES_MATCHING PATTERN "*" PATTERN "*") if(LINUX) - INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/dist.linux/ DESTINATION ${CMAKE_INSTALL_PREFIX} FILES_MATCHING PATTERN "*" PATTERN "*") + + + if(NOT ADD_UPDATER) + INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/dist.linux/ DESTINATION ${CMAKE_INSTALL_PREFIX} PATTERN "*cellframe-updater*" EXCLUDE ) + else() + INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/dist.linux/ DESTINATION ${CMAKE_INSTALL_PREFIX} FILES_MATCHING PATTERN "*" PATTERN "*") + endif() elseif(BSD) INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/dist.bsd/ DESTINATION ${CMAKE_INSTALL_PREFIX} FILES_MATCHING PATTERN "*" PATTERN "*") endif() diff --git a/dist.linux/share/cellframe-updater.service b/dist.linux/share/cellframe-updater.service new file mode 100644 index 0000000000000000000000000000000000000000..a1f119ebebe98718e071493ebdb9395efb5241ca --- /dev/null +++ b/dist.linux/share/cellframe-updater.service @@ -0,0 +1,14 @@ +[Unit] +Description=Cellframe Updater +After=network.target + +[Service] +WorkingDirectory=/opt/cellframe-node/ +ExecStart=/bin/bash /opt/cellframe-node/share/update.sh & + +User=root +Group=root +LogNamespace=cellframe + +[Install] +WantedBy=timers.target \ No newline at end of file diff --git a/dist.linux/share/cellframe-updater.timer b/dist.linux/share/cellframe-updater.timer new file mode 100644 index 0000000000000000000000000000000000000000..c30ec758e2b205920c0f3d237e477460341b4312 --- /dev/null +++ b/dist.linux/share/cellframe-updater.timer @@ -0,0 +1,4 @@ +[Timer] +OnCalendar=0/2:00:00 +Persistent=true +unit=cellframe-updater \ No newline at end of file diff --git a/dist.linux/share/update.sh b/dist.linux/share/update.sh new file mode 100755 index 0000000000000000000000000000000000000000..6c49a0d87382b466537ce235fe7855a904b78a6e --- /dev/null +++ b/dist.linux/share/update.sh @@ -0,0 +1,47 @@ + #! /bin/bash +set -e +STORAGE_URL=https://pub.cellframe.net/linux/cellframe-node/release-5.2/updates +REGEXP="href=\"cellframe-node-([0-9].[0-9]-[0-9]+)-updtr-amd64.deb" +INSTALLED_VERSION=$(dpkg -l | awk '$2=="cellframe-node" { print $3 }') + +echo "Cellframe-node installed: $INSTALLED_VERSION" + + +AVAILABLE_VERSIONS=() +for l in $(wget -qO- $STORAGE_URL) +do + if [[ $l =~ $REGEXP ]] + then + AVAILABLE_VERSIONS+=(${BASH_REMATCH[1]}) + fi +done + +echo "Available versions: ${AVAILABLE_VERSIONS[@]}" + +REBUILDS=() +for l in ${AVAILABLE_VERSIONS[@]} +do + REBUILDS+=($(echo $l )) +done + +MAX_REBUILD=( $( printf "%s\n" "${AVAILABLE_VERSIONS[@]}" | cut -c 5-10 | sort -nr ) ) +CURRENT_REBUILD=$(echo $INSTALLED_VERSION | grep -Po "[0-9]([0-9]+)") + +echo "Available patch: $MAX_REBUILD | Current patch: $CURRENT_REBUILD" + +if (( MAX_REBUILD > CURRENT_REBUILD )); then + echo "Need update cellframe-node to 5.2-$MAX_REBUILD..." +else + echo "No need to update cellframe-node" + exit 0 +fi + +PACKAGE_NAME="cellframe-node-5.2-$MAX_REBUILD-updtr-amd64.deb" +echo "wget" +mkdir -p /tmp/cfupd/ +wget $STORAGE_URL/$PACKAGE_NAME -O /tmp/cfupd/$PACKAGE_NAME +echo "wgot" + +service cellframe-node stop +dpkg -i /tmp/cfupd/$PACKAGE_NAME +service cellframe-node start \ No newline at end of file diff --git a/os/debian/postinst b/os/debian/postinst index 244613ab2ad1e27f5433c7af77aa5a17f73f106d..ec1c9972365bd42c71f71f0b09095acbdc8833c5 100755 --- a/os/debian/postinst +++ b/os/debian/postinst @@ -260,7 +260,23 @@ else systemctl --system enable $DAP_PREFIX/share/cellframe-diagtool.service || true fi fi - + #updater service + if [ -f "$DAP_PREFIX/share/update.sh" ]; then + if [ -e /etc/systemd/system/cellframe-updater.service ]; then + echo "[*] Restarting cellframe-updater service" + systemctl --system stop cellframe-updater >> /dev/null|| true + echo "[*] Stopped cellframe-updater" + systemctl daemon-reload || true + systemctl --system start cellframe-updater || true + echo "[*] Started cellframe-diagtool" + else + echo "[!] Installing cellframe-updater as systemd service" + ln -sf $DAP_PREFIX/share/cellframe-updater.service /etc/systemd/system/cellframe-updater.service || true + ln -sf $DAP_PREFIX/share/cellframe-updater.timer /etc/systemd/system/cellframe-updater.timer || true + systemctl --system enable $DAP_PREFIX/share/cellframe-updater.service || true + systemctl start cellframe-updater.timer + fi + fi chmod 0666 $DAP_CFG chmod 0666 $DAP_CFG_TPL chmod 0774 $DAP_PREFIX/bin/* || true diff --git a/os/debian/postrm b/os/debian/postrm index d95f25eb2b386280e41b03cb6f465a4dc2d590dd..fd929100aa9b5281136d4ba6bf4b29c8bb927e48 100755 --- a/os/debian/postrm +++ b/os/debian/postrm @@ -8,4 +8,7 @@ GROUP_RM="cellframe-node" systemctl stop cellframe-node || true systemctl disable cellframe-node || true +rm /etc/systemd/system/cellframe-updater.service || true +rm /etc/systemd/system/cellframe-updater.timer || true + #this file will be merged to dashboard postinst, be aware of this diff --git a/version.mk b/version.mk index c4ef53f4671ece99bc9dd29ab391d42c0ddbff0a..d8712e8a45597dcf7ad47199b046c8b2216507e3 100644 --- a/version.mk +++ b/version.mk @@ -1,3 +1,3 @@ VERSION_MAJOR=5 VERSION_MINOR=2 -VERSION_PATCH=131 +VERSION_PATCH=133