various cleanups

This commit is contained in:
zawz 2020-10-26 11:25:36 +01:00
parent f4bad72473
commit 058b3c2b00
11 changed files with 91 additions and 204 deletions

View file

@ -24,63 +24,31 @@ arg_i=20
block_time=100 block_time=100
if [ -z "$FOLDER" ] [ -z "$FOLDER" ] && {
then
if [ -n "$XDG_DATA_HOME" ] if [ -n "$XDG_DATA_HOME" ]
then then
FOLDER="$XDG_DATA_HOME/zclick" FOLDER="$XDG_DATA_HOME/zclick"
else else
FOLDER="$HOME/.local/share/zclick" FOLDER="$HOME/.local/share/zclick"
fi fi
fi }
while getopts ":hi:b:dt" opt; while getopts ":hi:b:dt" opt;
do do
case $opt in case $opt in
h) h) usage && exit 0 ;;
usage i) [ "$OPTARG" -ge 0 ] 2>/dev/null || { error "i argument has to be positive" ; exit 2; }
exit 0 arg_i=$OPTARG ;;
;; b) [ "$OPTARG" -ge 1 ] 2>/dev/null || { error "b argument has to be strictly positive" ; exit 2; }
i) block_time=$OPTARG ;;
if ! [ "$OPTARG" -ge 0 ] 2>/dev/null d) opt_d=y ;;
then t) opt_t=y ;;
error "i argument has to be positive" \?) echo "Unknown option: $OPTARG" >&2 ; usage ; exit 1 ;;
exit 2
fi
arg_i=$OPTARG
;;
b)
if ! [ "$OPTARG" -ge 1 ] 2>/dev/null
then
error "b argument has to be strictly positive"
exit 2
fi
block_time=$OPTARG
;;
d)
opt_d=y
;;
t)
opt_t=y
;;
\?)
echo "Uknown option: $OPTARG"
usage
exit 1
;;
esac esac
done done
shift $((OPTIND-1)) shift $((OPTIND-1))
if [ -n "$1" ] && ! [ "$1" -gt 0 ] 2>/dev/null
then
error "Click ID has to be a strictly positive integer"
exit 2
fi
cid=$1
mkdir -p "$FOLDER" mkdir -p "$FOLDER"
if [ -n "$opt_d" ] if [ -n "$opt_d" ]
@ -114,12 +82,9 @@ then
else else
## CONTROL ## CONTROL
[ $# -le 0 ] && usage && exit 1
if [ -z "$cid" ] [ -n "$1" ] && ! [ "$1" -gt 0 ] 2>/dev/null && { error "Click ID has to be a strictly positive integer" ; exit 2; }
then cid=$1
usage
exit
fi
if [ -n "$opt_t" ] if [ -n "$opt_t" ]
then then

View file

@ -10,15 +10,13 @@ Operations:
make <type> : create Makefile make <type> : create Makefile
main : create main source file main : create main source file
ls : list source names ls : list source names
src <type> <name...> : create source files src <type> <name...> : create source files. Can be abbrieviated to 's'
rm <name...> : delete source files rm <name...> : delete source files
mv <name> <new> : rename source files mv <name> <new> : rename source files
clear : delete all sources, headers, and binaries clear : delete all sources, headers, and binaries
import <path> [name] : import source files from another destination import <path> [name] : import source files from another destination
export <name> <path> : export source files to another destination export <name> <path> : export source files to another destination
rclean [path] : perform a recursive '"'make clean ; make clear'"' rclean [path] : perform a recursive '"'make clean ; make clear'"''
Operation "src" can be abbrieviated to "s"'
} }
if [ -n "$XDG_DATA_HOME" ] if [ -n "$XDG_DATA_HOME" ]
@ -30,10 +28,7 @@ fi
usr_datapath="/usr/share/zcsf" usr_datapath="/usr/share/zcsf"
if [ -n "$CONFIGPATH" ] [ -n "$CONFIGPATH" ] && local_datapath="$CONFIGPATH"
then
local_datapath="$CONFIGPATH"
fi
header_ifndef() header_ifndef()
{ {
@ -76,7 +71,7 @@ load_env()
CC=$(grep "CC=" "$MAKEFILE" | cut -d'=' -f2- | head -n1) CC=$(grep "CC=" "$MAKEFILE" | cut -d'=' -f2- | head -n1)
fi fi
if [ "$CC" = "g++" ] || [ "$CPP" = "true" ] if [ "$CC" = "g++" ] || [ "$CC" = "clang++" ] || [ "$CPP" = "true" ]
then then
PP="pp" PP="pp"
fi fi

View file

@ -23,24 +23,22 @@ error() {
# $1 = message , $2 = title , $3 = time # $1 = message , $2 = title , $3 = time
notify () { notify () {
if which kdialog >/dev/null if which kdialog >/dev/null ; then
then
kdialog --passivepopup "$1" "$3" --title "$2" kdialog --passivepopup "$1" "$3" --title "$2"
elif which notify-send >/dev/null elif which notify-send >/dev/null ; then
then
notify-send -t "$3" "$2" "$1" notify-send -t "$3" "$2" "$1"
else error "No supported notification" else
error "No supported notification"
fi fi
} }
yesno () { yesno () {
if which kdialog >/dev/null if which kdialog >/dev/null ; then
then
kdialog --yesno "$1" --title "$2" kdialog --yesno "$1" --title "$2"
elif which zenity elif which zenity ; then
then
zenity --question --text="$1" --title="$2" zenity --question --text="$1" --title="$2"
else error "No supported prompt" else
error "No supported prompt"
fi fi
} }
@ -55,14 +53,14 @@ do
T) title=$OPTARG ;; T) title=$OPTARG ;;
t) _arg_t=$OPTARG ;; t) _arg_t=$OPTARG ;;
w) opt_w=y ;; w) opt_w=y ;;
\?) echo "Uknown option: $OPTARG" && usage && exit 2 ;; *) echo "Unknown option: $OPTARG" >&2 ; usage ; exit 2 ;;
esac esac
done done
shift $((OPTIND-1)) shift $((OPTIND-1))
if [ $# -gt 0 ] # exec and resolve message
then if [ $# -gt 0 ] ; then
[ -z "$opt_m" ] && message="'$*' finished" [ -z "$opt_m" ] && message="'$*' finished"
[ -z "$title" ] && title=$* [ -z "$title" ] && title=$*
"$@" "$@"
@ -71,8 +69,8 @@ else
[ -z "$title" ] && title="Ping" [ -z "$title" ] && title="Ping"
fi fi
if [ -n "$opt_y" ] # Send the notification
then if [ -n "$opt_y" ] ; then
yesno "$message" "$title" yesno "$message" "$title"
else else
notify "$message" "$title" "$_arg_t" notify "$message" "$title" "$_arg_t"

View file

@ -23,18 +23,9 @@ Options:
while getopts ":hc:" opt; while getopts ":hc:" opt;
do do
case $opt in case $opt in
h) h) usage ; exit 0 ;;
usage c) config_file="$OPTARG" ;;
exit 0 *) echo "Unknown option: $OPTARG" >&2 ; usage ; exit 1 ;;
;;
c)
config_file="$OPTARG"
;;
\?)
echo "Uknown option: $OPTARG"
usage
exit 1
;;
esac esac
done done
@ -52,41 +43,15 @@ export vblank_mode=0
shift $((OPTIND-1)) shift $((OPTIND-1))
if [ -n "$1" ]
then
if [ "$1" = "start" ]; then
shift $((OPTIND))
wine $OSUDIR/osu\!.exe $@
elif [ "$1" = "kill" ]; then
wineserver -k
elif [ "$1" = "sound" ]; then
case $1 in
start) shift $((OPTIND)) && wine "$OSUDIR/osu\!.exe" "$@" ;;
kill) wineserver -k ;;
sound)
case $2 in case $2 in
"pulse") pulse|stable) winetricks sound=pulse ;;
winetricks sound=pulse alsa|lowlatency) winetricks sound=alsa ;;
;; *) echo "$bin sound <pulse/alsa>" >&2 ; exit 1 ;;
"stable") esac ;;
winetricks sound=pulse *) usage ; exit 1 ;;
;; esac
"alsa")
winetricks sound=alsa
;;
"lowlatency")
winetricks sound=alsa
;;
*)
echo "$bin sound <pulse/alsa>"
esac
else
usage
exit 1
fi
else
usage
exit 1
fi

