diff options
Diffstat (limited to 'stuff/usb-notif-linux.html')
| -rw-r--r-- | stuff/usb-notif-linux.html | 193 |
1 files changed, 116 insertions, 77 deletions
diff --git a/stuff/usb-notif-linux.html b/stuff/usb-notif-linux.html index 4acc27b..2a03886 100644 --- a/stuff/usb-notif-linux.html +++ b/stuff/usb-notif-linux.html @@ -3,138 +3,177 @@ <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> - <title>subh.space</title> + <title>USB Notifications - subh.space</title> <style> + /* Gruvbox Dark Hard Palette */ :root { - --bg0: #282828; - --bg1: #3c3836; + --bg-outer: #1d2021; + --bg-inner: #282828; --fg: #ebdbb2; --gray: #928374; --yellow: #fabd2f; - --green: #b8bb26; - --orange: #fe8019; --aqua: #8ec07c; + --blue: #83a598; + --orange: #fe8019; + --line: #3c3836; } body { - font-family: 'Iosevka Nerd Font Propo'; - line-height: 1.7; + background-color: var(--bg-outer); color: var(--fg); - background-color: var(--bg0); - max-width: 780px; - margin: 40px auto; - padding: 0 20px; - -webkit-font-smoothing: antialiased; + font-family: 'Iosevka Nerd Font Propo'; + margin: 0; + padding: 0; + display: flex; + flex-direction: column; + align-items: center; + min-height: 100vh; + } + + header { + padding: 2.5rem 1rem; + display: flex; + gap: 1.5rem; + justify-content: center; + flex-wrap: wrap; + } + + header a { + color: var(--aqua); + text-decoration: none; + font-weight: bold; + } + + header a:hover { + text-decoration: underline; + } + + .container { + background-color: var(--bg-inner); + width: 90%; + max-width: 750px; + padding: 3rem; + border-radius: 4px; + box-shadow: 0 4px 15px rgba(0,0,0,0.5); } h1 { - font-size: 2.2em; color: var(--yellow); - border-bottom: 2px solid var(--bg1); - padding-bottom: 15px; - margin-bottom: 30px; + font-size: 1.8rem; + margin-top: 0; + margin-bottom: 1rem; + line-height: 1.2; } h2 { - font-size: 1.5em; - color: var(--aqua); - margin-top: 35px; - margin-bottom: 15px; - font-weight: 600; + color: var(--orange); + font-size: 1.3rem; + margin-top: 2rem; + margin-bottom: 0.8rem; } - p { margin-bottom: 1.2em; } + p { + line-height: 1.6; + margin-bottom: 1rem; + } code { - font-family: 'Fira Code', 'JetBrains Mono', 'Courier New', monospace; - background-color: var(--bg1); - color: var(--orange); - padding: 3px 6px; - border-radius: 4px; - font-size: 0.9em; + color: var(--blue); + font-family: 'JetBrains Mono', Courier, monospace; + font-size: 0.95rem; } pre { - background-color: #1d2021; - padding: 20px; - border-radius: 8px; + background-color: var(--bg-outer); + padding: 1.2rem; + border-radius: 4px; + border: 1px solid var(--line); overflow-x: auto; - border: 1px solid var(--bg1); - margin-bottom: 1.5em; + margin: 1.5rem 0; } pre code { - background-color: transparent; - padding: 0; - color: var(--fg); - color-scheme: dark; + color: var(--blue); + font-size: 0.9rem; + white-space: pre; } - ol, ul { margin-bottom: 1.5em; padding-left: 25px; } - li { margin-bottom: 0.8em; } - li pre { margin-top: 10px; margin-bottom: 10px; } + .comment { + color: var(--gray); + } + + .script-label { + color: var(--aqua); + font-weight: bold; + display: block; + margin-top: 1.5rem; + font-size: 0.9rem; + } + footer { + margin: 3rem 0; + color: var(--gray); + font-size: 0.85rem; + text-align: center; + } </style> </head> <body> -<h1>Configuring USB notifications on Linux</h1> - -<p>If you want to receive a small notification as soon as a USB storage device is plugged in or plugged out. You're in the right place</p> - -<p>Your system detects a USB device upon connection or disconnection using an utility named <code>udev</code>. udev allows for defining rules which can allow a user to perform a specific task when a USB device is connected or disconnected. This can be combined with <code>notify-send</code> to send notifications to a user as soon as a USB device is connected or disconnected</p> - -<h2>1. Creating a udev rule</h2> - -<p>Below is a rule file, which will trigger two scripts depending upon the connection or disconnection of a USB device</p> + <header> + <a href="../index.html">home</a> + <a href="https://git.subh.space">git</a> + <a href="https://github.com/5epi0l">github</a> + <a href="https://notes.subh.space">notes</a> + <a href="https://www.hackthebox.com">hackthebox</a> + </header> -<pre><code class="language-shell">ACTION=="add", SUBSYSTEM=="block", ENV{DEVTYPE}=="disk", RUN+="/usr/local/bin/usb-notify-add.sh '$env{ID_MODEL}'" -ACTION=="remove", SUBSYSTEM=="block", ENV{DEVTYPE}=="disk", RUN+="/usr/local/bin/usb-notify-rem.sh '$env{ID_MODEL}'" -</code></pre> + <main class="container"> + <h1>Configuring USB notifications on Linux</h1> + + <p>If you want to receive a small notification as soon as a USB storage device is plugged in or plugged out, you're in the right place.</p> -<p>save this as <code>99-usb-notify.rules</code> file under <code>/etc/udev/rules.d/</code>.</p> + <p>Your system detects a USB device upon connection or disconnection using a utility named <code>udev</code>. It allows for defining rules to perform specific tasks. Combined with <code>notify-send</code>, you can trigger desktop notifications instantly.</p> -<h2>2. Configuring the scripts</h2> + <h2>1. Creating a udev rule</h2> + <p>Save the following as <code>99-usb-notify.rules</code> under <code>/etc/udev/rules.d/</code></p> -<p>Below are the scripts:</p> + <pre><code>ACTION=="add", SUBSYSTEM=="block", ENV{DEVTYPE}=="disk", RUN+="/usr/local/bin/usb-notify-add.sh '$env{ID_MODEL}'" +ACTION=="remove", SUBSYSTEM=="block", ENV{DEVTYPE}=="disk", RUN+="/usr/local/bin/usb-notify-rem.sh '$env{ID_MODEL}'"</code></pre> -<ul> - <li>usb-notify-add.sh</li> -</ul> + <h2>2. Configuring the scripts</h2> + <p>Save both scripts under <code>/usr/local/bin/</code> and make them executable</p> -<pre><code class="language-shell">#!/bin/bash + <span class="script-label">usb-notify-add.sh</span> + <pre><code>#!/bin/bash DEVICE_NAME=${1:-"Unknown USB Device"} USER_ID=$(id -u <your-username>) export DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$USER_ID/bus -sudo -u <your-username> DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS /usr/bin/notify-send "USB Connected" "Device: $DEVICE_NAME" -</code></pre> +sudo -u <your-username> DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS /usr/bin/notify-send "USB Connected" "Device: $DEVICE_NAME"</code></pre> -<ul> - <li>usb-notify-rem.sh</li> -</ul> - -<pre><code class="language-shell">#!/bin/bash + <span class="script-label">usb-notify-rem.sh</span> + <pre><code>#!/bin/bash DEVICE_NAME=${1:-"Unknown USB Device"} USER_ID=$(id -u <your-username>) export DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$USER_ID/bus -sudo -u <your-username> DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS /usr/bin/notify-send "USB Disconnected" "Device: $DEVICE_NAME" -</code></pre> - -<p>Save both the scripts under <code>/usr/local/bin</code> and make them executable with <code>chmod</code></p> +sudo -u <your-username> DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS /usr/bin/notify-send "USB Disconnected" "Device: $DEVICE_NAME"</code></pre> -<h2>3. Reloading the udev rules</h2> + <h2>3. Reloading the udev rules</h2> + <p>Once the files are saved, reload the udev configuration to apply the changes:</p> + <pre><code>sudo udevadm control --reload-rules +sudo udevadm trigger</code></pre> -<p>Once all the files have been saved. Reload udev rules as follows:</p> + <p>And just like that, you've setup USB notifications. Give it a try! Plug in a device and check if your system sends a notification with the device name.</p> + </main> -<pre><code class="language-shell">sudo udevadm control --reload-rules -sudo udevadm trigger -</code></pre> - -<p>And just like that, you've setup USB notifications. Give it a try! Plug in a USB device and check whether your system sends you a notification with the name of the USB device.</p> + <footer> + © 2026 subh.space + </footer> </body> </html> + |
