chore: move install recipes in separate files

This commit is contained in:
wpetit 2023-02-26 19:15:24 +01:00
parent 110b6b0df8
commit 0ce214195e
10 changed files with 155 additions and 37 deletions

5
.gitignore vendored
View File

@ -5,8 +5,5 @@
/bin
/tools
/gitea-dl
/files/etc/emissary
/files/usr/local/bin/emissary
/files/var/lib/emissary
/files/usr/share/emissary
/files
/.gitea-release

View File

@ -26,7 +26,11 @@ EMISSARY_ARCH ?= armv6
EMISSARY_RECONCILIATION_INTERVAL ?=
EMISSARY_SERVER_URL ?=
BASE_INSTALL ?= install-emissary-files
ADDITIONAL_INSTALL ?=
include targets/*.mk
include install/*.mk
all:
@ -75,7 +79,8 @@ $(IMAGEBUILDER_CUSTOM_FILES_DIR_PATH):
echo "GIT_VERSION=$(GIT_VERSION)" >> "$(IMAGEBUILDER_CUSTOM_FILES_DIR_PATH)/etc/emissary_firmware"
echo "OPENWRT_PROFILE=$(OPENWRT_PROFILE)" >> "$(IMAGEBUILDER_CUSTOM_FILES_DIR_PATH)/etc/emissary_firmware"
$(MAKE) copy-emissary-files
rm -rf files/*
$(MAKE) $(BASE_INSTALL) $(ADDITIONAL_INSTALL)
cp -rf files/* $(IMAGEBUILDER_CUSTOM_FILES_DIR_PATH)/
@ -115,33 +120,6 @@ download-emissary-release: tools/gitea-download/bin/gitea-download.sh
GITEA_DOWNLOAD_RELEASE_NAME="$(GITEA_DOWNLOAD_RELEASE_NAME)" \
tools/gitea-download/bin/gitea-download.sh
.PHONY: copy-emissary-files
copy-emissary-files: download-emissary-release tools/yq/bin/yq tools/upx/bin/upx
mkdir -p gitea-dl/emissary-agent_linux_$(EMISSARY_ARCH)
cd gitea-dl && tar -xzf emissary-agent_*_linux_$(EMISSARY_ARCH).tar.gz -C emissary-agent_linux_$(EMISSARY_ARCH)
# Copy agent config
mkdir -p files/etc/emissary
cp gitea-dl/emissary-agent_linux_$(EMISSARY_ARCH)/misc/packaging/common/config-agent.yml files/etc/emissary/agent.yml
# Patch agent config
tools/yq/bin/yq -i '.agent.controllers.spec.serverUrl = "$${EMISSARY_SERVER_URL}"' files/etc/emissary/agent.yml
tools/yq/bin/yq -i '.agent.reconciliationInterval = "$${EMISSARY_RECONCILIATION_INTERVAL}"' files/etc/emissary/agent.yml
# Copy emissary binary
mkdir -p files/usr/local/bin
cp gitea-dl/emissary-agent_linux_$(EMISSARY_ARCH)/emissary files/usr/local/bin/emissary
chmod +x files/usr/local/bin/emissary
# Set defaults
mkdir -p files/etc/emissary
rm -rf files/etc/emissary/default.conf
echo "EMISSARY_RECONCILIATION_INTERVAL='$(EMISSARY_RECONCILIATION_INTERVAL)'" > files/etc/emissary/default.conf
echo "EMISSARY_SERVER_URL='$(EMISSARY_SERVER_URL)'" >> files/etc/emissary/default.conf
# Compress emissary binary
tools/upx/bin/upx -9 files/usr/local/bin/emissary
tools/gitea-release/bin/gitea-release.sh:
mkdir -p tools/gitea-release/bin
curl --output tools/gitea-release/bin/gitea-release.sh https://forge.cadoles.com/Cadoles/Jenkins/raw/branch/master/resources/com/cadoles/gitea/gitea-release.sh

34
install/emissary-files.mk Normal file
View File

@ -0,0 +1,34 @@
install-emissary-files:
mkdir -p files/etc/config
cp -r misc/emissary/config/* files/etc/config/
mkdir -p files/etc/init.d
cp -r misc/emissary/init.d/* files/etc/init.d/
mkdir -p files/etc/uci-defaults
cp -r misc/emissary/uci-defaults/* files/etc/uci-defaults/
mkdir -p gitea-dl/emissary-agent_linux_$(EMISSARY_ARCH)
cd gitea-dl && tar -xzf emissary-agent_*_linux_$(EMISSARY_ARCH).tar.gz -C emissary-agent_linux_$(EMISSARY_ARCH)
# Copy agent config
mkdir -p files/etc/emissary
cp gitea-dl/emissary-agent_linux_$(EMISSARY_ARCH)/misc/packaging/common/config-agent.yml files/etc/emissary/agent.yml
# Patch agent config
tools/yq/bin/yq -i '.agent.controllers.spec.serverUrl = "$${EMISSARY_SERVER_URL}"' files/etc/emissary/agent.yml
tools/yq/bin/yq -i '.agent.reconciliationInterval = "$${EMISSARY_RECONCILIATION_INTERVAL}"' files/etc/emissary/agent.yml
# Copy emissary binary
mkdir -p files/usr/local/bin
cp gitea-dl/emissary-agent_linux_$(EMISSARY_ARCH)/emissary files/usr/local/bin/emissary
chmod +x files/usr/local/bin/emissary
# Set defaults
mkdir -p files/etc/emissary
rm -rf files/etc/emissary/default.conf
echo "EMISSARY_RECONCILIATION_INTERVAL='$(EMISSARY_RECONCILIATION_INTERVAL)'" > files/etc/emissary/default.conf
echo "EMISSARY_SERVER_URL='$(EMISSARY_SERVER_URL)'" >> files/etc/emissary/default.conf
# Compress emissary binary
tools/upx/bin/upx -9 files/usr/local/bin/emissary

View File

@ -0,0 +1,3 @@
install-x86-network-config:
mkdir -p files/etc/config
cp misc/x86/uci/network files/etc/config/network

View File

@ -0,0 +1,5 @@
package emissary
config main 'agent'
option reconciliation_interval '60'
option server_url 'https://emissary.cadol.es'

View File

@ -0,0 +1,35 @@
#!/bin/sh /etc/rc.common
USE_PROCD=1
START=50
STOP=50
start_service() {
config_load emissary
mkdir -p /usr/share/emissary
mkdir -p /var/lib/emissary
config_get emissary_reconciliation_interval agent 'reconciliation_interval' "60"
config_get emissary_server_url agent 'server_url' "https://emissary.cadol.es"
local config_file="/etc/emissary/agent.yml"
procd_open_instance emissary-agent
procd_set_param env EMISSARY_SERVER_URL="$emissary_server_url" EMISSARY_RECONCILIATION_INTERVAL="$emissary_reconciliation_interval"
procd_set_param command /usr/local/bin/emissary
procd_append_param command --workdir /usr/share/emissary
procd_append_param command --config "$config_file"
procd_append_param command agent run
procd_set_param respawn ${respawn_threshold:-3600} ${respawn_timeout:-5} ${respawn_retry:-5}
procd_set_param file "$config_file"
procd_set_param stdout 1
procd_set_param stderr 1
procd_set_param pidfile /var/run/emissary-agent.pid
procd_close_instance
}
service_triggers()
{
# Reload service (restart) on emissary config changes
procd_add_reload_trigger "emissary"
}

View File

@ -0,0 +1,30 @@
#/bin/sh
set -e
main() {
local default_config="/etc/emissary/default.conf"
if [ ! -f "${default_config}" ]; then
exit 0
fi
source "${default_config}"
if [ ! -z "${EMISSARY_RECONCILIATION_INTERVAL}" ]; then
uci set "emissary.agent.reconciliation_interval=${EMISSARY_RECONCILIATION_INTERVAL}"
fi
if [ ! -z "${EMISSARY_SERVER_URL}" ]; then
uci set "emissary.agent.server_url=${EMISSARY_SERVER_URL}"
fi
# Commit modifications
uci commit
# Delete file
rm -f "${default_config}"
/etc/init.d/emissary-agent enable
}
main

View File

@ -0,0 +1,24 @@
#/bin/sh
set -e
main() {
local machine_id_file="/etc/machine-id"
if [ -f "$machine_id_file" ]; then
echo "Machine ID already generated. Doing nothing."
exit 0
fi
# Accumulate data to create unique machine id
local mac_addresses=$(cat /sys/class/net/*/address | uniq | sort)
local device_model=$(cat /sys/firmware/devicetree/base/model)
# Ensure destination directory
mkdir -p "$(dirname "$machine_id_file")"
# Generate SHA256 hash of data and save it to $machine_id_file
echo "$mac_adresses $device_model" | sha256sum | cut -d ' ' -f1 > "$machine_id_file"
}
main

