#!/usr/bin/env bash
#
#   Script name: ubboot
#   Description: Script for managing boot UBLinux
#   GitLab: https://gitlab.ublinux.ru/
#   Author: asmeron@ublinux.ru
#   Contributors: asmeron@ublinux.ru
#
#   Copyright (c) 2021-2022 UBLinux Development Team <support@ublinux.ru>
#
#   This program is free software; you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation; either version 2 of the License, or
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program.  If not, see <http://www.gnu.org/licenses/>.

VERSION_SCRIPT="1.9"

# Exit Immediately if a command fails
#set -o errexit

#################################
###   :::   C O L O R S   :::   #
#################################
set_color() {
#http://abload.de/img/bash-color-chartmxjbp.png
    export BBC=$'\e[1;34m'
    export RBC=$'\e[1;31m'
    export WBC=$'\e[1m'
    export EC=$'\e[0m'

    export txtblk='\033[0;30m' # Black - Regular
    export txtred='\033[0;31m' # Red			# prompt: error color
    export txtgrn='\033[0;32m' # Green			# prompt: success color
    export txtylw='\033[0;33m' # Yellow			# prompt: waring color
    export txtblu='\033[0;34m' # Blue			
    export txtpur='\033[0;35m' # Purple
    export txtcyn='\033[0;36m' # Cyan			# prompt: info color
    export txtwht='\033[0;37m' # White
    export bldblk='\033[1;30m' # Black - Bold
    export bldred='\033[1;31m' # Red			# prompt: bold error color
    export bldgrn='\033[1;32m' # Green			# prompt: bold success color
    export bldylw="\033[1;33m" # Yellow                 # prompt: bold warning color
    export bldblu='\033[1;34m' # Blue				
    export bldpur='\033[1;35m' # Purple
    export bldcyn="\033[1;36m" # Cyan                   # prompt: bold info color
    export bldwht="\033[1;37m" # White			# prompt: bold default color

    export undblk='\033[4;30m' # Black - Underline
    export undred='\033[4;31m' # Red

    export bakblk='\033[40m'   # Black - Background
    export bakred='\033[41m'   # Red
    export badgrn='\033[42m'   # Green

    export txtrst='\033[0m'    # Text Reset		# prompt: default color
}

#######################################
###   :::   F U N C T I O N S   :::   #
#######################################

check_root() {
    if [[ ${EUID:-$(id -u)} > 0 ]]; then
        prompt -wq "Please run as root!"
    fi
}

# Check command availability
has_command() { command -v $1 &> /dev/null; }

 # echo like ... with flag type and display message colors
prompt() {
    [[ -n ${QUIET} ]] && return
    case ${1} in
	-s  | --success)	echo -e "${bldgrn}${@/#-s/}${txtrst}" ;;    			# print success message
	-sq | --success-quit)	echo -e "${bldgrn}${@/#-sq/}${txtrst}" && exit 1 ;;    		# print success message
	-e  | --error)   	echo -e "${bldred}ERROR:${@/#-e/}${txtrst}" ;;   		# print error message
	-eq | --error-quit)   	echo -e "${bldred}ERROR:${@/#-eq/}${txtrst}" && exit 1 ;;	# print error message
	-w  | --warning) 	echo -e "${bldylw}WARNING:${bldwht}${@/#-w/}${txtrst}" ;; 	# print warning message
	-wq | --warning-quit) 	echo -e "${bldylw}WARNING:${bldwht}${@/#-wq/}${txtrst}" && exit 1 ;; # print warning message
	-i  | --info)    	echo -e "${bldcyn}INFO:${txtcyn}${@/#-i/}${txtrst}" ;;    	# print info message
	-iq | --info-quit)    	echo -e "${bldcyn}INFO:${txtcyn}${@/#-iq/}${txtrst}" && exit 1 ;;  # print info message
	*)    			echo -e "$@" ;;							# print all message
    esac
}


