Skip to content

Commit

Permalink
refactor: update reset-ssl2
Browse files Browse the repository at this point in the history
  • Loading branch information
flexiondotorg committed Jan 22, 2025
1 parent 174a41d commit a42bf15
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
17 changes: 6 additions & 11 deletions home-manager/_mixins/scripts/reset-ssl2/default.nix
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
{
hostname,
lib,
pkgs,
...
}:
{ pkgs, ... }:
let
installOn = [
"phasma"
"vader"
];
name = builtins.baseNameOf (builtins.toString ./.);
shellApplication = pkgs.writeShellApplication {
inherit name;
runtimeInputs = with pkgs; [
coreutils-full
gnugrep
usb-reset
usbutils
];
text = builtins.readFile ./${name}.sh;
};
in
lib.mkIf (lib.elem hostname installOn) { home.packages = with pkgs; [ shellApplication ]; }
{
home.packages = with pkgs; [ shellApplication ];
}
22 changes: 20 additions & 2 deletions home-manager/_mixins/scripts/reset-ssl2/reset-ssl2.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,26 @@
#!/usr/bin/env bash

VENDOR="31e9"
PRODUCT="0001"
HOST=$(hostnamectl hostname)
case "${HOST}" in
phasma) usb-reset 31e9:0002;;
vader) usb-reset 31e9:0001;;
phasma) PRODUCT="0002";;
*) echo "This script is only meant to be run on phasma or vader";;
esac

sudo true
# If usb-reset is installed, use it
if [ -x "$(command -v usb-reset)" ]; then
sudo usb-reset ${VENDOR}:${PRODUCT}
elif [ -x "$(command -v usbreset)" ]; then
# Get the bus and device number of the SSL 2
SSL2="$(lsusb -d ${VENDOR}: | grep "SSL 2")"
#Bus 001 Device 007: ID 31e9:0001 Solid State Logic SSL 2
#Bus 001 Device 009: ID 31e9:0002 Solid State Logic SSL 2+
BUS="$(echo "${SSL2}" | cut -d' ' -f 2)"
DEV="$(echo "${SSL2}" | cut -d' ' -f 4 | cut -d':' -f 1)"
sudo usbreset ${BUS}/${DEV}
else
echo "ERROR! usb-reset or usbreset is not installed. Please install it."
exit 1
fi

0 comments on commit a42bf15

Please sign in to comment.