View file

@ -1,37 +1,27 @@
#!/bin/sh #!/bin/sh
if [ "$OSUDIR" == "" ] ; then [ -z "$OSUDIR" ] && OSUDIR='osu'
OSUDIR='osu' [ -z "$WINEDIR" ] && WINEDIR='$(pwd)/.wine'
fi
if [ "$WINEDIR" == "" ] ; then
WINEDIR='$(pwd)/.wine'
fi
export WINEARCH=win32 export WINEARCH=win32
export WINEPREFIX=$(echo "echo $WINEDIR" | sh) export WINEPREFIX=$(echo "echo $WINEDIR" | sh)
silentmk()
{
if [ ! -d "$1" ] ; then
mkdir "$1"
fi
}
pacman_packages() pacman_packages()
{ {
sudo pacman -S --needed --noconfirm lib32-alsa-lib lib32-libpulse lib32-gnutls lib32-libxcomposite sudo pacman -S --needed --noconfirm lib32-alsa-lib lib32-libpulse lib32-gnutls lib32-libxcomposite
} }
echo_red() { echo_red() {
printf "\033[1;31m$1\033[0m\n" printf "\033[1;31m%s\033[0m\n" "$*"
} }
echo_blue() { echo_blue() {
printf "\033[1;34m$1\033[0m\n" printf "\033[1;34m%s\033[0m\n" "$*"
} }
echo_yellow() { echo_yellow() {
printf "\033[1;33m$1\033[0m\n" printf "\033[1;33m%s\033[0m\n" "$*"
} }
echo_white() { echo_white() {
printf "\033[1;37m$1\033[0m\n" printf "\033[1;37m%s\033[0m\n" "$*"
} }
_done() { _done() {
printf "\033[1;32mDone\033[0m\n\n" printf "\033[1;32mDone\033[0m\n\n"
@ -73,12 +63,8 @@ fi
echo_white "Wine environment will be setup. This can take a very long time and may fail" echo_white "Wine environment will be setup. This can take a very long time and may fail"
read -p "Proceed? [Y/n]: " yn read -p "Proceed? [Y/n]: " yn
case $yn in case $yn in
[Nn]* ) [Nn]*) echo_red "Aborting" ; exit 1 ;;
echo_red "Aborting" *) ;;
exit
;;
* )
;;
esac esac
# The big one # The big one
@ -101,9 +87,8 @@ _done
# ALSA audio # ALSA audio
read -p "Experimental audio lag lowering? [Y/n]: " yn read -p "Experimental audio lag lowering? [Y/n]: " yn
case $yn in case $yn in
[Nn]* ) [Nn]* ) ;;
;; *)
* )
winetricks sound=alsa winetricks sound=alsa
echo_yellow "If you encounter audio distortion, run 'zosu sound pulse' to revert" echo_yellow "If you encounter audio distortion, run 'zosu sound pulse' to revert"
_done _done
@ -113,10 +98,8 @@ esac
# install osu # install osu
read -p "Insall fresh osu? [Y/n]: " yn read -p "Insall fresh osu? [Y/n]: " yn
case $yn in case $yn in
[Nn]* ) [Nn]*) echo_blue "Provide a link '$OSUDIR' to the desired osu instance" ;;
echo_blue "Provide a link '$OSUDIR' to the desired osu instance" *)
;;
* )
wget https://m1.ppy.sh/r/osu\!install.exe wget https://m1.ppy.sh/r/osu\!install.exe
echo_white "Starting osu installer. Don't change the install directory" echo_white "Starting osu installer. Don't change the install directory"
wine osu\!install.exe > /dev/null 2>&1 wine osu\!install.exe > /dev/null 2>&1

