From 4b73d6cdf02ba0a3ccfc029767fa3e6d7d29c715 Mon Sep 17 00:00:00 2001 From: MrGeorgen Date: Wed, 9 Dec 2020 17:35:53 +0100 Subject: [PATCH] first commit --- epic-download | 4 + kernel-build | 7 ++ md | 12 +++ nvim.c | 29 +++++++ open_with_linux.py | 186 +++++++++++++++++++++++++++++++++++++++++++++ syslinux-mkconfig | 23 ++++++ update | 5 ++ upload | 8 ++ 8 files changed, 274 insertions(+) create mode 100755 epic-download create mode 100755 kernel-build create mode 100755 md create mode 100644 nvim.c create mode 100755 open_with_linux.py create mode 100755 syslinux-mkconfig create mode 100755 update create mode 100755 upload diff --git a/epic-download b/epic-download new file mode 100755 index 0000000..43c8739 --- /dev/null +++ b/epic-download @@ -0,0 +1,4 @@ +#!/bin/bash +game="$(legendary list-games |grep "$1" |awk '{for (I=1;I<=NF;I++) if ($I == "(App" && $(I+1) == "name:") {print $(I+2)};}')" +legendary install "$game" +echo -e "[Desktop Entry]\nName=$1\nExec=legendary launch $game" > ~/.local/share/applications/"$1".desktop diff --git a/kernel-build b/kernel-build new file mode 100755 index 0000000..51a4375 --- /dev/null +++ b/kernel-build @@ -0,0 +1,7 @@ +#!/bin/sh +make -j12 +make modules_prepare +make install +make modules_install +eclean-kernel -n 3 +syslinux-mkconfig diff --git a/md b/md new file mode 100755 index 0000000..83c5767 --- /dev/null +++ b/md @@ -0,0 +1,12 @@ +#!/bin/bash +cd ~/Musik/2020 +file_name="$(youtube-dl "ytsearch:$1 lyrics" \ + --extract-audio \ + --output '%(title)s.%(ext)s' \ + --metadata-from-title "%(artist)s - %(title)s" \ + --audio-quality 0 \ + --audio-format mp3 \ + --embed-thumbnail \ + --add-metadata \ + |awk '$1 == "[ffmpeg]" && $2 == "Destination:" {print substr($0, index($0,$3))}')" +r128gain "$file_name" diff --git a/nvim.c b/nvim.c new file mode 100644 index 0000000..d5d2214 --- /dev/null +++ b/nvim.c @@ -0,0 +1,29 @@ +#include +#include +#include +#include +int main(int argc, char **argv) { + char **execargv = malloc((argc + 2) * sizeof *execargv); + for(int i = 1; i < argc; ++i) { + char **arg = &execargv[i+ 2]; + if(argv[i][0] == '/') { + const char *home = "/home/"; + if(!memcmp(home, argv[i], strlen(home))){ + *arg = argv[i]; + goto exec; + } + const char *gentooPath = "/bedrock/strata/gentoo"; + *arg = malloc(strlen(gentooPath) + strlen(argv[i]) + 2); + strcpy(*arg, gentooPath); + strcat(*arg, argv[i]); + printf("Path: %s\n", *arg); + } + else *arg = argv[i]; + } +exec: + execargv[0] = "strat"; + execargv[1] = "arch"; + execargv[2] = "/usr/bin/nvim"; + execargv[argc + 2] = NULL; + execvp(execargv[0], execargv); +} diff --git a/open_with_linux.py b/open_with_linux.py new file mode 100755 index 0000000..6a4f979 --- /dev/null +++ b/open_with_linux.py @@ -0,0 +1,186 @@ +#!/usr/bin/env python +from __future__ import print_function + +import os +import sys +import json +import struct +import subprocess + +VERSION = '7.2.2' + +try: + sys.stdin.buffer + + # Python 3.x version + # Read a message from stdin and decode it. + def getMessage(): + rawLength = sys.stdin.buffer.read(4) + if len(rawLength) == 0: + sys.exit(0) + messageLength = struct.unpack('@I', rawLength)[0] + message = sys.stdin.buffer.read(messageLength).decode('utf-8') + return json.loads(message) + + # Send an encoded message to stdout + def sendMessage(messageContent): + encodedContent = json.dumps(messageContent).encode('utf-8') + encodedLength = struct.pack('@I', len(encodedContent)) + + sys.stdout.buffer.write(encodedLength) + sys.stdout.buffer.write(encodedContent) + sys.stdout.buffer.flush() + +except AttributeError: + # Python 2.x version (if sys.stdin.buffer is not defined) + # Read a message from stdin and decode it. + def getMessage(): + rawLength = sys.stdin.read(4) + if len(rawLength) == 0: + sys.exit(0) + messageLength = struct.unpack('@I', rawLength)[0] + message = sys.stdin.read(messageLength) + return json.loads(message) + + # Send an encoded message to stdout + def sendMessage(messageContent): + encodedContent = json.dumps(messageContent) + encodedLength = struct.pack('@I', len(encodedContent)) + + sys.stdout.write(encodedLength) + sys.stdout.write(encodedContent) + sys.stdout.flush() + + +def install(): + home_path = os.getenv('HOME') + + manifest = { + 'name': 'open_with', + 'description': 'Open With native host', + 'path': os.path.realpath(__file__), + 'type': 'stdio', + } + locations = { + 'chrome': os.path.join(home_path, '.config', 'google-chrome', 'NativeMessagingHosts'), + 'chrome-beta': os.path.join(home_path, '.config', 'google-chrome-beta', 'NativeMessagingHosts'), + 'chrome-unstable': os.path.join(home_path, '.config', 'google-chrome-unstable', 'NativeMessagingHosts'), + 'chromium': os.path.join(home_path, '.config', 'chromium', 'NativeMessagingHosts'), + 'firefox': os.path.join(home_path, '.mozilla', 'native-messaging-hosts'), + } + filename = 'open_with.json' + + for browser, location in locations.items(): + if os.path.exists(os.path.dirname(location)): + if not os.path.exists(location): + os.mkdir(location) + + browser_manifest = manifest.copy() + if browser == 'firefox': + browser_manifest['allowed_extensions'] = ['openwith@darktrojan.net'] + else: + browser_manifest['allowed_origins'] = [ + 'chrome-extension://cogjlncmljjnjpbgppagklanlcbchlno/', # Chrome + 'chrome-extension://fbmcaggceafhobjkhnaakhgfmdaadhhg/', # Opera + ] + + with open(os.path.join(location, filename), 'w') as file: + file.write( + json.dumps(browser_manifest, indent=2, separators=(',', ': '), sort_keys=True).replace(' ', '\t') + '\n' + ) + + +def _read_desktop_file(path): + with open(path, 'r') as desktop_file: + current_section = None + name = None + command = None + for line in desktop_file: + if line[0] == '[': + current_section = line[1:-2] + if current_section != 'Desktop Entry': + continue + + if line.startswith('Name='): + name = line[5:].strip() + elif line.startswith('Exec='): + command = line[5:].strip() + + return { + 'name': name, + 'command': command + } + + +def find_browsers(): + apps = [ + 'Chrome', + 'Chromium', + 'chromium-browser', + 'firefox', + 'Firefox', + 'Google Chrome', + 'google-chrome', + 'opera', + 'Opera', + 'SeaMonkey', + 'seamonkey', + ] + paths = [ + os.path.join(os.getenv('HOME'), '.local/share/applications'), + '/usr/local/share/applications', + '/usr/share/applications' + ] + suffix = '.desktop' + + results = [] + for p in paths: + for a in apps: + fp = os.path.join(p, a) + suffix + if os.path.exists(fp): + results.append(_read_desktop_file(fp)) + return results + + +def listen(): + receivedMessage = getMessage() + if receivedMessage == 'ping': + sendMessage({ + 'version': VERSION, + 'file': os.path.realpath(__file__) + }) + elif receivedMessage == 'find': + sendMessage(find_browsers()) + else: + for k, v in os.environ.items(): + if k.startswith('MOZ_'): + try: + os.unsetenv(k) + except: + os.environ[k] = '' + + devnull = open(os.devnull, 'w') + subprocess.Popen(receivedMessage, stdout=devnull, stderr=devnull) + sendMessage(None) + + +if __name__ == '__main__': + if len(sys.argv) == 2: + if sys.argv[1] == 'install': + install() + sys.exit(0) + elif sys.argv[1] == 'find_browsers': + print(find_browsers()) + sys.exit(0) + + allowed_extensions = [ + 'openwith@darktrojan.net', + 'chrome-extension://cogjlncmljjnjpbgppagklanlcbchlno/', + 'chrome-extension://fbmcaggceafhobjkhnaakhgfmdaadhhg/', + ] + for ae in allowed_extensions: + if ae in sys.argv: + listen() + sys.exit(0) + + print('Open With native helper, version %s.' % VERSION) diff --git a/syslinux-mkconfig b/syslinux-mkconfig new file mode 100755 index 0000000..a82a746 --- /dev/null +++ b/syslinux-mkconfig @@ -0,0 +1,23 @@ +#!/usr/bin/python +from distutils.version import LooseVersion +import glob +import os +syslinuxCfgPath = "/boot/EFI/syslinux/syslinux.cfg" +options = "APPEND root=PARTUUID=6ce9f430-9a06-d64f-ad4e-806594365431 rootflags=subvol=bedrock" +baseName = "bedrock" +os.chdir("/boot") +lv = [LooseVersion(v) for v in glob.iglob("vmlinuz-*")] +lv.sort() +lv.reverse() +for i in range(len(lv)): + if i + 1 < len(lv) and str(lv[i]).replace(".old", "") == str(lv[i + 1]): + cache = lv[i] + lv[i] = lv[i + 1] + lv[i + 1] = cache + versionName = baseName + "/" + str(lv[i]) + if i == 0: + config = "ONTIMEOUT " + versionName + "\nTIMEOUT 10\nUI vesamenu.c32\nMENU TITLE Boot bedrock\nMENU RESOLUTION 1920 1080" + config = config + "\nLABEL " + versionName + "\nMENU LABEL " + versionName + "\nLINUX /" + str(lv[i]) + "\n" + options +syslinuxCfg = open(syslinuxCfgPath, "w") +syslinuxCfg.write(config) +syslinuxCfg.close diff --git a/update b/update new file mode 100755 index 0000000..67f160a --- /dev/null +++ b/update @@ -0,0 +1,5 @@ +#!/bin/sh +emerge --sync +emerge -Du --with-bdeps=y @world +xbps-install -Su +sudo -u mrgeorgen yay diff --git a/upload b/upload new file mode 100755 index 0000000..8a49c91 --- /dev/null +++ b/upload @@ -0,0 +1,8 @@ +#!/bin/bash +url="https://share.redstoneunion.de" +dataDir="/var/www/share" +sshargs="natur" +dirname=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 32) +ssh "$sshargs" mkdir "$dataDir/$dirname" +scp "$1" "$sshargs:$dataDir/$dirname" +echo -n "$url/$dirname/$(basename "$1")" | xclip -sel clip