Compare commits

...

4 Commits

Author SHA1 Message Date
d3bdb21f94 Moved helpers to tools 2022-04-03 23:53:51 +03:00
4bff0c15f5 Removed attic 2022-04-03 23:53:51 +03:00
a101b152eb Added all changes since last year 2022-04-03 23:53:51 +03:00
lanxu
dccfecec74 Added new scripts for various use-cases 2022-04-03 23:53:51 +03:00
56 changed files with 816 additions and 196 deletions

5
.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
*.log
*.old
*.swp
__pycache__
temp

View File

@ -1,6 +0,0 @@
.log
.old
.swp
__pycache__
temp
.scr

View File

@ -1,6 +1,10 @@
# Script collection by lanxu :muscle:
This is a general collection of useful scripts used by me. Most of the scripts are written or modified by me.
## Disclaimer
Totally out-of-date. Will be updated in the future!
## Scripts by others
Script | Description
@ -40,4 +44,3 @@ There are a few scripts that are just thrown into the mix in case I need them at
convertAtlasXMLToJson.php (convert sprite atlases to json)
sortPackagesBySize.sh (pacman script to sort packages by used size)

View File

@ -0,0 +1,14 @@
[Desktop Entry]
Name=imv-folder
Name[en_US]=imv
GenericName=Image viewer
GenericName[en_US]=Image viewer
Comment=Fast freeimage-based Image Viewer | Open all images on a folder
Exec=imv-dir %f
NoDisplay=true
Terminal=false
Type=Application
Categories=Graphics;2DGraphics;Viewer;
MimeType=image/bmp;image/gif;image/jpeg;image/jpg;image/pjpeg;image/png;image/tiff;image/x-bmp;image/x-pcx;image/x-png;image/x-portable-anymap;image/x-portable-bitmap;image/x-portable-graymap;image/x-portable-pixmap;image/x-tga;image/x-xbitmap;
Icon=multimedia-photo-viewer
Keywords=photo;picture;

View File

@ -0,0 +1,10 @@
[Desktop Entry]
Type=Application
Name=itch (XWayland)
Exec=env GDK_BACKEND=x11 itch %U
Icon=itch
Terminal=false
Categories=Game;
MimeType=x-scheme-handler/itchio;x-scheme-handler/itch;
X-GNOME-Autostart-enabled=true
Comment=Install and play itch.io games easily (uses X11 for games)

View File

@ -0,0 +1,8 @@
[Desktop Entry]
Type=Application
Name=lf-terminal
Comment=Launches the lf file manager
Icon=utilities-terminal
Exec=kitty -e lf
Categories=System;FileTools;FileManager
MimeType=inode/directory;

View File

@ -0,0 +1,9 @@
[Desktop Entry]
Name=Mullvad VPN (XWayland)
Exec=env GDK_BACKEND=x11 "/opt/Mullvad VPN/mullvad-vpn" %U
Terminal=false
Type=Application
Icon=mullvad-vpn
StartupWMClass=Mullvad VPN
Comment=Mullvad VPN client
Categories=Network;

View File

@ -1,95 +0,0 @@
#!/bin/php
<?php
$VERSION = 1;
if (isset($argv)) {
//get the file name
$filename = $argv[1];
//see if that file exists
if (file_exists($filename)) {
$xml = simplexml_load_file($filename);
//the xml is now imported
$json = convertXMLToJSONHash($xml);
$new_filename = explode(".", $filename)[0] . ".json";
logMsg("{$json->meta->sprites} textures processed successfully with {$json->meta->app} version {$json->meta->version}");
file_put_contents($new_filename, json_encode($json));
logMsg("Saved to {$new_filename}");
} else {
logMsg("No file exists named: {$filename}");
die();
}
}
else {
logMsg("No input file name provided");
die();
}
die();
function convertXMLToJSONHash($xml){
$json = new stdClass();
//build out the frames obj (contains all the images)
$json->frames = new stdClass();
//build out the meta object (just info about this program)
$json->meta = writeJSONMeta();
//loop through all subtextures
$i = 0;
foreach ($xml->SubTexture as $frame){
//get the attributes for each XML node
$attrs = $frame->attributes();
//make the right object, JSON arr would differ here
$json->frames->{$attrs["name"]} = new stdClass();
//make the frame object
$frame_obj = new stdClass();
$frame_obj->x = intval($attrs["x"]);
$frame_obj->y = intval($attrs["y"]);
$frame_obj->w = intval($attrs["width"]);
$frame_obj->h = intval($attrs["height"]);
//set the frame object
$json->frames->{$attrs["name"]}->frame = $frame_obj;
//make the sprite source object
$sprite_obj = new stdClass();
$sprite_obj->x = 0;
$sprite_obj->y = 0;
$sprite_obj->w = $frame_obj->w;
$sprite_obj->h = $frame_obj->h;
//set the sprite source object
$json->frames->{$attrs["name"]}->spriteSourceSize = $sprite_obj;
//make the source size object
$source_obj = new stdClass();
$source_obj->w = $frame_obj->w;
$source_obj->h = $frame_obj->h;
//set the sprite source object
$json->frames->{$attrs["name"]}->sourceSize = $source_obj;
//add some more stuff that may or may not matter
$json->frames->{$attrs["name"]}->rotated = false;
$json->frames->{$attrs["name"]}->trimmed = false;
//make the pivot object
$pivot_obj = new stdClass();
$pivot_obj->x = 0.5;
$pivot_obj->y = 0.5;
$json->frames->{$attrs["name"]}->rotated = false;
$i++;
}
$json->meta->sprites = $i;
//get root attributes
$attrs = $xml->attributes();
$json->meta->image = (string)$attrs["imagePath"];
return $json;
}
function writeJSONMeta(){
global $VERSION;
$meta = new stdClass();
$meta->app = "TextureAtlasConverter";
$meta->version = $VERSION;
return $meta;
}
function logMsg ($message){
echo "{$message}\n";
}
?>

View File

@ -1,5 +0,0 @@
#!/bin/bash
s=`~/Scripts/dropbox.py puburl "$1"`
zenity --info --text="$s" && echo "$s" | xclip -selection c

View File

@ -1,17 +0,0 @@
#!/bin/sh
# This script restores local aur repository after fuckup with cleaning which
# happens way too often for me
echo "Creating custom repository..."
sudo install -d /var/cache/pacman/custom -o lanxu
repo-add /var/cache/pacman/custom/custom.db.tar
aur sync -u
echo "Retrieving aur packages which are installed..."
pacman -Qm | cut -f 1 -d " " > aur-packages.txt
echo "Installing..."
xargs -a aur-packages.txt aur sync
echo "Done."

10
docker-clean Executable file
View File

@ -0,0 +1,10 @@
#!/bin/sh
# Stop everything
docker stop $(docker ps -a -q)
# Remove all containers
docker rm $(docker ps -a -q)
# Remove all imagesa
docker rmi $(docker images -q)

View File

@ -3,8 +3,10 @@
appname=$1
sound="message"
if [ "$appname" = "Telegram-desktop" ]; then
if [ $appname = "Telegram Desktop" ]; then
sound="window-attention"
fi
echo "$1" >> /tmp/test
echo "$sound" >> /tmp/test
mpv --no-terminal /usr/share/sounds/freedesktop/stereo/$sound.oga&

View File

@ -0,0 +1,31 @@
#!/bin/python
import requests
import sys
import re
def get_urls(text):
text = text.replace('\n', ' ').replace('\r', '')
#r = re.compile("\"(https:([^<>]*))\">", re.I|re.M)
urls = []
matches = re.findall("\"(https:([^<>]*))\">", text)
if matches:
for m in matches:
urls.append(m[0])
return urls
if __name__ == "__main__":
url = sys.argv[1]
jar = requests.cookies.RequestsCookieJar()
jar.set('_groupees_session', 'OWFWT1ZVTVZtdkFJU2NUUW5ZM2kwblNtTkFYVW0xdUhSWlVpdmROZE9ITWE0UDJIQlV5bmRpcXZLOTF5S1B1Z2lQZ08zUkJpT05FeVRaL0xQcDJJL1hKaVMvOWJPQUVvTTNzVjlaVERXQ2s5RE9WeEc4aWk1ZU9zMGVJd0tscGhLazZvSjVCQWZPMEdFWmVEdXZSYWNld3lTWDlyY1ZYdGdXOG54OXkrOUYyRjB4UXBpVUJJTXloZkN2REhYNTlwZ0s0NlVtbVNBclBRSXZEYVRmZXo1dz09LS0rOEkxVmUvR0ZCUEY1d3Y1RDVXSHd3PT0%3D--fc3a4f506f7c4a283a5d105ae9cb400b604a7fc8', domain='.groupees.com', path="/")
r = requests.get(url, cookies=jar)
urls = get_urls(r.text)
file_urls = [u for u in urls if "https://storage.groupees.com" in u]
cookie = jar.get('_groupees_session')
print("header=\"Cookie:_groupees_session=%s;\"" % cookie)
for file_url in file_urls:
print("remote-header-name")
print("remote-name")
print("url=\"%s\"" % (file_url))

View File

@ -2,12 +2,19 @@
import re
import logging
from logging.handlers import RotatingFileHandler
import subprocess
from subprocess import check_output
import lib.helpers as helpers
FORMAT = "%(asctime)s %(levelname)s %(message)s"
logging.basicConfig(format=FORMAT, filename=__file__+'.log', level=logging.DEBUG)
log_formatter = logging.Formatter("%(asctime)s %(levelname)s %(message)s")
log_handler = RotatingFileHandler(__file__+'.log', maxBytes=1024*1024*10, mode='a', backupCount=0, encoding=None, delay=0)
log_handler.setFormatter(log_formatter)
log_handler.setLevel(logging.DEBUG)
logger = logging.getLogger('root')
logger.setLevel(logging.DEBUG)
logger.addHandler(log_handler)
ATICONFIG_AVAILABLE = helpers.is_exe("/usr/bin/aticonfig")
SENSORS_AVAILABLE = helpers.is_exe("/usr/bin/sensors")
@ -16,7 +23,7 @@ def get_temperature():
command = None
if SENSORS_AVAILABLE:
commands = ["sensors amdgpu-pci-0800 | grep edge",
commands = ["sensors amdgpu-pci-0a00 | grep edge",
"sensors radeon-pci-* | grep temp1",
"sensors thinkpad-isa-0000 | grep ATI"]
@ -48,8 +55,8 @@ def get_temperature():
m = re.search(r'- (.*) C', return_value.decode("utf-8"))
temp = m.group(1)
else:
logging.info('wat')
logging.info(temp)
logger.info('wat')
logger.info(temp)
return temp
print(get_temperature())

View File

@ -1,16 +0,0 @@
#!/usr/bin/python
import os
import re
import lib.helpers as helpers
from subprocess import check_output
hubic_available = helpers.is_exe('/usr/bin/hubic')
if not hubic_available:
print('Not running')
os.exit(1)
return_value = check_output(['hubic', 'status'])
m = re.search(r'State: (.*)', return_value.decode("utf-8"))
print(m.group(1))

46
i3-disable-standby-fs.py Normal file
View File

@ -0,0 +1,46 @@
#!/usr/bin/env python3
from argparse import ArgumentParser
from subprocess import call
import i3ipc
i3 = i3ipc.Connection()
parser = ArgumentParser(prog='disable-standby-fs',
description='''
Disable standby (dpms) and screensaver when a window becomes fullscreen
or exits fullscreen-mode. Requires `xorg-xset`.
''')
args = parser.parse_args()
def find_fullscreen(con):
# XXX remove me when this method is available on the con in a release
return [c for c in con.descendents() if c.type == 'con' and c.fullscreen_mode]
def set_dpms(state):
if state:
print('setting dpms on')
call(['xset', 's', 'on'])
call(['xset', '+dpms'])
else:
print('setting dpms off')
call(['xset', 's', 'off'])
call(['xset', '-dpms'])
def on_fullscreen_mode(i3, e):
set_dpms(not len(find_fullscreen(i3.get_tree())))
def on_window_close(i3, e):
if not len(find_fullscreen(i3.get_tree())):
set_dpms(True)
i3.on('window::fullscreen_mode', on_fullscreen_mode)
i3.on('window::close', on_window_close)
i3.main()

2
i3/lock.sh Executable file
View File

@ -0,0 +1,2 @@
#!/bin/sh
i3lock -k -i /usr/share/backgrounds/archlinux/wave.png --time-color FFFFFF --date-color FFFFFF --ignore-empty-password --show-failed-attempts -C

18
i3/screenoff.sh Executable file
View File

@ -0,0 +1,18 @@
#!/usr/bin/env bash
# Only exported variables can be used within the timer's command.
#export PRIMARY_DISPLAY="$(xrandr | awk '/ primary/{print $1}')"
# Run xidlehook
xidlehook \
`# Don't lock when there's a fullscreen application` \
--not-when-fullscreen \
`# Don't lock when there's audio playing` \
--not-when-audio \
`# Dim the screen after 60 seconds, undim if user becomes active` \
--timer 15 \
'xset dpms force off' \
'xset dpms force on' \
#--timer 300 \
# 'systemctl suspend' \
# ''

24
i3/screensaver.sh Executable file
View File

@ -0,0 +1,24 @@
#!/usr/bin/env bash
# Only exported variables can be used within the timer's command.
#export PRIMARY_DISPLAY="$(xrandr | awk '/ primary/{print $1}')"
# Run xidlehook
xidlehook \
--not-when-fullscreen \
--not-when-audio \
--timer 180 \
'notify-send -u low "Locking in 15 seconds..."' \
'' \
--timer 15 \
'xset dpms force off' \
'xset dpms force on'
# --timer 300 \
# 'systemctl suspend' \
# ''
# --timer 15 \
# 'loginctl lock-session' \
# '' \
# --timer 15 \
# 'i3lock -k -i /usr/share/backgrounds/archlinux/wave.png --timecolor FFFFFF --datecolor FFFFFF --ignore-empty-password --show-failed-attempts -C' \
# '' \

47
i3/xscreensaverstopper.sh Executable file
View File

@ -0,0 +1,47 @@
#!/bin/bash
# xscreensaverstopper.sh
# This script is licensed under GNU GPL version 2.0 or above
# Uses elements from lightsOn.sh
# Copyright (c) 2011 iye.cba at gmail com
# url: https://github.com/iye/lightsOn
# This script is licensed under GNU GPL version 2.0 or above
# Description: Restarts xscreensaver's idle countdown while
# full screen applications are running.
# Checks every 30 seconds to see if a full screen application
# has focus, if so then the xscreensaver is told to restart
# its idle countdown.
# enumerate all the attached screens
displays=""
while read id
do
displays="$displays $id"
done< <(xvinfo | sed -n 's/^screen #\([0-9]\+\)$/\1/p')
checkFullscreen()
{
# loop through every display looking for a fullscreen window
for display in $displays
do
#get id of active window and clean output
activ_win_id=`DISPLAY=$DISPLAY.${display} xprop -root _NET_ACTIVE_WINDOW`
activ_win_id=${activ_win_id:40:9}
# Check if Active Window (the foremost window) is in fullscreen state
isActivWinFullscreen=`DISPLAY=$DISPLAY.${display} xprop -id $activ_win_id | grep _NET_WM_STATE_FULLSCREEN`
if [[ "$isActivWinFullscreen" == *NET_WM_STATE_FULLSCREEN* ]];then
xscreensaver-command -deactivate
fi
done
}
while sleep $((30)); do
checkFullscreen
done
exit 0

17
import-gsettings Executable file
View File

@ -0,0 +1,17 @@
#!/bin/sh
# By default wayland only reads settings from gsettings and not from settings.ini
# usage: import-gsettings
config="${XDG_CONFIG_HOME:-$HOME/.config}/gtk-3.0/settings.ini"
if [ ! -f "$config" ]; then exit 1; fi
gnome_schema="org.gnome.desktop.interface"
gtk_theme="$(grep 'gtk-theme-name' "$config" | sed 's/.*\s*=\s*//')"
icon_theme="$(grep 'gtk-icon-theme-name' "$config" | sed 's/.*\s*=\s*//')"
cursor_theme="$(grep 'gtk-cursor-theme-name' "$config" | sed 's/.*\s*=\s*//')"
font_name="$(grep 'gtk-font-name' "$config" | sed 's/.*\s*=\s*//')"
gsettings set "$gnome_schema" gtk-theme "$gtk_theme"
gsettings set "$gnome_schema" icon-theme "$icon_theme"
gsettings set "$gnome_schema" cursor-theme "$cursor_theme"
gsettings set "$gnome_schema" font-name "$font_name"

9
imv-dir Executable file
View File

@ -0,0 +1,9 @@
#!/bin/bash
image="$1"
declare -a ARGS
for a in "$(dirname "$image")"/*; do
if [ -f "$a" ]; then
ARGS+=("$a")
fi
done
exec imv "${ARGS[@]}" -n "$image"

12
killwine Executable file
View File

@ -0,0 +1,12 @@
#!/bin/sh
killall -9 conhost.exe
killall -9 svchost.exe
killall -9 explorer.exe
killall -9 winedevice.exe
killall -9 plugplay.exe
killall -9 winedevice.exe
killall -9 services.exe
killall -9 wineboot.exe
killall -9 wineserver
killall -9 wine

View File

@ -1,14 +0,0 @@
#!/bin/sh
# First check if lastpass is correctly initialized
if lpass ls 1>/dev/null 2>&1; then
# success
lpass ls | grep --ignore-case $1 | awk '{ if (match($0,/\[id: (.*)?\]/,m)) print m[1] }' | xargs lpass show
# --color=always --format="%ai %au %ap" # unable to use because lpass is buggy with the formatting
else
# failure
echo -n "Enter login name: "
read loginname
lpass login $loginname
fi

19
maintenance/aur-restore.sh Executable file
View File

@ -0,0 +1,19 @@
#!/bin/sh
#REPOSITORY=/home/lanxu/Arch/localrepo
REPOSITORY=/var/cache/pacman/localrepo
# This script restores local aur repository after fuckup with cleaning which
# happens way too often for me
#echo "Creating custom repository..."
#sudo install -d $REPOSITORY -o lanxu
repo-add $REPOSITORY/localrepo.db.tar.gz
aur sync -u
#echo "Retrieving aur packages which are installed..."
#pacman -Qm | cut -f 1 -d " " > aur-packages.txt
echo "Installing..."
xargs -a aur-packages.txt aur sync -n
#echo "Done."

20
powermenu.sh Executable file
View File

@ -0,0 +1,20 @@
#!/usr/bin/env bash
op=$( echo -e " Poweroff\n Reboot\n Suspend\n Lock\n Logout" | wofi -i --dmenu | awk '{print tolower($2)}' )
case $op in
poweroff)
;&
reboot)
;&
suspend)
systemctl $op
;;
lock)
#loginctl lock-session
swaylock -f -c 000000
;;
logout)
swaymsg exit
;;
esac

View File

@ -1,6 +0,0 @@
#!/bin/sh
URI=$1
REALPATH=$(echo "$URI" | sed 's/file\:\/\///g')
export TERMCMD=kitty
notify-send "Opening '$REALPATH'"
kitty -1 ranger '$REALPATH'

View File

@ -1,22 +0,0 @@
#!/bin/bash
if [ $# -eq 0 ]
then
echo "No arguments supplied"
exit -1
fi
WINEDIR=$HOME/Pelit/Wine/$1/
export WINEDEBUG=-all
#export WINEARCH=win32
export WINEPREFIX=$WINEDIR
echo "Run in $WINEDIR"
#if [ $# -eq 1 ]
#then
# wine $2
#fi
shift 1;
exec $@

5
run-xhost Executable file
View File

@ -0,0 +1,5 @@
#!/bin/sh
echo "$@"
xhost +si:lanxu:root
pkexec "$@"
xhost -si:lanxu:root

View File

@ -1,5 +0,0 @@
#!/bin/sh
if [ -z $1 ]; then echo "Search requires search string"; exit 1; fi
grep -Irn "$1" .

View File

@ -10,16 +10,22 @@ export XKB_DEFAULT_MODEL=pc105
# configure wayland backend
export GDK_BACKEND=wayland
export QT_QPA_PLATFORM=wayland # wayland-egl?
export QT_WAYLAND_DISABLE_WINDOWDECORATION=1
export QT_AUTO_SCREEN_SCALE_FACTOR=1
export CLUTTER_BACKEND=wayland
export SDL_VIDEODRIVER=wayland
export EWOL_BACKEND=wayland
# firefox
export MOZ_ENABLE_WAYLAND=1
export MOZ_DBUS_REMOTE=1
# auth
eval $(/usr/bin/gnome-keyring-daemon --start --components=pkcs11,secrets,ssh)
export SSH_AUTH_SOCK
#eval $(/usr/bin/gnome-keyring-daemon --start --components=pkcs11,secrets,ssh)
#export SSH_AUTH_SOCK
# start!
sway
XDG_CURRENT_DESKTOP=sway XDG_SESSION_TYPE=wayland sway
#XDG_CURRENT_DESKTOP=kde XDG_SESSION_TYPE=wayland dbus-run-session startplasma-wayland
#XDG_CURRENT_DESKTOP=gnome XDG_SESSION_TYPE=wayland dbus-run-session gnome-shell --wayland

5
steam Executable file
View File

@ -0,0 +1,5 @@
#!/bin/sh
#XDG_CURRENT_DESKTOP=XFCE xdg-dbus-proxy "$DBUS_SESSION_BUS_ADDRESS" "$XDG_RUNTIME_DIR/steam-bus-proxy" --filter --call="org.freedesktop.DBus.*=*" --call="org.freedesktop.IBus.*=*" --call="org.freedesktop.portal.*=*" --call="com.feralinteractive.GameMode.*=*" --call="com.canonical.*=*" --broadcast="*=*" --call="org.kde.*=*" --call="org.gtk.*=*" &
xdg-dbus-proxy "$DBUS_SESSION_BUS_ADDRESS" "$XDG_RUNTIME_DIR/steam-bus-proxy" --filter --call="org.freedesktop.DBus.*=*" --call="org.freedesktop.IBus.*=*" --call="org.freedesktop.portal.*=*" --call="com.feralinteractive.GameMode.*=*" --call="com.canonical.*=*" --broadcast="*=*" --call="org.kde.*=*" --call="org.gtk.*=*" &
DBUS_SESSION_BUS_ADDRESS="unix:path=$XDG_RUNTIME_DIR/steam-bus-proxy" /usr/bin/steam
kill %1

View File

@ -0,0 +1,6 @@
[Unit]
Description=fullscreen inhibiter for sway
[Service]
Type=oneshot
ExecStart=/bin/sh /home/lanxu/Scripts/sway/fullscreen-inhibiter.sh

10
sway/fullscreen-inhibiter.sh Executable file
View File

@ -0,0 +1,10 @@
#!/bin/sh
# Get all open windows from sway
IN_FULLSCREEN=$(swaymsg -t get_tree | jq '[[recurse(.nodes[]) | del(.nodes)] | .[] | select((.window_properties.class) or (.app_id)) | {app_id: .app_id, class: .window_properties.class, fullscreen_mode: .fullscreen_mode}]' | jq 'any(.fullscreen_mode == 1)')
if [ $IN_FULLSCREEN = "true" ]; then
dunstctl set-paused true
else
dunstctl set-paused false
fi

View File

@ -0,0 +1,9 @@
[Unit]
Description=Fullscreen inhibiter for Sway timer
[Timer]
OnUnitActiveSec=10s
OnBootSec=10s
[Install]
WantedBy=timers.target

13
sway/setup-tablet.sh Executable file
View File

@ -0,0 +1,13 @@
#!/bin/sh
# Get inputs
# swaymsg -t get_inputs
# Get ouputs
# swaymsg -t get_outputs
#PAD_ID="9580:110:HID_256c:006e_Pad"
PAD_ID="9580:110:HID_256c:006e"
OUTPUT="DP-2"
echo "swaymsg 'input $PAD_ID map_to_output $OUTPUT'"
swaymsg 'input '$PAD_ID' map_to_output '$OUTPUT

9
sway/take_screenshot.sh Executable file
View File

@ -0,0 +1,9 @@
#!/bin/sh
MODE=$1
FILENAME=$(xdg-user-dir PICTURES)/$(date +%F_%T_grim.png)
case $MODE in "region-copy") grim -g "$(slurp)" - | wl-copy;;
"region") grim -g "$(slurp)" $FILENAME && notify-send -i "$FILENAME" "Screenshot saved";;
*) grim $FILENAME && notify-send -i "$FILENAME" "Screenshot saved";;
esac

3
sway_lock.sh Executable file
View File

@ -0,0 +1,3 @@
#!/bin/sh
#i3lock -k -i /usr/share/backgrounds/archlinux/wave.png --time-color FFFFFF --date-color FFFFFF --ignore-empty-password --show-failed-attempts -C
swaylock -f -c 000000

6
sway_screensaver.sh Executable file
View File

@ -0,0 +1,6 @@
#!/usr/bin/env bash
swayidle -w \
timeout 30 'swaylock -f -c 000000' \
timeout 60 'swaymsg "output * dpms off"' \
resume 'swaymsg "output * dpms on"' \
before-sleep 'swaylock -f -c 000000'

9
testing/run_zandronum.sh Normal file
View File

@ -0,0 +1,9 @@
docker run -it \
--rm \
-p 10666:10666 \
-v /usr/share/games/doom/:/wads:ro \
--name=zandronum-server \
frozenfoxx/zandronum-server:latest \
-cooperative \
-lan \
-private

3
testing/sheet_process.sh Normal file
View File

@ -0,0 +1,3 @@
mogrify -format png *.tga
rm *.tga
mogrify -crop 256x400+0+0 +repage *.png

100
tools/24-bit-color.sh Normal file
View File

@ -0,0 +1,100 @@
#!/bin/bash
# This file was originally taken from iterm2 https://github.com/gnachman/iTerm2/blob/master/tests/24-bit-color.sh
#
# This file echoes a bunch of 24-bit color codes
# to the terminal to demonstrate its functionality.
# The foreground escape sequence is ^[38;2;<r>;<g>;<b>m
# The background escape sequence is ^[48;2;<r>;<g>;<b>m
# <r> <g> <b> range from 0 to 255 inclusive.
# The escape sequence ^[0m returns output to default
setBackgroundColor()
{
#printf '\x1bPtmux;\x1b\x1b[48;2;%s;%s;%sm' $1 $2 $3
printf '\x1b[48;2;%s;%s;%sm' $1 $2 $3
}
resetOutput()
{
echo -en "\x1b[0m\n"
}
# Gives a color $1/255 % along HSV
# Who knows what happens when $1 is outside 0-255
# Echoes "$red $green $blue" where
# $red $green and $blue are integers
# ranging between 0 and 255 inclusive
rainbowColor()
{
let h=$1/43
let f=$1-43*$h
let t=$f*255/43
let q=255-t
if [ $h -eq 0 ]
then
echo "255 $t 0"
elif [ $h -eq 1 ]
then
echo "$q 255 0"
elif [ $h -eq 2 ]
then
echo "0 255 $t"
elif [ $h -eq 3 ]
then
echo "0 $q 255"
elif [ $h -eq 4 ]
then
echo "$t 0 255"
elif [ $h -eq 5 ]
then
echo "255 0 $q"
else
# execution should never reach here
echo "0 0 0"
fi
}
for i in `seq 0 127`; do
setBackgroundColor $i 0 0
echo -en " "
done
resetOutput
for i in `seq 255 -1 128`; do
setBackgroundColor $i 0 0
echo -en " "
done
resetOutput
for i in `seq 0 127`; do
setBackgroundColor 0 $i 0
echo -n " "
done
resetOutput
for i in `seq 255 -1 128`; do
setBackgroundColor 0 $i 0
echo -n " "
done
resetOutput
for i in `seq 0 127`; do
setBackgroundColor 0 0 $i
echo -n " "
done
resetOutput
for i in `seq 255 -1 128`; do
setBackgroundColor 0 0 $i
echo -n " "
done
resetOutput
for i in `seq 0 127`; do
setBackgroundColor `rainbowColor $i`
echo -n " "
done
resetOutput
for i in `seq 255 -1 128`; do
setBackgroundColor `rainbowColor $i`
echo -n " "
done
resetOutput

119
tools/gif_anim_montage.sh Executable file
View File

@ -0,0 +1,119 @@
#!/bin/sh
#
# gif_anim_montage [options] animation.gif [output_image]
#
# Convert a GIF animation into a strip showing each sub-frame of the
# animation with a black border, positioned in the larger canvas context
# of the animation. Also include a label defining the size and position,
# and disposal setting of each frame in the animation.
#
# OPTIONS:
# -u Underlay a dimmed coaleased image (context for frame)
# -c Add checkerboard background for transparent areas
# -g Use granite for background
# -w Use a white background
# -b Use a black background
# -t image Use this image (or color image) for background
# -r Use a red border color rather than black
# #x# tile the images (default one single row)
# -n Don't label the animation frames (not important)
#
####
#
# WARNING: Input arguments are NOT tested for correctness.
# This script represents a security risk if used ONLINE.
# I accept no responsiblity for misuse. Use at own risk.
#
# Anthony Thyssen Feburary 2006
#
PROGNAME=`type $0 | awk '{print $3}'` # search for executable on path
PROGDIR=`dirname $PROGNAME` # extract directory of program
PROGNAME=`basename $PROGNAME` # base name of program
Usage() { # output the script comments as docs
echo >&2 "$PROGNAME:" "$@"
sed >&2 -n '/^###/q; /^#/!q; s/^#//; s/^ //; 3s/^/Usage: /; 2,$ p' \
"$PROGDIR/$PROGNAME"
exit 10;
}
border=black
thickness=1x1
pointsize=10
tile='-tile x1'
montage_opts=""
method=1
background=none
# Figure out the montage label to use
# Does IM understand %T as the frame time delay?
label='%s: %D\n%wx%h%O'
case `identify -format %T rose:` in
0) label="%D, %Tcs\n%wx%h%O"
esac
while [ $# -gt 0 ]; do
case "$1" in
--help|--doc*) Usage ;;
-u) method=2 ;; # add disposal image context
-n) label='' ;; # don't label the montage
-c) tile_image="pattern:checkerboard" ;;
-g) tile_image="granite:" ;;
-w) background="white" ;;
-b) background="black" ;;
-r) border=red ;;
[0-9]*x*[0-9]|[0-9]*x|x*[0-9])
X=`expr "$1" : '\([0-9]*\)x'`
Y=`expr "$1" : '[0-9]*x\([0-9]*\)$'`
tile="-tile ${X}x${Y}"
;;
-) break ;; # stdin filename
--) shift; break ;; # end of user options
-*) Usage "Unknown option \"$1\"" ;;
*) break ;; # end of user options
esac
shift # next option
done
input="$1"
[ $# -eq 0 ] && Usage "Missing Animation to Montage"
[ $# -eq 1 ] && output='show:'
[ $# -eq 2 ] && output="$2"
[ $# -gt 2 ] && Usage "Too Many Arguments"
if [ "$tile_image" ]; then
montage_opts="$montage_opts -texture $tile_image"
fi
if [ "$background" ]; then
montage_opts="$montage_opts -background $background"
fi
case "$method" in
1) # Montage only method
convert "$input" -set background none -alpha on -set label "$label" \
-compose Copy -bordercolor $border -border $thickness \
-set dispose Background -coalesce miff:- |\
montage - -frame 4 -geometry '+1+1' $tile \
-bordercolor none -pointsize $pointsize \
$montage_opts "$output"
;;
2) # Montage with a disposed image underlay
# Still need some way to make the underlay partically transparent
convert "$input" -set label "$label" -write mpr:a \
-coalesce -bordercolor none -border $thickness \
-channel A -evaluate divide 2 +channel null: \
\( mpr:a -bordercolor none -mattecolor $border -frame $thickness \
\) -layers Composite \
miff:- | \
montage - -frame 4 -geometry '+1+1' $tile \
-bordercolor none -pointsize $pointsize \
$montage_opts "$output"
;;
3) # convert only method -- no montage labels :-(
convert -dispose Background "$input" \
-compose Copy -bordercolor $border -border $thickness \
-compose Over -coalesce -bordercolor none -frame 4x4+1+1 \
-bordercolor none -border 2x2 +append -set delay 0 \
$montage_opts "$output"
esac

81
tools/updateorigin.sh Normal file
View File

@ -0,0 +1,81 @@
#!/bin/bash
PATH32="drive_c/Program Files/Origin"
PATH64="drive_c/Program Files (x86)/Origin"
UPDATEPATH=""
update() {
local DIR="$1"
if which aria2c; then
command="aria2c -x8 -c"
else
command="wget"
fi
echo "Downloading latest Origin setup file:"
if $command "https://download.dm.origin.com/origin/live/OriginSetup.exe"; then
echo "Extracting the installation file:"
unzip OriginSetup.exe 'update/*.zip'
unzip -o ./update/*.zip -d "$DIR"
echo "Cleaning up..."
rm -r ./update
rm OriginSetup.exe
echo "Done!"
fi
}
if [[ ! -z "$WINEPREFIX" ]];
then
# exit if no Origin folder can be found in the WINEPREFIX
if [[ ! -e "$WINEPREFIX/$PATH32" ]] && [[ ! -e "$WINEPREFIX/$PATH64" ]];
then
echo "Origin not found in WINEPREFIX!"
echo "Please run this script again with the correct WINEPREFIX"
echo "or cd to your Origin directory and run the script there."
exit 1
fi
# check which installation of Origin is present. If both are (dunno why), then 64bit is being used
if [[ -e "$WINEPREFIX/$PATH32" ]];
then
UPDATEPATH=$PATH32
echo "Found a 32bit installation of Origin, going to use this:"
fi
if [[ -e "$WINEPREFIX/$PATH64" ]];
then
UPDATEPATH=$PATH64
echo "Found a 64bit installation of Origin, going to use this:"
fi
# ouput the folder, so that the user has confirmation
echo "=> $WINEPREFIX/$UPDATEPATH"
# now we do our magic!
update "$WINEPREFIX/$UPDATEPATH"
exit 0
fi
if [[ -z $WINEPREFIX ]]
then
echo "WINEPREFIX not passed, checking working directory..."
if [[ -w "$PWD/Origin.exe" ]];
then
update "$PWD"
exit 0
fi
if [[ ! -w "$PWD/Origin.exe" ]];
then
echo "Origin.exe not found in working directory!"
echo "Please enter your Origin installation path:"
read -e path
if [[ -w "$path/Origin.exe" ]];
then
update "$path"
fi
if [[ ! -w "$path/Origin.exe" ]];
then
echo "This path does not contain Origin.exe!"
fi
fi
fi

105
tools/vimeo-audio-and-video.py Executable file
View File

@ -0,0 +1,105 @@
#!/usr/bin/env python3
import argparse
import base64
import os
import re
import requests
import subprocess
from tqdm import tqdm
parser = argparse.ArgumentParser()
parser.add_argument('-i', '--url-list', help='List of URL/filename pairs, delimited by tabs')
args = parser.parse_args()
for line in open(args.url_list):
output_file, master_json_url = line.rstrip().split('\t')
print('\n\n\nProcessing %s' % output_file)
# Extract some stuff
base_url = master_json_url[:master_json_url.rfind('/', 0, -26) + 1]
resp = requests.get(master_json_url)
content = resp.json()
# Video download here
heights = [(i, d['height']) for (i, d) in enumerate(content['video'])]
idx = max(heights, key=lambda x: x[1])[0]
video = content['video'][idx]
video_base_url = base_url + content['base_url'] + video['base_url']
print('Base url:', video_base_url)
filenameVideo = 'video_%s.mp4' % video['id']
print('Saving VIDEO to %s' % filenameVideo)
video_file = open(filenameVideo, 'wb')
init_segment = base64.b64decode(video['init_segment'])
video_file.write(init_segment)
for segment in tqdm(video['segments']):
segment_url = video_base_url + segment['url']
print(segment_url + '\n')
print(video_base_url+ '\n')
print(segment['url']+ '\n')
resp = requests.get(segment_url, stream=True)
if resp.status_code != 200:
print('not 200!')
print(resp)
print(segment_url)
break
for chunk in resp:
video_file.write(chunk)
video_file.flush()
video_file.close()
# Audio download here
bitrate = [(i, d['bitrate']) for (i, d) in enumerate(content['audio'])]
print('Bitrate', bitrate)
idx = max(bitrate, key=lambda x: x[1])[0]
audio = content['audio'][idx]
audio_base_url = base_url + content['base_url'] + audio['base_url']
print('Base url:', audio_base_url)
filenameAudio = 'audio_%s.mp4' % audio['id']
print('Saving AUDIO to %s' % filenameAudio)
audio_file = open(filenameAudio, 'wb')
init_segment = base64.b64decode(audio['init_segment'])
audio_file.write(init_segment)
for segment in tqdm(audio['segments']):
segment_url = audio_base_url + segment['url']
segment_url = re.sub(r'/[a-zA-Z0-9_-]*/\.\./',r'/',segment_url.rstrip())
resp = requests.get(segment_url, stream=True)
if resp.status_code != 200:
print('not 200!')
print(resp)
print(segment_url)
break
for chunk in resp:
audio_file.write(chunk)
audio_file.flush()
audio_file.close()
# Combine audio and video here
print('Combining video and audio...')
cmd = 'ffmpeg -y -i '
cmd += filenameAudio
cmd += ' -i '
cmd += filenameVideo
cmd += ' ' + output_file
subprocess.call(cmd, shell=True)
print('Mixing Done!')
# Delete the remaining single audio and video files
# os.remove(filenameAudio)
# os.remove(filenameVideo)
# print("Temporary files removed!")
# Log the conclusion of the operations
print("*** VIDEO DOWNLOADED SUCCESSFULLY ***")
print(video['base_url'])

View File

@ -0,0 +1,4 @@
#!/bin/sh
# First, set flatpak overrides
flatpak override --user --socket=wayland io.freetubeapp.FreeTube