From 1343e25004ddc0a24a0bdce96c4b737ccb4fd6c4 Mon Sep 17 00:00:00 2001 From: QRX53 <69993408+QRX53@users.noreply.github.com> Date: Fri, 15 Dec 2023 00:57:21 -0700 Subject: [PATCH] Upload --- dwn/BuildQLocal.sh | 12 +- dwn/FastQLocal.sh | 124 ++++++++++++++++++ .../java/qlang/runtime/core/CommandLine.java | 12 ++ 3 files changed, 142 insertions(+), 6 deletions(-) create mode 100755 dwn/FastQLocal.sh diff --git a/dwn/BuildQLocal.sh b/dwn/BuildQLocal.sh index 1cb11b2..7c347b0 100755 --- a/dwn/BuildQLocal.sh +++ b/dwn/BuildQLocal.sh @@ -16,7 +16,7 @@ function get_greeting() { if ((current_hour >= 20 || current_hour < 5)); then echo "Good evening" elif ((current_hour >= 5 && current_hour < 17)); then - echo "Good afternoon" + echo "Hello" else echo "Good evening" fi @@ -44,19 +44,19 @@ function customize_installation() { echo "Customizing installation..." # Prompt user for Maven command - read -p "Enter Maven command (default: 'mvn clean compile assembly:single'): " maven_command + read -rp "Enter Maven command (default: 'mvn clean compile assembly:single'): " maven_command maven_command=${maven_command:-"mvn clean compile assembly:single"} # Prompt user for installation directory - read -p "Enter installation directory (default: '/usr/local/bin/'): " install_dir + read -rp "Enter installation directory (default: '/usr/local/bin/'): " install_dir install_dir=${install_dir:-"/usr/local/bin/"} # Prompt user for PATH update - read -p "Do you want to update the PATH? (yes/no, default: yes): " update_path + read -rp "Do you want to update the PATH? (yes/no, default: yes): " update_path update_path=${update_path:-"yes"} # Prompt user for running in a temporary folder - read -p "Run in a temporary folder? (yes/no, default: yes): " temp_folder + read -rp "Run in a temporary folder? (yes/no, default: yes): " temp_folder temp_folder=${temp_folder:-"yes"} # Move to the chosen directory @@ -77,7 +77,7 @@ function customize_installation() { # Build the project echo "Building the project..." - $maven_command || { print_red "Error building the project"; exit 1; } + "$maven_command" || { print_red "Error building the project"; exit 1; } print_green "$(calculate_percentage 2) - Project built successfully!" # Rename the JAR file diff --git a/dwn/FastQLocal.sh b/dwn/FastQLocal.sh new file mode 100755 index 0000000..a3549d1 --- /dev/null +++ b/dwn/FastQLocal.sh @@ -0,0 +1,124 @@ +#!/bin/bash + +function print_green() { echo -e "$(tput setaf 2)$1$(tput sgr0)"; } +function print_red() { echo -e "$(tput setaf 1)$1$(tput sgr0)"; } + +function get_greeting() { + current_hour=$(date +%H) greeting="Good evening" + ((current_hour >= 5 && current_hour < 17)) && greeting="Hello" + echo "$greeting" +} + +function calculate_percentage() { + total_steps=8 completed_steps=$1 + percentage=$((completed_steps * 100 / total_steps)) + echo "$percentage% done" +} + +function display_help() { + echo "Usage: $0 [-s|--silent] [-h|--help] [-c|--customize]" + echo "Options:" + echo " -s, --silent Run in silent mode (suppress progress messages)" + echo " -h, --help Display this help menu" + echo " -c, --customize Customize the installation process" +} + +function customize_installation() { + echo "Customizing installation..." + + read -rp "Enter Maven command (default: 'mvn clean compile assembly:single'): " maven_command + maven_command=${maven_command:-mvn clean compile assembly:single} + + read -rp "Enter installation directory (default: '/usr/local/bin/'): " install_dir + install_dir=${install_dir:-/usr/local/bin/} + + read -rp "Do you want to update the PATH? (yes/no, default: yes): " update_path + update_path=${update_path:-yes} + + read -rp "Run in a temporary folder? (yes/no, default: yes): " temp_folder + temp_folder=${temp_folder:-yes} + + temp_dir="/tmp/.q_setup_custom" + mkdir -p "$temp_dir" && cd "$temp_dir" || { print_red "Error changing to temporary directory"; exit 1; } + + echo "Cloning the repository..." + git clone http://github.com/QRX53/Q || { print_red "Error cloning repository"; exit 1; } + print_green "$(calculate_percentage 1) - Repository cloned successfully!" + + cd Q || { print_red "Error changing to Q directory"; exit 1; } + + echo "Building the project..." + $maven_command || { print_red "Error building the project"; exit 1; } + print_green "$(calculate_percentage 2) - Project built successfully!" + + echo "Renaming the JAR file..." + mv target/Q-1.0-jar-with-dependencies.jar target/Q.jar || { print_red "Error renaming the JAR file"; exit 1; } + print_green "$(calculate_percentage 3) - JAR file renamed successfully!" + + echo "Creating and setting up the script..." + { echo "#! /usr/bin/env java -jar"; 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!" + + 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!" + + if [ "$update_path" ]; 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 + + print_green "$(calculate_percentage 7) - Customized script executed successfully!" + + [ "$temp_folder" ] && cd ~ || exit && rm -rf "$temp_dir" +} + +while [[ "$#" -gt 0 ]]; do + case $1 in + -s|--silent) silent_mode=true ;; + -h|--help) display_help; exit 0 ;; + -c|--customize) customize_installation; exit 0 ;; + *) echo "Unknown option: $1"; display_help; exit 1 ;; + esac + shift +done + +greeting=$(get_greeting) +echo "$greeting! Starting the script..." + +[ "$EUID" -ne 0 ] && { print_red "This script must be run as root or with sudo. Exiting..."; exit 1; } + +temp_dir="/tmp/.q_setup" +mkdir -p "$temp_dir" && [ -d "$temp_dir/Q" ] && { print_green "Existing 'Q' folder found. Deleting..."; rm -rf "$temp_dir/Q"; } + +cd "$temp_dir" || { print_red "Error changing to temporary directory"; exit 1; } +[ "$silent_mode" ] && exec > /dev/null 2>&1 + +echo "Cloning the repository..." +[ "$silent_mode" ] && git clone -q http://github.com/QRX53/Q || git clone http://github.com/QRX53/Q +print_green "$(calculate_percentage 1) - Repository cloned successfully!" + +cd Q || { print_red "Error changing to Q directory"; exit 1; } +[ "$silent_mode" ] && { mvn -q clean compile assembly:single || exit 1; } || mvn clean compile assembly:single +print_green "$(calculate_percentage 2) - Project built successfully!" + +echo "Renaming the JAR file..." +mv target/Q-1.0-jar-with-dependencies.jar target/Q.jar || { print_red "Error renaming the JAR file"; exit 1; } +print_green "$(calculate_percentage 3) - JAR file renamed successfully!" + +echo "Creating and setting up the script..." +{ echo "#! /usr/bin/env java -jar"; 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!" + +echo "Moving the JAR file to /usr/local/bin/..." && mv target/Q.jar /usr/local/bin/ || { print_red "Error moving the JAR file"; exit 1; } +print_green "$(calculate_percentage 5) - JAR file moved successfully!" + +echo "Updating the PATH..." && export PATH="/usr/local/bin/q:$PATH" || { print_red "Error updating the PATH"; exit 1; } +print_green "$(calculate_percentage 6) - PATH updated successfully!" + +print_green "$(calculate_percentage 7) - Script executed successfully!" + +cd ~ || exit && rm -rf "$temp_dir" diff --git a/src/main/java/qlang/runtime/core/CommandLine.java b/src/main/java/qlang/runtime/core/CommandLine.java index 747a9ac..525a7e1 100644 --- a/src/main/java/qlang/runtime/core/CommandLine.java +++ b/src/main/java/qlang/runtime/core/CommandLine.java @@ -108,6 +108,8 @@ public void moreInfo(String cmd) { System.out.println(prettyPrintflagInfo("--interact", "-in", "Create a new Q interactive shell, useful for Java-side debugging.", "None", "No")); } else if (matches(cmd, "--update", "-u")) { System.out.println(prettyPrintflagInfo("--update", "-u", "Currently non-functional, but in theory will run Q's update script.", "None", "No")); + } else if (matches(cmd, "--uninstall", "-unin")) { + System.out.println(prettyPrintflagInfo("--uninstall", "-unin", "Removes your Q installation. Cannot be undone.", "None", "No")); } else if (matches(cmd, "--moreinfo", "-mi")) { System.out.println(prettyPrintflagInfo("--moreinfo", "-mi", "Print detailed information about each of Q's flags.", "-- | -", "Either")); } else { @@ -717,6 +719,16 @@ fn main(args): } } + } else if (matches(zero, "--uninstall", "-unin")) { + try { + File qExec = new File("/usr/local/bin/q"); + + if (qExec.exists()) { + qExec.delete(); + } + } catch (Exception e) { + Log.log(Log.Severity.FATAL, "Failed to delete `/usr/local/bin/q`. Likely due to permissions errors."); + } } else if (matches(zero, "--update", "-u")) { Log.log(Log.Severity.WARNING, "This flag is not fully completed."); System.exit(0);