add bin scripts

This commit is contained in:
iofq 2023-12-28 21:47:36 -06:00
parent d37834a164
commit 211ba8a0b0
16 changed files with 349 additions and 53 deletions

91
bin/bar.sh Executable file
View file

@ -0,0 +1,91 @@
#!/bin/bash
trap \
"{ pkill -P $$ ; exit 255; }" \
SIGINT SIGTERM ERR EXIT
bat() {
battery=$(cat /sys/class/power_supply/BAT0/capacity)
time=$(cat /tmp/.battime)
drain=$(cat /sys/class/power_supply/BAT0/power_now)
if [[ $(cat /sys/class/power_supply/BAT0/status) == "Charging" ]]; then
echo "$battery%+"
else
echo "$time, $battery%$charge, $(echo "scale=1; $drain / 1000000" | bc)mW"
fi
}
time_date() {
FORMAT="%a %m.%d.%y %T"
DATE=`date "+${FORMAT}"`
echo "${DATE}"
}
mem() {
echo "scale=2; $(free -m | sed -n 2p | awk '{print $3 + $5}') / 1000" | bc
}
vol() {
MUTED=$(amixer get Master | grep off)
amixer get Master | grep -m1 -Po "\d{1,3}%"
[[ $MUTED != '' ]] && echo " M";
}
temp_update() {
TEMP=$(cat /sys/class/thermal/thermal_zone0/temp)
echo $((TEMP / 1000))
}
cpu_update() {
read prevtotal previdle < /tmp/.cpulast
read cpu a b c idle rest < /proc/stat
total=$((a+b+c+idle))
[[ $prevtotal == 0 ]] && prevtotal=1
cpu=$((100*( (total-prevtotal) - (idle-previdle) ) / (total-prevtotal) ))
echo $total $idle > /tmp/.cpulast
echo "$cpu%"
}
calc(){ awk "BEGIN { print "$*" }"; }
mhz_update() {
mhz=$(cat /proc/cpuinfo | grep 'cpu MHz' | awk '{print $4}' | head -n1 | cut -d "." -f 1)
echo "$(calc $mhz/1000 | awk '{ printf "%1.2f\n", $0 }') GHz"
}
update_3() {
while true; do
cpu_update > /tmp/.cpu
temp_update > /tmp/.temp
mhz_update > /tmp/.mhz
sleep 3
done
}
update_30() {
while :; do
awk 'NR==3 {printf("%.0ddB",$4) > "/tmp/.wifi"}' /proc/net/wireless
acpi | awk '{print $5}' > /tmp/.battime
if ping -W 1 -c 1 8.8.8.8 > /dev/null; then
echo "@" > /tmp/.online
else
echo "?" > /tmp/.online
fi
sleep 30
done
}
update_300() {
while :; do
curl -s wttr.in/madison?format=%t | head -c 7 > /tmp/.wttr
sleep 300
done
}
SLEEP_SEC=1
PAD=" | "
update_300 &
update_30 &
update_3 &
while true; do
xsetroot -name "$(mem)G$PAD$(cat /tmp/.cpu)$PAD$(cat /tmp/.mhz)$PAD$(cat /tmp/.temp)°C$PAD$(cat /tmp/.wifi), $(cat /tmp/.online)$PAD$(vol)$PAD$(bat)$PAD$(cat /tmp/.wttr), $(time_date)"
sleep $SLEEP_SEC
done

26
bin/colors.sh Executable file
View file

@ -0,0 +1,26 @@
#!/usr/bin/env bash
# This file echoes a bunch of color codes to the
#terminal to demonstrate what's available. Each
# line is the color code of one forground color,
# out of 17 (default + 16 escapes), followed by a
# test use of that color on all nine background
# colors (default + 8 escapes).
#
T='gYw' # The test text
echo -e "\n 40m 41m 42m 43m\
44m 45m 46m 47m";
for FGs in ' m' ' 1m' ' 30m' '1;30m' ' 31m' '1;31m' ' 32m' \
'1;32m' ' 33m' '1;33m' ' 34m' '1;34m' ' 35m' '1;35m' \
' 36m' '1;36m' ' 37m' '1;37m';
do FG=${FGs// /}
echo -en " $FGs \033[$FG $T "
for BG in 40m 41m 42m 43m 44m 45m 46m 47m;
do echo -en "$EINS \033[$FG\033[$BG $T \033[0m";
done
echo;
done
echo

19
bin/extract Executable file
View file

@ -0,0 +1,19 @@
if [ -f $1 ] ; then
case $1 in
*.tar.bz2) tar xjf $1 ;;
*.tar.xz) tar xf $1 ;;
*.tar.gz) tar xzf $1 ;;
*.bz2) bunzip2 $1 ;;
*.rar) unrar x $1 ;;
*.gz) gunzip $1 ;;
*.tar) tar xf $1 ;;
*.tbz2) tar xjf $1 ;;
*.tgz) tar xzf $1 ;;
*.zip) 7z x $1 ;;
*.Z) uncompress $1;;
*.7z) 7z x $1 ;;
*) echo "'$1' cannot be extracted via extract()" ;;
esac
else
echo "'$1' is not a valid file"
fi

