You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.4 KiB

  1. #!/bin/bash
  2. CURRENT_DIR=$( dirname "$(readlink -f "$0")" )
  3. OFFLINE_FILES_DIR_NAME="offline-files"
  4. OFFLINE_FILES_DIR="${CURRENT_DIR}/${OFFLINE_FILES_DIR_NAME}"
  5. OFFLINE_FILES_ARCHIVE="${CURRENT_DIR}/offline-files.tar.gz"
  6. FILES_LIST=${FILES_LIST:-"${CURRENT_DIR}/temp/files.list"}
  7. NGINX_PORT=8080
  8. # download files
  9. if [ ! -f "${FILES_LIST}" ]; then
  10. echo "${FILES_LIST} should exist, run ./generate_list.sh first."
  11. exit 1
  12. fi
  13. rm -rf "${OFFLINE_FILES_DIR}"
  14. rm "${OFFLINE_FILES_ARCHIVE}"
  15. mkdir "${OFFLINE_FILES_DIR}"
  16. while read -r url; do
  17. if ! wget -x -P "${OFFLINE_FILES_DIR}" "${url}"; then
  18. exit 1
  19. fi
  20. done < "${FILES_LIST}"
  21. tar -czvf "${OFFLINE_FILES_ARCHIVE}" "${OFFLINE_FILES_DIR_NAME}"
  22. [ -n "$NO_HTTP_SERVER" ] && echo "skip to run nginx" && exit 0
  23. # run nginx container server
  24. if command -v nerdctl 1>/dev/null 2>&1; then
  25. runtime="nerdctl"
  26. elif command -v podman 1>/dev/null 2>&1; then
  27. runtime="podman"
  28. elif command -v docker 1>/dev/null 2>&1; then
  29. runtime="docker"
  30. else
  31. echo "No supported container runtime found"
  32. exit 1
  33. fi
  34. sudo "${runtime}" container inspect nginx >/dev/null 2>&1
  35. if [ $? -ne 0 ]; then
  36. sudo "${runtime}" run \
  37. --restart=always -d -p ${NGINX_PORT}:80 \
  38. --volume "${OFFLINE_FILES_DIR}":/usr/share/nginx/html/download \
  39. --volume "${CURRENT_DIR}"/nginx.conf:/etc/nginx/nginx.conf \
  40. --name nginx nginx:alpine
  41. fi