usage() {
    printf "%s  %s\n" "${0##*/}" "version: ${VERSION_SCRIPT}"
    cat <<EOF
Manage boot UBLinux

Usage: ${0##*/} {COMMAND} [OPTIONS]

Commands:
  create		Create a new UBLinux root skeleton
  update		Update GRUB, boot.tar.xz, ublinux-data.tar.xz on boot partitional
Meta Commands:
  help          	Show this help

OPTIONS:
  -p, --path=PATH  	Path to the real root
			Without PATH for command 'update' PATH="/mnt/livemedia"
			Without PATH for command 'create' PATH="./"
  -s, --skel-ublinux	Create/Update skeleton '/ublinux'
    			The system settings will return to default "ublinux.ini"
  -d  --skel-data	Create/Update skeleton '/ublinux-data'
    			The system settings will return to default "ublinux.ini"
  -c, --grub-cfg	Create/Update GRUB configure
  -t, --grub-theme=NAME Create/Update GRUB theme
            		If the grub theme [NAME] is not found, 
            		then automatically select from the found installed theme
  -q, --quiet		Quiet mode
  -h, --help		Show this help
  -V, --version		Show package version

Examples:
${0##*/} create -sdc
${0##*/} update -sc -p /home/iso
${0##*/} update -d -p /mnt/livemedia
EOF
    exit 0
}

arguments() {
# Pre-process options to:
# - expand -xyz into -x -y -z
# - expand --longopt=arg into --longopt arg
    local ARGV=()
    local END_OF_OPT=
    while [[ $# -gt 0 ]]; do
	arg="$1"; shift
	case "${END_OF_OPT}${arg}" in
	    --) ARGV+=("$arg"); END_OF_OPT=1 ;;
	    --*=*)ARGV+=("${arg%%=*}" "${arg#*=}") ;;
	    --*) ARGV+=("$arg") ;;
	    -*) for i in $(seq 2 ${#arg}); do ARGV+=("-${arg:i-1:1}"); done ;;
	    *) ARGV+=("$arg") ;;
	esac
    done
# Apply pre-processed options
    set -- "${ARGV[@]}"
# Parse options
    local END_OF_OPT=
    local POSITIONAL_ARGS=()
    [[ -z $@ ]] && usage && exit 0
    while [[ $# -gt 0 ]]; do
	case "${END_OF_OPT}${1}" in
	    -h | --help | help)	  usage ;;
	    -p | --path)	  shift; PATH_ROOT="$1" ;;
	    -c | --grub-cfg)	  GRUB_CFG=1 ;;
	    -t | --grub-theme)	  [[ -n $2 ]] && ! grep -q "^-" <<< "$2" && shift && GRUB_THEME_NAME="$1" || GRUB_THEME_NAME="auto";;
	    -s | --skel-ublinux)  SKEL_UBLINUX=1 ;;
	    -d | --skel-data)	  SKEL_DATA=1 ;;
	    -q | --quiet)     	  QUIET=1 ;;
	    -V | --version)	  echo "Version: ${VERSION_SCRIPT}"; exit 0 ;;
	    update)    		  COMMAND="update" ;;
	    create)    		  COMMAND="create" ;;
	    --stdin)        	  READ_STDIN=1 ;;
	    --)             	  END_OF_OPT=1 ;;
	    -*|--*)         	  echo "WARNING: Unrecognized argument, skiped: $1" >&2  ;;
	    *)              	  POSITIONAL_ARGS+=("$1") ;;
	esac
	shift
    done
# Restore positional parameters
    set -- "${POSITIONAL_ARGS[@]}"
    [[ -z ${COMMAND} ]] && usage
    [[ -n ${PATH_ROOT} ]] && PATH_ROOT=$(realpath ${PATH_ROOT})
    if [[ ${COMMAND} == "update" ]]; then
	[[ -n ${PATH_ROOT} ]] && PATH_ROOT_MEDIA="${PATH_ROOT}" && PATH_ROOT_DATA="${PATH_ROOT}"
	[[ -z ${PATH_ROOT} ]] && PATH_ROOT_MEDIA="/mnt/livemedia" && PATH_ROOT_DATA="/mnt/livedata"
	[[ -w ${PATH_ROOT_MEDIA} && -w ${PATH_ROOT_DATA} ]] || exit 0
    fi
    if [[ ${COMMAND} == "create" ]]; then
	[[ -z ${PATH_ROOT} ]] && PATH_ROOT="${PATH_WORK}"
	[[ -w ${PATH_ROOT} ]] || exit 0
    fi
}