13
bin/kp Executable file
View file

@ -0,0 +1,13 @@
### PROCESS
# mnemonic: [K]ill [P]rocess
# show output of "ps -ef", use [tab] to select one or multiple entries
# press [enter] to kill selected processes and go back to the process list.
# or press [escape] to go back to the process list. Press [escape] twice to exit completely.
pid=$(ps -ef | sed 1d | eval "fzf ${FZF_DEFAULT_OPTS} -m --header='[kill:process]'" | awk '{print $2}')
if [ "x$pid" != "x" ]
then
echo $pid | xargs kill -${1:-9}
kp
fi

9
bin/lc Executable file
View file

@ -0,0 +1,9 @@
#!/bin/bash
# Usage: lc [number_of_cpus_to_load [number_of_seconds] ]
pids=""
cpus=${1:-1}
seconds=${2:-60}
echo loading $cpus CPUs for $seconds seconds
trap 'for p in $pids; do kill $p; done' 0
for ((i=0;i<cpus;i++)); do while : ; do : ; done & pids="$pids $!"; done
sleep $seconds

71
bin/ufetch Executable file
View file

@ -0,0 +1,71 @@
#!/bin/sh
## INFO
host="$(cat /etc/hostname)"
os='Debian 11'
kernel="$(uname -sr)"
uptime="69 days, 4 hours, 20 minutes"
packages="$(apt list --installed 2>/dev/null | wc -l)"
shell="$(basename "$SHELL")"
## UI DETECTION
if [ -n "${DE}" ]; then
ui="${DE}"
uitype='DE'
elif [ -n "${WM}" ]; then
ui="${WM}"
uitype='WM'
elif [ -n "${XDG_CURRENT_DESKTOP}" ]; then
ui="${XDG_CURRENT_DESKTOP}"
uitype='DE'
elif [ -n "${DESKTOP_SESSION}" ]; then
ui="${DESKTOP_SESSION}"
uitype='DE'
elif [ -f "${HOME}/.xinitrc" ]; then
ui="$(tail -n 1 "${HOME}/.xinitrc" | cut -d ' ' -f 2)"
uitype='WM'
elif [ -f "${HOME}/.xsession" ]; then
ui="$(tail -n 1 "${HOME}/.xsession" | cut -d ' ' -f 2)"
uitype='WM'
else
ui='unknown'
uitype='UI'
fi
##hardcode because our .xinitrc doesn't end like exec wm
ui="dwm"
## DEFINE COLORS
# probably don't change these
if [ -x "$(command -v tput)" ]; then
bold="$(tput bold)"
black="$(tput setaf 0)"
red="$(tput setaf 1)"
green="$(tput setaf 2)"
yellow="$(tput setaf 3)"
blue="$(tput setaf 4)"
magenta="$(tput setaf 5)"
cyan="$(tput setaf 6)"
white="$(tput setaf 7)"
reset="$(tput sgr0)"
fi
# you can change these
lc="${reset}${bold}${white}" # labels
nc="${reset}${bold}${white}" # user and hostname
ic="${reset}" # info
c0="${reset}${white}" # first color
## OUTPUT
clear
cat <<EOF
${c0}${nc}${USER}${ic}@${nc}${host}${reset}
------
${c0}${lc}OS: ${ic}${os}${reset}
${c0}${lc}KERNEL: ${ic}${kernel}${reset}
${c0}${lc}UPTIME: ${ic}${uptime}${reset}
${c0}${lc}PACKAGES: ${ic}${packages}${reset}
${c0}${lc}SHELL: ${ic}${shell}${reset}
${c0}${lc}${uitype}: ${ic}${ui}${reset}
EOF

30
flake.lock generated
View file

