update
This commit is contained in:
parent
0ef4854ae2
commit
eb4e8bdb12
8 changed files with 433 additions and 1 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -1,2 +1,3 @@
|
||||||
Zmakefile
|
Zmakefile
|
||||||
zmakefile
|
zmakefile
|
||||||
|
local
|
||||||
|
|
|
||||||
48
confbak/confbak
Executable file
48
confbak/confbak
Executable file
|
|
@ -0,0 +1,48 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
[ "$DEBUG" = true ] && set -x
|
||||||
|
|
||||||
|
[ ! -f "${XDG_CONFIG_HOME-$HOME/.config}/confbak.conf" ] && exit 1
|
||||||
|
|
||||||
|
. "${XDG_CONFIG_HOME-$HOME/.config}/confbak.conf"
|
||||||
|
|
||||||
|
basedest=~
|
||||||
|
if [ "$server" != "${server#*:}" ] ; then
|
||||||
|
basedest=${server#*:}
|
||||||
|
server=${server%%:*}
|
||||||
|
fi
|
||||||
|
|
||||||
|
HOSTNAME=$(cat /etc/hostname)
|
||||||
|
if [ -z "$files" ] ; then
|
||||||
|
files="
|
||||||
|
$HOSTNAME/etc:/etc:
|
||||||
|
$HOSTNAME/config:$HOME/.config:
|
||||||
|
$HOSTNAME/share:$HOME/.local/share:
|
||||||
|
"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# $1 = dest , $2 = extension
|
||||||
|
compress_and_send() {
|
||||||
|
zstd -T0 | ssh "$server" "mkdir -p '$basedest/$(dirname "$1")' && cat > '$basedest/$1.zst'"
|
||||||
|
}
|
||||||
|
|
||||||
|
echo "$files" | while read -r ln ; do
|
||||||
|
[ -z "$ln" ] && continue
|
||||||
|
dest=$(echo "$ln" | cut -d: -f1)
|
||||||
|
folder=$(echo "$ln" | cut -d: -f2)
|
||||||
|
excludecmd=
|
||||||
|
for oneex in $(echo "$ln" | cut -d: -f3- | tr , '\n') ; do
|
||||||
|
excludecmd="$excludecmd --exclude=./$oneex"
|
||||||
|
done
|
||||||
|
(
|
||||||
|
cd "$folder"
|
||||||
|
sudo tar -cf - $excludecmd . | compress_and_send "$dest.tar"
|
||||||
|
)
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "$cmds" | while read -r ln ; do
|
||||||
|
[ -z "$ln" ] && continue
|
||||||
|
dest=$(echo "$ln" | cut -d: -f1)
|
||||||
|
cmd=$(echo "$ln" | cut -d: -f2-)
|
||||||
|
sh -c "$cmd" | compress_and_send "$dest"
|
||||||
|
done
|
||||||
96
fscp/fscp
Executable file
96
fscp/fscp
Executable file
|
|
@ -0,0 +1,96 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
[ "$DEBUG" = true ] && set -x
|
||||||
|
|
||||||
|
usage() {
|
||||||
|
cat << EOF
|
||||||
|
$0 <src> <dest>
|
||||||
|
Fast SCP, wrapper script to SCP using tar
|
||||||
|
|
||||||
|
Environment config:
|
||||||
|
COMPRESSION Compression command. Default "gzip"
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
|
ssh_exec() {
|
||||||
|
addr=$1
|
||||||
|
shift
|
||||||
|
if [ -n "$addr" ] ; then
|
||||||
|
ssh "$addr" exec "$(/usr/bin/printf "%q " "$@")"
|
||||||
|
else
|
||||||
|
exec "$@"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
srcscript='
|
||||||
|
set -e
|
||||||
|
path=$1
|
||||||
|
comp=$2
|
||||||
|
cw=$3
|
||||||
|
shift 3
|
||||||
|
cd "$(dirname "$path")"
|
||||||
|
name=$(basename "$path")
|
||||||
|
size=$(du -sb "$name" | cut -f1)
|
||||||
|
sleep 0.1
|
||||||
|
printf "%s\n" "$name"
|
||||||
|
sleep 0.1
|
||||||
|
if [ -d "$name" ] ; then
|
||||||
|
echo folder
|
||||||
|
cd "$name"
|
||||||
|
name=.
|
||||||
|
else
|
||||||
|
echo file
|
||||||
|
fi
|
||||||
|
sleep 0.1
|
||||||
|
exec "$@" "$name" | pv -s "$size" -fw $cw | $comp
|
||||||
|
'
|
||||||
|
|
||||||
|
dstscript='
|
||||||
|
set -e
|
||||||
|
path=$1
|
||||||
|
comp=$2
|
||||||
|
shift 3
|
||||||
|
name=$(head -n1)
|
||||||
|
type=$(head -n1)
|
||||||
|
if [ -d "$path" ] ; then
|
||||||
|
cd "$path"
|
||||||
|
else
|
||||||
|
cd "$(dirname "$path")"
|
||||||
|
name=$(basename "$path")
|
||||||
|
fi
|
||||||
|
if [ $type = folder ] ; then
|
||||||
|
mkdir -p "$name"
|
||||||
|
cd "$name"
|
||||||
|
$comp -d | "$@"
|
||||||
|
else
|
||||||
|
$comp -d | "$@" -O "$srcname" > "$name"
|
||||||
|
fi
|
||||||
|
'
|
||||||
|
|
||||||
|
# $1 = url , $2 = script , $3 = compression , $@ = script args
|
||||||
|
wrapssh() {
|
||||||
|
path=$1
|
||||||
|
script=$2
|
||||||
|
comp=$3
|
||||||
|
remote=
|
||||||
|
shift 3
|
||||||
|
if [ "$path" != "${path#*:}" ] ; then
|
||||||
|
remote=${path%%:*}
|
||||||
|
path=${path#*:}
|
||||||
|
fi
|
||||||
|
ssh_exec "$remote" sh -c "$script" sh "$path" "$comp" $(/usr/bin/tput cols) "$@"
|
||||||
|
}
|
||||||
|
|
||||||
|
if [ $# -lt 2 -o "$1" = "-h" -o "$1" = "--help" ] ; then
|
||||||
|
usage
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
src=$1
|
||||||
|
dst=$2
|
||||||
|
|
||||||
|
comp=${COMPRESSION-gzip}
|
||||||
|
|
||||||
|
wrapssh "$src" "$srcscript" "$comp" tar -cf - |
|
||||||
|
wrapssh "$dst" "$dstscript" "$comp" tar -xf -
|
||||||
|
|
||||||
73
rbuild/rbuild
Executable file
73
rbuild/rbuild
Executable file
|
|
@ -0,0 +1,73 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
[ "$DEBUG" = true ] && set -x
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# $1 = addr
|
||||||
|
ssh_exec() {
|
||||||
|
addr=$1
|
||||||
|
code=$2
|
||||||
|
shift 2
|
||||||
|
ssh "$addr" sh -c "$(/usr/bin/printf "%q " "$code")" sh "$(/usr/bin/printf "%q " "$@")"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BIND=${BIND}
|
||||||
|
MAP=${MAP}
|
||||||
|
REMOTE=${REMOTE-zawz@zsv}
|
||||||
|
|
||||||
|
IMAGE=${IMAGE-gcc:10-buster}
|
||||||
|
MODE=${MODE-docker}
|
||||||
|
TARGET=${TARGET-$(basename "$PWD")}
|
||||||
|
RESULT=${RESULT-$TARGET}
|
||||||
|
RESULT_LOCAL=${RESULT_LOCAL-$RESULT}
|
||||||
|
EXCLUDE=${EXCLUDE-obj}
|
||||||
|
DOCKER_USER=${DOCKER_USER-$UID}
|
||||||
|
|
||||||
|
volume_map=()
|
||||||
|
while read -r I
|
||||||
|
do
|
||||||
|
volume_map[N++]=--volume
|
||||||
|
volume_map[N++]=$I:$I:ro
|
||||||
|
done < <(tr ',' '\n' <<< "$BIND")
|
||||||
|
|
||||||
|
remotedir=$(ssh_exec "$REMOTE" 'mkdir -p "code/$1">/dev/null ; readlink -f "code/$1"' "$TARGET")
|
||||||
|
while IFS=: read -r I J
|
||||||
|
do
|
||||||
|
I=$(echo "$I" | sed "s|^\./|$remotedir/|g")
|
||||||
|
volume_map[N++]=--volume
|
||||||
|
volume_map[N++]=$I:$J:rw
|
||||||
|
done < <(tr ',' '\n' <<< "$MAP")
|
||||||
|
|
||||||
|
rsync -rvlpt --exclude="$EXCLUDE" -e ssh "$PWD/" "$REMOTE:code/$TARGET" >/dev/null
|
||||||
|
if [ "$MODE" = docker ] ; then
|
||||||
|
ssh_exec "$REMOTE" '
|
||||||
|
set -e
|
||||||
|
path=$1
|
||||||
|
user=$2
|
||||||
|
shift 2
|
||||||
|
cd "code/$path"
|
||||||
|
cat > .env
|
||||||
|
docker run --rm --user=$user \
|
||||||
|
--env-file=.env -w "/$path" \
|
||||||
|
--volume "$(pwd):/$path" \
|
||||||
|
"$@"
|
||||||
|
' "$TARGET" "$DOCKER_USER" "${volume_map[@]}" "$IMAGE" "$@" < <(
|
||||||
|
for I in $ENVBIND ; do
|
||||||
|
echo "$I=${!I}"
|
||||||
|
done
|
||||||
|
)
|
||||||
|
else
|
||||||
|
ssh_exec "$REMOTE" '
|
||||||
|
path=$1
|
||||||
|
shift 1
|
||||||
|
cd "code/$path"
|
||||||
|
cat > env
|
||||||
|
. env
|
||||||
|
set -x
|
||||||
|
"$@"
|
||||||
|
' "$target" "$@"
|
||||||
|
fi
|
||||||
|
|
||||||
|
mkdir -p "$(dirname "$RESULT_LOCAL")"
|
||||||
|
scp "$REMOTE:code/$TARGET/$RESULT" "$RESULT_LOCAL"
|
||||||
|
|
@ -85,7 +85,9 @@ domod()
|
||||||
sleep $(echo "scale=3; $N*$interval/1000" | bc) &
|
sleep $(echo "scale=3; $N*$interval/1000" | bc) &
|
||||||
sleepjob=$!
|
sleepjob=$!
|
||||||
statedown=$(xinput query-state "$1" | grep -o '[1-9][0-9]*\]=down' | cut -d ']' -f1 | head -n1)
|
statedown=$(xinput query-state "$1" | grep -o '[1-9][0-9]*\]=down' | cut -d ']' -f1 | head -n1)
|
||||||
|
activewin=$(xdotool getactivewindow)
|
||||||
for cid in $statedown ; do
|
for cid in $statedown ; do
|
||||||
|
xdotool mouseup --window $activewin $cid
|
||||||
xdotool click --repeat $N --delay $2 "$cid" &
|
xdotool click --repeat $N --delay $2 "$cid" &
|
||||||
done
|
done
|
||||||
wait $sleepjob
|
wait $sleepjob
|
||||||
|
|
|
||||||
110
zmon/zdu
Executable file
110
zmon/zdu
Executable file
|
|
@ -0,0 +1,110 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
fname=$(basename $0)
|
||||||
|
|
||||||
|
usage() {
|
||||||
|
echo "$fname [options] [path]"
|
||||||
|
echo 'Find the biggest size hog in given path
|
||||||
|
|
||||||
|
Options:
|
||||||
|
-h Display help
|
||||||
|
-r <val> Size ratio for continuation
|
||||||
|
-s Print only size
|
||||||
|
-p Print only path
|
||||||
|
-k Print raw size (kbyte)
|
||||||
|
'
|
||||||
|
}
|
||||||
|
|
||||||
|
get_dirsize_list() {
|
||||||
|
du -d1 $1 2>/dev/null | sort -n
|
||||||
|
}
|
||||||
|
|
||||||
|
ratio=0.5
|
||||||
|
unset opt_s opt_p opt_k
|
||||||
|
|
||||||
|
duopt="xh"
|
||||||
|
|
||||||
|
while getopts ":hr:spk" opt
|
||||||
|
do
|
||||||
|
case $opt in
|
||||||
|
h)
|
||||||
|
usage
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
r)
|
||||||
|
if [ -z "$OPTARG" ]
|
||||||
|
then
|
||||||
|
echo "r needs an argument" >/dev/stderr
|
||||||
|
exit 2
|
||||||
|
fi
|
||||||
|
ratio=$OPTARG
|
||||||
|
;;
|
||||||
|
s)
|
||||||
|
opt_s=y
|
||||||
|
;;
|
||||||
|
p)
|
||||||
|
opt_p=y
|
||||||
|
;;
|
||||||
|
k)
|
||||||
|
duopt="x"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "Unknown option: -$opt" >/dev/stderr
|
||||||
|
exit 2
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
[ -z "$opt_p" ] && [ -z "$opt_s" ] && opt_p=y opt_s=y
|
||||||
|
|
||||||
|
shift $((OPTIND-1))
|
||||||
|
|
||||||
|
list=""
|
||||||
|
pval=""
|
||||||
|
nval=""
|
||||||
|
cratio=""
|
||||||
|
dest=""
|
||||||
|
|
||||||
|
_step()
|
||||||
|
{
|
||||||
|
list=$(get_dirsize_list $1)
|
||||||
|
if [ "$(echo "$list" | wc -l)" = "1" ]
|
||||||
|
then
|
||||||
|
cratio=""
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
pval=$(echo "$list" | tail -n1)
|
||||||
|
nval=$(echo "$list" | tail -n2 | head -n1)
|
||||||
|
cratio=$(echo "scale=2;$(echo "$nval" | cut -f1)/$(echo "$pval" | cut -f1)" | bc 2>/dev/null)
|
||||||
|
dest=$(echo "$nval" | cut -f2- | xargs basename 2>/dev/null)
|
||||||
|
}
|
||||||
|
|
||||||
|
path="."
|
||||||
|
[ -n "$1" ] && path=$1
|
||||||
|
if ! [ -d $path ]
|
||||||
|
then
|
||||||
|
echo "Invalid path" >/dev/stderr
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
_step $path
|
||||||
|
|
||||||
|
while [ -n "$cratio" ] && [ "1" -eq "$(echo "$cratio >= $ratio" | bc)" ]
|
||||||
|
do
|
||||||
|
path="$path/$dest"
|
||||||
|
_step $path
|
||||||
|
done
|
||||||
|
|
||||||
|
pval=$(get_dirsize_list $path | tail -n1)
|
||||||
|
nval=$(find $path -maxdepth 1 -type f -printf '%s %p\n' | awk '{print int(($1+1023)/1024)"\t"$2}' | sort -n | tail -n1)
|
||||||
|
cratio=$(echo "scale=2;$(echo "$nval" | cut -f1)/$(echo "$pval" | cut -f1)" | bc 2>/dev/null)
|
||||||
|
|
||||||
|
if [ -n "$cratio" ] && [ "1" -eq "$(echo "$cratio >= $ratio" | bc)" ]
|
||||||
|
then
|
||||||
|
path="$path/$(echo "$nval" | cut -f2- | xargs basename)"
|
||||||
|
fi
|
||||||
|
|
||||||
|
[ -n "$opt_p" ] && printf "%s " "$path" | sed 's|^\./||;s|/./|/|' | tr -s '/'
|
||||||
|
[ -n "$opt_s" ] && printf "%s" "$(du -"$duopt"d0 "$path" | cut -f1)"
|
||||||
|
printf "\n"
|
||||||
|
|
||||||
102
zmon/zmem
Executable file
102
zmon/zmem
Executable file
|
|
@ -0,0 +1,102 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
fname=$(basename $0)
|
||||||
|
|
||||||
|
usage () {
|
||||||
|
echo "$fname [options]"
|
||||||
|
echo 'Display the most memory intensive processes
|
||||||
|
memory pid process
|
||||||
|
|
||||||
|
Options:
|
||||||
|
-h Display help
|
||||||
|
-n <int> Top n processes. Default 10
|
||||||
|
-p <pid> Operate on given process id
|
||||||
|
-m Full memory map of processes, sorted by usage'
|
||||||
|
}
|
||||||
|
|
||||||
|
nmax=10
|
||||||
|
unset process map
|
||||||
|
|
||||||
|
while getopts ":hn:p:m" opt;
|
||||||
|
do
|
||||||
|
case $opt in
|
||||||
|
h)
|
||||||
|
usage
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
n)
|
||||||
|
if ! echo $OPTARG | grep -Eq '^[0-9]+$'
|
||||||
|
then
|
||||||
|
error "n argument has to be an integer"
|
||||||
|
exit 2
|
||||||
|
fi
|
||||||
|
if [ -z "$OPTARG" ]
|
||||||
|
then
|
||||||
|
error "n needs an argument"
|
||||||
|
exit 2
|
||||||
|
fi
|
||||||
|
if [ "$OPTARG" -lt 1 ]
|
||||||
|
then
|
||||||
|
error "n argument has to be greater than 0"
|
||||||
|
exit 2
|
||||||
|
fi
|
||||||
|
nmax=$OPTARG
|
||||||
|
;;
|
||||||
|
p)
|
||||||
|
process=$OPTARG
|
||||||
|
;;
|
||||||
|
m)
|
||||||
|
map=y
|
||||||
|
;;
|
||||||
|
\?)
|
||||||
|
echo "Uknown option: $OPTARG"
|
||||||
|
usage
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
shift $((OPTIND-1))
|
||||||
|
|
||||||
|
|
||||||
|
if [ -n "$process" ] ; then
|
||||||
|
LIST=$(ps -q $process -eo "rss,pid,comm" | tail -n1)
|
||||||
|
else
|
||||||
|
LIST=$(ps -eo "rss,pid,comm" | tail -n+2 | sort -g | tail -n$nmax | tac)
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -n "$map" ]
|
||||||
|
then
|
||||||
|
|
||||||
|
plist=$(echo "$LIST" | awk '{print $2}')
|
||||||
|
|
||||||
|
flist=""
|
||||||
|
|
||||||
|
for i in $plist
|
||||||
|
do
|
||||||
|
if [ -z "$flist" ]
|
||||||
|
then
|
||||||
|
flist=$(pmap -x $i | tail -n+3 | head -n-2)
|
||||||
|
else
|
||||||
|
flist=$(printf "%s\n%s" "$flist" "$(pmap -x $i | tail -n+3 | head -n-2)")
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "$flist" | sort -nk3
|
||||||
|
|
||||||
|
else
|
||||||
|
|
||||||
|
echo "$LIST" | awk '{
|
||||||
|
if(int($1/1048576)>0) {
|
||||||
|
p=int($1/1048576)"G"
|
||||||
|
}
|
||||||
|
else if(int($1/1024)>0) {
|
||||||
|
p=int($1/1024)"M"
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
p=$1"K"
|
||||||
|
}
|
||||||
|
printf "%5s %5s %s\n", p, $2, $3
|
||||||
|
}'
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
@ -166,7 +166,7 @@ sinkinvolumeset()
|
||||||
}
|
}
|
||||||
sinkin_get_indexes()
|
sinkin_get_indexes()
|
||||||
{
|
{
|
||||||
list_sink_inputs | grep -E "(^Sink Input #)|(application.process.binary = )" | grep -F "application.process.binary = \"$1\"" -B1 | grep '^Sink Input' | cut -d'#' -f2
|
list_sink_inputs | grep -E "(^Sink Input #)|(application.process.binary = )|(application.name = )" | grep -E "(application.process.binary = \"$1\")|(application.name = \"$1\")" -B2 | grep '^Sink Input' | cut -d'#' -f2
|
||||||
}
|
}
|
||||||
|
|
||||||
#############
|
#############
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue