setup.sh 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. #!/usr/bin/env sh
  2. # ArchiveBox Setup Script: https://github.com/ArchiveBox/ArchiveBox
  3. # Supported Platforms: Ubuntu/Debian/FreeBSD/macOS
  4. # Usage:
  5. # curl -sSL 'https://raw.githubusercontent.com/ArchiveBox/ArchiveBox/dev/bin/setup.sh' | sh
  6. clear
  7. if [ $(id -u) -eq 0 ]; then
  8. echo ""
  9. echo "[X] You cannot run this script as root. You must run it as a non-root user with sudo ability."
  10. echo " Create a new non-privileged user 'archivebox' if necessary."
  11. echo " adduser archivebox && usermod -a archivebox -G sudo && su archivebox"
  12. echo " https://www.digitalocean.com/community/tutorials/how-to-create-a-new-sudo-enabled-user-on-ubuntu-20-04-quickstart"
  13. echo " https://www.vultr.com/docs/create-a-sudo-user-on-freebsd"
  14. echo " Then re-run this script as the non-root user."
  15. echo ""
  16. exit 2
  17. fi
  18. if (which docker-compose > /dev/null && docker pull archivebox/archivebox:latest); then
  19. echo "[+] Initializing an ArchiveBox data folder at ~/archivebox/data using Docker Compose..."
  20. mkdir -p ~/archivebox
  21. cd ~/archivebox
  22. mkdir -p data
  23. if [ -f "./index.sqlite3" ]; then
  24. mv ~/archivebox/* ~/archivebox/data/
  25. fi
  26. curl -O 'https://raw.githubusercontent.com/ArchiveBox/ArchiveBox/master/docker-compose.yml'
  27. docker-compose run --rm archivebox init --setup
  28. echo
  29. echo "[+] Starting ArchiveBox server using: docker-compose up -d..."
  30. docker-compose up -d
  31. sleep 7
  32. open http://127.0.0.1:8000 || true
  33. echo
  34. echo "[√] Server started on http://0.0.0.0:8000 and data directory initialized in ~/archivebox/data. Usage:"
  35. echo " cd ~/archivebox"
  36. echo " docker-compose ps"
  37. echo " docker-compose down"
  38. echo " docker-compose pull"
  39. echo " docker-compose up"
  40. echo " docker-compose run archivebox manage createsuperuser"
  41. echo " docker-compose run archivebox add 'https://example.com'"
  42. echo " docker-compose run archivebox list"
  43. echo " docker-compose run archivebox help"
  44. exit 0
  45. elif (which docker > /dev/null && docker pull archivebox/archivebox:latest); then
  46. echo "[+] Initializing an ArchiveBox data folder at ~/archivebox using Docker..."
  47. mkdir -p ~/archivebox
  48. cd ~/archivebox
  49. if [ -f "./data/index.sqlite3" ]; then
  50. cd ./data
  51. fi
  52. docker run -v "$PWD":/data -it --rm archivebox/archivebox:latest init --setup
  53. echo
  54. echo "[+] Starting ArchiveBox server using: docker run -d archivebox/archivebox..."
  55. docker run -v "$PWD":/data -it -d -p 8000:8000 --name=archivebox archivebox/archivebox:latest
  56. sleep 7
  57. open http://127.0.0.1:8000 || true
  58. echo
  59. echo "[√] Server started on http://0.0.0.0:8000 and data directory initialized in ~/archivebox. Usage:"
  60. echo " cd ~/archivebox"
  61. echo " docker ps --filter name=archivebox"
  62. echo " docker kill archivebox"
  63. echo " docker pull archivebox/archivebox"
  64. echo " docker run -v $PWD:/data -d -p 8000:8000 --name=archivebox archivebox/archivebox"
  65. echo " docker run -v $PWD:/data -it archivebox/archivebox manage createsuperuser"
  66. echo " docker run -v $PWD:/data -it archivebox/archivebox add 'https://example.com'"
  67. echo " docker run -v $PWD:/data -it archivebox/archivebox list"
  68. echo " docker run -v $PWD:/data -it archivebox/archivebox help"
  69. exit 0
  70. fi
  71. echo ""
  72. echo "[!] It's highly recommended to use ArchiveBox with Docker, but Docker wasn't found."
  73. echo ""
  74. echo " ⚠️ If you want to use Docker, press [Ctrl-C] to cancel now. ⚠️"
  75. echo " Get Docker: https://docs.docker.com/get-docker/"
  76. echo " After you've installed Docker, run this script again."
  77. echo ""
  78. echo "Otherwise, install will continue with apt/brew/pip in 12s... (press [Ctrl+C] to cancel)"
  79. echo ""
  80. sleep 12 || exit 1
  81. echo "Proceeding with system package manager..."
  82. echo ""
  83. echo "[i] ArchiveBox Setup Script 📦"
  84. echo ""
  85. echo " This is a helper script which installs the ArchiveBox dependencies on your system using brew/apt/pip3."
  86. echo " You may be prompted for a sudo password in order to install the following:"
  87. echo ""
  88. echo " - archivebox"
  89. echo " - python3, pip, nodejs, npm (languages used by ArchiveBox, and its extractor modules)"
  90. echo " - curl, wget, git, youtube-dl, yt-dlp (used for extracting title, favicon, git, media, and more)"
  91. echo " - chromium (skips this if any Chrome/Chromium version is already installed)"
  92. echo ""
  93. echo " If you'd rather install these manually as-needed, you can find detailed documentation here:"
  94. echo " https://github.com/ArchiveBox/ArchiveBox/wiki/Install"
  95. echo ""
  96. echo "Continuing in 12s... (press [Ctrl+C] to cancel)"
  97. echo ""
  98. sleep 12 || exit 1
  99. echo "Proceeding to install dependencies..."
  100. echo ""
  101. # On Linux:
  102. if which apt-get > /dev/null; then
  103. echo "[+] Adding ArchiveBox apt repo and signing key to sources..."
  104. if ! (sudo apt install -y software-properties-common && sudo add-apt-repository -u ppa:archivebox/archivebox); then
  105. echo "deb http://ppa.launchpad.net/archivebox/archivebox/ubuntu focal main" | sudo tee /etc/apt/sources.list.d/archivebox.list
  106. echo "deb-src http://ppa.launchpad.net/archivebox/archivebox/ubuntu focal main" | sudo tee -a /etc/apt/sources.list.d/archivebox.list
  107. sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys C258F79DCC02E369
  108. sudo apt-get update -qq
  109. fi
  110. echo
  111. echo "[+] Installing ArchiveBox system dependencies using apt..."
  112. sudo apt-get install -y git python3 python3-pip python3-distutils wget curl youtube-dl yt-dlp ffmpeg git nodejs npm ripgrep
  113. sudo apt-get install -y libgtk2.0-0 libgtk-3-0 libnotify-dev libgconf-2-4 libnss3 libxss1 libasound2 libxtst6 xauth xvfb libgbm-dev || sudo apt-get install -y chromium || sudo apt-get install -y chromium-browser || true
  114. sudo apt-get install -y archivebox
  115. sudo apt-get --only-upgrade install -y archivebox
  116. echo ""
  117. echo "[+] Installing ArchiveBox python dependencies using pip3..."
  118. sudo python3 -m pip install --upgrade --ignore-installed archivebox
  119. # On Mac:
  120. elif which brew > /dev/null; then
  121. echo "[+] Installing ArchiveBox system dependencies using brew..."
  122. brew tap archivebox/archivebox
  123. brew update
  124. brew install --fetch-HEAD -f archivebox
  125. echo ""
  126. echo "[+] Installing ArchiveBox python dependencies using pip3..."
  127. python3 -m pip install --upgrade --ignore-installed archivebox
  128. elif which pkg > /dev/null; then
  129. echo "[+] Installing ArchiveBox system dependencies using pkg and pip (python3.9)..."
  130. sudo pkg install -y python3 py39-pip py39-sqlite3 npm wget curl youtube_dl ffmpeg git ripgrep
  131. sudo pkg install -y chromium
  132. echo ""
  133. echo "[+] Installing ArchiveBox python dependencies using pip..."
  134. # don't use sudo here so that pip installs in $HOME/.local instead of into /usr/local
  135. python3 -m pip install --upgrade --ignore-installed archivebox
  136. else
  137. echo "[!] Warning: Could not find aptitude/homebrew/pkg! May not be able to install all dependencies automatically."
  138. echo ""
  139. echo " If you're on macOS, make sure you have homebrew installed: https://brew.sh/"
  140. echo " If you're on Linux, only Ubuntu/Debian/BSD systems are officially supported with this script."
  141. echo " If you're on Windows, this script is not officially supported (Docker is recommeded instead)."
  142. echo ""
  143. echo "See the README.md for Manual Setup & Troubleshooting instructions if you you're unable to run ArchiveBox after this script completes."
  144. fi
  145. echo ""
  146. if ! (python3 --version && python3 -m pip --version && python3 -m django --version); then
  147. echo "[X] Python 3 pip was not found on your system!"
  148. echo " You must first install Python >= 3.7 (and pip3):"
  149. echo " https://www.python.org/downloads/"
  150. echo " https://wiki.python.org/moin/BeginnersGuide/Download"
  151. echo " After installing, run this script again."
  152. exit 1
  153. fi
  154. if ! (python3 -m django --version && python3 -m archivebox version --quiet); then
  155. echo "[X] Django and ArchiveBox were not found after installing!"
  156. echo " Check to see if a previous step failed."
  157. echo ""
  158. exit 1
  159. fi
  160. # echo ""
  161. # echo "[+] Upgrading npm and pip..."
  162. # sudo npm i -g npm || true
  163. # sudo python3 -m pip install --upgrade pip setuptools || true
  164. echo
  165. echo "[+] Initializing ArchiveBox data folder at ~/archivebox..."
  166. mkdir -p ~/archivebox
  167. cd ~/archivebox
  168. if [ -f "./data/index.sqlite3" ]; then
  169. cd ./data
  170. fi
  171. : | python3 -m archivebox init --setup || true # pipe in empty command to make sure stdin is closed
  172. echo
  173. echo "[+] Starting ArchiveBox server using: nohup archivebox server &..."
  174. nohup python3 -m archivebox server 0.0.0.0:8000 > ./logs/server.log 2>&1 &
  175. sleep 7
  176. which open > /dev/null && open http://127.0.0.1:8000 || true
  177. echo
  178. echo "[√] Server started on http://0.0.0.0:8000 and data directory initialized in ~/archivebox. Usage:"
  179. echo " cd ~/archivebox"
  180. echo " ps aux | grep archivebox"
  181. echo " pkill -f archivebox"
  182. echo " python3 -m pip install --upgrade archivebox"
  183. echo " archivebox server --quick-init 0.0.0.0:8000"
  184. echo " archivebox manage createsuperuser"
  185. echo " archivebox add 'https://example.com'"
  186. echo " archivebox list"
  187. echo " archivebox help"