Skip to content
Snippets Groups Projects
freedombone-utils-elixir 3.35 KiB
Newer Older
#!/bin/bash
Bob Mottram's avatar
Bob Mottram committed
#  _____               _           _
# |   __|___ ___ ___ _| |___ _____| |_ ___ ___ ___
# |   __|  _| -_| -_| . | . |     | . | . |   | -_|
# |__|  |_| |___|___|___|___|_|_|_|___|___|_|_|___|
Bob Mottram's avatar
Bob Mottram committed
#                              Freedom in the Cloud
#
# Elixir functions
#
# There's a problem with installing this onto mesh images, which is
# that qemu appears to run out of RAM when using yarn to add webpack.
#
# License
# =======
#
Bob Mottram's avatar
Bob Mottram committed
# Copyright (C) 2018-2019 Bob Mottram <bob@freedombone.net>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

erlang_package='erlang-solutions_1.0_all.deb'

function remove_elixir {
    $REMOVE_PACKAGES elixir erlang-xmerl erlang-dev erlang-parsetools
    $REMOVE_PACKAGES esl-erlang
}

function install_elixir {
    if [ -f /usr/local/bin/mix ]; then
        return
    fi

    $INSTALL_PACKAGES wget build-essential

    if [ ! -d "$INSTALL_DIR" ]; then
        mkdir -p "$INSTALL_DIR"
    fi

    cd "$INSTALL_DIR" || exit 76
    wget https://packages.erlang-solutions.com/$erlang_package
    if [ ! -f "$INSTALL_DIR/$erlang_package" ]; then
    fi
    dpkg -i $erlang_package
    $UPDATE_PACKAGES
    $INSTALL_PACKAGES esl-erlang
    $INSTALL_PACKAGES elixir erlang-xmerl erlang-dev erlang-parsetools

    if [ ! -f /usr/local/bin/mix ]; then
        if [ ! -f /usr/bin/mix ]; then
            echo $'mix command not found after elixir installation'
            exit 62
        fi
function image_install_elixir {
    if [[ $VARIANT == "mesh"* ]]; then
        return
    fi

    # shellcheck disable=SC2154,SC2086
    chroot "$rootdir" $INSTALL_PACKAGES wget build-essential

    if [ ! -d "$rootdir$INSTALL_DIR" ]; then
        mkdir -p "$rootdir$INSTALL_DIR"
    fi

    { echo '#!/bin/bash';
      echo "cd $INSTALL_DIR || exit 1";
      echo "erlang_package=$erlang_package";
      echo "wget https://packages.erlang-solutions.com/\$erlang_package";
Bob Mottram's avatar
Bob Mottram committed
      echo "if [ ! -f \"$INSTALL_DIR/\$erlang_package\" ]; then";
      echo '    exit 2';
      echo 'fi';
      echo "dpkg -i \$erlang_package"; } > "$rootdir/usr/bin/install_elixir"
    chmod +x "$rootdir/usr/bin/install_elixir"
    chroot "$rootdir" /usr/bin/install_elixir
Bob Mottram's avatar
Bob Mottram committed
    # shellcheck disable=SC2086
    chroot "$rootdir" $UPDATE_PACKAGES
    # shellcheck disable=SC2086
    chroot "$rootdir" $INSTALL_PACKAGES esl-erlang
    # shellcheck disable=SC2086
    chroot "$rootdir" $INSTALL_PACKAGES elixir erlang-xmerl erlang-dev erlang-parsetools
    # note: the install location of mix is inconsistent between ARM and x86
    # elixir debian packages
    if [ ! -f "$rootdir/usr/local/bin/mix" ]; then
        if [ ! -f "$rootdir/usr/bin/mix" ]; then
            echo $'mix command not found after elixir installation'
            exit 62
        fi
# NOTE: deliberately no exit 0