|
| 1 | +#!/usr/bin/env bash |
| 2 | +# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| 3 | +# title Install Script + |
| 4 | +# project nord-konsole + |
| 5 | +# repository https://github.com/arcticicestudio/nord-konsole + |
| 6 | +# author Arctic Ice Studio + |
| 7 | +# email development@arcticicestudio.com + |
| 8 | +# copyright Copyright (C) 2016 + |
| 9 | +# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| 10 | +set -e |
| 11 | + |
| 12 | +_ct_error="\e[0;31m" |
| 13 | +_ct_success="\e[0;32m" |
| 14 | +_ct_warning="\e[0;33m" |
| 15 | +_ct_highlight="\e[0;34m" |
| 16 | +_ct_primary="\e[0;36m" |
| 17 | +_ct="\e[0;37m" |
| 18 | +_ctb_subtle="\e[1;30m" |
| 19 | +_ctb_error="\e[1;31m" |
| 20 | +_ctb_success="\e[1;32m" |
| 21 | +_ctb_warning="\e[1;33m" |
| 22 | +_ctb_highlight="\e[1;34m" |
| 23 | +_ctb_primary="\e[1;36m" |
| 24 | +_ctb="\e[1;37m" |
| 25 | +_c_reset="\e[0m" |
| 26 | + |
| 27 | +__help() { |
| 28 | + printf "${_ctb}Usage: ${_ct_primary}install.sh ${_ctb_subtle}[OPTIONS]\n" |
| 29 | + printf " ${_ctb_highlight}-h${_ct},${_ctb_highlight} --help ${_ct}Help\n" |
| 30 | + printf " ${_ctb_highlight}-v${_ct},${_ctb_highlight} --verbose ${_ct}Verbose output\n${_ctb_reset}" |
| 31 | + printf " ${_ctb_highlight}-s${_ct},${_ctb_highlight} --schemefile <SCHEME_FILE> \ |
| 32 | +${_ct}Use the specified color scheme file\n${_ctb_reset}" |
| 33 | +} |
| 34 | + |
| 35 | +__cleanup() { |
| 36 | + trap '' SIGINT SIGTERM |
| 37 | + unset -v _ct_error _ct_success _ct_warning _ct_highlight _ct_primary _ct |
| 38 | + unset -v _ctb_error _ctb_success _ctb_warning _ctb_highlight _ctb_primary _ctb _c_reset |
| 39 | + unset -v NORD_KONSOLE_SCRIPT_OPTS SCHEME_FILE VERBOSE LOCAL_INSTALL NORD_KONSOLE_VERSION |
| 40 | + unset -f __help __cleanup __log_error __log_success __log_warning __log_info |
| 41 | + unset -f __validate_file __local_install |
| 42 | +} |
| 43 | + |
| 44 | +__log_error() { |
| 45 | + printf "${_ctb_error}[ERROR] ${_ct}$1${_c_reset}\n" |
| 46 | +} |
| 47 | + |
| 48 | +__log_success() { |
| 49 | + printf "${_ctb_success}[OK] ${_ct}$1${_c_reset}\n" |
| 50 | +} |
| 51 | + |
| 52 | +__log_warning() { |
| 53 | + printf "${_ctb_warning}[WARN] ${_ct}$1${_c_reset}\n" |
| 54 | +} |
| 55 | + |
| 56 | +__log_info() { |
| 57 | + printf "${_ctb}[INFO] ${_ct}$1${_c_reset}\n" |
| 58 | +} |
| 59 | + |
| 60 | +__summary_success() { |
| 61 | + __log_success "Local installation completed" |
| 62 | + __cleanup |
| 63 | + exit 0 |
| 64 | +} |
| 65 | + |
| 66 | +__summary_error() { |
| 67 | + __log_error "An error occurred during the installation!" |
| 68 | + __log_error "Exit code: $1" |
| 69 | + __cleanup |
| 70 | + exit 1 |
| 71 | +} |
| 72 | + |
| 73 | +__local_install() { |
| 74 | + __validate_file |
| 75 | + if [ ! -d $LOCAL_INSTALL_DIR ]; then |
| 76 | + mkdir -p $LOCAL_INSTALL_DIR |
| 77 | + if [ $? -eq 0 ]; then |
| 78 | + if [ $VERBOSE = true ]; then __log_info "Created local directory $LOCAL_INSTALL_DIR"; fi |
| 79 | + else |
| 80 | + __log_error "Could not create local directory $LOCAL_INSTALL_DIR" |
| 81 | + __summary_error 1 |
| 82 | + fi |
| 83 | + fi |
| 84 | + cp -f $SCHEME_FILE $LOCAL_INSTALL_DIR |
| 85 | + if [ $? -eq 0 ]; then |
| 86 | + if [ $VERBOSE = true ]; then __log_success "Copied color scheme file to $LOCAL_INSTALL_DIR"; fi |
| 87 | + __summary_success |
| 88 | + else |
| 89 | + __log_error "Could not copy color scheme file to $LOCAL_INSTALL_DIR" |
| 90 | + __summary_error 1 |
| 91 | + fi |
| 92 | +} |
| 93 | + |
| 94 | +__validate_file() { |
| 95 | + if [ ! -f $SCHEME_FILE ]; then |
| 96 | + __log_error "Color scheme file not found: $SCHEME_FILE" |
| 97 | + __summary_error 1 |
| 98 | + fi |
| 99 | +} |
| 100 | + |
| 101 | +trap "printf '${_ctb_error}User aborted.${_ctb_reset}\n' && exit 1" SIGINT SIGTERM |
| 102 | + |
| 103 | +NORD_KONSOLE_SCRIPT_OPTS=`getopt -o vhs: --long verbose,help,schemefile: -n 'install.sh' -- "$@"` |
| 104 | +SCHEME_FILE=src/nord.colorscheme |
| 105 | +VERBOSE=false |
| 106 | +LOCAL_INSTALL_DIR=~/.local/share/konsole |
| 107 | +NORD_KONSOLE_VERSION= |
| 108 | + |
| 109 | +eval set -- "$NORD_KONSOLE_SCRIPT_OPTS" |
| 110 | +while true; do |
| 111 | + case "$1" in |
| 112 | + -v | --verbose ) VERBOSE=true; shift ;; |
| 113 | + -h | --help ) __help; exit 0; break ;; |
| 114 | + -s | --schemefile ) |
| 115 | + SCHEME_FILE="$2"; shift 2 ;; |
| 116 | + -- ) shift; break ;; |
| 117 | + * ) break ;; |
| 118 | + esac |
| 119 | +done |
| 120 | + |
| 121 | +__local_install |
| 122 | + |
| 123 | +__cleanup |
| 124 | +exit 0 |
0 commit comments