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.

44 lines
1.3 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. wget -x -P "${OFFLINE_FILES_DIR}" -i "${FILES_LIST}"
  17. tar -czvf "${OFFLINE_FILES_ARCHIVE}" "${OFFLINE_FILES_DIR_NAME}"
  18. [ -n "$NO_HTTP_SERVER" ] && echo "skip to run nginx" && exit 0
  19. # run nginx container server
  20. if command -v nerdctl 1>/dev/null 2>&1; then
  21. runtime="nerdctl"
  22. elif command -v podman 1>/dev/null 2>&1; then
  23. runtime="podman"
  24. elif command -v docker 1>/dev/null 2>&1; then
  25. runtime="docker"
  26. else
  27. echo "No supported container runtime found"
  28. exit 1
  29. fi
  30. sudo "${runtime}" container inspect nginx >/dev/null 2>&1
  31. if [ $? -ne 0 ]; then
  32. sudo "${runtime}" run \
  33. --restart=always -d -p ${NGINX_PORT}:80 \
  34. --volume "${OFFLINE_FILES_DIR}:/usr/share/nginx/html/download" \
  35. --volume "$(pwd)"/nginx.conf:/etc/nginx/nginx.conf \
  36. --name nginx nginx:alpine
  37. fi