Cleaner up shell.nix by removing bash commands and replacing them with just recipes.

This commit is contained in:
ajasibley 2023-05-24 15:07:33 -07:00
parent c0e8da7912
commit 5d66c80d99
4 changed files with 96 additions and 83 deletions

28
justfile Normal file
View file

@ -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

View file

@ -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

20
scripts/update_path.sh Normal file
View file

@ -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" <<EOF
export PATH="/Users/test/.cosmo/bin:\${builtins.getEnv "PATH"}"
EOF
source "${builtins.getEnv "HOME"}/.bashrc"
elif [[ "$current_shell" == "zsh" ]]; then
cat >> "${builtins.getEnv "HOME"}/.zshrc" <<EOF
export PATH="/Users/test/.cosmo/bin:\${builtins.getEnv "PATH"}"
EOF
source "${builtins.getEnv "HOME"}/.zshrc"
else
echo "Unsupported shell: $current_shell"
exit 1
fi

View file

@ -10,89 +10,6 @@ pkgs.mkShell {
vespa-cli
];
shellHook = ''
# Check if Rust is installed, if not install it
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
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" <<EOF
export PATH="/Users/test/.cosmo/bin:\${builtins.getEnv "PATH"}"
EOF
source "${builtins.getEnv "HOME"}/.bashrc"
elif [[ "$current_shell" == "zsh" ]]; then
cat >> "${builtins.getEnv "HOME"}/.zshrc" <<EOF
export PATH="/Users/test/.cosmo/bin:\${builtins.getEnv "PATH"}"
EOF
source "${builtins.getEnv "HOME"}/.zshrc"
else
echo "Unsupported shell: $current_shell"
exit 1
fi
fi
cat <<'EOF'
.-.
`-'