Skip to content

Commit

Permalink
Merge pull request #6 from atomvm/install-script
Browse files Browse the repository at this point in the history
  • Loading branch information
UncleGrumpy committed Oct 14, 2023
2 parents a4017c5 + 76a5b30 commit 4c0d1f7
Show file tree
Hide file tree
Showing 3 changed files with 131 additions and 8 deletions.
15 changes: 7 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <sub-command> <options> <args>
Expand Down
100 changes: 100 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
#!/bin/sh
#
# This file is part of AtomVM.
#
# Copyright 2023 Fred Dushin <[email protected]>
#
# 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 <prefix> <version>
# where <prefix> is the prefix location for the install
# <version> 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 <prefix>/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 <prefix> <version>"
echo " where <prefix> is the prefix location for the install"
echo " <version> 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}."
24 changes: 24 additions & 0 deletions release/packbeam.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/sh
#
# This file is part of AtomVM.
#
# Copyright 2023 Fred Dushin <[email protected]>
#
# 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 "$@"

0 comments on commit 4c0d1f7

Please sign in to comment.