pub / sguard

Suspend Guard for the PhoneShell "Phosh"
git clone https://https://src.jayvii.de/pub/sguard.git
Home | Log | Files | Exports | Refs | README | RSS

commit 62a678615cf801414c3559967cf8aea06ed7bf0d
parent a28b8cdaad695d57a55a315dd023d229ac9dbdea
Author: JayVii <jayvii[AT]posteo[DOT]de>
Date:   Thu, 30 Dec 2021 11:33:19 +0100

clean up unmaintained pieces

Diffstat:
MREADME.md | 5+++++
AREADME.md.license | 2++
Dbalarm/balarm.sh | 73-------------------------------------------------------------------------
Dbalarm/daemon.sh | 124-------------------------------------------------------------------------------
Dmconnect-yad/mconnect-yad.sh | 53-----------------------------------------------------
Dpodcatch/podcatch.sh | 74--------------------------------------------------------------------------
Dsettheme/set_theme.sh | 20--------------------
Dsxmo/hooks/lock | 45---------------------------------------------
8 files changed, 7 insertions(+), 389 deletions(-)

diff --git a/README.md b/README.md @@ -1,2 +1,7 @@ # PinePhoneScripts +Just a collection of (hopefully) useful scripts for the PinePhone (and +potentially other devices). + +Right now, there is only "sguard", please refer to its README to find out more: +https://src.jayvii.de/pub/pinephone-scripts/file/sguard/README.md.html diff --git a/README.md.license b/README.md.license @@ -0,0 +1,2 @@ +SPDX-FileCopyrightText: 2021 JayVii +SPDX-License-Identifier: GPL-3.0-or-later diff --git a/balarm/balarm.sh b/balarm/balarm.sh @@ -1,73 +0,0 @@ -#!/usr/bin/env bash -# Copyright (C) 2020 Jan "JayVii" -# Author 2020 Jan "JayVii" <jayvii [AT] posteo [DOT] de> -# SPDX-License-Identifier: gpl-3.0 -# About this header: <https://reuse.software> - -############################################################################### -# balarm.sh - the alarm-script written in bash. # -# # -# this script is typically executed by daemon.sh, but may also work with cron # -# # -# this script requires "yad" and "mpv" to be installed. # -############################################################################### - -# Configuration --------------------------------------------------------------- -BASE_PATH="$HOME/.config/balarm" -ALARM_FILE="$BASE_PATH/sound" -SNOOZE_TIME=300 - -# defaults -------------------------------------------------------------------- -ZZZACTION=0 -FULLVOLUME=1 - -# checks ---------------------------------------------------------------------- -# has alarmtone been chosen yet? -if [ ! -f "$ALARM_FILE" ]; then - # assuming some tone... - ln -s /usr/share/sounds/freedesktop/stereo/phone-incoming-call.oga \ - "$ALARM_FILE" -fi - -# turn up volume -if [ $FULLVOLUME == 1 ]; then - pactl set-sink-volume 0 0.99 # not really sure why, but it works... - pactl set-sink-volume 1 0.99 # can be either apparently... -fi - -# Function: ring alarm -------------------------------------------------------- -function alarm_ring { - # play ringtone - mpv --loop-file=inf "$1" & - # noting down PID of alarm process - ALARMPID=$! -} - -# Function: ask user what to do ----------------------------------------------- -function zzzorawake { - yad --title="Alarm!" \ - --text="$(date '+%a, %Y-%m-%d %H:%M:%S')" \ - --button="Snooze..." \ - --button="Stop!" - ZZZACTION=$? -} - -# initial run ----------------------------------------------------------------- -# ringing alarm... -alarm_ring "$ALARM_FILE" -# asking user what to do -zzzorawake - -# the famous snooze loop ------------------------------------------------------ -# if snooze was chosen, wait for another 5 minutes before ringing -while [ $ZZZACTION == 0 ]; do - kill -9 $ALARMPID - sleep $SNOOZE_TIME # snooze... - alarm_ring "$ALARM_FILE" # ring alarm - zzzorawake # ask user what to do -done - -# if you finally get up, we can stop the misery ------------------------------- -kill $ALARMPID - -# EOF balarm.sh diff --git a/balarm/daemon.sh b/balarm/daemon.sh @@ -1,124 +0,0 @@ -#!/usr/bin/env bash -# Copyright (C) 2020 Jan "JayVii" -# Author 2020 Jan "JayVii" <jayvii [AT] posteo [DOT] de> -# SPDX-License-Identifier: gpl-3.0 -# About this header: <https://reuse.software> - -############################################################################### -# daemon.sh - time-watcher script for balarm.sh, the alarm-script written in # -# bash. # -# # -# ATTENTION: requires balarm.sh to be in $PATH # -############################################################################### - -# Configuration --------------------------------------------------------------- -BASE_PATH="$HOME/.config/balarm" -PID_FILE="$HOME/.cache/balarm.pid" -RANG_FILE="$HOME/.cache/balarm.log" -TIME_FILE="$BASE_PATH/timings.txt" - -# SetUp ----------------------------------------------------------------------- -if [ ! -d "$BASE_PATH" ]; then mkdir -p "$BASE_PATH"; fi -if [ ! -f "$TIME_FILE" ]; then touch "$TIME_FILE"; fi -if [ ! -f "$RANG_FILE" ]; then touch "$RANG_FILE"; fi -if [ ! -f "$PID_FILE" ]; then touch "$PID_FILE"; fi - -# Functions ------------------------------------------------------------------- - -# compares two time strings in "%H %M %a" format. -# sets $TIME_MATCH to 1 if time is equal or diff by 1 -function compare_time { - # Extract hours, minutes & day from current time - _HOURS=$(echo "$1" | awk '{ print $1 }') - _MINUTES=$(echo "$1" | awk '{ print $2 }') - _DAY=$(echo "$1" | awk '{ print $3 }') - # construct +1 and -1 minute strings - if [[ $_MINUTES -eq 0 ]]; then - if [[ $_HOURS -lt 11 ]]; then - M1="0$(($_HOURS - 1)) 59 $_DAY" - else - M1="$(($_HOURS - 1)) 59 $_DAY" - fi - P1="$_HOURS $(($_MINUTES + 1)) $_DAY" - elif [[ $_MINUTES -eq 59 ]]; then - M1="$_HOURS 58 $_DAY" - P1="$(($_HOURS + 1)) 00 $_DAY" - else - if [[ $_MINUTES -lt 11 ]]; then - M1="$_HOURS 0$(($_MINUTES - 1)) $_DAY" - else - M1="$_HOURS $(($_MINUTES - 1)) $_DAY" - fi - P1="$_HOURS $(($_MINUTES + 1)) $_DAY" - fi - # compare strings - if [[ "$2" == "$1" ]] || [[ "$2" == "$M1" ]]; then #|| [[ "$2" == "$P1" ]]; then - TIME_MATCH=1 - else - TIME_MATCH=0 - fi -} - -# checks whether current alarm has been executed already. -function rang_yet { - # check whether current alarm has been executed today already... - _RANG=$(grep "$CURRDATE $ALARM" "$RANG_FILE") - if [[ "$_RANG" == "$CURRDATE $ALARM" ]]; then - HAS_RANG=1 # yes, it has! - else - HAS_RANG=0 # no, it has not! - fi -} - -# Refresh PID file ------------------------------------------------------------ - -# reported PID for daemon -TMP_PID=$(cat "$PID_FILE") - -# does reported PID correspond to THIS process? -DAE_PID=$(ps all | grep " $TMP_PID " | grep -v "grep" | grep "daemon.sh") - -# if so, restart daemon. Else just refresh PID -if [ "$DAE_PID" ]; then - echo "Refreshing..." - kill -9 "$TMP_PID" -fi - -# either way, refresh reported PID for daemon -echo $$ > "$PID_FILE" - -# Run time-watch daemon ------------------------------------------------------- - -while :; do - - # How many active alarms do we have? - ALARM_N=$(wc -l "$TIME_FILE" | awk '{ print $1 }') - - # Check current time and date - CURRTIME=$(date "+%H %M %a") - CURRDATE=$(date "+%Y %m %d") - - # loop through all set up alarms - for i in $(seq 1 1 $ALARM_N); do - # current alarm's time - ALARMTIME=$(sed -ne "${i}p" "$TIME_FILE") - # compare alarm time to current time - compare_time "$CURRTIME" "$ALARMTIME" - # if they match, check whether it has been executed already - if [ $TIME_MATCH -eq 1 ]; then - rang_yet - # if it has not been executed yet, execute it - if [ $HAS_RANG -eq 0 ]; then - balarm.sh & - echo "$CURRDATE $ALARMTIME" > "$RANG_FILE" - fi - fi - done - - # timeout (1min - execution time) - CURRSEC=$(date +%S) # current time (seconds) after execution loop - sleep $((60 - $CURRSEC)) # should precisely land on HH:MM+1:00. - -done - -# EOF daemon.sh diff --git a/mconnect-yad/mconnect-yad.sh b/mconnect-yad/mconnect-yad.sh @@ -1,53 +0,0 @@ -#!/usr/bin/env bash - -if [[ -d `whereis mconnectctl | awk '{ print $2 }'` ]]; then - echo "[FAIL] mconnect and mconnectctl need to be installed." - exit 1; -fi - -if [[ -d `pidof mconnect` ]]; then - echo "[FAIL] mconnect needs to be running: \"mconnect -d\"." - exit 2; -fi - -DEVICES=`mconnectctl list-devices | \ - grep "/org/mconnect/device/" | \ - sed -e 's/^.*\/org\/mconnect\/device\///g' | \ - tr '\n' ';'` - -CHOICE=`yad --title="MConnect" \ - --form \ - --item-separator=";" \ - --field="Device:CBE" "${DEVICES}" \ - --field="Text:TEXT" \ - --field="File:FL" \ - --field="Allow Device:CHK"` - -CH_DEV=`echo $CHOICE | cut -d "|" -f1 | awk '{ print $1 }'` -CH_TXT=`echo $CHOICE | cut -d "|" -f2` -CH_DAT=`echo $CHOICE | cut -d "|" -f3` -CH_ALW=`echo $CHOICE | cut -d "|" -f4` - -if [[ "$CH_ALW" == "TRUE" ]]; then - mconnectctl allow-device /org/mconnect/device/${CH_DEV} -fi - -IS_URL=FALSE -if [[ -d "$CH_TXT" ]]; then - if [[ ! -d `echo "$CH_TXT" | grep "^(http|mailto:)"` ]]; then - IS_URL=TRUE - fi -fi - -if [[ $IS_URL == TRUE ]]; then - mconnectctl share-url /org/mconnect/device/${CH_DEV} "$CH_TXT" -elif [[ "$CH_TXT" != "" ]]; then - mconnectctl share-text /org/mconnect/device/${CH_DEV} "$CH_TXT" -elif [[ "$CH_DAT" != "" ]]; then - mconnectctl share-file /org/mconnect/device/${CH_DEV} "$CH_DAT" -else - echo "[FAIL] Nothing to be shared..." -fi - -exit 0; - diff --git a/podcatch/podcatch.sh b/podcatch/podcatch.sh @@ -1,74 +0,0 @@ -#!/usr/bin/env bash - -if [[ ! -d "$HOME/Podcasts/.data" ]]; then - mkdir -p "$HOME/Podcasts/.data" -fi - -function check_connection { - if [[ -z $(ip a s "$1" | grep "UP") ]]; then - echo "DOWN" - else - echo "UP" - fi -} - -function sort_and_link { - # find files (recursively) and sort them by date - FILES=$(find $1 -type f -printf '%T+\t%p\n' | sort -nr | awk '{ print $2 }') - - # set counters - INDEX=0 - - # linking loop - for f in $FILES; do - - if [ $(echo "$f" | grep -E ".mp3$|.mp4$|.opus$|.m4a$") ]; then - - # increment index - INDEX=$(echo "$INDEX + 1" | bc) - - # add leading zero for 1-9 - if [ $INDEX -lt 10 ]; then - INDEX=0$INDEX - fi - - # construct new filename - PERFORMER=$(mediainfo "$f" --Inform="General;%Performer%" | sed -e 's/|//g' -e 's/\"//g') - TITLE=$(mediainfo "$f" --Inform="General;%Track%" | sed -e 's/\///g' -e 's/|//g' -e 's/\"//g') - NFN=$(echo "$PERFORMER - $TITLE" | cut -b -120) - NF="${2}/${INDEX}_$NFN" - ln -s "$f" "$NF" - - fi - done -} - -function delete_old { - # create list of days that are not deleted... - for dat in $(seq 0 1 $2); do - NOT_DEL="$NOT_DEL\|$(date +%Y-%m-%d -d -${dat}\ days)" - done - DELETE=$(find "$1" -type f -printf '%T+\t%p\n' | sort -nr | grep -v "$NOT_DEL" | awk '{ print $2 }' | grep -v "/.LOG/") - # delete old files - for f in $DELETE; do - echo "[INFO] Deleting $f" - rm "$f" - done -} - -if [[ $(check_connection wlan0) == "UP" ]]; -then - - # Download Podcasts - cpulimit --limit 25 --foreground -- podget - - # Delete old Episodes (> 7 days) - delete_old "$HOME/Podcasts/.data" 7 - - # Create collection folder - rm $HOME/Podcasts/* # does not include .data - - # Link collection - sort_and_link "$HOME/Podcasts/.data" "$HOME/Podcasts" - -fi diff --git a/settheme/set_theme.sh b/settheme/set_theme.sh @@ -1,20 +0,0 @@ -# Copyright (C) 2020 Jan "JayVii" -# Author 2020 Jan "JayVii" <jayvii [AT] posteo [DOT] de> -# SPDX-License-Identifier: gpl-3.0 -# About this header: <https://reuse.software> - -# default paths -GTK_DIRS="/usr/share/themes/ $HOME/.themes/" -ICON_DIRS="/usr/share/icons/ $HOME/.icons/" - -# get available gtk-themes -for DIR in "$GTK_DIRS"; do - INST_GTK=`find "$DIR" -maxdepth 1 -type d | sed -e "s#$DIR##"` -done - -# get available icon-themes -for DIR in "$ICON_DIRS"; do - INST_ICON=`find "$DIR" -maxdepth 1 -type d | sed -e "s#$DIR##"` -done - -# EOF set_theme.sh diff --git a/sxmo/hooks/lock b/sxmo/hooks/lock @@ -1,44 +0,0 @@ -#!/usr/bin/env sh - -function suspend_after_x() { - - # Initial timeout - sleep $1 - - # As long as media is running / sound is playing, do not suspend. - while [ $(check_player_state) == "true" ]; do - sleep $1 - done - - # If screen is locked, suspend immediately again. - if [ ! -z $(pidof sxmo_screenlock) ]; then - #pkill -9 sxmo_screenlock # probably not necessary... - if [ -z $SXMO_RTCWAKEINTERVAL ]; then - sxmo_screenlock --suspend - else - sxmo_screenlock --suspend --wake-interval $SXMO_RTCWAKEINTERVAL - fi - fi - - # Post wake: reset backlight again - sxmo_setpinebacklight $2 -} - -function check_player_state { - if [[ -z $(pacmd list-sink-inputs | grep "state: RUNNING$") ]]; then - echo false - else - echo true - fi -} - -# Current backlight? -CUR_BL=$(cat /sys/class/backlight/backlight/brightness) - -SXMO_LOCK_SUSPEND_AFTER_X=30 # that should be in .profile or .xinitrc - -if [! -z $SXMO_LOCK_SUSPEND_AFTER_X ]; then - suspend_after_x $SXMO_LOCK_SUSPEND_AFTER_X $CUR_BL & -fi - -# EOF lock -\ No newline at end of file