setup.sh 10 KB

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