aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xbuild_repo.sh4
-rw-r--r--updater-ng-auto/Makefile158
-rw-r--r--updater-ng-auto/files/updater.config9
-rw-r--r--updater-ng-auto/files/updater.defaults24
-rwxr-xr-xutils/updater-ng-auto.sh (renamed from utils/opkg-trans-master.sh)8
5 files changed, 198 insertions, 5 deletions
diff --git a/build_repo.sh b/build_repo.sh
index 8bbe5fd..89127c9 100755
--- a/build_repo.sh
+++ b/build_repo.sh
@@ -43,8 +43,8 @@ for d in *; do
[ -d .turris-sdk ] && cp -r $d .turris-sdk/package/
done
-[ -d .omnia-sdk ] && ./utils/opkg-trans-master.sh .omnia-sdk/package/
-[ -d .turris-sdk ] && ./utils/opkg-trans-master.sh .turris-sdk/package/
+[ -d .omnia-sdk ] && ./utils/updater-ng-auto.sh .omnia-sdk/package/
+[ -d .turris-sdk ] && ./utils/updater-ng-auto.sh .turris-sdk/package/
if [ -f CONFIG ]; then
echo -e "\e[1;34mApply CONFIG\e[0m"
diff --git a/updater-ng-auto/Makefile b/updater-ng-auto/Makefile
new file mode 100644
index 0000000..04b1f6e
--- /dev/null
+++ b/updater-ng-auto/Makefile
@@ -0,0 +1,158 @@
+#
+## Copyright (C) 2016-2017 CZ.NIC z.s.p.o. (http://www.nic.cz/)
+#
+## This is free software, licensed under the GNU General Public License v2.
+# See /LICENSE for more information.
+# #
+#
+include $(TOPDIR)/rules.mk
+
+PKG_NAME:=updater-ng
+PKG_VERSION:=59.3
+PKG_RELEASE:=1
+PKG_SOURCE_PROTO:=git
+PKG_SOURCE_URL:=https://gitlab.labs.nic.cz/turris/updater.git
+PKG_SOURCE:=$(PKG_NAME).tar.gz
+PKG_SOURCE_VERSION:=v$(PKG_VERSION)
+PKG_SOURCE:=$(PKG_NAME)-$(PKG_SOURCE_VERSION).tar.gz
+PKG_SOURCE_SUBDIR:=$(PKG_NAME)
+PKG_MAINTAINER:=Michal Vaner <michal.vaner@nic.cz>
+PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)
+HOST_BUILD_DIR:=$(BUILD_DIR_HOST)/$(PKG_NAME)
+HOST_BUILD_DEPENDS:=curl/host libevent2/host lua/host
+
+include $(INCLUDE_DIR)/package.mk
+include $(INCLUDE_DIR)/host-build.mk
+
+define Package/$(PKG_NAME)
+ TITLE:=The next generation updater
+ DEPENDS:=+liblua +libevent2 +usign +libcurl +vixie-cron
+ PROVIDES:=updater
+endef
+
+define Package/$(PKG_NAME)/install
+ $(INSTALL_DIR) $(1)/usr/lib/
+ $(INSTALL_BIN) $(PKG_BUILD_DIR)/lib/libupdater.so $(1)/usr/lib/
+
+ $(INSTALL_DIR) $(1)/usr/bin
+ $(INSTALL_BIN) $(PKG_BUILD_DIR)/bin/opkg-trans $(1)/usr/bin/
+ $(INSTALL_BIN) $(PKG_BUILD_DIR)/bin/pkgupdate $(1)/usr/bin/
+ $(INSTALL_BIN) $(PKG_BUILD_DIR)/src/pkgupdate/updater.sh $(1)/usr/bin/
+ $(INSTALL_BIN) $(PKG_BUILD_DIR)/src/pkgupdate/updater-unstuck.sh $(1)/usr/bin/
+ $(INSTALL_BIN) $(PKG_BUILD_DIR)/src/pkgupdate/updater-wipe.sh $(1)/usr/bin/
+
+ $(INSTALL_DIR) $(1)/etc/updater
+ $(INSTALL_CONF) $(PKG_BUILD_DIR)/src/pkgupdate/configs/* $(1)/etc/updater
+
+ $(INSTALL_DIR) $(1)/etc/updater/hook_preupdate
+ $(INSTALL_DIR) $(1)/etc/updater/hook_postupdate
+ $(INSTALL_DIR) $(1)/etc/updater/hook_reboot_required
+ touch $(1)/etc/updater/hook_preupdate/.keep
+ touch $(1)/etc/updater/hook_postupdate/.keep
+ $(INSTALL_BIN) $(PKG_BUILD_DIR)/src/pkgupdate/hook_reboot_required/50-create-notification.sh $(1)/etc/updater/hook_reboot_required/50-create-notification.sh
+
+ $(INSTALL_DIR) $(1)/etc/config
+ $(INSTALL_CONF) ./files/updater.config $(1)/etc/config/updater
+ifneq ($(PKG_BRANCH),)
+ echo >> $(1)/etc/config/updater
+ echo "config override 'override'" >> $(1)/etc/config/updater
+ echo " option branch '$(PKG_BRANCH)'" >> $(1)/etc/config/updater
+endif
+ $(INSTALL_DIR) $(1)/etc/init.d
+ $(INSTALL_BIN) $(PKG_BUILD_DIR)/src/pkgupdate/init $(1)/etc/init.d/updater
+
+ $(INSTALL_DIR) $(1)/etc/ssl
+ $(INSTALL_DATA) $(PKG_BUILD_DIR)/updater.pem $(1)/etc/ssl/updater.pem
+
+ $(INSTALL_DIR) $(1)/etc/uci-defaults
+ $(INSTALL_BIN) ./files/updater.defaults $(1)/etc/uci-defaults/updater
+endef
+
+define Package/$(PKG_NAME)/conffiles
+/etc/updater/auto.lua
+/etc/updater/user.lua
+/etc/config/updater
+endef
+
+define Package/$(PKG_NAME)/postinst
+#!/bin/sh
+[ -n "$$IPKG_INSTROOT" ] || {
+/etc/init.d/updater enable || true
+# Run the uci-defaults now if we are installed at runtime and not flashed
+/etc/uci-defaults/updater && rm /etc/uci-defaults/updater
+}
+# Remove morphered syntax from auto.lua
+# This matches all Install and Package commands not follwed by brackets. Whole
+# line is enclosed with brackets and between strings and tables are added commas.
+AUTOTMP="$$(mktemp)"
+sed -E '/^(Install|Package) +[^(]/{
+ s/(Install|Package) +(.*)/\1(\2)/;
+ s/("|\}) ("|\{)/\1, \2/g
+ }' "$$IPKG_INSTROOT/etc/updater/auto.lua" > "$$AUTOTMP"
+# Note: Edit in place in busybox limits regexp syntax so we are using our temporally file
+mv "$$AUTOTMP" "$$IPKG_INSTROOT/etc/updater/auto.lua"
+endef
+
+define Build/Compile
+ $(MAKE_VARS) $(MAKE) -C $(PKG_BUILD_DIR) $(MAKE_FLAGS) NO_DOC=1 LUA_COMPILE:=no UPDATER_VERSION:=$(PKG_VERSION)
+endef
+
+define Host/Compile
+ $(MAKE) $(HOST_JOBS) -C $(HOST_BUILD_DIR) $(HOST_MAKE_FLAGS) NO_DOC=1 LUA_COMPILE:=no UPDATER_VERSION:=$(PKG_VERSION)
+endef
+
+define Host/Install
+ $(INSTALL_DIR) $(STAGING_DIR_HOST)/usr/lib/
+ $(INSTALL_BIN) $(HOST_BUILD_DIR)/lib/libupdater.so $(STAGING_DIR_HOST)/usr/lib/
+
+ $(INSTALL_DIR) $(STAGING_DIR_HOST)/usr/bin
+ $(INSTALL_BIN) $(HOST_BUILD_DIR)/bin/opkg-trans $(STAGING_DIR_HOST)/usr/bin/
+ $(INSTALL_BIN) $(HOST_BUILD_DIR)/bin/pkgupdate $(STAGING_DIR_HOST)/usr/bin/
+endef
+
+
+define Package/$(PKG_NAME)-localrepo
+ TITLE:=Next generation updater local repository manager
+ DEPENDS:=+python
+endef
+
+define Package/$(PKG_NAME)-localrepo/install
+ $(INSTALL_DIR) $(1)/usr/bin
+ $(INSTALL_BIN) $(PKG_BUILD_DIR)/utils/localrepo $(1)/usr/bin/localrepo
+endef
+
+
+define Package/$(PKG_NAME)-opkg
+ TITLE:=OPKG compatibility wrapper for next generation updater
+ DEPENDS:=+opkg +localrepo
+endef
+
+define Package/$(PKG_NAME)-opkg/install
+ $(INSTALL_DIR) $(1)/usr/bin
+ $(INSTALL_BIN) $(PKG_BUILD_DIR)/utils/opkg $(1)/usr/bin/opkg-pkgupdate-wrapper.sh
+endef
+
+# Current implementation of updater can't remove package before replan and so we
+# can't let updater-ng steal opkg-trans files. With dependency:
+# if not version_match then
+# Package 'updater-ng' { deps = 'opkg-trans' }
+# end
+# this empty package should ensure that we correctly move packages from opkg-trans
+# to updater-ng even with old version of updater. Unfortunately this won't work
+# with downgrade.
+# Note that because version_match was defined after package rename we can't use it
+# to check version. But if it isn't defined than we know that we are using some
+# old version of updater.
+define Package/opkg-trans
+ TITLE:=Dummy opkg-trans package
+endef
+
+define Package/opkg-trans/install
+ true
+endef
+
+$(eval $(call BuildPackage,updater-ng))
+$(eval $(call BuildPackage,updater-ng-localrepo))
+$(eval $(call BuildPackage,updater-ng-opkg))
+$(eval $(call BuildPackage,opkg-trans))
+$(eval $(call HostBuild))
diff --git a/updater-ng-auto/files/updater.config b/updater-ng-auto/files/updater.config
new file mode 100644
index 0000000..4bc05ed
--- /dev/null
+++ b/updater-ng-auto/files/updater.config
@@ -0,0 +1,9 @@
+config pkglists pkglists
+ list lists 'cacerts'
+ list lists 'luci-controls'
+ list lists 'nas'
+ list lists 'netutils'
+
+config l10n 'l10n'
+ list langs 'cs'
+ list langs 'de'
diff --git a/updater-ng-auto/files/updater.defaults b/updater-ng-auto/files/updater.defaults
new file mode 100644
index 0000000..951558a
--- /dev/null
+++ b/updater-ng-auto/files/updater.defaults
@@ -0,0 +1,24 @@
+#!/bin/sh
+
+# We want to generate some "random" time when the updater is run, every 12 hours.
+# The time when the router is first booted or the updater is installed for
+# the first time is as good source of the time as any.
+#
+# With date +%l we get time in interval 1-12. Substracting 1 gives us 0-11, and
+# the next run is 12-23 by adding 12. We may take the minutes as they are.
+#
+# We need to take care not to have leading zeroes, since tools tend to take that
+# as octal. We don't want to study which tools are OK with it, so we simply
+# don't have them.
+
+HOUR=$(($(date +%I | sed -e 's/^0*\(..*\)/\1/') - 1)) # We want 12-hour interval. And no leading zeroes (except for a lone 0)
+HOUR_NEXT=$(($HOUR + 12))
+MINUTE=$(date +%M | sed -e 's/^0*\(..*\)/\1/')
+
+# Generate the cron script
+(
+ echo 'MAILTO=""'
+ echo "$MINUTE $HOUR,$HOUR_NEXT * * * root /usr/bin/updater.sh >/dev/null 2>&1 &"
+ echo "0 0 * * * root /usr/bin/updater-unstuck.sh >/dev/null 2>&1"
+) >/etc/cron.d/updater
+chmod 0600 /etc/cron.d/updater
diff --git a/utils/opkg-trans-master.sh b/utils/updater-ng-auto.sh
index b16845c..449b045 100755
--- a/utils/opkg-trans-master.sh
+++ b/utils/updater-ng-auto.sh
@@ -5,8 +5,8 @@
UPDATER_REPO=https://kkoci@gitlab.labs.nic.cz/turris/updater.git
UPDATER_REPO_PATH=/tmp/myrepo_updater_repo
-if [ ! -f $1/opkg-trans-master-auto/Makefile ]; then
- # Skip this when we don't have opkg-trans-master-auto
+if [ ! -f $1/updater-ng-auto/Makefile ]; then
+ # Skip this when we don't have updater-ng-auto
exit
fi
@@ -23,4 +23,6 @@ VERSION="$(git $GIT_ARGS describe --abbrev=0 --tags)"
RELEASE="$(($(git $GIT_ARGS rev-list --count $VERSION..HEAD) + 1))"
# Now replace stuff in Makefile
-sed -i "s/^PKG_VERSION:=.*/PKG_VERSION:=$VERSION/;s/^PKG_RELEASE:=.*/PKG_RELEASE:=$RELEASE/;s/^PKG_SOURCE_VERSION:=.*/PKG_SOURCE_VERSION:=$HASH/" $1/opkg-trans-master-auto/Makefile
+sed -i "s/^PKG_VERSION:=.*/PKG_VERSION:=$VERSION/;s/^PKG_RELEASE:=.*/PKG_RELEASE:=$RELEASE/;s/^PKG_SOURCE_VERSION:=.*/PKG_SOURCE_VERSION:=$HASH/" $1/updater-ng-auto/Makefile
+
+echo -e "\e[1;35mUpdater-ng package has now version: $VERSION-$RELEASE\e[0m"