#!/usr/bin/env bash DIRNAME=$(dirname "$0") BINDIR="${DIRNAME}/bin" download_binary() { echo "downloading launcher..." package="${BINDIR}/launcher.tar.gz" package_md5="${BINDIR}/launcher.tar.gz.md5" arch=none case $(uname -m) in aarch64 | arm64) arch=arm64 ;; x86_64) arch=amd64 ;; *) echo "ERROR: unsupported arch detected." exit 1 ;; esac os=none case $(uname -o) in Darwin) os=darwin ;; GNU/Linux) os=linux ;; *) echo "ERROR: unsupported os detected." exit 1 ;; esac curl -s -o ${package} -L https://get.discourse.org/launcher/latest/launcher-${os}-${arch}.tar.gz curl -s -o ${package_md5} -L https://get.discourse.org/launcher/latest/launcher-${os}-${arch}.tar.gz.md5 tar -zxf ${package} -C ${BINDIR} rm ${package} ${package_md5} } # From https://stackoverflow.com/a/44660519/702738 compare_version() { if [[ $1 == $2 ]]; then return 1 fi local IFS=. local i a=(${1%%[^0-9.]*}) b=(${2%%[^0-9.]*}) local arem=${1#${1%%[^0-9.]*}} brem=${2#${2%%[^0-9.]*}} for ((i=0; i<${#a[@]} || i<${#b[@]}; i++)); do if ((10#${a[i]:-0} < 10#${b[i]:-0})); then return 1 elif ((10#${a[i]:-0} > 10#${b[i]:-0})); then return 0 fi done if [ "$arem" '<' "$brem" ]; then return 1 elif [ "$arem" '>' "$brem" ]; then return 0 fi return 1 } check_prereqs() { docker_path=`which docker.io 2> /dev/null || which docker` git_path=`which git` docker_min_version='20.10.0' docker_rec_version='24.0.7' git_min_version='1.8.0' git_rec_version='1.8.0' kernel_min_version='4.4.0' if [ -z $docker_path ]; then echo "Docker is not installed, you will need to install Docker in order to run Launcher" echo "See https://docs.docker.com/installation/" exit 1 fi # 1. docker daemon running? # we send stderr to /dev/null cause we don't care about warnings, # it usually complains about swap which does not matter test=`$docker_path info 2> /dev/null` if [[ $? -ne 0 ]] ; then echo "Cannot connect to the docker daemon - verify it is running and you have access" exit 1 fi # 2. running an approved storage driver? if ! $docker_path info 2> /dev/null | grep -E -q 'Storage Driver: (btrfs|aufs|zfs|overlay2|overlayfs)$'; then echo "Your Docker installation is not using a supported storage driver. If we were to proceed you may have a broken install." echo "overlay2 is the recommended storage driver, although zfs and aufs may work as well." echo "Other storage drivers are known to be problematic." echo "You can tell what filesystem you are using by running \"docker info\" and looking at the 'Storage Driver' line." echo echo "If you wish to continue anyway using your existing unsupported storage driver," echo "read the source code of launcher and figure out how to bypass this check." exit 1 fi # 3. running recommended docker version test=($($docker_path --version)) # Get docker version string test=${test[2]//,/} # Get version alone and strip comma if exists # At least minimum docker version if compare_version "${docker_min_version}" "${test}"; then echo "ERROR: Docker version ${test} not supported, please upgrade to at least ${docker_min_version}, or recommended ${docker_rec_version}" exit 1 fi # Recommend newer docker version if compare_version "${docker_rec_version}" "${test}"; then echo "WARNING: Docker version ${test} deprecated, recommend upgrade to ${docker_rec_version} or newer." fi case $(uname -m) in armv7l) echo "ERROR: 32bit arm is not supported. Check if your hardware support arm64, which is supported in experimental capacity." exit 1 ;; aarch64 | arm64) echo "WARNING: Support for aarch64 is experimental at the moment. Please report any problems at https://meta.discourse.org/tag/arm" ;; x86_64) echo "x86_64 arch detected." ;; *) echo "ERROR: unknown arch detected." exit 1 ;; esac # 4. discourse docker image is downloaded test=`$docker_path images | awk '{print $1 ":" $2 }' | grep "$image"` # 5. running recommended git version test=($($git_path --version)) # Get git version string test=${test[2]//,/} # Get version alone and strip comma if exists # At least minimum version if compare_version "${git_min_version}" "${test}"; then echo "ERROR: Git version ${test} not supported, please upgrade to at least ${git_min_version}, or recommended ${git_rec_version}" exit 1 fi # Recommend best version if compare_version "${git_rec_version}" "${test}"; then echo "WARNING: Git version ${test} deprecated, recommend upgrade to ${git_rec_version} or newer." fi # Check minimum kernel version due to https://bugs.ruby-lang.org/issues/13885 test=($(uname -r)) # At least minimum version if compare_version "${kernel_min_version}" "${test}"; then echo "ERROR: Kernel version ${test} not supported, please upgrade to at least ${kernel_min_version}" exit 1 fi # 6. able to attach stderr / out / tty test=`$docker_path run -i --rm -a stdout -a stderr hello-world` if [[ "$test" =~ "Hello from Docker" ]] ; then : ; else echo "Your Docker installation is not working correctly" echo echo "See: https://meta.discourse.org/t/docker-error-on-bootstrap/13657/18?u=sam" exit 1 fi # 7. enough space for the bootstrap on docker folder folder=`$docker_path info --format '{{.DockerRootDir}}'` safe_folder=${folder:-/var/lib/docker} if [[ -d $safe_folder && $(stat -f --format="%a*%S" $safe_folder)/1024**3 -lt 5 ]] ; then echo "You have less than 5GB of free space on the disk where $safe_folder is located. You will need more space to continue" df -h $safe_folder echo if tty >/dev/null; then read -p "Would you like to attempt to recover space by cleaning docker images and containers in the system? (y/N)" -n 1 -r echo if [[ $REPLY =~ ^[Yy]$ ]] then $docker_path container prune --force --filter until=24h >/dev/null $docker_path image prune --all --force --filter until=24h >/dev/null echo "If the cleanup was successful, you may try again now" fi fi exit 1 fi } autocompletion=false if [[ $1 == "sh" ]] || [[ $1 == "install-completions" ]]; then autocompletion=true fi if [[ autocompletion == false ]]; then echo "run './launcher update' to update launcher" fi if [[ $1 == "update" ]]; then rm ${BINDIR}/launcher download_binary echo "Launcher updated" exit 0 fi if [ ! -f "${BINDIR}/launcher" ]; then download_binary if [[ autocompletion == false ]]; then echo "Launcher downloaded" fi fi exec "${BINDIR}/launcher" "$@"