View file

@ -3,6 +3,7 @@
if [ $# -lt 2 ] if [ $# -lt 2 ]
then then
echo "$0 <rate> <file>" echo "$0 <rate> <file>"
exit 1
fi fi
RATE="$1" RATE="$1"
@ -13,8 +14,7 @@ OUTPUTFILE="$(echo "$2" | sed 's/\.osu//g' | cut -d']' -f1) x$RATE].osu"
AUDIO=$(grep "AudioFilename:" "$FILE" | cut -d' ' -f2- | tr -d '\n\r') AUDIO=$(grep "AudioFilename:" "$FILE" | cut -d' ' -f2- | tr -d '\n\r')
AUDIORATED=$(echo $AUDIO | cut -d'.' -f1)-x$RATE".mp3" AUDIORATED=$(echo $AUDIO | cut -d'.' -f1)-x$RATE".mp3"
echo "" > $OUTPUTFILE echo "" > "$OUTPUTFILE"
rm "$OUTPUTFILE"
output_line () { output_line () {
printf "%s\r\n" "$1" >> $OUTPUTFILE printf "%s\r\n" "$1" >> $OUTPUTFILE

View file

@ -418,7 +418,7 @@ do
arg_c="$OPTARG" arg_c="$OPTARG"
;; ;;
h) usage && exit 1 ;; h) usage && exit 1 ;;
\?) echo "Uknown option: $OPTARG" >&2 && usage && exit 1 ;; \?) echo "Unknown option: $OPTARG" >&2 && usage && exit 1 ;;
esac esac
done done
shift $((OPTIND-1)) shift $((OPTIND-1))

View file

@ -43,7 +43,7 @@ do
_opt_d=y _opt_d=y
;; ;;
\?) \?)
echo "Uknown option: $OPTARG" >&2 echo "Unknown option: $OPTARG" >&2
usage usage
exit 1 exit 1
;; ;;

View file

@ -30,7 +30,7 @@ do
_opt_f=y _opt_f=y
;; ;;
\?) \?)
echo "Uknown option: $OPTARG" >&2 echo "Unknown option: $OPTARG" >&2
usage usage
exit 1 exit 1
;; ;;

