From 53037d812faa5a3023fe7bc80901fadd8064432b Mon Sep 17 00:00:00 2001 From: vcatafesta Date: Sun, 24 Sep 2023 00:39:42 -0400 Subject: [PATCH] dom 24 set 2023 00:39:42 -04 Vilmar Catafesta (vcatafesta@gmail.com) --- pkgbuild/PKGBUILD | 34 +++- usr/share/bigbashview/bcc/shell/bcclib.sh | 175 +++++++++++++++++- usr/share/bigbashview/bcc/shell/bcfglib.sh | 2 +- usr/share/bigbashview/bcc/shell/bstrlib.sh | 101 ++++++---- usr/share/bigbashview/bcc/shell/getbgcolor.sh | 28 +-- usr/share/bigbashview/bcc/shell/setbgcolor.sh | 6 +- 6 files changed, 286 insertions(+), 60 deletions(-) diff --git a/pkgbuild/PKGBUILD b/pkgbuild/PKGBUILD index 181003d..f801d76 100644 --- a/pkgbuild/PKGBUILD +++ b/pkgbuild/PKGBUILD @@ -1,6 +1,8 @@ +# Maintainer : Vilmar Catafesta + + pkgname=bigcontrolcenter-base pkgdesc="Base files and libs to bigcontrolcenter interfaces" -depends=('bigbashview' ) # makedepends=('') # conflicts=('') pkgver=$(date +%y.%m.%d) @@ -9,6 +11,36 @@ arch=('any') license=('GPL3') url="https://github.com/biglinux/$pkgname" provides=("$pkgname") +depends=('bash' + 'curl' + 'coreutils' # cat, cut, mkdir,rmdir, rm, sort, uniq, ... etc + 'util-linux' # rev + 'gawk' + 'grep' + 'jq' + 'pamac-gtk' + 'paru' + 'polkit' + 'parallel' + 'rxvt-unicode' + 'sed' + 'xorg-xwininfo' + 'xorg-xrandr' + 'xorg-xprop' # xprop + 'xsetprop' # xsetprop + 'xtermset' + 'wmctrl' # wmctrl + 'yay' + 'yad' + 'libnotify' # notify-send + 'kdialog' + 'lsof' + 'libnewt' # whiptail + 'procps-ng' # pipof, pgrep + 'pacman' + 'pacman-mirrors' + 'mhwd' + ) source=("git+${url}.git") md5sums=('SKIP') if [ -e "${pkgname}.install" ];then diff --git a/usr/share/bigbashview/bcc/shell/bcclib.sh b/usr/share/bigbashview/bcc/shell/bcclib.sh index 17ac7ff..f32ab11 100755 --- a/usr/share/bigbashview/bcc/shell/bcclib.sh +++ b/usr/share/bigbashview/bcc/shell/bcclib.sh @@ -6,7 +6,7 @@ # Description: Control Center to help usage of BigLinux # # Created: 2022/02/28 -# Altered: 2023/09/02 +# Altered: 2023/09/24 # # Copyright (c) 2023-2023, Vilmar Catafesta # 2022-2023, Bruno Gonçalves @@ -33,8 +33,11 @@ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +[[ -n "$LIB_BCCLIB_SH" ]] && return +LIB_BCCLIB_SH=1 + APP="${0##*/}" -_VERSION_="1.0.0-20230902" +_VERSION_="1.0.0-20230924" #BOOTLOG="/tmp/bigcontrolcenter-$USER-$(date +"%d%m%Y").log" LOGGER='/dev/tty8' @@ -616,10 +619,10 @@ function sh_install_terminal { "install_snap") if [[ ! -e "$HOME_FOLDER/disable_snap_unused_remove" ]]; then pkexec env DISPLAY="$DISPLAY" XAUTHORITY="$XAUTHORITY" snap install "$PACKAGE_NAME" - sh_snap_clean + sh_snap_clean else snap install "$PACKAGE_NAME" - sh_snap_clean + sh_snap_clean fi ;; "remove_snap") @@ -636,6 +639,7 @@ function sh_install_terminal { "reinstall_allpkg") pkexec env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY sh_reinstall_allpkg ;; "system_upgrade") pkexec env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY pamac update --no-confirm ;; "system_upgradetotal") pkexec env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY bigsudo pacman -Syyu --noconfirm ;; + "enable_snapd") sh_enable_snapd_and_apparmor;; esac fi @@ -674,6 +678,169 @@ function sh_install_terminal_resize { } export -f sh_install_terminal_resize +# Função para atualizar um valor no arquivo INI ou criar o arquivo se não existir +# Exemplo de uso: atualize o valor da chave "versao" da seção "App" no arquivo "config.ini" +# tini.write_value "config.ini" "App" "versao" "2.0" +function tini.write_value { + local config_file="$1" + local section="$2" + local key="$3" + local new_value="$4" + + declare -A ini_data # Array associativo para armazenar as seções e chaves + + if [[ -f "$config_file" ]]; then + # Ler o arquivo INI e armazenar as informações em um array associativo + local current_section="" + while IFS= read -r line; do + if [[ "$line" =~ ^\[(.*)\] ]]; then + current_section="${BASH_REMATCH[1]}" + elif [[ "$line" =~ ^([^=]+)=(.*) ]]; then + local current_key="${BASH_REMATCH[1]}" + local current_value="${BASH_REMATCH[2]}" + ini_data["$current_section,$current_key"]="$current_value" + fi + done <"$config_file" + fi + + # Atualizar o valor no array associativo + ini_data["$section,$key"]="$new_value" + +:<<'comment' + # Extrair as chaves do array associativo para um array de strings + keys=("${!ini_data[@]}") + + # Ordenar o array de chaves pelo section_key + IFS=$'\n' sorted_keys=($(sort <<<"${keys[*]}")) + unset IFS + + # Iterar sobre as chaves ordenadas e acessar os valores correspondentes no array associativo + for sorted_key in "${sorted_keys[@]}"; do + local key="${key_pair##*,}" + local section_key="${sorted_key%,*}" + local value="${ini_data[$sorted_key]}" + # Faça o que você precisa com section_key e value aqui + done +comment + + # Reescrever o arquivo INI com as seções e chaves atualizadas + >"$config_file" + local current_section="" + for section_key in "${!ini_data[@]}"; do + local section_name="${section_key%,*}" + local key_name="${section_key#*,}" + local value="${ini_data[$section_key]}" + + # Verifique se a seção já foi gravada + if [[ "$current_section" != "$section_name" ]]; then + echo "" >>"$config_file" + echo "[$section_name]" >>"$config_file" + current_section="$section_name" + fi + echo "$key_name=$value" >>"$config_file" + done + tini.align_ini_file "$config_file" +} +export -f tini.write_value + +# Função para atualizar o valor de uma chave em uma seção no arquivo INI +function tini.update_value { + local config_file="$1" + local section="$2" + local key="$3" + local new_value="$4" + + if [[ -f "$config_file" ]]; then + sed -i "/^\[$section\]/s/^$key=.*/$key=$new_value/" "$config_file" + fi +} +export -f tini.update_value + +# Função para verificar se um valor em uma seção corresponde a um valor de referência em um arquivo INI +# tini.exist_value "config.ini" "flatpak" "active" '0'; echo $? +# tini.exist_value "config.ini" "snapd" "active" '1'; echo $? +# tini.exist_value "config.ini" "flatpak" "active" '1'; echo $? +# tini.exist_value "config.ini" "snapd" "active" '0'; echo $? +# tini.exist_value "config.ini" "snapd" "xactive" '0'; echo $? +function tini.exist_value { + local config_file="$1" + local section="$2" + local key="$3" + local comp_value="$4" + + if [[ -f "$config_file" ]]; then + local section_found=false + local key_found=false + local value="" + + while IFS= read -r line; do + if [[ "$line" == "[$section]" ]]; then + section_found=true + elif [[ "$line" == "["* ]]; then + section_found=false + fi + + if [[ "$section_found" == true && "$line" == "$key="* ]]; then + value=$(echo "$line" | cut -d'=' -f2) + key_found=true + fi + + if [[ "$section_found" == true && "$key_found" == true ]]; then + if [[ "$value" == "$comp_value" ]]; then + return 0 # Valor encontrado e corresponde ao valor de referência + else + return 1 # Valor encontrado, mas não corresponde ao valor de referência + fi + fi + done < "$config_file" + fi + return 2 # Seção ou chave não encontrada no arquivo INI +} +export -f tini.exist_value + +# Função para ler um valor do arquivo INI +# tini.read_value "config.ini" "flatpak" "active" +function tini.read_value { + local config_file="$1" + local section="$2" + local key="$3" + local found_section=false + + # Variável para armazenar o valor encontrado + local value="" + + # Use grep para encontrar a chave na seção especificada no arquivo INI + while IFS= read -r line; do + if [[ "$line" =~ ^\[$section\] ]]; then + found_section=true + elif [[ "$found_section" == true && "$line" =~ ^$key= ]]; then + # Encontramos a chave dentro da seção + value=$(echo "$line" | cut -d'=' -f2) + break # Saia do loop, pois encontramos o valor + elif [[ "$line" =~ ^\[.*\] ]]; then + # Se encontrarmos outra seção, saia do loop para evitar procurar em outras seções + found_section=false + fi + done < "$config_file" + + # Verifique se encontramos o valor + if [[ -n "$value" ]]; then + echo "$value" + else + echo "Chave não encontrada." + fi +} +export -f tini.read_value + +function tini.align_ini_file { + local fini="$1" + local fini_tmp=(mktemp "$fini-xxx") + awk 'BEGIN { insection=0; } /^\[.*\]$/ { if (!seen[$0]++) print; insection=1; next; } insection { print; }' "$fini" > "$fini_tmp" + sed -i '/^[[:space:]]*$/d' "$fini_tmp" + mv -f "$fini_tmp" "$fini" +} +export -f tini.align_ini_file + function sh_main { local execute_app="$1" diff --git a/usr/share/bigbashview/bcc/shell/bcfglib.sh b/usr/share/bigbashview/bcc/shell/bcfglib.sh index 1784488..b1c5fde 100755 --- a/usr/share/bigbashview/bcc/shell/bcfglib.sh +++ b/usr/share/bigbashview/bcc/shell/bcfglib.sh @@ -57,7 +57,7 @@ function sh_reset_chromium { return fi - rm -r ~/.config/chromium + rm -r ~/.config/chromium rm -r ~/.config/chromium-optimize if [ "$1" = "skel" ]; then cp -r /etc/skel/.config/chromium ~/.config/chromium diff --git a/usr/share/bigbashview/bcc/shell/bstrlib.sh b/usr/share/bigbashview/bcc/shell/bstrlib.sh index ed353aa..32f8427 100755 --- a/usr/share/bigbashview/bcc/shell/bstrlib.sh +++ b/usr/share/bigbashview/bcc/shell/bstrlib.sh @@ -6,7 +6,7 @@ # Description: Big Store installing programs for BigLinux # # Created: 2023/08/11 -# Altered: 2023/09/02 +# Altered: 2023/09/24 # # Copyright (c) 2023-2023, Vilmar Catafesta # All rights reserved. @@ -31,6 +31,13 @@ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +[[ -n "$LIB_BSTRLIB_SH" ]] && return +LIB_BSTRLIB_SH=1 + +APP="${0##*/}" +_VERSION_="1.0.0-20230924" +LOGGER='/dev/tty8' + export HOME_FOLDER="$HOME/.bigstore" export TMP_FOLDER="/tmp/bigstore-$USER" unset GREP_OPTIONS @@ -635,30 +642,6 @@ function sh_pkg_pacman_build_date { } export -f sh_pkg_pacman_build_date -function sh_run_pamac_remove { - packages_to_remove=$(LC_ALL=C timeout 10s pamac remove -odc "$*" | awk '/^ / { print $1 }') - pamac-installer --remove "$@" $packages_to_remove & - PID="$!" - if [[ -z "$PID" ]]; then - exit - fi - - CONTADOR=0 - while [ $CONTADOR -lt 100 ]; do - if [ "$(wmctrl -p -l | grep -m1 " $PID " | cut -f1 -d" ")" != "" ]; then - xsetprop -id="$(wmctrl -p -l | grep -m1 " $PID " | cut -f1 -d" ")" --atom WM_TRANSIENT_FOR --value "$(wmctrl -p -l -x | grep Big-Store$ | cut -f1 -d" ")" -f 32x - wmctrl -i -r "$(wmctrl -p -l | grep -m1 " $PID " | cut -f1 -d" ")" -b add,skip_pager,skip_taskbar - wmctrl -i -r "$(wmctrl -p -l | grep -m1 " $PID " | cut -f1 -d" ")" -b toggle,modal - break - fi - - sleep 0.1 - ((++CONTADOR)) - done - wait -} -export -f sh_run_pamac_remove - function sh_update_cache_snap { folder_to_save_files="$HOME_FOLDER/snap_list_files/snap_list" file_to_save_cache="$HOME_FOLDER/snap.cache" @@ -679,17 +662,17 @@ function sh_update_cache_snap { # jq -r '._embedded."clickindex:package"[]| select( .package_name == "wps-2019-snap" )' $folder_to_save_files* # Lê na pagina inicial quantas paginas devem ser baixadas e salva o valor na variavel $number_of_pages - # echo "Baixando header: $SITE" - notify-send --icon=big-store --app-name "$0" "$TITLE" "Baixando header: $SITE" --expire-time=2000 +# echo "Baixando header: $SITE" +# notify-send --icon=big-store --app-name "$0" "$TITLE" "Baixando header: $SITE" --expire-time=2000 number_of_pages="$(curl --silent --compressed --insecure --url "$SITE" | jq -r '._links.last' | sed 's|.*page=||g;s|"||g' | grep '[0-9]')" if ((number_of_pages)); then # Baixa os arquivos em paralelo - parallel --gnu --jobs 100% \ + parallel --gnu --jobs 50% \ "curl --compressed --silent --insecure -s --url '${URL}{}' --continue-at - --output '${folder_to_save_files}{}'" ::: $(seq 1 $number_of_pages) # Filtra e processa os arquivos em paralelo - parallel --gnu --jobs 100% \ + parallel --gnu --jobs 50% \ "jq -r '._embedded.\"clickindex:package\"[]| .title + \"|\" + .snap_id + \"|\" + .media[0].url + \"|\" + .summary + \"|\" + .version + \"|\" + .package_name + \"|\"' '${folder_to_save_files}{}' | sort -u >> '${file_to_save_cache}'" ::: $(seq 1 $number_of_pages) # Aguarda o processamento wait @@ -754,7 +737,7 @@ function sh_update_cache_flatpak { # rev | uniq --skip-fields=2 | rev > "$CACHE_FILE" rev | uniq --skip-fields=2 | rev | # Utiliza o parallel para escrever o resultado no arquivo - parallel --gnu --jobs 100% "echo {} >> '$CACHE_FILE'" + parallel --gnu --jobs 50% "echo {} >> '$CACHE_FILE'" wait # Executa o comando flatpak update para listar atualizações disponíveis @@ -763,7 +746,7 @@ function sh_update_cache_flatpak { # for i in $(LC_ALL=C flatpak update | grep "^ [1-9]" | awk '{print $2}'); do # sed -i "s/|${i}.*/&update|/" "$CACHE_FILE" # done - LC_ALL=C flatpak update | grep "^ [1-9]" | awk '{print $2}' | parallel --gnu --jobs 100% \ + LC_ALL=C flatpak update | grep "^ [1-9]" | awk '{print $2}' | parallel --gnu --jobs 50% \ "sed -i 's/|{}.*$/&update|/' '$CACHE_FILE'" wait @@ -802,13 +785,57 @@ function sh_snap_clean { } export -f sh_snap_clean -function sh_snap_enable { - systemctl start snapd - systemctl enable snapd - systemctl start apparmor - systemctl enable apparmor +function sh_package_is_installed { + pacman -Q $1 + return $? } -export -f sh_snap_enable +export -f sh_package_is_installed + +function sh_enable_snapd_and_apparmor { + # need param in boot loader + # linux /boot/vmlinuz-linux root=UUID=978e3e81-8048-4ae1-8a06-aa727458e8ff quiet splash apparmor=1 security=apparmor + # /etc/default/grub + # GRUB_CMDLINE_LINUX_DEFAULT="quiet apparmor=1 security=apparmor" + + if sh_package_is_installed 'apparmor'; then + systemctl enable --now apparmor + if sh_package_is_installed 'snapd'; then + systemctl enable --now snapd + fi + fi + systemctl status apparmor +# systemctl status snapd +# failed +# inactive +# active + systemctl is-active apparmor + systemctl is-active snapd +} +export -f sh_enable_snapd_and_apparmor + +function sh_run_pamac_remove { + packages_to_remove=$(LC_ALL=C timeout 10s pamac remove -odc "$*" | awk '/^ / { print $1 }') + pamac-installer --remove "$@" $packages_to_remove & + PID="$!" + if [[ -z "$PID" ]]; then + exit + fi + + CONTADOR=0 + while [ $CONTADOR -lt 100 ]; do + if [ "$(wmctrl -p -l | grep -m1 " $PID " | cut -f1 -d" ")" != "" ]; then + xsetprop -id="$(wmctrl -p -l | grep -m1 " $PID " | cut -f1 -d" ")" --atom WM_TRANSIENT_FOR --value "$(wmctrl -p -l -x | grep Big-Store$ | cut -f1 -d" ")" -f 32x + wmctrl -i -r "$(wmctrl -p -l | grep -m1 " $PID " | cut -f1 -d" ")" -b add,skip_pager,skip_taskbar + wmctrl -i -r "$(wmctrl -p -l | grep -m1 " $PID " | cut -f1 -d" ")" -b toggle,modal + break + fi + + sleep 0.1 + ((++CONTADOR)) + done + wait +} +export -f sh_run_pamac_remove function sh_run_pamac_installer { local action="$1" diff --git a/usr/share/bigbashview/bcc/shell/getbgcolor.sh b/usr/share/bigbashview/bcc/shell/getbgcolor.sh index 271caef..e940b04 100755 --- a/usr/share/bigbashview/bcc/shell/getbgcolor.sh +++ b/usr/share/bigbashview/bcc/shell/getbgcolor.sh @@ -1,24 +1,24 @@ -#!/bin/bash +#!/usr/bin/env bash # Open Autodetect and read saved background color if [ ! -e "$HOME/.config/bigbashview_lightmode" ]; then - # Read background color - KDE_BG_COLOR="$(kreadconfig5 --group "Colors:Window" --key BackgroundNormal | sed 's|^|(|g;s|,|+|g;s|$|)/3|g' | bc)" + # Read background color + KDE_BG_COLOR="$(kreadconfig5 --group "Colors:Window" --key BackgroundNormal | sed 's|^|(|g;s|,|+|g;s|$|)/3|g' | bc)" - # Verify if is light or not - if [ "$KDE_BG_COLOR" -gt "127" ]; then - echo '' - else - echo '' - fi + # Verify if is light or not + if [ "$KDE_BG_COLOR" -gt "127" ]; then + echo '' + else + echo '' + fi else - if [ "$(cat "$HOME/.config/bigbashview_lightmode")" = "1" ]; then - echo '' - else - echo '' - fi + if [ "$(cat "$HOME/.config/bigbashview_lightmode")" = "1" ]; then + echo '' + else + echo '' + fi fi # Close Autodetect and read saved background color diff --git a/usr/share/bigbashview/bcc/shell/setbgcolor.sh b/usr/share/bigbashview/bcc/shell/setbgcolor.sh index 2d54c6f..6764196 100755 --- a/usr/share/bigbashview/bcc/shell/setbgcolor.sh +++ b/usr/share/bigbashview/bcc/shell/setbgcolor.sh @@ -1,7 +1,7 @@ -#!/bin/bash +#!/usr/bin/env bash if [ "$1" = "true" ]; then - echo '1' > ~/.config/bigbashview_lightmode + echo '1' >~/.config/bigbashview_lightmode else - echo '0' > ~/.config/bigbashview_lightmode + echo '0' >~/.config/bigbashview_lightmode fi