From 5d66c80d99b15be3da781ddba3f6f4d40fe51646 Mon Sep 17 00:00:00 2001 From: ajasibley <125228925+ajasibley@users.noreply.github.com> Date: Wed, 24 May 2023 15:07:33 -0700 Subject: [PATCH] Cleaner up shell.nix by removing bash commands and replacing them with just recipes. --- justfile | 28 +++++++++++++ scripts/install_openssl.sh | 48 ++++++++++++++++++++++ scripts/update_path.sh | 20 +++++++++ shell.nix | 83 -------------------------------------- 4 files changed, 96 insertions(+), 83 deletions(-) create mode 100644 justfile create mode 100644 scripts/install_openssl.sh create mode 100644 scripts/update_path.sh diff --git a/justfile b/justfile new file mode 100644 index 000000000..ed2b6090b --- /dev/null +++ b/justfile @@ -0,0 +1,28 @@ +scripts_dir := "scripts" + +# Check if Rust is installed, if not install it +install-rust: + @if ! command -v rustc &> /dev/null; then \ + curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh; \ + fi + +# Check if wasm32-unknown-unknown target is installed, if not install it +install-wasm-target: + @if ! rustup target list --installed | grep -q "wasm32-unknown-unknown"; then \ + rustup target add wasm32-unknown-unknown; \ + fi + +# Check if OpenSSL 1.1 is installed +install-openssl: + @if ! (command -v openssl &> /dev/null && openssl version | grep -q "OpenSSL 1.1"); then \ + . {{scripts_dir}}/install_openssl.sh; \ + fi + +# Check if cosmo is installed, if not install it +install-cosmo: + @if ! command -v cosmo &> /dev/null; then \ + bash -c "$(curl -fsSL https://cosmonic.sh/install.sh)"; \ + . {{scripts_dir}}/update_path.sh; \ + fi + +all: install-rust install-wasm-target install-openssl install-cosmo diff --git a/scripts/install_openssl.sh b/scripts/install_openssl.sh new file mode 100644 index 000000000..a6dc47d88 --- /dev/null +++ b/scripts/install_openssl.sh @@ -0,0 +1,48 @@ +#!/bin/bash + +# Check if OpenSSL 1.1 is installed +if ! (command -v openssl &> /dev/null && openssl version | grep -q "OpenSSL 1.1"); then + + # Check the architecture and install OpenSSL 1.1 if needed + if [[ $(uname -m) == "arm64" ]]; then + if [[ "$OSTYPE" == "darwin"* ]]; then + # MacOS M1 installation + if ! command -v brew &> /dev/null; then + /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" + fi + + export PATH="/opt/homebrew/bin:$PATH" + + brew install openssl@1.1 + + elif [[ "$OSTYPE" == "linux-gnu"* ]]; then + # Check for Debian-based system + if grep -qi 'debian' /etc/os-release; then + # Ubuntu ARM installation + + apt update && apt install curl -y + + curl -s https://packagecloud.io/install/repositories/wasmcloud/core/script.deb.sh | bash + + apt install wash + + curl -fLO http://ftp.us.debian.org/debian/pool/main/o/openssl/libssl1.1_1.1.1n-0+deb11u4_arm64.deb + + dpkg -i libssl1.1_1.1.1n-0+deb11u4_arm64.deb + + else + echo "This script is designed for Debian-based systems only." + exit 1 + fi + + else + echo "Unsupported system type." + exit 1 + fi + + else + echo "This script is designed for arm64 systems only." + exit 1 + fi + +fi diff --git a/scripts/update_path.sh b/scripts/update_path.sh new file mode 100644 index 000000000..81b100e22 --- /dev/null +++ b/scripts/update_path.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +# Get the current shell name +current_shell="$(basename ${builtins.getEnv "SHELL"})" + +# Update the corresponding configuration file based on the current shell +if [[ "$current_shell" == "bash" ]]; then + cat >> "${builtins.getEnv "HOME"}/.bashrc" <> "${builtins.getEnv "HOME"}/.zshrc" < /dev/null; then - curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh - fi - - # Check if wasm32-unknown-unknown target is installed, if not install it - if ! rustup target list --installed | grep -q "wasm32-unknown-unknown"; then - rustup target add wasm32-unknown-unknown - fi - - - # Check if OpenSSL 1.1 is installed - if ! (command -v openssl &> /dev/null && openssl version | grep -q "OpenSSL 1.1"); then - - # Check the architecture and install OpenSSL 1.1 if needed - if [[ $(uname -m) == "arm64" ]]; then - if [[ "$OSTYPE" == "darwin"* ]]; then - # MacOS M1 installation - if ! command -v brew &> /dev/null; then - /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" - fi - - export PATH="/opt/homebrew/bin:$PATH" - - brew install openssl@1.1 - - elif [[ "$OSTYPE" == "linux-gnu"* ]]; then - # Check for Debian-based system - if grep -qi 'debian' /etc/os-release; then - # Ubuntu ARM installation - - apt update && apt install curl -y - - curl -s https://packagecloud.io/install/repositories/wasmcloud/core/script.deb.sh | bash - - apt install wash - - curl -fLO http://ftp.us.debian.org/debian/pool/main/o/openssl/libssl1.1_1.1.1n-0+deb11u4_arm64.deb - - dpkg -i libssl1.1_1.1.1n-0+deb11u4_arm64.deb - - else - echo "This script is designed for Debian-based systems only." - exit 1 - fi - - else - echo "Unsupported system type." - exit 1 - fi - - else - echo "This script is designed for arm64 systems only." - exit 1 - fi - - fi - - # Check if cosmo is installed, if not install it - if ! command -v cosmo &> /dev/null; then - bash -c "$(curl -fsSL https://cosmonic.sh/install.sh)" - - # Get the current shell name - current_shell="$(basename ${builtins.getEnv "SHELL"})" - - # Update the corresponding configuration file based on the current shell - if [[ "$current_shell" == "bash" ]]; then - cat >> "${builtins.getEnv "HOME"}/.bashrc" <> "${builtins.getEnv "HOME"}/.zshrc" <