diff --git a/README.md b/README.md index a89124a..b2797d1 100644 --- a/README.md +++ b/README.md @@ -29,19 +29,18 @@ in your local working directory. > IMPORTANT! The files in this tar archive do not contain the `atomvm_packbeam` prefix, so extracting these files without care will create a `bin` and `lib` directory in the location into which files from the archive is extracted. See the example below before proceeding! -You can then copy this tar file to any compatible system and extract the contents into a local directory. E.g., +You can use the `install.sh` script to install the `atomvm_packbeam` utility into a location on your local machine. You will need to specify the prefix location into which you want to install the utility, together with it's current version. - shell$ mkdir /opt/atomvm_packbeam-0.6.2 - shell$ cp _build/prod/rel/atomvm_packbeam/atomvm_packbeam-0.6.2.tar.gz /opt/atomvm_packbeam-0.6.2/. - shell$ cd /opt/atomvm_packbeam-0.6.2 - shell$ tar xf atomvm_packbeam-0.6.2.tar.gz - ... + shell$ ./install.sh /usr/local 0.6.2 + atomvm_packbeam version 0.6.2 installed in /usr/local. + +> Note. Some prefix locations may require `root` permissions to write files to. -Set your `PATH` environment variable to include the `bin` directory of this unpacked archive, and you should then be able to run the `packbeam` command included therein. +Set your `PATH` environment variable to include the `bin` directory of the installation prefix (if not already set), and you should then be able to run the `packbeam` command included therein. For example: - shell$ export PATH=/opt/atomvm_packbeam-0.6.2/bin:$PATH + shell$ export PATH=/usr/local/bin:$PATH shell$ packbeam help Syntax: packbeam diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..5713b17 --- /dev/null +++ b/install.sh @@ -0,0 +1,100 @@ +#!/bin/sh +# +# This file is part of AtomVM. +# +# Copyright 2023 Fred Dushin +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later +# + +# +# Install script for the packbeam utility. +# +# This script will install the packbeam utility in a given location +# on the user's machine. You must provide the prefix location for the +# installation, in addition to the currently operative version, as +# defined in the relx section of this project's rebar.config. +# +# Syntax: install.sh +# where is the prefix location for the install +# is the current release packbeam version +# +# This script will create a self-contained packbeam installation, including +# ERTS as built for the target platform. Effort is made to not conflict +# with any other ERTS or Erlang installations already on the machine. +# +# After installation, users may run /bin/packbeam on the +# command line. (Some installation tools will provide this automatically +# in the user's PATH) +# +# Set the environemnt variable PACKBEAM_DEBUG to a non-empty string +# to get diagnostic information about the installation. +# + +set -e + +readonly root_dir="$(cd $(dirname $0) && pwd)" + +readonly nargs=$# +if [[ ${nargs} -lt 2 ]]; then + echo + echo "Syntax: $0 " + echo " where is the prefix location for the install" + echo " is the current release packbeam version" + echo + exit 1 +fi +readonly prefix="${1}" +readonly version="${2}" + +if [ ! -e "${prefix}" ]; then + echo "ERROR! Prefix dir ${prefix} must exist!" + exit 1 +fi + +echo_run() { + local cmd="$@" + if [ -n "${PACKBEAM_DEBUG}" ]; then + echo "# $(date) [$(hostname)]> ${cmd}" + fi + ${cmd} +} + +readonly src_tar="${root_dir}/_build/default/rel/atomvm_packbeam/atomvm_packbeam-${version}.tar.gz" +if [ ! -e "${src_tar}" ]; then + echo "ERROR! It looks like atomvm_packbeam version ${version} has not been built!" + exit 1 +fi + +## unzip the archive (so that BSD tar can deal with it) +readonly tmp_dir="$(mktemp -d /tmp/atomvm_packbeam.XXXXXX)" +echo_run cp "${src_tar}" "${tmp_dir}/." +echo_run gunzip "${tmp_dir}/atomvm_packbeam-${version}.tar.gz" + +readonly dest_dir="${prefix}/atomvm_packbeam" +if [ -e "${dest_dir}" ]; then + echo "ERROR! It looks like ${dest_dir} already exists!" + exit 1 +fi + +echo_run mkdir -p "${dest_dir}" +echo_run tar -C "${dest_dir}" -x -f "${tmp_dir}/atomvm_packbeam-${version}.tar" + +echo_run mkdir -p "${prefix}/bin" +echo_run cp "${root_dir}/release/packbeam.in" "${prefix}/bin/packbeam" +echo_run chmod 755 "${prefix}/bin/packbeam" + +echo_run rm -rf "${tmp_dir}" +echo "atomvm_packbeam version ${version} installed in ${dest_dir}." diff --git a/release/packbeam.in b/release/packbeam.in new file mode 100644 index 0000000..2548348 --- /dev/null +++ b/release/packbeam.in @@ -0,0 +1,24 @@ +#!/bin/sh +# +# This file is part of AtomVM. +# +# Copyright 2023 Fred Dushin +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later +# + +readonly root_dir="$(cd $(dirname $0)/.. && pwd)" + +exec ${root_dir}/atomvm_packbeam/bin/packbeam "$@"