check_lib() {
    [[ -d ${PATH_UBBOOT_LIB} ]] || prompt -eq "path not found ${PATH_UBBOOT_LIB}"
    [[ -d ${PATH_TEMPLATE} ]] || prompt -eq "path not found ${PATH_TEMPLATE}"
    [[ -d ${PATH_TEMPLATE_UBINIT} ]] || prompt -eq "path not found ${PATH_TEMPLATE_UBINIT}"
    [[ -f ${FILE_LICENSE} ]] || prompt -eq "file not found ${FILE_LICENSE}"
    [[ -d ${PATH_GRUB_SHARE} ]] || prompt -eq "path not found ${PATH_GRUB_SHARE}"
    [[ -d ${PATH_GRUB_LIB} ]] || prompt -eq "path not found ${PATH_GRUB_LIB}"
}

install_pkg() {
    if [[ ${COMMAND} == "create" || -n ${GRUB_CFG} ]]; then
	if ! pacman -Qqs memtest86+ > /dev/null; then
	    prompt -i "install 'memtest86+' package" 
	    pacman --noconfirm -Sqy memtest86+ > /dev/null
	fi
    fi
}

oper_grub() {
    local PATH_ROOT_BOOT="$1/boot"
    local PATH_ROOT_GRUB="${PATH_ROOT_BOOT}/grub"
    local LOCAL_COMMAND="$2"
    [[ ! -d ${PATH_ROOT_GRUB} && ${LOCAL_COMMAND} == "update" ]] || install -dm0755 -o root -g root ${PATH_ROOT_GRUB}/ublinux
    if [[ -d ${PATH_ROOT_GRUB} ]]; then
        prompt -i "update GRUB configure to ${PATH_ROOT_GRUB}" 
        install -CDm0640 ${PATH_GRUB_SHARE}/unicode.pf2 "${PATH_ROOT_GRUB}/fonts/unicode.pf2"
        install -CDm0640 ${PATH_GRUB_SHARE}/ascii.pf2 "${PATH_ROOT_GRUB}/fonts/ascii.pf2"
        install -CDm0640 ${PATH_GRUB_SHARE}/euro.pf2 "${PATH_ROOT_GRUB}/fonts/euro.pf2"
        cd "${PATH_TEMPLATE}/grub"
        install -CDbm0640 root_grub.cfg "${PATH_ROOT_GRUB}/grub.cfg" 
        if [[ ${LOCAL_COMMAND} == "create" ]]; then
    	    install -CDbm0640 grubenv -t "${PATH_ROOT_GRUB}"
    	    install -CDbm0640 grub_var_user.cfg -t "${PATH_ROOT_GRUB}/ublinux" 
    	fi
        install -CDbm0640 -t "${PATH_ROOT_GRUB}/ublinux" \
	    gfxmenu.cfg \
    	    grub.cfg \
    	    grub_en.cfg \
    	    grub_ru_addon.cfg \
    	    grub_ru_boothdd.cfg \
    	    grub_ru_recovery.cfg \
    	    grub_ru.cfg \
    	    grub_var.cfg \
    	    modules.cfg
        install -dm0750 -o root -g root "${PATH_ROOT_GRUB}/ublinux/themes"
        [[ -f /boot/memtest86+/memtest.bin ]] && install -CDm0640 /boot/memtest86+/memtest.bin "${PATH_ROOT_BOOT}/memtest86+/memtest.bin"
    else
        prompt -e "not found GRUB path ${PATH_ROOT_GRUB}" 
	return 1
    fi
}

oper_grub_bin() {
    local PATH_ROOT_BOOT="$1/boot"
    local PATH_ROOT_GRUB="${PATH_ROOT_BOOT}/grub"
    local LOCAL_COMMAND="$2"
    [[ ! -d ${PATH_ROOT_GRUB} && ${LOCAL_COMMAND} == "update" ]] || install -dm0755 -o root -g root ${PATH_ROOT_GRUB}/ublinux
    if [[ -d ${PATH_ROOT_GRUB} ]]; then
        prompt -i "update GRUB binaries to ${PATH_ROOT_GRUB}" 
	cd ${PATH_GRUB_LIB}
	find . -type f -exec install -CDm0644 {} ${PATH_ROOT_GRUB}/{} \;
    else
        prompt -e "not found GRUB path ${PATH_ROOT_GRUB}" 
	return 1
    fi
}

