From 45bb0d11161b1c5077a1415eed6dbd0fd25ccb6a Mon Sep 17 00:00:00 2001 From: jdlugosz963 Date: Fri, 20 Sep 2024 14:16:56 +0200 Subject: Change dotfiles structure, and add guix-channels declaration. --- files/.bin/arduino-cli | 14 +++ files/.bin/chiaki | 21 ++++ files/.bin/clean.sh | 3 + files/.bin/download_music.sh | 26 +++++ files/.bin/esp_upload.sh | 6 ++ files/.bin/file_upload.sh | 38 +++++++ files/.bin/guix-container | 8 ++ files/.bin/home-reconfigure | 3 + files/.bin/jd-arduino-cli.Dockerfile | 16 +++ files/.bin/mount-nas-abaks | 1 + files/.bin/oath | 14 +++ files/.bin/profile-add-all | 9 ++ files/.bin/stumpish | 196 +++++++++++++++++++++++++++++++++++ files/.bin/system-reconfigure | 3 + files/.bin/update.sh | 4 + files/.bin/whois-at-hsp | 84 +++++++++++++++ 16 files changed, 446 insertions(+) create mode 100755 files/.bin/arduino-cli create mode 100755 files/.bin/chiaki create mode 100755 files/.bin/clean.sh create mode 100755 files/.bin/download_music.sh create mode 100755 files/.bin/esp_upload.sh create mode 100755 files/.bin/file_upload.sh create mode 100755 files/.bin/guix-container create mode 100755 files/.bin/home-reconfigure create mode 100644 files/.bin/jd-arduino-cli.Dockerfile create mode 100755 files/.bin/mount-nas-abaks create mode 100755 files/.bin/oath create mode 100755 files/.bin/profile-add-all create mode 100755 files/.bin/stumpish create mode 100755 files/.bin/system-reconfigure create mode 100755 files/.bin/update.sh create mode 100755 files/.bin/whois-at-hsp (limited to 'files/.bin') diff --git a/files/.bin/arduino-cli b/files/.bin/arduino-cli new file mode 100755 index 0000000..7c0d41a --- /dev/null +++ b/files/.bin/arduino-cli @@ -0,0 +1,14 @@ +#!/bin/sh + +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) + +if [[ $(docker images | grep jd-arduino-cli | wc -l) -eq 0 ]] +then + docker build -f "$SCRIPT_DIR/jd-arduino-cli.Dockerfile" -t jd-arduino-cli . +fi + +docker run --rm --network none -it --privileged \ + -v $(pwd):/src \ + -v jd-arduino-cli-tmp:/tmp \ + -v /dev:/dev jd-arduino-cli \ + arduino-cli $@ diff --git a/files/.bin/chiaki b/files/.bin/chiaki new file mode 100755 index 0000000..5fa6547 --- /dev/null +++ b/files/.bin/chiaki @@ -0,0 +1,21 @@ +#!/bin/sh + +CHIAKI_SHELL=/tmp/.chiaki.nix + +cat < $CHIAKI_SHELL +let + nixgl = import (fetchTarball https://github.com/guibou/nixGL/archive/main.tar.gz) { }; +in +{ nixpkgs ? import {} }: +with nixpkgs; mkShell { + buildInputs = [ + chiaki + nixgl.auto.nixGLDefault + ]; + shellHook = '' + nixGL chiaki && exit; + ''; +} +EOF + +nix-shell $CHIAKI_SHELL diff --git a/files/.bin/clean.sh b/files/.bin/clean.sh new file mode 100755 index 0000000..3e6bbfd --- /dev/null +++ b/files/.bin/clean.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +sudo emerge --ask --depclean; diff --git a/files/.bin/download_music.sh b/files/.bin/download_music.sh new file mode 100755 index 0000000..e3a3601 --- /dev/null +++ b/files/.bin/download_music.sh @@ -0,0 +1,26 @@ +#!/bin/sh + +BOLD="\e[1"; +ENDCOLOR="\e[0m"; +Green="32"; +LightRed="31"; + +if ! [ $1 ]; then + echo "" + echo -e $BOLD";"";"$LightRed"m Please provide music url!"$ENDCOLOR + echo "" + exit +fi + +MUSIC_DIR="~/Documents/Music/%(artist)s/%(album)s/%(title)s-%(id)s.%(ext)s" +if [ $2 ]; then + MUSIC_DIR="${a}/%(artist)s/%(album)s/%(title)s-%(id)s.%(ext)s" +fi + +echo "" +echo -e $BOLD";"";"$Green"m Music will download to ${MUSIC_DIR} directory!"$ENDCOLOR +echo "" + +sleep 1 + +yt-dlp -x --audio-format mp3 --embed-metadata -o $MUSIC_DIR $1 diff --git a/files/.bin/esp_upload.sh b/files/.bin/esp_upload.sh new file mode 100755 index 0000000..27d8d41 --- /dev/null +++ b/files/.bin/esp_upload.sh @@ -0,0 +1,6 @@ +#!/bin/sh + +# rm /tmp/arduino-sketch-*/ -r +~/.local/bin/arduino-cli cache clean +~/.local/bin/arduino-cli compile --fqbn esp8266:esp8266:nodemcuv2 +~/.local/bin/arduino-cli upload -p /dev/ttyUSB0 --fqbn esp8266:esp8266:nodemcuv2 diff --git a/files/.bin/file_upload.sh b/files/.bin/file_upload.sh new file mode 100755 index 0000000..0ff6c57 --- /dev/null +++ b/files/.bin/file_upload.sh @@ -0,0 +1,38 @@ +#!/bin/sh + +BOLD="\e[1"; +ENDCOLOR="\e[0m"; +Green="32m"; +LightRed="31m"; + +echo "" +echo -e $BOLD";"";"$Green" FILE UPLOADER"$ENDCOLOR +echo "" + +if ! [ $1 ]; then + echo "" + echo -e $BOLD";"";"$LightRed" Please provide file path!"$ENDCOLOR + echo "" + exit +fi + +if [ $1 ]; then + echo -e " Are u sure u want upload this file: "$BOLD";"";"$Green" '$1'"$ENDCOLOR"? [y/N]: " + read -p " " input + echo "" + # read -r -p " " input + case $input in + [yY][eE][sS]|[yY]) + URL=$(curl -s -F "file=@$1" https://0x0.st); + echo -e " URL: "$BOLD";"";"$Green"$URL"$ENDCOLOR; + ;; + [nN][oO]|[nN]) + echo -e $BOLD";"";"$Green" OK"$ENDCOLOR; + ;; + *) + echo -e $BOLD";"";"$LightRed" Invalid input..."$ENDCOLOR; + exit 1 + ;; + esac + echo "" +fi; diff --git a/files/.bin/guix-container b/files/.bin/guix-container new file mode 100755 index 0000000..162eda0 --- /dev/null +++ b/files/.bin/guix-container @@ -0,0 +1,8 @@ +#!/bin/sh + +guix shell -C -F -N \ + -E XDG_RUNTIME_DIR=/tmp \ + -E WAYLAND_DISPLAY \ + -E DISPLAY \ + --share=$XDG_RUNTIME_DIR/$WAYLAND_DISPLAY=/tmp/$WAYLAND_DISPLAY \ + $@ coreutils diff --git a/files/.bin/home-reconfigure b/files/.bin/home-reconfigure new file mode 100755 index 0000000..f3a4e5f --- /dev/null +++ b/files/.bin/home-reconfigure @@ -0,0 +1,3 @@ +#!/bin/sh + +JD_HOME=1 guix home -L $HOME/dotfiles/guix reconfigure $HOME/dotfiles/guix/jd/desktops/$(hostname).scm diff --git a/files/.bin/jd-arduino-cli.Dockerfile b/files/.bin/jd-arduino-cli.Dockerfile new file mode 100644 index 0000000..cb8eb91 --- /dev/null +++ b/files/.bin/jd-arduino-cli.Dockerfile @@ -0,0 +1,16 @@ +FROM python:3.12-rc-slim + +RUN apt update && apt install -y wget && \ + wget https://downloads.arduino.cc/arduino-cli/nightly/arduino-cli_nightly-latest_Linux_64bit.tar.gz && \ + tar -C /usr/bin/ -xf arduino-cli_nightly-latest_Linux_64bit.tar.gz + +RUN mkdir ~/.arduino15 && \ + echo "board_manager:" > ~/.arduino15/arduino-cli.yaml && \ + echo " additional_urls:" >> ~/.arduino15/arduino-cli.yaml && \ + echo " - http://arduino.esp8266.com/stable/package_esp8266com_index.json" >> ~/.arduino15/arduino-cli.yaml + + +RUN arduino-cli core update-index && \ + arduino-cli core install esp8266:esp8266 + +WORKDIR /src \ No newline at end of file diff --git a/files/.bin/mount-nas-abaks b/files/.bin/mount-nas-abaks new file mode 100755 index 0000000..6c14817 --- /dev/null +++ b/files/.bin/mount-nas-abaks @@ -0,0 +1 @@ +sudo mount -t cifs -o vers=2.0,username=kdlugosz,password=$(pass nas/abaks/kdlugosz) //195.74.91.28/kdlugosz /mnt \ No newline at end of file diff --git a/files/.bin/oath b/files/.bin/oath new file mode 100755 index 0000000..7444993 --- /dev/null +++ b/files/.bin/oath @@ -0,0 +1,14 @@ +#!/bin/sh + +if [[ $1 ]]; then + PASS=$(oathtool -b --totp $(pass show "oath/$1")) + printf $PASS | wl-copy + echo "pass: $PASS" + echo "Password should be in your clipboard!" +else + echo "Usage: oath " + echo "Available pass:" + pass oath +fi + + diff --git a/files/.bin/profile-add-all b/files/.bin/profile-add-all new file mode 100755 index 0000000..bca4178 --- /dev/null +++ b/files/.bin/profile-add-all @@ -0,0 +1,9 @@ +#!/bin/sh + +GUIX_EXTRA_PROFILES=$HOME/.guix-extra-profiles +for i in $HOME/.config/guix/manifests/*; do + echo $i + MANIFEST_NAME=$(basename $i .scm) + mkdir -p "$GUIX_EXTRA_PROFILES"/"$MANIFEST_NAME" + guix package --manifest=$i --profile="$GUIX_EXTRA_PROFILES/$MANIFEST_NAME/$MANIFEST_NAME" +done diff --git a/files/.bin/stumpish b/files/.bin/stumpish new file mode 100755 index 0000000..9e95c0c --- /dev/null +++ b/files/.bin/stumpish @@ -0,0 +1,196 @@ +#!/bin/sh + +# Copyright (C) 2007 Jonathan Moore Liles +# +# Maintainer: Jonathan Moore Liles +# +# stumpish is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2, or (at your option) +# any later version. +# +# stumpish is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this software; see the file COPYING. If not, see +# . + +### STUMPwm Interactive SHell. + +DELAY=0.01 + +if ! sleep $DELAY 2>/dev/null >&2 +then + DELAY=1 +fi + +# replace -E with -r option for old versions of GNU sed +if ! sed -E 1p /dev/null 2>/dev/null; then + sed() { shift; command sed -r "$@"; } +fi + +# parse C-style backslash sequences by default +if [ "$(echo -e foo)" = foo ]; then + echo() { builtin echo -e "$@"; } +fi + +wait_result () +{ + while true + do + RESULT=$(xprop -root -f STUMPWM_COMMAND_RESULT 8s \ + STUMPWM_COMMAND_RESULT 2>/dev/null | + sed -E 's/\\([[:digit:]]+)/\\0\1/g') + if echo "$RESULT" | grep -v -q 'not found.$' + then + break + fi + + sleep $DELAY + done + + xprop -root -remove STUMPWM_COMMAND_RESULT + + if echo "$RESULT" | grep -q '= $' + then + return 0 + fi + + echo "$RESULT" | + sed -E 's/[^"\\n]+"// + /^"[[:space:]]*$/d + s/(^|[^\\])\\n/\1\ +/g + s/\\(["\\n])/\1/g + s/\^([*[:digit:]]+|[Bbn])//g' +} + +send_cmd () +{ + local cmd="$1" + + if [ "$cmd" = "stumpwm-quit" ] + then + cmd=quit + elif [ "$cmd" = "quit" ] + then + exit + fi + + xprop -root -f STUMPWM_COMMAND 8s -set STUMPWM_COMMAND "$cmd" + + wait_result +} + +usage () +{ + cat <&2 +} + +tput () +{ + local cap1=$1 cap2=$2 + shift 2 + + command tput $cap1 $@ 2>/dev/null || + command tput $cap2 $@ 2>/dev/null +} + +READLINE=yes + +if [ "x$1" = "x-r" ] +then + READLINE=no + shift 1 +fi + +if [ $# -gt 0 ] +then + [ "$1" = "--help" ] && usage + if [ "$1" = "-e" ] + then + if [ $# -ne 2 ] + then + echo "'-e' requires exactly one argument!" + exit + fi + shift 1 + IFS='' + ARGS=$(cat /dev/stdin) + send_cmd "$1 $ARGS" + else + IFS=' ' + send_cmd "$*" + fi +else + if [ -t 0 ] + then + if ! type rlwrap 2>/dev/null >&2 + then + warn rlwrap not found, command completion won\'t work + elif [ $READLINE = yes ] + then + COMMANDS="${TMPDIR:-/tmp}/stumpish.commands.$$" + echo $(send_cmd "commands") | + sed -E 's/[[:space:]]+/\ +/g' | + sort > "$COMMANDS" + trap 'rm -f "$COMMANDS"' exit int term + rlwrap -b '' -f "$COMMANDS" "$0" -r + exit + fi + + tput AF setaf 5 + echo Welcome to the STUMPwm Interactive SHell. + tput me sgr0 + echo 'Type \c' + tput AF setaf 2 + echo 'commands\c' + tput me sgr0 + echo \ for a list of commands. + + while read -p '> ' REPLY + do + tput md bold + tput AF setaf 2 + send_cmd "$REPLY" + tput me sgr0 + done + else + while read REPLY + do + send_cmd "$REPLY" + done + fi +fi diff --git a/files/.bin/system-reconfigure b/files/.bin/system-reconfigure new file mode 100755 index 0000000..c4c1a05 --- /dev/null +++ b/files/.bin/system-reconfigure @@ -0,0 +1,3 @@ +#!/bin/sh + +sudo -E guix system -L $HOME/dotfiles/guix reconfigure $HOME/dotfiles/guix/jd/desktops/$(hostname).scm \ No newline at end of file diff --git a/files/.bin/update.sh b/files/.bin/update.sh new file mode 100755 index 0000000..e6f9f8d --- /dev/null +++ b/files/.bin/update.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +sudo emerge --sync +sudo emerge --ask --verbose --update --newuse --deep @world; diff --git a/files/.bin/whois-at-hsp b/files/.bin/whois-at-hsp new file mode 100755 index 0000000..982a90e --- /dev/null +++ b/files/.bin/whois-at-hsp @@ -0,0 +1,84 @@ +#!/usr/bin/env -S guix shell guile guile-json -- guile --no-auto-compile -e main -s +-*- scheme -*- +!# + +(use-modules (srfi srfi-1) + (ice-9 iconv) + (ice-9 receive) + (web client) + (json)) + +(define whois-at-hsp-endpoint "https://whois.at.hsp.sh/api/now") + +(define (http-get-serialize-json url) + (receive (response data) (http-request url) + (values (json-string->scm (bytevector->string data "UTF-8")) + response))) + +(define (whois-data->users whois-data) + (assoc-ref whois-data "users")) + +(define (whois-data->unknown-devices whois-data) + (assoc-ref whois-data "unknown_devices")) + +(define (whois-data->head-count whois-data) + (assoc-ref whois-data "headcount")) + +(define (whois-data->formated-users whois-data) + (let ((users (vector->list (whois-data->users whois-data)))) + (if (> (length users) 0) + (fold-right + (lambda (a b) (string-append a " " b)) + "" + users) + "No visible users!"))) + +(define (whois-data->summary whois-data) + (string-append + "Unknown devices: " + (number->string (whois-data->unknown-devices whois-data)) + "\nUsers: [" (number->string (whois-data->head-count whois-data)) "] " + (whois-data->formated-users whois-data))) + +(define (notify data) + (system* "notify-send" + "WHOIS AT HSP" + (whois-data->summary data))) + +(define (command-line-option? option args) + (> (length (or (member option args) + '())) + 0)) + +(define-syntax-rule (command-line-args-handle args default ((option ...) body ...) ...) + (let ((option? (lambda (o) (command-line-option? o args)))) + (cond ((or (option? option) ...) body ...) ... + (#t default)))) + +;; (command-line-args-handle '("a" "--help") +;; 0 +;; (("-h" "--help") "dupa")) + +(define (main args) + (let ((whois-data (http-get-serialize-json whois-at-hsp-endpoint))) + (command-line-args-handle args + (begin (display (whois-data->summary whois-data)) + (newline)) + (("-h" "--help") + (display (string-append "-h, --help Help message\n" + "-n, --notify Notification massage with whois information.\n" + "-u Get users\n" + "-H Get head count\n" + "-U Get unknown devices\n"))) + (("-n" "--notify") + (notify whois-data)) + (("-u") + (display (whois-data->formated-users whois-data)) + (newline)) + (("-H") + (display (whois-data->head-count whois-data)) + (newline)) + (("-U") + (display (whois-data->unknown-devices whois-data)) + (newline))))) + -- cgit v1.2.3