Compare commits
No commits in common. "c6a602dbda5cb9eee575baee4a381835dd90771e" and "9168b9d13f8135f30d82af8dc258d30742d5303b" have entirely different histories.
c6a602dbda
...
9168b9d13f
13 changed files with 129 additions and 163 deletions
5
bin/deezer
Executable file
5
bin/deezer
Executable file
|
@ -0,0 +1,5 @@
|
|||
#!/bin/sh
|
||||
exec xargs /usr/bin/deezer \
|
||||
"$@" \
|
||||
< ~/.config/electron13-flags.conf
|
||||
|
1
bin/freetube
Symbolic link
1
bin/freetube
Symbolic link
|
@ -0,0 +1 @@
|
|||
waylectron
|
1
bin/heroic
Symbolic link
1
bin/heroic
Symbolic link
|
@ -0,0 +1 @@
|
|||
waylectron
|
15
bin/instvnc
Executable file
15
bin/instvnc
Executable file
|
@ -0,0 +1,15 @@
|
|||
#!/bin/sh -e
|
||||
|
||||
display="$(grep "$LOGNAME" /etc/tigervnc/vncserver.users | head -n 1 | awk -F '=' '{ print $1 }')"
|
||||
echo "Using display: $display"
|
||||
test -n "$display"
|
||||
|
||||
set -x
|
||||
cd
|
||||
exec \
|
||||
screen \
|
||||
-d \
|
||||
-m \
|
||||
vncserver \
|
||||
"$display"
|
||||
|
14
bin/iwqr
14
bin/iwqr
|
@ -1,14 +0,0 @@
|
|||
#!/bin/sh -e
|
||||
|
||||
if [ "$(whoami)" != root ]; then
|
||||
exec sudo "$0" "$@"
|
||||
fi
|
||||
|
||||
cd /var/lib/iwd
|
||||
|
||||
field='Connected network'
|
||||
ssid=$(iwctl station wlan show | grep '^\s*'"${field}"'\s' | xargs | sed "s/^${field} //")
|
||||
unset field
|
||||
passphrase=$(awk -F = '($1 == "'"${1}"'") { print $2 }' "${ssid}.psk")
|
||||
|
||||
qrencode -s 1 -l H -o - "WIFI:T:WPA;S:${ssid};P:${passphrase};;" | catimg -H 0 -
|
8
bin/makeprio
Executable file
8
bin/makeprio
Executable file
|
@ -0,0 +1,8 @@
|
|||
#!/bin/sh -e
|
||||
|
||||
pid="$(pidof "$1")"
|
||||
shift
|
||||
prio="${1:--22}"
|
||||
|
||||
sudo renice "$prio" "$pid"
|
||||
|
57
bin/mcserv
57
bin/mcserv
|
@ -1,24 +1,21 @@
|
|||
#!/bin/bash
|
||||
|
||||
exec_as() {
|
||||
exec_user() {
|
||||
local user="$1"
|
||||
shift
|
||||
if [ "$(whoami)" != "$user" ]; then
|
||||
if [ "$USER" != "$user" ]; then
|
||||
exec sudo -u "$user" "$0" "$@"
|
||||
else
|
||||
cd
|
||||
return 0
|
||||
fi
|
||||
}
|
||||
|
||||
exec_as minecraft "$@" || exit
|
||||
bin=bin
|
||||
PATH="${bin}:${PATH}"
|
||||
EDITOR="${EDITOR:-nvim}"
|
||||
alias ls='ls --color=auto'
|
||||
shopt -s expand_aliases
|
||||
exec_user minecraft "$@"
|
||||
|
||||
cd ~/bin || exit
|
||||
|
||||
print_error() {
|
||||
>&2 printf '\033[31;1mERROR:\033[0m \033[1m%s\033[0m\n' "$*"
|
||||
>&2 printf '\033[31;1m%s\033[0m \033[1m%s\033[0m\n' ERROR: "$*"
|
||||
}
|
||||
|
||||
public_usage() {
|
||||
|
@ -26,8 +23,8 @@ public_usage() {
|
|||
name="$(basename "$0")"
|
||||
cat << EOF
|
||||
${name}: utilisation
|
||||
${name} start|status|stop|watch|restart|edit <nom serveur>
|
||||
${name} list|active|usage|shell
|
||||
${name} start|status|stop|watch|restart NOM_SERVEUR
|
||||
${name} list|active|usage
|
||||
EOF
|
||||
}
|
||||
|
||||
|
@ -39,8 +36,8 @@ error_usage() {
|
|||
|
||||
public_start() {
|
||||
if [ -n "$1" ]; then
|
||||
exec screen -S "$1" \
|
||||
"$1"
|
||||
screen -d -m -S "$1" \
|
||||
"./${1}"
|
||||
else
|
||||
error_usage
|
||||
fi
|
||||
|
@ -61,23 +58,23 @@ public_status() {
|
|||
|
||||
public_stop() {
|
||||
if [ -n "$1" ]; then
|
||||
exec screen -S "$1" -X stuff '^E^Ustop^M'
|
||||
screen -S "$1" -X stuff '^E^Ustop^M'
|
||||
else
|
||||
error_usage
|
||||
fi
|
||||
}
|
||||
|
||||
public_watch() {
|
||||
exec screen -dr "$1"
|
||||
screen -dr "$1"
|
||||
}
|
||||
|
||||
public_active() {
|
||||
exec screen -ls
|
||||
screen -ls
|
||||
}
|
||||
|
||||
public_list() {
|
||||
echo "Serveurs disponibles :"
|
||||
exec ls "$bin"
|
||||
ls --color=auto
|
||||
}
|
||||
|
||||
public_restart() {
|
||||
|
@ -87,21 +84,17 @@ public_restart() {
|
|||
set +e
|
||||
}
|
||||
|
||||
public_edit() {
|
||||
exec "$EDITOR" "${bin}/${1}"
|
||||
}
|
||||
|
||||
public_shell() {
|
||||
exec bash -i
|
||||
}
|
||||
|
||||
verb="$1"
|
||||
shift
|
||||
|
||||
if [ -z "$verb" ]; then
|
||||
public_active
|
||||
elif declare -F | cut -d \ -f 3 | grep '^public_' | sed 's/^public_//' | grep -q "^${verb}$"; then
|
||||
case "$verb" in
|
||||
start|status|stop|watch|active|list|usage|restart)
|
||||
"public_${verb}" "$@"
|
||||
else
|
||||
;;
|
||||
"")
|
||||
public_active
|
||||
;;
|
||||
*)
|
||||
error_usage
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
|
|
53
bin/miam
Executable file
53
bin/miam
Executable file
|
@ -0,0 +1,53 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Functions
|
||||
# Throw
|
||||
function throw {
|
||||
>&2 echo "$1"
|
||||
exit "$2"
|
||||
}
|
||||
|
||||
# Throw a value
|
||||
function throw-value {
|
||||
throw "Invalid value for \"$1\": \"$2\"" "$3"
|
||||
}
|
||||
|
||||
# Variables
|
||||
selection_mode="$1"
|
||||
saving_mode="$2"
|
||||
screenshot_d="/tmp"
|
||||
_command=()
|
||||
|
||||
# Command building
|
||||
_command+=("maim")
|
||||
case "$selection_mode" in
|
||||
"full")
|
||||
:
|
||||
;;
|
||||
"area")
|
||||
_command+=("-s")
|
||||
;;
|
||||
*)
|
||||
throw-value "selection mode" "$selection_mode" 1
|
||||
;;
|
||||
esac
|
||||
case "$saving_mode" in
|
||||
"clip")
|
||||
_command+=("|")
|
||||
_command+=("xclip" "-selection" "clipboard" "-t" "image/png")
|
||||
;;
|
||||
"file")
|
||||
_command+=(">" "${screenshot_d}/$(printf '%s-screenshot-%s.png' "$LOGNAME" "$(date +'%Y_%m_%d_%s')")")
|
||||
;;
|
||||
*)
|
||||
throw-value "saving mode" "$saving_mode" 2
|
||||
;;
|
||||
esac
|
||||
|
||||
# Debug
|
||||
#echo "${_command[@]}"
|
||||
#exit 0
|
||||
|
||||
# Execution
|
||||
"${_command[@]}"
|
||||
|
|
@ -41,7 +41,7 @@ ${name}: usage:
|
|||
${name} start <VM name> - start a VM
|
||||
${name} watch <VM name> - attach VM screen session
|
||||
${name} ls - list available VMs
|
||||
${name} edit <VM name> - edit VM launching script
|
||||
${name} add <VM name> <template> - add launch script based on template
|
||||
${name} rm <VM name> - delete launch script
|
||||
${name} diskls - list available disk images
|
||||
${name} diskadd <disk name> <size> - create a disk image
|
||||
|
|
17
bin/qrconn
Executable file
17
bin/qrconn
Executable file
|
@ -0,0 +1,17 @@
|
|||
#!/bin/sh -e
|
||||
|
||||
if [ "$(whoami)" != root ]; then
|
||||
exec sudo "$0" "$@"
|
||||
fi
|
||||
|
||||
cd "/var/lib/connman/$(connmanctl services | head -n 1 | awk '{ print $NF }')"
|
||||
|
||||
get_var() {
|
||||
awk -F = '($1 == "'"${1}"'") { print $2 }' settings
|
||||
}
|
||||
|
||||
ssid="$(get_var Name)"
|
||||
psk="$(get_var Passphrase)"
|
||||
|
||||
qrencode -s 1 -l H -o - "WIFI:T:WPA;S:${ssid};P:${psk};;" | catimg -H 0 -
|
||||
|
|
@ -4,5 +4,5 @@ exec linux \
|
|||
-device virtio-serial \
|
||||
-chardev spicevmc,id=vdagent,debug=0,name=vdagent \
|
||||
-device virtserialport,chardev=vdagent,name=com.redhat.spice.0 \
|
||||
-spice port="$(first-free-port 5900)",addr=127.0.0.1,disable-ticketing=on \
|
||||
-spice port=5900,addr=127.0.0.1,disable-ticketing=on \
|
||||
"$@"
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#!/bin/sh -x
|
||||
exec windows \
|
||||
-vga qxl \
|
||||
-spice port="$(first-free-port 5900)",addr=127.0.0.1,disable-ticketing=on \
|
||||
-spice port=5900,addr=127.0.0.1,disable-ticketing=on \
|
||||
-chardev spicevmc,id=vdagent,name=vdagent \
|
||||
-device virtserialport,chardev=vdagent,name=com.redhat.spice.0 \
|
||||
"$@"
|
||||
|
|
|
@ -1,113 +0,0 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <fcntl.h>
|
||||
#include <sysexits.h>
|
||||
#include <string.h>
|
||||
|
||||
#define MIN_TCP_PORT 1
|
||||
#define MAX_TCP_PORT 65534
|
||||
#define TCP_TABLE "/proc/net/tcp"
|
||||
#define TCP_TABLE_LINE_LENGTH 151
|
||||
#define LOCALHOST_HEX "0100007F"
|
||||
#define WILDCARD_HEX "00000000"
|
||||
#define LISTENING_HEX "0A"
|
||||
#define PORTS_BLOCKS_TO_ALLOW 4
|
||||
|
||||
/**
|
||||
* Get all the listening TCP ports
|
||||
*/
|
||||
static unsigned short *get_listening_ports(unsigned short *listening_ports, FILE *tcp_table_fptr) {
|
||||
char line[TCP_TABLE_LINE_LENGTH];
|
||||
char delimiter[] = " ";
|
||||
unsigned short len = 0;
|
||||
char *address;
|
||||
char *state;
|
||||
char *field;
|
||||
size_t allowed_for_ports = PORTS_BLOCKS_TO_ALLOW;
|
||||
|
||||
// Skip first line (header)
|
||||
fgets(line, sizeof(line), tcp_table_fptr);
|
||||
|
||||
// Tokenize lines one by one
|
||||
while (fgets(line, sizeof(line), tcp_table_fptr) != NULL) {
|
||||
strtok(line, delimiter);
|
||||
|
||||
address = strtok(NULL, delimiter);
|
||||
strtok(NULL, delimiter);
|
||||
state = strtok(NULL, delimiter);
|
||||
field = strtok(NULL, delimiter);
|
||||
|
||||
while (field != NULL) {
|
||||
field = strtok(NULL, delimiter);
|
||||
}
|
||||
|
||||
if ((!strncmp(address, LOCALHOST_HEX, 8) || !strncmp(address, WILDCARD_HEX, 8)) && !strncmp(state, LISTENING_HEX, 2)) {
|
||||
if (len == allowed_for_ports) {
|
||||
allowed_for_ports = allowed_for_ports + PORTS_BLOCKS_TO_ALLOW;
|
||||
listening_ports = realloc(listening_ports, allowed_for_ports * sizeof(unsigned short));
|
||||
}
|
||||
listening_ports[len] = strtol(address + strlen(address) - 4, NULL, 16);
|
||||
len++;
|
||||
}
|
||||
}
|
||||
|
||||
if (len == allowed_for_ports) {
|
||||
allowed_for_ports = allowed_for_ports + PORTS_BLOCKS_TO_ALLOW;
|
||||
listening_ports = realloc(listening_ports, allowed_for_ports * sizeof(unsigned short));
|
||||
}
|
||||
listening_ports[len] = 0;
|
||||
|
||||
return listening_ports;
|
||||
}
|
||||
|
||||
static unsigned char is_port_available(const unsigned short port, const unsigned short *listening_ports) {
|
||||
unsigned short i = 0;
|
||||
while (listening_ports[i] != 0 && listening_ports[i] != port) {
|
||||
i++;
|
||||
}
|
||||
return listening_ports[i] == 0;
|
||||
}
|
||||
|
||||
static unsigned char is_valid_tcp_port(unsigned short tcp_port) {
|
||||
return tcp_port >= MIN_TCP_PORT && tcp_port <= MAX_TCP_PORT;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
unsigned short current_port;
|
||||
|
||||
if (argc >= 2) {
|
||||
current_port = atoi(argv[1]);
|
||||
} else {
|
||||
current_port = 0;
|
||||
}
|
||||
|
||||
if (!is_valid_tcp_port(current_port)) {
|
||||
fprintf(stderr, "Provide a valid TCP port number as first argument.\n");
|
||||
return EX_USAGE;
|
||||
}
|
||||
|
||||
// Open TCP table
|
||||
FILE *tcp_table_fptr = fopen(TCP_TABLE, "r");
|
||||
if (tcp_table_fptr == NULL) {
|
||||
fprintf(stderr, "Error opening the TCP table.\n");
|
||||
return EX_OSFILE;
|
||||
}
|
||||
|
||||
unsigned short *listening_ports = malloc(PORTS_BLOCKS_TO_ALLOW * sizeof(unsigned short));
|
||||
listening_ports = get_listening_ports(listening_ports, tcp_table_fptr);
|
||||
|
||||
// Check if the current port is available, add
|
||||
while (!is_port_available(current_port, listening_ports)) {
|
||||
current_port++;
|
||||
}
|
||||
|
||||
free(listening_ports);
|
||||
|
||||
if (is_valid_tcp_port(current_port)) {
|
||||
printf("%d\n", current_port);
|
||||
return EXIT_SUCCESS;
|
||||
} else {
|
||||
fprintf(stderr, "No more ports available. How did you fuck up that bad ???\n");
|
||||
return EX_TEMPFAIL;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue