Skip to content
Snippets Groups Projects
Verified Commit 2e478c0a authored by Štěpán Henek's avatar Štěpán Henek :bear:
Browse files

server-uplink: package added

parent d883022b
Branches
Tags
No related merge requests found
#
## Copyright (C) 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:=server-uplink
PKG_VERSION:=1
PKG_MAINTAINER:=Stepan Henek <stepan.henek@nic.cz>
PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)
include $(INCLUDE_DIR)/package.mk
define Package/$(PKG_NAME)
TITLE:=$(PKG_NAME)
DEPENDS:=+curl +cznic-cacert-bundle
endef
define Package/$(PKG_NAME)/description
Contains a couple of scripts which are resposible to communicate with server realated to
Turris Project.
endef
# The built is empty. But as there's no makefile in the git repo, we need to
# override the default that runs "make".
define Build/Compile
true
endef
define Package/$(PKG_NAME)/install
$(INSTALL_DIR) $(1)/etc/cron.d
$(INSTALL_DATA) files/server-uplink.cron $(1)/etc/cron.d/
$(INSTALL_DIR) $(1)/usr/share/server-uplink/
$(INSTALL_BIN) files/registration_code.sh $(1)/usr/share/server-uplink/
$(INSTALL_BIN) files/contract_valid.sh $(1)/usr/share/server-uplink/
$(INSTALL_BIN) files/registered.sh $(1)/usr/share/server-uplink/
endef
define Package/$(PKG_NAME)/postinst
#!/bin/sh
[ -n "$${IPKG_INSTROOT}" ] || {
# run scripts to update files
/usr/share/server-uplink/registration_code.sh
/usr/share/server-uplink/contract_valid.sh
}
endef
define Package/$(PKG_NAME)/postrm
#!/bin/sh
[ -n "$${IPKG_INSTROOT}" ] || {
# remove downloaded files
rm -rf /usr/share/server-uplink
}
endef
$(eval $(call BuildPackage,$(PKG_NAME)))
#!/bin/sh
#
# Copyright (C) 2017 CZ.NIC, z.s.p.o. (http://www.nic.cz/)
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#
set -e
TIMEOUT=120
CA_FILE=/etc/ssl/www_turris_cz_ca.pem
OUTPUT_FILE=/usr/share/server-uplink/contract_valid
CONTRACT_URL='https://www.turris.cz/api/contract-valid.txt?registration_code='
CODE=$(cat /usr/share/server-uplink/registration_code)
RESULT=$(curl -s -S -L -H "Accept: plain/text" --cacert "$CA_FILE" --cert-status -m "$TIMEOUT" "$CONTRACT_URL$CODE" | sed -ne 's/^result: *\(..*\)/\1/p')
# test whether the code is the same
if [ -f "$OUTPUT_FILE" ] ; then
if [ "$RESULT" == "$(cat "$OUTPUT_FILE")" ] ; then
exit 0
fi
fi
echo -n "$RESULT" > "$OUTPUT_FILE"
#!/bin/sh
#
# Copyright (C) 2017 CZ.NIC, z.s.p.o. (http://www.nic.cz/)
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#
set -e
usage() {
echo "$0 <email> [<lang>]"
}
if [ "$#" -lt 1 -o "$#" -gt 2 ]; then
usage
exit 1
fi
EMAIL="$1"
LANG="$2"
LANG=${LANG:-en}
TIMEOUT=120
CA_FILE=/etc/ssl/www_turris_cz_ca.pem
CODE=$(cat /usr/share/server-uplink/registration_code)
URL="https://www.turris.cz/api/registration-lookup.txt?registration_code=${CODE}&email=${EMAIL}"
curl -s -S -L -H "Accept: plain/text" -H "Accept-Language: $LANG" --cacert "$CA_FILE" \
--cert-status -m "$TIMEOUT" "$URL" -w "\ncode: %{http_code}"
#!/bin/sh
#
# Copyright (C) 2017 CZ.NIC, z.s.p.o. (http://www.nic.cz/)
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#
set -e
TIMEOUT=120
CA_FILE=/etc/ssl/www_turris_cz_ca.pem
CHALLENGE_URL=https://api.turris.cz/challenge.cgi
OUTPUT_FILE=/usr/share/server-uplink/registration_code
CODE=$(curl -s -k -m $TIMEOUT "$CHALLENGE_URL" | atsha204cmd challenge-response | head -c 16)
# test whether the code is the same
if [ -f "$OUTPUT_FILE" ] ; then
if [ "$CODE" == "$(cat "$OUTPUT_FILE")" ] ; then
exit 0
fi
fi
echo -n "$CODE" > "$OUTPUT_FILE"
MAILTO=""
*/60 * * * * root /usr/share/server-uplink/registration_code.sh
*/60 * * * * root /usr/share/server-uplink/contract_valid.sh
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment