From 8b3f47308fb8d282f1b80dd0c7db5b534eb8aab5 Mon Sep 17 00:00:00 2001 From: Thorrak Date: Sun, 22 Nov 2020 09:44:38 -0500 Subject: [PATCH] Finish migrating legacy installation to non_docker_install --- automated_install/auto-docker-install.sh | 184 --------------- automated_install/auto-install.sh | 170 ++++++-------- install-docker.sh => install.sh | 24 +- .../auto-install-legacy-apps.sh | 0 non_docker_install/auto-install.sh | 222 ++++++++++++++++++ ...roduction.yml => sample.docker-compose.yml | 0 6 files changed, 295 insertions(+), 305 deletions(-) delete mode 100755 automated_install/auto-docker-install.sh rename install-docker.sh => install.sh (93%) rename automated_install/auto-install-legacy.sh => non_docker_install/auto-install-legacy-apps.sh (100%) create mode 100755 non_docker_install/auto-install.sh rename sample.production.yml => sample.docker-compose.yml (100%) diff --git a/automated_install/auto-docker-install.sh b/automated_install/auto-docker-install.sh deleted file mode 100755 index a0dfd83..0000000 --- a/automated_install/auto-docker-install.sh +++ /dev/null @@ -1,184 +0,0 @@ -#!/usr/bin/env bash - -# auto-install.sh -# -# This script attempts to automatically download fermentrack-tools and use install.sh to install Fermentrack. -# It can be run via curl (See install_curl_command below) which enables the user to install everything with one -# command. - -# Fermentrack is free software, and is distributed under the terms of the MIT license. -# A copy of the MIT license should be included with Fermentrack. If not, a copy can be -# reviewed at - -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. - -package_name="Fermentrack" -install_curl_url="install.fermentrack.com" -install_script_name="install-docker.sh" -install_curl_command="curl -L $install_curl_url | sudo bash" -tools_name="fermentrack-tools" -tools_repo_url="https://github.com/thorrak/fermentrack-tools.git" - -# Set scriptPath to the current script path -unset CDPATH -scriptPath="$( cd "$( dirname "${BASH_SOURCE[0]}")" && pwd )" - - - -####### -#### Error capturing functions - Originally from http://mywiki.wooledge.org/BashFAQ/101 -####### -warn() { - local fmt="$1" - command shift 2>/dev/null - echo -e "$fmt\n" "${@}" - echo -e "\n*** ERROR ERROR ERROR ERROR ERROR ***\n----------------------------------\nSee above lines for error message\nSetup NOT completed\n" -} - -die () { - local st="$?" - warn "$@" - exit "$st" -} - - -####### -#### Compatibility checks & tests -####### -exit_if_pi_zero() { - # Pi Zero string (armv6l) - # Linux dockerzero 5.4.51+ #1333 Mon Aug 10 16:38:02 BST 2020 armv6l GNU/Linux - if uname -a | grep -q 'armv6l'; then - # I tried supporting armv6l pis, but they're too slow (or otherwise don't work) - die "This is an armv6l Pi (e.g. Pi Zero, Zero W, or Original RPi) which isn't capable of running Fermentrack. Exiting." - fi -} - -verifyRunAsRoot() { - # verifyRunAsRoot does two things - First, it checks if the script was run by a root user. Assuming it wasn't, - # it prompts the user to relaunch as root. - - echo ":: Checking user" - - if [[ ${EUID} -eq 0 ]]; then - echo "::: This script was launched as root. Although this used to be the recommended installation method," - echo "::: installs now recommend being launched under the standard user (generally 'pi' for Raspberry Pi" - echo "::: installations). If you wish to cancel this installation and relaunch as a different user, press" - echo "::: Ctrl+C now. If you wish to continue to install as 'root' wait 10 seconds and the script will" - echo "::: continue." - sleep 10s - else - echo "::: This script was called without root privileges, which is recommended. The script will, however," - echo "::: need root privileges periodically in order to install certain packages. Please be ready to" - echo "::: enter your password if prompted to allow installation to continue." - echo ":::" - fi - -} - -verifyFreeDiskSpace() { - echo ":: Verifying free disk space..." - local required_free_gigabytes=2 - local required_free_kilobytes=$(( required_free_gigabytes*1024000 )) - local existing_free_kilobytes=$(df -Pk | grep -m1 '\/$' | awk '{print $4}') - - # - Unknown free disk space , not a integer - if ! [[ "${existing_free_kilobytes}" =~ ^([0-9])+$ ]]; then - echo "::: Unknown free disk space!" - echo ":::: We were unable to determine available free disk space on this system." - exit 1 - # - Insufficient free disk space - elif [[ ${existing_free_kilobytes} -lt ${required_free_kilobytes} ]]; then - echo "::: Insufficient Disk Space!" - echo ":::: Your system appears to be low on disk space. ${package_name} recommends a minimum of $required_free_gigabytes GB." - echo ":::: After freeing up space, run this installation script again. (${install_curl_command})" - echo "Insufficient free space, exiting..." - exit 1 - fi - - echo "::: Sufficent free space for installation" -} - -####### -#### Installation functions -####### - -# getAptPackages runs apt-get update, and installs the basic packages we need to continue the Fermentrack install -# (git and build-essential). The rest can be installed by fermentrack-tools/install.sh -getAptPackages() { - echo -e ":: Installing dependencies using apt-get" - lastUpdate=$(stat -c %Y /var/lib/apt/lists) - nowTime=$(date +%s) - if [ $(($nowTime - $lastUpdate)) -gt 604800 ] ; then - echo "::: Last 'apt-get update' was awhile back. Updating now." - sudo apt-get update &> /dev/null||die - echo ":::: 'apt-get update' ran successfully." - fi - - echo "::: installing git and build-essential." - echo "::: (This may take a few minutes during which everything will be silent)" - sudo apt-get install -y git build-essential &> /dev/null || die - echo ":::: All packages installed successfully." -} - - -cloneFromGit() { - echo -e ":: Cloning ${tools_name} repo from GitHub into ${scriptPath}/${tools_name}" - - if [ -f "./${tools_name}/$install_script_name" ]; then - echo -e "::: Existing instance of ${tools_name} found at ${scriptPath}/${tools_name}" - echo -e "::: Pulling from Git rather than re-cloning" - cd ${tools_name} || die "Unable to cd to $tools_name" - git fetch &> /dev/null - # TODO - Strip out the next line when all this is merged into master - git checkout docker &> /dev/null - git pull &> /dev/null - cd .. - echo -e ":::: Pull from Git was successful" - else - git clone ${tools_repo_url} "${tools_name}" -q &> /dev/null||die "Unable to clone from GitHub" - # TODO - remove this when everything is merged into master - cd ${tools_name} || die "Unable to cd to $tools_name" - git checkout docker &> /dev/null - git pull &> /dev/null - cd .. - echo "::: Repo was cloned successfully." - fi - - -} - - -launchInstall() { - echo -e ":: This script will now attempt to install ${package_name} using the script that has been created at" - echo -e "::: ${scriptPath}/${tools_name}/${install_script_name}" - echo -e "::: If the install script does not complete successfully, please relaunch the script above directly." - echo -e "::: " - echo -e ":::: Launching ${package_name} installer." - cd ${tools_name} || die "Unable to launch ${install_script_name}!" - # The -n flag makes the install script non-interactive - #bash ./$install_script_name -n - exec "./${install_script_name}" - echo -e "::: Automated installation script has now finished. If installation did not complete successfully please" - echo -e "::: relaunch the installation script which has been downloaded at:" - echo -e "::: ${scriptPath}/${tools_name}/${install_script_name}" -} - -####### -### Now, for the main event... -####### -echo "" -echo "<<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>>" - -exit_if_pi_zero -verifyRunAsRoot -verifyFreeDiskSpace -getAptPackages -cloneFromGit -launchInstall diff --git a/automated_install/auto-install.sh b/automated_install/auto-install.sh index 79e97f7..12ab770 100755 --- a/automated_install/auto-install.sh +++ b/automated_install/auto-install.sh @@ -51,45 +51,58 @@ die () { ####### #### Compatibility checks & tests ####### +exit_if_pi_zero() { + # Pi Zero string (armv6l) + # Linux dockerzero 5.4.51+ #1333 Mon Aug 10 16:38:02 BST 2020 armv6l GNU/Linux + if uname -a | grep -q 'armv6l'; then + # I tried supporting armv6l pis, but they're too slow (or otherwise don't work) + die "This is an armv6l Pi (e.g. Pi Zero, Zero W, or Original RPi) which isn't capable of running Fermentrack. Exiting." + fi +} + verifyRunAsRoot() { # verifyRunAsRoot does two things - First, it checks if the script was run by a root user. Assuming it wasn't, # it prompts the user to relaunch as root. + echo ":: Checking user" + if [[ ${EUID} -eq 0 ]]; then - echo "::: This script was launched as root. Continuing installation." + echo "::: This script was launched as root. Although this used to be the recommended installation method," + echo "::: installs now recommend being launched under the standard user (generally 'pi' for Raspberry Pi" + echo "::: installations). If you wish to cancel this installation and relaunch as a different user, press" + echo "::: Ctrl+C now. If you wish to continue to install as 'root' wait 10 seconds and the script will" + echo "::: continue." + sleep 10s else - echo "::: This script was called without root privileges, which are required as it installs and updates several" - echo "::: packages, and the script it calls within ${tools_name} creates user accounts and updates system" - echo "::: settings. To continue, this script must launched using the 'sudo' command to run as root. Please check" - echo "::: the contents of this script (as well as the install script within ${tools_name}) for any concerns with" - echo "::: this requirement. Please be sure to access this script (and ${tools_name}) from a trusted source." + echo "::: This script was called without root privileges, which is recommended. The script will, however," + echo "::: need root privileges periodically in order to install certain packages. Please be ready to" + echo "::: enter your password if prompted to allow installation to continue." echo ":::" - echo "::: To re-run this script with sudo permissions, type:" - echo "::: sudo $install_curl_command" - exit 1 fi } verifyFreeDiskSpace() { - echo "::: Verifying free disk space..." - local required_free_kilobytes=512000 + echo ":: Verifying free disk space..." + local required_free_gigabytes=2 + local required_free_kilobytes=$(( required_free_gigabytes*1024000 )) local existing_free_kilobytes=$(df -Pk | grep -m1 '\/$' | awk '{print $4}') # - Unknown free disk space , not a integer if ! [[ "${existing_free_kilobytes}" =~ ^([0-9])+$ ]]; then - echo ":: Unknown free disk space!" - echo ":: We were unable to determine available free disk space on this system." + echo "::: Unknown free disk space!" + echo ":::: We were unable to determine available free disk space on this system." exit 1 # - Insufficient free disk space elif [[ ${existing_free_kilobytes} -lt ${required_free_kilobytes} ]]; then - echo ":: Insufficient Disk Space!" - echo ":: Your system appears to be low on disk space. ${package_name} recommends a minimum of $required_free_kilobytes KB." - echo ":: You only have ${existing_free_kilobytes} KB free." - echo ":: After freeing up space, run this installation script again. (${install_curl_command})" + echo "::: Insufficient Disk Space!" + echo ":::: Your system appears to be low on disk space. ${package_name} recommends a minimum of $required_free_gigabytes GB." + echo ":::: After freeing up space, run this installation script again. (${install_curl_command})" echo "Insufficient free space, exiting..." exit 1 fi + + echo "::: Sufficent free space for installation" } ####### @@ -97,113 +110,61 @@ verifyFreeDiskSpace() { ####### # getAptPackages runs apt-get update, and installs the basic packages we need to continue the Fermentrack install -# (git-core, build-essential, python-dev, python-virtualenv). The rest can be installed by fermentrack-tools/install.sh +# (git and build-essential). The rest can be installed by fermentrack-tools/install.sh getAptPackages() { - echo -e "::: Installing dependencies using apt-get" + echo -e ":: Installing dependencies using apt-get" lastUpdate=$(stat -c %Y /var/lib/apt/lists) nowTime=$(date +%s) if [ $(($nowTime - $lastUpdate)) -gt 604800 ] ; then - echo "::: Last 'apt-get update' was awhile back. Updating now." - sudo apt-get update &> /dev/null||die - echo ":: 'apt-get update' ran successfully." + echo "::: Last 'apt-get update' was awhile back. Updating now." + sudo apt-get update &> /dev/null||die + echo ":::: 'apt-get update' ran successfully." fi - sudo apt-key update &> /dev/null||die - echo "::: 'apt-key update' ran successfully." - - # Installing the nginx stack along with everything we need for circus, etc. - echo "::: apt is updated - installing git-core and build-essential." + echo "::: installing git and build-essential." echo "::: (This may take a few minutes during which everything will be silent)" - sudo apt-get install -y git-core build-essential &> /dev/null || die - echo ":: All packages installed successfully." + sudo apt-get install -y git build-essential &> /dev/null || die + echo ":::: All packages installed successfully." } -handleExistingTools() { - echo -e ":::: Existing instance of ${tools_name} found at ${scriptPath}/${tools_name}" - echo -e ":::: Moving to ${scriptPath}/${tools_name}.old/" - rm -r ${tools_name}.old &> /dev/null - mv ${tools_name} ${tools_name}.old||die - echo -e ":::: Moved successfully. Reattempting clone." - git clone ${tools_repo_url} "${tools_name}" -q &> /dev/null||die - # TODO - remove this when everything is merged into master - cd ${tools_name} || die "Unable to cd to $tools_name" - git checkout docker &> /dev/null - git pull &> /dev/null - cd .. -} cloneFromGit() { - echo -e "::: Cloning ${tools_name} repo from GitHub into ${scriptPath}/${tools_name}" - git clone ${tools_repo_url} "${tools_name}" -q &> /dev/null||handleExistingTools - # TODO - remove this when everything is merged into master - cd ${tools_name} || die "Unable to cd to $tools_name" - git checkout docker &> /dev/null - git pull &> /dev/null - cd .. - echo ":: Repo was cloned successfully." -} + echo -e ":: Cloning ${tools_name} repo from GitHub into ${scriptPath}/${tools_name}" + + if [ -f "./${tools_name}/$install_script_name" ]; then + echo -e "::: Existing instance of ${tools_name} found at ${scriptPath}/${tools_name}" + echo -e "::: Pulling from Git rather than re-cloning" + cd ${tools_name} || die "Unable to cd to $tools_name" + git fetch &> /dev/null + # TODO - Strip out the next line when all this is merged into master + git checkout docker &> /dev/null + git pull &> /dev/null + cd .. + echo -e ":::: Pull from Git was successful" + else + git clone ${tools_repo_url} "${tools_name}" -q &> /dev/null||die "Unable to clone from GitHub" + # TODO - remove this when everything is merged into master + cd ${tools_name} || die "Unable to cd to $tools_name" + git checkout docker &> /dev/null + git pull &> /dev/null + cd .. + echo "::: Repo was cloned successfully." + fi -installPython() { - echo "Installing Python 3.7.7" - echo -e "Warning - This may take several hours to complete, depending on your Pi version" - echo -e "Let it do its thing. This is important." - cd ~ || exit - sudo apt-get update -y - sudo apt-get install -y build-essential tk-dev libncurses5-dev libncursesw5-dev libreadline6-dev libdb5.3-dev libgdbm-dev libsqlite3-dev libssl-dev libbz2-dev libexpat1-dev liblzma-dev zlib1g-dev libffi-dev - sudo apt-get install -y make libreadline-dev wget curl llvm xz-utils libxml2-dev libxmlsec1-dev libzmq5-dev - wget https://www.python.org/ftp/python/3.7.7/Python-3.7.7.tar.xz - tar xf Python-3.7.7.tar.xz - cd Python-3.7.7 || exit - ./configure - make -j 4 - sudo make altinstall - cd .. - rm Python-3.7.7.tar.xz - sudo apt-get --purge remove tk-dev libncurses5-dev libncursesw5-dev libreadline6-dev libdb5.3-dev libgdbm-dev libsqlite3-dev libssl-dev libbz2-dev libexpat1-dev liblzma-dev zlib1g-dev libffi-dev -y - sudo apt-get autoremove -y - sudo apt-get clean } -checkPython37() { - if command -v python3.7 &> /dev/null; then - # Python 3.7 is installed. No need to reinstall python manually - echo "Python 3.7 is installed. Continuing." - else - echo "Python 3.7 is NOT installed, but is required for Fermentrack. This generally means" - echo "that you are running an older version of Raspbian. Fermentrack recommends Raspbian" - echo "Buster or later." - echo "" - echo "Although the installation script can manually install Python 3.7, it is *highly*" - echo "recommended that you upgrade your version of Raspbian instead. Installing on this" - echo "version of Raspbian may take several hours longer than an installation on Buster." - echo "" - echo "To stop installation here, press Ctrl+C. Installation will otherwise continue in 10 seconds." - - sleep 11s - - # This script is almost always run non-interactively, so we can't solicit feedback here -# read -p "Do you want to manually install Python 3.7 and continue installing Fermentrack? [y/N] " yn -# case "$yn" in -# y | Y | yes | YES | Yes ) printinfo "Ok, let's go!";; -# * ) exit;; -# esac - - installPython - fi -} launchInstall() { - echo "::: This script will now attempt to install ${package_name} using the script that has been created at" + echo -e ":: This script will now attempt to install ${package_name} using the script that has been created at" echo -e "::: ${scriptPath}/${tools_name}/${install_script_name}" echo -e "::: If the install script does not complete successfully, please relaunch the script above directly." echo -e "::: " - echo -e "::: Launching ${package_name} installer." - cd ${tools_name} || exit 1 - cd non_docker_install + echo -e ":::: Launching ${package_name} installer." + cd ${tools_name} || die "Unable to launch ${install_script_name}!" # The -n flag makes the install script non-interactive - # TODO - strip out the -b docker - sudo bash ./$install_script_name -n -b docker + #bash ./$install_script_name -n + exec "./${install_script_name}" echo -e "::: Automated installation script has now finished. If installation did not complete successfully please" echo -e "::: relaunch the installation script which has been downloaded at:" echo -e "::: ${scriptPath}/${tools_name}/${install_script_name}" @@ -214,9 +175,10 @@ launchInstall() { ####### echo "" echo "<<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>>" + +exit_if_pi_zero verifyRunAsRoot verifyFreeDiskSpace getAptPackages -checkPython37 cloneFromGit launchInstall diff --git a/install-docker.sh b/install.sh similarity index 93% rename from install-docker.sh rename to install.sh index 4409ea7..fa2ad86 100755 --- a/install-docker.sh +++ b/install.sh @@ -135,14 +135,14 @@ docker_compose_down() { # docker_compose_down is a way for us to nuke an existing docker stack -JUST IN CASE-. if command -v docker-compose &> /dev/null; then # Docker compose exists - if [ -f "./production.yml" ]; then + if [ -f "./docker-compose.yml" ]; then # The docker-compose file also exists. The user is probably re-running the install script when (this is an existing installation) printwarn "Existing run of this installer detected." printinfo "This script will now attempt to shut down any previous installation of ${PACKAGE_NAME}" printinfo "before proceeding. To cancel this, press Ctrl+C in the next 5 seconds." sleep 5s printinfo "Shutting down previous installation..." - docker-compose -f production.yml down &>> install.log + docker-compose -f docker-compose.yml down &>> install.log printinfo "Previous installation shut down. Continuing with install." fi fi @@ -255,26 +255,16 @@ get_files_from_main_repo() { # Delete the docker compose files if they exist (we want to overwrite these) rm -rf ./compose/ - if [ -f "./production.yml" ]; then + if [ -f "./docker-compose.yml" ]; then # TODO - Warn the user on this - rm production.yml + rm docker-compose.yml fi # Download the relevant files from GitHub # TODO - Revert this once the files are merged to master (or alternatively dev) -# svn export https://github.com/thorrak/fermentrack/trunk/compose &>> install.log -# svn export https://github.com/thorrak/fermentrack/trunk/production.yml &>> install.log svn export https://github.com/thorrak/fermentrack/branches/docker/compose &>> install.log -# svn export https://github.com/thorrak/fermentrack/branches/docker/production.yml &>> install.log - # Rewrite production.yml -# if [ -f "./production.yml" ]; then -# sed -i "s+./.envs/.production/.+./envs/+g" production.yml -# sed -i "s+./compose/production/django/Dockerfile+./Dockerfile+g" production.yml -# else -# die "Unable to download production.yml from GitHub" -# fi - cp sample.production.yml production.yml + cp sample.docker-compose.yml docker-compose.yml } setup_django_env() { @@ -327,8 +317,8 @@ set_web_services_port() { sed -i "s+:80+:${PORT}+g" ./compose/production/nginx/nginx.conf fi - # Update the port mapping in production.yml (ignored if we're using net=host) - sed -i "s+80:80+${PORT}:80+g" production.yml + # Update the port mapping in docker-compose.yml (ignored if we're using net=host) + sed -i "s+80:80+${PORT}:80+g" docker-compose.yml } diff --git a/automated_install/auto-install-legacy.sh b/non_docker_install/auto-install-legacy-apps.sh similarity index 100% rename from automated_install/auto-install-legacy.sh rename to non_docker_install/auto-install-legacy-apps.sh diff --git a/non_docker_install/auto-install.sh b/non_docker_install/auto-install.sh new file mode 100755 index 0000000..df32cdb --- /dev/null +++ b/non_docker_install/auto-install.sh @@ -0,0 +1,222 @@ +#!/usr/bin/env bash + +# auto-install.sh +# +# This script attempts to automatically download fermentrack-tools and use install.sh to install Fermentrack. +# It can be run via curl (See install_curl_command below) which enables the user to install everything with one +# command. + +# Fermentrack is free software, and is distributed under the terms of the MIT license. +# A copy of the MIT license should be included with Fermentrack. If not, a copy can be +# reviewed at + +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +package_name="Fermentrack" +install_curl_url="install.fermentrack.com" +install_script_name="non_docker_install/install.sh" +install_curl_command="curl -L $install_curl_url | sudo bash" +tools_name="fermentrack-tools" +tools_repo_url="https://github.com/thorrak/fermentrack-tools.git" + +# Set scriptPath to the current script path +unset CDPATH +scriptPath="$( cd "$( dirname "${BASH_SOURCE[0]}")" && pwd )" + + + +####### +#### Error capturing functions - Originally from http://mywiki.wooledge.org/BashFAQ/101 +####### +warn() { + local fmt="$1" + command shift 2>/dev/null + echo -e "$fmt\n" "${@}" + echo -e "\n*** ERROR ERROR ERROR ERROR ERROR ***\n----------------------------------\nSee above lines for error message\nSetup NOT completed\n" +} + +die () { + local st="$?" + warn "$@" + exit "$st" +} + + +####### +#### Compatibility checks & tests +####### +verifyRunAsRoot() { + # verifyRunAsRoot does two things - First, it checks if the script was run by a root user. Assuming it wasn't, + # it prompts the user to relaunch as root. + + if [[ ${EUID} -eq 0 ]]; then + echo "::: This script was launched as root. Continuing installation." + else + echo "::: This script was called without root privileges, which are required as it installs and updates several" + echo "::: packages, and the script it calls within ${tools_name} creates user accounts and updates system" + echo "::: settings. To continue, this script must launched using the 'sudo' command to run as root. Please check" + echo "::: the contents of this script (as well as the install script within ${tools_name}) for any concerns with" + echo "::: this requirement. Please be sure to access this script (and ${tools_name}) from a trusted source." + echo ":::" + echo "::: To re-run this script with sudo permissions, type:" + echo "::: sudo $install_curl_command" + exit 1 + fi + +} + +verifyFreeDiskSpace() { + echo "::: Verifying free disk space..." + local required_free_kilobytes=512000 + local existing_free_kilobytes=$(df -Pk | grep -m1 '\/$' | awk '{print $4}') + + # - Unknown free disk space , not a integer + if ! [[ "${existing_free_kilobytes}" =~ ^([0-9])+$ ]]; then + echo ":: Unknown free disk space!" + echo ":: We were unable to determine available free disk space on this system." + exit 1 + # - Insufficient free disk space + elif [[ ${existing_free_kilobytes} -lt ${required_free_kilobytes} ]]; then + echo ":: Insufficient Disk Space!" + echo ":: Your system appears to be low on disk space. ${package_name} recommends a minimum of $required_free_kilobytes KB." + echo ":: You only have ${existing_free_kilobytes} KB free." + echo ":: After freeing up space, run this installation script again. (${install_curl_command})" + echo "Insufficient free space, exiting..." + exit 1 + fi +} + +####### +#### Installation functions +####### + +# getAptPackages runs apt-get update, and installs the basic packages we need to continue the Fermentrack install +# (git-core, build-essential, python-dev, python-virtualenv). The rest can be installed by fermentrack-tools/install.sh +getAptPackages() { + echo -e "::: Installing dependencies using apt-get" + lastUpdate=$(stat -c %Y /var/lib/apt/lists) + nowTime=$(date +%s) + if [ $(($nowTime - $lastUpdate)) -gt 604800 ] ; then + echo "::: Last 'apt-get update' was awhile back. Updating now." + sudo apt-get update &> /dev/null||die + echo ":: 'apt-get update' ran successfully." + fi + + sudo apt-key update &> /dev/null||die + echo "::: 'apt-key update' ran successfully." + + # Installing the nginx stack along with everything we need for circus, etc. + echo "::: apt is updated - installing git-core and build-essential." + echo "::: (This may take a few minutes during which everything will be silent)" + sudo apt-get install -y git-core build-essential &> /dev/null || die + echo ":: All packages installed successfully." +} + +handleExistingTools() { + echo -e ":::: Existing instance of ${tools_name} found at ${scriptPath}/${tools_name}" + echo -e ":::: Moving to ${scriptPath}/${tools_name}.old/" + rm -r ${tools_name}.old &> /dev/null + mv ${tools_name} ${tools_name}.old||die + echo -e ":::: Moved successfully. Reattempting clone." + git clone ${tools_repo_url} "${tools_name}" -q &> /dev/null||die + # TODO - remove this when everything is merged into master + cd ${tools_name} || die "Unable to cd to $tools_name" + git checkout docker &> /dev/null + git pull &> /dev/null + cd .. +} + +cloneFromGit() { + echo -e "::: Cloning ${tools_name} repo from GitHub into ${scriptPath}/${tools_name}" + git clone ${tools_repo_url} "${tools_name}" -q &> /dev/null||handleExistingTools + # TODO - remove this when everything is merged into master + cd ${tools_name} || die "Unable to cd to $tools_name" + git checkout docker &> /dev/null + git pull &> /dev/null + cd .. + echo ":: Repo was cloned successfully." +} + +installPython() { + echo "Installing Python 3.7.7" + echo -e "Warning - This may take several hours to complete, depending on your Pi version" + echo -e "Let it do its thing. This is important." + cd ~ || exit + sudo apt-get update -y + sudo apt-get install -y build-essential tk-dev libncurses5-dev libncursesw5-dev libreadline6-dev libdb5.3-dev libgdbm-dev libsqlite3-dev libssl-dev libbz2-dev libexpat1-dev liblzma-dev zlib1g-dev libffi-dev + sudo apt-get install -y make libreadline-dev wget curl llvm xz-utils libxml2-dev libxmlsec1-dev libzmq5-dev + wget https://www.python.org/ftp/python/3.7.7/Python-3.7.7.tar.xz + tar xf Python-3.7.7.tar.xz + cd Python-3.7.7 || exit + ./configure + make -j 4 + sudo make altinstall + cd .. + rm Python-3.7.7.tar.xz + sudo apt-get --purge remove tk-dev libncurses5-dev libncursesw5-dev libreadline6-dev libdb5.3-dev libgdbm-dev libsqlite3-dev libssl-dev libbz2-dev libexpat1-dev liblzma-dev zlib1g-dev libffi-dev -y + sudo apt-get autoremove -y + sudo apt-get clean + +} + +checkPython37() { + if command -v python3.7 &> /dev/null; then + # Python 3.7 is installed. No need to reinstall python manually + echo "Python 3.7 is installed. Continuing." + else + echo "Python 3.7 is NOT installed, but is required for Fermentrack. This generally means" + echo "that you are running an older version of Raspbian. Fermentrack recommends Raspbian" + echo "Buster or later." + echo "" + echo "Although the installation script can manually install Python 3.7, it is *highly*" + echo "recommended that you upgrade your version of Raspbian instead. Installing on this" + echo "version of Raspbian may take several hours longer than an installation on Buster." + echo "" + echo "To stop installation here, press Ctrl+C. Installation will otherwise continue in 10 seconds." + + sleep 11s + + # This script is almost always run non-interactively, so we can't solicit feedback here +# read -p "Do you want to manually install Python 3.7 and continue installing Fermentrack? [y/N] " yn +# case "$yn" in +# y | Y | yes | YES | Yes ) printinfo "Ok, let's go!";; +# * ) exit;; +# esac + + installPython + fi +} + +launchInstall() { + echo "::: This script will now attempt to install ${package_name} using the script that has been created at" + echo -e "::: ${scriptPath}/${tools_name}/${install_script_name}" + echo -e "::: If the install script does not complete successfully, please relaunch the script above directly." + echo -e "::: " + echo -e "::: Launching ${package_name} installer." + cd ${tools_name} || exit 1 + cd non_docker_install + # The -n flag makes the install script non-interactive + # TODO - strip out the -b docker + sudo bash ./$install_script_name -n -b docker + echo -e "::: Automated installation script has now finished. If installation did not complete successfully please" + echo -e "::: relaunch the installation script which has been downloaded at:" + echo -e "::: ${scriptPath}/${tools_name}/${install_script_name}" +} + +####### +### Now, for the main event... +####### +echo "" +echo "<<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>>" +verifyRunAsRoot +verifyFreeDiskSpace +getAptPackages +checkPython37 +cloneFromGit +launchInstall diff --git a/sample.production.yml b/sample.docker-compose.yml similarity index 100% rename from sample.production.yml rename to sample.docker-compose.yml