oper_grub_theme() {
    local PATH_ROOT_GRUB_THEMES="$1/boot/grub/ublinux/themes"
    local PATH_ROOT_GRUB_FONTS="$1/boot/grub/fonts"
    local PATH_ROOT_UBLINUX="$1/ublinux"
    local PATH_THEME="${PATH_GRUB_SHARE}/themes"
    local GRUB_THEME_NAME="$2"
    local LOCAL_COMMAND="$3"
    [[ ! -d ${PATH_ROOT_GRUB_THEMES} && ${LOCAL_COMMAND} == "update" ]] || install -dm0755 -o root -g root ${PATH_ROOT_GRUB_THEMES}
    if [[ -z ${GRUB_THEME_NAME} || ${GRUB_THEME_NAME,,} == "auto" ]]; then
	if ls "${PATH_ROOT_UBLINUX}"/VERSION_* &> /dev/null; then
	    OS_RELEASE_PRETTY_NAME="$(cat ${PATH_ROOT_UBLINUX}/VERSION_* | head -1)"
	elif [[ -f /usr/lib/os-release ]]; then
	    OS_RELEASE_PRETTY_NAME="$(cat /usr/lib/os-release | grep "PRETTY_NAME=" | cut -d= -f2 | sed 's/"//g')"
	else
	    OS_RELEASE_PRETTY_NAME="UBLinux 0000 Unknown (x)"
	fi
	GRUB_THEME_NAME="$(${PATH_UBBOOT_LIB}/ubdistconv -d ${OS_RELEASE_PRETTY_NAME})"
    fi
    # If theme not found then select first found ublinux_*
    if [[ ! -d ${PATH_THEME}/${GRUB_THEME_NAME} ]]; then
	prompt -w "GRUB theme '${GRUB_THEME_NAME}' not found!"
	GRUB_THEME_NAME="$(ls -d ${PATH_THEME}/ublinux_* | head -1 | sed 's/.*\///')"
	prompt -i "first found GRUB theme selected: ${GRUB_THEME_NAME}"
    fi
    if [[ -d ${PATH_ROOT_GRUB_THEMES} && -d ${PATH_THEME} ]]; then
        prompt -i "update GRUB theme '${GRUB_THEME_NAME}'"
        cd ${PATH_THEME}
        find ${GRUB_THEME_NAME}/ -type f ! -iname "*.pf2" -exec install -CDm0640 {} ${PATH_ROOT_GRUB_THEMES}/{} \;
	cd ${GRUB_THEME_NAME}
        find . -type f -iname "*.pf2" -exec install -CDm0640 {} ${PATH_ROOT_GRUB_FONTS}/{} \;
        chmod 0750 ${PATH_ROOT_GRUB_THEMES}/${GRUB_THEME_NAME}
    else
        prompt -e "not found GRUB theme path '${PATH_ROOT_GRUB_THEMES}'"
	return 1
    fi
}

oper_skel_ublinux() {
    local PATH_ROOT_UBLINUX="$1/ublinux"
    local LOCAL_COMMAND="$2"
    [[ ! -d ${PATH_ROOT_UBLINUX} && ${LOCAL_COMMAND} == "update" ]] || install -dm0755 -o root -g root ${PATH_ROOT_UBLINUX}
    if [[ -d ${PATH_ROOT_UBLINUX} ]]; then
        prompt -i "update skeleton '${PATH_ROOT_UBLINUX}'"
	install -dm0750 -o root -g root \
	    "${PATH_ROOT_UBLINUX}/base" \
	    "${PATH_ROOT_UBLINUX}/machines/dynamic" \
	    "${PATH_ROOT_UBLINUX}/machines/static" \
	    "${PATH_ROOT_UBLINUX}/modules" \
	    "${PATH_ROOT_UBLINUX}/optional" 
	install -CDm0644 "${FILE_LICENSE}" "${PATH_ROOT_UBLINUX}/LICENSE"
	if [[ ${LOCAL_COMMAND} == "create" ]]; then
	    install -CDm0640 "${PATH_TEMPLATE_UBINIT}/ublinux.ini" "${PATH_ROOT_UBLINUX}/ublinux.ini"
	fi
	ls "${PATH_ROOT_UBLINUX}"/ublinux-*.sgn &>/dev/null || install -CDm0640 "${PATH_TEMPLATE_UBINIT}/ublinux.sgn" "${PATH_ROOT_UBLINUX}/ublinux.sgn"
	build_boot_tarxz "${PATH_ROOT_UBLINUX}"
	build_skel_ublinux_data_tarxz "${PATH_ROOT_UBLINUX}"
    else
        prompt -e "not found skeleton path '${PATH_ROOT_UBLINUX}'"
	return 1
    fi
}