64
ztr/ztr
View file

@ -16,11 +16,10 @@ Options:
gen_tr_lines_disk() gen_tr_lines_disk()
{ {
# find /sys/block -maxdepth 1
cd /sys/block cd /sys/block
for I in * for I in *
do do
_t=$(zdtol $I | head -n1) _t=$(zdtol "$I" | head -n1)
[ -n "$_t" ] && printf "/dev/%s:%s\n" "$I" "$_t" [ -n "$_t" ] && printf "/dev/%s:%s\n" "$I" "$_t"
done done
} }
@ -42,8 +41,6 @@ fi
DATA_PATH=$CONFIG_PATH/data/ DATA_PATH=$CONFIG_PATH/data/
FILE=/dev/stdin
while getopts ":hPsf:pdl" opt; while getopts ":hPsf:pdl" opt;
do do
_opt=y _opt=y
@ -51,25 +48,21 @@ do
h) usage && exit 0 ;; h) usage && exit 0 ;;
P) _opt_P=y ;; P) _opt_P=y ;;
s) _opt_s=y ;; s) _opt_s=y ;;
f) f) _opt_f=y
_opt_f=y
_arg_f=$OPTARG _arg_f=$OPTARG
_opt_data=y _opt_data=y
;; ;;
d) d) _opt_d=y
_opt_d=y _opt_data=y
_opt_data=y ;;
;; p) _opt_p=y
p) _opt_data=y
_opt_p=y ;;
_opt_data=y l) _opt_l=y
;; _opt_data=y
l) ;;
_opt_l=y
_opt_data=y
;;
\?) \?)
echo "Uknown option: $OPTARG" >&2 echo "Unknown option: $OPTARG" >&2
usage usage
exit 1 exit 1
;; ;;
@ -78,40 +71,27 @@ done
shift $((OPTIND-1)) shift $((OPTIND-1))
if [ -z "$_opt_data" ] [ -z "$_opt_data" ] && {
then
_opt_p=y _opt_p=y
_opt_d=y _opt_d=y
_opt_l=y _opt_l=y
_opt_L=y _opt_L=y
fi }
mkdir -p "$DATA_PATH" mkdir -p "$DATA_PATH"
LINES=""
if [ -n "$_opt_f" ] LINES=""
then [ -n "$_opt_f" ] && LINES="$(printf "%s\n%s" "$LINES" "$(cat "$_arg_f")" )"
LINES="$(printf "%s\n%s" "$LINES" "$(cat "$_arg_f")" )" [ -n "$_opt_l" ] && LINES="$(printf "%s\n%s" "$LINES" "$(cat "$DATA_PATH"/* 2>/dev/null)" )"
fi [ -n "$_opt_p" ] && LINES="$(printf "%s\n%s" "$LINES" "$(gen_tr_lines_part)" )"
if [ -n "$_opt_l" ] [ -n "$_opt_d" ] && LINES="$(printf "%s\n%s" "$LINES" "$(gen_tr_lines_disk)" )"
then
LINES="$(printf "%s\n%s" "$LINES" "$(cat "$DATA_PATH"/* 2>/dev/null)" )"
fi
if [ -n "$_opt_p" ]
then
LINES="$(printf "%s\n%s" "$LINES" "$(gen_tr_lines_part)" )"
fi
if [ -n "$_opt_d" ]
then
LINES="$(printf "%s\n%s" "$LINES" "$(gen_tr_lines_disk)" )"
fi
LINES=$(echo "$LINES" | grep -v '^$') LINES=$(echo "$LINES" | grep -v '^$')
if [ -n "$1" ] ; then FILE=/dev/stdin
FILE="$1" [ -n "$1" ] && FILE="$1"
fi
if [ -t 0 ] || [ -n "$_opt_P" ] && [ -z "$1" ] if [ -t 0 ] || [ -n "$_opt_P" ] && [ -z "$1" ]
then then

View file

@ -2,14 +2,15 @@
shift $((OPTIND-1)) shift $((OPTIND-1))
# $@ = paths
default_umask() {
find "$@" -type d -print0 | xargs -0 chmod "$(umask -S)" &&
find "$@" -type f -print0 | xargs -0 chmod "$(umask -S | tr -d 'x')"
}
if [ $# -gt 0 ] if [ $# -gt 0 ]
then then
_path=$* default_umask "$@"
else else
_path=$(pwd) default_umask .
fi fi
#find "$_path" -type d -exec chmod $(umask -S) {} \;
#find "$_path" -type f -exec chmod $(umask -S | tr -d 'x') {} \;
chmod "$(umask -S)" $(find "$_path" -type d)
chmod "$(umask -S | tr -d 'x')" $(find "$_path" -type f)