copy and update from /config/desktop-ubuntu/_scripts

This commit is contained in:
Dym Sohin 2023-08-06 22:15:06 +02:00
parent d89399cb80
commit 9c1dea02ca
27 changed files with 709 additions and 3 deletions

View File

@ -1,3 +0,0 @@
# _dump
a pile of shell script too small to get their own repos

41
bak-current.sh Executable file
View File

@ -0,0 +1,41 @@
#!/usr/bin/env zsh
BAK="/mnt/self-files"
if [ ! -z "$1" ]; then
BAK="$1"
fi
cd `realpath "$0" | xargs dirname`
./bak-home.sh "$BAK/Home_bak"
cp /home/dym/.config/doublecmd/doublecmd.xml \
/Cfg/doublecmd/
DIRS=(
_
Apps
Cfg
home/dym/.privat
)
for DIR in "${DIRS[@]}"; do
echo "-
-
# '$DIR'"
sudo \
rsync -zrhP --links --size-only --verbose --delete \
--exclude '**/.Trash-1000' \
--exclude '**/__sapper__/' \
--exclude '**/node_modules/' \
--exclude '**/target/' \
"/$DIR/" \
"$BAK/${DIR}"
done
echo "-
-
# '.privat'"
sudo \
rsync -zrhP --links --size-only --verbose --delete \
"/home/dym/.privat/" \
"$BAK/.privat"

73
bak-current_to_archive.sh Executable file
View File

@ -0,0 +1,73 @@
#!/usr/bin/env zsh
BAK="/Data/_bak"
# restic init '/home/dym/.privat' \
# -p '/home/dym/.privat/restic/p.txt' \
# -r "$BAK/.privat"
restic backup '/home/dym/.privat' \
-p '/home/dym/.privat/restic/p.txt' \
-r "$BAK/.privat"
cd `realpath "$0" | xargs dirname`
./bak-home "$BAK/Home_nix"
sudo \
rsync -zrhP --links --size-only --verbose --delete \
--exclude '**/.Trash-1000' \
--exclude '**/__sapper__/' \
--exclude '**/node_modules/' \
--exclude '**/target/' \
"/Servers/self-files/My/" \
"/Data/_my"
# sudo \
# rsync -zrhP --links --size-only --verbose --delete \
# --exclude '**/.Trash-1000' \
# --exclude '**/__sapper__/' \
# --exclude '**/node_modules/' \
# --exclude '**/target/' \
# "/Work/" \
# "$BAK/work-CURRENT"
DIRS=(
Apps
Books
Cfg
Code
Img
Music
Ui
)
for DIR in "${DIRS[@]}"; do
echo "-
-
# '$DIR'"
sudo \
rsync -zrhP --links --size-only --verbose --delete \
--exclude '**/.Trash-1000' \
--exclude '**/__sapper__/' \
--exclude '**/node_modules/' \
--exclude '**/target/' \
"/Servers/self-files/$DIR/" \
"$BAK/${DIR}"
done
echo "-
-
# '.fonts'"
sudo \
rsync -zrhP --links --size-only --verbose --delete \
--exclude '**/.Trash-1000' \
--exclude '**/__sapper__/' \
--exclude '**/node_modules/' \
--exclude '**/target/' \
"/home/dym/.fonts/" \
"$BAK/Fonts"

34
bak-data.sh Executable file
View File

@ -0,0 +1,34 @@
#!/usr/bin/env zsh
BAK="/media/data_bak"
if [ ! -z "$1" ]; then
BAK="$1"
fi
DIRS=(
Apps_andr
Apps_deb
Apps_wnd
Audio
Books
Bugs
Code
Drivers
Fonts
Img
Iso
Music
Posts
Texts
Video
)
for DIR in "${DIRS[@]}"; do
echo "-
-
# '$DIR'"
sudo \
rsync -zrhP --links --size-only --verbose --delete \
--exclude '**/.Trash-1000' \
"/Data/${DIR}/" \
"$BAK/${DIR}"
done

80
bak-home.sh Executable file
View File

@ -0,0 +1,80 @@
#!/usr/bin/env zsh
# home.sh
BAK='/Data/_bak/Home_nix'
if [ ! -z "$1" ]; then
BAK="$1"
fi
echo "BAK: backing up '$HOME' to '$BAK'"
rsync -rhP --links --size-only --verbose --delete \
--exclude '**/.Trash-1000/' \
--exclude '**/*.log' \
--exclude '**/*.part' \
--exclude '**/*~' \
--exclude '**/hyphen-data/' \
--exclude '**/logs/' \
--exclude '**/node_modules/' \
--exclude '**/storage/default/' \
--exclude '**/datareporting/' \
--exclude '.android/' \
--exclude '.bun/' \
--exclude '.cabal/' \
--exclude '.cache/' \
--exclude '.cargo/' \
--exclude '.cinnamon/' \
--exclude '.config/agregore-browser/' \
--exclude '.config/chromium/' \
--exclude '.config/Code/Cache*' \
--exclude '.config/Code/Crashpad/' \
--exclude '.config/Code/Service Worker/' \
--exclude '.config/Code/User/History/' \
--exclude '.config/Code/User/workspaceStorage/' \
--exclude '.config/google-chrome-unstable/' \
--exclude '.config/google-chrome/' \
--exclude '.config/vivaldi/' \
--exclude '.config/xnviewmp/' \
--exclude '.deno/' \
--exclude '.docker/' \
--exclude '.electron-gyp/' \
--exclude '.figma/' \
--exclude '.fonts/' \
--exclude '.gnome/' \
--exclude '.gnupg/' \
--exclude '.gphoto/' \
--exclude '.gradle/' \
--exclude '.java/' \
--exclude '.linuxmint/' \
--exclude '.local/share/lutris' \
--exclude '.local/share/Trash' \
--exclude '.nix-defexpr' \
--exclude '.nix-profile' \
--exclude '.node/' \
--exclude '.npm/' \
--exclude '.nv/' \
--exclude '.pipupgrade/' \
--exclude '.pki/' \
--exclude '.privat/' \
--exclude '.Private/' \
--exclude '.pub-cache/' \
--exclude '.rustup/' \
--exclude '.ssh' \
--exclude '.steam*' \
--exclude '.thunderbird' \
--exclude '.zoom/' \
--exclude 'Android/' \
--exclude 'FontBase/' \
--exclude 'Games/' \
--exclude 'Cfg/' \
--exclude 'Desktop/' \
--exclude 'Inbox/' \
--exclude 'My Games/' \
--exclude 'go/' \
--exclude 'Private/' \
--exclude 'snap/' \
--exclude 'Steam/' \
--exclude 'Servers/' \
--exclude 'tmp/' \
"/home/dym/" \
"$BAK"

26
device-info.sh Executable file
View File

@ -0,0 +1,26 @@
#!/usr/bin/env zsh
# devices info
sudo apt install -y \
hddtemp lm-sensors
sudo hddtemp /dev/sd*
sudo sensors-detect
sudo sensors
free -h
sensors
sudo hddtemp SATA:/dev/sda
sudo hddtemp SATA:/dev/sdb
sudo hddtemp SATA:/dev/sdc
sudo hddtemp SATA:/dev/sdd
# hdd details
iostat -dx /dev/sd*

17
devices-report.sh Executable file
View File

@ -0,0 +1,17 @@
#!/usr/bin/env zsh
echo -e "Subject: server report on $(date -u '+%Y-%m-%d @ %H:%M:%S')\n\n" \
> ~/devinfo.txt
free -h \
>> ~/devinfo.txt
df -H \
>> ~/devinfo.txt
iostat -dx /dev/sd* \
>> ~/devinfo.txt
cat ~/devinfo.txt \
| sendmail \
-v server@dym.sh

6
disable-power-button.sh Executable file
View File

@ -0,0 +1,6 @@
#!/usr/bin/env zsh
# power button
gsettings set org.gnome.settings-daemon.plugins.power button-sleep "nothing"
gsettings set org.gnome.settings-daemon.plugins.power button-suspend "nothing"
gsettings set org.gnome.settings-daemon.plugins.power button-hibernate "nothing"

17
files_date_sort.sh Executable file
View File

