diff --git a/dwn/Install.sh b/dwn/Install.sh new file mode 100644 index 0000000..56aa728 --- /dev/null +++ b/dwn/Install.sh @@ -0,0 +1,324 @@ +#!/bin/bash + +# Function to print in green +function print_green() { + echo -e "$(tput setaf 2)$1$(tput sgr0)" +} + +# Function to print in red +function print_red() { + echo -e "$(tput setaf 1)$1$(tput sgr0)" +} + +# Function to get the greeting based on the current time +function get_greeting() { + current_hour=$(date +%H) + if ((current_hour >= 0 && current_hour < 12)); then + echo "Good morning" + elif ((current_hour >= 12 && current_hour < 18)); then + echo "Good afternoon" + else + echo "Good evening" + fi +} + +# Function to calculate percentage completion +function calculate_percentage() { + total_steps=8 + completed_steps=$1 + percentage=$((completed_steps * 100 / total_steps)) + echo "$percentage% done" +} + +# Function to display help menu +function display_help() { + cat < q + cat target/Q.jar >> q + chmod +x q || { print_red "Error setting up the script"; exit 1; } + print_green "$(calculate_percentage 4) - Script created and set up successfully!" + + # Move the JAR file to the chosen directory + echo "Moving the JAR file to $install_dir..." + mv target/Q.jar "$install_dir" || { print_red "Error moving the JAR file"; exit 1; } + print_green "$(calculate_percentage 5) - JAR file moved successfully!" + + # Update the PATH + if [ "$update_path" == "yes" ]; then + echo "Updating the PATH..." + export PATH="$install_dir:$PATH" || { print_red "Error updating the PATH"; exit 1; } + print_green "$(calculate_percentage 6) - PATH updated successfully!" + else + print_green "$(calculate_percentage 6) - PATH not updated" + fi + + # All steps completed successfully + print_green "$(calculate_percentage 7) - Customized script executed successfully!" + + # Clean up temporary directory if used + if [ "$temp_folder" == "yes" ]; then + cd ~ || exit + rm -rf "$temp_dir" + fi +} + +# Function to handle downloading the latest release +function download_latest_release() { + TMP_DIR=$(mktemp -d -t q_temp.XXXXXX) + cd "$TMP_DIR" || exit 1 + + # Download the latest release file + echo + echo "Downloading the latest release file..." + if curl -# -L -o Q.jar "http://github.com/qRX53/Q/releases/latest/download/Q.jar"; then + print_green "Download complete." + else + print_red "Error downloading the file. Exiting." + exit 1 + fi + + # Create the 'q' script + echo + echo "Creating the 'q' script..." + if echo "#! /usr/bin/env java -jar" > q && cat Q.jar >> q && chmod +x q; then + print_green "'q' script created." + else + print_red "Error creating the 'q' script. Exiting." + exit 1 + fi + + # Move the 'q' script to /usr/local/bin + echo + echo "Moving the 'q' script to /usr/local/bin..." + if sudo mv q /usr/local/bin/; then + print_green "'q' executable moved to /usr/local/bin." + else + print_red "Error moving the 'q' script. Exiting." + exit 1 + fi + + # Update PATH + echo + echo "Updating PATH..." + + { + export PATH="/usr/local/bin/q:$PATH" + print_green "PATH updated." + } || { + print_red "Failed to update path." + } + + # All steps completed + echo + print_green "Installation complete!" + + # Clean up: Remove the downloaded jar file + echo + echo "Cleaning up..." + if rm Q.jar; then + print_green "Post install clean up complete." + else + print_red "Error cleaning up. Please remove 'Q.jar' manually." + fi + + # Print next steps + echo + print_green "To get started, run: q --version" +} + +# Check for command-line options +while [[ "$#" -gt 0 ]]; do + case $1 in + -s|--silent) + silent_mode=true + ;; + -h|--help) + display_help + exit 0 + ;; + -c|--customize) + customize_installation + exit 0 + ;; + -b|--build-local) + build_local=true + ;; + -d|--download-release) + download_release=true + ;; + -V|--verbose) + verbose=true + ;; + -u|--uninstall) + uninstall=true + ;; + -f|--force) + force=true + ;; + --debug) + debug=true + ;; + *) + echo "Unknown option: $1" + display_help + exit 1 + ;; + esac + shift +done + +# Check if both options are selected or none is selected +if [ "$build_local" == true ] && [ "$download_release" == true ]; then + print_red "Error: Please choose either --build-local or --download-release, not both." + display_help + exit 1 +elif [ "$build_local" != true ] && [ "$download_release" != true ]; then + # If no flags are provided, prompt the user to choose between local build and download + echo "Welcome to the Q installation script!" + echo "Choose an option:" + echo "1. Build locally" + echo "2. Download the latest release" + read -p "Enter the number corresponding to your choice: " user_choice + + case $user_choice in + 1) + build_local=true + ;; + 2) + download_release=true + ;; + *) + print_red "Invalid choice. Exiting." + display_help + exit 1 + ;; + esac +fi + +# Continue script based on user choice +# Try to gain root access if not already running with sufficient privileges +if [ "$EUID" -ne 0 ]; then + print_green "Attempting to gain root access..." + if sudo -v; then + print_green "Root access granted." + else + print_red "Failed to gain root access. Please run the script as root or with sudo. Exiting..." + exit 1 + fi +fi + +# Move to a hidden temporary directory +temp_dir="/tmp/.q_setup" +mkdir -p "$temp_dir" + +# Check if 'Q' folder already exists in /tmp/ +if [ -d "$temp_dir/Q" ]; then + print_green "Existing 'Q' folder found. Deleting..." + rm -rf "$temp_dir/Q" +fi + +cd "$temp_dir" || { print_red "Error changing to temporary directory"; exit 1; } + +# Check for silent mode +if [ "$silent_mode" == true ]; then + exec > /dev/null 2>&1 +fi + +# Execute the chosen option +if [ "$download_release" == true ]; then + download_latest_release +else + customize_installation +fi + +# Clean up hidden temporary directory +cd ~ || exit +rm -rf "$temp_dir" diff --git a/dwn/README.md b/dwn/README.md index 472f8c3..90403d6 100644 --- a/dwn/README.md +++ b/dwn/README.md @@ -2,4 +2,6 @@ This folder is reserved for various Q installation scripts. -With the exception of `install-arch`, these are updated regularly. \ No newline at end of file +With the exception of `install-arch`, these are updated regularly. + +The primary installation script, `Install.sh` was not written entirely by me, I had lots of help. \ No newline at end of file diff --git a/src/main/java/qlang/core/lang/Environment.java b/src/main/java/qlang/core/lang/Environment.java index f3f921c..9897fb4 100644 --- a/src/main/java/qlang/core/lang/Environment.java +++ b/src/main/java/qlang/core/lang/Environment.java @@ -33,7 +33,7 @@ public class Environment { public Visitor visitor = new Visitor(scope, functions); public String response = Utilities.string(); public boolean verbose = false; - public String shver = "v1.2.07"; + public String shver = "v1.2.08"; public String qversion = shver; public String releaseNotes = "Q Release: " + this.qversion + "\n\nShell Build: " + this.shver + "\n\nRelease Notes: Q version (" + this.qversion + ") fixes several issues with Q project creation, as well as adding more options to the Q help menu."; diff --git a/src/main/java/qlang/runtime/core/CommandLine.java b/src/main/java/qlang/runtime/core/CommandLine.java index 1b1e4ee..747a9ac 100644 --- a/src/main/java/qlang/runtime/core/CommandLine.java +++ b/src/main/java/qlang/runtime/core/CommandLine.java @@ -243,7 +243,7 @@ public String exec(String[] args, String fpath) { } else if (matches(zero, "--run", "-r")) { if (args.length == 1) { - System.out.println(Chalk.on("No QFile provided! Try this, `q --run .q`").bgBlue()); + System.out.println(("No QFile provided! Try this, `q --run .q`")); System.exit(0); } else { if (new File(args[1]).isDirectory()) { @@ -264,7 +264,7 @@ public String exec(String[] args, String fpath) { } else if (matches(zero, "--runblind", "-rb")) { if (args.length == 1) { - System.out.println(Chalk.on("No QFile provided! Try this, `q --runblind .q`").bgBlue()); + System.out.println("No QFile provided! Try this, `q --runblind .q`"); System.exit(0); } @@ -725,8 +725,8 @@ fn main(args): System.exit(0); } } else { - System.out.println(Chalk.on(String.format("Q Release %s: ✅\n", Environment.global.qversion)).bgGreen()); - System.out.println(Chalk.on("\nTo get started run `q --help`.").bgGreen()); + System.out.printf("Q Release %s: ✅\n%n", Environment.global.qversion); + System.out.println("\nTo get started run `q --help`."); System.exit(0); } return fpath;