Skip to content

Commit

Permalink
Add automated setup script
Browse files Browse the repository at this point in the history
  • Loading branch information
mustafaquraish committed Oct 25, 2024
1 parent 4092c0a commit 1088d12
Show file tree
Hide file tree
Showing 2 changed files with 127 additions and 1 deletion.
23 changes: 22 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,28 @@

`ocen` transpiles to C, and the _only_ dependency for this compiler is a C compiler on your system (`gcc` by default, but can be specified with `CC` environment variable). For now `ocen` is only tested/supported on linux and macOS, but contributions to help get this running on Windows are welcome if anyone is interested.

## Usage
## Installing

### Automated Installation

For the _"I don't care, just give me the command"_ people. **This will add some environment variables to your shell config**

```shell
# Default (installs in ~/ocen):
$ curl -sSL https://raw.githubusercontent.com/ocen-lang/ocen/master/meta/install.sh | bash

# Custom install path:
$ curl -sSL https://raw.githubusercontent.com/ocen-lang/ocen/master/meta/install.sh | BASE=~/local/ bash
```

### Manual Installation

Clone the repository:

```shell
$ git clone https://github.com/ocen-lang/ocen.git
$ cd ocen
```

Use the following command to build the initial compiler:

Expand Down
105 changes: 105 additions & 0 deletions meta/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
#!/bin/bash

# This is meant to be a one-liner to clone, build and install `ocen` on your system.

BASE=${BASE:=$HOME/}
CLONE_DIR=${CLONE_DIR:=$BASE/ocen}

function show_env_vars() {
echo
echo "export OCEN_ROOT=$CLONE_DIR"
echo "export PATH=\$OCEN_ROOT/bin:\$PATH"
echo
}

function clone_ocen() {
# Clone the repository and build ocen if it doesn't exist
if [ ! -d $CLONE_DIR ]; then
echo "[+] Cloning ocen-lang/ocen to $CLONE_DIR"
git config --global core.autocrlf false
git clone https://github.com/ocen-lang/ocen $CLONE_DIR
echo "[+] Building ocen"
cd $CLONE_DIR
./meta/bootstrap.sh
else
echo "[-] Directory $CLONE_DIR already exists. Please remove it or specify BASE or CLONE_DIR."
exit 1
fi
}

function update_shell() {
# Find correct .rc file depending on the shell
if [ -f $HOME/.bashrc ]; then
RC_FILE=$HOME/.bashrc
elif [ -f $HOME/.zshrc ]; then
RC_FILE=$HOME/.zshrc
else
echo "-----------------------------------------------------------"
echo "[-] Unknown shell. Add these to your shell config file:"
show_env_vars
return 1
fi

# Check if RC_FILE already contains OCEN_ROOT
if grep -q "OCEN_ROOT" $RC_FILE; then
echo "[+] Shell config already contains OCEN_ROOT. Trying compiler..."

# Check if `ocen --help` works, but ignore errors
OUTPUT=$(source $RC_FILE && ocen --help 2>&1)
# If exit code is 0, ocen is installed correctly
if [ $? -eq 0 ]; then
echo "[+] ocen is already installed and working."
return 0
else
echo "-----------------------------------------------------------"
echo $OUTPUT
echo "-----------------------------------------------------------"
echo "[-] ocen is not installed correctly. Please check your shell config file for:"
show_env_vars
return 1
fi

else

read -p "[+] Add OCEN_ROOT to $RC_FILE? [Y/n] " -n 1 -r
echo # (optional) move to a new line
if [[ $REPLY =~ ^[Nn]$ ]]
then
echo "-----------------------------------------------------------"
echo "[-] Okay. Add these to your shell config file:"
show_env_vars
return 0
fi

echo "export OCEN_ROOT=$CLONE_DIR" >> $RC_FILE
echo "export PATH=\$OCEN_ROOT/bin:\$PATH" >> $RC_FILE
fi
}

function install_vscode_extension() {
# If VSCode is not installed, skip this step
if ! command -v code &> /dev/null; then
echo "[-] VSCode is not installed. Skipping extension installation."
return 0
fi

# Check if `mustafaquraish.ocen` extension is already installed
if code --list-extensions | grep -q "mustafaquraish.ocen"; then
echo "[+] VSCode Ocen extension is already installed."
return 0
fi

read -p "[+] Install VSCode Ocen extension? [Y/n] " -n 1 -r
echo # (optional) move to a new line
if [[ $REPLY =~ ^[Nn]$ ]]
then
echo "[-] Okay. You can install the extension manually from the VSCode marketplace."
return 0
fi

code --install-extension mustafaquraish.ocen
}

clone_ocen
update_shell
install_vscode_extension

0 comments on commit 1088d12

Please sign in to comment.