website

My personal website
git clone git://git.ckyln.com/website
Log | Files | Refs

commit e623cfda7de654435c23e46e1892fafaca133303
parent 07b310e2f9d8bf3dc63a1ae0e1f004b0db72f023
Author: Cem Keylan <cem@ckyln.com>
Date:   Fri, 28 Aug 2020 21:22:23 +0300

update

Diffstat:
Mdocs/blog.html | 1+
Mdocs/blog.txt | 1+
Adocs/blog/20200828-wpa-add-script.html | 162+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Adocs/blog/20200828-wpa-add-script.txt | 120+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mdocs/index.html | 120+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mdocs/index.txt | 127+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mdocs/rss.xml | 121++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
Msrc/blog.md | 1+
Asrc/blog/20200828-wpa-add-script.md | 120+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/index.md | 127+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/rss.xml | 121++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
11 files changed, 1019 insertions(+), 2 deletions(-)

diff --git a/docs/blog.html b/docs/blog.html @@ -44,6 +44,7 @@ <h2>Blog Index</h2> <ul> +<li>Aug 28 2020 - <a href="/blog/20200828-wpa-add-script.html">wpa_add script</a></li> <li>Aug 28 2020 - <a href="/blog/20200828-static-linking.html">Static linking</a></li> <li>Aug 12 2020 - <a href="/blog/20200812-starting-x-without-xinit.html">Starting X without Xinit</a></li> <li>May 08 2020 - <a href="/blog/20200508-why-i-dislike-arch-and-gentoo.html">Why I dislike Arch and Gentoo</a></li> diff --git a/docs/blog.txt b/docs/blog.txt @@ -1,6 +1,7 @@ Blog Index -------------------------------------------------------------------------------- +* Aug 28 2020 - [wpa_add script](/blog/20200828-wpa-add-script.html) * Aug 28 2020 - [Static linking](/blog/20200828-static-linking.html) * Aug 12 2020 - [Starting X without Xinit](/blog/20200812-starting-x-without-xinit.html) * May 08 2020 - [Why I dislike Arch and Gentoo](/blog/20200508-why-i-dislike-arch-and-gentoo.html) diff --git a/docs/blog/20200828-wpa-add-script.html b/docs/blog/20200828-wpa-add-script.html @@ -0,0 +1,162 @@ +<!DOCTYPE HTML> +<html lan=en> + <head> + <title>wpa_add script | Cem's Website</title> + <meta charset="utf-8"> + <meta name="Description" content="Cem Keylan's Website"> + <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> + <style> + html {font-family:monospace;font-size:16px;color:#282a36;} + body { + width: 80%; + max-width: 1050px; + margin-left: auto; + margin-right: auto; + margin-top: 20px; + overflow: none; + overflow-y: scroll; + padding-right: 10px; + padding-left: 10px; + } + a{text-decoration:none;font-weight:bold;color:#282a36;} + a:hover{text-decoration:underline;} + @media (prefers-color-scheme: dark) { + html {color: white;background:#282a36;} + a{color:white;} + } + </style> + <link rel="stylesheet" href="/static/syntax.css"> + <script src="/static/highlight.pack.js"></script> + <script>hljs.initHighlightingOnLoad();</script> + </head> + <body> + <div class="header"> + <nav> + | <a href='/'>index</a> | + <a href="/software.html">software</a> | + <a href="//git.ckyln.com">git</a> | + <a href="/blog.html">blog</a> | + <a href="/contact.html">contact</a> | + </nav> + </div> + <hr> + <p> +<h1>wpa_add script</h1> + +<p>I have this script named <code>wpa_add</code>, which I use to easily add new WiFi when I +am outside, possibly in a cafe. I have written this script because I don&rsquo;t like +the way my girlfriend looks at me while thinking that I am an absolute moron for +not using Windows 10, and the entirety of Linux is a circlejerk. It is only +natural that she thinks this way. I use my own distribution that doesn&rsquo;t have +things like <code>dbus</code>, or <code>NetworkManager</code>, or one of those common desktop +environments. You could install it by creating a simple package, but I am happy +to not have any of those in my system.</p> + +<p>This script uses wpa-supplicant to add a new network and reconfigure. It uses +dmenu for input, however you could replace dmenu calls with some command line +prompts. I am doing the following assumptions: +- You can manipulate <code>wpa_supplicant</code> without root access. +- The configuration is on <code>/etc/wpa_supplicant.conf</code>. +- You can edit <code>/etc/wpa/supplicant.conf</code>.</p> + +<p>If you want to ensure the above just do the following (as root):</p> + +<pre><code class="sh"># Add yourself to the wheel group if you aren't already. +adduser user wheel + +# Change the ownership of /etc/wpa_supplicant.conf +chown root:wheel /etc/wpa_supplicant.conf + +# Make sure the configuration can be edited by the wheel group. +chmod 664 /etc/wpa_supplicant.conf +</code></pre> + +<p>Your <code>wpa_supplicant</code> configuration must include the following line (or something similar):</p> + +<pre><code class="plaintext">ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=wheel +</code></pre> + +<p>Here is the script</p> + +<pre><code class="sh">#!/bin/sh +# Script to add wpa_supplicant networks through dmenu + +if [ "$1" ]; then + name=$1 +else + name=$(dmenu -p "Please enter network name, leave empty if you want to search" &lt;&amp;-) +fi + +[ "$name" ] || { + wpa_cli scan + name=$( + wpa_cli scan_results | sed 1,2d | while read -r _ _ _ _ ssid _; do + # Hidden wifi are not to be returned + [ "$ssid" ] || continue + echo "$ssid" + done | sort -u | dmenu -l 10 -p "Please choose WiFi") + [ "$name" ] || exit 1 +} + +pass=$(dmenu -P -p "Please enter your password, leave empty if the network has open access.") + +if [ "$pass" ]; then + wpa_passphrase "$name" &lt;&lt;EOF&gt;&gt; /etc/wpa_supplicant.conf +$pass +EOF +else + printf 'network={\n\tssid="%s"\n\tkey_mgmt=NONE\n\tpriority=-999\n}\n' "$name" &gt;&gt; /etc/wpa_supplicant.conf +fi + +wpa_cli reconfigure +</code></pre> + +<p>As I have said, you could do something similar in a command-line-only tool as +well. This one uses <code>fzf</code> on WiFi selection.</p> + +<pre><code class="sh">#!/bin/sh -e + +stty="$(stty -g)" +trap "stty $stty" EXIT INT TERM HUP + +if [ "$1" ]; then + name=$1 +else + printf 'Network Name, leave empty if you want to search: ' + read -r name +fi + +[ "$name" ] || { + wpa_cli scan &gt;/dev/null + name=$( + wpa_cli scan_results | sed 1,2d | while read -r _ _ _ _ ssid _; do + # Hidden wifi are not to be returned + [ "$ssid" ] || continue + echo "$ssid" + done | sort -u | fzf --prompt "Please choose WiFi: ") +} + +[ "$name" ] || exit 1 + +stty -echo +printf 'Please enter your password, leave empty if the network has open access.\nPassword: ' +read -r pass + +if [ "$pass" ]; then + wpa_passphrase "$name" &lt;&lt;EOF&gt;&gt; /etc/wpa_supplicant.conf +$pass +EOF +else + printf 'network={\n\tssid="%s"\n\tkey_mgmt=NONE\n\tpriority=-999\n}\n' "$name" &gt;&gt; /etc/wpa_supplicant.conf +fi + +wpa_cli reconfigure +</code></pre> + +<p>These scripts can be found as a gist <a href="https://git.io/JULL6">here</a></p> + </p> + <a href="/blog/20200828-wpa-add-script.txt">This page in plain-text</a> + <hr> + <p class=footer>Copyright © 2019-2020 Cem Keylan</p> + </body> +</html> diff --git a/docs/blog/20200828-wpa-add-script.txt b/docs/blog/20200828-wpa-add-script.txt @@ -0,0 +1,120 @@ +wpa_add script +================================================================================ + +I have this script named `wpa_add`, which I use to easily add new WiFi when I +am outside, possibly in a cafe. I have written this script because I don't like +the way my girlfriend looks at me while thinking that I am an absolute moron for +not using Windows 10, and the entirety of Linux is a circlejerk. It is only +natural that she thinks this way. I use my own distribution that doesn't have +things like `dbus`, or `NetworkManager`, or one of those common desktop +environments. You could install it by creating a simple package, but I am happy +to not have any of those in my system. + +This script uses wpa-supplicant to add a new network and reconfigure. It uses +dmenu for input, however you could replace dmenu calls with some command line +prompts. I am doing the following assumptions: +- You can manipulate `wpa_supplicant` without root access. +- The configuration is on `/etc/wpa_supplicant.conf`. +- You can edit `/etc/wpa/supplicant.conf`. + +If you want to ensure the above just do the following (as root): + +```sh +# Add yourself to the wheel group if you aren't already. +adduser user wheel + +# Change the ownership of /etc/wpa_supplicant.conf +chown root:wheel /etc/wpa_supplicant.conf + +# Make sure the configuration can be edited by the wheel group. +chmod 664 /etc/wpa_supplicant.conf +``` + +Your `wpa_supplicant` configuration must include the following line (or something similar): + +```plaintext +ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=wheel +``` + + +Here is the script + +```sh +#!/bin/sh +# Script to add wpa_supplicant networks through dmenu + +if [ "$1" ]; then + name=$1 +else + name=$(dmenu -p "Please enter network name, leave empty if you want to search" <&-) +fi + +[ "$name" ] || { + wpa_cli scan + name=$( + wpa_cli scan_results | sed 1,2d | while read -r _ _ _ _ ssid _; do + # Hidden wifi are not to be returned + [ "$ssid" ] || continue + echo "$ssid" + done | sort -u | dmenu -l 10 -p "Please choose WiFi") + [ "$name" ] || exit 1 +} + +pass=$(dmenu -P -p "Please enter your password, leave empty if the network has open access.") + +if [ "$pass" ]; then + wpa_passphrase "$name" <<EOF>> /etc/wpa_supplicant.conf +$pass +EOF +else + printf 'network={\n\tssid="%s"\n\tkey_mgmt=NONE\n\tpriority=-999\n}\n' "$name" >> /etc/wpa_supplicant.conf +fi + +wpa_cli reconfigure +``` + + +As I have said, you could do something similar in a command-line-only tool as +well. This one uses `fzf` on WiFi selection. + +```sh +#!/bin/sh -e + +stty="$(stty -g)" +trap "stty $stty" EXIT INT TERM HUP + +if [ "$1" ]; then + name=$1 +else + printf 'Network Name, leave empty if you want to search: ' + read -r name +fi + +[ "$name" ] || { + wpa_cli scan >/dev/null + name=$( + wpa_cli scan_results | sed 1,2d | while read -r _ _ _ _ ssid _; do + # Hidden wifi are not to be returned + [ "$ssid" ] || continue + echo "$ssid" + done | sort -u | fzf --prompt "Please choose WiFi: ") +} + +[ "$name" ] || exit 1 + +stty -echo +printf 'Please enter your password, leave empty if the network has open access.\nPassword: ' +read -r pass + +if [ "$pass" ]; then + wpa_passphrase "$name" <<EOF>> /etc/wpa_supplicant.conf +$pass +EOF +else + printf 'network={\n\tssid="%s"\n\tkey_mgmt=NONE\n\tpriority=-999\n}\n' "$name" >> /etc/wpa_supplicant.conf +fi + +wpa_cli reconfigure +``` + +These scripts can be found as a gist [here](https://git.io/JULL6) diff --git a/docs/index.html b/docs/index.html @@ -55,6 +55,126 @@ able to view this site in your favourite pager! In your terminal simply type:</p <hr /> +<h1>wpa_add script</h1> + +<p><a href="/blog/20200828-wpa-add-script.html">Permalink</a></p> + +<p>Date: Aug 28 2020</p> + +<p>I have this script named <code>wpa_add</code>, which I use to easily add new WiFi when I +am outside, possibly in a cafe. I have written this script because I don&rsquo;t like +the way my girlfriend looks at me while thinking that I am an absolute moron for +not using Windows 10, and the entirety of Linux is a circlejerk. It is only +natural that she thinks this way. I use my own distribution that doesn&rsquo;t have +things like <code>dbus</code>, or <code>NetworkManager</code>, or one of those common desktop +environments. You could install it by creating a simple package, but I am happy +to not have any of those in my system.</p> + +<p>This script uses wpa-supplicant to add a new network and reconfigure. It uses +dmenu for input, however you could replace dmenu calls with some command line +prompts. I am doing the following assumptions: +- You can manipulate <code>wpa_supplicant</code> without root access. +- The configuration is on <code>/etc/wpa_supplicant.conf</code>. +- You can edit <code>/etc/wpa/supplicant.conf</code>.</p> + +<p>If you want to ensure the above just do the following (as root):</p> + +<pre><code class="sh"># Add yourself to the wheel group if you aren't already. +adduser user wheel + +# Change the ownership of /etc/wpa_supplicant.conf +chown root:wheel /etc/wpa_supplicant.conf + +# Make sure the configuration can be edited by the wheel group. +chmod 664 /etc/wpa_supplicant.conf +</code></pre> + +<p>Your <code>wpa_supplicant</code> configuration must include the following line (or something similar):</p> + +<pre><code class="plaintext">ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=wheel +</code></pre> + +<p>Here is the script</p> + +<pre><code class="sh">#!/bin/sh +# Script to add wpa_supplicant networks through dmenu + +if [ "$1" ]; then + name=$1 +else + name=$(dmenu -p "Please enter network name, leave empty if you want to search" &lt;&amp;-) +fi + +[ "$name" ] || { + wpa_cli scan + name=$( + wpa_cli scan_results | sed 1,2d | while read -r _ _ _ _ ssid _; do + # Hidden wifi are not to be returned + [ "$ssid" ] || continue + echo "$ssid" + done | sort -u | dmenu -l 10 -p "Please choose WiFi") + [ "$name" ] || exit 1 +} + +pass=$(dmenu -P -p "Please enter your password, leave empty if the network has open access.") + +if [ "$pass" ]; then + wpa_passphrase "$name" &lt;&lt;EOF&gt;&gt; /etc/wpa_supplicant.conf +$pass +EOF +else + printf 'network={\n\tssid="%s"\n\tkey_mgmt=NONE\n\tpriority=-999\n}\n' "$name" &gt;&gt; /etc/wpa_supplicant.conf +fi + +wpa_cli reconfigure +</code></pre> + +<p>As I have said, you could do something similar in a command-line-only tool as +well. This one uses <code>fzf</code> on WiFi selection.</p> + +<pre><code class="sh">#!/bin/sh -e + +stty="$(stty -g)" +trap "stty $stty" EXIT INT TERM HUP + +if [ "$1" ]; then + name=$1 +else + printf 'Network Name, leave empty if you want to search: ' + read -r name +fi + +[ "$name" ] || { + wpa_cli scan &gt;/dev/null + name=$( + wpa_cli scan_results | sed 1,2d | while read -r _ _ _ _ ssid _; do + # Hidden wifi are not to be returned + [ "$ssid" ] || continue + echo "$ssid" + done | sort -u | fzf --prompt "Please choose WiFi: ") +} + +[ "$name" ] || exit 1 + +stty -echo +printf 'Please enter your password, leave empty if the network has open access.\nPassword: ' +read -r pass + +if [ "$pass" ]; then + wpa_passphrase "$name" &lt;&lt;EOF&gt;&gt; /etc/wpa_supplicant.conf +$pass +EOF +else + printf 'network={\n\tssid="%s"\n\tkey_mgmt=NONE\n\tpriority=-999\n}\n' "$name" &gt;&gt; /etc/wpa_supplicant.conf +fi + +wpa_cli reconfigure +</code></pre> + +<p>These scripts can be found as a gist <a href="https://git.io/JULL6">here</a></p> + +<hr /> + <h1>Static linking</h1> <p><a href="/blog/20200828-static-linking.html">Permalink</a></p> diff --git a/docs/index.txt b/docs/index.txt @@ -12,6 +12,133 @@ able to view this site in your favourite pager! In your terminal simply type: ******************************************************************************** +wpa_add script +================================================================================ +[Permalink](/blog/20200828-wpa-add-script.html) + +Date: Aug 28 2020 + + +I have this script named `wpa_add`, which I use to easily add new WiFi when I +am outside, possibly in a cafe. I have written this script because I don't like +the way my girlfriend looks at me while thinking that I am an absolute moron for +not using Windows 10, and the entirety of Linux is a circlejerk. It is only +natural that she thinks this way. I use my own distribution that doesn't have +things like `dbus`, or `NetworkManager`, or one of those common desktop +environments. You could install it by creating a simple package, but I am happy +to not have any of those in my system. + +This script uses wpa-supplicant to add a new network and reconfigure. It uses +dmenu for input, however you could replace dmenu calls with some command line +prompts. I am doing the following assumptions: +- You can manipulate `wpa_supplicant` without root access. +- The configuration is on `/etc/wpa_supplicant.conf`. +- You can edit `/etc/wpa/supplicant.conf`. + +If you want to ensure the above just do the following (as root): + +```sh +# Add yourself to the wheel group if you aren't already. +adduser user wheel + +# Change the ownership of /etc/wpa_supplicant.conf +chown root:wheel /etc/wpa_supplicant.conf + +# Make sure the configuration can be edited by the wheel group. +chmod 664 /etc/wpa_supplicant.conf +``` + +Your `wpa_supplicant` configuration must include the following line (or something similar): + +```plaintext +ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=wheel +``` + + +Here is the script + +```sh +#!/bin/sh +# Script to add wpa_supplicant networks through dmenu + +if [ "$1" ]; then + name=$1 +else + name=$(dmenu -p "Please enter network name, leave empty if you want to search" <&-) +fi + +[ "$name" ] || { + wpa_cli scan + name=$( + wpa_cli scan_results | sed 1,2d | while read -r _ _ _ _ ssid _; do + # Hidden wifi are not to be returned + [ "$ssid" ] || continue + echo "$ssid" + done | sort -u | dmenu -l 10 -p "Please choose WiFi") + [ "$name" ] || exit 1 +} + +pass=$(dmenu -P -p "Please enter your password, leave empty if the network has open access.") + +if [ "$pass" ]; then + wpa_passphrase "$name" <<EOF>> /etc/wpa_supplicant.conf +$pass +EOF +else + printf 'network={\n\tssid="%s"\n\tkey_mgmt=NONE\n\tpriority=-999\n}\n' "$name" >> /etc/wpa_supplicant.conf +fi + +wpa_cli reconfigure +``` + + +As I have said, you could do something similar in a command-line-only tool as +well. This one uses `fzf` on WiFi selection. + +```sh +#!/bin/sh -e + +stty="$(stty -g)" +trap "stty $stty" EXIT INT TERM HUP + +if [ "$1" ]; then + name=$1 +else + printf 'Network Name, leave empty if you want to search: ' + read -r name +fi + +[ "$name" ] || { + wpa_cli scan >/dev/null + name=$( + wpa_cli scan_results | sed 1,2d | while read -r _ _ _ _ ssid _; do + # Hidden wifi are not to be returned + [ "$ssid" ] || continue + echo "$ssid" + done | sort -u | fzf --prompt "Please choose WiFi: ") +} + +[ "$name" ] || exit 1 + +stty -echo +printf 'Please enter your password, leave empty if the network has open access.\nPassword: ' +read -r pass + +if [ "$pass" ]; then + wpa_passphrase "$name" <<EOF>> /etc/wpa_supplicant.conf +$pass +EOF +else + printf 'network={\n\tssid="%s"\n\tkey_mgmt=NONE\n\tpriority=-999\n}\n' "$name" >> /etc/wpa_supplicant.conf +fi + +wpa_cli reconfigure +``` + +These scripts can be found as a gist [here](https://git.io/JULL6) + +******************************************************************************** + Static linking ================================================================================ [Permalink](/blog/20200828-static-linking.html) diff --git a/docs/rss.xml b/docs/rss.xml @@ -9,7 +9,126 @@ <description>Personal blog/website on Linux/tech/nerdy stuff</description> <link>https://cemkeylan.com</link> <atom:link href="https://cemkeylan.com/rss.xml" rel="self" type="application/rss+xml" /> - <lastBuildDate>Fri Aug 28 2020 17:00</lastBuildDate> + <lastBuildDate>Fri Aug 28 2020 18:00</lastBuildDate> +<item> +<title>wpa_add script</title> +<pubDate>Fri, 28 Aug 2020</pubDate> +<dc:creator>Cem Keylan</dc:creator> +<link>https://cemkeylan.com/blog/20200828-wpa-add-script.html</link> +<description>&lt;h1&gt;wpa_add script&lt;/h1&gt; + +&lt;p&gt;I have this script named &lt;code&gt;wpa_add&lt;/code&gt;, which I use to easily add new WiFi when I +am outside, possibly in a cafe. I have written this script because I don&amp;rsquo;t like +the way my girlfriend looks at me while thinking that I am an absolute moron for +not using Windows 10, and the entirety of Linux is a circlejerk. It is only +natural that she thinks this way. I use my own distribution that doesn&amp;rsquo;t have +things like &lt;code&gt;dbus&lt;/code&gt;, or &lt;code&gt;NetworkManager&lt;/code&gt;, or one of those common desktop +environments. You could install it by creating a simple package, but I am happy +to not have any of those in my system.&lt;/p&gt; + +&lt;p&gt;This script uses wpa-supplicant to add a new network and reconfigure. It uses +dmenu for input, however you could replace dmenu calls with some command line +prompts. I am doing the following assumptions: +- You can manipulate &lt;code&gt;wpa_supplicant&lt;/code&gt; without root access. +- The configuration is on &lt;code&gt;/etc/wpa_supplicant.conf&lt;/code&gt;. +- You can edit &lt;code&gt;/etc/wpa/supplicant.conf&lt;/code&gt;.&lt;/p&gt; + +&lt;p&gt;If you want to ensure the above just do the following (as root):&lt;/p&gt; + +&lt;pre&gt;&lt;code class=&quot;sh&quot;&gt;# Add yourself to the wheel group if you aren&apos;t already. +adduser user wheel + +# Change the ownership of /etc/wpa_supplicant.conf +chown root:wheel /etc/wpa_supplicant.conf + +# Make sure the configuration can be edited by the wheel group. +chmod 664 /etc/wpa_supplicant.conf +&lt;/code&gt;&lt;/pre&gt; + +&lt;p&gt;Your &lt;code&gt;wpa_supplicant&lt;/code&gt; configuration must include the following line (or something similar):&lt;/p&gt; + +&lt;pre&gt;&lt;code class=&quot;plaintext&quot;&gt;ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=wheel +&lt;/code&gt;&lt;/pre&gt; + +&lt;p&gt;Here is the script&lt;/p&gt; + +&lt;pre&gt;&lt;code class=&quot;sh&quot;&gt;#!/bin/sh +# Script to add wpa_supplicant networks through dmenu + +if [ &quot;$1&quot; ]; then + name=$1 +else + name=$(dmenu -p &quot;Please enter network name, leave empty if you want to search&quot; &amp;lt;&amp;amp;-) +fi + +[ &quot;$name&quot; ] || { + wpa_cli scan + name=$( + wpa_cli scan_results | sed 1,2d | while read -r _ _ _ _ ssid _; do + # Hidden wifi are not to be returned + [ &quot;$ssid&quot; ] || continue + echo &quot;$ssid&quot; + done | sort -u | dmenu -l 10 -p &quot;Please choose WiFi&quot;) + [ &quot;$name&quot; ] || exit 1 +} + +pass=$(dmenu -P -p &quot;Please enter your password, leave empty if the network has open access.&quot;) + +if [ &quot;$pass&quot; ]; then + wpa_passphrase &quot;$name&quot; &amp;lt;&amp;lt;EOF&amp;gt;&amp;gt; /etc/wpa_supplicant.conf +$pass +EOF +else + printf &apos;network={\n\tssid=&quot;%s&quot;\n\tkey_mgmt=NONE\n\tpriority=-999\n}\n&apos; &quot;$name&quot; &amp;gt;&amp;gt; /etc/wpa_supplicant.conf +fi + +wpa_cli reconfigure +&lt;/code&gt;&lt;/pre&gt; + +&lt;p&gt;As I have said, you could do something similar in a command-line-only tool as +well. This one uses &lt;code&gt;fzf&lt;/code&gt; on WiFi selection.&lt;/p&gt; + +&lt;pre&gt;&lt;code class=&quot;sh&quot;&gt;#!/bin/sh -e + +stty=&quot;$(stty -g)&quot; +trap &quot;stty $stty&quot; EXIT INT TERM HUP + +if [ &quot;$1&quot; ]; then + name=$1 +else + printf &apos;Network Name, leave empty if you want to search: &apos; + read -r name +fi + +[ &quot;$name&quot; ] || { + wpa_cli scan &amp;gt;/dev/null + name=$( + wpa_cli scan_results | sed 1,2d | while read -r _ _ _ _ ssid _; do + # Hidden wifi are not to be returned + [ &quot;$ssid&quot; ] || continue + echo &quot;$ssid&quot; + done | sort -u | fzf --prompt &quot;Please choose WiFi: &quot;) +} + +[ &quot;$name&quot; ] || exit 1 + +stty -echo +printf &apos;Please enter your password, leave empty if the network has open access.\nPassword: &apos; +read -r pass + +if [ &quot;$pass&quot; ]; then + wpa_passphrase &quot;$name&quot; &amp;lt;&amp;lt;EOF&amp;gt;&amp;gt; /etc/wpa_supplicant.conf +$pass +EOF +else + printf &apos;network={\n\tssid=&quot;%s&quot;\n\tkey_mgmt=NONE\n\tpriority=-999\n}\n&apos; &quot;$name&quot; &amp;gt;&amp;gt; /etc/wpa_supplicant.conf +fi + +wpa_cli reconfigure +&lt;/code&gt;&lt;/pre&gt; + +&lt;p&gt;These scripts can be found as a gist &lt;a href=&quot;https://git.io/JULL6&quot;&gt;here&lt;/a&gt;&lt;/p&gt;</description> +</item> <item> <title>Static linking</title> <pubDate>Fri, 28 Aug 2020</pubDate> diff --git a/src/blog.md b/src/blog.md @@ -1,6 +1,7 @@ Blog Index -------------------------------------------------------------------------------- +* Aug 28 2020 - [wpa_add script](/blog/20200828-wpa-add-script.html) * Aug 28 2020 - [Static linking](/blog/20200828-static-linking.html) * Aug 12 2020 - [Starting X without Xinit](/blog/20200812-starting-x-without-xinit.html) * May 08 2020 - [Why I dislike Arch and Gentoo](/blog/20200508-why-i-dislike-arch-and-gentoo.html) diff --git a/src/blog/20200828-wpa-add-script.md b/src/blog/20200828-wpa-add-script.md @@ -0,0 +1,120 @@ +wpa_add script +================================================================================ + +I have this script named `wpa_add`, which I use to easily add new WiFi when I +am outside, possibly in a cafe. I have written this script because I don't like +the way my girlfriend looks at me while thinking that I am an absolute moron for +not using Windows 10, and the entirety of Linux is a circlejerk. It is only +natural that she thinks this way. I use my own distribution that doesn't have +things like `dbus`, or `NetworkManager`, or one of those common desktop +environments. You could install it by creating a simple package, but I am happy +to not have any of those in my system. + +This script uses wpa-supplicant to add a new network and reconfigure. It uses +dmenu for input, however you could replace dmenu calls with some command line +prompts. I am doing the following assumptions: +- You can manipulate `wpa_supplicant` without root access. +- The configuration is on `/etc/wpa_supplicant.conf`. +- You can edit `/etc/wpa/supplicant.conf`. + +If you want to ensure the above just do the following (as root): + +```sh +# Add yourself to the wheel group if you aren't already. +adduser user wheel + +# Change the ownership of /etc/wpa_supplicant.conf +chown root:wheel /etc/wpa_supplicant.conf + +# Make sure the configuration can be edited by the wheel group. +chmod 664 /etc/wpa_supplicant.conf +``` + +Your `wpa_supplicant` configuration must include the following line (or something similar): + +```plaintext +ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=wheel +``` + + +Here is the script + +```sh +#!/bin/sh +# Script to add wpa_supplicant networks through dmenu + +if [ "$1" ]; then + name=$1 +else + name=$(dmenu -p "Please enter network name, leave empty if you want to search" <&-) +fi + +[ "$name" ] || { + wpa_cli scan + name=$( + wpa_cli scan_results | sed 1,2d | while read -r _ _ _ _ ssid _; do + # Hidden wifi are not to be returned + [ "$ssid" ] || continue + echo "$ssid" + done | sort -u | dmenu -l 10 -p "Please choose WiFi") + [ "$name" ] || exit 1 +} + +pass=$(dmenu -P -p "Please enter your password, leave empty if the network has open access.") + +if [ "$pass" ]; then + wpa_passphrase "$name" <<EOF>> /etc/wpa_supplicant.conf +$pass +EOF +else + printf 'network={\n\tssid="%s"\n\tkey_mgmt=NONE\n\tpriority=-999\n}\n' "$name" >> /etc/wpa_supplicant.conf +fi + +wpa_cli reconfigure +``` + + +As I have said, you could do something similar in a command-line-only tool as +well. This one uses `fzf` on WiFi selection. + +```sh +#!/bin/sh -e + +stty="$(stty -g)" +trap "stty $stty" EXIT INT TERM HUP + +if [ "$1" ]; then + name=$1 +else + printf 'Network Name, leave empty if you want to search: ' + read -r name +fi + +[ "$name" ] || { + wpa_cli scan >/dev/null + name=$( + wpa_cli scan_results | sed 1,2d | while read -r _ _ _ _ ssid _; do + # Hidden wifi are not to be returned + [ "$ssid" ] || continue + echo "$ssid" + done | sort -u | fzf --prompt "Please choose WiFi: ") +} + +[ "$name" ] || exit 1 + +stty -echo +printf 'Please enter your password, leave empty if the network has open access.\nPassword: ' +read -r pass + +if [ "$pass" ]; then + wpa_passphrase "$name" <<EOF>> /etc/wpa_supplicant.conf +$pass +EOF +else + printf 'network={\n\tssid="%s"\n\tkey_mgmt=NONE\n\tpriority=-999\n}\n' "$name" >> /etc/wpa_supplicant.conf +fi + +wpa_cli reconfigure +``` + +These scripts can be found as a gist [here](https://git.io/JULL6) diff --git a/src/index.md b/src/index.md @@ -12,6 +12,133 @@ able to view this site in your favourite pager! In your terminal simply type: ******************************************************************************** +wpa_add script +================================================================================ +[Permalink](/blog/20200828-wpa-add-script.html) + +Date: Aug 28 2020 + + +I have this script named `wpa_add`, which I use to easily add new WiFi when I +am outside, possibly in a cafe. I have written this script because I don't like +the way my girlfriend looks at me while thinking that I am an absolute moron for +not using Windows 10, and the entirety of Linux is a circlejerk. It is only +natural that she thinks this way. I use my own distribution that doesn't have +things like `dbus`, or `NetworkManager`, or one of those common desktop +environments. You could install it by creating a simple package, but I am happy +to not have any of those in my system. + +This script uses wpa-supplicant to add a new network and reconfigure. It uses +dmenu for input, however you could replace dmenu calls with some command line +prompts. I am doing the following assumptions: +- You can manipulate `wpa_supplicant` without root access. +- The configuration is on `/etc/wpa_supplicant.conf`. +- You can edit `/etc/wpa/supplicant.conf`. + +If you want to ensure the above just do the following (as root): + +```sh +# Add yourself to the wheel group if you aren't already. +adduser user wheel + +# Change the ownership of /etc/wpa_supplicant.conf +chown root:wheel /etc/wpa_supplicant.conf + +# Make sure the configuration can be edited by the wheel group. +chmod 664 /etc/wpa_supplicant.conf +``` + +Your `wpa_supplicant` configuration must include the following line (or something similar): + +```plaintext +ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=wheel +``` + + +Here is the script + +```sh +#!/bin/sh +# Script to add wpa_supplicant networks through dmenu + +if [ "$1" ]; then + name=$1 +else + name=$(dmenu -p "Please enter network name, leave empty if you want to search" <&-) +fi + +[ "$name" ] || { + wpa_cli scan + name=$( + wpa_cli scan_results | sed 1,2d | while read -r _ _ _ _ ssid _; do + # Hidden wifi are not to be returned + [ "$ssid" ] || continue + echo "$ssid" + done | sort -u | dmenu -l 10 -p "Please choose WiFi") + [ "$name" ] || exit 1 +} + +pass=$(dmenu -P -p "Please enter your password, leave empty if the network has open access.") + +if [ "$pass" ]; then + wpa_passphrase "$name" <<EOF>> /etc/wpa_supplicant.conf +$pass +EOF +else + printf 'network={\n\tssid="%s"\n\tkey_mgmt=NONE\n\tpriority=-999\n}\n' "$name" >> /etc/wpa_supplicant.conf +fi + +wpa_cli reconfigure +``` + + +As I have said, you could do something similar in a command-line-only tool as +well. This one uses `fzf` on WiFi selection. + +```sh +#!/bin/sh -e + +stty="$(stty -g)" +trap "stty $stty" EXIT INT TERM HUP + +if [ "$1" ]; then + name=$1 +else + printf 'Network Name, leave empty if you want to search: ' + read -r name +fi + +[ "$name" ] || { + wpa_cli scan >/dev/null + name=$( + wpa_cli scan_results | sed 1,2d | while read -r _ _ _ _ ssid _; do + # Hidden wifi are not to be returned + [ "$ssid" ] || continue + echo "$ssid" + done | sort -u | fzf --prompt "Please choose WiFi: ") +} + +[ "$name" ] || exit 1 + +stty -echo +printf 'Please enter your password, leave empty if the network has open access.\nPassword: ' +read -r pass + +if [ "$pass" ]; then + wpa_passphrase "$name" <<EOF>> /etc/wpa_supplicant.conf +$pass +EOF +else + printf 'network={\n\tssid="%s"\n\tkey_mgmt=NONE\n\tpriority=-999\n}\n' "$name" >> /etc/wpa_supplicant.conf +fi + +wpa_cli reconfigure +``` + +These scripts can be found as a gist [here](https://git.io/JULL6) + +******************************************************************************** + Static linking ================================================================================ [Permalink](/blog/20200828-static-linking.html) diff --git a/src/rss.xml b/src/rss.xml @@ -9,7 +9,126 @@ <description>Personal blog/website on Linux/tech/nerdy stuff</description> <link>https://cemkeylan.com</link> <atom:link href="https://cemkeylan.com/rss.xml" rel="self" type="application/rss+xml" /> - <lastBuildDate>Fri Aug 28 2020 17:00</lastBuildDate> + <lastBuildDate>Fri Aug 28 2020 18:00</lastBuildDate> +<item> +<title>wpa_add script</title> +<pubDate>Fri, 28 Aug 2020</pubDate> +<dc:creator>Cem Keylan</dc:creator> +<link>https://cemkeylan.com/blog/20200828-wpa-add-script.html</link> +<description>&lt;h1&gt;wpa_add script&lt;/h1&gt; + +&lt;p&gt;I have this script named &lt;code&gt;wpa_add&lt;/code&gt;, which I use to easily add new WiFi when I +am outside, possibly in a cafe. I have written this script because I don&amp;rsquo;t like +the way my girlfriend looks at me while thinking that I am an absolute moron for +not using Windows 10, and the entirety of Linux is a circlejerk. It is only +natural that she thinks this way. I use my own distribution that doesn&amp;rsquo;t have +things like &lt;code&gt;dbus&lt;/code&gt;, or &lt;code&gt;NetworkManager&lt;/code&gt;, or one of those common desktop +environments. You could install it by creating a simple package, but I am happy +to not have any of those in my system.&lt;/p&gt; + +&lt;p&gt;This script uses wpa-supplicant to add a new network and reconfigure. It uses +dmenu for input, however you could replace dmenu calls with some command line +prompts. I am doing the following assumptions: +- You can manipulate &lt;code&gt;wpa_supplicant&lt;/code&gt; without root access. +- The configuration is on &lt;code&gt;/etc/wpa_supplicant.conf&lt;/code&gt;. +- You can edit &lt;code&gt;/etc/wpa/supplicant.conf&lt;/code&gt;.&lt;/p&gt; + +&lt;p&gt;If you want to ensure the above just do the following (as root):&lt;/p&gt; + +&lt;pre&gt;&lt;code class=&quot;sh&quot;&gt;# Add yourself to the wheel group if you aren&apos;t already. +adduser user wheel + +# Change the ownership of /etc/wpa_supplicant.conf +chown root:wheel /etc/wpa_supplicant.conf + +# Make sure the configuration can be edited by the wheel group. +chmod 664 /etc/wpa_supplicant.conf +&lt;/code&gt;&lt;/pre&gt; + +&lt;p&gt;Your &lt;code&gt;wpa_supplicant&lt;/code&gt; configuration must include the following line (or something similar):&lt;/p&gt; + +&lt;pre&gt;&lt;code class=&quot;plaintext&quot;&gt;ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=wheel +&lt;/code&gt;&lt;/pre&gt; + +&lt;p&gt;Here is the script&lt;/p&gt; + +&lt;pre&gt;&lt;code class=&quot;sh&quot;&gt;#!/bin/sh +# Script to add wpa_supplicant networks through dmenu + +if [ &quot;$1&quot; ]; then + name=$1 +else + name=$(dmenu -p &quot;Please enter network name, leave empty if you want to search&quot; &amp;lt;&amp;amp;-) +fi + +[ &quot;$name&quot; ] || { + wpa_cli scan + name=$( + wpa_cli scan_results | sed 1,2d | while read -r _ _ _ _ ssid _; do + # Hidden wifi are not to be returned + [ &quot;$ssid&quot; ] || continue + echo &quot;$ssid&quot; + done | sort -u | dmenu -l 10 -p &quot;Please choose WiFi&quot;) + [ &quot;$name&quot; ] || exit 1 +} + +pass=$(dmenu -P -p &quot;Please enter your password, leave empty if the network has open access.&quot;) + +if [ &quot;$pass&quot; ]; then + wpa_passphrase &quot;$name&quot; &amp;lt;&amp;lt;EOF&amp;gt;&amp;gt; /etc/wpa_supplicant.conf +$pass +EOF +else + printf &apos;network={\n\tssid=&quot;%s&quot;\n\tkey_mgmt=NONE\n\tpriority=-999\n}\n&apos; &quot;$name&quot; &amp;gt;&amp;gt; /etc/wpa_supplicant.conf +fi + +wpa_cli reconfigure +&lt;/code&gt;&lt;/pre&gt; + +&lt;p&gt;As I have said, you could do something similar in a command-line-only tool as +well. This one uses &lt;code&gt;fzf&lt;/code&gt; on WiFi selection.&lt;/p&gt; + +&lt;pre&gt;&lt;code class=&quot;sh&quot;&gt;#!/bin/sh -e + +stty=&quot;$(stty -g)&quot; +trap &quot;stty $stty&quot; EXIT INT TERM HUP + +if [ &quot;$1&quot; ]; then + name=$1 +else + printf &apos;Network Name, leave empty if you want to search: &apos; + read -r name +fi + +[ &quot;$name&quot; ] || { + wpa_cli scan &amp;gt;/dev/null + name=$( + wpa_cli scan_results | sed 1,2d | while read -r _ _ _ _ ssid _; do + # Hidden wifi are not to be returned + [ &quot;$ssid&quot; ] || continue + echo &quot;$ssid&quot; + done | sort -u | fzf --prompt &quot;Please choose WiFi: &quot;) +} + +[ &quot;$name&quot; ] || exit 1 + +stty -echo +printf &apos;Please enter your password, leave empty if the network has open access.\nPassword: &apos; +read -r pass + +if [ &quot;$pass&quot; ]; then + wpa_passphrase &quot;$name&quot; &amp;lt;&amp;lt;EOF&amp;gt;&amp;gt; /etc/wpa_supplicant.conf +$pass +EOF +else + printf &apos;network={\n\tssid=&quot;%s&quot;\n\tkey_mgmt=NONE\n\tpriority=-999\n}\n&apos; &quot;$name&quot; &amp;gt;&amp;gt; /etc/wpa_supplicant.conf +fi + +wpa_cli reconfigure +&lt;/code&gt;&lt;/pre&gt; + +&lt;p&gt;These scripts can be found as a gist &lt;a href=&quot;https://git.io/JULL6&quot;&gt;here&lt;/a&gt;&lt;/p&gt;</description> +</item> <item> <title>Static linking</title> <pubDate>Fri, 28 Aug 2020</pubDate>