Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arch linux support for installer script #223

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Head over to the [AT Protocol PDS Admins Discord](https://discord.gg/e7hpHxRfBP)
* [Open your cloud firewall for HTTP and HTTPS](#open-your-cloud-firewall-for-http-and-https)
* [Configure DNS for your domain](#configure-dns-for-your-domain)
* [Check that DNS is working as expected](#check-that-dns-is-working-as-expected)
* [Installer on Ubuntu 20.04/22.04 and Debian 11/12](#installer-on-ubuntu-20042204-and-debian-1112)
* [Installer on Ubuntu 20.04/22.04, Debian 11/12, and Arch Linux](#installer-on-ubuntu-20042204-debian-1112-and-arch-linux)
* [Verifying that your PDS is online and accessible](#verifying-that-your-pds-is-online-and-accessible)
* [Creating an account using pdsadmin](#creating-an-account-using-pdsadmin)
* [Creating an account using an invite code](#creating-an-account-using-an-invite-code)
Expand Down Expand Up @@ -130,7 +130,7 @@ Examples to check (record type `A`):

These should all return your server's public IP.

### Installer on Ubuntu 20.04/22.04 and Debian 11/12
### Installer on Ubuntu 20.04/22.04, Debian 11/12, and Arch Linux

On your server via ssh, download the installer script using wget:

Expand Down
130 changes: 95 additions & 35 deletions installer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@ REQUIRED_SYSTEM_PACKAGES="
sqlite3
xxd
"

# System dependencies for Arch Linux
REQUIRED_SYSTEM_PACKAGES_ARCH="
ca-certificates
curl
gnupg
jq
lsb-release
openssl
sqlite
"

# Docker packages.
REQUIRED_DOCKER_PACKAGES="
containerd.io
Expand All @@ -40,6 +52,12 @@ REQUIRED_DOCKER_PACKAGES="
docker-compose-plugin
"

# Docker packages for Arch Linux
REQUIRED_DOCKER_PACKAGES_ARCH="
docker
docker-compose
"

PUBLIC_IP=""
METADATA_URLS=()
METADATA_URLS+=("http://169.254.169.254/v1/interfaces/0/ipv4/address") # Vultr
Expand Down Expand Up @@ -86,6 +104,7 @@ function main {

# Check for a supported distribution.
SUPPORTED_OS="false"
IS_ARCH="false"
if [[ "${DISTRIB_ID}" == "ubuntu" ]]; then
if [[ "${DISTRIB_CODENAME}" == "focal" ]]; then
SUPPORTED_OS="true"
Expand All @@ -105,10 +124,14 @@ function main {
SUPPORTED_OS="true"
echo "* Detected supported distribution Debian 12"
fi
elif [[ "${DISTRIB_ID}" == "arch" ]] || [[ "$(grep -i 'arch linux' /etc/os-release || true)" ]]; then
SUPPORTED_OS="true"
IS_ARCH="true"
echo "* Detected supported distribution Arch Linux"
fi

if [[ "${SUPPORTED_OS}" != "true" ]]; then
echo "Sorry, only Ubuntu 20.04, 22.04, Debian 11 and Debian 12 are supported by this installer. Exiting..."
echo "Sorry, only Ubuntu 20.04, 22.04, Debian 11, Debian 12, and Arch Linux are supported by this installer. Exiting..."
exit 1
fi

Expand Down Expand Up @@ -145,11 +168,19 @@ function main {
# Attempt to determine server's public IP.
#

# First try using the hostname command, which usually works.
# Get IP addresses using a cross-platform approach - use ip command if available, fall back to ifconfig
if [[ -z "${PUBLIC_IP}" ]]; then
PUBLIC_IP=$(hostname --all-ip-addresses | awk '{ print $1 }')
if command -v ip >/dev/null 2>&1; then
PUBLIC_IP=$(ip -4 addr show scope global | grep -oP '(?<=inet\s)\d+(\.\d+){3}' | head -n1)
elif command -v ifconfig >/dev/null 2>&1; then
PUBLIC_IP=$(ifconfig | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1' | head -n1)
elif [[ "${IS_ARCH}" == "false" ]] && command -v hostname >/dev/null 2>&1; then
# Try hostname command with --all-ip-addresses flag (Debian/Ubuntu only)
PUBLIC_IP=$(hostname --all-ip-addresses 2>/dev/null | awk '{ print $1 }' || true)
fi
fi


# Prevent any private IP address from being used, since it won't work.
if [[ "${PUBLIC_IP}" =~ ^(127\.|10\.|172\.1[6-9]\.|172\.2[0-9]\.|172\.3[0-1]\.|192\.168\.) ]]; then
PUBLIC_IP=""
Expand Down Expand Up @@ -231,58 +262,87 @@ INSTALLER_MESSAGE
#
# Install system packages.
#
if lsof -v >/dev/null 2>&1; then
while true; do
apt_process_count="$(lsof -n -t /var/cache/apt/archives/lock /var/lib/apt/lists/lock /var/lib/dpkg/lock | wc --lines || true)"
if (( apt_process_count == 0 )); then
break
fi
echo "* Waiting for other apt process to complete..."
sleep 2
done
fi
if [[ "${IS_ARCH}" == "true" ]]; then
echo "* Installing system packages for Arch Linux"
# Check if pacman is already running
if [[ -f /var/lib/pacman/db.lck ]]; then
echo "* Waiting for other pacman process to complete..."
while [[ -f /var/lib/pacman/db.lck ]]; do
sleep 2
done
fi

# Install system packages for Arch
pacman -Sy --noconfirm ${REQUIRED_SYSTEM_PACKAGES_ARCH}
else
if lsof -v >/dev/null 2>&1; then
while true; do
apt_process_count="$(lsof -n -t /var/cache/apt/archives/lock /var/lib/apt/lists/lock /var/lib/dpkg/lock | wc --lines || true)"
if (( apt_process_count == 0 )); then
break
fi
echo "* Waiting for other apt process to complete..."
sleep 2
done
fi

apt-get update
apt-get install --yes ${REQUIRED_SYSTEM_PACKAGES}
apt-get update
apt-get install --yes ${REQUIRED_SYSTEM_PACKAGES}
fi

#
# Install Docker
#
if ! docker version >/dev/null 2>&1; then
echo "* Installing Docker"
mkdir --parents /etc/apt/keyrings

# Remove the existing file, if it exists,
# so there's no prompt on a second run.
rm --force /etc/apt/keyrings/docker.gpg
curl --fail --silent --show-error --location "https://download.docker.com/linux/${DISTRIB_ID}/gpg" | \
gpg --dearmor --output /etc/apt/keyrings/docker.gpg
if [[ "${IS_ARCH}" == "true" ]]; then
# Install Docker on Arch Linux
pacman -Sy --noconfirm ${REQUIRED_DOCKER_PACKAGES_ARCH}

echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/${DISTRIB_ID} ${DISTRIB_CODENAME} stable" >/etc/apt/sources.list.d/docker.list
# Start and enable Docker service
systemctl enable docker.service
systemctl start docker.service
else
mkdir --parents /etc/apt/keyrings

apt-get update
apt-get install --yes ${REQUIRED_DOCKER_PACKAGES}
# Remove the existing file, if it exists,
# so there's no prompt on a second run.
rm --force /etc/apt/keyrings/docker.gpg
curl --fail --silent --show-error --location "https://download.docker.com/linux/${DISTRIB_ID}/gpg" | \
gpg --dearmor --output /etc/apt/keyrings/docker.gpg

echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/${DISTRIB_ID} ${DISTRIB_CODENAME} stable" >/etc/apt/sources.list.d/docker.list

apt-get update
apt-get install --yes ${REQUIRED_DOCKER_PACKAGES}
fi
fi

#
# Configure the Docker daemon so that logs don't fill up the disk.
#
if ! [[ -e /etc/docker/daemon.json ]]; then
echo "* Configuring Docker daemon"
cat <<'DOCKERD_CONFIG' >/etc/docker/daemon.json
# Configure Docker daemon for log rotation
if [ ! -d /etc/docker ]; then
mkdir -p /etc/docker
echo "* Created /etc/docker directory"
fi

if [ ! -e /etc/docker/daemon.json ]; then
echo "* Configuring Docker daemon"
cat <<'DOCKERD_CONFIG' >/etc/docker/daemon.json
{
"log-driver": "json-file",
"log-opts": {
"max-size": "500m",
"max-file": "4"
}
"log-driver": "json-file",
"log-opts": {
"max-size": "500m",
"max-file": "4"
}
}
DOCKERD_CONFIG
systemctl restart docker
systemctl restart docker
else
echo "* Docker daemon already configured! Ensure log rotation is enabled."
echo "* Docker daemon already configured! Ensure log rotation is enabled."
fi

#
# Create data directory.
#
Expand Down