@ -5,11 +5,11 @@
"systems": "systems"
},
"locked": {
"lastModified": 1681202837,
"narHash": "sha256-H+Rh19JDwRtpVPAWp64F+rlEtxUWBAQW28eAi3SRSzg=",
"lastModified": 1701680307,
"narHash": "sha256-kAuep2h5ajznlPMD9rnQyffWG8EM/C73lejGofXvdM8=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "cfacdce06f30d2b68473a46042957675eebb3401",
"rev": "4022d587cbbfd70fe950c1e2083a02621806a725",
"type": "github"
},
"original": {
@ -25,11 +25,11 @@
]
},
"locked": {
"lastModified": 1701609479,
"narHash": "sha256-mcEnMz7XB3K57ZX16VXoEkswljSNGXdMuUu5+g8a8R8=",
"lastModified": 1703808179,
"narHash": "sha256-svlFDbozZlZJwnnSoeh5yE9jEnCmgmuRMRX866CL4J0=",
"owner": "nix-community",
"repo": "home-manager",
"rev": "e504e8d01f950776c3a3160ba38c5957a1b89e66",
"rev": "77c698fa4b3081b6019ad77d1bfedf06dbbde0db",
"type": "github"
},
"original": {
@ -40,11 +40,11 @@
},
"nixos-hardware": {
"locked": {
"lastModified": 1701598471,
"narHash": "sha256-kHdJ2qc4qKeMTzUIHEcP41ah/dBIhCgvWgrjllt2G78=",
"lastModified": 1703545041,
"narHash": "sha256-nvQA+k1rSszrf4kA4eK2i/SGbzoXyoKHzzyzq/Jca1w=",
"owner": "NixOS",
"repo": "nixos-hardware",
"rev": "a89745edd5f657e2e5be5ed1bea86725ca78d92e",
"rev": "a15b6e525f5737a47b4ce28445c836996fb2ea8c",
"type": "github"
},
"original": {
@ -56,11 +56,11 @@
},
"nixpkgs": {
"locked": {
"lastModified": 1701253981,
"narHash": "sha256-ztaDIyZ7HrTAfEEUt9AtTDNoCYxUdSd6NrRHaYOIxtk=",
"lastModified": 1703438236,
"narHash": "sha256-aqVBq1u09yFhL7bj1/xyUeJjzr92fXVvQSSEx6AdB1M=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "e92039b55bcd58469325ded85d4f58dd5a4eaf58",
"rev": "5f64a12a728902226210bf01d25ec6cbb9d9265b",
"type": "github"
},
"original": {
@ -78,11 +78,11 @@
]
},
"locked": {
"lastModified": 1695262048,
"narHash": "sha256-gLJnpuxRhZjvAkHTPMHXi927lHcDrT8/Lx5xx7lhGt4=",
"lastModified": 1703231060,
"narHash": "sha256-oAiG8DuK+zO9niSSb2qbA0YM6gBlpChM6qoXtuD6e4w=",
"owner": "iofq",
"repo": "nvim.nix",
"rev": "dc80e6953dbad5ad78be591eb7536b1eeb404d79",
"rev": "0c397bd3c752daa6b5e5c27c029723a5ca00ffde",
"type": "github"
},
"original": {

View file

@ -35,7 +35,7 @@
};
in {
nixosConfigurations = (
import ./nixos { inherit inputs pkgs attrs; }
import ./nixos { inherit inputs pkgs attrs system; }
);
homeConfigurations = (
import ./home-manager { inherit inputs pkgs attrs; }

View file

@ -1,4 +1,4 @@
{ inputs, pkgs, ... }:
{ inputs, ... }:
{
programs.home-manager.enable = true;
nix = {
@ -6,6 +6,11 @@
};
home = {
stateVersion = "22.11";
file = {
".local/bin" = {
source = ../bin;
};
};
};
imports = [ ./shared/programs/min.nix ];
xdg.enable = true;

View file

@ -1,4 +1,4 @@
{ pkgs, host, ...}:
{ host, ... }:
{
imports = [
./tmux.nix
@ -20,6 +20,7 @@
sus = "systemctl suspend";
hms = "home-manager switch --flake $NIX_FLAKE#${host.username}";
rbs = "sudo nixos-rebuild switch --flake $NIX_FLAKE#${host.hostName}";
update = "nix flake update $NIX_FLAKE && rbs && hms";
nvim-dev = "nix run ~/dev/nvim.nix";
g = "git";
k = "kubectl";

View file

@ -30,6 +30,15 @@
];
};
programs.ssh = {
enable = true;
matchBlocks = {
"10110110.xyz" = {
hostname = "10110110.xyz";
identityFile = "/home/e/.ssh/racknerd";
};
};
};
fonts.fontconfig.enable = true;
systemd.user.startServices = "sd-switch";
}

View file

@ -1,19 +1,7 @@
{ packages, host, ... }:
{ packages, host, system, ... }:
{
boot.loader.systemd-boot.enable = true;
boot.loader.efi.canTouchEfiVariables = true;
networking.networkmanager.enable = true;
users.groups.plugdev = {}; # Create plugdev group
networking.hostName = host.hostName;
networking.firewall = {
enable = true;
allowedTCPPorts = [11111];
allowedUDPPorts = [];
logRefusedConnections = true;
};
users.users.${host.username} = {
isNormalUser = true;
extraGroups = [
@ -22,7 +10,6 @@
"video"
];
};
security.pam.services.swaylock = {};
time.timeZone = "America/Chicago";
# Enable flakes and unfree packages
@ -35,6 +22,4 @@
dates = "00:00";
options = "--delete-older-than 14d";
};
system.stateVersion = "22.11";
}

View file

@ -1,21 +1,30 @@
{ inputs, ... }:
let
in
{ t14 = inputs.nixpkgs.lib.nixosSystem {
specialArgs = {
inherit inputs;
system = "x86_64-linux";
host = {
hostName = "t14";
username = "e";
};
{ inputs, pkgs, attrs, system, ... }:
{
t14 = inputs.nixpkgs.lib.nixosSystem {
specialArgs = {
inherit inputs system pkgs;
host = {
hostName = "t14";
username = attrs.username;
};
modules = [
./configuration.nix
./t14/configuration.nix
inputs.nixos-hardware.nixosModules.lenovo-thinkpad-t14-amd-gen1
];
};
}
modules = [
./configuration.nix
./t14/configuration.nix
inputs.nixos-hardware.nixosModules.lenovo-thinkpad-t14-amd-gen1
];
};
rknrd = inputs.nixpkgs.lib.nixosSystem {
specialArgs = {
inherit inputs system pkgs;
host = {
hostName = "rknrd";
username = attrs.username;
};
};
modules = [
./configuration.nix
./racknerd/configuration.nix
];
};
}

View file

@ -0,0 +1,37 @@
{ inputs, pkgs, system, ... }: {
imports = [
./hardware-configuration.nix
];
environment.systemPackages = with pkgs; [
nfs-utils
];
boot.tmp.cleanOnBoot = true;
zramSwap.enable = false;
networking.hostName = "rknrd";
networking.domain = "";
networking.firewall = {
enable = true;
allowedTCPPorts = [22];
allowedUDPPorts = [];
logRefusedConnections = true;
};
services.openssh.enable = true;
users.users = {
root = {
openssh.authorizedKeys.keys = [''ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILU2TUxKyGKoZ68IG4hw23RmxVf72u5K9W0StkgTr0b2 e@t14'' ];
};
e = {
isNormalUser = true;
extraGroups = [ "wheel" ];
packages = with pkgs; [
vim
htop
tree
];
openssh.authorizedKeys.keys = [''ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILU2TUxKyGKoZ68IG4hw23RmxVf72u5K9W0StkgTr0b2 e@t14'' ];
};
};
security.sudo.wheelNeedsPassword = false;
nix.settings.trusted-users = ["e"];
system.stateVersion = "22.11";
}

View file

@ -0,0 +1,10 @@
{ config, lib, pkgs, modulesPath, ... }:
{
imports = [ (modulesPath + "/profiles/qemu-guest.nix") ];
nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux";
boot.loader.grub.device = "/dev/vda";
boot.initrd.availableKernelModules = [ "ata_piix" "uhci_hcd" "xen_blkfront" "vmw_pvscsi" ];
boot.initrd.kernelModules = [ "nvme" ];
fileSystems."/" = { device = "/dev/vda1"; fsType = "ext4"; };
swapDevices = [ { device = "/dev/vda2"; } ];
}

View file

@ -5,6 +5,16 @@
./hardware-configuration.nix
./nano.nix
];
boot.loader.systemd-boot.enable = true;
boot.loader.efi.canTouchEfiVariables = true;
networking.networkmanager.enable = true;
networking.firewall = {
enable = true;
allowedTCPPorts = [11111];
allowedUDPPorts = [];
logRefusedConnections = true;
};
environment.systemPackages = with pkgs; [
cryptsetup
nfs-utils
@ -15,6 +25,7 @@
};
programs.light.enable = true;
security.pam.services.swaylock = {};
services.pipewire = {
enable = true;
alsa.enable = true;