-
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add armbian-router to software section
- Loading branch information
1 parent
814d302
commit 785af32
Showing
2 changed files
with
133 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
module_options+=( | ||
["module_armbianrouter,author"]="@armbian" | ||
["module_armbianrouter,maintainer"]="@efectn" | ||
["module_armbianrouter,feature"]="module_armbianrouter" | ||
["module_armbianrouter,example"]="install remove purge status help" | ||
["module_armbianrouter,desc"]="Install armbian router container" | ||
["module_armbianrouter,status"]="Active" | ||
["module_armbianrouter,doc_link"]="https://github.com/armbian/armbian-router" | ||
["module_armbianrouter,group"]="Other" | ||
["module_armbianrouter,port"]="8080" | ||
["module_armbianrouter,arch"]="x86-64 arm64" | ||
) | ||
|
||
function download_all_images() { | ||
wget -qO- https://github.armbian.com/all-images.json > "${1}/all-images.json" | ||
} | ||
|
||
# | ||
# Module armbianrouter | ||
# | ||
function module_armbianrouter () { | ||
local title="armbianrouter" | ||
local condition=$(which "$title" 2>/dev/null) | ||
|
||
if pkg_installed docker-ce; then | ||
local container=$(docker container ls -a --format '{{.ID}} {{.Names}}' | mawk '$2 ~ /^armbianrouter/ {print $1}') | ||
local image=$(docker image ls -a | mawk '/armbian-router?( |$)/{print $3}') | ||
fi | ||
|
||
local commands | ||
IFS=' ' read -r -a commands <<< "${module_options["module_armbianrouter,example"]}" | ||
|
||
ROUTER_BASE="${SOFTWARE_FOLDER}/armbian_router" | ||
|
||
declare -A routers | ||
routers["8080"]="dlrouter-debs" | ||
routers["8081"]="dlrouter-images" | ||
routers["8082"]="dlrouter-archive" | ||
routers["8083"]="dlrouter-debs-beta" | ||
routers["8084"]="dlrouter-cache" | ||
|
||
case "$1" in | ||
"${commands[0]}") | ||
pkg_installed docker-ce || module_docker install | ||
[[ -d "$ROUTER_BASE" ]] || mkdir -p "$ROUTER_BASE" || { echo "Couldn't create storage directory: $ROUTER_BASE"; exit 1; } | ||
|
||
# Download all config yaml files | ||
for port in "${!routers[@]}"; do | ||
wget -qO- https://github.armbian.com/${routers[$port]}.yaml > "${ROUTER_BASE}/${routers[$port]}.yaml" | ||
sed -i "s|/scripts/redirect-config|/app|g" "${ROUTER_BASE}/${routers[$port]}.yaml" | ||
done | ||
|
||
# Download geoip database | ||
wget -qO- https://github.armbian.com/GeoLite2-ASN.mmdb > "${ROUTER_BASE}/GeoLite2-ASN.mmdb" | ||
wget -qO- https://github.armbian.com/GeoLite2-City.mmdb > "${ROUTER_BASE}/GeoLite2-City.mmdb" | ||
|
||
# Download all images json | ||
download_all_images "${ROUTER_BASE}" | ||
|
||
for port in "${!routers[@]}"; do | ||
docker run -d \ | ||
--name=armbianrouter-${routers[$port]} \ | ||
--net=lsio \ | ||
-p $port:$port \ | ||
-v "${ROUTER_BASE}:/app" \ | ||
--restart unless-stopped \ | ||
ghcr.io/armbian/armbian-router:latest /bin/dlrouter --config /app/${routers[$port]}.yaml | ||
for i in $(seq 1 20); do | ||
if docker inspect -f '{{ index .Config.Labels "build_version" }}' armbianrouter-${routers[$port]} >/dev/null 2>&1 ; then | ||
break | ||
else | ||
sleep 3 | ||
fi | ||
if [ $i -eq 20 ] ; then | ||
echo -e "\nTimed out waiting for ${title} to start, consult your container logs for more info (\`docker logs armbianrouter-dlrouter-{debs,images,archive,debs-beta,cache}\`)" | ||
exit 1 | ||
fi | ||
done | ||
done | ||
;; | ||
"${commands[1]}") | ||
for port in "${!routers[@]}"; do | ||
docker container rm -f armbianrouter-${routers[$port]} >/dev/null | ||
done | ||
|
||
[[ "${image}" ]] && docker image rm "$image" >/dev/null | ||
;; | ||
"${commands[2]}") | ||
${module_options["module_armbianrouter,feature"]} ${commands[1]} | ||
[[ -n "${ROUTER_BASE}" && "${ROUTER_BASE}" != "/" ]] && rm -rf "${ROUTER_BASE}" | ||
;; | ||
"${commands[3]}") | ||
if [[ "${container}" && "${image}" ]]; then | ||
return 0 | ||
else | ||
return 1 | ||
fi | ||
;; | ||
"${commands[4]}") | ||
echo -e "\nUsage: ${module_options["module_armbianrouter,feature"]} <command>" | ||
echo -e "Commands: ${module_options["module_armbianrouter,example"]}" | ||
echo "Available commands:" | ||
echo -e "\tinstall\t- Install $title." | ||
echo -e "\tstatus\t- Installation status $title." | ||
echo -e "\tremove\t- Remove $title." | ||
echo -e "\tremove\t- Purge $title." | ||
echo | ||
;; | ||
*) | ||
${module_options["module_armbianrouter,feature"]} ${commands[4]} | ||
;; | ||
esac | ||
} |