diff --git a/hyprlock.sh b/hyprlock.sh index 91c6514..5f0d66a 100644 --- a/hyprlock.sh +++ b/hyprlock.sh @@ -7,6 +7,30 @@ command_exists() { command -v "$@" >/dev/null 2>&1 } +# ─< package variable >─────────────────────────────────────────────────────────────────── +unset PACKAGE + +# ─< argument list variables >──────────────────────────────────────────────────────────── +silent=false + +sleep 0.1 + +PACKAGE=hyprlock +if command_exists "$PACKAGE"; then + echo "$PACKAGE is already installed!" + echo "Exiting now!" + exit 69 +fi + +# ─< parse arguments and get variable contents >────────────────────────────────────────── +for arg in "$@"; do + case "$arg" in + --silent | -s) + export silent=true + ;; + esac +done + # WHY: # This import will give you the following variables: # _sudo="sudo -E" <- only if non root user @@ -34,19 +58,6 @@ getImports() { source "$import" sleep 0.2 rm "$import" - - unset PACKAGE - - PACKAGE=hyprlock && - echo_note "Installing $PACKAGE.." - - sleep 1 - - if command_exists $PACKAGE; then - echo_warning "$PACKAGE is alread installed!" - echo_warning "Exiting now!" - exit 69 - fi } checkComp() { @@ -163,7 +174,7 @@ cloneAndBuildUtils() { } build() { - echo_info "Building hyprlock" + echo_pkg build "Building hyprlock" run cmake --no-warn-unused-cli -DCMAKE_BUILD_TYPE:STRING=Release -S . -B ./build run cmake --build ./build --config Release --target hyprlock -j"$cores" } @@ -173,11 +184,13 @@ cloneAndBuildLock() { cd $cloneDir || mkdir -p $cloneDir && cd $cloneDir + echo_pkg git "Cloning hyprlock into $cloneDir/hyprlock" + git clone https://github.com/hyprwm/hyprlock.git && cd hyprlock if build; then - echo_info "Installing hyprlock.." + echo_pkg install "Installing hyprlock.." $_sudo cmake --install build else echo_error "Build has failed for $distro compiling hyprlock" @@ -186,6 +199,14 @@ cloneAndBuildLock() { } main() { + if $silent; then + echo_warning "Executing script silently!" + fi + + if ! getDependencies; then + echo_error "Error when installing dependencies.." + fi + case "$distro" in arch) _install hyprlock @@ -194,22 +215,12 @@ main() { cloneAndBuildLock ;; *) - echo "$distro is not supported by this script!" + echo_error "$distro is not supported by this script!" exit 1 ;; esac } if getImports; then - case "$@" in - --silent | -s) - silent=true - echo_warning "Running script silently!" - ;; - *) - silent=false - ;; - esac - getDependencies main fi