feat: initial commit
This commit is contained in:
15
misc/packaging/common/config-agent.yml
Normal file
15
misc/packaging/common/config-agent.yml
Normal file
@ -0,0 +1,15 @@
|
||||
agent:
|
||||
reconciliationInterval: 5
|
||||
controllers:
|
||||
persistence:
|
||||
enabled: true
|
||||
stateFile: /var/lib/emissary/state.json
|
||||
spec:
|
||||
enabled: true
|
||||
serverUrl: http://192.168.0.45:3000
|
||||
gateway:
|
||||
enabled: true
|
||||
uci:
|
||||
enabled: true
|
||||
binPath: uci
|
||||
configBackupFile: /var/lib/emissary/uci-backup.conf
|
24
misc/packaging/common/config-server.yml
Normal file
24
misc/packaging/common/config-server.yml
Normal file
@ -0,0 +1,24 @@
|
||||
http:
|
||||
host: 0.0.0.0
|
||||
port: 3000
|
||||
logger:
|
||||
level: 1
|
||||
format: human
|
||||
database:
|
||||
driver: sqlite
|
||||
dsn: sqlite:///var/lib/emissary/data.sqlite
|
||||
cors:
|
||||
allowedOrigins: []
|
||||
allowCredentials: true
|
||||
allowMethods:
|
||||
- POST
|
||||
- GET
|
||||
- PUT
|
||||
- DELETE
|
||||
allowedHeaders:
|
||||
- Origin
|
||||
- Accept
|
||||
- Content-Type
|
||||
- Authorization
|
||||
- Sentry-Trace
|
||||
debug: false
|
73
misc/packaging/common/postinstall-agent.sh
Normal file
73
misc/packaging/common/postinstall-agent.sh
Normal file
@ -0,0 +1,73 @@
|
||||
#!/bin/sh
|
||||
|
||||
use_systemctl="True"
|
||||
systemd_version=0
|
||||
if ! command -V systemctl >/dev/null 2>&1; then
|
||||
use_systemctl="False"
|
||||
else
|
||||
systemd_version=$(systemctl --version | head -1 | cut -d ' ' -f 2)
|
||||
fi
|
||||
|
||||
service_name=emissary-agent
|
||||
|
||||
cleanup() {
|
||||
if [ "${use_systemctl}" = "False" ]; then
|
||||
rm -f /usr/lib/systemd/system/${service_name}.service
|
||||
else
|
||||
rm -f /etc/chkconfig/${service_name}
|
||||
rm -f /etc/init.d/${service_name}
|
||||
fi
|
||||
}
|
||||
|
||||
cleanInstall() {
|
||||
printf "\033[32m Post Install of an clean install\033[0m\n"
|
||||
if [ "${use_systemctl}" = "False" ]; then
|
||||
if command -V chkconfig >/dev/null 2>&1; then
|
||||
chkconfig --add ${service_name}
|
||||
fi
|
||||
|
||||
service ${service_name} restart || :
|
||||
else
|
||||
if [[ "${systemd_version}" -lt 231 ]]; then
|
||||
printf "\033[31m systemd version %s is less then 231, fixing the service file \033[0m\n" "${systemd_version}"
|
||||
sed -i "s/=+/=/g" /usr/lib/systemd/system/${service_name}.service
|
||||
fi
|
||||
printf "\033[32m Reload the service unit from disk\033[0m\n"
|
||||
systemctl daemon-reload || :
|
||||
printf "\033[32m Unmask the service\033[0m\n"
|
||||
systemctl unmask ${service_name} || :
|
||||
printf "\033[32m Set the preset flag for the service unit\033[0m\n"
|
||||
systemctl preset ${service_name} || :
|
||||
printf "\033[32m Set the enabled flag for the service unit\033[0m\n"
|
||||
systemctl enable ${service_name} || :
|
||||
systemctl restart ${service_name} || :
|
||||
fi
|
||||
}
|
||||
|
||||
upgrade() {
|
||||
printf "\033[32m Post Install of an upgrade\033[0m\n"
|
||||
}
|
||||
|
||||
# Step 2, check if this is a clean install or an upgrade
|
||||
action="$1"
|
||||
if [ "$1" = "configure" ] && [ -z "$2" ]; then
|
||||
action="install"
|
||||
elif [ "$1" = "configure" ] && [ -n "$2" ]; then
|
||||
action="upgrade"
|
||||
fi
|
||||
|
||||
case "$action" in
|
||||
"1" | "install")
|
||||
cleanInstall
|
||||
;;
|
||||
"2" | "upgrade")
|
||||
printf "\033[32m Post Install of an upgrade\033[0m\n"
|
||||
upgrade
|
||||
;;
|
||||
*)
|
||||
printf "\033[32m Alpine\033[0m"
|
||||
cleanInstall
|
||||
;;
|
||||
esac
|
||||
|
||||
cleanup
|
73
misc/packaging/common/postinstall-server.sh
Normal file
73
misc/packaging/common/postinstall-server.sh
Normal file
@ -0,0 +1,73 @@
|
||||
#!/bin/sh
|
||||
|
||||
use_systemctl="True"
|
||||
systemd_version=0
|
||||
if ! command -V systemctl >/dev/null 2>&1; then
|
||||
use_systemctl="False"
|
||||
else
|
||||
systemd_version=$(systemctl --version | head -1 | cut -d ' ' -f 2)
|
||||
fi
|
||||
|
||||
service_name=emissary-server
|
||||
|
||||
cleanup() {
|
||||
if [ "${use_systemctl}" = "False" ]; then
|
||||
rm -f /usr/lib/systemd/system/${service_name}.service
|
||||
else
|
||||
rm -f /etc/chkconfig/${service_name}
|
||||
rm -f /etc/init.d/${service_name}
|
||||
fi
|
||||
}
|
||||
|
||||
cleanInstall() {
|
||||
printf "\033[32m Post Install of an clean install\033[0m\n"
|
||||
if [ "${use_systemctl}" = "False" ]; then
|
||||
if command -V chkconfig >/dev/null 2>&1; then
|
||||
chkconfig --add ${service_name}
|
||||
fi
|
||||
|
||||
service ${service_name} restart || :
|
||||
else
|
||||
if [[ "${systemd_version}" -lt 231 ]]; then
|
||||
printf "\033[31m systemd version %s is less then 231, fixing the service file \033[0m\n" "${systemd_version}"
|
||||
sed -i "s/=+/=/g" /usr/lib/systemd/system/${service_name}.service
|
||||
fi
|
||||
printf "\033[32m Reload the service unit from disk\033[0m\n"
|
||||
systemctl daemon-reload || :
|
||||
printf "\033[32m Unmask the service\033[0m\n"
|
||||
systemctl unmask ${service_name} || :
|
||||
printf "\033[32m Set the preset flag for the service unit\033[0m\n"
|
||||
systemctl preset ${service_name} || :
|
||||
printf "\033[32m Set the enabled flag for the service unit\033[0m\n"
|
||||
systemctl enable ${service_name} || :
|
||||
systemctl restart ${service_name} || :
|
||||
fi
|
||||
}
|
||||
|
||||
upgrade() {
|
||||
printf "\033[32m Post Install of an upgrade\033[0m\n"
|
||||
}
|
||||
|
||||
# Step 2, check if this is a clean install or an upgrade
|
||||
action="$1"
|
||||
if [ "$1" = "configure" ] && [ -z "$2" ]; then
|
||||
action="install"
|
||||
elif [ "$1" = "configure" ] && [ -n "$2" ]; then
|
||||
action="upgrade"
|
||||
fi
|
||||
|
||||
case "$action" in
|
||||
"1" | "install")
|
||||
cleanInstall
|
||||
;;
|
||||
"2" | "upgrade")
|
||||
printf "\033[32m Post Install of an upgrade\033[0m\n"
|
||||
upgrade
|
||||
;;
|
||||
*)
|
||||
printf "\033[32m Alpine\033[0m"
|
||||
cleanInstall
|
||||
;;
|
||||
esac
|
||||
|
||||
cleanup
|
10
misc/packaging/openrc/emissary-agent.openrc.sh
Normal file
10
misc/packaging/openrc/emissary-agent.openrc.sh
Normal file
@ -0,0 +1,10 @@
|
||||
#!/sbin/openrc-run
|
||||
|
||||
command="/usr/bin/emissary"
|
||||
command_args="--config /etc/emissary/config.yml agent run"
|
||||
start_stop_daemon_args='--chdir /usr/share/emissary'
|
||||
supervisor=supervise-daemon
|
||||
|
||||
depend() {
|
||||
need net
|
||||
}
|
10
misc/packaging/openrc/emissary-server.openrc.sh
Normal file
10
misc/packaging/openrc/emissary-server.openrc.sh
Normal file
@ -0,0 +1,10 @@
|
||||
#!/sbin/openrc-run
|
||||
|
||||
command="/usr/bin/emissary"
|
||||
command_args="--config /etc/emissary/config.yml server run"
|
||||
start_stop_daemon_args='--chdir /usr/share/emissary'
|
||||
supervisor=supervise-daemon
|
||||
|
||||
depend() {
|
||||
need net
|
||||
}
|
20
misc/packaging/openwrt/emissary-agent.init.sh
Normal file
20
misc/packaging/openwrt/emissary-agent.init.sh
Normal file
@ -0,0 +1,20 @@
|
||||
#!/bin/sh /etc/rc.common
|
||||
|
||||
USE_PROCD=1
|
||||
START=50
|
||||
STOP=50
|
||||
|
||||
start_service() {
|
||||
local config_file="/etc/emissary/agent.yml"
|
||||
procd_open_instance emissary-agent
|
||||
procd_set_param command /usr/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
|
||||
}
|
12
misc/packaging/systemd/emissary-agent.systemd.service
Normal file
12
misc/packaging/systemd/emissary-agent.systemd.service
Normal file
@ -0,0 +1,12 @@
|
||||
[Unit]
|
||||
Description=emissary agent service
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
Restart=always
|
||||
WorkingDirectory=/usr/share/emissary
|
||||
ExecStart=/usr/bin/emissary --config /etc/emissary/config.yml agent run
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
12
misc/packaging/systemd/emissary-server.systemd.service
Normal file
12
misc/packaging/systemd/emissary-server.systemd.service
Normal file
@ -0,0 +1,12 @@
|
||||
[Unit]
|
||||
Description=emissary server service
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
Restart=always
|
||||
WorkingDirectory=/usr/share/emissary
|
||||
ExecStart=/usr/bin/emissary --config /etc/emissary/config.yml server run
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
65
misc/rest/server.rest
Normal file
65
misc/rest/server.rest
Normal file
@ -0,0 +1,65 @@
|
||||
@baseUrl = http://localhost:3000
|
||||
|
||||
### Get agents
|
||||
|
||||
# @name getAgents
|
||||
GET {{ baseUrl }}/api/v1/agents
|
||||
Content-Type: application/json
|
||||
|
||||
@agentId = {{ getAgents.response.body.Data.Agents.0.ID }}
|
||||
|
||||
### Update an agent (accept it)
|
||||
|
||||
PUT {{ baseUrl }}/api/v1/agents/{{ agentId }}
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"Status": 1
|
||||
}
|
||||
|
||||
### Get an agent
|
||||
|
||||
GET {{ baseUrl }}/api/v1/agents/{{ agentId }}
|
||||
Content-Type: application/json
|
||||
|
||||
### Get an agent specs
|
||||
|
||||
# @name getSpecs
|
||||
GET {{ baseUrl }}/api/v1/agents/{{ agentId }}/specs
|
||||
Content-Type: application/json
|
||||
|
||||
@specName = {{ getSpecs.response.body.Data.Specs.0.Name }}
|
||||
|
||||
### Update an agent specs
|
||||
|
||||
POST {{ baseUrl }}/api/v1/agents/{{ agentId }}/specs
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"Name": "gateway.emissary.cadoles.com",
|
||||
"Revision": 2,
|
||||
"Data": {
|
||||
"gateways": {
|
||||
"cadoles.com":{
|
||||
"address":":3003",
|
||||
"target":"https://www.cadoles.com"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
### Delete an agent spec
|
||||
|
||||
DELETE {{ baseUrl }}/api/v1/agents/{{ agentId }}/specs
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"Name": "gateway.emissary.cadoles.com"
|
||||
}
|
||||
|
||||
### Update UCI spec with uhttpd config
|
||||
|
||||
POST {{ baseUrl }}/api/v1/agents/2/specs
|
||||
Content-Type: application/json
|
||||
|
||||
< ./uci-spec.payload.json
|
163
misc/rest/uci-spec.payload.json
Normal file
163
misc/rest/uci-spec.payload.json
Normal file
@ -0,0 +1,163 @@
|
||||
{
|
||||
"Name": "uci.emissary.cadoles.com",
|
||||
"Revision": 6,
|
||||
"Data": {
|
||||
"config": {
|
||||
"packages": [
|
||||
{
|
||||
"name": "uhttpd",
|
||||
"configs": [
|
||||
{
|
||||
"name": "uhttpd",
|
||||
"section": "main",
|
||||
"options": [
|
||||
{
|
||||
"type": "list",
|
||||
"name": "listen_http",
|
||||
"value": "0.0.0.0:8080"
|
||||
},
|
||||
{
|
||||
"type": "list",
|
||||
"name": "listen_http",
|
||||
"value": "[::]:8080"
|
||||
},
|
||||
{
|
||||
"type": "list",
|
||||
"name": "listen_https",
|
||||
"value": "0.0.0.0:8443"
|
||||
},
|
||||
{
|
||||
"type": "list",
|
||||
"name": "listen_https",
|
||||
"value": "[::]:8443"
|
||||
},
|
||||
{
|
||||
"type": "option",
|
||||
"name": "redirect_https",
|
||||
"value": "0"
|
||||
},
|
||||
{
|
||||
"type": "option",
|
||||
"name": "home",
|
||||
"value": "/www"
|
||||
},
|
||||
{
|
||||
"type": "option",
|
||||
"name": "rfc1918_filter",
|
||||
"value": "1"
|
||||
},
|
||||
{
|
||||
"type": "option",
|
||||
"name": "max_requests",
|
||||
"value": "3"
|
||||
},
|
||||
{
|
||||
"type": "option",
|
||||
"name": "max_connections",
|
||||
"value": "100"
|
||||
},
|
||||
{
|
||||
"type": "option",
|
||||
"name": "cert",
|
||||
"value": "/etc/uhttpd.crt"
|
||||
},
|
||||
{
|
||||
"type": "option",
|
||||
"name": "key",
|
||||
"value": "/etc/uhttpd.key"
|
||||
},
|
||||
{
|
||||
"type": "option",
|
||||
"name": "cgi_prefix",
|
||||
"value": "/cgi-bin"
|
||||
},
|
||||
{
|
||||
"type": "list",
|
||||
"name": "lua_prefix",
|
||||
"value": "/cgi-bin/luci=/usr/lib/lua/luci/sgi/uhttpd.lua"
|
||||
},
|
||||
{
|
||||
"type": "option",
|
||||
"name": "script_timeout",
|
||||
"value": "60"
|
||||
},
|
||||
{
|
||||
"type": "option",
|
||||
"name": "network_timeout",
|
||||
"value": "30"
|
||||
},
|
||||
{
|
||||
"type": "option",
|
||||
"name": "http_keepalive",
|
||||
"value": "20"
|
||||
},
|
||||
{
|
||||
"type": "option",
|
||||
"name": "tcp_keepalive",
|
||||
"value": "1"
|
||||
},
|
||||
{
|
||||
"type": "option",
|
||||
"name": "ubus_prefix",
|
||||
"value": "/ubus"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "cert",
|
||||
"section": "defaults",
|
||||
"options": [
|
||||
{
|
||||
"type": "option",
|
||||
"name": "days",
|
||||
"value": "730"
|
||||
},
|
||||
{
|
||||
"type": "option",
|
||||
"name": "key_type",
|
||||
"value": "ec"
|
||||
},
|
||||
{
|
||||
"type": "option",
|
||||
"name": "bits",
|
||||
"value": "2048"
|
||||
},
|
||||
{
|
||||
"type": "option",
|
||||
"name": "ec_curve",
|
||||
"value": "P-256"
|
||||
},
|
||||
{
|
||||
"type": "option",
|
||||
"name": "country",
|
||||
"value": "ZZ"
|
||||
},
|
||||
{
|
||||
"type": "option",
|
||||
"name": "state",
|
||||
"value": "Somewhere"
|
||||
},
|
||||
{
|
||||
"type": "option",
|
||||
"name": "location",
|
||||
"value": "Unknown"
|
||||
},
|
||||
{
|
||||
"type": "option",
|
||||
"name": "commonname",
|
||||
"value": "OpenWrt"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"postImportCommands": [
|
||||
{
|
||||
"command": "reload_config",
|
||||
"args": []
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
57
misc/script/install.sh
Normal file
57
misc/script/install.sh
Normal file
@ -0,0 +1,57 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
PROJECT_NAME="FAQd"
|
||||
PROJECT_RELEASES_URL="https://forge.cadoles.com/Cadoles/emissary/releases"
|
||||
PROJECT_DESTDIR="."
|
||||
PROJECT_FILE_BASENAME="faqd"
|
||||
PROJECT_PLATFORM_SUFFIX="$(uname -s)_$(uname -m)"
|
||||
|
||||
function main {
|
||||
test -z "${PROJECT_VERSION}" && PROJECT_VERSION="$(curl -sfL -o /dev/null -w %{url_effective} "${PROJECT_RELEASES_URL}/latest" |
|
||||
rev |
|
||||
cut -f1 -d'/'|
|
||||
rev)"
|
||||
|
||||
# Check version variable initialization
|
||||
test -z "${PROJECT_VERSION}" && {
|
||||
echo "Unable to get ${PROJECT_NAME} version !" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
test -z "${PROJECT_TMPDIR}" && PROJECT_TMPDIR="$(mktemp -d)"
|
||||
export TAR_FILE="${PROJECT_TMPDIR}/${PROJECT_FILE_BASENAME}_${PROJECT_VERSION}_${PROJECT_PLATFORM_SUFFIX}.tar.gz"
|
||||
|
||||
(
|
||||
cd "${PROJECT_TMPDIR}"
|
||||
|
||||
# Download project
|
||||
echo "Downloading ${PROJECT_NAME} ${PROJECT_VERSION}..."
|
||||
curl -sfLo "${TAR_FILE}" \
|
||||
"${PROJECT_RELEASES_URL}/download/${PROJECT_VERSION}/${PROJECT_FILE_BASENAME}_${PROJECT_VERSION}_${PROJECT_PLATFORM_SUFFIX}.tar.gz" ||
|
||||
( echo "Error while downloading ${PROJECT_NAME} !" >&2 && exit 1 )
|
||||
|
||||
# Download checksums
|
||||
curl -sfLo "checksums.txt" "${PROJECT_RELEASES_URL}/download/${PROJECT_VERSION}/checksums.txt"
|
||||
|
||||
echo "Verifying checksum..."
|
||||
check_sum ||
|
||||
( echo "Error while verifying checksums !" >&2 && exit 1 )
|
||||
)
|
||||
|
||||
# Extracting archive files
|
||||
tar -xf "${TAR_FILE}" -C "${PROJECT_TMPDIR}"
|
||||
|
||||
# Moving downloaded binary to destination directory
|
||||
mv -f "${PROJECT_TMPDIR}/${PROJECT_FILE_BASENAME}" "${PROJECT_DESTDIR}/"
|
||||
|
||||
echo "You can now use '${PROJECT_DESTDIR}/${PROJECT_FILE_BASENAME}', enjoy !"
|
||||
}
|
||||
|
||||
function check_sum {
|
||||
set -o pipefail
|
||||
cat checksums.txt | grep ${PROJECT_FILE_BASENAME}_*_${PROJECT_PLATFORM_SUFFIX}.tar.gz | sha256sum -c
|
||||
set +o pipefail
|
||||
}
|
||||
|
||||
main $@
|
36
misc/script/test_install.sh
Normal file
36
misc/script/test_install.sh
Normal file
@ -0,0 +1,36 @@
|
||||
#!/bin/bash
|
||||
|
||||
SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]:-$0}"; )" &> /dev/null && pwd 2> /dev/null; )";
|
||||
|
||||
function test_install_ubuntu_20.04 {
|
||||
cat <<EOF | run_in_docker ubuntu:20.04
|
||||
apt update && apt install -y curl
|
||||
bash /src/misc/script/install.sh
|
||||
test -f ./faqd
|
||||
EOF
|
||||
}
|
||||
|
||||
function test_install_alpine_3.16 {
|
||||
cat <<EOF | run_in_docker alpine:3.16
|
||||
apk add curl
|
||||
sh /src/misc/script/install.sh
|
||||
test -f ./faqd
|
||||
EOF
|
||||
}
|
||||
|
||||
function test_install_fedora_36 {
|
||||
cat <<EOF | run_in_docker fedora:36
|
||||
yum install -y util-linux
|
||||
bash /src/misc/script/install.sh
|
||||
test -f ./faqd
|
||||
EOF
|
||||
}
|
||||
|
||||
function run_in_docker {
|
||||
local image=$1
|
||||
cat | docker run \
|
||||
-v "${SCRIPT_DIR}/../..:/src" \
|
||||
--workdir /tmp \
|
||||
-i --rm \
|
||||
${image}
|
||||
}
|
Reference in New Issue
Block a user