oper_skel_ublinux_data() {
    local PATH_ROOT_UBLINUX_DATA="$1/ublinux-data"
    local LOCAL_COMMAND="$2"
    [[ ! -d ${PATH_ROOT_UBLINUX_DATA} && ${LOCAL_COMMAND} == "update" ]] || install -dm0755 -o root -g root ${PATH_ROOT_UBLINUX_DATA}
    if [[ -d ${PATH_ROOT_UBLINUX_DATA} ]]; then
        prompt -i "update skeleton '${PATH_ROOT_UBLINUX_DATA}'"
	install -dm0750 -o root -g root \
	    "${PATH_ROOT_UBLINUX_DATA}/cache" \
	    "${PATH_ROOT_UBLINUX_DATA}/modules" \
	    "${PATH_ROOT_UBLINUX_DATA}/optional" \
	    "${PATH_ROOT_UBLINUX_DATA}/upgrade"
	install -dm0755 -o root -g root \
	    "${PATH_ROOT_UBLINUX_DATA}/homes" \
	    "${PATH_ROOT_UBLINUX_DATA}/changes" \
	    "${PATH_ROOT_UBLINUX_DATA}/machines/dynamic" \
	    "${PATH_ROOT_UBLINUX_DATA}/machines/static" \
	    "${PATH_ROOT_UBLINUX_DATA}/rootcopy"
    	if [[ ${LOCAL_COMMAND} == "create" ]]; then 
	    install -CDm0640 "${PATH_TEMPLATE_UBINIT}/ublinux-data.ini" "${PATH_ROOT_UBLINUX_DATA}/ublinux.ini"
	elif [[ ${LOCAL_COMMAND} == "update" ]]; then
#	    cp --backup=numbered "${PATH_TEMPLATE_UBINIT}/ublinux-data.ini" "${PATH_ROOT_UBLINUX_DATA}/ublinux.ini"
#	    Запустить запись текущих настроек в обновлённый файл ublinux.ini
#	    ubconfig upgrade
	    chmod 0640 "${PATH_ROOT_UBLINUX_DATA}/ublinux.ini"
	fi		
	ls "${PATH_ROOT_UBLINUX_DATA}"/ublinux-data*.sgn &>/dev/null || install -CDm0640 "${PATH_TEMPLATE_UBINIT}/ublinux-data.sgn" "${PATH_ROOT_UBLINUX_DATA}/ublinux-data.sgn"
    else
        prompt -e "not found skeleton path '${PATH_ROOT_UBLINUX_DATA}'"
	return 1
    fi
}

build_boot_tarxz() {
    local PATH_SAVE_TARXZ="$1"
    local PATH_TMP_TARXZ=$(mktemp -d /tmp/${PKGNAME}.XXXX)
    oper_grub "${PATH_TMP_TARXZ}" "create"
    oper_grub_bin "${PATH_TMP_TARXZ}" "create"
    oper_grub_theme "${PATH_TMP_TARXZ}" "${GRUB_THEME_NAME}" "create"
    cd "${PATH_TMP_TARXZ}"
    tar -cvJf "${PATH_SAVE_TARXZ}/boot.tar.xz" "boot" >/dev/null 2>&1
    rm -rdf "${PATH_TMP_TARXZ}"
}

build_skel_ublinux_data_tarxz() {
    local PATH_SAVE_TARXZ="$1"
    local PATH_TMP_TARXZ=$(mktemp -d /tmp/${PKGNAME}.XXXX)
    oper_skel_ublinux_data "${PATH_TMP_TARXZ}" "create"
    cd "${PATH_TMP_TARXZ}"
    tar -cvJf "${PATH_SAVE_TARXZ}/ublinux-data.tar.xz" "ublinux-data" >/dev/null 2>&1
    rm -rdf "${PATH_TMP_TARXZ}"
}

