setup.sh 10 KB

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