@ -0,0 +1,17 @@
#!/usr/bin/env zsh
MONTHS=( 01 02 03 04 05 06 07 08 09 10 11 12 )
for Y in `( /bin/ls /Ui )`; do
cd /Ui/$Y/
echo "'/Ui/$Y'"
for M in $MONTHS; do
mkdir -p ./$M/
echo "'/Ui/$Y/$M/'"
mv ./*$Y-$M* ./$M/
mv ./*$Y$M* ./$M/
done
done

17
files_date_sort_ui_unsorted.sh Executable file
View File

@ -0,0 +1,17 @@
#!/usr/bin/env zsh
MONTHS=( 01 02 03 04 05 06 07 08 09 10 11 12 )
cd /Ui/_un/
for Y in `( /bin/ls /Ui )`; do
for M in $MONTHS; do
mkdir -p "/Ui/$Y/$M/"
echo "'/Ui/$Y/$M/'"
mv /Ui/_un/*$Y-$M* /Ui/$Y/$M/
mv /Ui/_un/*$Y$M* /Ui/$Y/$M/
done
done

7
heic.sh Executable file
View File

@ -0,0 +1,7 @@
#!/usr/bin/env zsh
for f in "$@"
do
echo "Converting $f ..."
heif-convert $f "$f-$(date +\%Y-\%m-\%d@\%H-\%M).jpg"
done

79
hourly-backup.sh Executable file
View File

@ -0,0 +1,79 @@
#!/usr/bin/env bash
bpath="/backup_new"
db_name=''
db_login=''
db_pass=''
db_name2=''
db_login2=''
db_pass2=''
[ ! -d "$bpath/day" ] \
&& mkdir -p "${bpath}/day"
[ ! -d "$bpath/week" ] \
&& mkdir -p "${bpath}/week"
[ ! -d "$bpath/month" ] \
&& mkdir -p "${bpath}/month"
[ ! -d "$bpath/year" ] \
&& mkdir -p "${bpath}/year"
year=`date +"%Y"`
month=`date +"%m"`
day=`date +"%d"`
time=`date +"%H-00"`
date="${year}-${month}-${day}"
tmp_short="b_${date}_${time}"
tmp_full="${bpath}/${tmp_short}"
mkdir -p "$tmp_full"
mysqldump -u "$db_login" -p"$db_pass" --databases "$db_name" \
> "${tmp_full}/bu_${db_name}__${date}_${time}.sql"
mysqldump -u "$db_login2" -p"$db_pass2" --databases "$db_name2" \
> "${tmp_full}/bu_${db_name2}__${date}_${time}.sql"
archive="${tmp_full}.tar.gz"
cd "$bpath"
tar -czf "$archive" "$tmp_short"
ln "$archive" "${bpath}/day/"
if [ "$time" == "00-00" ]
then
ln "$archive" "${bpath}/week/"
if [ "$day" == "01" ]
then
ln "$archive" "${bpath}/month/"
if [ "$month" == "01" ]
then
ln "$archive" "${bpath}/year/"
fi
fi
fi
if [ "$time" == "02-00" ]
then
scp -rp \
-i ~/.ssh/backup+ \
"$archive" \
'backup@<backup.DOMAIN.TLD>:/b_incoming/'
fi
rm $archive
rm -rf "$tmp_full"
find ${bpath}/day/* -mtime +1 -exec rm {} \;
find ${bpath}/week/* -mtime +7 -exec rm {} \;
find ${bpath}/month/* -mtime +365 -exec rm {} \;

3
kk.sh Executable file
View File

@ -0,0 +1,3 @@
#!/usr/bin/env zsh
kill -9 `ps aux | grep "$1" | awk '{print $2}'`

6
off.sh Executable file
View File

@ -0,0 +1,6 @@
#!/bin/sh
# off
sudo systemctl stop mysql
sudo shutdown now

44
opti.sh Executable file
View File

@ -0,0 +1,44 @@
#!/usr/bin/env zsh
# optimize png and jpg files
calc_reduction()
{
SIZE_PRE="$1"
SIZE_POST="$2"
PERECENT=` echo "scale=2; 100 - (100 * $SIZE_POST / $SIZE_PRE)" | bc `
RESULT="$(( $SIZE_PRE / 1000 ))-$(( ( $SIZE_PRE - $SIZE_POST ) / 1000 )) kb \
($PERECENT%)
"
echo " $RESULT"
}
for FILENAME in "$@"
do
FILETYPE=` file -b --mime-type "$FILENAME" `
echo "$FILENAME : $FILETYPE"
SIZE_PRE=` stat "$FILENAME" -c '%s' `
case "$FILETYPE" in
'image/png')
mogrify "$FILENAME"
pngcrush -nolimits -s "$FILENAME" "$FILENAME.tmp.png"
if [ -f "$FILENAME.tmp.png" ] \
&& [ -s "$FILENAME.tmp.png" ]
then
mv "$FILENAME.tmp.png" "$FILENAME"
else
rm "$FILENAME.tmp.png"
fi
;;
'image/jpeg')
jpegoptim "$FILENAME" -qsftp
;;
esac
SIZE_POST=` stat "$FILENAME" -c '%s' `
[ $SIZE_PRE -gt $SIZE_POST ] \
&& echo ` calc_reduction "$SIZE_PRE" "$SIZE_POST" `
done

19
pdf-slice.sh Executable file
View File

@ -0,0 +1,19 @@
#!/usr/bin/env zsh
for PAGE in {1..25};do
gs -sDEVICE=pdfwrite -dNOPAUSE -dBATCH -dSAFER \
-dFirstPage=$PAGE -dLastPage=$PAGE \
-sOutputFile=p_$PAGE.pdf all.pdf
done
gs -sDEVICE=pdfwrite -dNOPAUSE -dBATCH -dSAFER \
-sOutputFile=crit_2.pdf \
p_{5..7}.pdf
gs -sDEVICE=pdfwrite -dNOPAUSE -dBATCH -dSAFER \
-sOutputFile=crit_3.pdf \
p_{8..9}.pdf
gs -sDEVICE=pdfwrite -dNOPAUSE -dBATCH -dSAFER \
-sOutputFile=crit_4.pdf \
p_{11..16}.pdf

11
prtwnd.sh Executable file
View File

@ -0,0 +1,11 @@
#!/usr/bin/env zsh
# print screen current window
WND=`xprop -root \
| grep '_NET_ACTIVE_WINDOW(WINDOW)' \
| grep -oE '0x\w+'
`
import -window "$WND" \
"/_/PrtWnd--$(date '+%Y%m%d@%H%M%S').png"

60
purge.sh Executable file
View File

@ -0,0 +1,60 @@
#!/usr/bin/env zsh
# purge memory
free -h
echo "clearing memory"
sudo sync
sudo sh -c 'echo 3 > /proc/sys/vm/drop_caches'
free -h
# clear logs
echo "clearing /var/log"
sudo du -hs /var/log
sudo find /var/log -type f -delete
sudo du -hs /var/log
# remove temp things
rm -rf /var/lib/systemd/coredump/*
echo "clearing /etc/apache2/logs"
sudo du -hs /etc/apache2/logs
sudo find /etc/apache2/logs -type f -delete
sudo du -hs /etc/apache2/logs
rm ~/.xsession-errors*
rm ~/.config/doublecmd/doublecmd.err
rm ~/.mozilla/firefox/Crash\ Reports/
# empty trash
rm -rf ~/.local/share/Trash
sudo rm -rf /root/.local/share/Trash/*
sudo rm -rf /[A-Z]*/.Trash-1000
sudo rm -rf /media/*/.Trash-1000
sudo rm -rf /media/*/*/.Trash-1000
sudo rm -rf /mnt/*/.Trash-1000
sudo rm -rf /mnt/*/*/.Trash-1000
# rm -rf /_servers/*/.Trash-1000
# vacuum firefox
kill -9 firefox
cd ~/.mozilla/firefox/dym/
find -maxdepth 1 -type f \
| xargs file -F "" \
| awk '/SQLite/{print $1}' \
| xargs -n 1 -I FILE bash -c \
'echo Vacuuming $1; sqlite3 $1 "vacuum;"' \
bash FILE
#Cleaning the old kernels
dpkg-query -l | grep 'linux-im*'
#dpkg-query -l | grep linux-im* | awk '{print $2}'
sudo apt-get purge -y $(dpkg -l 'linux-*' \
| sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d' | head -n -1) \
--assume-yes
sudo apt-get install -y linux-headers-`uname -r \
|cut -d'-' -f3`-`uname -r \
|cut -d'-' -f4`

4
readme.md Normal file
View File

@ -0,0 +1,4 @@
# _dump
> a pile of shell script too small to get their own repos

6
restart.sh Executable file
View File

@ -0,0 +1,6 @@
#!/usr/bin/env zsh
# restart
sudo systemctl stop mysql
sudo shutdown -r now

8
save-cfg.sh Executable file
View File

@ -0,0 +1,8 @@
#!/bin/sh
rm -rf /Site/config/desktop-ubuntu
sudo cp -r /Cfg /Site/config/desktop-ubuntu
sudo chown -R $USER:$USER /Site/config/desktop-ubuntu/
cd /Site/config/desktop-ubuntu/
git add .
shipit

47
sort_out.sh Executable file
View File

@ -0,0 +1,47 @@
#!/usr/bin/env zsh
Y=`date '+%Y'`
M=`date '+%m'`
UI_PATH="/Ui/$Y/$M/"
[ ! -d "$UI_PATH" ] \
&& mkdir -p "$UI_PATH"
mv /_/*\[footer*.(jpg|png|gif|webp|avif|svg) "$UI_PATH"
mv /_/*\[fold*.(jpg|png|gif|webp|avif|svg) "$UI_PATH"
mv /_/*\[full*.(jpg|png|gif|webp|avif|svg) "$UI_PATH"
mv /_/*\[menu*.(jpg|png|gif|webp|avif|svg) "$UI_PATH"
mv /_/*\[part*.(jpg|png|gif|webp|avif|svg) "$UI_PATH"
mv /_/*\[section*.(jpg|png|gif|webp|avif|svg) "$UI_PATH"
LOGO_PATH="/Img/identity/"
[ ! -d "$LOGO_PATH" ] \
&& mkdir -p "$LOGO_PATH"
mv /_/*\[logo*.(jpg|png|gif|webp|avif|svg) "$LOGO_PATH"
COVERS_PATH="/Img/covers/"
[ ! -d "$COVERS_PATH" ] \
&& mkdir -p "$COVERS_PATH"
mv /_/*\[poster*.(jpg|png|gif|webp|avif|svg) "$COVERS_PATH"
mv /_/*\[album*.(jpg|png|gif|webp|avif|svg) "$COVERS_PATH"
mv /_/*\[cover*.(jpg|png|gif|webp|avif|svg) "$COVERS_PATH"
IMG_PATH="/Img/$Y/$M/"
[ ! -d "$IMG_PATH" ] \
&& mkdir -p "$IMG_PATH"
mv /_/*.(jpg|png|gif|webp|avif|svg) "$IMG_PATH"
DUST_PATH='/Data/Video/yt/@watchdust/'
[ ! -d "$DUST_PATH" ] \
&& mkdir -p "$DUST_PATH"
mv /_/yt-Sci-Fi*.(mp4|webm|mkv) "$DUST_PATH"
VID_PATH="/Data/Video/$Y/$M/"
[ ! -d "$VID_PATH" ] \
&& mkdir -p "$VID_PATH"
mv /_/*.(mp4|webm|mkv|mov|3gp|avi|mp2) "$VID_PATH"

14
ssh-keygen.sh Executable file
View File

@ -0,0 +1,14 @@
#!/usr/bin/env bash
NEW_SSH_EMAIL="$1"
[ -z "$NEW_SSH_EMAIL" ] \
&& NEW_SSH_EMAIL="rsa-key_$(date +\%Y\%m\%d\%H\%M)"
ssh-keygen \
-t rsa -b 4096 \
-C "$NEW_SSH_EMAIL@dym.sh" \
-f ~/.ssh/$NEW_SSH_EMAIL
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/$NEW_SSH_EMAIL

23
to_dec.sh Executable file
View File

@ -0,0 +1,23 @@
#!/usr/bin/env zsh
# convert hexadecimal to base10
# #TODO
# - whitespace-separated arguments to corresponding array of values
# (exluding -f/--flags)
# - convert hex-colors[with alpha] to rgb[a]()
# (i.e. "#00FFCC[80]" to "rgba(0, 255, 204[, 0.5])")
HEX=`echo "$1" | tr 'a-z' 'A-Z'`
DEC=`echo "obase=10; ibase=16; $HEX" \
| bc
`
if [[ $@ =~ '-v' ]]; then
echo "HEX: '$HEX'
DEC: '$DEC'
"
else
echo "$DEC"
fi

23
to_hex.sh Executable file
View File

@ -0,0 +1,23 @@
#!/usr/bin/env zsh
# convert base10 to hexadecimal
# #TODO
# - whitespace-separated arguments to corresponding array of values
# (exluding -f/--flags)
# - multiple convert arguments to acco
# (i.e. "0 255 204" to "00 FF CC")
DEC="$1"
HEX=`echo "obase=16; ibase=10; $DEC" \
| bc
`
if [[ $@ =~ '-v' ]]; then
echo "DEC: '$DEC'
HEX: '$HEX'
"
else
echo "$HEX"
fi

22
to_mp3.sh Executable file
View File

@ -0,0 +1,22 @@
#!/usr/bin/env zsh
# convert to mp3
echo "to mp3: [ $@ ]"
for UNCOMPRESSED in "$@"
do
MP3=` echo "$UNCOMPRESSED" \
| sd '\.\w+$' ' [conv].mp3' \
`
echo "'$UNCOMPRESSED'"
echo ">> '$MP3'"
ffmpeg \
-i "$UNCOMPRESSED" \
-codec:a libmp3lame \
-qscale:a 2 \
-loglevel quiet \
-y "$MP3" \
&& \
rm "$UNCOMPRESSED"
done

22
upd.sh Executable file
View File

@ -0,0 +1,22 @@
#!/usr/bin/env zsh
# oh-my-zsh
cd ~/.oh-my-zsh/ \
&& ./tools/upgrade.sh \
&& cd -
# rust & co
rustup update
cargo install-update -a
# bun
bun upgrade
# deno
deno upgrade
# nix
sudo nix-channel --update
sudo nixos-rebuild switch -I nixos-config=$HOME/Cfg/configuration.nix