create() {
    local PATH_ROOT="$1"
    if [[ -n ${SKEL_UBLINUX} ]]; then
	oper_grub "${PATH_ROOT}" "${COMMAND}"
	oper_grub_bin "${PATH_ROOT}" "${COMMAND}"
	oper_grub_theme "${PATH_ROOT}" "${GRUB_THEME_NAME}" "${COMMAND}"
	oper_skel_ublinux "${PATH_ROOT}" "${COMMAND}"
    fi
    if [[ -n ${SKEL_DATA} ]]; then
	oper_skel_ublinux_data "${PATH_ROOT}" "${COMMAND}"
    fi
}

update_grub_var_user() {
    local PATH_ROOT_MEDIA=$1
    local PATH_ROOT_DATA=$2
    UBLINUX_SGN=$(ls ${PATH_ROOT_MEDIA}/ublinux/ublinux*.sgn 2>/dev/null | head -1)
    UBLINUX_DATA_SGN=$(ls ${PATH_ROOT_DATA}/ublinux-data/ublinux*.sgn 2>/dev/null | head -1)
    GRUB_VAR_USER="${PATH_ROOT_MEDIA}/boot/grub/ublinux/grub_var_user.cfg"
    if [[ -n ${UBLINUX_SGN} ]]; then
	if grep -q "^set SGNFILE_UBLINUX=" "${GRUB_VAR_USER}" 2>/dev/null; then
	    sed -i "s/^\(set SGNFILE_UBLINUX\s*=\s*\).*\$/\1${UBLINUX_SGN##*/}/" "${GRUB_VAR_USER}"
	else
	    echo "set SGNFILE_UBLINUX=${UBLINUX_SGN##*/}" >> "${GRUB_VAR_USER}"
	    echo "export SGNFILE_UBLINUX" >> "${GRUB_VAR_USER}"
	fi
    fi
    if [[ -n ${UBLINUX_DATA_SGN} ]]; then
	if grep -q "^set SGNFILE_UBLINUX_DATA=" "${GRUB_VAR_USER}" 2>/dev/null; then
	    sed -i "s/^\(set SGNFILE_UBLINUX_DATA\s*=\s*\).*\$/\1${UBLINUX_DATA_SGN##*/}/" "${GRUB_VAR_USER}"
	else
	    echo "set SGNFILE_UBLINUX_DATA=${UBLINUX_DATA_SGN##*/}" >> "${GRUB_VAR_USER}"
	    echo "export SGNFILE_UBLINUX_DATA" >> "${GRUB_VAR_USER}"
	fi
    fi
}

###############################
###   :::   M A I N   :::   ###
###############################

    PKGNAME=${0##*/}
    PATH_WORK=$(realpath ${PWD})
    PATH_UBBOOT_LIB="/usr/lib/ubboot"
    PATH_TEMPLATE="/usr/share/ubboot"
    PATH_TEMPLATE_UBINIT="/usr/lib/ublinux/templates"
    FILE_LICENSE="/usr/share/licenses/ublinux/LICENSE"
    PATH_GRUB_SHARE="/usr/share/grub"
    PATH_GRUB_LIB="/usr/lib/grub"
    set_color
    arguments $@
    check_root
    check_lib
    install_pkg

    if [[ ${COMMAND} == "create" ]]; then
	create "${PATH_ROOT}"
#	update_grub_var_user "${PATH_ROOT}" "${PATH_ROOT}" "${COMMAND}"
    elif [[ ${COMMAND} == "update" ]]; then
	[[ -n ${GRUB_CFG} ]] && { oper_grub "${PATH_ROOT_MEDIA}" "${COMMAND}" || RESULT=1; }
	[[ -n ${GRUB_CFG} ]] && { update_grub_var_user "${PATH_ROOT_MEDIA}" "${PATH_ROOT_DATA}" "${COMMAND}" || RESULT=1; }
	[[ -n ${GRUB_THEME_NAME} ]] && { oper_grub_theme "${PATH_ROOT_MEDIA}" "${GRUB_THEME_NAME}" "${COMMAND}" || RESULT=1; }
	[[ -n ${SKEL_UBLINUX} ]] && { oper_skel_ublinux "${PATH_ROOT_MEDIA}" "${COMMAND}" || RESULT=1; }
	[[ -n ${SKEL_DATA} ]] && { oper_skel_ublinux_data "${PATH_ROOT_DATA}" "${COMMAND}" || RESULT=1; }
    fi
    [[ ${RESULT} < 1 ]] || exit 1
    