9
misc/x86/uci/network Normal file
View File

@ -0,0 +1,9 @@
config interface 'loopback'
option ifname 'lo'
option proto 'static'
option ipaddr '127.0.0.1'
option netmask '255.0.0.0'
config interface 'wan'
option ifname 'eth0'
option proto 'dhcp'

View File

@ -1,7 +1,12 @@
all: x86_generic
x86_generic:
$(MAKE) OPENWRT_TARGET="x86/generic" EMISSARY_ARCH="386" OPENWRT_PROFILE="generic" build
$(MAKE) \
ADDITIONAL_INSTALL="install-x86-network-config" \
OPENWRT_TARGET="x86/generic" \
EMISSARY_ARCH="386" \
OPENWRT_PROFILE="generic" \
build
run_x86_generic: bin/$(OPENWRT_VERSION)/x86/generic/generic/openwrt-$(OPENWRT_VERSION)-emissary-*-ext4-combined.img
qemu-system-x86_64 \
@ -9,10 +14,8 @@ run_x86_generic: bin/$(OPENWRT_VERSION)/x86/generic/generic/openwrt-$(OPENWRT_VE
-nographic \
-drive file=$(shell ls bin/$(OPENWRT_VERSION)/x86/generic/generic/openwrt-$(OPENWRT_VERSION)-emissary-*-ext4-combined.img),id=d0,if=none \
-device ide-hd,drive=d0,bus=ide.0 \
-netdev bridge,br=virbr0,id=hn0 \
-device e1000,netdev=hn0,id=nic1 \
-netdev user,id=hn1 \
-device e1000,netdev=hn1,id=nic2
-device e1000,netdev=hn1,id=nic1
bin/$(OPENWRT_VERSION)/x86/generic/generic/openwrt-$(OPENWRT_VERSION)-emissary-*-ext4-combined.img:
gunzip bin/$(OPENWRT_VERSION)/x86/generic/generic/openwrt-$(OPENWRT_VERSION)-emissary-*-ext4-combined.img.gz || exit 0
gunzip bin/$(OPENWRT_VERSION)/x86/generic/generic/openwrt-$(OPENWRT_VERSION)-emissary-*-ext4-combined.img.gz