From acc7907a724708fbebdd5f74e84e2cd3a0f488e4 Mon Sep 17 00:00:00 2001 From: Anthony Axenov Date: Wed, 12 Apr 2023 16:47:46 +0800 Subject: [PATCH 1/5] fix-obs-vcam revamped --- tools/fix-obs-vcam.sh | 48 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/tools/fix-obs-vcam.sh b/tools/fix-obs-vcam.sh index 9a23939..ac2d209 100755 --- a/tools/fix-obs-vcam.sh +++ b/tools/fix-obs-vcam.sh @@ -1,4 +1,50 @@ #!/bin/bash +# https://obsproject.com/kb/virtual-camera-troubleshooting # https://obsproject.com/forum/threads/how-to-start-virtual-camera-without-sudo-privileges.139783/ -sudo modprobe v4l2loopback video_nr=2 card_label="OBS Virtual Camera" +# https://blog.csdn.net/qq_43008667/article/details/128041455 +# https://blog.jbrains.ca/permalink/using-obs-studio-as-a-virtual-cam-on-linux +# https://github.com/obsproject/obs-studio/issues/4808 + +# v4l2loopback-dkms + +# obs_start() +# { +# #This function is intended to prevent blank cameras in OBS upon OBS restart / exit +# #1. load/refresh uvcvideo before starting obs +# if lsmod | grep -q 'uvcvideo'; then +# sudo rmmod uvcvideo +# fi +# sudo modprobe uvcvideo +# #2. since no environment with a keyring to prompt for allowing virtual webcams prior is a must +# sudo modprobe v4l2loopback video_nr=10 card_label='OBS Virtual Camera' +# sleep 1 +# sh -c "$obs_cmd --startvirtualcam || sleep 3; sudo rmmod uvcvideo" +# } + +installed () { + command -v $1 > /dev/null +} + +installed 'obs' && obs_cmd='obs' +installed 'obs-studio' && obs_cmd='obs-studio' + +# obs executes this command when you start virtual camera +# sudo modprobe v4l2loopback exclusive_caps=1 card_label="OBS Virtual Camera" + +# another version from one of links below +# sudo modprobe v4l2loopback video_nr=2 devices=1 card_label="OBS Virtual Camera" + +sudo modprobe -r v4l2loopback || sudo rmmod v4l2loopback +if [[ $? == 0 ]]; then + sudo modprobe v4l2loopback video_nr=2 devices=1 card_label="OBS Virtual Camera" + if [[ $? == 0 ]]; then + $obs_cmd --startvirtualcam & disown + else + echo "Cannot run modprobe. Ensure v4l2loopback-dkms is installed and try again" + exit 1 + fi +else + echo "Cannot remove v4l2loopback device" + exit 2 +fi From c261d62b36954ee1991d386889370679bc1caf55 Mon Sep 17 00:00:00 2001 From: Anthony Axenov Date: Wed, 12 Apr 2023 17:00:41 +0800 Subject: [PATCH 2/5] new jetbrains mono fonts installer --- install/jbmono | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100755 install/jbmono diff --git a/install/jbmono b/install/jbmono new file mode 100755 index 0000000..a610105 --- /dev/null +++ b/install/jbmono @@ -0,0 +1,22 @@ +#!/bin/bash +##makedesc: Install JetBrains Mono fonts + +# https://www.jetbrains.com/lp/mono/#how-to-install + +echo +echo "===============================================" +echo "Installing JetBrains Mono fonts..." +echo "===============================================" +echo + +installed() { + command -v "$1" >/dev/null 2>&1 +} + +! installed wget && sudo apt install wget +! installed unzip && sudo apt install unzip + +mkdir -p "$HOME/install/jbmono" "$HOME/.local/share/fonts/" +wget https://download.jetbrains.com/fonts/JetBrainsMono-2.304.zip -O "$HOME/install/jbmono.zip" && \ + unzip -oj "$HOME/install/jbmono.zip" "fonts/ttf/*.ttf" -d "$HOME/.local/share/fonts/" && \ + fc-cache -vf "$HOME/.local/share/fonts/" From 4670ee9b576367272b3d068d8e9ac242c1e00e24 Mon Sep 17 00:00:00 2001 From: Anthony Axenov Date: Wed, 12 Apr 2023 17:03:00 +0800 Subject: [PATCH 3/5] makefile updated --- Makefile | 18 +++++++++++++----- gen-makefile | 2 +- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 98b27c7..8c4ec52 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -# Autogenerated at 01.02.2023 22:27 using ./gen-makefile +# Autogenerated at 12.04.2023 17:02 using ./gen-makefile .DEFAULT_GOAL := help #=============================================== @@ -57,11 +57,15 @@ golang: grubc: @./install/grubc +##jbmono: Install JetBrains Mono fonts +jbmono: + @./install/jbmono + ##kde-appmenu: Install KDE Window AppMenu Applet kde-appmenu: @./install/kde-appmenu -##kde-backports: Install KDE Backports + ppa +##kde-backports: Install KDE Backports kde-backports: @./install/kde-backports @@ -169,6 +173,10 @@ syncthing: telebit: @./install/telebit +##telegram: Install telegram (latest) +telegram: + @./install/telegram + ##ulauncher: Install ulauncher (latest) + ppa ulauncher: @./install/ulauncher @@ -181,7 +189,7 @@ vivaldi: wine: @./install/wine -##youtube-dl: Install youtube-dl +##youtube-dl: Install youtube-dl (src) youtube-dl: @./install/youtube-dl @@ -202,7 +210,7 @@ zsh: # Scripts listed in ./packs #=============================================== -##flameshot: [TODO] qt5 + flameshot from source +##flameshot: [TODO] [PACK] qt5 + flameshot from source flameshot: qt5 flameshot-build ##lamp: [PACK] Apache + php + mariadb @@ -271,7 +279,7 @@ help: Makefile @echo "\nAvailable GOALs:" @sed -n 's/^##//p' $< | column -ts ':' | sed -e "s/^/\t/" +%: - @ + @make ^%: @./upgrade/ @%: diff --git a/gen-makefile b/gen-makefile index 6e616db..e0cbb7a 100755 --- a/gen-makefile +++ b/gen-makefile @@ -87,7 +87,7 @@ help: Makefile @echo "\nAvailable GOALs:" @sed -n 's/^##//p' $< | column -ts ':' | sed -e "s/^/\t/" +%: - @$(MAKE) $* + @make $* ^%: @./upgrade/$* @%: From 86c7c92ae0ac2df448957c8f90713f5ad52a74a9 Mon Sep 17 00:00:00 2001 From: Anthony Axenov Date: Wed, 12 Apr 2023 19:05:12 +0800 Subject: [PATCH 4/5] fixes in makefile generation --- Makefile | 16 ++++++---------- gen-makefile | 8 ++------ 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/Makefile b/Makefile index 8c4ec52..d3bc5d5 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -# Autogenerated at 12.04.2023 17:02 using ./gen-makefile +# Autogenerated at 12.04.2023 19:04 using ./gen-makefile .DEFAULT_GOAL := help #=============================================== @@ -234,7 +234,7 @@ phpstack: php phptools # Scripts listed in ./upgrade #=============================================== -# Upgrade omz +##^omz: Upgrade omz ^omz: @./upgrade/omz @@ -242,19 +242,19 @@ phpstack: php phptools # Scripts listed in ./uninstall #=============================================== -# Uninstall docker + ppa +##/docker: Uninstall docker + ppa /docker: @./uninstall/docker -# Uninstall lite-xl +##/lite-xl: Uninstall lite-xl /lite-xl: @./uninstall/lite-xl -# Uninstall omz +##/omz: Uninstall omz /omz: @./uninstall/omz -# Uninstall vivaldi + ppa +##/vivaldi: Uninstall vivaldi + ppa /vivaldi: @./uninstall/vivaldi @@ -280,7 +280,3 @@ help: Makefile @sed -n 's/^##//p' $< | column -ts ':' | sed -e "s/^/\t/" +%: @make -^%: - @./upgrade/ -@%: - @./uninstall/ diff --git a/gen-makefile b/gen-makefile index e0cbb7a..725ce40 100755 --- a/gen-makefile +++ b/gen-makefile @@ -47,7 +47,7 @@ for file in ./upgrade/*; do name=${name%.sh} desc=$(grep -m 1 -oP "(?<=^##makedesc:\s).*$" ${file}) [ -z "$desc" ] && desc='' - echo -e "# ${desc}\n${CHR_UPGRADE}${name}:\n\t@${file}\n" >> Makefile + echo -e "##${CHR_UPGRADE}${name}: ${desc}\n${CHR_UPGRADE}${name}:\n\t@${file}\n" >> Makefile done; cat << EOF >> Makefile @@ -62,7 +62,7 @@ for file in ./uninstall/*; do name=${name%.sh} desc=$(grep -m 1 -oP "(?<=^##makedesc:\s).*$" ${file}) [ -z "$desc" ] && desc='' - echo -e "# ${desc}\n${CHR_UNINSTALL}${name}:\n\t@${file}\n" >> Makefile + echo -e "##${CHR_UNINSTALL}${name}: ${desc}\n${CHR_UNINSTALL}${name}:\n\t@${file}\n" >> Makefile done; cat << EOF >> Makefile @@ -88,10 +88,6 @@ help: Makefile @sed -n 's/^##//p' $< | column -ts ':' | sed -e "s/^/\t/" +%: @make $* -^%: - @./upgrade/$* -@%: - @./uninstall/$* EOF echo "New ./Makefile has been generated!" From 19d9f17f772d00539f10546e7ce89ae4bbb0f34d Mon Sep 17 00:00:00 2001 From: Anthony Axenov Date: Wed, 12 Apr 2023 19:06:42 +0800 Subject: [PATCH 5/5] testing new helper functions in jbmono --- helpers | 196 +++++++++++++++++++++++++++++++++++++++++++++++++ install/jbmono | 18 ++--- 2 files changed, 201 insertions(+), 13 deletions(-) create mode 100644 helpers diff --git a/helpers b/helpers new file mode 100644 index 0000000..25c27da --- /dev/null +++ b/helpers @@ -0,0 +1,196 @@ +#!/bin/bash + +installed() { + command -v "$1" >/dev/null 2>&1 +} + +title() { + [ "$1" ] && title="$1" || title="$(grep -m 1 -oP "(?<=^##makedesc:\s).*$" ${BASH_SOURCE[1]})" + info + info "===============================================" + info "$title" + info "===============================================" + info +} + +require() { + if ! installed "$1"; then + if [ "$2" ]; then + die "'$1' must to be installed in your system" 200 + else + info "Installing '$1' because it is required to continue" + sudo apt install "$1" + [ $? -gt 0 ] && die "installation cancelled" 201 + fi + fi +} + +download() { + require wget 1 + wget "$1" -O "$2" +} + +abspath() { + echo $(realpath -q "${1/#\~/$HOME}") +} + +is_writable() { + [ -w "$(abspath $1)" ] +} + +is_dir() { + [ -d "$(abspath $1)" ] +} + +is_file() { + [ -f "$(abspath $1)" ] +} + +is_function() { + declare -F "$1" > /dev/null +} + +regex_match() { + printf "%s" "$1" | grep -qP "$2" +} + +in_array() { + local find=$1 + shift + for e in "$@"; do + [[ "$e" == "$find" ]] && return 0 + done + return 1 +} + +implode() { + local d=${1-} + local f=${2-} + if shift 2; then + printf %s "$f" "${@/#/$d}" + fi +} + +IINFO="( i )" +INOTE="( * )" +IWARN="( # )" +IERROR="( ! )" +IFATAL="( @ )" +ISUCCESS="( ! )" +IASK="( ? )" +IDEBUG="(DBG)" +IVRB="( + )" + +BOLD="\e[1m" +DIM="\e[2m" +NOTBOLD="\e[22m" # sometimes \e[21m +NOTDIM="\e[22m" +NORMAL="\e[20m" +RESET="\e[0m" + +FRESET="\e[39m" +FBLACK="\e[30m" +FWHITE="\e[97m" +FRED="\e[31m" +FGREEN="\e[32m" +FYELLOW="\e[33m" +FBLUE="\e[34m" +FLRED="\e[91m" +FLGREEN="\e[92m" +FLYELLOW="\e[93m" +FLBLUE="\e[94m" + +BRESET="\e[49m" +BBLACK="\e[40m" +BWHITE="\e[107m" +BRED="\e[41m" +BGREEN="\e[42m" +BYELLOW="\e[43m" +BBLUE="\e[44m" +BLRED="\e[101m" +BLGREEN="\e[102m" +BLYELLOW="\e[103m" +BLBLUE="\e[104m" + +dt() { + echo "[$(date +'%H:%M:%S')] " +} + +ask() { + IFS= read -rp "$(print ${BOLD}${BBLUE}${FWHITE}${IASK}${BRESET}\ ${BOLD}$1 ): " $2 +} + +print() { + echo -e "$*${RESET}" +} + +debug() { + if [ "$2" ]; then + print "${DIM}${BOLD}${RESET}${DIM} ${FUNCNAME[1]:-?}():${BASH_LINENO:-?}\t$1 " + else + print "${DIM}${BOLD}${RESET}${DIM}$1 " + fi +} + + +verbose() { + print "${BOLD}${IVRB}${RESET}${FYELLOW} $1 " +} + +info() { + print "${BOLD}${FWHITE}${BLBLUE}${IINFO}${RESET}${FWHITE} $1 " +} + +note() { + print "${BOLD}${DIM}${FWHITE}${INOTE}${RESET} $1 " +} + +success() { + print "${BOLD}${BGREEN}${FWHITE}${ISUCCESS}${BRESET}$FGREEN $1 " +} + +warn() { + print "${BOLD}${BYELLOW}${FBLACK}${IWARN}${BRESET}${FYELLOW} Warning:${RESET} $1 " +} + +error() { + print "${BOLD}${BLRED}${FWHITE}${IERROR} Error: ${BRESET}${FLRED} $1 " >&2 + # print_stacktrace +} + +fatal() { + print "${BOLD}${BRED}${FWHITE}${IFATAL} FATAL: $1 " >&2 + print_stacktrace +} + +die() { + error "$1" + [ "$2" ] && exit $2 || exit 100 +} + +die_fatal() { + fatal "$1" + [ "$2" ] && exit $2 || exit 100 +} + +die_help() { + error "$1" + [ "$2" ] && is_function "$2".help && $2.help + [ "$3" ] && exit $3 || exit 100 +} + +print_stacktrace() { + STACK="" + local i + local stack_size=${#FUNCNAME[@]} + debug "Callstack:" + # for (( i=$stack_size-1; i>=1; i-- )); do + for (( i=1; i<$stack_size; i++ )); do + local func="${FUNCNAME[$i]}" + [ x$func = x ] && func=MAIN + local linen="${BASH_LINENO[$(( i - 1 ))]}" + local src="${BASH_SOURCE[$i]}" + [ x"$src" = x ] && src=non_file_source + debug " at $func $src:$linen" + done +} diff --git a/install/jbmono b/install/jbmono index a610105..a98c633 100755 --- a/install/jbmono +++ b/install/jbmono @@ -1,22 +1,14 @@ #!/bin/bash ##makedesc: Install JetBrains Mono fonts +[ -f `dirname $0`/../helpers ] && source `dirname $0`/../helpers || exit 255 # https://www.jetbrains.com/lp/mono/#how-to-install -echo -echo "===============================================" -echo "Installing JetBrains Mono fonts..." -echo "===============================================" -echo - -installed() { - command -v "$1" >/dev/null 2>&1 -} - -! installed wget && sudo apt install wget -! installed unzip && sudo apt install unzip +title +require unzip mkdir -p "$HOME/install/jbmono" "$HOME/.local/share/fonts/" -wget https://download.jetbrains.com/fonts/JetBrainsMono-2.304.zip -O "$HOME/install/jbmono.zip" && \ + +download "https://download.jetbrains.com/fonts/JetBrainsMono-2.304.zip" "$HOME/install/jbmono.zip" && \ unzip -oj "$HOME/install/jbmono.zip" "fonts/ttf/*.ttf" -d "$HOME/.local/share/fonts/" && \ fc-cache -vf "$HOME/.local/share/fonts/"