ArchiveBox/bin/setup.sh

211 lines
10 KiB
Bash
Raw Normal View History

2021-04-24 06:11:04 +00:00
#!/usr/bin/env sh
2024-02-18 13:21:27 +00:00
# ArchiveBox Setup Script (Ubuntu/Debian/FreeBSD/macOS)
# - Project Homepage: https://github.com/ArchiveBox/ArchiveBox
# - Install Documentation: https://github.com/ArchiveBox/ArchiveBox/wiki/Install
# Script Usage:
# curl -fsSL 'https://raw.githubusercontent.com/ArchiveBox/ArchiveBox/dev/bin/setup.sh' | sh
# (aka https://docker-compose.archivebox.io)
2021-04-24 06:11:04 +00:00
clear
2018-06-11 01:58:48 +00:00
2021-04-24 06:27:30 +00:00
if [ $(id -u) -eq 0 ]; then
2024-02-18 13:27:17 +00:00
echo
2021-04-24 06:26:25 +00:00
echo "[X] You cannot run this script as root. You must run it as a non-root user with sudo ability."
2021-04-24 07:09:18 +00:00
echo " Create a new non-privileged user 'archivebox' if necessary."
echo " adduser archivebox && usermod -a archivebox -G sudo && su archivebox"
echo " https://www.digitalocean.com/community/tutorials/how-to-create-a-new-sudo-enabled-user-on-ubuntu-20-04-quickstart"
echo " https://www.vultr.com/docs/create-a-sudo-user-on-freebsd"
2021-04-24 06:40:45 +00:00
echo " Then re-run this script as the non-root user."
2024-02-18 13:27:17 +00:00
echo
2021-04-24 06:30:31 +00:00
exit 2
2021-04-24 06:26:25 +00:00
fi
if (which docker-compose > /dev/null && docker pull archivebox/archivebox:latest); then
2021-04-24 04:06:07 +00:00
echo "[+] Initializing an ArchiveBox data folder at ~/archivebox/data using Docker Compose..."
2024-02-18 13:21:27 +00:00
mkdir -p ~/archivebox/data
2021-04-24 04:06:07 +00:00
cd ~/archivebox
2021-04-24 04:08:17 +00:00
if [ -f "./index.sqlite3" ]; then
2024-02-18 13:21:27 +00:00
mv -i ~/archivebox/* ~/archivebox/data/
2021-04-24 04:06:07 +00:00
fi
curl -fsSL 'https://raw.githubusercontent.com/ArchiveBox/ArchiveBox/stable/docker-compose.yml' > docker-compose.yml
2024-02-18 13:21:27 +00:00
mkdir -p ./etc
curl -fsSL 'https://raw.githubusercontent.com/ArchiveBox/ArchiveBox/stable/etc/sonic.cfg' > ./etc/sonic.cfg
2024-01-17 02:15:14 +00:00
docker compose run --rm archivebox init --setup
2021-04-24 04:55:51 +00:00
echo
2024-01-17 02:15:14 +00:00
echo "[+] Starting ArchiveBox server using: docker compose up -d..."
docker compose up -d
2021-04-24 04:06:07 +00:00
sleep 7
2024-02-18 13:21:27 +00:00
which open > /dev/null && open "http://127.0.0.1:8000" || true
2021-04-24 04:55:51 +00:00
echo
2021-04-24 04:23:14 +00:00
echo "[√] Server started on http://0.0.0.0:8000 and data directory initialized in ~/archivebox/data. Usage:"
echo " cd ~/archivebox"
2024-01-17 02:15:14 +00:00
echo " docker compose ps"
echo " docker compose down"
echo " docker compose pull"
echo " docker compose up"
echo " docker compose run archivebox manage createsuperuser"
echo " docker compose run archivebox add 'https://example.com'"
echo " docker compose run archivebox list"
echo " docker compose run archivebox help"
2021-04-24 04:06:07 +00:00
exit 0
elif (which docker > /dev/null && docker pull archivebox/archivebox:latest); then
2024-02-18 13:21:27 +00:00
echo "[+] Initializing an ArchiveBox data folder at ~/archivebox/data using Docker..."
mkdir -p ~/archivebox/data
cd ~/archivebox
2024-02-18 13:21:27 +00:00
if [ -f "./index.sqlite3" ]; then
mv -i ~/archivebox/* ~/archivebox/data/
2021-04-24 04:06:07 +00:00
fi
2024-02-18 13:21:27 +00:00
cd ./data
docker run -v "$PWD":/data -it --rm archivebox/archivebox:latest init --setup
2021-04-24 04:55:51 +00:00
echo
echo "[+] Starting ArchiveBox server using: docker run -d archivebox/archivebox..."
docker run -v "$PWD":/data -it -d -p 8000:8000 --name=archivebox archivebox/archivebox:latest
2021-04-24 04:06:07 +00:00
sleep 7
2024-02-18 13:21:27 +00:00
which open > /dev/null && open "http://127.0.0.1:8000" || true
2021-04-24 04:55:51 +00:00
echo
2024-02-18 13:21:27 +00:00
echo "[√] Server started on http://0.0.0.0:8000 and data directory initialized in ~/archivebox/data. Usage:"
echo " cd ~/archivebox/data"
2021-04-24 04:23:14 +00:00
echo " docker ps --filter name=archivebox"
echo " docker kill archivebox"
echo " docker pull archivebox/archivebox"
echo " docker run -v $PWD:/data -d -p 8000:8000 --name=archivebox archivebox/archivebox"
echo " docker run -v $PWD:/data -it archivebox/archivebox manage createsuperuser"
2021-04-24 04:23:14 +00:00
echo " docker run -v $PWD:/data -it archivebox/archivebox add 'https://example.com'"
echo " docker run -v $PWD:/data -it archivebox/archivebox list"
echo " docker run -v $PWD:/data -it archivebox/archivebox help"
exit 0
fi
2024-02-18 13:27:17 +00:00
echo
2021-04-24 05:02:12 +00:00
echo "[!] It's highly recommended to use ArchiveBox with Docker, but Docker wasn't found."
2024-02-18 13:27:17 +00:00
echo
2021-04-24 05:02:12 +00:00
echo " ⚠️ If you want to use Docker, press [Ctrl-C] to cancel now. ⚠️"
echo " Get Docker: https://docs.docker.com/get-docker/"
2021-04-24 06:40:45 +00:00
echo " After you've installed Docker, run this script again."
2024-02-18 13:27:17 +00:00
echo
2024-02-18 13:28:48 +00:00
echo "Otherwise, install will continue with apt/brew/pkg + pip in 12s... (press [Ctrl+C] to cancel)"
2024-02-18 13:27:17 +00:00
echo
2021-04-24 11:08:56 +00:00
sleep 12 || exit 1
echo "Proceeding with system package manager..."
2024-02-18 13:27:17 +00:00
echo
2019-03-12 21:49:40 +00:00
echo "[i] ArchiveBox Setup Script 📦"
2024-02-18 13:27:17 +00:00
echo
2021-04-24 03:43:41 +00:00
echo " This is a helper script which installs the ArchiveBox dependencies on your system using brew/apt/pip3."
2021-04-24 04:55:51 +00:00
echo " You may be prompted for a sudo password in order to install the following:"
2024-02-18 13:27:17 +00:00
echo
echo " - archivebox"
2022-09-12 21:52:01 +00:00
echo " - python3, pip, nodejs, npm (languages used by ArchiveBox, and its extractor modules)"
2022-09-12 20:34:02 +00:00
echo " - curl, wget, git, youtube-dl, yt-dlp (used for extracting title, favicon, git, media, and more)"
echo " - chromium (skips this if any Chrome/Chromium version is already installed)"
2024-02-18 13:27:17 +00:00
echo
2021-04-24 03:43:41 +00:00
echo " If you'd rather install these manually as-needed, you can find detailed documentation here:"
2020-11-23 07:04:39 +00:00
echo " https://github.com/ArchiveBox/ArchiveBox/wiki/Install"
2024-02-18 13:27:17 +00:00
echo
2021-04-24 11:08:56 +00:00
echo "Continuing in 12s... (press [Ctrl+C] to cancel)"
2024-02-18 13:27:17 +00:00
echo
2021-04-24 11:08:56 +00:00
sleep 12 || exit 1
echo "Proceeding to install dependencies..."
2024-02-18 13:27:17 +00:00
echo
2018-06-11 01:58:48 +00:00
# On Linux:
if which apt-get > /dev/null; then
2021-04-24 04:55:51 +00:00
echo "[+] Adding ArchiveBox apt repo and signing key to sources..."
2021-04-24 03:43:41 +00:00
if ! (sudo apt install -y software-properties-common && sudo add-apt-repository -u ppa:archivebox/archivebox); then
echo "deb http://ppa.launchpad.net/archivebox/archivebox/ubuntu focal main" | sudo tee /etc/apt/sources.list.d/archivebox.list
echo "deb-src http://ppa.launchpad.net/archivebox/archivebox/ubuntu focal main" | sudo tee -a /etc/apt/sources.list.d/archivebox.list
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys C258F79DCC02E369
sudo apt-get update -qq
2018-06-11 01:58:48 +00:00
fi
2021-04-24 04:55:51 +00:00
echo
2021-04-24 11:08:56 +00:00
echo "[+] Installing ArchiveBox system dependencies using apt..."
2024-02-18 13:21:27 +00:00
sudo apt-get install -y git python3 python3-pip python3-distutils wget curl yt-dlp ffmpeg git nodejs npm ripgrep
2021-04-24 11:08:56 +00:00
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
2021-04-24 03:43:41 +00:00
sudo apt-get install -y archivebox
sudo apt-get --only-upgrade install -y archivebox
2024-02-18 13:27:17 +00:00
echo
echo "[+] Installing ArchiveBox python dependencies using pip3..."
2024-02-18 13:21:27 +00:00
sudo python3 -m pip install --upgrade --ignore-installed archivebox yt-dlp playwright
2018-06-11 01:58:48 +00:00
# On Mac:
2021-04-24 03:43:41 +00:00
elif which brew > /dev/null; then
2021-04-24 11:08:56 +00:00
echo "[+] Installing ArchiveBox system dependencies using brew..."
2021-04-24 03:43:41 +00:00
brew tap archivebox/archivebox
brew update
2024-02-18 13:21:27 +00:00
brew install python3 node git wget curl yt-dlp ripgrep
2021-04-24 03:43:41 +00:00
brew install --fetch-HEAD -f archivebox
2024-02-18 13:27:17 +00:00
echo
echo "[+] Installing ArchiveBox python dependencies using pip3..."
2024-02-18 13:21:27 +00:00
python3 -m pip install --upgrade --ignore-installed archivebox yt-dlp playwright
2021-04-24 06:26:25 +00:00
elif which pkg > /dev/null; then
echo "[+] Installing ArchiveBox system dependencies using pkg and pip (python3.9)..."
sudo pkg install -y python3 py39-pip py39-sqlite3 npm wget curl youtube_dl ffmpeg git ripgrep
2021-04-24 07:21:22 +00:00
sudo pkg install -y chromium
2024-02-18 13:27:17 +00:00
echo
echo "[+] Installing ArchiveBox python dependencies using pip..."
# don't use sudo here so that pip installs in $HOME/.local instead of into /usr/local
2024-02-18 13:21:27 +00:00
python3 -m pip install --upgrade --ignore-installed archivebox yt-dlp playwright
2018-06-11 01:58:48 +00:00
else
2021-04-24 06:54:18 +00:00
echo "[!] Warning: Could not find aptitude/homebrew/pkg! May not be able to install all dependencies automatically."
2024-02-18 13:27:17 +00:00
echo
2018-06-11 01:58:48 +00:00
echo " If you're on macOS, make sure you have homebrew installed: https://brew.sh/"
2021-04-24 06:54:18 +00:00
echo " If you're on Linux, only Ubuntu/Debian/BSD systems are officially supported with this script."
echo " If you're on Windows, this script is not officially supported (Docker is recommeded instead)."
2024-02-18 13:27:17 +00:00
echo
2021-04-24 03:43:41 +00:00
echo "See the README.md for Manual Setup & Troubleshooting instructions if you you're unable to run ArchiveBox after this script completes."
2018-06-11 01:58:48 +00:00
fi
2024-02-18 13:27:17 +00:00
echo
2021-04-24 11:08:56 +00:00
if ! (python3 --version && python3 -m pip --version && python3 -m django --version); then
2021-04-24 06:40:45 +00:00
echo "[X] Python 3 pip was not found on your system!"
echo " You must first install Python >= 3.7 (and pip3):"
echo " https://www.python.org/downloads/"
echo " https://wiki.python.org/moin/BeginnersGuide/Download"
echo " After installing, run this script again."
exit 1
fi
2024-02-18 13:46:53 +00:00
if ! (python3 -m django --version && python3 -m pip show archivebox && which -a archivebox); then
2021-04-24 11:08:56 +00:00
echo "[X] Django and ArchiveBox were not found after installing!"
echo " Check to see if a previous step failed."
2024-02-18 13:27:17 +00:00
echo
2021-04-24 11:08:56 +00:00
exit 1
fi
2024-02-18 13:27:17 +00:00
# echo
2021-04-24 06:54:18 +00:00
# echo "[+] Upgrading npm and pip..."
# sudo npm i -g npm || true
# sudo python3 -m pip install --upgrade pip setuptools || true
2021-01-22 18:41:16 +00:00
2024-02-18 13:27:17 +00:00
echo
echo "[+] Installing Chromium binary using playwright..."
2024-02-18 13:40:30 +00:00
python3 -m playwright install --with-deps chromium || true
2024-02-18 13:27:17 +00:00
echo
2021-04-24 04:55:51 +00:00
echo
2024-02-18 13:21:27 +00:00
echo "[+] Initializing ArchiveBox data folder at ~/archivebox/data..."
mkdir -p ~/archivebox/data
2021-04-24 03:43:41 +00:00
cd ~/archivebox
2024-02-18 13:21:27 +00:00
if [ -f "./index.sqlite3" ]; then
mv -i ~/archivebox/* ~/archivebox/data/
2021-04-24 04:06:07 +00:00
fi
2024-02-18 13:21:27 +00:00
cd ./data
2021-04-24 06:54:18 +00:00
: | python3 -m archivebox init --setup || true # pipe in empty command to make sure stdin is closed
2024-02-18 13:40:30 +00:00
# init shows version output at the end too
2021-04-24 04:55:51 +00:00
echo
echo "[+] Starting ArchiveBox server using: nohup archivebox server &..."
2021-04-24 06:54:18 +00:00
nohup python3 -m archivebox server 0.0.0.0:8000 > ./logs/server.log 2>&1 &
2021-04-24 04:23:14 +00:00
sleep 7
2024-02-18 13:21:27 +00:00
which open > /dev/null && open "http://127.0.0.1:8000" || true
2021-04-24 04:55:51 +00:00
echo
2024-02-18 13:21:27 +00:00
echo "[√] Server started on http://0.0.0.0:8000 and data directory initialized in ~/archivebox/data. Usage:"
echo " cd ~/archivebox/data # see your data dir"
2024-02-18 13:40:30 +00:00
echo " archivebox server --quick-init 0.0.0.0:8000 # start server process"
echo " archivebox manage createsuperuser # add an admin user+pass"
2024-01-17 02:15:14 +00:00
echo " ps aux | grep archivebox # see server process pid"
echo " pkill -f archivebox # stop the server"
echo " pip install --upgrade archivebox; archivebox init # update versions"
echo " archivebox add 'https://example.com'" # archive a new URL
echo " archivebox list # see URLs archived"
echo " archivebox help # see more help & examples"