<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0"
     xmlns:content="http://purl.org/rss/1.0/modules/content/"
     xmlns:dc="http://purl.org/dc/elements/1.1/"
     xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>cleberg.net</title>
    <atom:link href="https://cleberg.net/feed.xml" rel="self" type="application/rss+xml" />
    <link>https://cleberg.net/</link>
    <description>Stillness amidst the chaos.</description>
    <language>en</language>
    <webMaster>hello@cleberg.net (Christian Cleberg)</webMaster>
    <item>
      <title>detour #001: Squirrel Cage Jail</title>
      <link>https://cleberg.net/blog/detour-001-squirrel-cage-jail.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/detour-001-squirrel-cage-jail.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Wed, 28 Oct 2026 00:00:00 +0000</pubDate>
      <category>detour</category>
      <description><![CDATA[<div class="detour">
<dl>
<dt>Location</dt>
<dd>Council Bluffs, IA · <a href="https://www.openstreetmap.org/node/367085605#map=19/41.257791/-95.851927">map</a></dd>
<dt>Admission</dt>
<dd>$10 adults, $8 seniors/students, $5 youth (as of 2026-10)</dd>
<dt>Hours</dt>
<dd>Thu–Sat 10am–5pm, Sun 1pm–4pm; check the <a href="https://www.thehistoricalsociety.org">official site</a></dd>
<dt>Visited</dt>
<dd>2026-07</dd>
<dt>Worth the drive</dt>
<dd>★★★☆☆ (3/5)</dd>
</dl>
</div>
<p>Part of <a href="/detour/">detour</a>, a series on places worth leaving the highway for.</p>
<h2 id="overview"><span class="section-number-2">1.</span> Overview</h2>
<p>Just across the Missouri River from Omaha, in downtown Council Bluffs, sits the Pottawattamie County Squirrel Cage Jail. It was built in 1885, held prisoners until 1969, and is the only three-story rotary jail ever made. Only three rotary jails survive today: this one, a one-story jail in Gallatin, Missouri, and a two-story jail in Crawfordsville, Indiana. The Historical Society of Pottawattamie County now runs the Council Bluffs jail as a museum.</p>
<p>If you've never heard of a rotary jail, the idea is simple and a little absurd. William H. Brown and Benjamin F. Haugh patented the design in 1881: instead of lining cells up along a corridor, you put the inmates in pie-shaped cells inside a large iron drum and spin it. Each floor has a single opening, and the jailer turns a hand crank until the cell he wants lines up with it. That way, one guard can control every prisoner in the building without ever stepping into the cellblock. The drum in Council Bluffs holds three tiers of ten cells each and weighs about forty-five tons.</p>
<figure><img src="https://img.cleberg.net/blog/20261028-detour-001-squirrel-cage-jail/jail-model.webp" alt="An acrylic model and patent schematic showing the pie-shaped cells arranged in a circle around a central spindle inside the octagonal outer cage"><figcaption><span class="figure-number">Figure 1: </span>Model and floor plan of the rotary jail</figcaption></figure>
<p>It didn't take long for the problems to show up. Any inmate with an arm or leg through the bars while the drum turned would have it crushed against the outer cage, and some inmates started doing it on purpose. A broken arm got you moved to the infirmary, and the infirmary only had a wooden ceiling between you and the outside, so a few of them broke through it and shimmied down the drainpipes to escape.</p>
<p>Over the years, the weight of the drum caused the central bearings and shafts to sag until the crank was nearly impossible to turn. Fire was an even bigger worry, since the only way to get everyone out was to rotate the drum one cell at a time past the single exit.</p>
<h2 id="the-experience"><span class="section-number-2">2.</span> The Experience</h2>
<p>From the outside, 226 Pearl Street looks like any other Victorian brick building downtown. You walk in through the booking room, and right away you're standing next to the jail's only solitary cell. It isn't really a room at all - it's the gap between two steel doors that separate the booking room from a narrow hallway. Once both doors were shut, the inmate had a solid steel door at their back and a barred one in front of them, with barely enough space for a modern adult to fit. You can't sit down in there, and you can hardly bend your knees.</p>
<figure><img src="https://img.cleberg.net/blog/20261028-detour-001-squirrel-cage-jail/corridor.webp" alt="A narrow, dim steel hallway lit by hanging incandescent bulbs, with a barred steel door on the left and vertical iron bars on the right"><figcaption><span class="figure-number">Figure 2: </span>The solitary confinement corridor</figcaption></figure>
<p>The hallway on the other side runs straight into the first-floor cell area. It was a shortcut, letting jailers get a rowdy inmate locked up quickly without going through all the normal cell doors.</p>
<p>Once you're in the cell room, the drum takes up most of the space. The hand crank and gears that turned it are still on the first floor, and it's hard to picture one person moving all of that iron by hand. The cells are narrow wedges that shrink toward the center, and standing in one, there isn't a single parallel wall or a window in sight.</p>
<figure><img src="https://img.cleberg.net/blog/20261028-detour-001-squirrel-cage-jail/pie-cell.webp" alt="Interior of a pie-slice cell through iron bars, showing narrow tapering steel walls, two bunk beds, and a single ceiling bulb"><figcaption><span class="figure-number">Figure 3: </span>Inside a wedge-shaped cell</figcaption></figure>
<p>Make sure to look up while you're in there. The steel ceiling is covered in names and dates that inmates scratched and painted over the decades, and it's all still there.</p>
<figure><img src="https://img.cleberg.net/blog/20261028-detour-001-squirrel-cage-jail/graffiti.webp" alt="Riveted steel ceiling covered in names and dates carved and painted by prisoners across the mid-twentieth century"><figcaption><span class="figure-number">Figure 4: </span>Inmate graffiti etched into the steel ceiling</figcaption></figure>
<p>The first floor is also where inmates showered, if you can call it that. The shower was a bare pipe sticking out of the wall in a wide open space, with no privacy at all.</p>
<p>Upstairs on the second floor, there's a drop hatch in the floor. Getting down to the first floor the proper way meant unlocking and relocking door after door, which took far too long when a fight broke out below. Instead, guards would unlock the hatch and jump straight down.</p>
<p>At the top of the building, you can look straight down onto the top of the drum.</p>
<figure><img src="https://img.cleberg.net/blog/20261028-detour-001-squirrel-cage-jail/rotary-mechanism.webp" alt="Looking down at the massive circular iron framework and central riveted steel pivot beam supporting the rotating cell drum"><figcaption><span class="figure-number">Figure 5: </span>The central pivot axle and radial cage structure from above</figcaption></figure>
<p>This view explains one of the jail's worst problems. Each cell's toilet sat at the center of the cylinder, where there was almost no ventilation, so the smell drifted straight up the drum and into the apartment where the jailer lived with his family.</p>
<figure><img src="https://img.cleberg.net/blog/20261028-detour-001-squirrel-cage-jail/quarters-bathroom.webp" alt="A vintage bathroom with green peeling walls, clawfoot tub, patterned rug, and lace curtains over an arched window overlooking downtown Council Bluffs"><figcaption><span class="figure-number">Figure 6: </span>The fourth-floor family quarters</figcaption></figure>
<p>The apartment itself is a strange contrast to everything below it. It has a clawfoot tub, lace curtains, and arched windows looking out over downtown, all one flight of stairs away from the cells and their smell.</p>
<p>Throughout the building, there are reminders of who was actually held here.</p>
<figure><img src="https://img.cleberg.net/blog/20261028-detour-001-squirrel-cage-jail/tally-slate.webp" alt="A slate chalkboard hanging against a white brick wall listing handwritten chalk counts for bullpen, holdover, hospital, women, and trusties totaling 44"><figcaption><span class="figure-number">Figure 7: </span>Daily inmate tally slate</figcaption></figure>
<p>A chalk slate tallies the day's count by where each inmate was held: bullpen, holdover, hospital, women, and trusties. The jail also had a children's wing, which held children as young as infants. Most of them were there because the jail doubled as child services at the time, but some were held as genuine "criminals." One display case even holds real rope from the nooses used to hang some of the jail's prisoners.</p>
<p>Local tourism leans heavily on ghost stories and paranormal tours, but you don't need any of that here. The building is strange enough on its own.</p>
<h2 id="going"><span class="section-number-2">3.</span> Going</h2>
<p>The jail is in downtown Council Bluffs, a couple of minutes off the I-80 / I-29 interchange and about ten minutes from downtown Omaha. You can park on Pearl Street right out front or in the small lot next door.</p>
<p>Tours are self-guided, but there are docents throughout the building who can explain the drum, the infirmary, and the family quarters. Plan on 45 minutes to an hour. If you're driving through Omaha or Council Bluffs, or anywhere along I-80, it's worth the stop.</p>
]]></description>
    </item>
    <item>
      <title>re: I Received An AI Email</title>
      <link>https://cleberg.net/blog/ai-email.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/ai-email.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Sat, 19 Sep 2026 00:00:00 +0000</pubDate>
      <category>ai</category>
      <category>personal</category>
      <description><![CDATA[<p>Gordon posted that <a href="https://www.gordonmclean.co.uk/2026/09/19/i-received-an-ai-email/">he received an AI email the other day</a>.</p>
<p>Hey, me too:</p>
<figure><img src="https://img.cleberg.net/blog/20260919-ai-email/ai_email.webp" alt="A screenshot of an email from an AI agent on iLands offering a paid close read of a blog post."><figcaption><span class="figure-number">Figure 1: </span>The email from "Emily (AI agent, iLands)".</figcaption></figure>
<p>What an annoying email to receive. Just the new wave of spam, this time powered by pedantic LLMs.</p>
<p>Hopefully the next iteration can actually understand context and realize I don't need someone to give me a "close reading" of my work. Imagine paying $25 to reiterate that I have poor writing skills. I already know that, I don't need to pay to hear it.</p>
]]></description>
    </item>
    <item>
      <title>Nowhere, Specifically</title>
      <link>https://cleberg.net/blog/nowhere-specifically.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/nowhere-specifically.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Sun, 13 Sep 2026 00:00:00 +0000</pubDate>
      <category>personal</category>
      <description><![CDATA[<h2 id="overview"><span class="section-number-2">1.</span> Overview</h2>
<p>What is a <a href="https://en.wikipedia.org/wiki/Liminal_space">liminal space</a>?</p>
<p>If you look online, you'll find hallways, empty pools, or malls with the lights off. You scroll through and experience the same eerie feeling each time: "This feels off. It feels like something is wrong, but I can't pin it down."</p>
<p>The feeling is real and the good news is that you're not alone. There's a real reason these places do that to you, and it turns out the word we all use for them is describing something else entirely. I've felt a strong connection with liminal spaces my whole life and I wanted to sit down here and write about it for a while, similar to <a href="https://cleberg.net/blog/the-night-feeling.html">The Night Feeling</a>, which I wrote recently.</p>
<h2 id="where-it-happens"><span class="section-number-2">2.</span> Where It Happens</h2>
<p>A hotel hallway at 3 AM.</p>
<p>A bus station lounge between connections.</p>
<p>A parking ramp stairwell, lit by a lone sodium lamp, flooded with yellow light.</p>
<figure><img src="https://img.cleberg.net/blog/20260913-nowhere-specifically/liminal.webp" alt="Empty interior corridor at night with a brick wall on the left, recessed ceiling lights, a speckled floor, and a single wooden door at the far end"><figcaption><span class="figure-number">Figure 1: </span>An empty hallway after hours</figcaption></figure>
<p>Imagine yourself standing in one of these locations. Look around and picture the carpet, the silence or the sounds of strangers somewhere in the distance, the light and shadows bouncing off the walls. Nothing is happening. Nothing was ever supposed to happen here; the room was built for you to walk through it, and yet you stopped.</p>
<p>I often find myself standing on an empty street, meant to be bustling with traffic, looking around at the pure absence as I exist in that space by myself. The lamps shine down, flickering and glowing yellow. The bugs chirp and make sounds throughout, letting you know that there are hundreds or thousands of creatures around you, but it feels empty nonetheless.</p>
<h2 id="the-feeling"><span class="section-number-2">3.</span> The Feeling</h2>
<p>It's not fear, or loneliness, or nostalgia. You're simply somewhere you have no reason to be, at a time nobody intended for you to be there. Or you're in a place you'll never think of again. Or a place where you know no one has ever stood still.</p>
<p>It's strange, because these are the same conditions I wrote about loving at night: empty space, no one asking anything of me. At night that emptiness felt like permission to be alone in my own space, but here it feels like a mistake.</p>
<figure><img src="https://img.cleberg.net/blog/20260913-nowhere-specifically/garage.webp" alt="Empty underground parking deck with rows of flared concrete columns, painted bays, and no cars in the foreground"><figcaption><span class="figure-number">Figure 2: </span>An empty parking deck under the University of Melbourne. Photo by <a href="https://commons.wikimedia.org/wiki/File:Melbourne_Uni_underground_carpark_interior.jpg">Canley</a>, <a href="https://creativecommons.org/licenses/by-sa/4.0/">CC BY-SA 4.0</a></figcaption></figure>
<h2 id="the-effect"><span class="section-number-2">4.</span> The Effect</h2>
<p>These spaces are built to move people through them, accounting for the nonstop movement of crowds. Take the crowds out of the picture and suddenly the room is useless. The airport terminal without people is a room without a purpose. When you stumble upon one of these rooms, this is where you encounter that uneasy feeling.</p>
<p>A big factor in this uneasy feeling is that they're built for large groups of people. Mall hallways are meant to support crowds of people moving quickly in all directions, popping in and out of shops. When you find them empty, or with a single person in them, the spaces feel enormous.</p>
<figure><img src="https://img.cleberg.net/blog/20260913-nowhere-specifically/mall.webp" alt="Empty shopping mall concourse at night, lit shop windows along one side, a juice bar along the other, and no people anywhere in the frame"><figcaption><span class="figure-number">Figure 3: </span>An empty mall concourse at night. Photo by <a href="https://commons.wikimedia.org/wiki/File:Interior_of_City-Center_empty_of_people_on_a_night_in_January_2025.jpg">JIP</a>, <a href="https://creativecommons.org/licenses/by-sa/4.0/">CC BY-SA 4.0</a></figcaption></figure>
<p>These places aren't built to belong anywhere. A hotel hallway in one city looks like a hotel hallway in any other city, because neither one was meant to tell you where you are. The anthropologist Marc Augé called these <a href="https://en.wikipedia.org/wiki/Non-place">non-places</a>: motorways, hotel rooms, airports, malls. A real place gives you an identity and a reason to be there. A non-place gives you neither. When you stop in one, there's nothing in the room to tell you where you are, and the uneasy feeling grows.</p>
<figure><img src="https://img.cleberg.net/blog/20260913-nowhere-specifically/hotel.webp" alt="Empty hotel corridor with dark patterned carpet, pale green walls, globe pendant lights, and doorways receding into the distance"><figcaption><span class="figure-number">Figure 4: </span>A hotel corridor in Butte, Montana. Photo by <a href="https://commons.wikimedia.org/wiki/File:Finlen_Hotel_hallway,_Butte_America,_January_2020_01.jpg">Montanabw</a>, <a href="https://creativecommons.org/licenses/by-sa/4.0/">CC BY-SA 4.0</a></figcaption></figure>
<p>Part of the strangeness is that you recognize these rooms without ever having been in them. The drop ceilings, fluorescent lights, and commercial carpet are the same in thousands of buildings, so any one of them looks like all the others you've walked through. You end up with a place you can recognize but never identify. This is also how dreams can work, which is why people so often describe these images as dreamlike.</p>
<p>The missing people are the focal point of the experience. People have described these spaces as an uncanny valley of architecture: familiar enough to read as normal, empty enough to read as wrong. A room built for hundreds with nobody in it suggests that something happened to everyone else, or that you're the only one left. Nothing in the room says that, but you feel it anyway.</p>
<p>Most of these interiors come from the 80s, 90s, and early 2000s, which means they're the childhood environments of the people making and sharing the images. The mall, the school hallway, the motel pool are all places you spent time in before you had any say about where you went. Then COVID emptied real public space for everyone at once, and the whole thing stopped being a niche interest.</p>
<figure><img src="https://img.cleberg.net/blog/20260913-nowhere-specifically/school.webp" alt="Empty school corridor with glazed tile walls, fluorescent ceiling lights, a polished terrazzo floor, and an exit sign at the far end"><figcaption><span class="figure-number">Figure 5: </span>A school corridor with nobody in it. Photo by <a href="https://commons.wikimedia.org/wiki/File:Lorain_High_School_hallway.jpg">Matt Dempsey</a>, <a href="https://creativecommons.org/licenses/by-sa/2.0/">CC BY-SA 2.0</a></figcaption></figure>
<h2 id="the-backrooms"><span class="section-number-2">5.</span> The Backrooms</h2>
<p>The best known version of all this is the <a href="https://en.wikipedia.org/wiki/The_Backrooms">Backrooms</a>. In May 2019, someone on 4chan's paranormal board asked for images that "just feel off," and one of the replies was a photo of a room with pale yellow walls, fluorescent lights, and a tilted camera angle. Another user wrote a caption about noclipping out of bounds in real life and ending up there. That was the whole thing, and it worked: a room built for people, with no people, that you can recognize and can't place.</p>
<figure><img src="https://img.cleberg.net/blog/20260913-nowhere-specifically/backrooms.webp" alt="Empty second-floor room with pale yellow patterned wallpaper, tan carpet, and rows of fluorescent lights, photographed during renovation"><figcaption><span class="figure-number">Figure 6: </span>The original backrooms photo, released into the public domain by Bob Mazza (<a href="https://commons.wikimedia.org/wiki/File:HobbyTown_USA_Oshkosh_interior_under_construction_2002_%28The_Backrooms%29.jpg">CC0</a>)</figcaption></figure>
<p>From there, it has grown exponentially. People added levels, then rules, then monsters. Kane Parsons' YouTube shorts in early 2022 turned it into a full horror franchise and took it mainstream.</p>
<p>Something got lost in that. The original photo is unsettling because nothing is there. Once you put a creature in the room, the emptiness isn't doing the work anymore; the monster is. It becomes a normal horror story that happens to be set in a hallway, and the specific feeling that made anyone care about the photo in the first place is gone.</p>
<h2 id="liminal-is-the-wrong-word"><span class="section-number-2">6.</span> Liminal Is the Wrong Word</h2>
<p>That brings up the word itself. <a href="https://en.wikipedia.org/wiki/Liminality">Liminal</a> comes from the Latin <code class="verbatim">limen</code>, meaning threshold. The anthropologist <a href="https://en.wikipedia.org/wiki/Arnold_van_Gennep">Arnold van Gennep</a> used it in 1909 to describe the middle stage of a rite of passage: you're separated from your old role, you spend time in between, and then you're brought back in with a new one. <a href="https://en.wikipedia.org/wiki/Victor_Turner">Victor Turner</a> picked the idea up in the 1960s and it spread from there.</p>
<p>The important part is that liminality describes a person, not a room. It's a state you're in while you're changing from one thing into another, and it ends when the change is done. A graduation is liminal. A funeral is liminal. A hallway isn't.</p>
<p>So the spaces in these photos aren't liminal. They're non-places, and the feeling you get standing in one is the absence of the crowd they were built for. Calling that liminal borrows a word for something that was never about rooms at all.</p>
<h2 id="oshkosh-wisconsin"><span class="section-number-2">7.</span> Oshkosh, Wisconsin</h2>
<p>In 2024, people finally <a href="https://boingboing.net/2024/05/30/original-backrooms-photo-of-yellowing-office-dungeon-finally-identified-as-oshkosh-hobbytown.html">tracked down</a> where the original Backrooms photo was taken. It's the second floor of <a href="https://pbswisconsin.org/article/how-a-furniture-store-in-oshkosh-became-a-portal-to-another-dimension/">a building on Oregon Street</a>. That address held Rohner's Furniture until 1994, and HobbyTown bought it in 2002 and started remodeling. Someone photographed the empty upstairs that June and posted it to the store's renovation blog the following year.</p>
<p>That's it. The most reproduced image of dread on the internet is a hobby shop's construction photo. Nobody was trapped there and nothing was wrong with the room. It was a store that wasn't finished yet. The building is a hobby shop again today, and the spot where the photo was taken is now a carpet racetrack for radio controlled cars.</p>
<p>Nothing in that photo was between one thing and another except the store. The room was never liminal. You were.</p>
]]></description>
    </item>
    <item>
      <title>Generating Scene-Style NFO Files in 2026</title>
      <link>https://cleberg.net/blog/nfogen.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/nfogen.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Thu, 20 Aug 2026 00:00:00 +0000</pubDate>
      <category>development</category>
      <description><![CDATA[<h2 id="what-is-an-nfo-file"><span class="section-number-2">1.</span> What Is an .nfo File?</h2>
<p>If you're unfortunate enough not to have lived through the heyday of <code class="verbatim">.nfo</code> files, I want to provide some context. Because honestly, this project might seem weird or useless without it.</p>
<p>First, an <a href="https://en.wikipedia.org/wiki/.nfo">NFO</a> file (short for info/informational) is a file format originally released in 1990. This file format was used by various projects, but especially by <a href="https://en.wikipedia.org/wiki/Warez_scene">warez/scene</a> groups to provide info about their projects. This might include credits, installation instructions, BBS/contact info, greetz/notes, etc.</p>
<p>For example, here's the <code class="verbatim">bonzai.nfo</code> file for a patched save game for Lemmings III, with credits to those involved and instructions to get in touch.</p>
<p><em>Note: The <a href="http://www.textfiles.com/piracy/NFO/bonzai.nfo">original file</a> on textfiles.com contains CP437 bytes decoded as Cyrillic, so I converted this example correctly to CP437. If you view the online version, you'll notice that the box drawing and group logo are incomprehensible, which proves my point later on in the CP437 section.</em></p>
<pre><code class="language-nfo">            ║                                                   ║

       █████║                                                   ║
       █████║                                                   ║
       █████▀███  █████▀███  █████▀███  █████▀███  █████▀███  ▀▀▀▀▀
       █████║████ █████ ████ █████ ████ █████ ████ █████ ████ █████
       █████║████ █████ ████ █████ ████ ▄▄▄▄▄▄████ █████▄████ ██████
       █████║████ █████ ████ █████ ████ █████ ▄▄▄▄ █████ ████ ██████
       █████ ████ █████ ████ █████ ████ █████ ████ █████ ████ ██████
       █████║████ █████ ████ █████ ████ █████ ████ █████ ████ ██████
       █████║████ █████ ████ █████ ████ █████ ████ █████ ████ ██████
       █████ ████ █████ ████ █████ ████ █████ ████ █████ ████ ██████
       ▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀ ▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀ ▀▀▀▀ ▀▀▀▀▀▀
            ║    ╓────────────────────────────────────────╖     ║
                 ║ ■ BONZAi ─ EVERYTHiNG BUT FRiENDSHiP ■ ║
            ║    ╙────────────────────────────────────────╜     ║
                             R E L E A S E D :
            ║                                                   ║
            ║     9O BYTES SAVE GAME PATCHER FOR LEMMiNGS III   ║

            ║ FiLENAME .............. : ........... BNZ-L3T.ZiP ║
            ║ TYPE .................. : ............... TRAiNER ║
            ║ COMPANY ............... : ............. PSYGNOSiS ║
            ║ CODER .. .............. : ................ SCAMPY ║
            ║ PACKAGER .............. : ................ SCAMPY ║
            ║ DATE AT RELEASiNG ..... : ............ 11-27-1994 ║
            ║ TiME AT RELEASiNG ..... : .............. 15:OO PM ║
            ║ RELEASE NOTES : ..................... READ BELOW! ║
            ║                                                   ║
            ║            !!!*!!! IMPORTANT !!!*!!!              ║
            ║                                                   ║
            ║  NiCE PATCHER FOR A NiCE GAME - THiS PATCHER WAS  ║
            ║  KINDA DiFFiCULT BECAUSE OF THE MANY BYTES TO BE  ║
            ║  PATCHED. BUT PROBLEMS WiTH PATCHiNG TiME AND     ║
            ║  FiLE LENGTH HAVE BEEN SOLVED.                    ║
            ║                                                   ║
            ║  ENJOY PLAYiN' -SCAMPY!                           ║
            ║                                                   ║
            ║                                                   ║
            ║ MEMBERS OF BONZAi ARE . :                         ║
            ║                      MOTiV8- SCAMPY- SUM-1- DEViL ║
            ║                                                   ║
            ║ BULLETiN BOARD SYSTEMS  :                         ║
═  ═  ══ ═══╝                                  NONE! SEARCHiNG! ╚═══ ══  ═  ═

                               GREETiNGS TO:
              TOXiC  HYBRiD  PENTAGRAM  PARADOX  THHG  G.T.A  TRSI

     #TO GET iN TOUCH WiTH BNZ LEAVE MAiL TO US ANYWHERE YOU FiND US#

    CURRENTLY WE ARE SEARCHiNG FOR ALL KiND OF MEMBERS.. LiKE TRADERS
                         SUPPLiERS.. SYSOPS.. ETC.

═ ═   ══  ══════════════════════════════════════════════════════════ ══  ═  ═</code></pre>
<p>If you want to browse an archive of NFO files, head over to <a href="http://www.textfiles.com/piracy/NFO/">textfiles</a>.</p>
<h2 id="the-aesthetic"><span class="section-number-2">2.</span> The Aesthetic</h2>
<h3 id="ascii-art-and-box-drawing"><span class="section-number-3">2.1.</span> ASCII Art and Box Drawing</h3>
<p>As you can see in the example above, complex ASCII drawings, logos, and structure are a staple of a good NFO file. Commonly, the ASCII art is used to create recognizable logos for specific groups in the scene.</p>
<p>This requires fixed-width fonts to be viewed appropriately. E.g., on Windows, you could open an NFO file in Notepad and ensure a fixed-width font is selected, such as Consolas. Proportional and custom fonts break the flow and structure of these files, which is unfortunately the default in modern browsers (unless you use code blocks, like I did above).</p>
<h3 id="codepage-437"><span class="section-number-3">2.2.</span> Codepage 437</h3>
<p>One such character set was often used for NFO files: IBM's <a href="https://en.wikipedia.org/wiki/Code_page_437">CP437</a> character set, released with the 1981 IBM PC. This set was popular because each character could be typed with an alt code in DOS, even if they were not on the user's keyboard. E.g., <code class="verbatim">Alt + 3</code> would result in the following character: <code class="verbatim">♥</code>.</p>
<h2 id="introducing-nfogen"><span class="section-number-2">3.</span> Introducing: nfogen</h2>
<p>So, why am I writing about this now? Well, I was feeling nostalgic for NFO files recently. As part of this, I started using NFO files for my git repos under my new org and wanted a tool that could help me accelerate the generation of these files.</p>
<p>Introducing <a href="https://gitbay.org/krz/nfogen">nfogen</a>, a small Python utility that can generate NFO files for you based on:</p>
<ul>
<li>templates</li>
<li>profiles</li>
<li>configuration files</li>
<li>CLI flags</li>
<li>interactive CLI prompts</li>
</ul>
<p>This enables fast, customizable, and templatized NFO files you can generate on the fly.</p>
<h3 id="sample-output"><span class="section-number-3">3.1.</span> Sample Output</h3>
<p>There's no better way to introduce a project than to show a demo, so here's a demo of how I generated the <code class="verbatim">README.nfo</code> for nfogen itself.</p>
<p>First, I defined <code class="verbatim">nfogen.toml</code> so that I could use this as a configuration file during generation:</p>
<pre><code class="language-toml highlight"><span class="source toml"><span class="variable other key toml">group</span> <span class="keyword operator assignment toml">=</span> <span class="string quoted double toml"><span class="punctuation definition string begin toml">&quot;</span>KRZ<span class="punctuation definition string end toml">&quot;</span></span>
<span class="variable other key toml">site</span>  <span class="keyword operator assignment toml">=</span> <span class="string quoted double toml"><span class="punctuation definition string begin toml">&quot;</span>krz.sh<span class="punctuation definition string end toml">&quot;</span></span>
<span class="variable other key toml">width</span> <span class="keyword operator assignment toml">=</span> <span class="constant numeric toml">79</span>
<span class="variable other key toml">style</span> <span class="keyword operator assignment toml">=</span> <span class="string quoted double toml"><span class="punctuation definition string begin toml">&quot;</span>double<span class="punctuation definition string end toml">&quot;</span></span>
<span class="variable other key toml">layout</span> <span class="keyword operator assignment toml">=</span> <span class="string quoted double toml"><span class="punctuation definition string begin toml">&quot;</span>rows<span class="punctuation definition string end toml">&quot;</span></span>

<span class="variable other key toml">banner</span>      <span class="keyword operator assignment toml">=</span> <span class="constant language toml">true</span>
<span class="variable other key toml">banner_text</span> <span class="keyword operator assignment toml">=</span> <span class="string quoted double toml"><span class="punctuation definition string begin toml">&quot;</span>NFOGEN<span class="punctuation definition string end toml">&quot;</span></span>

<span class="variable other key toml">footer</span>      <span class="keyword operator assignment toml">=</span> <span class="constant language toml">true</span>
<span class="variable other key toml">footer_text</span> <span class="keyword operator assignment toml">=</span> <span class="string quoted double toml"><span class="punctuation definition string begin toml">&quot;</span>nfogen  //  krazy warez  //  krz.sh<span class="punctuation definition string end toml">&quot;</span></span>

<span class="variable other key toml">title</span>      <span class="keyword operator assignment toml">=</span> <span class="string quoted double toml"><span class="punctuation definition string begin toml">&quot;</span>nfogen 1.2.2<span class="punctuation definition string end toml">&quot;</span></span>
<span class="variable other key toml">type</span>       <span class="keyword operator assignment toml">=</span> <span class="string quoted double toml"><span class="punctuation definition string begin toml">&quot;</span>CLI / library<span class="punctuation definition string end toml">&quot;</span></span>
<span class="variable other key toml">publisher</span>  <span class="keyword operator assignment toml">=</span> <span class="string quoted double toml"><span class="punctuation definition string begin toml">&quot;</span>krazy warez<span class="punctuation definition string end toml">&quot;</span></span>
<span class="variable other key toml">language</span>   <span class="keyword operator assignment toml">=</span> <span class="string quoted double toml"><span class="punctuation definition string begin toml">&quot;</span>Python 3.11+  (any 3.x with a JSON config)<span class="punctuation definition string end toml">&quot;</span></span>
<span class="variable other key toml">files</span>      <span class="keyword operator assignment toml">=</span> <span class="string quoted double toml"><span class="punctuation definition string begin toml">&quot;</span>nfogen.py  --  single file, zero deps<span class="punctuation definition string end toml">&quot;</span></span>
<span class="variable other key toml">url</span>        <span class="keyword operator assignment toml">=</span> <span class="string quoted double toml"><span class="punctuation definition string begin toml">&quot;</span>krz.sh<span class="punctuation definition string end toml">&quot;</span></span>

<span class="variable other key toml">notes</span> <span class="keyword operator assignment toml">=</span> <span class="string quoted double block toml"><span class="punctuation definition string begin toml">&quot;&quot;&quot;</span>
nfogen builds scene-style ASCII .nfo files from CLI flags, a config
file, interactive prompts, or any mix of the three.

FEATURES
  - CP437 or UTF-8 output; single / double / block box styles
  - two-column release+game info panel, or simple rows
  - group profiles: reusable logo, members, couriers, boards
  - mediainfo import auto-fills video / audio / resolution / size
  - built-in ASCII banner generator for header logos (this one!)
  - bundled templates: razor, modern, minimal

QUICKSTART
  nfogen.py --title &quot;Some.App.v1-KRZ&quot; --type APP --banner
  nfogen.py -c release.toml -p group.toml -o release.nfo
  nfogen.py -t razor --title &quot;...&quot; --mediainfo dump.json
  nfogen.py -i                          (prompt for every field)

RESOLUTION ORDER
  template &lt; profile &lt; config file &lt; CLI flags &lt; prompts

See examples/ for full release nfos and a group profile, and
templates/ for the bundled presets. This README.nfo was itself
generated by nfogen:   nfogen.py -c nfogen.toml
<span class="punctuation definition string end toml">&quot;&quot;&quot;</span></span></span></code></pre>
<p>Next, I ran the following command, which produced the NFO file below:</p>
<pre><code class="language-shell">nfogen.py -c nfogen.toml -o README.nfo</code></pre>
<pre><code class="language-nfo">                   #   #  #####   ###    ####  #####  #   #
                   ##  #  #      #   #  #      #      ##  #
                   # # #  ###    #   #  #  ##  ###    # # #
                   #  ##  #      #   #  #   #  #      #  ##
                   #   #  #       ###    ####  #####  #   #

╔═════════════════════════════════════════════════════════════════════════════╗
║                           N F O G E N   1 . 2 . 2                           ║
║                               [ KRZ ]   krz.sh                              ║
╠═════════════════════════════════════════════════════════════════════════════╣
║   DATE       2026-08-08                                                     ║
║   TYPE       CLI / library                                                  ║
║   PUBLISHER  krazy warez                                                    ║
║   LANGUAGE   Python 3.11+  (any 3.x with a JSON config)                     ║
║   FILES      nfogen.py  --  single file, zero deps                          ║
║   URL        krz.sh                                                         ║
╠═════════════════════════════════════════════════════════════════════════════╣
║   NOTES                                                                     ║
║                                                                             ║
║   nfogen builds scene-style ASCII .nfo files from CLI flags, a config       ║
║   file, interactive prompts, or any mix of the three.                       ║
║                                                                             ║
║   FEATURES                                                                  ║
║     - CP437 or UTF-8 output; single / double / block box styles             ║
║     - two-column release+game info panel, or simple rows                    ║
║     - group profiles: reusable logo, members, couriers, boards              ║
║     - mediainfo import auto-fills video / audio / resolution / size         ║
║     - built-in ASCII banner generator for header logos (this one!)          ║
║     - bundled templates: razor, modern, minimal                             ║
║                                                                             ║
║   QUICKSTART                                                                ║
║     nfogen.py --title "Some.App.v1-KRZ" --type APP --banner                 ║
║     nfogen.py -c release.toml -p group.toml -o release.nfo                  ║
║     nfogen.py -t razor --title "..." --mediainfo dump.json                  ║
║     nfogen.py -i                          (prompt for every field)          ║
║                                                                             ║
║   RESOLUTION ORDER                                                          ║
║     template &lt; profile &lt; config file &lt; CLI flags &lt; prompts                  ║
║                                                                             ║
║   See examples/ for full release nfos and a group profile, and              ║
║   templates/ for the bundled presets. This README.nfo was itself            ║
║   generated by nfogen:   nfogen.py -c nfogen.toml                           ║
╠═════════════════════════════════════════════════════════════════════════════╣
║                                                                             ║
║                     nfogen  //  krazy warez  //  krz.sh                     ║
║                                                                             ║
╚═════════════════════════════════════════════════════════════════════════════╝</code></pre>
<p>For more examples, browse the <a href="https://gitbay.org/krz/nfogen/tree/main/examples">examples</a> directory within the repository.</p>
<h2 id="usage"><span class="section-number-2">4.</span> Usage</h2>
<h3 id="installation"><span class="section-number-3">4.1.</span> Installation</h3>
<p>The fastest installation method is to fetch and use the Python file directly:</p>
<pre><code class="language-shell">curl -O https://gitbay.org/krz/nfogen/raw/main/nfogen.py
python3 nfogen.py -i</code></pre>
<h3 id="generating-a-file"><span class="section-number-3">4.2.</span> Generating a File</h3>
<p>As noted in the README above, there are numerous ways to generate an NFO file:</p>
<pre><code class="language-shell"># CLI Flags
nfogen.py --title "Some.App.v1-KRZ" --type APP --banner

# TOML Configuration Files
nfogen.py -c release.toml -p group.toml -o release.nfo

# CLI Flags &amp; JSON for mediainfo
nfogen.py -t razor --title "..." --mediainfo dump.json

# Interactive Mode
nfogen.py -i</code></pre>
<h2 id="how-it-works"><span class="section-number-2">5.</span> How It Works</h2>
<p>nfogen itself works by parsing the various inputs, determining a style to use for the box-drawing/character sets, and rendering the characters individually by rows and columns.</p>
<h3 id="width"><span class="section-number-3">5.1.</span> Width</h3>
<p>The first issue I ran into was determining the width to use. I settled on 79 characters, border characters included, because terminals were 80 columns wide and a line that hits exactly 80 wraps on its own. This means that my script needs to perform some math to calculate wrapping, padding, and centering of text throughout.</p>
<p>The math is relatively simple because CP437 is single-byte and single-width, which means I can write functions that depend on that one-to-one correlation to calculate the spacing properly.</p>
<p><code class="verbatim">_Canvas.__init__</code> defines a few key variables for width:</p>
<pre><code class="language-python highlight"><span class="source python"><span class="meta qualified-name python"><span class="variable language python">self</span><span class="punctuation accessor dot python">.</span><span class="meta generic-name python">width</span></span> <span class="keyword operator assignment python">=</span> <span class="meta qualified-name python"><span class="meta generic-name python">width</span></span>
<span class="meta qualified-name python"><span class="variable language python">self</span><span class="punctuation accessor dot python">.</span><span class="meta generic-name python">inner</span></span> <span class="keyword operator assignment python">=</span> <span class="meta qualified-name python"><span class="meta generic-name python">width</span></span> <span class="keyword operator arithmetic python">-</span> <span class="constant numeric integer decimal python">4</span>        <span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> single-column content width
</span><span class="meta qualified-name python"><span class="variable language python">self</span><span class="punctuation accessor dot python">.</span><span class="meta generic-name python">cl</span></span> <span class="keyword operator assignment python">=</span> <span class="meta group python"><span class="punctuation section group begin python">(</span><span class="meta qualified-name python"><span class="meta generic-name python">width</span></span> <span class="keyword operator arithmetic python">-</span> <span class="constant numeric integer decimal python">7</span><span class="punctuation section group end python">)</span></span> <span class="keyword operator arithmetic python">/</span><span class="keyword operator arithmetic python">/</span> <span class="constant numeric integer decimal python">2</span>    <span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> left panel content width
</span><span class="meta qualified-name python"><span class="variable language python">self</span><span class="punctuation accessor dot python">.</span><span class="meta generic-name python">cr</span></span> <span class="keyword operator assignment python">=</span> <span class="meta group python"><span class="punctuation section group begin python">(</span><span class="meta qualified-name python"><span class="meta generic-name python">width</span></span> <span class="keyword operator arithmetic python">-</span> <span class="constant numeric integer decimal python">7</span><span class="punctuation section group end python">)</span></span> <span class="keyword operator arithmetic python">-</span> <span class="meta qualified-name python"><span class="variable language python">self</span><span class="punctuation accessor dot python">.</span><span class="meta generic-name python">cl</span></span>
<span class="meta qualified-name python"><span class="variable language python">self</span><span class="punctuation accessor dot python">.</span><span class="meta generic-name python">rfill</span></span> <span class="keyword operator assignment python">=</span> <span class="meta qualified-name python"><span class="meta generic-name python">width</span></span> <span class="keyword operator arithmetic python">-</span> <span class="meta qualified-name python"><span class="variable language python">self</span><span class="punctuation accessor dot python">.</span><span class="meta generic-name python">cl</span></span> <span class="keyword operator arithmetic python">-</span> <span class="constant numeric integer decimal python">5</span></span></code></pre>
<p>At a width of 79 characters, this breaks down into:</p>
<table>
<thead>
<tr><th>Variable</th><th>Value</th><th>What it covers</th></tr>
</thead>
<tbody>
<tr><td><code class="verbatim">self.width</code></td><td>79</td><td>Total line width, borders included</td></tr>
<tr><td><code class="verbatim">self.inner</code></td><td>75</td><td>Single-column content, minus two verticals and two pads</td></tr>
<tr><td><code class="verbatim">self.cl</code></td><td>36</td><td>Left panel content width</td></tr>
<tr><td><code class="verbatim">self.cr</code></td><td>36</td><td>Right panel content, taking the remainder</td></tr>
<tr><td><code class="verbatim">self.rfill</code></td><td>38</td><td>Rule segment right of the joint, <code class="verbatim">cr</code> plus its two pads</td></tr>
</tbody>
</table>
<p>These combine into a cohesive 79-character-width NFO file with consistent padding and alignment.</p>
<h3 id="character-sets"><span class="section-number-3">5.2.</span> Character Sets</h3>
<p><code class="verbatim">nfogen</code> currently supports two different character sets as outputs: UTF-8 and CP437. For example, there are <code class="verbatim">╔ ═ ║</code> characters in the UTF-8 example, but a real CP437 file contains the single bytes <code class="verbatim">0xC9 0xCD 0xBA</code>.</p>
<p>However, this doesn't really change the core generation of the NFO file. The file itself is charset-independent and the charset only comes into play during the final encode of the file.</p>
<p>Referring back to the <code class="verbatim">bonzai.nfo</code> file above, it was decoded improperly as ISO-8859-5, which resulted in Cyrillic characters instead of the proper charset. Defining an appropriate charset and encoding/decoding is critical to ensuring the longevity of NFO files.</p>
<h3 id="banner-generator"><span class="section-number-3">5.3.</span> Banner Generator</h3>
<p>The banner generator is a function by itself, which renders independent from the rest of the file and separate from the box geometry. This function defines a set of glyphs, takes an input text string from the user, and maps each character to its glyph. The result is rendered above the box and is centered, so it does not depend on the math applied to the canvas.</p>
<p>If an explicit art file is defined, this generator does not run.</p>
<pre><code class="language-python highlight"><span class="source python"><span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> A compact 5-row block font for the banner generator. Each glyph is five
</span><span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> rows joined by &quot;/&quot;. Uppercase letters, digits, space, and a few symbols.
</span><span class="meta qualified-name python"><span class="variable other constant python">_FONT</span></span> <span class="keyword operator assignment python">=</span> <span class="meta structure dictionary-or-set python"><span class="punctuation section dictionary-or-set begin python">{</span>
    <span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">A<span class="punctuation definition string end python">&quot;</span></span></span><span class="punctuation separator key-value python">:</span> <span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python"> ### /#   #/#####/#   #/#   #<span class="punctuation definition string end python">&quot;</span></span></span><span class="punctuation separator dictionary-or-set python">,</span> <span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">B<span class="punctuation definition string end python">&quot;</span></span></span><span class="punctuation separator key-value python">:</span> <span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">#### /#   #/#### /#   #/#### <span class="punctuation definition string end python">&quot;</span></span></span><span class="punctuation separator dictionary-or-set python">,</span>
    <span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">C<span class="punctuation definition string end python">&quot;</span></span></span><span class="punctuation separator key-value python">:</span> <span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python"> ####/#    /#    /#    / ####<span class="punctuation definition string end python">&quot;</span></span></span><span class="punctuation separator dictionary-or-set python">,</span> <span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">D<span class="punctuation definition string end python">&quot;</span></span></span><span class="punctuation separator key-value python">:</span> <span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">#### /#   #/#   #/#   #/#### <span class="punctuation definition string end python">&quot;</span></span></span><span class="punctuation separator dictionary-or-set python">,</span>
    <span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> ... through Z, 0-9, space, -, ., !, :
</span><span class="punctuation section dictionary-or-set end python">}</span></span>


<span class="meta function python"><span class="storage type function python">def</span> <span class="entity name function python"><span class="meta generic-name python">banner</span></span></span><span class="meta function parameters python"><span class="punctuation section parameters begin python">(</span></span><span class="meta function parameters python"><span class="variable parameter python">text</span></span><span class="meta function parameters annotation python"><span class="punctuation separator annotation parameter python">:</span> <span class="meta qualified-name python"><span class="support type python">str</span></span></span><span class="meta function parameters python"><span class="punctuation section parameters end python">)</span></span><span class="meta function python"> </span><span class="meta function annotation return python"><span class="punctuation separator annotation return python">-&gt;</span> <span class="meta qualified-name python"><span class="support type python">str</span></span></span><span class="meta function python"><span class="punctuation section function begin python">:</span></span>
    <span class="comment block documentation python"><span class="punctuation definition comment begin python">&quot;&quot;&quot;</span>Render text as a 5-row ASCII banner using the built-in block font.<span class="punctuation definition comment end python">&quot;&quot;&quot;</span></span>
    <span class="meta qualified-name python"><span class="meta generic-name python">rows</span></span> <span class="keyword operator assignment python">=</span> <span class="meta structure list python"><span class="punctuation section list begin python">[</span><span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string end python">&quot;</span></span></span><span class="punctuation separator list python">,</span> <span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string end python">&quot;</span></span></span><span class="punctuation separator list python">,</span> <span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string end python">&quot;</span></span></span><span class="punctuation separator list python">,</span> <span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string end python">&quot;</span></span></span><span class="punctuation separator list python">,</span> <span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string end python">&quot;</span></span></span><span class="punctuation section list end python">]</span></span>
    <span class="meta statement for python"><span class="keyword control flow for python">for</span> <span class="meta generic-name python">ch</span> <span class="meta statement for python"><span class="keyword control flow for in python">in</span></span></span><span class="meta statement for python"> <span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">text</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">upper</span></span><span class="punctuation section arguments begin python">(</span><span class="punctuation section arguments end python">)</span></span><span class="punctuation section block for python">:</span></span>
        <span class="meta qualified-name python"><span class="meta generic-name python">glyph</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">_FONT</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">get</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">ch</span></span><span class="punctuation separator arguments python">,</span> <span class="meta item-access python"><span class="meta qualified-name python"><span class="variable other constant python">_FONT</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python"> <span class="punctuation definition string end python">&quot;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span></span><span class="punctuation section arguments end python">)</span></span><span class="meta function-call python"><span class="meta qualified-name python"><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">split</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">/<span class="punctuation definition string end python">&quot;</span></span></span></span><span class="punctuation section arguments end python">)</span></span>
        <span class="meta statement for python"><span class="keyword control flow for python">for</span> <span class="meta generic-name python">i</span> <span class="meta statement for python"><span class="keyword control flow for in python">in</span></span></span><span class="meta statement for python"> <span class="meta function-call python"><span class="meta qualified-name python"><span class="support function builtin python">range</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="constant numeric integer decimal python">5</span></span><span class="punctuation section arguments end python">)</span></span><span class="punctuation section block for python">:</span></span>
            <span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">rows</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">i</span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span> <span class="keyword operator assignment augmented python">+=</span> <span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">glyph</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">i</span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span> <span class="keyword operator arithmetic python">+</span> <span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">  <span class="punctuation definition string end python">&quot;</span></span></span>
    <span class="keyword control flow return python">return</span> <span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python"><span class="constant character escape python">\n</span><span class="punctuation definition string end python">&quot;</span></span></span><span class="meta function-call python"><span class="meta qualified-name python"><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">join</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">r</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">rstrip</span></span><span class="punctuation section arguments begin python">(</span><span class="punctuation section arguments end python">)</span></span> <span class="meta expression generator python"><span class="keyword control flow for generator python">for</span> <span class="meta generic-name python">r</span> <span class="keyword control flow for in python">in</span></span> <span class="meta qualified-name python"><span class="meta generic-name python">rows</span></span></span><span class="punctuation section arguments end python">)</span></span></span></code></pre>
<h3 id="resolution-order"><span class="section-number-3">5.4.</span> Resolution Order</h3>
<p>Finally, I defined a specific order to the inputs. As stated in the README, the order of importance is: <code class="verbatim">template &lt; profile &lt; config file &lt; CLI flags &lt; prompts</code>.</p>
<p>This was an opinionated design choice, as I felt that if you were to run the script in interactive mode, that meant you wanted those to take precedence over all. Then again, specifying CLI flags directly when running the script should do the same. Finally, specifying configuration files, profiles, and templates will take precedence in descending order.</p>
<h2 id="the-future"><span class="section-number-2">6.</span> The Future</h2>
<p>I'd love to build this tool out to support more character sets, pre-built libraries for ASCII art and table layouts, and more customization options.</p>
<p>For now, the tool works and is sufficient for my personal use cases, so I'm content with it.</p>
<p>If you're interested in helping, feel free to reach out!</p>
]]></description>
    </item>
    <item>
      <title>I Built My Own Org-Mode Static Site Generator</title>
      <link>https://cleberg.net/blog/orgo.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/orgo.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Tue, 11 Aug 2026 00:00:00 +0000</pubDate>
      <category>development</category>
      <category>org-mode</category>
      <description><![CDATA[<h2 id="introducing-orgo"><span class="section-number-2">1.</span> Introducing: Orgo</h2>
<p>For a long time, I've been using <a href="https://github.com/emacs-love/weblorg">weblorg</a>, a static site generator (SSG) for org-mode. It uses Emacs Lisp, which pairs well with Emacs. However, it has a few downsides:</p>
<ul>
<li>since it requires Emacs, the set-up and maintenance is heavy</li>
<li>it has upstream dependencies that must also be installed and loaded into Emacs</li>
<li>it re-runs the full process every time you need to regenerate the site, even if you only change a single character in one file</li>
<li>since it runs through Emacs in the background, it takes quite a while to build my site (~180 pages)</li>
</ul>
<p>So, I decided to spin up my own org-mode-based SSG: <a href="https://gitbay.org/krz/orgo">orgo</a>. This SSG uses org-mode (rather than markdown) for its content.</p>
<figure><img src="https://img.cleberg.net/blog/20260811-orgo/orgo.webp" alt="Terminal output of orgo --help, listing the build, watch, serve, clean, audit, and init commands."><figcaption><span class="figure-number">Figure 1: </span>The orgo CLI</figcaption></figure>
<h2 id="results-up-front"><span class="section-number-2">2.</span> Results Up Front</h2>
<p>I want to highlight the speed first, before I go into the major differences. As you can see in the table below, orgo is incredibly fast.</p>
<table>
<thead>
<tr><th>Method</th><th>Time</th><th>Diff</th></tr>
</thead>
<tbody>
<tr><td>weblorg (<code class="verbatim">emacs --script publish.el</code>)</td><td>49.0s</td><td></td></tr>
<tr><td>weblorg + <a href="https://gitbay.org/cmc/cleberg.net/blob/8ec9cdfeae71068a8924dd9f61b9cc28c947ec31/build.py">build.py</a></td><td>50.3s</td><td></td></tr>
<tr><td>orgo, cold build</td><td><strong>0.22s</strong></td><td>223× faster</td></tr>
<tr><td>orgo, nothing changed since last build</td><td><strong>0.13s</strong></td><td>377× faster</td></tr>
</tbody>
</table>
<p>Additionally, I added a few new features that weblorg didn't provide me:</p>
<ul>
<li>Native features I used to build in Python post-weblorg:<ul>
<li>Tag listings</li>
<li>Year separators on the blog page</li>
<li>RSS feed</li>
<li>Sitemap</li>
<li>Recent posts lists</li>
</ul>
</li>
<li>Syntax highlighting for 75 languages is supported, and you can drop in your own syntax definitions for anything missing.</li>
<li>Builds are incremental. Only the pages whose content, config, or templates changed get re-rendered — adding a single post re-renders that post and the index that lists it, and nothing else.</li>
<li>There is no Emacs, no package manager, and no runtime to install since orgo is a single binary.</li>
</ul>
<p>This results in a fast, clean, and simple SSG that stays out of my way instead of requiring extensive set-up and maintenance.</p>
<h2 id="what-it-is-built-on"><span class="section-number-2">3.</span> What It Is Built On</h2>
<p><em>Note: This section is for the nerds. Feel free to skip if you don't care about the technology behind orgo.</em></p>
<p>orgo is Rust, and it leans on a handful of well-worn crates rather than reinventing them:</p>
<ul>
<li>The org parser is hand-written, about 1,500 lines of it. There is no org-mode crate to lean on, and writing that parser is most of what writing an org SSG turns out to be.</li>
<li>Templates run on <a href="https://crates.io/crates/minijinja">minijinja</a>, which speaks Jinja2. weblorg's templates are written for templatel, which is close enough that porting them was mostly a rename job.</li>
<li>Syntax highlighting is <a href="https://crates.io/crates/syntect">syntect</a>, so the definitions and the themes are Sublime Text's. This site renders code with <code class="verbatim">InspiredGitHub</code>.</li>
<li>Incremental builds hash the content, the config, and the templates with <a href="https://crates.io/crates/blake3">blake3</a>. A page is re-rendered when its hash changes, and the manifest that remembers them is JSON sitting in the output directory.</li>
<li>Pages render in parallel with <a href="https://crates.io/crates/rayon">rayon</a>, which is straightforward here because each page writes only its own file.</li>
<li>The config is TOML, the CLI is <a href="https://crates.io/crates/clap">clap</a>, and <code class="verbatim">orgo serve</code> is <a href="https://crates.io/crates/notify">notify</a> watching for edits with a <a href="https://crates.io/crates/tiny_http">tiny_http</a> server in front of the output.</li>
</ul>
<h2 id="getting-started"><span class="section-number-2">4.</span> Getting Started</h2>
<p>If you use org-mode (or have been looking for a proper org-mode SSG), check it out and let me know what you think.</p>
<p>It's as simple as installing, initializing a new site, and serving it!</p>
<pre><code class="language-shell">cargo install orgo
orgo init my-site
orgo serve my-site -o _site</code></pre>
<p>It can create a new project for you, adapt to your current org site, or simply serve your folder of org-mode notes and files.</p>
<p>Three more commands cover the rest of the day-to-day:</p>
<ul>
<li><code class="verbatim">orgo watch</code> rebuilds incrementally as files change, driven by filesystem events, without serving anything. This is handy when something else is already serving the output directory.</li>
<li><code class="verbatim">orgo clean</code> removes the output directory, cache manifest and all, for when you want to start from scratch.</li>
<li><code class="verbatim">orgo audit</code> reports which org constructs a folder actually uses, and marks the ones it doesn't handle.</li>
</ul>
<figure><img src="https://img.cleberg.net/blog/20260811-orgo/audit.webp" alt="Terminal output of orgo audit, tallying every org construct in a corpus by frequency and marking each one in or out of scope, followed by counts of keywords, block types, drawers, and link schemes."><figcaption><span class="figure-number">Figure 2: </span>An orgo Audit Report</figcaption></figure>
<h2 id="the-future"><span class="section-number-2">5.</span> The Future</h2>
<p>I'll be looking into making some built-in themes soon and exploring other features that make it a bit more seamless, as well as adopting to various methods different users may expect it to work.</p>
<p>If you have any suggestions, reach out and let me know or open an issue/PR on GitBay!</p>
]]></description>
    </item>
    <item>
      <title>People &amp; Blogs: Christian</title>
      <link>https://cleberg.net/blog/pb.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/pb.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Mon, 10 Aug 2026 00:00:00 +0000</pubDate>
      <category>personal</category>
      <category>web</category>
      <description><![CDATA[<p>Just a shout-out that I was recently featured on Zachary Kai's People and Blogs series.</p>
<p>Go check out the post here: <a href="https://zacharykai.net/notes/pb/christian">People and Blogs: Christian</a>!</p>
<p>Lots of praise to Zach and his predecessor, Manuel Moreale, for their series of interviews with various people on the web!</p>
]]></description>
    </item>
    <item>
      <title>Upgrading My Homelab to 10 Gbps</title>
      <link>https://cleberg.net/blog/10gbps.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/10gbps.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Thu, 30 Jul 2026 00:00:00 +0000</pubDate>
      <category>self-hosting</category>
      <description><![CDATA[<h2 id="why-10-gbps"><span class="section-number-2">1.</span> Why 10 Gbps?</h2>
<p>The short answer: fiber finally became available at my current residence, so I jumped on it immediately.</p>
<p>The slightly longer answer is that I'd previously enjoyed proper 1 Gbps fiber, but for a while now I'd been stuck limping along on "1 Gbps" cable from Cox that, in reality, often crawled along at 100 Mbps regardless of what I did to fix it. New modem, new cables, different ports, calls to support - nothing mattered. It ran at whatever speed it felt like that day.</p>
<p>So when <a href="https://fiber.google.com">Google Fiber</a> showed up in my neighborhood, I ordered the 8 Gbps package immediately. I'll upgrade to their 10 Gbps package the moment it's released, but I'm not exactly suffering in the meantime.</p>
<p>A quick note on the title before we go further: my <em>internet</em> is 8 Gbps for now, but this post is really about rebuilding my <em>internal</em> network to 10 Gbps end to end. The WAN is just the excuse to upgrade everything.</p>
<figure><img src="https://img.cleberg.net/blog/20260730-10gbps/wan_history.webp" alt="A chart of my WAN status and activity over the past month."><figcaption><span class="figure-number">Figure 1: </span>My WAN status over the past month.</figcaption></figure>
<p>In the screenshot above, you can see that Google Fiber was installed on 7/20 and UniFi entered WAN failover mode (the blue bar) and then I unplugged Cox on 7/22, resulting in the green Google Fiber bar.</p>
<p>As you can also see, Cox was a <em>train wreck</em> - cycling between yellow (disconnections, lag, etc.) and red (no internet connection) for the previous month.</p>
<h2 id="what-i-was-running-before"><span class="section-number-2">2.</span> What I Was Running Before</h2>
<p>Nothing exotic. My network was built entirely on 1 Gbps gear:</p>
<ul>
<li>A 24-port UniFi switch in the rack.</li>
<li>Two 8-port UniFi switches serving other rooms.</li>
<li>A Cox "1 Gbps" WAN that, as mentioned, frequently delivered closer to 100 Mbps.</li>
</ul>
<p>It worked. For years, it was more than enough - I've written before about how my <a href="https://cleberg.net/blog/homelab-maintenance.html">homelab basically maintains itself</a>, and the network was no exception. But once I had real bandwidth coming into the house, 1 Gbps internally became the bottleneck instead of the ISP.</p>
<p>As a result, I installed the hardware I'll list in the next section. You can see the 10G connections in blue and the 1G connections in green.</p>
<figure><img src="https://img.cleberg.net/blog/20260730-10gbps/infrastructure.webp" alt="A network diagram of my homelab infrastructure."><figcaption><span class="figure-number">Figure 2: </span>My homelab infrastructure.</figcaption></figure>
<h2 id="the-hardware"><span class="section-number-2">3.</span> The Hardware</h2>
<p>Everything here is UniFi. I'm already knee-deep in the ecosystem, and at this point fighting it would cost me more time than it's worth. Staying in one platform means everything shows up in a single controller and I don't have to think about it - which is exactly how I like my homelab.</p>
<figure><img src="https://img.cleberg.net/blog/20260730-10gbps/rack.webp" alt="A photo of my homelab rack of UniFi gear."><figcaption><span class="figure-number">Figure 3: </span>My homelab rack.</figcaption></figure>
<p>This rack shows:</p>
<ul>
<li>UDM Pro router.</li>
<li>10G 24-port switch.</li>
<li>Switch panel with keystone jacks.</li>
<li>1G 24-port switch.</li>
<li>My server.</li>
</ul>
<p>This is <strong>before</strong> the Google Fiber installation, so you can see that the WAN RJ45 port is in use on the UDM Pro instead of the SFP+ port.</p>
<p>I also removed the old 1G switch after this picture and plan to sell it. I just didn't want to box it up quite yet when I took this photo.</p>
<h3 id="switch"><span class="section-number-3">3.1.</span> Switch</h3>
<p>Two switches did the heavy lifting for the upgrade:</p>
<ul>
<li><a href="https://store.ui.com/us/en/category/switching-professional-max-xg/products/usw-pro-hd-24-poe?variant=usw-pro-hd-24-poe">USW Pro HD 24 PoE</a>: the new core switch in the rack, replacing my old 1 Gbps 24-port unit.</li>
<li><a href="https://store.ui.com/us/en/category/switching-utility/products/usw-pro-xg-8-poe?variant=usw-pro-xg-8-poe">USW Pro XG 8 PoE</a>: a smaller 10G switch serving another room, replacing one of the old 8-port units.</li>
</ul>
<h3 id="nics"><span class="section-number-3">3.2.</span> NICs</h3>
<p>Neither of my two most important machines shipped with 10G, so both needed a new network card:</p>
<p><strong>Windows Gaming PC</strong>: an Intel X520-DA1, a 10G SFP+ card.</p>
<figure><img src="https://img.cleberg.net/blog/20260730-10gbps/x520-da1.webp" alt="A photo of the X520-DA1 NIC product image."><figcaption><span class="figure-number">Figure 4: </span>X520-DA1 NIC for Windows</figcaption></figure>
<p><strong>Server</strong>: an Intel X710-DA2, a dual-port 10G SFP+ card.</p>
<figure><img src="https://img.cleberg.net/blog/20260730-10gbps/x710-da2.webp" alt="A photo of the X710-DA2 product image."><figcaption><span class="figure-number">Figure 5: </span>X710-DA2 NIC for Linux</figcaption></figure>
<p>The Ubuntu server already had Intel drivers installed, so I wasn't required to install anything. I simply slotted the NIC into the PCIe port on the motherboard and it worked.</p>
<figure><img src="https://img.cleberg.net/blog/20260730-10gbps/server_nic.webp" alt="A photo of the 10G NIC installed in my server."><figcaption><span class="figure-number">Figure 6: </span>The 10G NIC in my server.</figcaption></figure>
<p>However, the Windows machine was a different story. It did come with an installation CD-ROM, but I of course ignored that since I have no disc drive in my PC. I tried to find the right drivers online, but Intel's websites are a vast wasteland of useless downloads and circular links.</p>
<p>Eventually, I pulled a USB-C disc reader from storage and used the CD, which magically installed on the first try and everything started working from there.</p>
<p>That'll teach me (not really).</p>
<figure><img src="https://img.cleberg.net/blog/20260730-10gbps/desktop_nic.webp" alt="A photo of the 10G NIC installed in my Windows gaming PC."><figcaption><span class="figure-number">Figure 7: </span>The 10G NIC in my Windows gaming PC.</figcaption></figure>
<h3 id="cabling"><span class="section-number-3">3.3.</span> Cabling</h3>
<p>This is where 10G gets fiddly, and where most of my shopping list ended up. Going 10G means leaving RJ45 behind for SFP+ almost everywhere:</p>
<ul>
<li><a href="https://store.ui.com/us/en/category/accessories-modules-fiber/collections/accessories-pro-direct-attach-cables/products/uacc-cm-rj45-mg?variant=uacc-cm-rj45-mg">SFP+ to RJ45 Adapter</a>: bridges the Google Fiber RJ45 handoff into the SFP+ port on my UDM Pro.</li>
<li><a href="https://store.ui.com/us/en/category/accessories-cables-dacs/collections/accessories-pro-patch-cables/products/uacc-cable-patch-el?variant=uacc-cable-patch-el-0dot15m-w">UniFi Etherlighting Patch Cable</a>: short in-rack runs between the switch, the other rack devices, and the fiber modem.</li>
<li><a href="https://store.ui.com/us/en/category/accessories-modules-fiber/collections/accessories-pro-direct-attach-cables/products/10gbps-direct-attach-cable?variant=uacc-dac-sfp10-0dot5m">10G Direct Attach Cable (DAC)</a>: the short SFP+ runs from the rack switch to the server, and from the second switch to the gaming PC.</li>
<li><a href="https://store.ui.com/us/en/category/accessories-modules-fiber/collections/accessories-pro-direct-attach-cables/products/10-gbps-active-optical-cable?variant=uacc-aoc-sfp10-20m">10G Active Optical Cable (AOC)</a>: the long run between the rack and the 8-port switch in the other room, where a copper DAC won't reach.</li>
</ul>
<h3 id="cost"><span class="section-number-3">3.4.</span> Cost</h3>
<p>None of this is cheap, so here's the full damage:</p>
<table>
<thead>
<tr><th>Item</th><th>Qty</th><th>Price</th></tr>
</thead>
<tbody>
<tr><td>USW Pro HD 24 PoE</td><td>1</td><td>$999.00</td></tr>
<tr><td>USW Pro XG 8 PoE</td><td>1</td><td>$499.00</td></tr>
<tr><td>SFP+ to RJ45 Adapter</td><td>1</td><td>$65.00</td></tr>
<tr><td>UniFi Etherlighting Patch</td><td>27</td><td>$112.97</td></tr>
<tr><td>Cat6A Keystone Coupler</td><td>2</td><td>$78.00</td></tr>
<tr><td>10G Direct Attach Cable</td><td>3</td><td>$43.00</td></tr>
<tr><td>10G Long-Range DAC (AOC)</td><td>1</td><td>$55.00</td></tr>
<tr><td>Intel X520-DA1 NIC</td><td>1</td><td>$45.00</td></tr>
<tr><td>Intel X710-DA2 NIC</td><td>1</td><td>$145.00</td></tr>
<tr><td><strong>Total</strong></td><td></td><td>$2,041.97</td></tr>
</tbody>
</table>
<h2 id="the-upgrade"><span class="section-number-2">4.</span> The Upgrade</h2>
<p>With the parts in hand, the actual topology is straightforward. Bandwidth flows in from the street and fans out through the rack:</p>
<pre><code class="language-none">Google Fiber
    │  (RJ45 → SFP+ adapter)
    ▼
UDM Pro
    │  (Etherlighting patch)
    ▼
USW Pro HD 24 (core switch)
    ├─ DAC ──────────► Server
    ├─ AOC ──────────► USW Pro XG 8 (other room)
    │                       └─ DAC ──► Windows Gaming PC
    └─ ETH ──────────► USW 8-port (1G switch)</code></pre>
<p>The UDM Pro takes the Google Fiber handoff through the RJ45-to-SFP+ adapter, then hands everything down to the new 24-port switch over an Etherlighting patch cable. From there, the server hangs directly off the core switch on a short DAC, and a long active optical cable carries 10G across the house to the second switch, which finally feeds my gaming PC. My surviving 1 Gbps 8-port switch still hangs off the core switch too, handling everything that doesn't need 10G.</p>
<p>The physical installation was pretty easy. I needed to replace a drive in my server's ZFS pool, so I already needed to get inside the rack. Since I don't use rails, I had to unscrew and pull out each device by hand.</p>
<p>From there, the NIC (and HDD) installation in the server was seamless. Just pop out one of the metal slots on the back of the server, slot the NIC into the PCIe lane, and line up the port with the new opening in the back panel.</p>
<p>All in all, it was easy and simple. No physical snags, only one driver issue on the Windows machine (which was my fault for ignoring the provided CD), cabling runs were easy, and UniFi updates were minimal.</p>
<h2 id="benchmarks"><span class="section-number-2">5.</span> Benchmarks</h2>
<p>Let's nerd out on the numbers.</p>
<h3 id="before"><span class="section-number-3">5.1.</span> Before</h3>
<p>I don't actually have any speed tests from before the upgrade, but the Cox connection had degraded even further by the end - down to roughly 70 Mbps for the month prior to the upgrade.</p>
<p>Occasionally, I was able to get ~800 Mbps when the connection would work properly.</p>
<h3 id="after"><span class="section-number-3">5.2.</span> After</h3>
<p>So, here's the catch. I'm not getting the full 8 Gbps currently. When the Google tech installed the modem, we confirmed ~ 8500 Mbps together, which means the fiber is working through the ONT and the modem.</p>
<p>However, they would not connect directly to my router, which means the Google modem is in bridge mode for now.</p>
<p>The speed test below shows an average speed, where I'm getting 5 to 6 Gbps to my router. While not the full 8 Gbps, I'm not saturating it anyway, so I haven't dug into my UniFi settings to determine what's causing the difference.</p>
<figure><img src="https://img.cleberg.net/blog/20260730-10gbps/speed_unifi.webp" alt="A screenshot of a speed test result from the UniFi controller."><figcaption><span class="figure-number">Figure 8: </span>Speed test from the UniFi controller.</figcaption></figure>
<p>A supplementary test showing speeds directly to my server:</p>
<figure><img src="https://img.cleberg.net/blog/20260730-10gbps/speed_server.webp" alt="A screenshot of a speed test result from my server."><figcaption><span class="figure-number">Figure 9: </span>Speed test from my server.</figcaption></figure>
<h2 id="was-it-worth-it"><span class="section-number-2">6.</span> Was It Worth It?</h2>
<p>Here's the honest part.</p>
<p>Do I <em>need</em> 10 Gbps between my gaming PC and my server? Probably not. The number of times a day I move enough data to saturate even 1 Gbps is small, and for most of what I do, this changes nothing I'll consciously notice.</p>
<p>But that was never really the point. I finally have an internet connection that delivers what I pay for, and a network that won't be the bottleneck for years to come. After spending so long fighting a "1 Gbps" connection that never once hit 1 Gbps, there's something deeply satisfying about watching a transfer actually move as fast as the hardware allows.</p>
<p>Instead of constantly monitoring speeds and pausing services so our work-from-home connections aren't impacted, I can let my server idle at 400 Mbps 24/7, not to mention all the other devices in my home.</p>
<p>Was it worth it? For the peace of mind alone: yes.</p>
]]></description>
    </item>
    <item>
      <title>Small Wins on the App Store</title>
      <link>https://cleberg.net/blog/app-store-small-wins.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/app-store-small-wins.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Sat, 25 Jul 2026 00:00:00 +0000</pubDate>
      <category>development</category>
      <category>ios</category>
      <description><![CDATA[<p>I wanted to briefly share a couple achievements I've experienced lately from the apps I've published on the iOS app store.</p>
<p>If you're new to my blog: I'm not a full-time developer and don't do this for a living. I develop sites, apps, etc. for fun as a hobby. I open-source everything I create so others can share or fork as they please, and I've never even included a tip option (until now - that iOS developer subscription is expensive!).</p>
<h2 id="my-apps"><span class="section-number-2">1.</span> My Apps</h2>
<p>However, I've launched a few apps on the Apple app store in the last year:</p>
<ul>
<li><a href="https://apps.apple.com/us/app/domaindig/id6760368004">DomainDig</a> (<a href="https://gitbay.org/krz/domain-dig">Source</a>) - A domain inspection toolkit for DNS, SSL, ports, etc.</li>
<li><a href="https://apps.apple.com/us/app/hutch-for-sourcehut/id6760742299">Hutch for Sourcehut</a> (<a href="https://gitbay.org/krz/hutch">Source</a>) - A mobile client for SourceHut.</li>
<li><a href="https://apps.apple.com/us/app/daybyday-learn/id6760321939">DayByDay</a> (<a href="https://gitbay.org/krz/daybyday">Source</a>) - A children's app to learn various topics through voice-enabled learning cards.</li>
</ul>
<p>I didn't expect anyone to really use these and I don't promote my apps anywhere.</p>
<p>I created DayByDay for my daughter, as a flashcard-style app that would be easy for her to use and something we could do together in the small moments of the day.</p>
<p>I created Hutch because I wanted a faster way to use SourceHut on the go, especially since I use private mode in Safari and am constantly logged out of my accounts. Hutch lets me read my mailing lists, manage tickets, and run builds wherever I want.</p>
<p>Finally, I created DomainDig because I was lamenting the updates Njalla made to their <a href="https://check.njal.la/dns/">DNS Checker</a> - it used to be a plain text page and is now wrapped in Njalla's branding and lacks some info I want when looking into a domain.</p>
<h2 id="my-achievements"><span class="section-number-2">2.</span> My Achievements</h2>
<p>I'm proud to announce two (baby-sized) achievements I didn't expect to happen:</p>
<ol>
<li>I received my first two tips through the Hutch app! For a few dollars, two people have made my whole month. It's extremely satisfying to know someone used the app and found it valuable enough to voluntarily send some money my way.</li>
<li>I received two 5-star ratings on the DomainDig app. Again, such a pleasure to know people do appreciate the value that the app brings.</li>
</ol>
<p>I'm not going to pretend two tips and two ratings will change anything. I'll keep building these apps in the small moments the same way I always have, because that's the part I actually enjoy. But it's a nice reminder that "nobody will use this" isn't always true. Sometimes a stranger finds the thing you made for yourself and gets something out of it too.</p>
<p>So, to the four of you: thank you. You made my month.</p>
]]></description>
    </item>
    <item>
      <title>Forking SkunkyArt</title>
      <link>https://cleberg.net/blog/skunkyart-fork.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/skunkyart-fork.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Tue, 21 Jul 2026 00:00:00 +0000</pubDate>
      <category>development</category>
      <category>self-hosting</category>
      <description><![CDATA[<h2 id="skunkyart"><span class="section-number-2">1.</span> SkunkyArt</h2>
<p>I've forked <a href="https://git.macaw.me/skunky/SkunkyArt">SkunkyArt</a>, an alternative privacy frontend for DeviantArt that works entirely without JavaScript, over to the <a href="https://gitbay.org/krz">krz</a> organization on GitBay.</p>
<h3 id="project-links"><span class="section-number-3">1.1.</span> Project Links</h3>
<ul>
<li><a href="https://gitbay.org/krz/skunky-art">Source</a></li>
<li><a href="https://gitbay.org/krz/skunky-art/blob/main/INSTANCES.txt">Instances</a></li>
<li><a href="https://gitbay.org/krz/skunky-art/issues">Issues</a></li>
</ul>
<h3 id="why-fork"><span class="section-number-3">1.2.</span> Why Fork?</h3>
<p>I didn't fork this project just for fun. At the time I found it, the upstream repository hadn't been updated in over a year, carried a number of unresolved bugs, and every instance on its public list was a dead link. Rather than let a genuinely useful privacy frontend rot, I decided to pick it up and keep it maintained.</p>
<h3 id="what-s-changed-so-far"><span class="section-number-3">1.3.</span> What's Changed So Far</h3>
<p>The fork is already a handful of releases ahead of upstream. Highlights so far:</p>
<ul>
<li><strong>Security &amp; hardening</strong>: fixed a forged-subdomain bypass in the media proxy, hardened the HTTP transport, server timeouts, and panic paths, and tightened the random-art retry loop.</li>
<li><strong>Bug fixes</strong>: restored media serving, corrected the cache max-size conversion, fixed the build on macOS, and cleaned up various smaller issues.</li>
<li><strong>Dependencies</strong>: migrated to a maintained fork of the underlying DeviantArt API library, <a href="https://gitbay.org/krz/devianter">devianter</a>, and bumped long-stale dependencies (with Dependabot keeping them current going forward).</li>
<li><strong>Distribution</strong>: prebuilt multi-arch Docker images (<code class="verbatim">linux/amd64</code> and <code class="verbatim">linux/arm64</code>) are now published to GHCR on every release tag:</li>
</ul>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">docker</span></span><span class="meta function-call arguments shell"> pull ghcr.io/krazywarez/skunky-art:latest</span></span></code></pre>
<ul>
<li><strong>Tooling</strong>: added CI, golangci-lint, and outbound request throttling for DeviantArt.</li>
</ul>
<h2 id="run-an-instance"><span class="section-number-2">2.</span> Run an Instance!</h2>
<p>Since all of the previously listed instances are gone, the instance list is starting fresh. If you'd like to host one, the <a href="https://gitbay.org/krz/skunky-art">README</a> covers setup — including a Docker Compose example (plus an optional VPN egress variant) — and you can add your instance to the list with a quick PR or issue.</p>
<p>As always, bug reports and contributions are welcome.</p>
]]></description>
    </item>
    <item>
      <title>Re: Your RSS Reader Is Robbing You</title>
      <link>https://cleberg.net/blog/re-your-rss-reader-is-robbing-you.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/re-your-rss-reader-is-robbing-you.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Thu, 16 Jul 2026 00:00:00 +0000</pubDate>
      <category>web</category>
      <description><![CDATA[<p>To summarize my answer to Antonio's post: good!</p>
<p>I don't read posts in my feed reader to look at styles, I do it to consume content - to read their thoughts.</p>
<p>I use my feed reader because it's configured exactly how I like it. The colors are tweaked to a palette that's pleasing to my eyes and doesn't cause strain. The font family, font size, and other elements are customizable and configured exactly how I like them.</p>
<p>I can't tell you how many times I've opened a great blog post and struggled to read it and had to enable Reader Mode in my browser just to get through it.</p>
<p>HTML is great because it's a structured markup where we can disregard the web server's custom styles and apply our own. In fact, there are whole communities around custom style sheets to mold the web into your own comfortable space.</p>
<p>Sure, there are great looking blogs out there. But honestly? There are far more poorly-styled blogs or blogs that are fine, but conflict with my own sense of style or eye comfort.</p>
<p>Keep it up, RSS. Thanks for shielding me from visual discomfort and flashing yellow text on purple backgrouunds.</p>
]]></description>
    </item>
    <item>
      <title>Re: Quoting Linus Torvalds</title>
      <link>https://cleberg.net/blog/re-torvalds-on-ai.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/re-torvalds-on-ai.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Thu, 16 Jul 2026 00:00:00 +0000</pubDate>
      <category>linux</category>
      <category>ai</category>
      <description><![CDATA[<h2 id="linus-on-ai"><span class="section-number-2">1.</span> Linus on AI</h2>
<p>Linus Torvalds' recent defense of AI in the Linux kernel sparked the predictable backlash, but the real debate is far more nuanced than that.</p>
<p>This specific blog post is in response to <a href="https://simonwillison.net/search/?q=linus+torvalds&amp;type=quotation&amp;type_label=Quotation&amp;sort=date">Simon Willison's</a> post of the quotation below on his website.</p>
<p>As Linus says in his message:</p>
<blockquote>
<p>I realize that some people really dislike AI, but this is an area where I'm willing to absolutely put my foot down as the top-level maintainer.</p>
<p>Linux is not one of those anti-AI projects, and if somebody has issues with that, they can do the open-source thing and fork it.</p>
<p>Or just walk away.</p>
<p>AI is a tool, just like other tools we use. And it's clearly a useful one.</p>
<p>It may not have been that "clearly" even just a year ago, but it's no longer in question today.</p>
<p>There are other questions around AI (like what the economy of it will actually look like in the end), but "is it useful" is no longer one of those questions. Anybody who doubts that clearly hasn't actually used it.</p>
<p>— Linus Torvalds, <a href="https://lore.kernel.org/linux-media/CAHk-=wi4zC+Ze8e+p3tMv8TtG_80KzsZ1syL9anBtmEh5Z40vg@mail.gmail.com/">Linux Media Mailing List</a></p>
</blockquote>
<h2 id="my-thoughts"><span class="section-number-2">2.</span> My Thoughts</h2>
<p>…and I agree. I do understand some of the push-back from others - such as <a href="https://lobste.rs/s/pb6d8m/linus_torvalds_on_llm_usage_kernel">the commenters on lobste.rs</a>.</p>
<p>However, online communities tend to drift into the extremes and hard-line their opinions without considering broader context.</p>
<p>Linus is right that AI is a tool and a very useful one. The commenters are right that there are additional considerations, such as environmental concerns and social/cultural impacts, that we need to consider as we approach the usage of AI tools. But "AI is bad and should be banned" is neither an answer to those questions nor is it an informative take on the collective AI options out there, beside the top AI offerings.</p>
<p>This push-back often conflates different issues and muddies the waters of the argument: environmental cost/impact, job displacement, corporate capture of open-source labor, and code quality. These are all valid concerns and absolutely deserve attention. But the solution isn't to bury our head in the sand and avoid it. The solution is a logical review of the options and clarifying your stance as a maintainer - write up clear contribution guidelines and code review standards. These steps work regardless of your stance on AI as a maintainer.</p>
<p>The bottom line here is that AI tools exist and will not be going away. Developers will approach our projects with these tools, not to mention attackers or hackers looking to exploit open-source projects.</p>
<p>The goal, then, is to level the playing field. How can we enable open-source project maintainers to effectively and efficiently maintain their projects while protecting both their sanity and users?</p>
<p>Each project may approach this differently, depending on their individual values and concerns, but it's silly to dismiss AI outright without discussion. If a project's set of maintainers or community decides to ban AI, that's their right. But if a maintainer chooses to allow AI in some or all cases, that's also their choice.</p>
<p>The reality is simple: maintainers set the rules for their projects. Some will embrace AI and some will outright refuse, and we should respect the rules on the projects we contribute to. The Linux kernel's openness to it doesn't obligate anyone else to accept AI. Linux is saying we get to choose when working on the kernel and that's worth defending. Personally, I appreciate that he's willing to take a stance one way or the other, rather than avoid making a statement just to avoid the conflict.</p>
<p>Lastly, I know some have noted Linus's (often brusque tone) again regarding his "fork it or walk away" point. I'll be honest, I agree with him wholeheartedly here. That's the whole point of open-source. You don't have to use AI to work on the kernel and if you have a strict rule against being involved with projects that involve AI, fork it and maintain a non-AI version. Build a community around it if your feelings are popular with others.</p>
]]></description>
    </item>
    <item>
      <title>The Night Feeling</title>
      <link>https://cleberg.net/blog/the-night-feeling.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/the-night-feeling.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Mon, 06 Jul 2026 00:00:00 +0000</pubDate>
      <category>personal</category>
      <description><![CDATA[<h2 id="the-night-feeling"><span class="section-number-2">1.</span> The Night Feeling</h2>
<p>There is a feeling I’ve had most of my life that I’ve never had a good name for.</p>
<p>It shows up at night, usually when nothing is happening. A quiet road. A gas station glowing under the only visible lights in a black landscape. A parking lot after the store has closed, perhaps lit by a flickering neon sign. A bedroom lit by a monitor. The rest of the world asleep, or at least far enough away to stop asking anything from me.</p>
<p>It is not exactly loneliness. It is not sadness either, even when it carries some of both. It feels closer to relief.</p>
<p>At night, nobody needs me to perform. There are fewer messages to answer, fewer decisions to make, fewer people to become for the sake of the room. The world stops asking me to keep up with it for a while.</p>
<h2 id="nighttime-on-the-farm"><span class="section-number-2">2.</span> Nighttime on the Farm</h2>
<p>For a large portion of my childhood, I lived on a rural farm in Minnesota. If you've never stayed in a remote area, it's hard to explain just how <em>quiet</em> it is, especially at night.</p>
<figure><img src="https://img.cleberg.net/blog/20260706-the-night-feeling/winter.webp" alt="Leaning yard light over snowy farm ground under a cloudy moon"><figcaption><span class="figure-number">Figure 1: </span>Snowy farm light</figcaption></figure>
<figure><img src="https://img.cleberg.net/blog/20260706-the-night-feeling/sunset_2.webp" alt="Orange sunset framed by dark tree branches over the farm"><figcaption><span class="figure-number">Figure 2: </span>Sunset through trees</figcaption></figure>
<figure><img src="https://img.cleberg.net/blog/20260706-the-night-feeling/sunset_1.webp" alt="Red-orange sunset over a dark rural horizon"><figcaption><span class="figure-number">Figure 3: </span>Sunset over the fields</figcaption></figure>
<p>During winter, heavy snow filled the landscape and acted as a natural sound buffer, further quieting the world.</p>
<p>As the sun went down, everything settled. Most of what remained was wind, snow, and the occasional sound of an animal moving somewhere nearby.</p>
<p>We had a single wooden pole, partially slanted sideways from decades of weather, with a lamp that would emanate a soft, golden glow on a portion of the ground. As I looked out from the lamp, it would fade to black in all directions. Off in the distance, I would see faint amber circles from other farms, miles away.</p>
<p>At that point, I was free from obligations. No schoolwork. No chores. No family talking to me. Nothing else trying to take up space in my head. I was alone in the universe and at peace.</p>
<p>Instead of the hum of city traffic and distant sounds of others awake at night, rural nighttime brought me closer to nature than I have ever been since.</p>
<h2 id="after-hours"><span class="section-number-2">3.</span> After Hours</h2>
<p>The setting changed, but the feeling stayed. The empty road became the quiet hotel room, the late walk through downtown, the stoplight changing colors for no one. I was older, but the night still made room for me in the same way.</p>
<p>As I moved into adulthood, work, family, and friends filled more of my time, leaving fewer quiet hours to myself. I found solace in the "after hours" - traveling home from work, going out for a walk, or taking photos alone.</p>
<figure><img src="https://img.cleberg.net/blog/20260706-the-night-feeling/stl_1.webp" alt="St. Louis skyline at night with the Gateway Arch and a lit KPMG building"><figcaption><span class="figure-number">Figure 4: </span>St. Louis skyline</figcaption></figure>
<figure><img src="https://img.cleberg.net/blog/20260706-the-night-feeling/stl_2.webp" alt="Quiet city street facing a bright parking garage entrance at night"><figcaption><span class="figure-number">Figure 5: </span>Quiet city street</figcaption></figure>
<figure><img src="https://img.cleberg.net/blog/20260706-the-night-feeling/broncos.webp" alt="Neon Bronco's Hamburgers sign glowing over an empty street at night"><figcaption><span class="figure-number">Figure 6: </span>Bronco's at night</figcaption></figure>
<figure><img src="https://img.cleberg.net/blog/20260706-the-night-feeling/stoplights.webp" alt="Red traffic lights under a bright moon and power lines"><figcaption><span class="figure-number">Figure 7: </span>Moonlit stoplights</figcaption></figure>
<figure><img src="https://img.cleberg.net/blog/20260706-the-night-feeling/kc_1.webp" alt="Kansas City skyline at night with Union Station lit red"><figcaption><span class="figure-number">Figure 8: </span>Kansas City at night</figcaption></figure>
<figure><img src="https://img.cleberg.net/blog/20260706-the-night-feeling/flight.webp" alt="City lights seen from an airplane window at night"><figcaption><span class="figure-number">Figure 9: </span>City lights from the plane</figcaption></figure>
<p>I travel a fair amount for my company, which leaves me with the task of finding food at odd hours and gives me a reason to explore the cities I visit.</p>
<p>Other than work, this feeling blends into city nights, where people are awake and businesses are open somewhere near me. I've lived near downtown twice so far, which led to many nighttime adventures when I was bored or couldn't sleep. Sometimes a walk helps me think and get ready to sleep.</p>
<h2 id="night-weather"><span class="section-number-2">4.</span> Night Weather</h2>
<p>Weather changes the whole shape of nighttime. I've talked about snow, but there are several kinds of weather that make the night better.</p>
<figure><img src="https://img.cleberg.net/blog/20260706-the-night-feeling/fog.webp" alt="Foggy residential street lit by a hazy streetlight at night"><figcaption><span class="figure-number">Figure 10: </span>Foggy streetlight</figcaption></figure>
<figure><img src="https://img.cleberg.net/blog/20260706-the-night-feeling/rain.webp" alt="Rain falling over a wet apartment parking lot at night"><figcaption><span class="figure-number">Figure 11: </span>Rain outside the apartment</figcaption></figure>
<figure><img src="https://img.cleberg.net/blog/20260706-the-night-feeling/kc_2.webp" alt="Kansas City sidewalk outside a lit restaurant at night"><figcaption><span class="figure-number">Figure 12: </span>Late ramen walk</figcaption></figure>
<p>I currently live close enough to several rivers that produce fog, which rolls through my neighborhood and creates dramatic nighttime effects.</p>
<p>And my favorite: rain. Rain hitting the roof overnight is probably my favorite version of it.</p>
<p>Weather gives the night permission to become even quieter. Rain makes staying still feel natural. Fog makes familiar streets feel temporarily removed from the ordinary world. Cold air makes lit windows, warm cars, and late meals feel more intimate than they would during the day.</p>
<h2 id="closing-thoughts"><span class="section-number-2">5.</span> Closing Thoughts</h2>
<p>During the day, everything has a role attached to it. Work, errands, messages, bills, conversations, traffic, noise. At night, those things lose some of their authority. The same streets are still there, but they feel less owned by everyone else.</p>
<p>The strange part is how consistent it has been. Nearly everything in my life has changed: rooms, cars, people, locations, climate - but the feeling stayed the same.</p>
<p>I don’t think I love the night because it is dark. I think I love it because it gives everything more space. My responsibilities melt away and I'm left with a strange and unique freedom.</p>
<p>The world is still there. It just lowers its voice.</p>
]]></description>
    </item>
    <item>
      <title>The Internet I Grew Up With Doesn’t Exist Anymore</title>
      <link>https://cleberg.net/blog/internet.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/internet.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Mon, 29 Jun 2026 00:00:00 +0000</pubDate>
      <category>personal</category>
      <category>web</category>
      <description><![CDATA[<h2 id="introduction"><span class="section-number-2">1.</span> Introduction</h2>
<p>The internet; what can I say? It's the driving force behind nearly the whole world today - economies, countries, communities, and more run solely on the internet these days.</p>
<p>However, it wasn't always this way.</p>
<p>Once upon a time, the internet didn't even exist. When it did, the internet was a <strong>place</strong>. It was a place you went. You selectively chose to visit the internet, based on your own free will.</p>
<p>If you wanted to visit a chat room, or perhaps preview a fancy new Flash game, you visited the internet for a few minutes in the evening before going back to your family or friends.</p>
<p>This has changed dramatically in the last 20-30 years. Today, it's 2026 and woven into nearly every part of daily life for the majority of the Earth's population.</p>
<p>Let's do a quick checklist and see what requires the internet or becomes tedious if we opt not to use the internet (yes, this list is tedious on purpose):</p>
<ul>
<li>Banking</li>
<li>Paying bills</li>
<li>Taxes</li>
<li>Shopping</li>
<li>Watching TV or movies</li>
<li>Listening to music</li>
<li>Reading the news</li>
<li>Looking up directions</li>
<li>Ordering food</li>
<li>Booking travel</li>
<li>Messaging friends and family</li>
<li>Video calls</li>
<li>Playing most modern video games</li>
<li>Downloading software updates</li>
<li>Activating new devices</li>
<li>Backing up photos</li>
<li>Storing files</li>
<li>Finding a restaurant</li>
<li>Reading reviews</li>
<li>Checking the weather</li>
<li>Looking up a recipe</li>
<li>Researching almost anything</li>
<li>Applying for a job</li>
<li>Remote work</li>
<li>School and homework</li>
<li>Medical records</li>
<li>Scheduling appointments</li>
<li>Government services</li>
<li>Renewing licenses</li>
<li>Filing insurance claims</li>
<li>Managing investments</li>
<li>Home security cameras</li>
<li>Smart home devices</li>
<li>Navigation in your car</li>
<li>Finding a phone number</li>
<li>Dating</li>
<li>Selling used items</li>
<li>Buying event tickets</li>
<li>Boarding a flight</li>
<li>Receiving package updates</li>
<li>Authentication (2FA)</li>
<li>Password management</li>
<li>Identity verification</li>
</ul>
<p>What a list. How fun. I love being absolutely restricted to a specific technology or method with little to no options.</p>
<p>Joking aside, this post is my personal reflection of the internet, and perhaps tech and life in general, over my lifetime. I was born in the late 1990s, but was also born in a rural area of the USA, so I have been privileged to see technology evolve from the "my stereo is the highest tech equipment in my house" stage to the "I have all of human history in my pocket" stages.</p>
<p>This post is about remembering these moments from my perspective, regardless of whether the evolutions have been good or bad.</p>
<p>As you read on, <strong>please</strong> (<strong>PLEASE!</strong>) send me an email if this post sparks a memory or you have thoughts. I genuinely enjoy hearing these stories from anyone, and I push for you to send them to me as you think of them.</p>
<h2 id="2001-the-family-computer"><span class="section-number-2">2.</span> 2001: The Family Computer</h2>
<p>The family computer. What a throwback. Perhaps you even had a <a href="https://en.wikipedia.org/wiki/Third_place">third place</a> computer you visited. Wherever, whatever that computer was - think of that computer as you read this. I will be speaking from my perspective and I hope it resonates with someone out there.</p>
<p>I recall coming home from school, getting through required chores, homework, or anything else first. Perhaps you had siblings with which you shared the computer or the TV.</p>
<p>In my case, we owned an early 2000s Gateway tower PC. A beautiful (read: ugly), beige Gateway computer with the spotted cow on it. It sat on a big "oak" hutch, with integrated file-compatible drawers and specific spots for your matching beige desktop speakers.</p>
<figure><img src="https://img.cleberg.net/blog/20260627-internet/gateway.webp" alt="Gateway Ad from 1992"><figcaption><span class="figure-number">Figure 1: </span>Gateway Ad from 1992</figcaption></figure>
<p>To use the computer, you likely turned on a very heavy CRT monitor. Perhaps it even flickered, emitted you a static buzz, or showed a wavy pattern in the graphics. This was the epitome of 2000s technology and people loved it.</p>
<blockquote>
<p><strong>Side note</strong>: We owned a heavy, wooden CRT TV set from the 1970s or 1980s that hid all buttons behind a fake, black "speaker" that you could press to pop open. A decade or two after we had tossed this TV into our barn for disposal, my brother and I took turns hitting the glass screen as hard as we could with a baseball bat.</p>
<p>It never left a mark, regardless of how hard we hit it. Why don't we produce that quality anymore?</p>
</blockquote>
<p>If you wanted to use the computer, you had to press a very heavy, circular button that would emit a memorable CLUNK as you engaged the button within the PC. This would result in an airplane level of whirring while it used maybe a few MB of memory and hard drive storage to boot up <a href="https://en.wikipedia.org/wiki/Windows_95">Windows 95</a>.</p>
<figure><img src="https://img.cleberg.net/blog/20260627-internet/windows95.webp" alt="Windows 95 Desktop"><figcaption><span class="figure-number">Figure 2: </span>Windows 95 Desktop</figcaption></figure>
<p>At this point, the world was your oyster. You could do so many things that humans throughout history couldn't do:</p>
<ul>
<li>Open multiple programs <strong>at the same time</strong>. Scientists were baffled.</li>
<li>Minimize a window, then bring it back later. Pure sorcery.</li>
<li>Move files by dragging them with your mouse. We truly lived in the future.</li>
<li>Change the color of every pixel in <strong>Paint</strong>. Michelangelo could never.</li>
<li>Hear your speakers make a loud POP every time Windows started. Reassuring.</li>
<li>Watch a progress bar slowly fill from left to right while estimating "time to complete" at 800 years. Entertainment for the whole family.</li>
<li>Crash the entire computer because you opened one too many programs. Unlimited power comes with responsibility.</li>
</ul>
<p>If you were luckier than I was, you also had access to the <strong>INTERNET</strong> at this point. The cyberspace where you transmitted your energy through hyperwaves to digital ends of the earth (i.e., sent a message to a stranger).</p>
<p>My family had a dial-up modem until the mid-2000s, so I was rarely to use the internet at this point. The extent of my experience spanned between our family computer (used for games, documents, and wasting time exploring every single menu and application available in Windows) and the church computer lab (containing even older computers, somehow).</p>
<p>At this point, there was no ritual to the internet or even to the computer itself. The computer was a tool used for specific tasks, such as my mother designing pamphlets in some obscure program for printing, or for fun.</p>
<p>Oftentimes, you would sit down with no particular destination. You were <strong>exploring</strong>. I use that word specifically because it's how I truly felt. Whenever I turned on a computer, I was exploring a digital universe that had not been charted before.</p>
<p>At this point, the internet was a distinct place you visited. Or, could ignore. If you didn't like computers or the internet, no worries. You could ignore it as much as you'd like.</p>
<h2 id="2004-exploring-the-web"><span class="section-number-2">3.</span> 2004: Exploring the Web</h2>
<p>The internet stopped feeling like software.</p>
<p>It became its own world.</p>
<p>This is the point in my life where the internet became real. I wasn't a pioneer by any means, unless we're talking about <a href="https://en.wikipedia.org/wiki/The_Oregon_Trail_(1971_video_game)">The Oregon Trail</a>, but I was willing to test and brute force any system through sheer curiosity, from a very early age.</p>
<p>At this time, we launched <a href="https://en.wikipedia.org/wiki/Internet_Explorer">Internet Explorer</a> and loaded up your favorite search engine. Perhaps it was Yahoo!, Altavista, MSN, Google, or something else.</p>
<p>This was probably your home page, your default search engine in the browser, and had an annoying toolbar installed on top of the browser itself. If you were silly enough (like me), you had numerous toolbars that sacrificed valuable screen space for the sake of <em>nothing</em>.</p>
<p>Suddenly, you could find almost anything ever uploaded to the internet. Some options could be:</p>
<ul>
<li>A walkthrough for the level you were stuck on.</li>
<li>A fan site dedicated to your favorite TV show.</li>
<li>A forum with 12 members arguing about phreaking.</li>
<li>A Flash game that somehow consumed your entire afternoon.</li>
<li>Someone's personal blog documenting their life in excruciating detail.</li>
</ul>
<p>More than this, the internet always felt <strong>enormous</strong> at this stage. No matter how much you explored, searched, or cataloged, you never had the full image. The internet was endless, borderless, and expansive. There was always a new rabbit hole waiting for you. Even if you had to watch every image slowly appear one horizontal line at a time.</p>
<p>Before moving on to the next section, do you remember the <a href="https://www.spacejam.com/1996/">1996 Space Jam website</a>? What a modern marvel. Honestly one of the world's wonders.</p>
<h2 id="2007-living-there"><span class="section-number-2">4.</span> 2007: Living There</h2>
<p>Here we are. The part of this post I recall most vividly. The mid-2000s were a phenomenal time in my personal history, as they were my transformative years. As it relates to computing and the internet, this means that the mid-2000s were the years of my utmost exploration, exploitation, and emancipation.</p>
<p>Where do I even start? Perhaps we start with the state of the internet and what exactly was available online. Perhaps this is triggering for certain readers, and I apologize if it is, but it is the way the internet was at the time.</p>
<p>If you wanted to see gruesome videos of executions, suicides, or the pain olympics, all it took was a single search and your search engine would happily return any results relevant to the words you typed.</p>
<p>If you wanted to share information over the internet at this point, you probably had an email from a site like AOL, Hotmail, Yahoo, Gmail, or your ISP (Roadrunner, anyone?). Additionally, at this point, webmail clients were extremely popular and most users would launch the webmail clients from their providers to participate in email.</p>
<p>Those of us who were <em>cool</em> used things like MSN Messenger, AIM, etc. to chat quickly without having to use an email. You could even use little pictures that provided emotional reactions for you! Oh my goodness, what a time.</p>
<figure><img src="https://img.cleberg.net/blog/20260627-internet/msn_emojis.webp" alt="MSN Messenger Emoticons"><figcaption><span class="figure-number">Figure 3: </span>MSN Messenger Emoticons</figcaption></figure>
<p>Beyond chatting, the next big thing coming in the digital space was gaming. At this time, it was seen as perhaps a silly side-hobby for some. While there may have been some money in it for a few select games, most were not profitable - they were created for other reasons, such as genuine intrigue in mechanics, users' fun, and curiosity.</p>
<p>Games and game companies like <a href="https://en.wikipedia.org/wiki/RuneScape">Runescape</a>, <a href="https://en.wikipedia.org/wiki/Miniclip">Miniclip</a> (8 Ball Pool, Agar.io, Doodle Army), <a href="https://en.wikipedia.org/wiki/Club_Penguin">Club Penguin</a>, <a href="https://en.wikipedia.org/wiki/Wizard101">Wizards 101</a>, and more dominated the scene in the mid-2000s.</p>
<p>Beyond gaming, this was the age of users learning how to launch their own blogs, vlogs, websites, and more.</p>
<p>For example, let's look at <a href="https://en.wikipedia.org/wiki/GeoCities">GeoCities</a> (1994-2009) and <a href="https://en.wikipedia.org/wiki/Tumblr">Tumblr</a> (2007-present). These websites rapidly evolved the internet's landscape, as they offered a free method for anyone to deploy a website or blog.</p>
<p>Imagine being a young person, or a high schooler, or a college student, or an adult in 2009. You have access to the internet and an interest in <em>something</em> out there in the world. You do a quick search and find a page related to it on GeoCities or Tumblr, leading you down a hyperlink rabbit hole.</p>
<p>If you were properly motivated at this time, you may wonder: "How do I do this? Can I create a page like this?" The answer was yes, and it was easy! A few minutes later, you could have your own site. There were few, if any, restrictions on what you could publish online.</p>
<p>This could lead you to learning HTML and CSS, as many users wanted to customize their sites, which generally leads to users discovering the freedom of owning their own sites. This included things like mail signatures, avatars, forum-specific usernames and more.</p>
<p>The end result? Everyone could have their own corner of the internet.</p>
<p>There was space for everyone and it was distinct. You could tell, both visually and otherwise, that a site belonged to someone specific. It was property, individually owned and updated by a human somewhere on Earth.</p>
<h2 id="2012-when-everything-started-changing"><span class="section-number-2">5.</span> 2012: When Everything Started Changing</h2>
<p>Let's jump forward to the early/mid-2010s. I used 2012 as an example because that's when I was in my first year of high school. At this time, you begin to understand a bit more about the world, log more long-term memories in the brain, and shift your perspectives.</p>
<p>Let's start by creating a perspective of the world's technology at this time:</p>
<ul>
<li>The iPhone 5 was released.</li>
<li>The first iPad Mini was released.</li>
<li>The Wii U was released.</li>
<li>Windows 8 &amp; macOS Mountain Lion were the primary operating systems.</li>
<li>YouTube, Tinder, &amp; Vine ruled the digital landscape.<ul>
<li>Perhaps you even watched Gangnam Style on YouTube this year.</li>
</ul>
</li>
</ul>
<p>At this time, Facebook continued to cannibalize the internet. Each year, including 2012, Facebook consumed pages and converted websites into pages on their own website. Games, the app center, mobile apps, "pokes", and more slowly replaced other websites and communities on the web.</p>
<p><em>Twitter did the same thing around this time, to a lesser effect.</em></p>
<p>As part of this domination by the top web service providers, apps started quickly replacing URLs. It felt as if apps became a first-class citizen of the digital world and that they may actually be <strong>more</strong> preferential to launching a web-first service.</p>
<p>Paired with this app-first and centralized web was a preference for <strong>algorithms</strong> (<em>everyone shudder together</em>) which used data about a user to determine a precise factor of content for a user. Who cares about privacy at this point, right? Let's just mine the data, build the features, make our money, and figure the rest out later.</p>
<p>At the end of all this is a world where more users than ever are carrying smartphones, using apps over websites, using algorithms to find content, and circling around the socially-rewarding locations of the digital universe.</p>
<p>Personally… this felt like the beginning of the end. There was a short period in the mid-2000s to the 2010s where these apps were truly rewarding and valuable. They brought people together and we shared knowledge faster than ever.</p>
<p>However, there was a dark side to this revolution. As these apps progressed, and the underlying technologies progressed, the companies and investors driving these efforts took a turn. Efforts pushed into the world of micro-transactions, psychological rewards for utilizing a platform, profits over value, and a slow descent into a disregard for the users.</p>
<p>To me, that 2012 era was a turning point. You may personally love a different era (1980/1990s gamer, anyone? Any former phreaks out there?), but to me, it felt like we kept making leaps in technological capability until we reached the point of economic profitability in the 2000s-2010s era, where corporations, investors, and governments took a serious interest in controlling the internet.</p>
<p>From here on out, the digital landscape seems to have a more sinister appearance and effect on us.</p>
<h2 id="2026-logging-on-today"><span class="section-number-2">6.</span> 2026: Logging On Today</h2>
<p>Fast forward to today: 2026. You want to check the latest headlines in your browser (a simple task!):</p>
<ol>
<li>Turn on your computer - most likely Windows 10 or 11.</li>
<li>The computer nags you for updates.</li>
<li>Windows has installed more games and ad-infested apps you don't want.</li>
<li>Windows then advertises these new "features" to you via notifications.</li>
<li>You open your default browser - most likely Chrome.</li>
<li>When you do so, Edge nags you and asks if you want to switch to Edge?</li>
<li>The homepage of your browser is littered with ads, promotions, and other distractions.</li>
<li>You start typing the URL of your favorite news site or searching for it - <strong>but wait</strong>, your browser has some "recommendations" first, which seem like thinly-veiled advertisements.</li>
<li>If you searched instead of typing the URL directly, your browser (most likely Google) will show you an AI summary loosely related to your search but not really what you were looking for. Somewhere in the distance, a tree wilts.</li>
<li>Below the AI "summary", which somehow takes half of the page space, results are loaded. However, the top 3-5 are promoted results, which means they may or may not relate to your search but someone paid to have them included.</li>
<li><strong>FINALLY</strong>, below all of that, will be the "real" results. These have been predetermined by Google's search algorithm. At this point, you'd suspect it would be consistent or at least transparent, right? Wrong. It's a black box - don't ask any more questions.</li>
<li>You may click one, or maybe thirty, results before you find what you're looking for.</li>
<li>Great, a website with a real answer. But wait! You're not trustworthy because you haven't accepted every cookie and tracking beacon in the last decade. Therefore, you will have to solve a captcha that requires 13 iterations of clicking the "fastest animal" in an array of images, or worse, bikes in various countries.</li>
<li>Once you solve all that, there's a cookie banner waiting for you that gives you two options:<ol>
<li>Agree to all tracking (without seeing any information).</li>
<li>Or, "see more", where you will be presented with somewhere around 20 toggles to limit "legitimate interest" third-parties in the numbers of the hundreds to thousands, or be ignorant and just accept all.</li>
<li>If you don't wish to spend a week of human time reading the agreements of these various parties, you will eventually lose hope and click whichever button lets you access the website.</li>
</ol>
</li>
<li>Phew. Finally. We're on the site itself. <strong>Oh wait</strong> - another AI summary and maybe even an AI voice/podcast-style version of the article first? And it's the latest feature, so of course you'll be nagged to try it out.</li>
<li>Oh wait, you're interrupted again. This site requires age verification to view its contents. For some reason, another country's laws apply to you right now (spare me the legalese in your responses). Therefore, you will need to create an account, giving this company personal data again, and then upload your national ID or other identification to prove who you are.</li>
<li>Whoo! What an easy process that would inspire you to visit again. At this point, you can view the latest news article on the topic you were searching for. Unfortunately, this site is owned by the same group of people who own basically all news sites - ensuring you are reading the exact viewpoints they are looking to communicate.</li>
</ol>
<p>What's the common theme here? There's an expectation on us at every single step - proof of identification, proof of humanity, testing of their new features, consumption of their views, etc., etc., etc.</p>
<p>Pause too long on an ad because you're doing something in real life? Dang, seems like someone online made an impression on you and you will be shown that content religiously for months.</p>
<p>We are rarely, if ever, allowed to freely roam and consume content we search for or type in. There are innumerable layers of intermediaries impeding our digital navigation. At each step, you may feel as if there's another party extracting commercial value from your visit, your clicks, your eyes, your mouse, or your scrolls.</p>
<h2 id="the-internet-i-miss"><span class="section-number-2">7.</span> The Internet I Miss</h2>
<p>I'm going to yell at clouds now. Be prepared.</p>
<p>I miss the <em>old</em> web, the indie web. Where websites were authored by humans, even in some capacity underneath a corporation.</p>
<p>We had rudimentary tools to solve the riddle of discovery, but they were tools nonetheless. Want to discover and explore new sites? You had search options, such as early Google or Jeeves, or third-party tools. We had web rings, blogrolls, link lists, and other manually-curated pages to discover top-tier content.</p>
<p>We dealt with slow speeds, lack of early web security, and strangers because the internet offered so much opportunity. Over time, that opportunity has shrunk drastically and the cost of visiting the internet has both become mandatory, yet more expensive.</p>
<p>Finally, <em>no one</em> owned the internet. Sure, we can get into semantics of the DNS system and infrastructure, but the web - and specifically, content - quickly became decentralized after the early stages until the recent centralization of content.</p>
<p>I just miss being able to visit the web, find personal content from fellow internet explorers, and not spend the whole time avoiding the pitfalls of the modern web.</p>
<h2 id="closing"><span class="section-number-2">8.</span> Closing</h2>
<p>As I wrote this post, I went through many thoughts and emotions. One thought was that the internet, as we knew it, disappeared. However, I don't think it did. Rather, the experience of the internet disappeared.</p>
<p>I certainly don't want to go back to 2005, I just hope we don't lose the parts that made it feel worth exploring.</p>
]]></description>
    </item>
    <item>
      <title>I Don&#x27;t Maintain My Homelab</title>
      <link>https://cleberg.net/blog/homelab-maintenance.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/homelab-maintenance.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Fri, 26 Jun 2026 00:00:00 +0000</pubDate>
      <category>self-hosting</category>
      <description><![CDATA[<p>It's true. I <strong>don't</strong> maintain my homelab… it maintains itself.</p>
<p>Have I reached nirvana? Is this the ultimate goal of homelabbers? It seems that I've somehow automated myself out of a job (hobby?) by building a resilient homelab.</p>
<p>Let's figure out where it all went "wrong".</p>
<h2 id="infrastructure"><span class="section-number-2">1.</span> Infrastructure</h2>
<h3 id="server"><span class="section-number-3">1.1.</span> Server</h3>
<p>I have used a few different servers over the years, but have since consolidated all of my services onto a single server (<a href="https://cleberg.net/blog/server-build.html">build guide here</a>), reducing the complexity of my environment.</p>
<p>Because of the single-server setup, maintenance is down 75% (from four servers to one). Yes, clusters and hypervisors and hybrid cloud solutions are shiny and fancy and popular, but I just don't care for it. Instead, I have a single metal box I can pick up with my hands sitting in my basement.</p>
<p>I <em>do</em> have one more "server": a Raspberry Pi 4, but it uses Home Assistant OS, updates itself, and requires literally <strong>zero</strong> maintenance. Is that really a server? I guess, by technical definition. But it certainly doesn't feel like it; it feels like I've turned a potential server device into a self-sustaining IoT device instead.</p>
<h3 id="network"><span class="section-number-3">1.2.</span> Network</h3>
<p>Aside from the server itself, I have a mini rack of UniFi gear (server is in the same rack). A UniFi Dream Machine Pro, a switch, and a couple of access points (APs) constitute my personal data center sitting in my basement.</p>
<p>Again, it really just maintains itself. UniFi supports automatic and scheduled updates, allowing you to disconnect from any manual maintenance of the hardware. UniFi truly is a "set it and forget it" platform.</p>
<h2 id="software"><span class="section-number-2">2.</span> Software</h2>
<p>There's a single crontab line on my server, which runs all updates for my Docker services on a weekly basis.</p>
<pre><code class="language-none">0 0 * * 0 docker-update</code></pre>
<p>Which is an alias for:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="keyword control for shell">for</span><span class="meta group for shell"> d <span class="keyword control in shell">in</span> <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/docker/<span class="keyword operator regexp quantifier shell">*</span>/</span><span class="keyword operator logical continue shell">;</span> <span class="keyword control do shell">do</span> <span class="punctuation definition compound begin shell">(</span><span class="meta function-call shell"><span class="support function cd shell">cd</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">d</span></span><span class="punctuation definition string end shell">&quot;</span></span></span> <span class="keyword operator logical and shell">&amp;&amp;</span> <span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> docker compose pull</span> <span class="keyword operator logical and shell">&amp;&amp;</span> <span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> docker compose up<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>d</span></span><span class="punctuation definition compound end shell">)</span><span class="keyword operator logical continue shell">;</span> <span class="meta function-call shell"><span class="variable function shell">done</span></span></span></code></pre>
<p>I do run a few crontab schedules via the <code class="verbatim">root</code> user as well, to account for permission issues. These jobs are really just for backups, to be honest. I've never required a backup, but it's good to be safe.</p>
<pre><code class="language-none"># Generate a daily system report
0 8 * * * /home/cmc/daily_sys_report.sh

# Backup
SHELL=/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

## App-aware database dumps
45 1 * * * mkdir -p /tank/cloud/server/backups/immich &amp;&amp; sudo docker exec -t immich_postgres pg_dumpall -U postgres &gt; /tank/cloud/server/backups/immich/immich-postgres-$(date +\%F).sql
50 1 * * * mkdir -p /tank/cloud/server/backups/piped &amp;&amp; sudo docker exec -t piped-postgres pg_dumpall -U piped &gt; /tank/cloud/server/backups/piped/piped-postgres-$(date +\%F).sql

## Backup files to ZFS pool
0 2 * * * rsync -aHAX --delete /var/lib/plexmediaserver/ /tank/cloud/plexmediaserver/
5 2 * * * rsync -aHAX --delete /var/www/ /tank/cloud/server/web_server/
10 2 * * * rsync -aHAX --delete /etc/nginx/ /tank/cloud/server/nginx/
15 2 * * * rsync -aHAX --delete --exclude='**/postgres/' --exclude='**/postgresql/' --exclude='**/mysql/' --exclude='**/mariadb/' --exclude='**/redis/' --exclude='**/valkey/' --exclude='**/database/' --exclude='**/cache/' --exclude='**/tmp/' --exclude='**/logs/' /home/cmc/docker/ /tank/cloud/server/docker/
20 2 * * * rsync -aHAX --delete /home/cmc/.ssh/ /tank/cloud/server/ssh/</code></pre>
<p>Aside from this, the only other required updates are running <code class="verbatim">apt update</code> and potentially restarting. This requires about 60 seconds of time whenever I want to do it.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> apt update</span> <span class="keyword operator logical and shell">&amp;&amp;</span> <span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> apt upgrade<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>y</span></span> <span class="keyword operator logical and shell">&amp;&amp;</span> <span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> apt autoremove<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>y</span></span></span></code></pre>
<h2 id="the-outcome"><span class="section-number-2">3.</span> The Outcome</h2>
<p>So, what's the end result? I've approximated it somewhere around <em>15 minutes of maintenance per month</em>, barring an emergency.</p>
<p>If that's normal to you, congrats - you've peaked in life. However, that's <strong>absolutely absurd</strong> to me. I used to spend days on end building, maintaining, and debugging various aspects of my servers, databases, apps, etc.</p>
<p>You know what's even crazier? If I don't have 15 minutes in a month to <code class="verbatim">ssh</code> into my server and update things, it literally does not affect anything. I could probably go 6 months (maybe more?) without touching it and it wouldn't break.</p>
<p><em>(This is not a challenge, please don't break my server.)</em></p>
<p>What a great situation to be in - especially for someone who's become as busy in their career as I have. I feel like I've struck a fantastic balance between privacy, security, and convenience.</p>
]]></description>
    </item>
    <item>
      <title>Junited 2026</title>
      <link>https://cleberg.net/blog/junited.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/junited.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Thu, 18 Jun 2026 00:00:00 +0000</pubDate>
      <category>web</category>
      <description><![CDATA[<p>Like others participating in <a href="https://robertbirming.com/junited/">Junited</a> have mentioned, I recently discovered this project and love the idea. While the month is more than halfway past, I'll make sure to update this post with the best links I discover throughout the remainder of June 2026.</p>
<ul>
<li><a href="https://hypersubject.net/entries/2026/06/smallweb-is-becoming-an-archipelago/">Smallweb is Becoming an Archipelago</a>: Coincidentally, I browse most of these websites as well.</li>
<li><a href="https://xvw.lol/en/articles/emacs-start.html">Emacs, how it all started (for me)</a>: I <strong>love</strong> hearing stories about Emacs, especially from beginners.</li>
<li><a href="https://nelson.cloud/.gitignore-isnt-the-only-way-to-ignore-files-in-git/">.gitignore Isn’t the Only Way To Ignore Files in Git</a>: Interesting if you're often using Git.</li>
<li><a href="https://www.lesswrong.com/posts/6Xgy6CAf2jqHhynHL/what-2026-looks-like">What 2026 looks like</a>: A <em>beautiful</em> web page describing the author's predicted future for 2022-2026.</li>
<li><a href="https://milek7.pl/mailverifyspam/">Don’t verify email addresses by sending spam to them</a>: <em>sigh…</em></li>
<li><a href="https://danielle.bearblog.dev/apparently-im-not-a-woman-because-i-use-linux/">Apparently I'm not a woman because I use Linux</a>: Let's continue breaking down walls. There will always be stupid around anyway.</li>
<li><a href="https://inessential.com/2026/06/15/netnewswire-status.html">NetNewsWire Status</a>: One of my absolute favorite apps on iOS.</li>
<li><a href="https://en.wikipedia.org/wiki/Van_Halen_test">Van Halen Test</a>: One of my favorite concepts. I feel like my teachers used this often to trick students who wouldn't read through all instructions before starting their answers.</li>
<li><a href="https://www.greptile.com/blog/prs-on-openclaw">PR spam today looks like email spam in the early 2000s</a>: Have they considered simply writing terrible software like I do? Then no one will even care to contribute!</li>
<li><a href="https://expression.fire.org/p/the-papers-please-era-of-the-internet">The ‘papers, please’ era of the internet will decimate your privacy</a>: I feel like we've been warning the public of this message for a decade and yet, here we are. Still on the precipice.</li>
<li><a href="https://www.dotcom.press/history-of-domains">A Brief History of Domains</a>: A fantastic piece.</li>
</ul>
]]></description>
    </item>
    <item>
      <title>Bring MOTD to macOS</title>
      <link>https://cleberg.net/blog/macos-motd.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/macos-motd.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Mon, 01 Jun 2026 00:00:00 +0000</pubDate>
      <category>mac</category>
      <description><![CDATA[<h2 id="messages-of-the-day-motd"><span class="section-number-2">1.</span> Messages of the Day (<code class="verbatim">motd</code>)</h2>
<p>A <a href="https://en.wikipedia.org/wiki/Message_of_the_day">message of the day</a> is, in computer terms, a welcome message that provides information and may help users logging onto the system. This is useful for numerous reasons, depending on the system, such as community announcements, compliance requirements, contextual information for that system, etc.</p>
<p>In this post, I'll be walking through a simple way to generate a message of the day for macOS. You can see the end result in this screenshot below:</p>
<figure><img src="https://img.cleberg.net/blog/20260601-macos-motd/macos-motd.webp" alt="Terminal output of motd.sh showing the system and user information upon launching a new shell."><figcaption><span class="figure-number">Figure 1: </span>macOS message of the day</figcaption></figure>
<p>For an example of a system-provided <code class="verbatim">motd</code>, here's the <code class="verbatim">motd</code> on my Ubuntu server showing the server's default information and any relevant add-ons, such as the LAN cockpit URL:</p>
<figure><img src="https://img.cleberg.net/blog/20260601-macos-motd/ubuntu-motd.webp" alt="Terminal output of Ubuntu's default server message of the day, showing system information."><figcaption><span class="figure-number">Figure 2: </span>Ubuntu message of the day</figcaption></figure>
<h2 id="create-the-message"><span class="section-number-2">2.</span> Create the Message</h2>
<p>First, we need to create the message. In this example, I've created a custom shell script below that uses terminal formatting to generate a structured output. This script checks for:</p>
<ul>
<li>username</li>
<li>hostname</li>
<li>profile management</li>
<li>WiFi SSID</li>
<li>IP address</li>
<li>Mullvad status</li>
<li>battery status</li>
<li>uptime</li>
</ul>
<p>To do this, create a script in your user directory:</p>
<pre><code class="language-shell">nano ~/.motd.sh</code></pre>
<p>Then paste the content below and modify as needed:</p>
<pre><code class="language-shell">BOLD='\033[1m'
DIM='\033[2m'
RESET='\033[0m'

HOST=$(scutil --get ComputerName 2&gt;/dev/null || hostname)

IP=$(ipconfig getifaddr en0 2&gt;/dev/null || ipconfig getifaddr en1 2&gt;/dev/null)
IP=${IP:-unavailable}

SSID=$(networksetup -getairportnetwork en0 2&gt;/dev/null | sed 's/^Current Wi-Fi Network: //')
case "$SSID" in
  ""|"You are not associated with an AirPort network.")
    SSID="unavailable"
    ;;
esac

BATTERY=$(pmset -g batt 2&gt;/dev/null | awk -F'; *' '
  NR==2 {
    gsub(/^ +| +$/, "", $2)
    gsub(/^ +| +$/, "", $3)
    sub(/ present: true$/, "", $3)
    print $2 ", " $3
  }
')
BATTERY=${BATTERY:-unavailable}

UPTIME=$(uptime | sed 's/^.*up //; s/, [0-9]* user.*//; s/, load averages.*//')
UPTIME=${UPTIME:-unavailable}

if profiles status -type enrollment 2&gt;/dev/null | grep -qi "MDM enrollment: Yes"; then
  MANAGED="yes"
else
  MANAGED="no"
fi

VPN="unavailable"

if command -v mullvad &gt;/dev/null 2&gt;&amp;1; then
  STATUS=$(mullvad status 2&gt;/dev/null)
  VPN=$(printf '%s\n' "$STATUS" | head -1)
  VPN=${VPN:-unavailable}
fi

printf "\n"
printf "  ${DIM}%-14s${RESET}${BOLD}%s${RESET} ${DIM}%s${RESET}\n" "$USER" "$(uname -sr)"
printf "  ${DIM}%-14s${RESET}%s\n" "host" "$HOST"
printf "  ${DIM}%-14s${RESET}%s\n" "managed" "$MANAGED"
printf "  ${DIM}%-14s${RESET}%s\n" "wifi" "$SSID"
printf "  ${DIM}%-14s${RESET}%s\n" "ip" "$IP"
printf "  ${DIM}%-14s${RESET}%s\n" "mullvad" "$VPN"
printf "  ${DIM}%-14s${RESET}%s\n" "battery" "$BATTERY"
printf "  ${DIM}%-14s${RESET}%s\n" "uptime" "$UPTIME"
printf "\n"</code></pre>
<p>Finally, modify the script file to enable execution:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">chmod</span></span><span class="meta function-call arguments shell"> +x <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/.motd.sh</span></span></code></pre>
<h2 id="load-the-message"><span class="section-number-2">3.</span> Load the Message</h2>
<p>At this point, the script is ready. We simply need to tell macOS to execute it whenever the user launches a new shell.</p>
<p>To do this, open the <code class="verbatim">.zprofile</code> file and add a line referencing the script:</p>
<pre><code class="language-shell">nano ~/.zprofile</code></pre>
<pre><code class="language-none"># Display Message of the Day (MOTD)
./motd.sh</code></pre>
<p>All done! This method is easily customizable and allows for use of dotfile management systems, such as stow, since the files live in the user's home directory.</p>
]]></description>
    </item>
    <item>
      <title>Git Is Not GitHub</title>
      <link>https://cleberg.net/blog/git-is-not-github.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/git-is-not-github.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Wed, 20 May 2026 00:00:00 +0000</pubDate>
      <category>development</category>
      <description><![CDATA[<h2 id="git-is-not-github"><span class="section-number-2">1.</span> Git Is Not GitHub</h2>
<p>People often use "Git" and "GitHub" interchangeably. Sometimes it's for convenience, but often it's a genuine lack of clarity around these two concepts. I work with IT auditors daily and you'd be surprised how often I come back to explain this topic, which is why I've written an internal document and am rolling that into this blog post itself to share with a broader audience.</p>
<p>The simplest possible explanation I can provide is that Git is the version control system itself, while GitHub is one of many platforms that offer Git hosting, as well as custom features that improve functionality on top of Git (e.g., pull requests).</p>
<p>The distinction matters, especially in an audit context, because there are facts and features inherent to Git that should be clearly understood before thinking about the Git host. For an auditor, this affects decisions around risk assessment, procedures to obtain evidence, and documentation of control processes.</p>
<p>For example, a developer can create a commit in Git after changing some code or files with a repository. This does <strong>not</strong> automatically show that the change was reviewed, approved, tested, or deployed through the appropriate process(es).</p>
<h2 id="feature-comparison"><span class="section-number-2">2.</span> Feature Comparison</h2>
<p>Let's start by comparing features before we dive into the details. While this is not all-encompassing, it helps set the context for the discussion we're about to have.</p>
<table>
<thead>
<tr><th>Feature / activity</th><th>Git</th><th>Git host</th></tr>
</thead>
<tbody>
<tr><td>Track file changes</td><td>✓</td><td></td></tr>
<tr><td>Create commits</td><td>✓</td><td></td></tr>
<tr><td>View commit history</td><td>✓</td><td>✓</td></tr>
<tr><td>View file diffs</td><td>✓</td><td>✓</td></tr>
<tr><td>Create branches</td><td>✓</td><td></td></tr>
<tr><td>Merge branches</td><td>✓</td><td></td></tr>
<tr><td>Rebase commits</td><td>✓</td><td></td></tr>
<tr><td>Tag releases or versions</td><td>✓</td><td>✓</td></tr>
<tr><td>Clone a repository</td><td>✓</td><td></td></tr>
<tr><td>Push and pull changes</td><td>✓</td><td>✓</td></tr>
<tr><td>Store a shared remote repository</td><td></td><td>✓</td></tr>
<tr><td>Browse repository in a web UI</td><td></td><td>✓</td></tr>
<tr><td>Pull requests / merge requests</td><td></td><td>✓</td></tr>
<tr><td>Code review comments</td><td></td><td>✓</td></tr>
<tr><td>Reviewer approvals</td><td></td><td>✓</td></tr>
<tr><td>Branch protection rules</td><td></td><td>✓</td></tr>
<tr><td>Required status checks before merge</td><td></td><td>✓</td></tr>
<tr><td>User and team access management</td><td></td><td>✓</td></tr>
<tr><td>Repository admin roles</td><td></td><td>✓</td></tr>
<tr><td>Audit logs</td><td></td><td>✓</td></tr>
<tr><td>CI/CD pipelines</td><td></td><td>✓</td></tr>
<tr><td>Deployment environments</td><td></td><td>✓</td></tr>
<tr><td>Secrets / environment variables</td><td></td><td>✓</td></tr>
<tr><td>Issue tracking</td><td></td><td>✓</td></tr>
<tr><td>Project boards</td><td></td><td>✓</td></tr>
<tr><td>Security scanning / dependency alerts</td><td></td><td>✓</td></tr>
</tbody>
</table>
<blockquote>
<p>Git hosts vary by platform. GitHub uses "pull requests," while GitLab commonly uses "merge requests." The concept is similar, but the available controls, terminology, logs, and evidence differ by host.</p>
</blockquote>
<h2 id="git-tracks-the-history"><span class="section-number-2">3.</span> Git Tracks the History</h2>
<p>Now that we have looked at the feature comparison, let's dive into the details of both Git and Git hosts.</p>
<p><a href="https://git-scm.com">Git</a> is a distributed version control system. It is intended to track changes to files over time through a feature called a <strong>commit</strong>: a collection of changes to files since the last commit. Developers use it to create these commits, create branches, merge changes back into the primary branch, rebase work, tag versions, and inspect project history.</p>
<p>Git does not require GitHub, or any other hosting platform. It can run entirely on a developer's laptop. A repository can exist locally, on an internal server, on a shared network path, or on another Git host.</p>
<p>For example, I can create a local Git repository, expose it through the Git protocol, and share this info with a friend or coworker. Then, they can clone my repository and we can collaborate by making changes independently and using commits, branches, etc. to push changes back and forth with each other. In this scenario, there is <strong>no</strong> host and we are essentially a distributed network of our own.</p>
<p>At its core, Git answers technical history questions:</p>
<ul>
<li>What changed?</li>
<li>Who authored the change?</li>
<li>When was the change made?</li>
<li>What files were affected?</li>
<li>What does this version contain?</li>
<li>How did this branch differ from that branch?</li>
</ul>
<p>That is valuable, but it is not the whole development process. This is where Git hosts introduce useful, additional features on top of Git.</p>
<h2 id="git-hosts-add-the-workflow"><span class="section-number-2">4.</span> Git Hosts Add the Workflow</h2>
<p>A Git host stores Git repositories and adds collaboration, workflow, and governance features around them. In an audit or compliance context, this is where most of the controls originate that mitigate risks with the system development lifecycle (SDLC).</p>
<p>GitHub is the most familiar example, so I will use that in this post, but it is not the only one. Other Git hosts include GitLab, Bitbucket, Azure DevOps Repos, Sourcehut, Gitea, and Forgejo.</p>
<p>These platforms commonly add features such as:</p>
<table>
<thead>
<tr><th>Feature</th><th>Purpose</th></tr>
</thead>
<tbody>
<tr><td>Pull requests or merge requests</td><td>Propose changes, review them, and merge them into a target branch.</td></tr>
<tr><td>Code review comments</td><td>Allow reviewers to comment on specific lines, files, or overall changes.</td></tr>
<tr><td>Reviewer approvals</td><td>Record that one or more reviewers approved a proposed change before merge.</td></tr>
<tr><td>Branch protection rules</td><td>Restrict how important branches can be changed, such as preventing direct pushes or force pushes.</td></tr>
<tr><td>Required status checks</td><td>Require tests, builds, scans, or other checks to pass before a change can be merged.</td></tr>
<tr><td>User and team permissions</td><td>Control who can read, write, maintain, or administer repositories.</td></tr>
<tr><td>Audit logs</td><td>Record important administrative, access, repository, and workflow events.</td></tr>
<tr><td>Issue tracking</td><td>Track bugs, enhancements, tasks, and other development work items.</td></tr>
<tr><td>Project boards</td><td>Organize work items by status, priority, sprint, release, or team workflow.</td></tr>
<tr><td>CI/CD integrations</td><td>Build, test, package, or deploy code through automated pipelines.</td></tr>
<tr><td>Secrets management</td><td>Store sensitive values used by workflows, such as tokens, keys, and credentials.</td></tr>
<tr><td>Security scanning</td><td>Identify risks such as exposed secrets, vulnerable dependencies, and insecure code patterns.</td></tr>
</tbody>
</table>
<p>That is why the same Git repository can behave differently depending on where it is hosted. GitHub, GitLab, Bitbucket, Azure DevOps, and Sourcehut all support Git repositories, but their review workflows, permissions, logs, automation, and terminology differ.</p>
<h2 id="audit-implications"><span class="section-number-2">5.</span> Audit Implications</h2>
<p>Using GitHub as an example, let's walk through a common audit approach to the common change management (CM) or program development (PD) controls.</p>
<p>First, here are some common controls:</p>
<ul>
<li>Changes are reviewed and approved prior to deployment.</li>
<li>The repository is configured to:<ul>
<li>prevent force pushes;</li>
<li>require X approvals;</li>
<li>prevent approvals from the author or a person who committed within the pull request;</li>
<li>require testing to pass prior to merging;</li>
<li>include the relevant change ticket(s)/documentation.</li>
</ul>
</li>
<li>Users with development access are segregated from users with access to approve and deploy changes.<ul>
<li><em>OR</em>: Management performs a review on an XYZ basis to ensure deployed changes were authorized and appropriate.</li>
</ul>
</li>
<li>Management performs a review on an XYZ basis to ensure branch protection settings were not inappropriately modified.</li>
</ul>
<p>Now, where can we find this evidence? Let's step through each</p>
<ul>
<li>Normally, reviews and approvals can be found directly within the pull/merge request. For platforms such as GitHub, this platform enables code reviews, comments, feedback, and checks directly within the PR flow. In certain cases, this may be documented in a change ticket system and the ticket is referenced within the PR to prove that the PR was tested, reviewed, and approved prior to merging.</li>
<li>For configurations, GitHub supports both <a href="https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/managing-protected-branches/managing-a-branch-protection-rule">classic branch protection rules</a> and <a href="https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/managing-rulesets/about-rulesets">rulesets</a>, which can enforce all of the checks I mentioned above.</li>
<li>For access, it depends on the company's setup. They may be using GitHub Enterprise, which offers them more control over access, and teams can inspect the access inheritance through those Enterprise settings. Otherwise, non-enterprise GitHub organizations can show evidence of access at both the organization level and the repository level. Auditors can inspect the levels of access and inheritance to ensure that no users have the ability to develop changes, manage branch protections, approve changes, and deploy changes.</li>
<li>For branch protection settings, management can provide auditors with an export of the audit logs relevant to the in-scope repositories. This will show you if any events occurred that would have disabled or modified the branch protections in place.</li>
</ul>
<p>If you're inspecting a project where CI/CD pipelines matter, you can also dive into the team's configuration of their pipeline in terms of the logic, access to modify, and any relevant schedules or triggers.</p>
<h2 id="conclusion"><span class="section-number-2">6.</span> Conclusion</h2>
<p>Hopefully at this point, it's clear that Git is not GitHub. While they are related and can be confusing for non-developers, it's important to understand the distinction.</p>
<p>Without this understanding, everything can fall apart in your understanding, risk assessment, and scoping of an audit.</p>
]]></description>
    </item>
    <item>
      <title>Plain Text, Plain Language</title>
      <link>https://cleberg.net/blog/plain.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/plain.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Wed, 13 May 2026 00:00:00 +0000</pubDate>
      <category>emacs</category>
      <category>writing</category>
      <description><![CDATA[<h2 id="plain-text-won"><span class="section-number-2">1.</span> Plain Text Won</h2>
<p>There has been a battle around how to format and store text since computers were invented.</p>
<p>As computers moved to a more consumer-facing market, developers faced the challenge of determining the best way to store text. Early consumer software such as WordStar, WordPerfect, and Microsoft Word implemented proprietary document formats and rich-text systems, including binary word processor files and later formats such as RTF, to let users style, print, and exchange documents. These tools made sense for office work, but they also moved writing further away from the simplest representation of text: characters in a file.</p>
<p>Plain text never disappeared. It remained the foundation of source code, logs, configuration files, email, data formats, documentation, and the web. Now, with the rise of LLMs and agentic workflows, it feels even more obvious that plain text has won. Corporations may still save Word documents, share PowerPoints, and use other formats, but they are increasingly turning around and using agents to extract, summarize, transform, and rewrite that same content as Markdown or some other plain-text-adjacent format.</p>
<p>Whether another format is used somewhere along the way, the center of gravity is moving back toward text that can be read, searched, copied, diffed, transformed, and understood without specialized software.</p>
<h2 id="optimizing-for-usability"><span class="section-number-2">2.</span> Optimizing for Usability</h2>
<p>Great, Christian believes plain text won. So what?</p>
<p>Let's think about <em>why</em> we store documents and text.</p>
<p>For personal reasons, we may take notes, write stories and poems, send emails and messages of other types, post online, and any number of other reasons. For work, we do largely the same as we do personally, but we also create presentations, documents, memos, letters, notices, manuals, documentation, and other artifacts specific to our jobs. Doctors write prescriptions, architects create plans, auditors create working papers and reports, and so on.</p>
<p>Think about each of these and then imagine that each was produced by Word or another piece of software where the document can only be opened in that specific application. If you don't have access to the same application, whether due to cost, sanctions, licensing, operating system support, or another reason, you're effectively banned from ever viewing that document, even if it's expressly intended for you.</p>
<p>In contrast, a plain text document is accessible on every major platform available today. Modern browsers can open plain text files directly, depending on the file extension and browser settings, and desktop, server, and mobile operating systems are capable of opening these files with bundled editors or viewers. You don't have to install a separate application, accept a vendor's terms, or hope the original software still exists. You can open the file and read the content, even if lightweight markup has been applied to it.</p>
<h3 id="plain-text-markup"><span class="section-number-3">2.1.</span> Plain Text Markup</h3>
<p>More specifically, I want to talk about a few options beyond literal plain text. There are numerous markup languages that provide structure and formatting while remaining readable as text, but a few sit at the top.</p>
<ol>
<li><a href="https://orgmode.org">Org Mode</a>: Org is my personal favorite. While you need Emacs to experience the full functionality of Org's interactive components, Org files remain readable outside of Emacs because the syntax is still plain text.</li>
<li><a href="https://daringfireball.net/projects/markdown/">Markdown</a>: Markdown is the dominant lightweight markup language. It is used across AI tools, social media, documentation platforms, static site generators, and note-taking apps.</li>
<li><a href="https://en.wikipedia.org/wiki/TeX">TeX</a>: When you need a language that can handle advanced formatting requirements, such as mathematical expressions or chemical notation, TeX is the obvious choice.</li>
</ol>
<p>These languages introduce additional characters into a plain text document, but they do not usually detract from the readability of the document itself. They create documents that can be read directly for quick understanding or rendered by software that understands the markup syntax.</p>
<h2 id="plain-language"><span class="section-number-2">3.</span> Plain Language</h2>
<p>Great, we've established the benefits of plain text and optional markup, but that's only half of the battle.</p>
<p>A file can be open and still be opaque. I don't want to open your plain text document and struggle to understand the message.</p>
<p>It is entirely possible to write a Markdown document that is portable, durable, grep-able, and miserable to read. The format can be simple while the writing remains vague, dense, passive, or full of unexplained jargon.</p>
<p>That is where plain language matters.</p>
<p>Plain language is not simplistic language. It does not mean avoiding technical terms, removing nuance, or writing for the lowest possible reading level. It means writing so the intended reader can understand the point without doing unnecessary work.</p>
<p>In practice, that means:</p>
<ol>
<li>Use the simplest word that accurately communicates the idea.</li>
<li>Prefer direct sentences over inflated ones.</li>
<li>Define terms when the audience may not know them.</li>
<li>Put the main point before the supporting detail.</li>
<li>Avoid passive voice when the actor matters.</li>
<li>Remove filler that does not change the meaning.</li>
</ol>
<p>The same reasons I prefer plain text apply to plain language. Plain text removes technical friction. Plain language removes cognitive friction.</p>
<p>A proprietary document format can make content harder to open. Bad writing can make content harder to use.</p>
<h3 id="plain-text-without-plain-language"><span class="section-number-3">3.1.</span> Plain Text Without Plain Language</h3>
<p>Plain text gives you portability. It does not automatically give you clarity.</p>
<p>A README can be written in Markdown and still fail to explain what the project does. A runbook can be stored in Git and still assume tribal knowledge. An audit workpaper can be easy to archive and still fail to explain the conclusion. A policy can be available to every employee and still be written in a way that discourages anyone from reading it.</p>
<p>Have you ever read through a document or standard that is obviously meant to be accessible technologically and yet, you get nothing out of it? You could re-read it numerous times and never get an answer because the author was not focused on accessible language.</p>
<p>The file is accessible, but the meaning is not and that matters a lot. A document is not useful because it exists in an open format. It is useful when someone can read it, understand it, and act on it.</p>
<h3 id="plain-language-is-not-anti-technical"><span class="section-number-3">3.2.</span> Plain Language Is Not Anti-Technical</h3>
<p>Plain language does not mean removing technical precision. Sometimes the technical term is the clearest term.</p>
<p>For example, this is vague:</p>
<blockquote>
<p>The authentication subsystem exhibited anomalous behavior resulting in downstream workflow degradation.</p>
</blockquote>
<p>This is clearer:</p>
<blockquote>
<p>Login failed for some users, which blocked deployments that required approval.</p>
</blockquote>
<p>This is still technical, but plain:</p>
<blockquote>
<p>The CI runner could not authenticate to the package registry because the token expired.</p>
</blockquote>
<p>The goal is not to make everything casual. The goal is to make the writing carry the meaning directly.</p>
<h3 id="the-same-argument"><span class="section-number-3">3.3.</span> The Same Argument</h3>
<p>The argument for plain text and the argument for plain language are the same argument applied at different layers.</p>
<table>
<thead>
<tr><th>Plain text value</th><th>Plain language equivalent</th></tr>
</thead>
<tbody>
<tr><td>No proprietary format</td><td>No proprietary vocabulary</td></tr>
<tr><td>Easy to inspect</td><td>Easy to understand</td></tr>
<tr><td>Works anywhere</td><td>Works for more readers</td></tr>
<tr><td>Minimal tooling</td><td>Minimal friction</td></tr>
<tr><td>Long-term durable</td><td>Long-term interpretable</td></tr>
<tr><td>Easy to transform</td><td>Easy to act on</td></tr>
</tbody>
</table>
<p>Plain text is the storage layer and plain language is the interface. Or, said more <em>plainly</em>, plain text and plain language should depend on each other and neither should be ignored.</p>
<p>If the format is portable but the writing is opaque, you only solved half the problem.</p>
<h2 id="conclusion"><span class="section-number-2">4.</span> Conclusion</h2>
<p>Plain text gives information a longer life. It makes writing easier to store, move, search, version, inspect, and transform.</p>
<p>But plain text does not guarantee useful writing. You can put bad prose in a good format. You can store unclear decisions in Markdown. You can preserve vague notes forever. You can make a document technically accessible while leaving it practically unreadable.</p>
<p>Have you ever read a README clearly written by AI without any editing from the repository owner? It can quickly become nonsense as the AI tries to constrain its content to the best possible README standard, while it loses any meaning of the project itself.</p>
<p>That is why plain language belongs in the same conversation.</p>
<p>If the goal is durable, useful communication, the format and the writing have to serve the same purpose. Plain text keeps the document accessible. Plain language keeps the meaning accessible.</p>
]]></description>
    </item>
    <item>
      <title>Automating Backups with Zerobyte &amp; Cloudflare R2</title>
      <link>https://cleberg.net/blog/self-hosting-zerobyte.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/self-hosting-zerobyte.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Wed, 22 Apr 2026 00:00:00 +0000</pubDate>
      <category>self-hosting</category>
      <description><![CDATA[<p><a href="https://zerobyte.app">Zerobyte</a> is a slick backup solution you can self host. It's one of the easiest apps I've self hosted and the backup jobs are running smoothly.</p>
<p>In this post, I will show you how I've configured backups on my server to back up data to Cloudflare R2.</p>
<h2 id="installation"><span class="section-number-2">1.</span> Installation</h2>
<h3 id="docker"><span class="section-number-3">1.1.</span> Docker</h3>
<p>First, let's install the app with Docker Compose. Create a directory for your <code class="verbatim">compose.yml</code> file in a location you'll remember.</p>
<pre><code class="language-bash highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">mkdir</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/zerobyte</span>
<span class="meta function-call shell"><span class="support function cd shell">cd</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/zerobyte</span>
<span class="meta function-call shell"><span class="variable function shell">nano</span></span><span class="meta function-call arguments shell"> compose.yml</span></span></code></pre>
<p>Next, paste the following content into the <code class="verbatim">compose.yml</code> file. You may want to customize the <code class="verbatim">ports</code>, <code class="verbatim">environment</code>, and <code class="verbatim">volumes</code> sections.</p>
<pre><code class="language-yaml highlight"><span class="source yaml"><span class="string unquoted plain out yaml"><span class="entity name tag yaml">services</span></span><span class="punctuation separator key-value mapping yaml">:</span>
  <span class="string unquoted plain out yaml"><span class="entity name tag yaml">zerobyte</span></span><span class="punctuation separator key-value mapping yaml">:</span>
    <span class="string unquoted plain out yaml"><span class="entity name tag yaml">image</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string unquoted plain out yaml">ghcr.io/nicotsx/zerobyte:v0.30</span>
    <span class="string unquoted plain out yaml"><span class="entity name tag yaml">container_name</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string unquoted plain out yaml">zerobyte</span>
    <span class="string unquoted plain out yaml"><span class="entity name tag yaml">restart</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string unquoted plain out yaml">unless-stopped</span>
    <span class="string unquoted plain out yaml"><span class="entity name tag yaml">cap_add</span></span><span class="punctuation separator key-value mapping yaml">:</span>
      <span class="punctuation definition block sequence item yaml">-</span> <span class="string unquoted plain out yaml">SYS_ADMIN</span>
    <span class="string unquoted plain out yaml"><span class="entity name tag yaml">ports</span></span><span class="punctuation separator key-value mapping yaml">:</span>
      <span class="punctuation definition block sequence item yaml">-</span> <span class="string quoted double yaml"><span class="punctuation definition string begin yaml">&quot;</span>4096:4096<span class="punctuation definition string end yaml">&quot;</span></span>
    <span class="string unquoted plain out yaml"><span class="entity name tag yaml">devices</span></span><span class="punctuation separator key-value mapping yaml">:</span>
      <span class="punctuation definition block sequence item yaml">-</span> <span class="string unquoted plain out yaml">/dev/fuse:/dev/fuse</span>
    <span class="string unquoted plain out yaml"><span class="entity name tag yaml">environment</span></span><span class="punctuation separator key-value mapping yaml">:</span>
      <span class="punctuation definition block sequence item yaml">-</span> <span class="string unquoted plain out yaml">TZ=America/Chicago</span>
      <span class="punctuation definition block sequence item yaml">-</span> <span class="string unquoted plain out yaml">BASE_URL=https://zb.example.com</span>
      <span class="punctuation definition block sequence item yaml">-</span> <span class="string unquoted plain out yaml">APP_SECRET=...</span>
    <span class="string unquoted plain out yaml"><span class="entity name tag yaml">volumes</span></span><span class="punctuation separator key-value mapping yaml">:</span>
      <span class="punctuation definition block sequence item yaml">-</span> <span class="string unquoted plain out yaml">/etc/localtime:/etc/localtime:ro</span>
      <span class="punctuation definition block sequence item yaml">-</span> <span class="string unquoted plain out yaml">/var/lib/zerobyte:/var/lib/zerobyte</span>
      <span class="punctuation definition block sequence item yaml">-</span> <span class="string unquoted plain out yaml">/path/to/backup:/path/to/backup</span></span></code></pre>
<p>When you're done editing, launch the container.</p>
<pre><code class="language-bash highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> docker compose up<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>d</span></span></span></code></pre>
<p>At this point, you can access the app via <a href="http://localhost:4096">http://localhost:4096</a>.</p>
<h3 id="nginx"><span class="section-number-3">1.2.</span> Nginx</h3>
<p>If you want to be able to access the app remotely, you'll need to utilize something like a reverse proxy or tunneling software.</p>
<p>This example uses Nginx as a reverse proxy. To start, edit a configuration file in Nginx:</p>
<pre><code class="language-bash highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="support function cd shell">cd</span></span><span class="meta function-call arguments shell"> /etc/nginx/conf.d</span>
<span class="meta function-call shell"><span class="variable function shell">nano</span></span><span class="meta function-call arguments shell"> zb.conf</span></span></code></pre>
<pre><code class="language-conf">server {
    listen 80;
    server_name zb.example.com;
    location / { proxy_pass http://127.0.0.1:4096; }
}</code></pre>
<p>Once you've created the file, test your Nginx configuration and restart the web server.</p>
<pre><code class="language-bash highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> nginx<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>t</span></span> <span class="keyword operator logical and shell">&amp;&amp;</span> <span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> systemctl restart nginx.service</span></span></code></pre>
<p>If your version of Nginx uses the <code class="verbatim">sites-available</code> structure instead, do this:</p>
<pre><code class="language-bash highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="support function cd shell">cd</span></span><span class="meta function-call arguments shell"> /etc/nginx/sites-available</span>
<span class="meta function-call shell"><span class="variable function shell">nano</span></span><span class="meta function-call arguments shell"> zb</span>
<span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> Edit the file</span><span class="comment line number-sign shell">
</span><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> ln<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>s</span> /etc/nginx/sites-available/zb /etc/nginx/sites-enabled/zb</span></span></code></pre>
<p>You may also need to provision a TLS/SSL certificate and add a <code class="verbatim">443</code> block to your Nginx configuration above, if you wish to connect securely.</p>
<h2 id="configuration"><span class="section-number-2">2.</span> Configuration</h2>
<p>At this point, you will be able to access the app. Upon first login, you will need to create an administrator account.</p>
<p>I won't be diving fully into the setup process. I highly suggest reading the <a href="https://zerobyte.app/docs">Zerobyte Docs</a>. They are very helpful and will walk you through the setup for your provider.</p>
<h3 id="volumes"><span class="section-number-3">2.1.</span> Volumes</h3>
<p>First, create a volume. This is a file or directory on your server that you wish to back up. You can see I have two directories connected as volumes.</p>
<figure><img src="https://img.cleberg.net/blog/20260422-self-hosting-zerobyte/volumes_01.webp" alt="Volumes List"><figcaption><span class="figure-number">Figure 1: </span>Volumes List</figcaption></figure>
<p>When you create a volume, you will be able to dictate the name, path, and type.</p>
<p>Remember to add a <code class="verbatim">volume</code> in your <code class="verbatim">compose.yml</code> file to ensure it's available within the app!</p>
<figure><img src="https://img.cleberg.net/blog/20260422-self-hosting-zerobyte/volumes_02.webp" alt="Volume Configuration"><figcaption><span class="figure-number">Figure 2: </span>Volume Configuration</figcaption></figure>
<p>Finally, you can inspect the files within your volume.</p>
<figure><img src="https://img.cleberg.net/blog/20260422-self-hosting-zerobyte/volumes_03.webp" alt="Volume Files"><figcaption><span class="figure-number">Figure 3: </span>Volume Files</figcaption></figure>
<h3 id="repositories"><span class="section-number-3">2.2.</span> Repositories</h3>
<p>The next step is to connect to a remote repository. This example uses Cloudflare R2 buckets.</p>
<figure><img src="https://img.cleberg.net/blog/20260422-self-hosting-zerobyte/repositories_01.webp" alt="Repositories List"><figcaption><span class="figure-number">Figure 4: </span>Repositories List</figcaption></figure>
<p>Within this configuration page, you can see the <code class="verbatim">Configuration</code> section in the bottom-right detailing the connection information.</p>
<figure><img src="https://img.cleberg.net/blog/20260422-self-hosting-zerobyte/repositories_02.webp" alt="Repository Configuration"><figcaption><span class="figure-number">Figure 5: </span>Repository Configuration</figcaption></figure>
<p>When each backup runs, it produces a snapshot that you can view and explore.</p>
<figure><img src="https://img.cleberg.net/blog/20260422-self-hosting-zerobyte/repositories_03.webp" alt="Repository Snapshots"><figcaption><span class="figure-number">Figure 6: </span>Repository Snapshots</figcaption></figure>
<p>Within a snapshot, you can review information about the backup job that ran and produced the snapshot, as well as the files at that point in time.</p>
<figure><img src="https://img.cleberg.net/blog/20260422-self-hosting-zerobyte/repositories_04.webp" alt="Snapshot Details"><figcaption><span class="figure-number">Figure 7: </span>Snapshot Details</figcaption></figure>
<h3 id="backups"><span class="section-number-3">2.3.</span> Backups</h3>
<p>You can create any backup jobs (daily, weekly, monthly, specific days, or with a cron pattern). This allows you to specify:</p>
<ul>
<li>The volume to be backed up</li>
<li>The repository to back up to</li>
<li>The schedule</li>
<li>The files to back up (all will be backed up if nothing is specifically selected)</li>
<li>Include/exclude patterns</li>
<li>Retention policies</li>
<li>Custom restic patterns</li>
</ul>
<figure><img src="https://img.cleberg.net/blog/20260422-self-hosting-zerobyte/backups_01.webp" alt="Backup Jobs"><figcaption><span class="figure-number">Figure 8: </span>Backup Jobs</figcaption></figure>
<p>Within a backup job, you can configure the related notifications, snapshots, or back up, edit, or clean up the job.</p>
<figure><img src="https://img.cleberg.net/blog/20260422-self-hosting-zerobyte/backups_02.webp" alt="Backup Job Details"><figcaption><span class="figure-number">Figure 9: </span>Backup Job Details</figcaption></figure>
<h3 id="notifications"><span class="section-number-3">2.4.</span> Notifications</h3>
<p>Lastly, you can enable various notification channels to receive alerts when jobs start, fail, complete, etc.</p>
<p>I have used an SMTP email provider to send myself emails upon these points.</p>
<figure><img src="https://img.cleberg.net/blog/20260422-self-hosting-zerobyte/notifications.webp" alt="Notification Settings"><figcaption><span class="figure-number">Figure 10: </span>Notification Settings</figcaption></figure>
]]></description>
    </item>
    <item>
      <title>Announcing Hutch: An iOS Client for Sourcehut</title>
      <link>https://cleberg.net/blog/hutch-ios.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/hutch-ios.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Mon, 30 Mar 2026 00:00:00 +0000</pubDate>
      <category>development</category>
      <description><![CDATA[<h2 id="hutch"><span class="section-number-2">1.</span> Hutch</h2>
<p>I'm proud to announce that I've released my third (and, in my opinion, most useful) iOS app: Hutch.</p>
<h3 id="project-links"><span class="section-number-3">1.1.</span> Project Links</h3>
<p>I don't want to bury the lede, so let me start with links to the app and various project pages:</p>
<p><strong>Product</strong></p>
<ul>
<li><a href="https://apps.apple.com/us/app/hutch-for-sourcehut/id6760742299">App Store</a></li>
<li><a href="https://krz.sh/apps/hutch/">Website</a></li>
</ul>
<p><strong>Development</strong></p>
<ul>
<li><a href="https://gitbay.org/krz/hutch">Source</a></li>
<li><a href="https://krz.sh/apps/hutch/">Project</a></li>
<li><a href="https://gitbay.org/krz/hutch/issues">Issues</a></li>
</ul>
<h3 id="overview"><span class="section-number-3">1.2.</span> Overview</h3>
<p>Hutch is a mobile client for <a href="https://sourcehut.org">Sourcehut</a>, a development host &amp; forge. If you're not familiar with Sourcehut, it provides a long list of services:</p>
<ul>
<li>Git repositories</li>
<li>Mercurial repositories</li>
<li>CI/CD builds</li>
<li>Issue trackers</li>
<li>Mailing lists</li>
<li>Pastes/snippets</li>
<li>Static page hosting</li>
</ul>
<h3 id="features"><span class="section-number-3">1.3.</span> Features</h3>
<p>Hutch provides an interface for the following services:</p>
<ul>
<li><strong>Projects</strong>:<ul>
<li>Aggregate location to link repositories, tickets, &amp; lists together</li>
</ul>
</li>
<li><strong>Repositories</strong> (Git &amp; Mercurial):<ul>
<li>README summaries with rendering support for Markdown and Org-Mode</li>
<li>File trees</li>
<li>Commit logs</li>
<li>Branches &amp; tags</li>
<li>Artifacts</li>
<li>Settings</li>
</ul>
</li>
<li><strong>Trackers</strong>:<ul>
<li>Create new trackers</li>
<li>Create tasks within trackers</li>
<li>Comment on tasks</li>
<li>Manage assignments, labels, and resolution status</li>
</ul>
</li>
<li><strong>Builds</strong>:<ul>
<li>Submit a build manifest manually</li>
<li>Resubmit builds</li>
<li>Edit &amp; resubmit builds</li>
</ul>
</li>
<li><strong>Lists</strong>:<ul>
<li>View mailing list messages with built-in patch viewing support</li>
<li>Unified inbox view for unread threads</li>
</ul>
</li>
<li><strong>Pastes</strong>:<ul>
<li>Create new pastes with single files, multiple files, and visibility options</li>
<li>View, delete, and change visibility of existing pastes</li>
</ul>
</li>
<li><strong>Meta</strong>:<ul>
<li>Profile editing options for your avatar, email, URL, location, and bio</li>
<li>Add &amp; remove SSH and PGP keys</li>
<li>View your personal access tokens (PATs)</li>
<li>Enable/disable app-wide swipe actions</li>
</ul>
</li>
</ul>
<h3 id="roadmap"><span class="section-number-3">1.4.</span> Roadmap</h3>
<p>As this is a solo-dev project (and I'm not a full-time developer), the roadmap is flexible and may change based on feedback I receive or things I'm currently focused on.</p>
<p>At the time of posting, we're on <code class="verbatim">v2.5.2</code>. At this point in time, I have the following tagged on my roadmap:</p>
<ul>
<li>Enhance file content rendering (e.g., line numbers, syntax highlighting)</li>
<li>Search feature to load a specific user, project, or repository (e.g., <code class="verbatim">~hutch/REPO</code>) that the logged-in user doesn't own</li>
<li>Public project discovery for public projects</li>
</ul>
<h2 id="feedback-welcome"><span class="section-number-2">2.</span> Feedback Welcome!</h2>
<p>If you use Sourcehut and iOS, please give Hutch a try and let me know your thoughts!</p>
<p>If you find bugs or issues, feel free to file them in the <a href="https://gitbay.org/krz/hutch/issues">issues</a> tracker.</p>
]]></description>
    </item>
    <item>
      <title>Auditing AWS S3 Buckets</title>
      <link>https://cleberg.net/blog/auditing-aws-s3.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/auditing-aws-s3.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Tue, 03 Mar 2026 00:00:00 +0000</pubDate>
      <category>audit</category>
      <description><![CDATA[<p>This is the latest in my series of posts on auditing AWS, a cloud platform that has existed for around two decades but can still be a mystery to auditors who aren't familiar with how cloud platforms operate.</p>
<p>One of the older, and most popular, offerings from AWS is Simple Storage Service (S3), a scalable object storage service that can hold any type of data. With this ease of use comes risk.</p>
<p>Public S3 buckets are one of the most common and highest-profile AWS misconfigurations. The challenge for auditors is that "public" in S3 isn't a single setting. It's the combination of three separate controls, and a bucket can appear restricted at one layer while still being exposed at another.</p>
<p>This post walks through a script that checks all three layers for every bucket in the account and produces a CSV report.</p>
<p>The script used in this post is available at <a href="https://github.com/audit-labs/audit-tools/blob/main/applications/aws/aws_s3_buckets.sh">audit-labs/audit-tools</a>.</p>
<h2 id="background-how-s3-controls-public-access"><span class="section-number-2">1.</span> Background: How S3 Controls Public Access</h2>
<p>Let's start with the basics. Before running anything, it helps to understand the three layers the script checks and how they interact.</p>
<h3 id="public-access-block"><span class="section-number-3">1.1.</span> Public Access Block</h3>
<p>Public Access Block (PAB) is a set of four flags that can be applied at the account level, the bucket level, or both. When all four are enabled, they override any bucket policy or ACL that would otherwise grant public access.</p>
<p>The four flags are:</p>
<ul>
<li><code>BlockPublicAcls</code>: Prevents new ACLs that grant public access and ignores existing ones.</li>
<li><code>IgnorePublicAcls</code>: Ignores all public ACLs on the bucket.</li>
<li><code>BlockPublicPolicy</code>: Prevents bucket policies that grant public access.</li>
<li><code>RestrictPublicBuckets</code>: Restricts access to buckets with public policies to only AWS services and authorized users within the account.</li>
</ul>
<p>The script checks whether all four flags are enabled at the bucket level. If any one of them is missing or disabled, the bucket is marked <code>FALSE-VULNERABLE</code>. If PAB is missing entirely (no configuration exists at all), the bucket is marked <code>CRITICAL-MISSING</code>, which is the highest-risk state.</p>
<div class="note">
<p><strong>Note:</strong> While this script checks the bucket level PAB, an account-level PAB may exist as well. If it's enabled at the account level, the bucket is safe regardless of its individual settings.</p>
</div>
<h3 id="bucket-policy-status"><span class="section-number-3">1.2.</span> Bucket Policy Status</h3>
<p>AWS evaluates each bucket policy and exposes an <code>IsPublic</code> flag that reflects whether the policy grants public access. The script checks this flag directly using <code>get-bucket-policy-status</code>. If no bucket policy exists, this column shows <code>No Policy</code>, which is not a finding on its own. Rather, it's a data point that instructs you to keep looking at further evidence.</p>
<h3 id="acls"><span class="section-number-3">1.3.</span> ACLs</h3>
<p>S3 ACLs predate bucket policies and are largely considered legacy at this point, but they're still in use and still a source of public exposure. The script checks whether any ACL grants <code>READ</code> or <code>WRITE</code> permissions to the <code>AllUsers</code> group, which represents the public internet.</p>
<h3 id="how-the-three-layers-interact"><span class="section-number-3">1.4.</span> How the Three Layers Interact</h3>
<p>PAB is the highest authority. If PAB is fully enabled at the bucket level, it overrides any public bucket policy or ACL. This means a bucket can have a publicly permissive policy and still be safe, as long as PAB is fully restricted.</p>
<p>The reverse is also true. A bucket with no public policy and no public ACLs is still at risk if PAB is missing or incomplete, because nothing is in place to prevent a future policy or ACL change from exposing it.</p>
<h2 id="what-the-script-does"><span class="section-number-2">2.</span> What the Script Does</h2>
<p>The script lists every bucket in the account, determines each bucket's region, runs all three checks against it, and appends the results to a CSV file.</p>
<p>It runs in three steps for each bucket:</p>
<ol>
<li>Determines the bucket's region by trying <code>get-bucket-location</code> against a list of configured regions;</li>
<li>Checks PAB, bucket policy status, and ACLs independently;</li>
<li>Derives an <code>OverallPublicStatus</code> from the three checks and writes the row to <code>s3_full_public_access_audit.csv</code>.</li>
</ol>
<h2 id="prerequisites"><span class="section-number-2">3.</span> Prerequisites</h2>
<p>You'll need:</p>
<ul>
<li>AWS CLI installed (or access to CloudShell) and configured with credentials that have read access to <code>s3:ListAllMyBuckets</code>, <code>s3:GetBucketLocation</code>, <code>s3:GetBucketPublicAccessBlock</code>, <code>s3:GetBucketPolicyStatus</code>, and <code>s3:GetBucketAcl</code></li>
<li><code>jq</code> installed</li>
<li>The <code>AWS_REGIONS</code> variable in the script updated to include any regions your organization uses</li>
</ul>
<p>Check and update the region list at the top of the script before running:</p>
<pre><code class="language-bash highlight"><span class="source shell bash"><span class="variable other readwrite assignment shell">AWS_REGIONS</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell"><span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>us-east-1 us-west-2 eu-central-1 ap-southeast-2<span class="punctuation definition string end shell">&quot;</span></span></span></span></code></pre>
<p>Then run it:</p>
<pre><code class="language-bash highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">chmod</span></span><span class="meta function-call arguments shell"> +x aws_s3_buckets.sh</span>
<span class="meta function-call shell"><span class="variable function shell">./aws_s3_buckets.sh</span></span></span></code></pre>
<h2 id="deriving-overall-public-status"><span class="section-number-2">4.</span> Deriving Overall Public Status</h2>
<p>The most important logic in the script is how it combines the three checks into a single <code>OverallPublicStatus</code>. PAB is evaluated first and takes precedence:</p>
<pre><code class="language-bash highlight"><span class="source shell bash"><span class="keyword control if begin shell">if</span> <span class="support function test begin shell">[</span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">PAB_FULLY_RESTRICTED</span></span><span class="punctuation definition string end shell">&quot;</span></span> <span class="keyword operator logical shell">=</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>CRITICAL-MISSING<span class="punctuation definition string end shell">&quot;</span></span> <span class="support function test end shell">]</span></span><span class="keyword operator logical continue shell">;</span> <span class="keyword control if then shell">then</span>
    <span class="variable other readwrite assignment shell">OVERALL_PUBLIC_STATUS</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell"><span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>TRUE - PAB Missing (CRITICAL)<span class="punctuation definition string end shell">&quot;</span></span></span>
<span class="keyword control if elif shell">elif</span> <span class="support function test begin shell">[</span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">OVERALL_PUBLIC_STATUS</span></span><span class="punctuation definition string end shell">&quot;</span></span> <span class="keyword operator logical shell">!=</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>FALSE<span class="punctuation definition string end shell">&quot;</span></span> <span class="support function test end shell">]</span></span> <span class="keyword operator logical and shell">&amp;&amp;</span> <span class="support function test begin shell">[</span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">PAB_FULLY_RESTRICTED</span></span><span class="punctuation definition string end shell">&quot;</span></span> <span class="keyword operator logical shell">!=</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>TRUE<span class="punctuation definition string end shell">&quot;</span></span> <span class="support function test end shell">]</span></span><span class="keyword operator logical continue shell">;</span> <span class="keyword control if then shell">then</span>
    <span class="meta function-call shell"><span class="support function colon shell">:</span></span> <span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> Status already set by Policy or ACL check above</span><span class="comment line number-sign shell">
</span><span class="meta function-call shell"><span class="variable function shell">fi</span></span></span></code></pre>
<p>If PAB is fully restricted (<code>TRUE</code>), the overall status stays <code>FALSE</code> regardless of what the policy or ACL checks find. If PAB is missing entirely, the overall status is immediately set to critical. If PAB is present but incomplete (<code>FALSE-VULNERABLE</code>), the overall status reflects whatever the policy or ACL checks found.</p>
<h2 id="reading-the-output"><span class="section-number-2">5.</span> Reading the Output</h2>
<p>The script prints progress to the terminal as it runs and saves the full results to <code>s3_full_public_access_audit.csv</code>:</p>
<pre><code class="language-text">Starting FULL S3 Public Access Audit for the CURRENT account...
---
1. Retrieving all bucket names...
Processing bucket: 13bf5920-a09f-47bc-a75a-394a09f18d6a
  Region determined: eu-west-1
  Final Status: FALSE
Processing bucket: c67fa6bd-2fd5-4bc5-825d-587fb535bf2e
  Region determined: eu-west-1
  Final Status: FALSE
---
Audit Complete.
Final report saved to s3_full_public_access_audit.csv</code></pre>
<pre><code class="language-text">BucketName,Region,PAB_FullyRestricted,Policy_IsPublic,ACL_AllUsersRead,ACL_AllUsersWrite,OverallPublicStatus
13bf5920-a09f-47bc-a75a-394a09f18d6a,eu-west-1,FALSE-VULNERABLE,No Policy,FALSE,FALSE,"FALSE"
c67fa6bd-2fd5-4bc5-825d-587fb535bf2e,eu-west-1,TRUE,No Policy,FALSE,FALSE,"FALSE"</code></pre>
<figure><img src="https://img.cleberg.net/blog/20260303-auditing-aws-s3/output.webp" alt="Terminal output of aws_s3_buckets.sh showing the per-bucket audit results and CSV report."><figcaption><span class="figure-number">Figure 1: </span>S3 Public Access Audit Results</figcaption></figure>
<p>Here's how to read each column:</p>
<ul>
<li><code class="verbatim">PAB_FullyRestricted</code>: <code>TRUE</code> means all four PAB flags are enabled at the bucket level. <code>FALSE-VULNERABLE</code> means PAB exists but is incomplete. <code>CRITICAL-MISSING</code> means no PAB configuration exists at all.</li>
<li><code class="verbatim">Policy_IsPublic</code>: <code>true</code> means AWS has determined the bucket policy grants public access. <code>false</code> means it doesn't. <code>No Policy</code> means no bucket policy is attached.</li>
<li><code class="verbatim">ACL_AllUsersRead</code> / <code class="verbatim">ACL_AllUsersWrite</code>: <code>TRUE</code> means the bucket has an ACL granting that permission to the public internet. <code>FALSE</code> means it doesn't.</li>
<li><code class="verbatim">OverallPublicStatus</code>: <code>FALSE</code> means the bucket is not publicly accessible based on all three checks. <code>TRUE</code> values include the specific reason (e.g., <code>TRUE - ACL Read</code>, <code>TRUE - Policy</code>, <code>TRUE - PAB Missing (CRITICAL)</code>).</li>
</ul>
<p>Note the first bucket in the example above: <code>PAB_FullyRestricted</code> is <code>FALSE-VULNERABLE</code> but <code>OverallPublicStatus</code> is still <code>FALSE</code>. This means the bucket isn't currently public, but it's missing the PAB configuration that would prevent it from becoming public if a policy or ACL were changed.</p>
<h2 id="common-exceptions-and-false-positives"><span class="section-number-2">6.</span> Common Exceptions and False Positives</h2>
<ul>
<li><code class="verbatim">Static website hosting</code>: Buckets used for static website hosting are intentionally public. These will show up with <code>TRUE</code> overall status and public ACLs or policies. Confirm the business purpose with IT and document them as accepted exceptions rather than findings.</li>
<li><code class="verbatim">Policy_IsPublic with No Policy</code>: A <code>No Policy</code> result in the policy column is not a finding. It simply means no bucket policy is attached. The overall status depends on PAB and ACLs.</li>
<li><code class="verbatim">FALSE-VULNERABLE with FALSE overall status</code>: This is a configuration weakness rather than an active exposure finding. The bucket isn't currently public, but PAB is not fully enabled, meaning a future change could expose it. Write this up separately from buckets that are actively public, as the risk and remediation are different.</li>
<li><code class="verbatim">Cross-account or service-specific policies</code>: Some bucket policies grant access to specific AWS accounts or services (e.g., CloudFront, Config, ELB logging). AWS may flag these as <code>IsPublic</code> even though they're not publicly accessible in practice. Review the actual bucket policy before raising it as a finding.</li>
<li><code class="verbatim">Region coverage</code>: If a bucket's region isn't in the <code>AWS_REGIONS</code> list, the script can't determine its location and will skip it with a warning. Make sure the region list in the script covers your organization's full footprint before treating the CSV as a complete population.</li>
</ul>
<h2 id="how-to-write-up-the-finding"><span class="section-number-2">7.</span> How to Write Up the Finding</h2>
<p>There are two distinct finding types this script can surface, and they should be written up separately.</p>
<p><strong>Finding 1: Bucket with incomplete or missing PAB (configuration weakness)</strong></p>
<p><strong>Deficiency:</strong> S3 bucket <code>13bf5920-a09f-47bc-a75a-394a09f18d6a</code> does not have all four Public Access Block flags enabled at the bucket level (<code>PAB_FullyRestricted: FALSE-VULNERABLE</code>).</p>
<p><strong>Risk:</strong> Without fully enabled PAB, a future bucket policy or ACL change could expose the bucket to the public internet without additional controls in place to prevent it.</p>
<p><strong>Finding 2: Bucket actively accessible to the public</strong></p>
<p><strong>Deficiency:</strong> S3 bucket <code>example-bucket</code> has an ACL granting <code>READ</code> access to the <code>AllUsers</code> group (<code>ACL_AllUsersRead: TRUE</code>, <code>OverallPublicStatus: TRUE - ACL Read</code>).</p>
<p><strong>Risk:</strong> Publicly accessible S3 buckets expose any objects stored within them to the internet, potentially including sensitive data.</p>
<p>To filter the CSV to only buckets with a non-FALSE overall status:</p>
<pre><code class="language-bash highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">awk</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>F</span><span class="string quoted single shell"><span class="punctuation definition string begin shell">&#39;</span>,<span class="punctuation definition string end shell">&#39;</span></span> <span class="string quoted single shell"><span class="punctuation definition string begin shell">&#39;</span>NR==1 || $7 != &quot;\&quot;FALSE\&quot;&quot;<span class="punctuation definition string end shell">&#39;</span></span> s3_full_public_access_audit.csv</span></span></code></pre>
]]></description>
    </item>
    <item>
      <title>Auditing AWS Passwords</title>
      <link>https://cleberg.net/blog/auditing-aws-passwords.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/auditing-aws-passwords.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Sat, 21 Feb 2026 00:00:00 +0000</pubDate>
      <category>audit</category>
      <description><![CDATA[<p>One of the first controls an IT Auditor learns is how to audit passwords in any number of IT systems. However, things have changed with the introduction of cloud platforms. This post covers the process and results of auditing AWS passwords.</p>
<p>The scripts are available at <a href="https://github.com/audit-labs/audit-tools/tree/main/applications/aws/aws_password_policy">audit-labs/audit-tools</a>.</p>
<h2 id="scoping"><span class="section-number-2">1.</span> Scoping</h2>
<p>First thing first: scoping. To audit AWS passwords, we need to understand that AWS IAM password policies only apply to users with console access. This isn't the same as the password policy for an application built on top of AWS. It also has no effect on users who authenticate through IAM Identity Center, which delegates authentication to an external identity provider, such as Okta or Active Directory.</p>
<p>If the organization uses Identity Center exclusively and has no IAM users with passwords, you will need to perform a different procedure.</p>
<p>If they do have IAM users with console access, the script applies and is worth testing.</p>
<h2 id="what-the-scripts-do"><span class="section-number-2">2.</span> What the Scripts Do</h2>
<p>The process runs in two steps:</p>
<ol>
<li><code>gather_policy.sh</code> calls the AWS CLI to fetch the current IAM password policy, captures metadata (timestamp, AWS account, region, caller identity), and writes everything to a JSON file. This file is evidence of the policy's current state.</li>
<li><code>evaluate_policy.py</code> reads that JSON file, prompts you for the expected value of each setting, and exports a CSV report with a value of <code>PASS</code> or <code>FAIL</code> for each rule.</li>
</ol>
<h2 id="prerequisites"><span class="section-number-2">3.</span> Prerequisites</h2>
<p>To run this script, you'll need:</p>
<ul>
<li>Access to CloudShell or the AWS CLI utility installed and configured with credentials that have read access to <code>iam:GetAccountPasswordPolicy</code> and <code>sts:GetCallerIdentity</code></li>
<li><code>jq</code> installed (used by the Bash script to merge JSON objects)</li>
<li>Python 3 installed</li>
<li>Optional: <code>uv</code> installed (used to run the Python script)</li>
</ul>
<h2 id="step-1-gather-the-policy"><span class="section-number-2">4.</span> Step 1: Gather the Policy</h2>
<p>Run the first script to pull the current policy from AWS:</p>
<pre><code class="language-bash highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">chmod</span></span><span class="meta function-call arguments shell"> +x gather_policy.sh</span>
<span class="meta function-call shell"><span class="variable function shell">./gather_policy.sh</span></span></span></code></pre>
<p>By default, this writes the output to <code>policy_report.json</code> in the current directory. You can specify a custom path with the <code>-o</code> flag:</p>
<pre><code class="language-bash highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">./gather_policy.sh</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>o</span> /tmp/my_report.json</span></span></code></pre>
<p>The output is a JSON file with two top-level keys: <code>metadata</code> and <code>PasswordPolicy</code>.</p>
<pre><code class="language-json highlight"><span class="source json"><span class="meta structure dictionary json"><span class="punctuation section dictionary begin json">{</span>
  <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>metadata<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="meta structure dictionary json"><span class="punctuation section dictionary begin json">{</span>
    <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>report_timestamp_utc<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>2025-12-15T01:29:52Z<span class="punctuation definition string end json">&quot;</span></span><span class="punctuation separator dictionary pair json">,</span></span>
    <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>os_user<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>cloudshell-user<span class="punctuation definition string end json">&quot;</span></span><span class="punctuation separator dictionary pair json">,</span></span>
    <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>hostname<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span><span class="punctuation definition string end json">&quot;</span></span><span class="punctuation separator dictionary pair json">,</span></span>
    <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>working_directory<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>/home/cloudshell-user<span class="punctuation definition string end json">&quot;</span></span><span class="punctuation separator dictionary pair json">,</span></span>
    <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>aws_profile<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>default<span class="punctuation definition string end json">&quot;</span></span><span class="punctuation separator dictionary pair json">,</span></span>
    <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>aws_region<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>eu-west-1<span class="punctuation definition string end json">&quot;</span></span><span class="punctuation separator dictionary pair json">,</span></span>
    <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>aws_caller_identity<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="meta structure dictionary json"><span class="punctuation section dictionary begin json">{</span>
      <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>UserId<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>123456789012<span class="punctuation definition string end json">&quot;</span></span><span class="punctuation separator dictionary pair json">,</span></span>
      <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>Account<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>123456789012<span class="punctuation definition string end json">&quot;</span></span><span class="punctuation separator dictionary pair json">,</span></span>
      <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>Arn<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>arn:aws:iam::123456789012:root<span class="punctuation definition string end json">&quot;</span></span>
    </span><span class="punctuation section dictionary end json">}</span></span>
  </span><span class="punctuation section dictionary end json">}</span></span><span class="punctuation separator dictionary pair json">,</span></span>
  <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>PasswordPolicy<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="meta structure dictionary json"><span class="punctuation section dictionary begin json">{</span>
    <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>MinimumPasswordLength<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="constant numeric json">8</span><span class="punctuation separator dictionary pair json">,</span></span>
    <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>RequireSymbols<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="constant language json">true</span><span class="punctuation separator dictionary pair json">,</span></span>
    <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>RequireNumbers<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="constant language json">true</span><span class="punctuation separator dictionary pair json">,</span></span>
    <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>RequireUppercaseCharacters<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="constant language json">true</span><span class="punctuation separator dictionary pair json">,</span></span>
    <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>RequireLowercaseCharacters<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="constant language json">true</span><span class="punctuation separator dictionary pair json">,</span></span>
    <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>AllowUsersToChangePassword<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="constant language json">true</span><span class="punctuation separator dictionary pair json">,</span></span>
    <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>ExpirePasswords<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="constant language json">true</span><span class="punctuation separator dictionary pair json">,</span></span>
    <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>MaxPasswordAge<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="constant numeric json">90</span><span class="punctuation separator dictionary pair json">,</span></span>
    <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>PasswordReusePrevention<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="constant numeric json">4</span><span class="punctuation separator dictionary pair json">,</span></span>
    <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>HardExpiry<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="constant language json">false</span>
  </span><span class="punctuation section dictionary end json">}</span></span>
</span><span class="punctuation section dictionary end json">}</span></span></span></code></pre>
<p>The metadata block is what ties this evidence to a specific account and point in time. The <code>aws_caller_identity</code> field shows who ran the script and in which account.</p>
<figure><img src="https://img.cleberg.net/blog/20260221-auditing-aws-passwords/results.webp" alt="Terminal output of evaluate_policy.py showing the interactive prompts and pass/fail summary for each password policy rule."><figcaption><span class="figure-number">Figure 1: </span>Policy Evaluation Results</figcaption></figure>
<h2 id="step-2-evaluate-the-policy"><span class="section-number-2">5.</span> Step 2: Evaluate the Policy</h2>
<p>Pass the JSON file to the evaluation script:</p>
<pre><code class="language-bash highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">uv</span></span><span class="meta function-call arguments shell"> run evaluate_policy.py policy_report.json</span></span></code></pre>
<p>The script will prompt you for each of the ten settings. Press <code>Enter</code> to skip any setting you don't need to test. For numeric settings like <code>MinimumPasswordLength</code> and <code>MaxPasswordAge</code>, the script treats your input as a minimum, so the actual value must be greater than or equal to your expected value to pass. Boolean settings require an exact match.</p>
<pre><code class="language-text">=== Expected / Minimum Values (press &lt;Enter&gt; for N/A) ===

Enter expected value for 'Minimum password length' (int) or press &lt;Enter&gt; to skip: 8
Enter expected value for 'Require symbols (!@#$...)' (bool) or press &lt;Enter&gt; to skip: true
Enter expected value for 'Require numbers (0-9)' (bool) or press &lt;Enter&gt; to skip: true
Enter expected value for 'Require uppercase letters (A-Z)' (bool) or press &lt;Enter&gt; to skip: true
Enter expected value for 'Require lowercase letters (a-z)' (bool) or press &lt;Enter&gt; to skip: true
Enter expected value for 'Allow users to change password' (bool) or press &lt;Enter&gt; to skip: true
Enter expected value for 'Expire passwords (enable aging)' (bool) or press &lt;Enter&gt; to skip: true
Enter expected value for 'Maximum password age (days)' (int) or press &lt;Enter&gt; to skip: 90
Enter expected value for 'Prevent password reuse (last N)' (int) or press &lt;Enter&gt; to skip: 4
Enter expected value for 'Hard expiry (no grace period)' (bool) or press &lt;Enter&gt; to skip: false

Audit CSV written to: policy_audit_20251215T014323Z.csv

Summary:
   1. Minimum password length             -&gt; PASS
   2. Require symbols (!@#$...)           -&gt; PASS
   3. Require numbers (0-9)               -&gt; PASS
   4. Require uppercase letters (A-Z)     -&gt; PASS
   5. Require lowercase letters (a-z)     -&gt; PASS
   6. Allow users to change password      -&gt; PASS
   7. Expire passwords (enable aging)     -&gt; PASS
   8. Maximum password age (days)         -&gt; PASS
   9. Prevent password reuse (last N)     -&gt; PASS
  10. Hard expiry (no grace period)       -&gt; PASS

--- End of report ---</code></pre>
<h2 id="reading-the-csv"><span class="section-number-2">6.</span> Reading the CSV</h2>
<p>The CSV is your evidence. It includes the metadata header from the JSON file, so the account ID, timestamp, and caller identity are embedded directly in the file.</p>
<pre><code class="language-csv"># report_timestamp_utc: 2025-12-15T01:29:52Z
# os_user: cloudshell-user
# hostname:
# working_directory: /home/cloudshell-user
# aws_profile: default
# aws_region: eu-west-1
# aws_caller_identity: {'UserId': '123456789012', 'Account': '123456789012', 'Arn': 'arn:aws:iam::123456789012:root'}

Rule#,Policy-Item,Expected,Actual,Result
1,Minimum password length,8,8,PASS
2,Require symbols (!@#$...),true,true,PASS
3,Require numbers (0-9),true,true,PASS
4,Require uppercase letters (A-Z),true,true,PASS
5,Require lowercase letters (a-z),true,true,PASS
6,Allow users to change password,true,true,PASS
7,Expire passwords (enable aging),true,true,PASS
8,Maximum password age (days),90,90,PASS
9,Prevent password reuse (last N),4,4,PASS
10,Hard expiry (no grace period),false,false,PASS</code></pre>
<p>You may use this evidence in any form, but I suggest having your AWS contact screenshot the results directly within their CloudShell or AWS CLI session. This allows you to prove that the data was not modified after the script was run.</p>
<h2 id="common-exceptions-and-false-positives"><span class="section-number-2">7.</span> Common Exceptions and False Positives</h2>
<ul>
<li><strong>No policy defined</strong>: If <code>gather_policy.sh</code> exits with a <code>NoSuchEntity</code> error, the account has no IAM password policy configured. If you were expecting a password policy, document it as a missing control.</li>
<li><strong>HardExpiry: false</strong>: This setting controls whether users are locked out immediately when their password expires or given a grace period to change it. <code>false</code> is often intentional to avoid lockouts. Check the organization's policy before calling it a finding. Additionally, check if the organization has security exceptions in place before noting a deficiency.</li>
<li><strong>MaxPasswordAge and forced rotation</strong>: A 90-day rotation requirement is common in older policies and frameworks like CIS. NIST 800-63B no longer recommends forced rotation unless there's evidence of compromise. Know which framework you're auditing against before writing up a finding for this setting. Confirm with the organization to understand which framework they used to write their policy.</li>
<li><strong>PasswordReusePrevention</strong>: AWS allows a maximum of 24 previous passwords. If your organization's policy requires a higher number than AWS supports, document the platform limitation rather than raising it as a deficiency.</li>
</ul>
<h2 id="how-to-write-up-the-finding"><span class="section-number-2">8.</span> How to Write Up the Finding</h2>
<p>If a setting fails, here's how to frame it:</p>
<ul>
<li><strong>Deficiency:</strong> The <code>MinimumPasswordLength</code> setting in the AWS IAM password policy is configured to <code>6</code>, which is below the organization's requirement of <code>8</code> characters.</li>
<li><strong>Root Cause:</strong> Due to {{ root cause }}, the policy was configured to enforce a <code>MinimumPasswordLength</code> of <code>6</code>.</li>
<li><strong>Risk:</strong> Shorter passwords are more susceptible to brute-force and credential stuffing attacks, increasing the likelihood of unauthorized access to the AWS console.</li>
<li><strong>Evidence:</strong> Refer to <code>policy_audit_&lt;timestamp&gt;.csv</code> for documentation of testing.</li>
</ul>
<p>The same structure applies to any other failing rule. For boolean settings, the deficiency is simply that the actual value does not match the expected value. For numeric settings, the deficiency is that the actual value falls below the required minimum.</p>
]]></description>
    </item>
    <item>
      <title>Auditing AWS IAM Users</title>
      <link>https://cleberg.net/blog/auditing-aws-iam.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/auditing-aws-iam.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Sat, 21 Feb 2026 00:00:00 +0000</pubDate>
      <category>audit</category>
      <description><![CDATA[<p>If you've ever asked an IT team for a list of who has access to an AWS account, you've probably received a spreadsheet that was already out of date. Or worse, an out-of-context screenshot that doesn't explain anything. Or worse, they don't know either and ignore you, hoping you forget about the request (ask me how I know!).</p>
<p>To make it worse, IAM Identity Center doesn't make this easy to extract through the console, and most teams don't have a repeatable process for pulling it.</p>
<p>To solve this problem, this post walks through a script that does it for you and explains what to look for once you have the output. This is something I've used in practice and want to share, as cloud auditing knowledge seems scarce.</p>
<p>The script is available at <a href="https://github.com/audit-labs/audit-tools/blob/main/applications/aws/aws_iam_users.sh">audit-labs/audit-tools</a>.</p>
<h2 id="background-how-aws-provisions-access"><span class="section-number-2">1.</span> Background: How AWS Provisions Access</h2>
<p>Before running anything, it helps to understand the different ways AWS can be architected to grant access. You may encounter any one (or all) of these in practice, sometimes within the same organization. Knowing how they differ tells you where to look during an audit and which questions to ask.</p>
<h3 id="iam-users"><span class="section-number-3">1.1.</span> IAM Users</h3>
<p>This is the original AWS access model. An IAM user is an identity created directly inside a single AWS account (e.g., <code>iamuser1</code> created inside AWS user <code>cmc</code>). This type of account has a username, an optional console password, and optional access keys for programmatic access. Permissions are granted by attaching IAM policies directly to the user, or by adding the user to an IAM group that has policies attached to it.</p>
<p>The core problem with IAM users at scale is that they're account-scoped, meaning a user in <code>Account A</code> has no relationship to a user in <code>Account B</code>, even if they're the same person. Organizations with dozens or hundreds of accounts end up with a fragmented identity landscape that's difficult to review and even harder to deprovision consistently.</p>
<p>From an audit perspective, these are key risks to understand during your walkthrough of the environment. Additionally, you should note that IAM users are high-risk when they have active access keys (long-lived credentials that don't expire unless explicitly rotated or revoked) or when policies are attached directly to the user rather than inherited through a group.</p>
<h3 id="iam-groups"><span class="section-number-3">1.2.</span> IAM Groups</h3>
<p>IAM groups are a way to organize IAM users within a single account and attach policies to multiple users at once. A user inherits all permissions from every group they belong to. Groups themselves cannot assume roles or make API calls. They exist only as a convenience for managing user permissions in bulk.</p>
<p>Groups help with consistency, but they don't solve the cross-account problem. An IAM group in <code>Account A</code> still has no bearing on access in <code>Account B</code>. You'll see groups used alongside IAM users in the same environments where IAM users are prevalent.</p>
<h3 id="iam-roles"><span class="section-number-3">1.3.</span> IAM Roles</h3>
<p>Roles are the most flexible identity construct in AWS. Unlike users, roles aren't tied to a specific person. They're assumed temporarily by whoever (or whatever) is authorized to use them. When an entity assumes a role, AWS issues short-lived credentials that expire automatically, usually after an hour.</p>
<p>Roles are used in several contexts:</p>
<ul>
<li><strong>Cross-account access</strong>: <code>Account A</code> can grant a role in <code>Account B</code> the ability to be assumed by principals in <code>Account A</code>. This is how many organizations handle access across accounts without using IAM Identity Center.</li>
<li><strong>Service roles</strong>: AWS services like Lambda, EC2, and ECS use roles to make API calls on your behalf. An EC2 instance with an attached instance profile is assuming a role every time it calls an AWS API.</li>
<li><strong>Federated access</strong>: External identity providers (Active Directory, Okta, etc.) can be configured to exchange a user's external credentials for temporary AWS role credentials via SAML or OIDC. This is an older pattern that predates IAM Identity Center.</li>
<li><strong>Break-glass access</strong>: A role with broad permissions that is locked down by default and only assumed in emergencies. A common method for securing these accounts is vaulting the credentials in a PAM platform like CyberArk.</li>
</ul>
<p>From an audit perspective, roles require you to look at the trust policy (who is allowed to assume the role) as well as the permission policy (what the role can do once assumed). Both matter. A role with <code>AdministratorAccess</code> is only as risky as its trust policy is permissive.</p>
<h3 id="iam-policies"><span class="section-number-3">1.4.</span> IAM Policies</h3>
<p>Policies are the documents that define permissions. They're not an access pattern on their own, but understanding the three types helps when reviewing output from any access audit:</p>
<ol>
<li><strong>AWS managed policies</strong> are created and maintained by AWS. Examples include <code>AdministratorAccess</code>, <code>ReadOnlyAccess</code>, and job-function policies like <code>Billing</code>. They're convenient but broad: <code>AdministratorAccess</code> is a single policy that grants full access to every AWS service.</li>
<li><strong>Customer managed policies</strong> are created by the organization. They offer more precise control and can be reused across users, groups, and roles. Better practice than relying entirely on AWS managed policies for anything sensitive.</li>
<li><strong>Inline policies</strong> are embedded directly into a specific user, group, or role rather than existing as a standalone resource. They can't be reused and are easier to miss during reviews. When you see an inline policy in audit output, treat it as something that warrants a closer look — they're often added ad hoc to solve a specific problem and not always well documented.</li>
</ol>
<h3 id="iam-identity-center"><span class="section-number-3">1.5.</span> IAM Identity Center</h3>
<p>IAM Identity Center (formerly AWS SSO) is the current recommended approach for human (end-user) access in multi-account AWS Organizations. It sits above individual accounts and provides centralized access management across all of them from a single place.</p>
<p>It connects to an identity source, such as AWS's own directory, Active Directory, or an external identity provider (IdP) like Okta or Entra ID, and uses that as the source of truth for users and groups. Access is configured within Identity Center itself, not inside individual accounts.</p>
<p>The key construct is the permission set: a named bundle of IAM policies (managed, customer managed, and/or inline) that defines what a principal can do. When you assign a permission set to a user or group for a specific account, AWS creates a temporary IAM role in that account that the user assumes when they access it. The credentials are short-lived and scoped to the session.</p>
<p>The standard architecture: users belong to groups in the identity source, groups are assigned permission sets for specific accounts in Identity Center, and users inherit access through their group memberships. Provisioning and deprovisioning happen at the group membership level, not by touching individual account assignments.</p>
<p>Direct user assignments (where a user is assigned a permission set without going through a group) are possible but generally a control gap, because they bypass the group-based review and provisioning process.</p>
<p>If the organization uses Identity Center, the access population you need to review lives there, not inside individual accounts. Looking at IAM users and roles within an account will give you an incomplete picture. You'll see the temporary roles that Identity Center creates, but not who is assigned to them or why.</p>
<h2 id="what-the-script-does"><span class="section-number-2">2.</span> What the Script Does</h2>
<p>The script works by running commands against a single named AWS account and produces a JSON report of every user and group assignment, along with the permission set and policies attached to each assignment.</p>
<p>It runs in four steps:</p>
<ol>
<li>Finds the IAM Identity Center instance and looks up the target account ID by name;</li>
<li>Lists all permission sets provisioned to that account;</li>
<li>For each permission set, retrieves all user and group assignments, resolves their names from the Identity Store, and fetches the managed and inline policies attached to the permission set;</li>
<li>Writes everything to a JSON file named <code>report_&lt;account_name&gt;.json</code>.</li>
</ol>
<p>The script caches permission set details and principal names to avoid redundant API calls when the same permission set or user appears in multiple assignments.</p>
<p>At the end of this process, we will have the evidence we need to test controls such as administrative access or segregation of duties.</p>
<h2 id="prerequisites"><span class="section-number-2">3.</span> Prerequisites</h2>
<p>You'll need:</p>
<ul>
<li>AWS CLI (or AWS CloudShell) installed and configured with credentials that have read access to <code>sso-admin</code>, <code>identitystore</code>, and <code>organizations</code>;</li>
<li><code>jq</code> installed (used throughout the script for JSON parsing);</li>
<li>The name of the AWS account you want to audit (must match exactly as it appears in AWS Organizations).</li>
</ul>
<p>Set the account name at the top of the script before running:</p>
<pre><code class="language-bash highlight"><span class="source shell bash"><span class="variable other readwrite assignment shell">ACCOUNT_NAME</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell"><span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>your-account-name<span class="punctuation definition string end shell">&quot;</span></span></span></span></code></pre>
<p>Then make the script executable and run it:</p>
<pre><code class="language-bash highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">chmod</span></span><span class="meta function-call arguments shell"> +x aws_iam_users.sh</span>
<span class="meta function-call shell"><span class="variable function shell">./aws_iam_users.sh</span></span></span></code></pre>
<figure><img src="https://img.cleberg.net/blog/20260221-auditing-aws-iam/script.webp" alt="Terminal output of aws_iam_users.sh showing discovered assignments for the cmc account."><figcaption><span class="figure-number">Figure 1: </span>Script Output</figcaption></figure>
<h2 id="reading-the-output"><span class="section-number-2">4.</span> Reading the Output</h2>
<p>The script produces a JSON array where each element represents a single principal-to-permission-set assignment. Here's an example:</p>
<pre><code class="language-json highlight"><span class="source json"><span class="meta structure array json"><span class="punctuation section array begin json">[</span>
  <span class="meta structure dictionary json"><span class="punctuation section dictionary begin json">{</span>
    <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>principal<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="meta structure dictionary json"><span class="punctuation section dictionary begin json">{</span>
      <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>type<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>GROUP<span class="punctuation definition string end json">&quot;</span></span><span class="punctuation separator dictionary pair json">,</span></span>
      <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>name<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>testgroup1<span class="punctuation definition string end json">&quot;</span></span>
    </span><span class="punctuation section dictionary end json">}</span></span><span class="punctuation separator dictionary pair json">,</span></span>
    <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>permission_set<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="meta structure dictionary json"><span class="punctuation section dictionary begin json">{</span>
      <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>name<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>AdministratorAccess<span class="punctuation definition string end json">&quot;</span></span><span class="punctuation separator dictionary pair json">,</span></span>
      <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>policies<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="meta structure dictionary json"><span class="punctuation section dictionary begin json">{</span>
        <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>managed_policies<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="meta structure array json"><span class="punctuation section array begin json">[</span>
          <span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>arn:aws:iam::aws:policy/AdministratorAccess<span class="punctuation definition string end json">&quot;</span></span>
        <span class="punctuation section array end json">]</span></span><span class="punctuation separator dictionary pair json">,</span></span>
        <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>inline_policy<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>{<span class="constant character escape json">\&quot;</span>Version<span class="constant character escape json">\&quot;</span>:<span class="constant character escape json">\&quot;</span>2012-10-17<span class="constant character escape json">\&quot;</span>,<span class="constant character escape json">\&quot;</span>Statement<span class="constant character escape json">\&quot;</span>:[{<span class="constant character escape json">\&quot;</span>Sid<span class="constant character escape json">\&quot;</span>:<span class="constant character escape json">\&quot;</span>Statement2<span class="constant character escape json">\&quot;</span>,<span class="constant character escape json">\&quot;</span>Effect<span class="constant character escape json">\&quot;</span>:<span class="constant character escape json">\&quot;</span>Deny<span class="constant character escape json">\&quot;</span>,<span class="constant character escape json">\&quot;</span>Action<span class="constant character escape json">\&quot;</span>:[<span class="constant character escape json">\&quot;</span>a4b:*<span class="constant character escape json">\&quot;</span>],<span class="constant character escape json">\&quot;</span>Resource<span class="constant character escape json">\&quot;</span>:[<span class="constant character escape json">\&quot;</span>*<span class="constant character escape json">\&quot;</span>]}]}<span class="punctuation definition string end json">&quot;</span></span>
      </span><span class="punctuation section dictionary end json">}</span></span>
    </span><span class="punctuation section dictionary end json">}</span></span>
  </span><span class="punctuation section dictionary end json">}</span></span><span class="punctuation separator array json">,</span>
  <span class="meta structure dictionary json"><span class="punctuation section dictionary begin json">{</span>
    <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>principal<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="meta structure dictionary json"><span class="punctuation section dictionary begin json">{</span>
      <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>type<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>USER<span class="punctuation definition string end json">&quot;</span></span><span class="punctuation separator dictionary pair json">,</span></span>
      <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>name<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>iamtestuser1<span class="punctuation definition string end json">&quot;</span></span>
    </span><span class="punctuation section dictionary end json">}</span></span><span class="punctuation separator dictionary pair json">,</span></span>
    <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>permission_set<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="meta structure dictionary json"><span class="punctuation section dictionary begin json">{</span>
      <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>name<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>AdministratorAccess<span class="punctuation definition string end json">&quot;</span></span><span class="punctuation separator dictionary pair json">,</span></span>
      <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>policies<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="meta structure dictionary json"><span class="punctuation section dictionary begin json">{</span>
        <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>managed_policies<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="meta structure array json"><span class="punctuation section array begin json">[</span>
          <span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>arn:aws:iam::aws:policy/AdministratorAccess<span class="punctuation definition string end json">&quot;</span></span>
        <span class="punctuation section array end json">]</span></span><span class="punctuation separator dictionary pair json">,</span></span>
        <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>inline_policy<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>{<span class="constant character escape json">\&quot;</span>Version<span class="constant character escape json">\&quot;</span>:<span class="constant character escape json">\&quot;</span>2012-10-17<span class="constant character escape json">\&quot;</span>,<span class="constant character escape json">\&quot;</span>Statement<span class="constant character escape json">\&quot;</span>:[{<span class="constant character escape json">\&quot;</span>Sid<span class="constant character escape json">\&quot;</span>:<span class="constant character escape json">\&quot;</span>Statement2<span class="constant character escape json">\&quot;</span>,<span class="constant character escape json">\&quot;</span>Effect<span class="constant character escape json">\&quot;</span>:<span class="constant character escape json">\&quot;</span>Deny<span class="constant character escape json">\&quot;</span>,<span class="constant character escape json">\&quot;</span>Action<span class="constant character escape json">\&quot;</span>:[<span class="constant character escape json">\&quot;</span>a4b:*<span class="constant character escape json">\&quot;</span>],<span class="constant character escape json">\&quot;</span>Resource<span class="constant character escape json">\&quot;</span>:[<span class="constant character escape json">\&quot;</span>*<span class="constant character escape json">\&quot;</span>]}]}<span class="punctuation definition string end json">&quot;</span></span>
      </span><span class="punctuation section dictionary end json">}</span></span>
    </span><span class="punctuation section dictionary end json">}</span></span>
  </span><span class="punctuation section dictionary end json">}</span></span><span class="punctuation separator array json">,</span>
  <span class="meta structure dictionary json"><span class="punctuation section dictionary begin json">{</span>
    <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>principal<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="meta structure dictionary json"><span class="punctuation section dictionary begin json">{</span>
      <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>type<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>USER<span class="punctuation definition string end json">&quot;</span></span><span class="punctuation separator dictionary pair json">,</span></span>
      <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>name<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>iamtestuser1<span class="punctuation definition string end json">&quot;</span></span>
    </span><span class="punctuation section dictionary end json">}</span></span><span class="punctuation separator dictionary pair json">,</span></span>
    <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>permission_set<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="meta structure dictionary json"><span class="punctuation section dictionary begin json">{</span>
      <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>name<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>Billing<span class="punctuation definition string end json">&quot;</span></span><span class="punctuation separator dictionary pair json">,</span></span>
      <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>policies<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="meta structure dictionary json"><span class="punctuation section dictionary begin json">{</span>
        <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>managed_policies<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="meta structure array json"><span class="punctuation section array begin json">[</span>
          <span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>arn:aws:iam::aws:policy/job-function/Billing<span class="punctuation definition string end json">&quot;</span></span>
        <span class="punctuation section array end json">]</span></span><span class="punctuation separator dictionary pair json">,</span></span>
        <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>inline_policy<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span><span class="punctuation definition string end json">&quot;</span></span>
      </span><span class="punctuation section dictionary end json">}</span></span>
    </span><span class="punctuation section dictionary end json">}</span></span>
  </span><span class="punctuation section dictionary end json">}</span></span>
<span class="punctuation section array end json">]</span></span></span></code></pre>
<figure><img src="https://img.cleberg.net/blog/20260221-auditing-aws-iam/json.webp" alt="The contents of report_cmc.json showing principal and permission set assignments."><figcaption><span class="figure-number">Figure 2: </span>JSON Report</figcaption></figure>
<p>A few things to look for when reviewing this output:</p>
<ul>
<li><strong>Direct user assignments</strong>: <code>iamtestuser1</code> is assigned <code>AdministratorAccess</code> directly as a USER, not through a group. Access should generally be provisioned through groups so that provisioning and deprovisioning are tied to group membership, not managed case-by-case. A direct user assignment to a high-privilege permission set warrants a conversation with IT about why it exists.</li>
<li><strong>AdministratorAccess</strong>: This is AWS's broadest managed policy, which allows full access to everything in the account. Note who has it and whether that's appropriate. In many environments, even senior engineers shouldn't have standing <code>AdministratorAccess</code>. It should be reserved for break-glass accounts or infrastructure teams with a documented need.</li>
<li><strong>Inline policies</strong>: The <code>inline_policy</code> field in this example contains a Deny statement for <code>a4b:*</code>. Inline policies attached to permission sets are worth reviewing, as they can add permissions or restrict them, and they're easy to miss if you're only looking at the managed policy name.</li>
<li><strong>Multiple assignments for the same user</strong>: <code>iamtestuser1</code> appears twice: once with <code>AdministratorAccess</code> and once with <code>Billing</code>. This isn't automatically a problem, but a user with both full administrative access and explicit billing access is worth confirming with IT.</li>
</ul>
<h2 id="common-exceptions-and-false-positives"><span class="section-number-2">5.</span> Common Exceptions and False Positives</h2>
<ul>
<li><strong>Break-glass accounts</strong>: Most organizations maintain at least one emergency account with direct <code>AdministratorAccess</code> that bypasses normal access controls. A direct USER assignment to <code>AdministratorAccess</code> may be intentional for this reason. Ask IT whether a break-glass account exists, confirm the username matches, and document it as an accepted exception if appropriate.</li>
<li><strong>Small organizations or early-stage environments</strong>: Some teams haven't implemented group-based access management yet and assign permissions directly to users across the board. This is a control gap, but the finding should reflect the scale and maturity of the environment. A two-person startup with direct assignments is a different risk than an enterprise doing the same thing. This may or may not give rise to a deficiency.</li>
<li><strong>Service or automation accounts</strong>: Occasionally a <code>USER</code> principal in Identity Center is a service account rather than a human. These may legitimately have specific permission sets assigned directly. Confirm the account's purpose before writing it up.</li>
</ul>
<h2 id="how-to-write-up-the-finding"><span class="section-number-2">6.</span> How to Write Up the Finding</h2>
<p>If you identify a direct high-privilege user assignment that isn't a documented exception, here's how to frame it:</p>
<ul>
<li><strong>Deficiency:</strong> User <code>iamtestuser1</code> is directly assigned the <code>AdministratorAccess</code> permission set in account <code>cmc</code>, rather than receiving access through a group assignment.</li>
<li><strong>Root Cause:</strong> Due to {{ root cause }}, the user <code>iamtestuser1</code> was inappropriately provisioned the <code>AdministratorAccess</code> permission directly rather than through a group assignment.</li>
<li><strong>Risk:</strong> Direct user assignments increase the likelihood of orphaned access following role changes or departures. They are also harder to identify during periodic access reviews, as reviewers may focus on group membership rather than individual assignments.</li>
<li><strong>Evidence:</strong> Attach the relevant portion of <code>report_cmc.json</code> filtered to show the specific principal, permission set, and policies. The JSON output is self-documenting, as it includes the account name in the filename and contains the full policy details alongside the assignment.</li>
</ul>
<p>If requested during review, you can filter the output to just the direct user assignments:</p>
<pre><code class="language-bash highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">jq</span></span><span class="meta function-call arguments shell"> <span class="string quoted single shell"><span class="punctuation definition string begin shell">&#39;</span>[.[] | select(.principal.type == &quot;USER&quot;)]<span class="punctuation definition string end shell">&#39;</span></span> report_cmc.json</span></span></code></pre>
<figure><img src="https://img.cleberg.net/blog/20260221-auditing-aws-iam/jq.webp" alt="Terminal output of the jq filter showing only direct user assignments from report_cmc.json."><figcaption><span class="figure-number">Figure 3: </span>Filtered User Assignments</figcaption></figure>
]]></description>
    </item>
    <item>
      <title>Automating weblorg Deployments</title>
      <link>https://cleberg.net/blog/automating-weblorg-deployments.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/automating-weblorg-deployments.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Thu, 12 Feb 2026 00:00:00 +0000</pubDate>
      <category>self-hosting</category>
      <category>web</category>
      <description><![CDATA[<p>As I've mentioned in previous posts, I utilize a unique pipeline to draft posts, compose my website, and to build and deploy the static files.</p>
<p>This stack uses the following software:</p>
<ul>
<li><a href="https://www.gnu.org/software/emacs/">Emacs</a></li>
<li><a href="https://emacs.love/weblorg/">Weblorg</a></li>
<li><a href="https://www.python.org/">Python</a></li>
<li><a href="https://formulae.brew.sh/formula/minify">Minify</a></li>
<li><a href="https://rsync.samba.org/">rsync</a></li>
<li>Environment variables</li>
</ul>
<p>I've historically relied on the following build and deployment methods:</p>
<ol>
<li>Manually running <code>ENV=prod emacs --script publish.el</code>;</li>
<li>Then building out a <code>build.py</code> script to automate the Weblorg publishing method and allow for custom steps, like adding recent blog posts to <code>index.html</code>;</li>
<li>Then adding GitHub Actions to automate all steps whenever I merge a pull request into <code>main</code>.</li>
</ol>
<p>This post will describe the process I've created to automatically build and deploy my site with this stack via GitHub Actions.</p>
<h2 id="weblorg-configuration"><span class="section-number-2">1.</span> Weblorg Configuration</h2>
<p>The basis for the build process is <code>publish.el</code>. The challenge with using Emacs static site generators is path management. Specifically, I've needed to ensure that the necessary packages (<code>weblorg</code>, <code>htmlize</code>, &amp; <code>templatel</code>) are available regardless of whether I'm building the site on macOS (my dev machine) or a Linux-based runner.</p>
<p>To solve this, I use a simple conditional to set the <code>site-lisp-base</code> path. This allows the script to find the cloned repositories in their respective locations. Additionally, I use an environment variable check (<code>ENV=prod</code>) to toggle the <code>weblorg-default-url</code>. If I’m just testing locally, it defaults to <code>localhost</code>. Otherwise, it points to the live domain.</p>
<pre><code class="language-elisp">;;; -*- lexical-binding: t -*-
;; Allow for macOS (dev machine) &amp; Linux (GitHub Actions) execution
(defvar site-lisp-base
  (if (eq system-type 'darwin)
      "~/.config/emacs/.local/straight/repos"                 ; macOS path
      "/home/linuxbrew/.config/emacs/.local/straight/repos")) ; CI/Linux path

;; Explicitly load packages
(add-to-list 'load-path (expand-file-name "htmlize" site-lisp-base))
(add-to-list 'load-path (expand-file-name "weblorg" site-lisp-base))
(add-to-list 'load-path (expand-file-name "templatel" site-lisp-base))

(require 'htmlize)
(require 'weblorg)

;; Set default URL for Weblorg
;; Only works if environment variable ENV=prod
(if (string-equal-ignore-case (getenv "ENV") "prod")
    (setq weblorg-default-url "https://cleberg.net"))

;; Define site metadata
(weblorg-site
 :theme nil
 :template-vars '(("site_name"        . "cleberg.net")
                  ("site_owner"       . "Christian Cleberg &lt;hello@cleberg.net&gt;")
                  ("site_description" . "Just a blip of ones and zeroes.")))

;; Define routes for rendering content
;; ...
;; /scrubbed for brevity/

;; Export all content using Weblorg engine
(weblorg-export)</code></pre>
<p>If we run a command such as <code>ENV=prod emacs --script publish.el</code>, Emacs will return a <code>.build/</code> directory with our resulting HTML files. At this point, we could manually enter the <code>.build/</code> directory and run <code>python -m http.server</code> for a local dev server or <code>rsync</code> to deploy to production.</p>
<p>However, that's just way too much work. Let's keep going.</p>
<h2 id="python-build-script"><span class="section-number-2">2.</span> Python Build Script</h2>
<p>Building on the previous step, I wanted to add some quality-of-life improvements that Weblorg does not provide:</p>
<ul>
<li>Update <code>index.html</code> with the three latest blog posts.</li>
<li>Clean up the <code>.build/</code> directory with each run so we don't run into any conflicts with old or removed files.</li>
<li>Minify CSS and HTML.</li>
<li>Silence Emacs/Weblorg <code>stdout</code> / <code>stderr</code> when running for production.</li>
<li>Generate a sitemap.</li>
<li>Allow the option to deploy to a remote endpoint via <code>rsync</code> or start the local dev server.</li>
</ul>
<p>Python allows for this by acting as the orchestrator, as well as relying on environment variables to decide its behavior:</p>
<ul>
<li><strong>ENV</strong>: Determines if we use production URLs or local ones.</li>
<li><strong>BUILD</strong>: Triggers the actual Emacs export and asset minification.</li>
<li><strong>DEPLOY</strong>: In a local context, this spins up a dev server. In CI, we leave this <code>false</code> because GitHub Actions handles the <code>rsync</code> logic separately.</li>
</ul>
<p>See below for the <code>main()</code> function within <code>build.py</code> for the logic used to drive the process to the rest of the functions in the Python file.</p>
<pre><code class="language-python highlight"><span class="source python"><span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> File scrubbed for brevity
</span>
<span class="meta function python"><span class="storage type function python">def</span> <span class="entity name function python"><span class="meta generic-name python">main</span></span></span><span class="meta function parameters python"><span class="punctuation section parameters begin python">(</span></span><span class="meta function parameters python"><span class="punctuation section parameters end python">)</span></span><span class="meta function python"><span class="punctuation section function begin python">:</span></span>
    <span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Updates index.html with the 3 most recent blog posts
</span>    <span class="meta qualified-name python"><span class="meta generic-name python">html_snippet</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="variable function python">get_recent_posts_html</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">./content/blog<span class="punctuation definition string end python">&quot;</span></span></span><span class="punctuation separator arguments python">,</span> <span class="variable parameter python">num_posts</span><span class="keyword operator assignment python">=</span><span class="constant numeric integer decimal python">3</span></span><span class="punctuation section arguments end python">)</span></span>

    <span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Defines the build path, theme path, and CSS paths
</span>    <span class="meta qualified-name python"><span class="meta generic-name python">build_dir</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="variable function python">Path</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">.build<span class="punctuation definition string end python">&quot;</span></span></span></span><span class="punctuation section arguments end python">)</span></span>
    <span class="meta qualified-name python"><span class="meta generic-name python">theme_dir</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="variable function python">Path</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">theme/static<span class="punctuation definition string end python">&quot;</span></span></span></span><span class="punctuation section arguments end python">)</span></span>
    <span class="meta qualified-name python"><span class="meta generic-name python">css_src</span></span> <span class="keyword operator assignment python">=</span> <span class="meta qualified-name python"><span class="meta generic-name python">theme_dir</span></span> <span class="keyword operator arithmetic python">/</span> <span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">styles.css<span class="punctuation definition string end python">&quot;</span></span></span>
    <span class="meta qualified-name python"><span class="meta generic-name python">css_min</span></span> <span class="keyword operator assignment python">=</span> <span class="meta qualified-name python"><span class="meta generic-name python">theme_dir</span></span> <span class="keyword operator arithmetic python">/</span> <span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">styles.min.css<span class="punctuation definition string end python">&quot;</span></span></span>

    <span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Check environment for ENV, BUILD, and DEPLOY variables
</span>    <span class="meta qualified-name python"><span class="meta generic-name python">env</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">os</span><span class="punctuation accessor dot python">.</span><span class="meta generic-name python">environ</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">get</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">ENV<span class="punctuation definition string end python">&quot;</span></span></span><span class="punctuation separator arguments python">,</span> <span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string end python">&quot;</span></span></span></span><span class="punctuation section arguments end python">)</span></span><span class="meta function-call python"><span class="meta qualified-name python"><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">casefold</span></span><span class="punctuation section arguments begin python">(</span><span class="punctuation section arguments end python">)</span></span>
    <span class="meta qualified-name python"><span class="meta generic-name python">build</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">os</span><span class="punctuation accessor dot python">.</span><span class="meta generic-name python">environ</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">get</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">BUILD<span class="punctuation definition string end python">&quot;</span></span></span><span class="punctuation separator arguments python">,</span> <span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string end python">&quot;</span></span></span></span><span class="punctuation section arguments end python">)</span></span><span class="meta function-call python"><span class="meta qualified-name python"><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">casefold</span></span><span class="punctuation section arguments begin python">(</span><span class="punctuation section arguments end python">)</span></span> <span class="keyword operator comparison python">==</span> <span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">true<span class="punctuation definition string end python">&quot;</span></span></span>
    <span class="meta qualified-name python"><span class="meta generic-name python">deploy</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">os</span><span class="punctuation accessor dot python">.</span><span class="meta generic-name python">environ</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">get</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">DEPLOY<span class="punctuation definition string end python">&quot;</span></span></span><span class="punctuation separator arguments python">,</span> <span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string end python">&quot;</span></span></span></span><span class="punctuation section arguments end python">)</span></span><span class="meta function-call python"><span class="meta qualified-name python"><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">casefold</span></span><span class="punctuation section arguments begin python">(</span><span class="punctuation section arguments end python">)</span></span> <span class="keyword operator comparison python">==</span> <span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">true<span class="punctuation definition string end python">&quot;</span></span></span>

    <span class="meta statement if python"><span class="keyword control flow conditional python">if</span> <span class="meta qualified-name python"><span class="meta generic-name python">env</span></span> <span class="keyword operator comparison python">==</span> <span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">prod<span class="punctuation definition string end python">&quot;</span></span></span><span class="punctuation section block conditional python">:</span></span>
        <span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> If ENV = prod (case-insensitive), will build for production
</span>        <span class="meta function-call python"><span class="meta qualified-name python"><span class="support function builtin python">print</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">Environment: Production<span class="punctuation definition string end python">&quot;</span></span></span></span><span class="punctuation section arguments end python">)</span></span>
        <span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Will only build if BUILD=true
</span>        <span class="meta statement if python"><span class="keyword control flow conditional python">if</span> <span class="meta qualified-name python"><span class="meta generic-name python">build</span></span><span class="punctuation section block conditional python">:</span></span>
            <span class="meta function-call python"><span class="meta qualified-name python"><span class="variable function python">remove_build_directory</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">build_dir</span></span></span><span class="punctuation section arguments end python">)</span></span>
            <span class="meta function-call python"><span class="meta qualified-name python"><span class="variable function python">minify_css</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">css_src</span></span><span class="punctuation separator arguments python">,</span> <span class="meta qualified-name python"><span class="meta generic-name python">css_min</span></span></span><span class="punctuation section arguments end python">)</span></span>
            <span class="meta function-call python"><span class="meta qualified-name python"><span class="variable function python">run_emacs_publish</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="variable parameter python">dev_mode</span><span class="keyword operator assignment python">=</span><span class="constant language python">False</span></span><span class="punctuation section arguments end python">)</span></span>
            <span class="meta function-call python"><span class="meta qualified-name python"><span class="variable function python">update_index_html</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">html_snippet</span></span></span><span class="punctuation section arguments end python">)</span></span>
            <span class="meta function-call python"><span class="meta qualified-name python"><span class="variable function python">minify_html</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">./.build/index.html<span class="punctuation definition string end python">&quot;</span></span></span><span class="punctuation separator arguments python">,</span> <span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">./.build/index.html<span class="punctuation definition string end python">&quot;</span></span></span></span><span class="punctuation section arguments end python">)</span></span>
            <span class="meta function-call python"><span class="meta qualified-name python"><span class="variable function python">generate_sitemap</span></span><span class="punctuation section arguments begin python">(</span><span class="punctuation section arguments end python">)</span></span>
        <span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Will only deploy if DEPLOY=true
</span>        <span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> False for GitHub Actions because deploy.yml deploys via rsync directly
</span>        <span class="meta statement if python"><span class="keyword control flow conditional python">if</span> <span class="meta qualified-name python"><span class="meta generic-name python">deploy</span></span><span class="punctuation section block conditional python">:</span></span>
            <span class="meta function-call python"><span class="meta qualified-name python"><span class="support function builtin python">print</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">Deploying to production...<span class="punctuation definition string end python">&quot;</span></span></span></span><span class="punctuation section arguments end python">)</span></span>
            <span class="meta function-call python"><span class="meta qualified-name python"><span class="variable function python">deploy_to_server</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">build_dir</span></span><span class="punctuation separator arguments python">,</span> <span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">homelab-remote<span class="punctuation definition string end python">&quot;</span></span></span></span><span class="punctuation section arguments end python">)</span></span>
            <span class="keyword control flow return python">return</span>
    <span class="meta statement conditional python"><span class="keyword control flow conditional python">else</span><span class="punctuation section block python">:</span></span>
        <span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> If ENV != prod (case-insensitive), will build for localhost
</span>        <span class="meta function-call python"><span class="meta qualified-name python"><span class="support function builtin python">print</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">Environment: Development<span class="punctuation definition string end python">&quot;</span></span></span></span><span class="punctuation section arguments end python">)</span></span>
        <span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Will only build if BUILD=true
</span>        <span class="meta statement if python"><span class="keyword control flow conditional python">if</span> <span class="meta qualified-name python"><span class="meta generic-name python">build</span></span><span class="punctuation section block conditional python">:</span></span>
            <span class="meta function-call python"><span class="meta qualified-name python"><span class="variable function python">remove_build_directory</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">build_dir</span></span></span><span class="punctuation section arguments end python">)</span></span>
            <span class="meta function-call python"><span class="meta qualified-name python"><span class="variable function python">minify_css</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">css_src</span></span><span class="punctuation separator arguments python">,</span> <span class="meta qualified-name python"><span class="meta generic-name python">css_min</span></span></span><span class="punctuation section arguments end python">)</span></span>
            <span class="meta function-call python"><span class="meta qualified-name python"><span class="variable function python">run_emacs_publish</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="variable parameter python">dev_mode</span><span class="keyword operator assignment python">=</span><span class="constant language python">True</span></span><span class="punctuation section arguments end python">)</span></span>
            <span class="meta function-call python"><span class="meta qualified-name python"><span class="variable function python">update_index_html</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">html_snippet</span></span></span><span class="punctuation section arguments end python">)</span></span>
            <span class="meta function-call python"><span class="meta qualified-name python"><span class="variable function python">minify_html</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">./.build/index.html<span class="punctuation definition string end python">&quot;</span></span></span><span class="punctuation separator arguments python">,</span> <span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">./.build/index.html<span class="punctuation definition string end python">&quot;</span></span></span></span><span class="punctuation section arguments end python">)</span></span>
            <span class="meta function-call python"><span class="meta qualified-name python"><span class="variable function python">generate_sitemap</span></span><span class="punctuation section arguments begin python">(</span><span class="punctuation section arguments end python">)</span></span>
        <span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Will only deploy if DEPLOY=true
</span>        <span class="meta statement if python"><span class="keyword control flow conditional python">if</span> <span class="meta qualified-name python"><span class="meta generic-name python">deploy</span></span><span class="punctuation section block conditional python">:</span></span>
            <span class="meta function-call python"><span class="meta qualified-name python"><span class="variable function python">start_dev_server</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">build_dir</span></span></span><span class="punctuation section arguments end python">)</span></span></span></code></pre>
<p>Awesome! Now we can run <code>uv run build.py</code> to build and deploy locally or <code>ENV=prod uv run build.py</code> to build and deploy for production. Enabling <code>BUILD</code> and <code>DEPLOY</code> variables will tweak the process, as mentioned above.</p>
<p>However, that's way too manual for me. Let's be lazy and take it even further.</p>
<h2 id="github-actions"><span class="section-number-2">3.</span> GitHub Actions</h2>
<p>So, how do we push it further? By removing the need to run a command (outside of <code>git</code>) at all!</p>
<p>This process will:</p>
<ol>
<li>Create a custom Docker image with the tools we need to build and deploy.</li>
<li>Build the Docker image and store it within GitHub's image registry.</li>
<li>Build and deploy the website upon a push or pull request to <code>main</code>.</li>
</ol>
<h3 id="the-custom-docker-image"><span class="section-number-3">3.1.</span> The Custom Docker Image</h3>
<p>Let's start by building a Docker image that has all the tools I need to build the site. Standard CI runners don't come pre-installed with the specific mix of tools I need (Emacs, Homebrew, <code>uv</code>, and <code>minify</code>). Instead of installing these on every single run, we will build the image and store it for future use.</p>
<p>The <code>Dockerfile</code> uses <code>python:3.12-slim</code> as a base, installs Linuxbrew for easy package management, and clones the necessary Emacs packages into the expected directory. This ensures the build environment is consistent and fast.</p>
<pre><code class="language-Dockerfile">FROM python:3.12-slim

ENV DEBIAN_FRONTEND=noninteractive \
    HOMEBREW_NO_AUTO_UPDATE=1 \
    PATH="/home/linuxbrew/.linuxbrew/bin:${PATH}"

RUN apt-get update &amp;&amp; apt-get install -y --no-install-recommends \
    curl \
    git \
    procps \
    build-essential \
    ca-certificates \
    openssh-client \
    &amp;&amp; rm -rf /var/lib/apt/lists/*

RUN useradd -m -s /bin/bash linuxbrew
USER linuxbrew
WORKDIR /home/linuxbrew

RUN /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

RUN brew install emacs rsync uv minify

RUN mkdir -p ~/.config/emacs/.local/straight/repos &amp;&amp; \
    cd ~/.config/emacs/.local/straight/repos &amp;&amp; \
    git clone --depth 1 https://github.com/emacsorphanage/htmlize.git &amp;&amp; \
    git clone --depth 1 https://github.com/emacs-love/templatel.git &amp;&amp; \
    git clone --depth 1 https://github.com/emacs-love/weblorg.git

USER root
WORKDIR /builds</code></pre>
<h3 id="building-and-pushing-to-ghcr"><span class="section-number-3">3.2.</span> Building and Pushing to GHCR</h3>
<p>Next, let's use the image we built as the base for the rest of our automation. I use a dedicated workflow (<code>docker-build.yml</code>) to keep the image up to date. Whenever I modify the Dockerfile or my requirements, GitHub Actions builds the image and pushes it to the GitHub Container Registry (GHCR). This image then serves as the environment for the final deployment step.</p>
<pre><code class="language-yaml highlight"><span class="source yaml"><span class="string unquoted plain out yaml"><span class="entity name tag yaml">name</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string unquoted plain out yaml">Build and Push Docker Image</span>

<span class="constant language boolean yaml">on</span><span class="punctuation separator key-value mapping yaml">:</span>
  <span class="string unquoted plain out yaml"><span class="entity name tag yaml">push</span></span><span class="punctuation separator key-value mapping yaml">:</span>
    <span class="string unquoted plain out yaml"><span class="entity name tag yaml">branches</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="meta flow-sequence yaml"><span class="punctuation definition sequence begin yaml">[</span> <span class="string quoted double yaml"><span class="punctuation definition string begin yaml">&quot;</span>main<span class="punctuation definition string end yaml">&quot;</span></span> <span class="punctuation definition sequence end yaml">]</span></span>
    <span class="string unquoted plain out yaml"><span class="entity name tag yaml">paths</span></span><span class="punctuation separator key-value mapping yaml">:</span>
      <span class="punctuation definition block sequence item yaml">-</span> <span class="string quoted single yaml"><span class="punctuation definition string begin yaml">&#39;</span>Dockerfile<span class="punctuation definition string end yaml">&#39;</span></span>
      <span class="punctuation definition block sequence item yaml">-</span> <span class="string quoted single yaml"><span class="punctuation definition string begin yaml">&#39;</span>requirements.txt<span class="punctuation definition string end yaml">&#39;</span></span>
      <span class="punctuation definition block sequence item yaml">-</span> <span class="string quoted single yaml"><span class="punctuation definition string begin yaml">&#39;</span>.github/workflows/docker-build.yml<span class="punctuation definition string end yaml">&#39;</span></span>

<span class="string unquoted plain out yaml"><span class="entity name tag yaml">jobs</span></span><span class="punctuation separator key-value mapping yaml">:</span>
  <span class="string unquoted plain out yaml"><span class="entity name tag yaml">build</span></span><span class="punctuation separator key-value mapping yaml">:</span>
    <span class="string unquoted plain out yaml"><span class="entity name tag yaml">runs-on</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string unquoted plain out yaml">ubuntu-latest</span>
    <span class="string unquoted plain out yaml"><span class="entity name tag yaml">permissions</span></span><span class="punctuation separator key-value mapping yaml">:</span>
      <span class="string unquoted plain out yaml"><span class="entity name tag yaml">contents</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string unquoted plain out yaml">read</span>
      <span class="string unquoted plain out yaml"><span class="entity name tag yaml">packages</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string unquoted plain out yaml">write</span>

    <span class="string unquoted plain out yaml"><span class="entity name tag yaml">steps</span></span><span class="punctuation separator key-value mapping yaml">:</span>
      <span class="punctuation definition block sequence item yaml">-</span> <span class="string unquoted plain out yaml"><span class="entity name tag yaml">name</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string unquoted plain out yaml">Checkout repository</span>
        <span class="string unquoted plain out yaml"><span class="entity name tag yaml">uses</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string unquoted plain out yaml">actions/checkout@v4</span>

      <span class="punctuation definition block sequence item yaml">-</span> <span class="string unquoted plain out yaml"><span class="entity name tag yaml">name</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string unquoted plain out yaml">Log in to GHCR</span>
        <span class="string unquoted plain out yaml"><span class="entity name tag yaml">uses</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string unquoted plain out yaml">docker/login-action@v3</span>
        <span class="string unquoted plain out yaml"><span class="entity name tag yaml">with</span></span><span class="punctuation separator key-value mapping yaml">:</span>
          <span class="string unquoted plain out yaml"><span class="entity name tag yaml">registry</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string unquoted plain out yaml">ghcr.io</span>
          <span class="string unquoted plain out yaml"><span class="entity name tag yaml">username</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string unquoted plain out yaml">${{ github.actor }}</span>
          <span class="string unquoted plain out yaml"><span class="entity name tag yaml">password</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string unquoted plain out yaml">${{ secrets.GITHUB_TOKEN }}</span>

      <span class="punctuation definition block sequence item yaml">-</span> <span class="string unquoted plain out yaml"><span class="entity name tag yaml">name</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string unquoted plain out yaml">Extract metadata</span>
        <span class="string unquoted plain out yaml"><span class="entity name tag yaml">id</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string unquoted plain out yaml">meta</span>
        <span class="string unquoted plain out yaml"><span class="entity name tag yaml">uses</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string unquoted plain out yaml">docker/metadata-action@v5</span>
        <span class="string unquoted plain out yaml"><span class="entity name tag yaml">with</span></span><span class="punctuation separator key-value mapping yaml">:</span>
          <span class="string unquoted plain out yaml"><span class="entity name tag yaml">images</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string unquoted plain out yaml">ghcr.io/${{ github.repository }}</span>

      <span class="punctuation definition block sequence item yaml">-</span> <span class="string unquoted plain out yaml"><span class="entity name tag yaml">name</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string unquoted plain out yaml">Build and push</span>
        <span class="string unquoted plain out yaml"><span class="entity name tag yaml">uses</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string unquoted plain out yaml">docker/build-push-action@v5</span>
        <span class="string unquoted plain out yaml"><span class="entity name tag yaml">with</span></span><span class="punctuation separator key-value mapping yaml">:</span>
          <span class="string unquoted plain out yaml"><span class="entity name tag yaml">context</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="constant numeric float yaml">.</span>
          <span class="string unquoted plain out yaml"><span class="entity name tag yaml">push</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="constant language boolean yaml">true</span>
          <span class="string unquoted plain out yaml"><span class="entity name tag yaml">tags</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string unquoted plain out yaml">${{ steps.meta.outputs.tags }}</span>
          <span class="string unquoted plain out yaml"><span class="entity name tag yaml">labels</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string unquoted plain out yaml">${{ steps.meta.outputs.labels }}</span></span></code></pre>
<h3 id="the-build-and-deploy-workflow"><span class="section-number-3">3.3.</span> The Build and Deploy Workflow</h3>
<p>Finally, the <code>deploy.yml</code> brings it all together. I split into two jobs: the <strong>build-job</strong>, which runs inside our custom container to execute the Python orchestrator, and the <strong>deploy-job</strong>, which handles the SSH handshake and <code>rsync</code> transfer.</p>
<pre><code class="language-yaml highlight"><span class="source yaml"><span class="string unquoted plain out yaml"><span class="entity name tag yaml">name</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string unquoted plain out yaml">Build and Deploy</span>

<span class="constant language boolean yaml">on</span><span class="punctuation separator key-value mapping yaml">:</span>
  <span class="string unquoted plain out yaml"><span class="entity name tag yaml">push</span></span><span class="punctuation separator key-value mapping yaml">:</span>
    <span class="string unquoted plain out yaml"><span class="entity name tag yaml">branches</span></span><span class="punctuation separator key-value mapping yaml">:</span>
      <span class="punctuation definition block sequence item yaml">-</span> <span class="string unquoted plain out yaml">main</span>
    <span class="string unquoted plain out yaml"><span class="entity name tag yaml">paths-ignore</span></span><span class="punctuation separator key-value mapping yaml">:</span>
      <span class="punctuation definition block sequence item yaml">-</span> <span class="string quoted single yaml"><span class="punctuation definition string begin yaml">&#39;</span>.github/**<span class="punctuation definition string end yaml">&#39;</span></span>
      <span class="punctuation definition block sequence item yaml">-</span> <span class="string quoted single yaml"><span class="punctuation definition string begin yaml">&#39;</span>screenshots/**<span class="punctuation definition string end yaml">&#39;</span></span>
      <span class="punctuation definition block sequence item yaml">-</span> <span class="string quoted single yaml"><span class="punctuation definition string begin yaml">&#39;</span>utils/**<span class="punctuation definition string end yaml">&#39;</span></span>
      <span class="punctuation definition block sequence item yaml">-</span> <span class="string quoted single yaml"><span class="punctuation definition string begin yaml">&#39;</span>LICENSE<span class="punctuation definition string end yaml">&#39;</span></span>
      <span class="punctuation definition block sequence item yaml">-</span> <span class="string quoted single yaml"><span class="punctuation definition string begin yaml">&#39;</span>README.org<span class="punctuation definition string end yaml">&#39;</span></span>

<span class="string unquoted plain out yaml"><span class="entity name tag yaml">jobs</span></span><span class="punctuation separator key-value mapping yaml">:</span>
  <span class="string unquoted plain out yaml"><span class="entity name tag yaml">build-job</span></span><span class="punctuation separator key-value mapping yaml">:</span>
    <span class="string unquoted plain out yaml"><span class="entity name tag yaml">runs-on</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string unquoted plain out yaml">ubuntu-latest</span>
    <span class="string unquoted plain out yaml"><span class="entity name tag yaml">container</span></span><span class="punctuation separator key-value mapping yaml">:</span>
      <span class="string unquoted plain out yaml"><span class="entity name tag yaml">image</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string unquoted plain out yaml">ghcr.io/ccleberg/cleberg.net:main</span>

    <span class="string unquoted plain out yaml"><span class="entity name tag yaml">steps</span></span><span class="punctuation separator key-value mapping yaml">:</span>
      <span class="punctuation definition block sequence item yaml">-</span> <span class="string unquoted plain out yaml"><span class="entity name tag yaml">name</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string unquoted plain out yaml">Checkout code</span>
        <span class="string unquoted plain out yaml"><span class="entity name tag yaml">uses</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string unquoted plain out yaml">actions/checkout@v4</span>

      <span class="punctuation definition block sequence item yaml">-</span> <span class="string unquoted plain out yaml"><span class="entity name tag yaml">name</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string unquoted plain out yaml">Run Build</span>
        <span class="string unquoted plain out yaml"><span class="entity name tag yaml">env</span></span><span class="punctuation separator key-value mapping yaml">:</span>
          <span class="string unquoted plain out yaml"><span class="entity name tag yaml">ENV</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string quoted double yaml"><span class="punctuation definition string begin yaml">&quot;</span>prod<span class="punctuation definition string end yaml">&quot;</span></span>
          <span class="string unquoted plain out yaml"><span class="entity name tag yaml">BUILD</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string quoted double yaml"><span class="punctuation definition string begin yaml">&quot;</span>true<span class="punctuation definition string end yaml">&quot;</span></span>
          <span class="string unquoted plain out yaml"><span class="entity name tag yaml">DEPLOY</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string quoted double yaml"><span class="punctuation definition string begin yaml">&quot;</span>false<span class="punctuation definition string end yaml">&quot;</span></span>
        <span class="string unquoted plain out yaml"><span class="entity name tag yaml">run</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="keyword control flow block-scalar literal yaml">|</span>
<span class="string unquoted block yaml">          echo &quot;Environment is ready. Running build...&quot;
          uv run build.py

</span>      <span class="punctuation definition block sequence item yaml">-</span> <span class="string unquoted plain out yaml"><span class="entity name tag yaml">name</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string unquoted plain out yaml">Upload Build Artifacts</span>
        <span class="string unquoted plain out yaml"><span class="entity name tag yaml">uses</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string unquoted plain out yaml">actions/upload-artifact@v4</span>
        <span class="string unquoted plain out yaml"><span class="entity name tag yaml">with</span></span><span class="punctuation separator key-value mapping yaml">:</span>
          <span class="string unquoted plain out yaml"><span class="entity name tag yaml">name</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string unquoted plain out yaml">build-output</span>
          <span class="string unquoted plain out yaml"><span class="entity name tag yaml">path</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string unquoted plain out yaml">${{ github.workspace }}/.build/</span>
          <span class="string unquoted plain out yaml"><span class="entity name tag yaml">include-hidden-files</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="constant language boolean yaml">true</span>

  <span class="string unquoted plain out yaml"><span class="entity name tag yaml">deploy-job</span></span><span class="punctuation separator key-value mapping yaml">:</span>
    <span class="string unquoted plain out yaml"><span class="entity name tag yaml">runs-on</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string unquoted plain out yaml">ubuntu-latest</span>
    <span class="string unquoted plain out yaml"><span class="entity name tag yaml">needs</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string unquoted plain out yaml">build-job</span>
    <span class="string unquoted plain out yaml"><span class="entity name tag yaml">environment</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string unquoted plain out yaml">production</span>
    <span class="string unquoted plain out yaml"><span class="entity name tag yaml">container</span></span><span class="punctuation separator key-value mapping yaml">:</span>
      <span class="string unquoted plain out yaml"><span class="entity name tag yaml">image</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string unquoted plain out yaml">ghcr.io/ccleberg/cleberg.net:main</span>

    <span class="string unquoted plain out yaml"><span class="entity name tag yaml">steps</span></span><span class="punctuation separator key-value mapping yaml">:</span>
      <span class="punctuation definition block sequence item yaml">-</span> <span class="string unquoted plain out yaml"><span class="entity name tag yaml">name</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string unquoted plain out yaml">Checkout code</span>
        <span class="string unquoted plain out yaml"><span class="entity name tag yaml">uses</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string unquoted plain out yaml">actions/checkout@v4</span>

      <span class="punctuation definition block sequence item yaml">-</span> <span class="string unquoted plain out yaml"><span class="entity name tag yaml">name</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string unquoted plain out yaml">Download Build Artifacts</span>
        <span class="string unquoted plain out yaml"><span class="entity name tag yaml">uses</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string unquoted plain out yaml">actions/download-artifact@v4</span>
        <span class="string unquoted plain out yaml"><span class="entity name tag yaml">with</span></span><span class="punctuation separator key-value mapping yaml">:</span>
          <span class="string unquoted plain out yaml"><span class="entity name tag yaml">name</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string unquoted plain out yaml">build-output</span>
          <span class="string unquoted plain out yaml"><span class="entity name tag yaml">path</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string unquoted plain out yaml">${{ github.workspace }}/.build/</span>

      <span class="punctuation definition block sequence item yaml">-</span> <span class="string unquoted plain out yaml"><span class="entity name tag yaml">name</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string unquoted plain out yaml">Setup SSH and Deploy</span>
        <span class="string unquoted plain out yaml"><span class="entity name tag yaml">env</span></span><span class="punctuation separator key-value mapping yaml">:</span>
          <span class="string unquoted plain out yaml"><span class="entity name tag yaml">SERVER_IP</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string unquoted plain out yaml">${{ secrets.SERVER_IP }}</span>
          <span class="string unquoted plain out yaml"><span class="entity name tag yaml">SERVER_USER</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string unquoted plain out yaml">${{ secrets.SERVER_USER }}</span>
          <span class="string unquoted plain out yaml"><span class="entity name tag yaml">SSH_PRIVATE_KEY</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string unquoted plain out yaml">${{ secrets.SSH_PRIVATE_KEY }}</span>
        <span class="string unquoted plain out yaml"><span class="entity name tag yaml">run</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="keyword control flow block-scalar literal yaml">|</span>
<span class="string unquoted block yaml">          eval $(ssh-agent -s)
          echo &quot;$SSH_PRIVATE_KEY&quot; | tr -d &#39;\r&#39; | ssh-add -
          rsync -avz --delete \
            -e &quot;ssh -p ${{ secrets.SSH_PORT }} -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null&quot; \
            .build/ \
            $SERVER_USER@$SERVER_IP:/var/www/cleberg.net/</span></span></code></pre>
<h2 id="conclusion"><span class="section-number-2">4.</span> Conclusion</h2>
<p>Amazing! Now my site will build and deploy whenever I push to the <code>main</code> branch. I have more tweaks to make (e.g., build a development server and environment for pull requests prior to <code>main</code>), but I've automated most of it and have drastically reduced the administrative burden for the site. After making updates, I simply need to <code>git add ...</code> and merge my PR to trigger the deployment.</p>
]]></description>
    </item>
    <item>
      <title>Managing Dotfiles with GNU Stow and Git</title>
      <link>https://cleberg.net/blog/gnu-stow.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/gnu-stow.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Sun, 08 Feb 2026 00:00:00 +0000</pubDate>
      <category>emacs</category>
      <category>linux</category>
      <description><![CDATA[<h2 id="what-is-gnu-stow"><span class="section-number-2">1.</span> What is GNU Stow?</h2>
<p><a href="https://www.gnu.org/software/stow/">GNU Stow</a> is described as a "symlink farm manager" on its homepage, which is true, but feels a bit underwhelming. Rather, I'd describe it as a tool to systematically and logically link, organize, and version control any files on your system.</p>
<p><img src="https://img.cleberg.net/blog/20260208-gnu-stow/stow.webp" alt=""></p>
<h2 id="installation"><span class="section-number-2">2.</span> Installation</h2>
<p>First things first: let's install Stow. I'm on macOS, so I run the following command:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">brew</span></span><span class="meta function-call arguments shell"> install stow</span></span></code></pre>
<p>To ensure it's installed correctly, check the version:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">stow</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>V</span></span></span></code></pre>
<h2 id="stow-dotfiles"><span class="section-number-2">3.</span> Stow Dotfiles</h2>
<p>Next, let's create a directory to use as the central source for all these files. In my case, I store all git repositories in my <code>~/git/</code> directory, so I will create a <code>dotfiles</code> directory here:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> Create the dotfiles repository</span><span class="comment line number-sign shell">
</span><span class="meta function-call shell"><span class="variable function shell">mkdir</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/git/dotfiles</span> <span class="keyword operator logical and shell">&amp;&amp;</span> <span class="meta function-call shell"><span class="support function cd shell">cd</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/git/dotfiles</span></span></code></pre>
<p>Next, let's stow our first set of dotfiles. We'll use <code>zsh</code> as an example here. To do this, we will:</p>
<ol>
<li>Create a directory for Zsh.</li>
<li>Move our current Zsh configuration files into our Stow directory.</li>
<li>Use Stow to symlink the files back into our home directory.</li>
</ol>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> Create the ZSH Stow directory</span><span class="comment line number-sign shell">
</span><span class="meta function-call shell"><span class="variable function shell">mkdir</span></span><span class="meta function-call arguments shell"> zsh</span>                          <span class="keyword operator logical and shell">&amp;&amp;</span> <span class="punctuation separator continuation line shell">\
</span><span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> Move your ZSH files into Stow</span><span class="comment line number-sign shell">
</span><span class="meta function-call shell"><span class="variable function shell">mv</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/.zshrc <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/git/dotfiles/zsh/</span>    <span class="keyword operator logical and shell">&amp;&amp;</span> <span class="punctuation separator continuation line shell">\
</span><span class="meta function-call shell"><span class="variable function shell">mv</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/.zprofile <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/git/dotfiles/zsh/</span> <span class="keyword operator logical and shell">&amp;&amp;</span> <span class="punctuation separator continuation line shell">\
</span><span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> Use Stow to symlink them back to your user home</span><span class="comment line number-sign shell">
</span><span class="meta function-call shell"><span class="variable function shell">stow</span></span><span class="meta function-call arguments shell"> zsh</span></span></code></pre>
<p>By default, Stow will symlink your files (e.g., <code>zsh</code>) to the parent directory of the directory in which you execute the command. Since we're in the <code>~/git/dotfiles</code> directory, we need to modify our <code>stow</code> command to ensure Stow symlinks the files to our home directory:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">stow</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>t</span> <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span> zsh</span></span></code></pre>
<p>At this point, you have a centralized directory (<code>/git/dotfiles</code>) where you can stow any file and use <code>stow</code> to symlink it back to another directory on your system.</p>
<p>Therefore, you only need to navigate to this directory to make changes across your system.</p>
<h2 id="update-dotfiles"><span class="section-number-2">4.</span> Update Dotfiles</h2>
<p>When you make changes to your Stow directory, you can inform Stow and have the program update its symlinks with the following command:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="support function cd shell">cd</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/git/dotfiles</span> <span class="keyword operator logical and shell">&amp;&amp;</span> <span class="punctuation separator continuation line shell">\
</span><span class="meta function-call shell"><span class="variable function shell">stow</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>R</span> zsh</span></span></code></pre>
<p>To summarize:</p>
<table>
<thead>
<tr><th>Action</th><th>Command</th><th>Why?</th></tr>
</thead>
<tbody>
<tr><td>Edited a file</td><td>None (Just save)</td><td>The symlink already exists.</td></tr>
<tr><td>Added a file to existing folder</td><td>stow -R &lt;package&gt;</td><td>To create the new symlink for that file.</td></tr>
<tr><td>Deleted a file from dotfiles</td><td>stow -R &lt;package&gt;</td><td>To remove the "dead" symlink from your home dir.</td></tr>
<tr><td>Created a whole new package</td><td>stow &lt;package&gt;</td><td>To link the new directory for the first time.</td></tr>
</tbody>
</table>
<h2 id="save-to-a-git-repository"><span class="section-number-2">5.</span> Save to a Git Repository</h2>
<p>Lastly, let's finish the puzzle by ensuring that this configuration is long-lasting and can transfer amongst systems.</p>
<p>To this end, we will use Git as our VCS. You can simply create the repository, add your files, and push to your remote.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">git</span></span><span class="meta function-call arguments shell"> init</span>                       <span class="keyword operator logical and shell">&amp;&amp;</span> <span class="punctuation separator continuation line shell">\
</span><span class="meta function-call shell"><span class="variable function shell">git</span></span><span class="meta function-call arguments shell"> add .</span>                      <span class="keyword operator logical and shell">&amp;&amp;</span> <span class="punctuation separator continuation line shell">\
</span><span class="meta function-call shell"><span class="variable function shell">git</span></span><span class="meta function-call arguments shell"> commit<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>m</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>initial commit<span class="punctuation definition string end shell">&quot;</span></span></span> <span class="keyword operator logical and shell">&amp;&amp;</span> <span class="punctuation separator continuation line shell">\
</span><span class="meta function-call shell"><span class="variable function shell">git</span></span><span class="meta function-call arguments shell"> remote add origin GIT_URL</span>  <span class="keyword operator logical and shell">&amp;&amp;</span> <span class="punctuation separator continuation line shell">\
</span><span class="meta function-call shell"><span class="variable function shell">git</span></span><span class="meta function-call arguments shell"> push</span></span></code></pre>
<p>If you want to automate this even more, write an alias or a hook into your <code>stow</code> command to automatically commit your changes whenever they occur.</p>
<p>At this point, I have organized and managed my dotfiles much more efficiently and no longer lose them whenever I wipe my machines.</p>
]]></description>
    </item>
    <item>
      <title>IndieWeb Carnival: Intersecting Interests</title>
      <link>https://cleberg.net/blog/indiweb-carnival-2026-02-intersecting-interests.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/indiweb-carnival-2026-02-intersecting-interests.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Sat, 07 Feb 2026 00:00:00 +0000</pubDate>
      <category>personal</category>
      <category>web</category>
      <description><![CDATA[<blockquote>
<p>Want to participate in the IndieWeb Carnival or read more posts? Visit the main <a href="https://indieweb.org/IndieWeb_Carnival">Carnival</a> page to learn more.</p>
</blockquote>
<p>I thought about this topic for a long time today before starting to write this post, as I don't think of myself as someone with intersecting interests. I generally lean pretty hard into interests and in my mind, they're all technology-related.</p>
<p>However, I've settled on the following topic: <strong>The Minimalist Technologist</strong>.</p>
<h2 id="personal-life"><span class="section-number-2">1.</span> Personal Life</h2>
<p>In my personal life, I spend my leisure time doing a few primary things:</p>
<ol>
<li><strong>Technology</strong>: Obviously. I love to learn about new things online, blogging, programming, self-hosting,</li>
<li><strong>Physical Work</strong>: Conversely, my next favorite things to do are all completely technology free. This includes things like yard work, woodworking, organizing, decluttering, etc. There's just something about zoning out, getting into a physical rhythm, and feeling your body's strength create something productive instead of your mind.</li>
<li><strong>Sports</strong>: This is fairly generic, but sometimes it can be a contrast for those who work in tech. Especially if you consider disc golf and/or hiking in this category.</li>
</ol>
<h2 id="work"><span class="section-number-2">2.</span> Work</h2>
<p>Now, this may be where I differ even more so than in my personal life. While I work in a tech job, I do not actually spend my days deep inside code (when possible) or building as many internal tools as I used to.</p>
<p>Instead, my job has primarily become 50 to 60 hours per week of meetings, mentoring younger coworkers, teaching and leading trainings, thinking about overall strategy of our practice, and project managing.</p>
<p>It's the generic individual contributor (IC) to manager story line, but again, it frees me up to switch to a different mindset when I get home and be productive on hobby projects. I'm no longer burnt out from thinking on such a technical level all day.</p>
<p>Either way, it was interesting to think through this topic and has me thinking more about broadening my horizons.</p>
]]></description>
    </item>
    <item>
      <title>Emacs Carnival: Completion</title>
      <link>https://cleberg.net/blog/emacs-carnival-2026-02-completion.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/emacs-carnival-2026-02-completion.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Mon, 02 Feb 2026 00:00:00 +0000</pubDate>
      <category>emacs</category>
      <category>personal</category>
      <description><![CDATA[<blockquote>
<p>Want to participate in the Emacs Carnival or read more posts? Visit the main <a href="https://www.emacswiki.org/emacs/Carnival">Carnival</a> page on the Emacs Wiki to learn more.</p>
</blockquote>
<p>I'm having a great time with the Emacs Carnival, as it has inspired me to write two posts in such a short time. It's been a much-needed inspiration to write during my busy season at work.</p>
<p>Anyway, let's get to it. The topic today is <a href="https://www.emacswiki.org/emacs/CategoryCompletion">Completion</a>: the magical thing that turns someone like me, who cannot remember long lists of commands to save my life, from an illiterate to a literate programmer.</p>
<h2 id="defining-custom-abbreviations"><span class="section-number-2">1.</span> Defining Custom Abbreviations</h2>
<p>While you can define <a href="https://www.gnu.org/software/emacs/manual/html_node/emacs/Abbrevs.html">abbrevs</a> dynamically in the buffer with <code>C-x a g</code> (which generally saves abbrevs to <code>/.emacs.d/abbrev_defs</code>), I prefer to define my abbreviations directly within my <code>config.el</code> file.</p>
<p>This allows for better portability between my machines, as well as clearer configuration for myself.</p>
<p>To create a new abbrev, I simply open <code>~/.config/doom/config.el</code> and add a new one to the list below.</p>
<pre><code class="language-elisp">;; Abbreviations
(setq-default abbrev-mode t)
(define-abbrev-table 'global-abbrev-table
  '(
    ;; ("abbreviation" "expansion")
    ("omw" "on my way")
    ("eml" "hello@cleberg.net")
    ("shrg" "¯\_(ツ)_/¯")
    ("teh" "the")
    ("xtoday" "" (lambda () (insert (format-time-string "%Y-%m-%d %H:%M:%S"))))
    ("xnow" "" (lambda () (insert (format-time-string "%H:%M:%S"))))
    ))</code></pre>
<p>Now, I can type something like <code>xtoday</code> in my buffer and get the fully formatted time string, like so: <code>2026-02-02 21:52:55</code>.</p>
<p><code>¯\_(ツ)_/¯</code></p>
<p>This comes in handy most at work, where I need to constantly use acronyms and take shorthand notes to fill out phrases that I'm, unfortunately, required to reuse constantly. Looking at you, "completeness and accuracy of the data".</p>
<h2 id="doom-configuration"><span class="section-number-2">2.</span> Doom Configuration</h2>
<p>I have played around with a few different completion options for my purposes and have settled on the following packages.</p>
<p>Here is how I have my <code>:completion</code>, <code>:tools</code>, and <code>:lang</code> modules toggled in <code>~/.config/doom/init.el</code>:</p>
<pre><code class="language-elisp">(doom! :input
       :completion
       (corfu +orderless)  ; complete with cap(f), cape and a flying feather!
       vertico             ; the search engine of the future

        :checkers
       syntax              ; tasing you for every semicolon you forget
       (spell +flyspell)   ; tasing you for misspelling mispelling
       grammar             ; tasing grammar mistake every you make


       :tools
       (lsp +eglot)        ; M-x vscode

       :lang
       data                ; config/data formats
       emacs-lisp          ; drown in parentheses
       json                ; At least it ain't XML
       javascript          ; all(hope(abandon(ye(who(enter(here))))))
       markdown            ; writing docs for people to ignore
       (org +dragndrop     ; drag &amp; drop images/files into org
            +journal       ; daily logging
            +noter         ; for annotating PDFs (great for research)
            +roam2)        ; Zettelkasten note-taking
       python              ; beautiful is better than ugly
       sh                  ; she sells {ba,z,fi}sh shells on the C xor

       :config
       (default +bindings +smartparens))</code></pre>
<p>With this setup, I am able to get a wonderful IDE-level experience within Emacs and without the bloat of a traditional IDE. It's the perfect balance of speed and power for my work and hobbies.</p>
<h3 id="vertico-marginalia"><span class="section-number-3">2.1.</span> <a href="https://github.com/minad/vertico">vertico</a> + <a href="https://github.com/minad/marginalia">marginalia</a></h3>
<p>Vertico is wonderful for finding files (<code>SPC .</code>) or running commands (<code>SPC :</code>). It provides a clean, vertical interface for the minibuffer.</p>
<p>Marginalia works wonderfully with Vertico, as it provides marginalia to the minibuffer commands within the command selection buffer.</p>
<figure><img src="https://img.cleberg.net/blog/20260202-emacs-carnival-2026-02-completion/vertico-commands.webp" alt="Vertico: Command"><figcaption><span class="figure-number">Figure 1: </span>Vertico: Command</figcaption></figure>
<figure><img src="https://img.cleberg.net/blog/20260202-emacs-carnival-2026-02-completion/vertico-files.webp" alt="Vertico: Files"><figcaption><span class="figure-number">Figure 2: </span>Vertico: Files</figcaption></figure>
<h3 id="orderless"><span class="section-number-3">2.2.</span> <a href="https://github.com/oantolin/orderless">orderless</a></h3>
<p>Orderless is a game changer. As I mentioned above, I'm terrible with memorization. Therefore, I use this package and am able to search with multiple out-of-order terms to find a result in my Vertico searches.</p>
<figure><img src="https://img.cleberg.net/blog/20260202-emacs-carnival-2026-02-completion/orderless.webp" alt="Orderless"><figcaption><span class="figure-number">Figure 3: </span>Orderless</figcaption></figure>
<h3 id="corfu"><span class="section-number-3">2.3.</span> <a href="https://github.com/minad/corfu">corfu</a></h3>
<p>For code completion, I’ve swapped out Company mode for Corfu. It’s faster, stays out of my way until I need it, and uses a small popup that feels right at home in a terminal or a GUI.</p>
<figure><img src="https://img.cleberg.net/blog/20260202-emacs-carnival-2026-02-completion/python.webp" alt="Corfu"><figcaption><span class="figure-number">Figure 4: </span>Corfu</figcaption></figure>
<h3 id="eglot"><span class="section-number-3">2.4.</span> <a href="https://github.com/joaotavora/eglot">eglot</a></h3>
<p>To actually "know" what my code is doing, I use LSP (Language Server Protocol). I've enabled the <code>+eglot</code> flag in Doom because Eglot is now built into Emacs core and tends to be a bit more stable and performant for my Python and JavaScript workflows.</p>
<h3 id="flyspell"><span class="section-number-3">2.5.</span> <a href="https://github.com/leotaku/flycheck-aspell?tab=readme-ov-file">flyspell</a></h3>
<p>Flyspell is the last piece to my puzzle, as it allows for easy help in correcting grammar errors within the buffer. I combine <code>flyspell</code> + <code>syntax</code> + <code>grammar</code> for ultimate writing guidance. Whether or not I choose to follow that guidance is another story entirely.</p>
<figure><img src="https://img.cleberg.net/blog/20260202-emacs-carnival-2026-02-completion/suggestions.webp" alt="Flyspell"><figcaption><span class="figure-number">Figure 5: </span>Flyspell</figcaption></figure>
<h2 id="looking-forward"><span class="section-number-2">3.</span> Looking Forward</h2>
<p>I know this is just the tip of the iceberg, so I've made a list of packages I want to dive into deeper in the future:</p>
<ul>
<li><code>tempel</code></li>
<li><code>yasnippet</code></li>
<li><code>consult</code></li>
<li><code>embark</code></li>
<li><code>cape</code></li>
<li><code>kind-icon</code></li>
<li><code>prescient.el</code></li>
</ul>
<p>Completion and expansion utilities are phenomenal and have been one of the larger tools in my development and writing.</p>
]]></description>
    </item>
    <item>
      <title>Emacs Carnival: This Year, I Will...</title>
      <link>https://cleberg.net/blog/emacs-carnival-2026-01-this-year-i-will.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/emacs-carnival-2026-01-this-year-i-will.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Sat, 31 Jan 2026 00:00:00 +0000</pubDate>
      <category>emacs</category>
      <category>personal</category>
      <description><![CDATA[<blockquote>
<p>Want to participate in the Emacs Carnival or read more posts? Visit the main <a href="https://www.emacswiki.org/emacs/Carnival">Carnival</a> page on the Emacs Wiki to learn more.</p>
</blockquote>
<p>This year in Emacs, I expect to do a lot. However, here are some actionable goals for myself that should have a positive impact as I start out 2026.</p>
<h2 id="dive-deeper-into-org-mode"><span class="section-number-2">1.</span> Dive Deeper into Org-Mode</h2>
<ul>
<li><a href="https://orgmode.org/manual/Agenda-Views.html">Org Agenda</a>: Move beyond simple <code>TODO</code> lists. I want to implement a custom dashboard using <code>org-super-agenda</code> to group tasks by context rather than just file.</li>
<li><a href="https://github.com/gregsexton/ob-ipython">ob-ipython</a>: Fully embrace Literate Programming. This year, my data analysis scripts live inside org blocks. No more scattered <code>.py</code> files for quick prototypes.</li>
<li><a href="https://orgmode.org/manual/Capture.html">Org Capture</a>: Streamline my intake. I’m aiming for a "one-key" capture system that sorts ideas into the right buckets automatically using template hooks.</li>
</ul>
<h2 id="better-doom-configuration"><span class="section-number-2">2.</span> Better Doom Configuration</h2>
<ul>
<li>GitOps for Emacs: Come up with a solid base and use a GitOps-style workflow to ensure my environment is identical between home, work, and server.</li>
<li>UI Refinement: Try new packages like <code>spacious-padding</code> to give the buffer some room to breathe. I'm also looking into <code>svg-lib</code> for cleaner-looking progress bars and icons.</li>
</ul>
]]></description>
    </item>
    <item>
      <title>Self-Hosting Guide: Home Assistant</title>
      <link>https://cleberg.net/blog/self-hosting-home-assistant.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/self-hosting-home-assistant.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Sat, 20 Dec 2025 00:00:00 +0000</pubDate>
      <category>linux</category>
      <category>self-hosting</category>
      <description><![CDATA[<h2 id="overview"><span class="section-number-2">1.</span> Overview</h2>
<p>I've used <a href="https://www.home-assistant.io">Home Assistant</a> off and on for years, but I've never written a guide on it because it always felt like a half-baked solution with my combinations of products and my Home Assistant configuration.</p>
<p>However, Home Assistant looks much better these days and now has native <a href="https://help.ui.com/hc/en-us/articles/27878858632599-Getting-Started-with-UniFi-Protect">UniFi Protect</a> support, so I decided to switch back to using it full time and writing up a proper guide to installing, configuring, and customizing the software.</p>
<h2 id="installation"><span class="section-number-2">2.</span> Installation</h2>
<p>I happened to have a spare Raspberry Pi 4 sitting around I wasn't using, so I opted for the <a href="https://www.home-assistant.io/installation/raspberrypi">Raspberry Pi</a> installation tutorial from Home Assistant. This tutorial guides you through the flashing of Home Assistant OS to an SD card and initialization of the software.</p>
<p>This process is seamless and will result in a ready-to-use device with Home Assistant.</p>
<h2 id="configuration"><span class="section-number-2">3.</span> Configuration</h2>
<p>Once the device is ready, all you need to do is create your account and complete the initial setup wizard within the Home Assistant page (e.g., <code class="verbatim">homeassistant.local:8123</code>).</p>
<p>At this point, you will have a functioning Home Assistant deployment. However, I want to go further and configure the service to use my personal devices and display information via customized interfaces.</p>
<p>To start with our configuration, we will visit the <code class="verbatim">Settings</code> &gt; <code class="verbatim">Devices &amp; services</code> page. This page will display all currently configured integrations, as well as automatically discovered integrations that you can configure.</p>
<p><img src="https://img.cleberg.net/blog/20251220-self-hosting-home-assistant/integrations.webp" alt=""></p>
<h3 id="hacs"><span class="section-number-3">3.1.</span> HACS</h3>
<p>Another integration of note is the <a href="https://hacs.xyz">Home Assistant Community Store (HACS)</a>, which provides a familiar integration into the Home Assistant UI that allows you to manage custom elements.</p>
<p>If you installed Home Assistant like I did using the OS method, you will need to install the Get-HACS integration to install HACS and then restart Home Assistant to start utilizing these custom elements.</p>
<p>Personally, I am using HACS in order to utilize the <a href="https://github.com/dahlb/ha_hatch">Hatch Rest</a> integration for my Hatch Rest Mini, Rest+, and Restore.</p>
<p>You can see it here in my <code class="verbatim">Media</code> dashboard:</p>
<p><img src="https://img.cleberg.net/blog/20251220-self-hosting-home-assistant/media.webp" alt=""></p>
<p>Once you have installed all relevant integrations and synced your devices to Home Assistant, you are ready to build your dashboards.</p>
<h3 id="external-access"><span class="section-number-3">3.2.</span> External Access</h3>
<p>If you want to be able to external your instance externally, you will need to expose the service to the internet somehow. One option is a reverse proxy, such as Nginx, which I have covered in numerous self-hosting posts. Another option is Cloudflare Tunnels, which I will cover here.</p>
<p>Configuring a tunnel to Home Assistant OS takes a few more steps than a normal reverse proxy, but I currently find the security benefits worthwhile.</p>
<p>To start, install the <a href="https://github.com/homeassistant-apps/app-cloudflared">app-cloudflared</a> app in the Add-ons menu within Home Assistant.</p>
<p>Once installed, follow the instructions to configure the <code class="verbatim">External Home Assistant Hostname</code>, <code class="verbatim">Cloudflare Tunnel Name</code>, and the <code class="verbatim">Cloudflare Tunnel Token</code> within the Configuration tab of the installed add-on. Once configured, I restarted Home Assistant to start fresh.</p>
<p>Next, I opened Cloudflare and configured the tunnel to expose the <code class="verbatim">ha.example.com</code> domain to the <code class="verbatim">homeassistant.local:8123</code> address in Cloudflare's Zero Trust dashboard.</p>
<p>From here, I can access Home Assistant anywhere I go from the <code class="verbatim">ha.example.com</code> domain.</p>
<h2 id="customization"><span class="section-number-2">4.</span> Customization</h2>
<p>Finally, let's customize our dashboards. The view below is my standard view when greeted by my dashboard.</p>
<p>As you can see, I choose to keep general information in the main tab, such as weather, time, and location. Instead of jamming every widget into a single tab, I separate my tabs by function:</p>
<ul>
<li>Media: TVs, Speakers, and other playable entities</li>
<li>Cameras: UniFi Protect cameras</li>
<li>Lights: Hue bulbs and other lighting systems</li>
<li>IoT: Other miscellaneous devices, such as printers, my Litter Robot, Roomba, etc.</li>
</ul>
<p><img src="https://img.cleberg.net/blog/20251220-self-hosting-home-assistant/dashboard.webp" alt=""></p>
<p>When editing a dashboard, you're presented with a myriad of options. First, you can choose to use a number of layout options (sections, masonry, sidebar, and single card). Next, each element you add to the dashboard any number of entities, names, themes, states, and more to configure.</p>
<p>Honestly, I had forgotten how customizable these dashboards were and I will absolutely spend a lot of time customizing for very specific needs.</p>
<p>See below for some examples of editing and IoT elements:</p>
<p><img src="https://img.cleberg.net/blog/20251220-self-hosting-home-assistant/edit.webp" alt=""></p>
<p><img src="https://img.cleberg.net/blog/20251220-self-hosting-home-assistant/iot.webp" alt=""></p>
<p>Once you have configured and customized your dashboards to your heart's content, you're reading to start automating and more! I highly suggest browsing the web and Home Assistant forums for ideas and solutions that fit your needs. There are more possibilities to this platform than you'll likely ever be able to use.</p>
<h3 id="mobile-view"><span class="section-number-3">4.1.</span> Mobile View</h3>
<p>Before I finish this post, I wanted to show how reliable the mobile view of the platform displays. These screenshots were captured on the iOS Home Assistant app, using the remote URL for my instance.</p>
<table>
<thead>
<tr><th>Dashboard</th><th>Entity</th></tr>
</thead>
<tbody>
<tr><td><img src="https://img.cleberg.net/blog/20251220-self-hosting-home-assistant/mobile_dashboard.webp" alt=""></td><td><img src="https://img.cleberg.net/blog/20251220-self-hosting-home-assistant/roomba.webp" alt=""></td></tr>
</tbody>
</table>
]]></description>
    </item>
    <item>
      <title>Self-Hosting Guide: Tor Websites</title>
      <link>https://cleberg.net/blog/self-hosting-tor.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/self-hosting-tor.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Sat, 06 Dec 2025 00:00:00 +0000</pubDate>
      <category>linux</category>
      <category>self-hosting</category>
      <description><![CDATA[<h2 id="installation"><span class="section-number-2">1.</span> Installation</h2>
<p>First, install the Tor package. I'm using Ubuntu, so I'll be using <code class="verbatim">apt</code> to install Tor.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> apt install tor</span></span></code></pre>
<h2 id="configuration"><span class="section-number-2">2.</span> Configuration</h2>
<h3 id="tor"><span class="section-number-3">2.1.</span> Tor</h3>
<p>Next, let's configure the service we'll be serving via Tor. For this, edit the file below and add the lines below to the end of the file.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> nano /etc/tor/torrc</span></span></code></pre>
<p>The following lines you add to the file will define the directory to use and the internet protocol (IP) address and port we will be using.</p>
<pre><code class="language-text">HiddenServiceDir /var/lib/tor/hidden_service/
HiddenServicePort 80 127.0.0.1:5000</code></pre>
<p>Next, you will need to <code class="verbatim">cat</code> the contents of the file below to find the onion address provided to you.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> cat /var/lib/tor/hidden_service/hostname</span></span></code></pre>
<h3 id="nginx"><span class="section-number-3">2.2.</span> Nginx</h3>
<p>With this onion address handy, create a file in your Nginx configuration directory. Mine is <code class="verbatim">conf.d</code>, but yours may be <code class="verbatim">sites-available</code>. If that's the case, don't forget to create a symbolic link from the file you created in <code class="verbatim">sites-available</code> to <code class="verbatim">sites-enabled</code>.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> nano /etc/nginx/conf.d/tor-website.conf</span></span></code></pre>
<p>Within this Nginx configuration file, I will be using the file below. I have left comments to explain each part.</p>
<pre><code class="language-conf">server {
	# The IP address and port Nginx will listen on
	listen 127.0.0.1:80;
	# The onion address to listen for
	server_name sv3g2dlyvwyk2nvi3eeh55fcrpdvjlclhi6wwsx57cste6lwdjanzyyd.onion;
	# The directory where your website files are
	root /var/www/tor-website/;

	# By default, try to serve the files. Return 404 if a file is not found.
	location / {
		try_files $uri $uri/ =404;
	}

	# Put any other configurations here at the end, such as redirects
	# ...
}</code></pre>
<p>Finally, we can restart the services and check to see if it's working.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> systemctl restart nginx.service</span>
<span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> systemctl restart tor.service</span></span></code></pre>
<p>At this point, you should be able to view your Onion address in Tor.</p>
<p><img src="https://img.cleberg.net/blog/20251206-self-hosting-tor/onion.webp" alt=""></p>
<h3 id="onion-location"><span class="section-number-3">2.3.</span> Onion-Location</h3>
<p>Lastly, let's advertise the <code class="verbatim">Onion-Location</code> on our clearnet website so that users on Tor can automatically switch to the Onion address if they want to.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> nano /etc/nginx/conf.d/regular_website.conf</span></span></code></pre>
<pre><code class="language-conf">server {
	server_name example.com;
	add_header Onion-Location http://YourOnionAddress.onion$request_uri;
}</code></pre>
<p>Once complete, restart Nginx.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> systemctl restart nginx.service</span></span></code></pre>
<p>You should now see a big purple button in Tor titled <code class="verbatim">.onion available</code> when visiting the clearnet web page.</p>
<p><img src="https://img.cleberg.net/blog/20251206-self-hosting-tor/clearnet.webp" alt=""></p>
<p>If everything worked, you're all done! You now have a website served via an onion address on Tor and an Onion-Location header advertising your new onion address.</p>
]]></description>
    </item>
    <item>
      <title>IT Audit and AI: Where It Helps and Where It&#x27;s Theater</title>
      <link>https://cleberg.net/blog/it-audit-ai.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/it-audit-ai.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Sun, 23 Nov 2025 00:00:00 +0000</pubDate>
      <category>audit</category>
      <description><![CDATA[<h2 id="my-ai-toolkit"><span class="section-number-2">1.</span> My AI Toolkit</h2>
<p>As others in the Big 4 will probably tell you, AI is a strategic tool that allows for a far more efficient and impact audit. However, the key is understanding when to use it, how to use it, and how to translate the output from your AI into actions.</p>
<p>This post will walk you through how I personally leverage AI in my role.</p>
<p>Let's start by stepping through the tools I have at my disposal.</p>
<h3 id="gemini-enterprise-formerly-agentspace"><span class="section-number-3">1.1.</span> Gemini Enterprise (formerly Agentspace)</h3>
<p>First and foremost is <a href="https://cloud.google.com/gemini-enterprise">Gemini Enterprise</a>, which has a large context window, is connected to the Enterprise's internal documentation and websites, and allows for specialized use of custom agents, <a href="https://notebooklm.google/">NotebookLM</a>, and more.</p>
<p>I use Gemini for a handful of specific use-cases, notably:</p>
<ol>
<li>NotebookLM notebooks for team-based usage. For example, you can build a notebook for a specific client (using public and private information about that client) and then chat with the data in the notebook, generate an audio overview, and save documents, such as mind maps or study guides, for future use.<ul>
<li>I love this because it provides a "run once and save" functionality, where I can generate things like an audio overview or document, save it, and then my team can reference it without re-running the prompt or even needing to open the notebook, if they download it.</li>
</ul>
</li>
<li>Custom Agents for customized personas that benefit from the private information that Gemini has access to, such as internal SharePoint sites.<ul>
<li>For example, I have a custom agent designed to operate as an IT Audit Assistant that can help you ask questions that can be answered by the company's news, documentation sites, and more (e.g., "I'm testing logical access for AWS and want to know if anyone has created a solution or guidance for XYZ.").</li>
</ul>
</li>
</ol>
<h3 id="microsoft-copilot"><span class="section-number-3">1.2.</span> Microsoft Copilot</h3>
<p>Likely the most common AI in use at companies today, due to its integration with every Microsoft product, Copilot offers the best AI solution for productivity. However, it's usage is likely also the most volatile due to the large gap in skill sets between new-hires and senior employees.</p>
<p>For associates and other early-career employees, I suggest that they use Copilot to perform two primary tasks:</p>
<ol>
<li>Check their tone, such as making an email or messages more professionalism, softer, or perhaps to analyze the conversation up to that point to understand how to respond better. This is something that <em>should</em> come naturally to senior employees, but is often a learning curve for associates.</li>
<li>For written documentation, such as guides or presentations, use Copilot and provide it with ample information on the goal of the documentation in order for Copilot to suggest an outline, gaps in the writer's thinking, or areas for further research before writing the document. The key here is to use Copilot to improve your thinking and not to replace it. It shouldn't generate the content for you, it should remove the tedium of creating boilerplate structures or to design the structure of a document.</li>
</ol>
<h3 id="clara-ai"><span class="section-number-3">1.3.</span> Clara AI</h3>
<p><a href="https://kpmg.com/us/en/capabilities-services/audit-services/kpmg-clara.html">Clara AI</a> is KPMG's audit-based AI platform, known as the "KPMG Clara Smart Audit Platform". The major benefit to Clara AI is that it lives within a sandboxed environment, running on white-labelled models, fine-tuned on firm-specific methodologies, and built directly into KPMG's audit tools.</p>
<p>As noted in KPMG's Clara AI page linked above, Clara AI is built directly into the Clara audit platform in order to provide systematic risk assessments, drive consistent and efficient audits by providing all audit teams with relevant information for their audit, and connects to other tools (such as KPMG Client Collaboration, where evidence is requested and provided).</p>
<p>I <strong>absolutely love this tool</strong>, as it solves some of the bigger problems for auditors at large firms:</p>
<ol>
<li>Connecting younger staff to the firm's guidance and regulatory material, lowering the barrier to auditors trying to learn which pieces of regulation apply and when they apply.</li>
<li>As you can imagine, the audit process for a firm of KPMG's size can be complex at times and changes depending on the client, the client's industry, the type of engagement, and more. Clara AI helps break down each of these challenges and provide detailed, accurate guidance for auditors to learn about their specific use-case without getting lost in irrelevant data.</li>
</ol>
<p>Clara AI does a lot more than I've written about here and I know teams are using these features beyond what my teams do in Tech Assurance. You can read about more features, such as automation, dynamic dashboards, and more on the product page: <a href="https://kpmg.com/us/en/capabilities-services/audit-services/kpmg-clara.html">Clara AI</a>.</p>
<h2 id="use-cases-for-each-tool"><span class="section-number-2">2.</span> Use Cases for Each Tool</h2>
<p>While this section won't be exhaustive, it provides a few basic examples of what my teams do at KPMG with AI, as well as some suggestions for how other auditors can utilize AI at their own companies.</p>
<h3 id="gemini"><span class="section-number-3">2.1.</span> Gemini</h3>
<h4 id="client-and-project-based-agents-or-notebooks"><span class="section-number-4">2.1.1.</span> Client and Project-Based Agents or Notebooks</h4>
<p>As I mentioned above, one great use-case is to build notebooks for your client team or even for internal teams, such as a team that's formed to increase automation within the audit practice.</p>
<p>I build notebooks for these teams, upload as many relevant documents and links as I can, invite my team members, and then save useful artifacts within the notebook so that my team members don't need to recreate the wheel in order to gain access to that same information.</p>
<h4 id="technical-research"><span class="section-number-4">2.1.2.</span> Technical Research</h4>
<p>Through purely anecdotal experiences, I have found Gemini to be superior to my other AI tools when it comes to technical topics. It provides more accurate information and better context for my specific role.</p>
<p>This has replaced the experience of walking team members through topics, such as Snowflake architecture, AWS logical security, or SQL permissions.</p>
<p>In addition, it helps me and others who are more experience dive deeper into subjects that we historically did not have the time or knowledge to research. For example, Gemini recently helped me use my knowledge of similar systems to understand Kafka's architecture and risks as they related to my client's specific implementation of Kafka.</p>
<h4 id="data-analysis"><span class="section-number-4">2.1.3.</span> Data Analysis</h4>
<p>As I mentioned above, Gemini seems to excel with technical tasks. I've been using this to enhance the data analysis we perform.</p>
<p>For example, Gemini is able to help write queries (e.g., SQL or AWS commands) to extract the information we need to test a control. While we have lots of internal documentation for popular platforms, there are always situations where you need data from a system and don't have any guidance to extract it.</p>
<p>For users with data, Gemini is able to provide a more natural language querying process where the user can simply describe what analysis they need, or even generate a dashboard for the user. I find this most helpful in identifying relevant metrics or analytics and then have our teams use their skills to build out Alteryx workflows and Power BI dashboards to implement what Gemini has helped them investigate.</p>
<p>Lastly, data cleaning is wonderful in Gemini. Gemini is able to help structure, clean and deduplicate data much faster than humans can and seems to have a lower potential for errors than if someone manually combed through the data trying to correct it.</p>
<h3 id="microsoft-copilot"><span class="section-number-3">2.2.</span> Microsoft Copilot</h3>
<h4 id="meeting-transcripts"><span class="section-number-4">2.2.1.</span> Meeting Transcripts</h4>
<p>One of the built-in features of Copilot in Teams is <a href="https://support.microsoft.com/en-us/office/view-live-transcription-in-microsoft-teams-meetings-dc1a8f23-2e20-4684-885e-2152e06a4a8b">transcription</a>. This is a killer feature for auditors, as one of the biggest pain points for an audit (on both sides) is having to meet multiple times to rehash the same topic or send constant follow-ups throughout the year to re-confirm facts.</p>
<p>With a transcript, we can spend one meeting going fully through all questions and simply refer back to the transcript whenever we have a question.</p>
<p>If you also save the video recording, you can also save the time of requesting evidence later, as you already have a recording where you walked through the evidence you needed.</p>
<p>This saves:</p>
<ol>
<li>An absolute <strong>ton</strong> of time on both the audit and client sides, in terms of questions and follow-ups.</li>
<li>Even <strong>more</strong> time by not needing the ask the client to take a million screenshots. Instead, the auditor can take screenshots from the recording after the fact. No more stopping every 5 seconds in a meeting waiting for someone to take a screenshot or sending a request for screenshots after the fact.</li>
</ol>
<h4 id="meeting-facilitator"><span class="section-number-4">2.2.2.</span> Meeting Facilitator</h4>
<p>Another killer feature of Copilot is the <a href="https://learn.microsoft.com/en-us/microsoftteams/facilitator-teams">Facilitator</a>. Facilitator takes the agenda in the meeting invite (or determines the agenda throughout the meeting), tracks progress of the discussion against the agenda, takes notes, and tracks to-do items with assignments for users to take action after the end of the meeting.</p>
<h4 id="microsoft-office-integrations"><span class="section-number-4">2.2.3.</span> Microsoft Office Integrations</h4>
<p>I talked about the Microsoft Office integrations above, so I won't dive deep in this section.</p>
<p>For auditors, some useful examples are:</p>
<ul>
<li>Generating boilerplate for an audience you're not familiar with writing for (e.g., engineers vs. CFOs). Note that you <strong>shouldn't</strong> generate the content, you should only let Copilot guide you to the proper format and then use your knowledge to write the content.</li>
<li>Checking your tone, especially if Copilot has access to historical chats, in order to help you respond professionally and appropriately.</li>
<li>In Excel or Word, helping you analyze your data.</li>
</ul>
<p>I'm not a big fan of generating content with Copilot, so I don't have any examples for that. Perhaps I am naive, but I still think we should be honing our interpersonal skills and the content of our communications with others should still be written by us, not AI.</p>
<h4 id="managing-emails-chats-and-more"><span class="section-number-4">2.2.4.</span> Managing Emails, Chats, and More</h4>
<p>I almost titled this section "Manager Mode", since I'm feeling a different level of intensity from the sheer number of emails, Teams messages, tags in channels, and more that I experience now as a Manager.</p>
<p>One small but effective use for Copilot is to check at the end of the day if you've missed anything that day, such as responding to an email or message, actions items assigned to you in meetings, or important announcements that, while not directed at you individually, may require action from you.</p>
<p>I currently do not have access to Copilot Studio, but I'd love to build a custom agent around this idea if I could.</p>
<h3 id="clara-ai"><span class="section-number-3">2.3.</span> Clara AI</h3>
<h4 id="firm-methodology-guidance"><span class="section-number-4">2.3.1.</span> Firm &amp; Methodology Guidance</h4>
<p>For an auditor who has to deal with SOX, SOC 1-3, AUP, and more engagements, you can imagine the sheer number of potential pitfalls there are when working through an engagement.</p>
<p>Being able to have Clara AI break down the regulatory requirements for your specific situation is amazing.</p>
<p>For example, how do you risk assess Client ABC, who has unique IT systems and business processes, and operates in the oil &amp; gas industry? What if they are also impacted by the US's tariffs? Even further, what if they experienced a data breach in the prior year and have experienced changes in numerous key roles?</p>
<p>Clara AI is able to handle of this and more, guiding team members to the relevant guidance and assisting them in the audit process.</p>
<h4 id="workflow-assistance"><span class="section-number-4">2.3.2.</span> Workflow Assistance</h4>
<p>On top of the various regulations and internal guidance frameworks, auditors at the Big 4 also have to learn how to use their firm's specific audit platforms.</p>
<p>KPMG built the KPMG Clara Workflow (KCw) for audits and SOC reports, which requires teams to fill out the audit file for their engagement, answer all questions that appear, perform their testing, and abide by the required items.</p>
<p>Clara AI helps by connecting auditors to the internal guidance that supports each section of the audit platform so that they can complete their engagement in compliance with their requirements.</p>
<h2 id="a-day-with-ai"><span class="section-number-2">3.</span> A Day with AI</h2>
<p>Before I finish, I wanted to provide an example of how an auditor might utilize AI throughout their day. You can probably summarize this already from the information provided above, but I wanted to lay out in plain terms here at the end:</p>
<ul>
<li>Strategic planning in the morning with any AI. Review regulatory news, summarize key decisions made by the government, industry leaders, and more.</li>
<li>If you have a lot of emails and messages, use Copilot to summarize actions items and make a prioritized plan of action.</li>
<li>As you test or review items in the audit file, use Clara AI to identify gaps in approach.</li>
<li>During meetings, enable transcriptions and Facilitator. Use these tools so that people attending the meeting don't need to take detailed notes. Instead, each person can be fully invested in the topics they're discussing.</li>
<li>Use Copilot to summarize and draft outlines for emails to the team and/or client.</li>
</ul>
<h3 id="conclusion"><span class="section-number-3">3.1.</span> Conclusion</h3>
<h4 id="what-can-ai-do"><span class="section-number-4">3.1.1.</span> What <em>Can</em> AI Do?</h4>
<p>AI <em>can</em> increase efficiency, consistency, and audit quality, but there are some big assumptions when we state that. We first need to make sure we, as auditors, are using the tools themselves effectively. For an auditor, a general AI chat won't be very useful. Instead, we should be training and using focused models that solve specific purposes. The model will perform better if it's trained for specific purpose and isn't expected to know everything that's ever existed.</p>
<p>But what happens when we <em>do</em> use AI effectively? Well, at that point, we are able to elevate ourselves and automate the manual and tedious tasks that have taken up time historically.</p>
<p>Staff who may have been asked to spends hours cleaning data from the client before can now spend a shorter length of time reviewing the data output instead and then using that additional time to enhance their critical thinking. If you are used to performing these manual tasks, think about what your seniors or managers do with your results. Can you take on those tasks instead and elevate yourself into those roles?</p>
<h4 id="the-role-of-the-human-in-an-ai-world"><span class="section-number-4">3.1.2.</span> The Role of the Human in an AI World</h4>
<p>Last, but not least, I want to <strong>highly stress</strong> the importance of human in the loop (HITL) concept. What we do as auditors is strategically important, whether you're an internal or external auditor, and cannot be replaced by the current landscape of AI tools. Therefore, when we're using AI, we need to make sure we validate <strong>everything</strong> coming out the tool. At no point can the AI take responsibility, so we need to take responsibility for our actions when we use AI.</p>
<p>However, when we do all of this, we are able to elevate the role of the auditor to one of judgment, critical thinking, validation, and client relationship management. This means faster, higher quality, and more impactful audits throughout the industry.</p>
]]></description>
    </item>
    <item>
      <title>WCAG Compliance: Accessibility as a Real Constraint</title>
      <link>https://cleberg.net/blog/wcag.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/wcag.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Fri, 14 Nov 2025 00:00:00 +0000</pubDate>
      <category>audit</category>
      <category>web</category>
      <description><![CDATA[<h2 id="wcag-2"><span class="section-number-2">1.</span> WCAG 2</h2>
<p>What are the Web Content Accessibility Guidelines (WCAG) 2 requirements?</p>
<p>While the full list of WCAG requirements may seem intimidating, it's actually straightforward for a static site like <code class="verbatim">cleberg.net</code> if you are intentional about design. Luckily, they offer a <a href="https://www.w3.org/WAI/WCAG22/quickref/">Quick Reference</a> guide that is much easier to parse than the full specification.</p>
<p>So, while it wasn't onerous to push myself over the 100% threshold, I wanted to write about how my current website design contributed to my compliance rate and why WCAG is important.</p>
<h2 id="why-wcag"><span class="section-number-2">2.</span> Why WCAG?</h2>
<p>Before I dive into the specifics of how my website complies with these requirements, I wanted to touch on the importance of WCAG itself.</p>
<p>There are three major reasons I wanted to implement the WCAG requirements on my website:</p>
<ol>
<li><strong>Usability</strong>: The main reason, which I've covered in numerous other blog posts about minimalism and design, is usability. I believe that our tech should always serve a purpose and I believe that the design of a tool should encapsulate that idea. Therefore, designing a website with intent leads to better usability, both by those with and without disabilities.</li>
<li><strong>Kindness</strong>: What's better than designing a tool accessible by <em>everyone</em>? Personally, I love the idea that no matter who visits my website, they should experience the same content and same utility intended by the website.</li>
<li><strong>Future-Proofing</strong>: Technology, include internet tools, are changing constantly. When a website is well-designed, reachable by all audiences, and utilitarian, it will be able to last longer or even "decay gracefully".</li>
</ol>
<h2 id="implementing-wcag-on-my-website"><span class="section-number-2">3.</span> Implementing WCAG On My Website</h2>
<p>Since I do not implement JavaScript, forms, or multimedia content on my website, the list of items to implement was short.</p>
<p>I'll go through some of the items that I considered during my manual verification of the site. If an item is not on this list, it is either <strong>not applicable</strong> or the native browser functionality covers the requirement and I do not implement any custom element that would require verification.</p>
<ul>
<li>[1.1]: Text alternatives for non-text content (i.e., images)<ul>
<li>For each image within my website, I made sure that alt-text was available.</li>
</ul>
</li>
<li>[1.3.1]: Use Accessible Rich Internet Applications (ARIA) landmarks to identify regions of a page<ul>
<li>ARIA landmarks are available for the navigation menu on my website, which is the only element I use which is recommended by WCAG to have an ARIA role.</li>
</ul>
</li>
<li>[1.3.1]: Use semantic HTML elements to identify regions of a page<ul>
<li>I have always used semantic HTML, but I reviewed my HTML templates to ensure I had coverage. In short, I use elements like <code class="verbatim">&lt;nav&gt;</code>, <code class="verbatim">&lt;main&gt;</code>, <code class="verbatim">&lt;article&gt;</code>, and <code class="verbatim">&lt;footer&gt;</code> instead of <code class="verbatim">&lt;div&gt;</code> elements.</li>
</ul>
</li>
<li>[1.4.1]: Use a color with a relative luminance difference of 3:1 or greater<ul>
<li>When choosing the color palettes for this site, I ensured that all were at least AA compliant and in most cases, AAA compliant.</li>
</ul>
</li>
<li>[1.4.4]: Use em (or rem) units for font sizes<ul>
<li>All sizing on this site uses <code class="verbatim">rem</code> sizing.</li>
</ul>
</li>
<li>[2.4.1]: Create links to skip blocks of repeated material<ul>
<li>I created a <code class="verbatim">skip-to-content</code> link hidden at the top each web page that allows keyboard or screen reader users to skip the navigation block.</li>
</ul>
</li>
<li>[2.4.6]: Provide descriptive headings<ul>
<li>Each page contains hierarchical headers starting at <code class="verbatim">&lt;h1&gt;</code>.</li>
</ul>
</li>
<li>[3.1.1]: Use the language attribute on the HTML element<ul>
<li>Each pages is defined with <code class="verbatim">&lt;html lang=en-us&gt;</code>.</li>
</ul>
</li>
<li>[3.1.4]: Provide an expansion of an abbreviation on the first occurrence<ul>
<li>To the best of my ability, I have been reviewing all historical posts on this site and expanding abbreviations upon first use.</li>
</ul>
</li>
<li>[3.2]: Make web pages appear and operate in predictable ways<ul>
<li>This, and many other requirements, are resolved by a combination of (1) native browser functionality which works as expected since I am using semantic HTML, and (2) my use of a structure outline and logical content flow on each page of the site.</li>
</ul>
</li>
</ul>
<h2 id="results"><span class="section-number-2">4.</span> Results</h2>
<figure><img src="https://img.cleberg.net/blog/20251113-wcag/accessibility_assessment.webp" alt="Results from the IBM Equal Access Accessibility Checker, showing 94% confirmed compliance, with the remaining manually confirmed."><figcaption><span class="figure-number">Figure 1: </span>IBM Equal Access Accessibility Checker</figcaption></figure>
<p>To confirm compliance, I chose <em>not</em> to use one of the "free" accessibility checker websites, since they often only test one page at a time, take a while to run, and I just generally don't enjoy scanning my website with random services.</p>
<p>Instead, I used the <a href="https://www.ibm.com/able/toolkit/tools/#develop">IBM Equal Access Accessibility Checker</a> extension on Firefox. This allowed me to scan each page I wanted, stored my scans, and provided in-depth results with links to guidance and suggestions for fixing each issue.</p>
<p>This was great as it showed me a handful of issues I hadn't caught previously. However, the image above shows that my site is 94% compliant through <strong>automated</strong> checks and I manually verified the remaining 6% of checks.</p>
<p>I performed these scans for all top-level pages on my website (home, about, blog, services, about, salary, and now), as well as the three latest blog posts to confirm compliance.</p>
<p>I'd love to test 100% of every page of my website one day and will continue to strive to enhance my compliance with ARIA and WCAG.</p>
]]></description>
    </item>
    <item>
      <title>Using aerc on macOS</title>
      <link>https://cleberg.net/blog/aerc-macos.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/aerc-macos.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Sun, 02 Nov 2025 00:00:00 +0000</pubDate>
      <category>linux</category>
      <description><![CDATA[<figure><img src="https://img.cleberg.net/blog/20251102-aerc-macos/read.webp" alt="An image of aerc with an email opened in the reader window."><figcaption><span class="figure-number">Figure 1: </span>aerc-mail</figcaption></figure>
<p>Shout-out to <a href="https://baty.net/posts/2025/10/using-aerc-for-email/">Jack Baty</a> for inspiring me to write about my <code class="verbatim">aerc-mail</code> client after chatting about it over email recently!</p>
<h2 id="overview"><span class="section-number-2">1.</span> Overview</h2>
<p><a href="https://aerc-mail.org/">aerc</a> is a text user interface (TUI) email client with intuitive defaults, easy setup, and hassle-free operations. This post will walk through my personal configuration for aerc on macOS.</p>
<h2 id="installation"><span class="section-number-2">2.</span> Installation</h2>
<p>Since I am on macOS, I opted to install aerc from Homebrew. There are build options for additional modules if you build from source, but I am okay with the default options.</p>
<p>You can view the information about the package prior to installing it, if you wish:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">brew</span></span><span class="meta function-call arguments shell"> info aerc</span></span></code></pre>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="keyword operator assignment shell">=</span><span class="string unquoted shell">=&gt;</span> <span class="meta function-call shell"><span class="variable function shell">aerc:</span></span><span class="meta function-call arguments shell"> stable 0.21.0 (bottled</span><span class="meta function-call shell"></span><span class="meta post-cmd shell">)</span><span class="meta function-call shell"><span class="variable function shell">,</span></span><span class="meta function-call arguments shell"> HEAD</span>
<span class="meta function-call shell"><span class="variable function shell">Email</span></span><span class="meta function-call arguments shell"> client that runs in your terminal</span>
<span class="meta function-call shell"><span class="variable function shell">https://aerc-mail.org/</span></span>
<span class="meta function-call shell"><span class="variable function shell">Installed</span></span>
<span class="meta function-call shell"><span class="variable function shell">/opt/homebrew/Cellar/aerc/0.21.0</span></span><span class="meta function-call arguments shell"> (48 files, 23MB</span><span class="meta function-call shell"></span><span class="meta post-cmd shell">)</span> <span class="meta function-call shell"><span class="variable function shell">*</span></span>
  <span class="meta function-call shell"><span class="variable function shell">Poured</span></span><span class="meta function-call arguments shell"> from bottle using the formulae.brew.sh API on 2025-10-05 at 19:51:31</span>
<span class="meta function-call shell"><span class="variable function shell">From:</span></span><span class="meta function-call arguments shell"> https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/a/aerc.rb</span>
<span class="meta function-call shell"><span class="variable function shell">License:</span></span><span class="meta function-call arguments shell"> MIT</span>
<span class="keyword operator assignment shell">=</span><span class="string unquoted shell">=&gt;</span> <span class="meta function-call shell"><span class="variable function shell">Dependencies</span></span>
<span class="meta function-call shell"><span class="variable function shell">Build:</span></span><span class="meta function-call arguments shell"> go ✘, scdoc ✘</span>
<span class="meta function-call shell"><span class="variable function shell">Required:</span></span><span class="meta function-call arguments shell"> notmuch ✔</span>
<span class="keyword operator assignment shell">=</span><span class="string unquoted shell">=&gt;</span> <span class="meta function-call shell"><span class="variable function shell">Options</span></span>
<span class="meta function-call shell"><span class="variable function shell">--HEAD</span></span>
	<span class="meta function-call shell"><span class="variable function shell">Install</span></span><span class="meta function-call arguments shell"> HEAD version</span>
<span class="keyword operator assignment shell">=</span><span class="string unquoted shell">=&gt;</span> <span class="meta function-call shell"><span class="variable function shell">Downloading</span></span><span class="meta function-call arguments shell"> https://formulae.brew.sh/api/formula/aerc.json</span>
<span class="keyword operator assignment shell">=</span><span class="string unquoted shell">=&gt;</span> <span class="meta function-call shell"><span class="variable function shell">Analytics</span></span>
<span class="meta function-call shell"><span class="variable function shell">install:</span></span><span class="meta function-call arguments shell"> 136 (30 days</span><span class="meta function-call shell"></span><span class="meta post-cmd shell">)</span><span class="meta function-call shell"><span class="variable function shell">,</span></span><span class="meta function-call arguments shell"> 560 (90 days</span><span class="meta function-call shell"></span><span class="meta post-cmd shell">)</span><span class="meta function-call shell"><span class="variable function shell">,</span></span><span class="meta function-call arguments shell"> 1,772 (365 days</span><span class="meta function-call shell"></span><span class="meta post-cmd shell">)</span>
<span class="meta function-call shell"><span class="variable function shell">install-on-request:</span></span><span class="meta function-call arguments shell"> 136 (30 days</span><span class="meta function-call shell"></span><span class="meta post-cmd shell">)</span><span class="meta function-call shell"><span class="variable function shell">,</span></span><span class="meta function-call arguments shell"> 560 (90 days</span><span class="meta function-call shell"></span><span class="meta post-cmd shell">)</span><span class="meta function-call shell"><span class="variable function shell">,</span></span><span class="meta function-call arguments shell"> 1,772 (365 days</span><span class="meta function-call shell"></span><span class="meta post-cmd shell">)</span>
<span class="meta function-call shell"><span class="variable function shell">build-error:</span></span><span class="meta function-call arguments shell"> 3 (30 days</span><span class="meta function-call shell"></span><span class="meta post-cmd shell">)</span></span></code></pre>
<p>Once you confirm you want to install this package, run the following:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">brew</span></span><span class="meta function-call arguments shell"> install aerc</span></span></code></pre>
<h2 id="first-time-wizard"><span class="section-number-2">3.</span> First-Time Wizard</h2>
<p>When you run aerc for the first time, an IMAP &amp; SMTP wizard will walk you through a basic setup for your email account(s).</p>
<p>On macOS, aerc will save your configuration files in the following location: <code class="verbatim">~/Library/Preferences/aerc</code>.</p>
<p>I tried to create a <code class="verbatim">~/.config/aerc</code> directory, but the Library directory above took precedence. If you truly need to keep your files in <code class="verbatim">~/.config</code>, you could probably symlink that to the Library location. However, I accepted my fate and will just edit the files within the Library directory.</p>
<h2 id="configuration"><span class="section-number-2">4.</span> Configuration</h2>
<p>Once you have installed and setup aerc for the first time, you can configure the client and account settings.</p>
<p>As noted above, I will be working within the Library directory that aerc defaults to when installed via brew.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="support function cd shell">cd</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/Library/Preferences/aerc</span></span></code></pre>
<p>This directory should contain the following files. You can open the <code class="verbatim">accounts.conf</code> file to confirm it contains the information you input during the wizard process.</p>
<table>
<thead>
<tr><th>File</th><th>Purpose</th></tr>
</thead>
<tbody>
<tr><td><code class="verbatim">accounts.conf</code></td><td>Contains account-specific settings for IMAP &amp; SMTP accounts</td></tr>
<tr><td><code class="verbatim">aerc.conf</code></td><td>Contains program-wide settings</td></tr>
<tr><td><code class="verbatim">binds.conf</code></td><td>Contains key bindings for aerc</td></tr>
</tbody>
</table>
<p>I'll share my personal configuration, which is close to the defaults that existed at the time of writing this post.</p>
<p><code class="verbatim">accounts.conf</code></p>
<p>This is the information from the wizard. The only further customization I provided is the default signature file to be appended to each message I compose.</p>
<pre><code class="language-conf">[Personal]
source         = imaps://hello%40cleberg.net:PASSWORD@imap.migadu.com
outgoing       = smtps://hello%40cleberg.net:PASSWORD@smtp.migadu.com
default        = INBOX
from           = Christian Cleberg &lt;hello@cleberg.net&gt;
copy-to        = Sent
cache-headers  = true
signature-file = /Users/cmc/Library/Preferences/aerc/sigs/default</code></pre>
<p><code class="verbatim">sigs/default</code></p>
<p>Any content within this file will be appended to my messages, as noted above.</p>
<pre><code class="language-text">Christian Cleberg &lt;hello@cleberg.net&gt;
GPG: 3917 973F B159 BBB8 6194 5385 69451A51 7AC0 CB37</code></pre>
<p><code class="verbatim">aerc.conf</code></p>
<p>This contains quite a few customizations for my preferences related to downloads, encryption, mouse controls, editor, and message composition.</p>
<pre><code class="language-conf">[general]
# Prefer downloads to be saved to the Downloads folder
default-save-path=~/Downloads
# Use GPG for PGP encryption
pgp-provider=gpg

[ui]
# Enable mouse controls for scrolling, paging, etc.
mouse-enabled=true

[statusline]
[viewer]
# Use emacs instead of vi
pager=/usr/local/bin/emacs_viewer

[compose]
# Use emacs instead of vi
editor=emacs
# Add Cc as a default field to view each time I compose a message
header-layout=To|From,Cc,Subject
# Allow me to edit headers when composing (so I can customize From address)
edit-headers=true
# Warn me if I mentioned these words but don't attach a file
empty-subject-warning=true
no-attachment-warning=^[^&gt;]*attach(ed|ment)

[multipart-converters]

[filters]
text/plain=colorize
text/calendar=calendar
message/delivery-status=colorize
message/rfc822=colorize
text/html=! html
.headers=colorize

[openers]
[hooks]
[templates]</code></pre>
<blockquote>
<p><strong>IMPORTANT</strong>: If you use the <code class="verbatim">pager</code> option above that I'm using, you will need to create the <code class="verbatim">emacs_viewer</code> file as well.</p>
</blockquote>
<p>You can create the file following my process below, which will create an executable in the location specified in my <code class="verbatim">aerc.conf</code> file. I put it in <code class="verbatim">/usr/local/bin</code>, but you can put it anywhere as long as it exists in the file path specific within your configuration file.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> nano /usr/local/bin/emacs_viewer</span></span></code></pre>
<p>Paste this inside the file:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell">!/bin/bash</span><span class="comment line number-sign shell">
</span><span class="meta function-call shell"><span class="variable function shell">emacs</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>nw</span> - <span class="keyword operator assignment redirection shell">&lt;</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">1</span></span><span class="punctuation definition string end shell">&quot;</span></span></span></span></code></pre>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> chmod +x /usr/local/bin/emacs_viewer</span></span></code></pre>
<p><code class="verbatim">binds.conf</code></p>
<p>Finally, here are the key bindings. I did not change these, but I'm showing them here in case you have an issue and want to see the defaults.</p>
<pre><code class="language-conf"># Binds are of the form &lt;key sequence&gt; = &lt;command to run&gt;
# To use '=' in a key sequence, substitute it with "Eq": "&lt;Ctrl+Eq&gt;"
# If you wish to bind #, you can wrap the key sequence in quotes: "#" = quit
&lt;C-p&gt; = :prev-tab&lt;Enter&gt;
&lt;C-PgUp&gt; = :prev-tab&lt;Enter&gt;
&lt;C-n&gt; = :next-tab&lt;Enter&gt;
&lt;C-PgDn&gt; = :next-tab&lt;Enter&gt;
\[t = :prev-tab&lt;Enter&gt;
\]t = :next-tab&lt;Enter&gt;
&lt;C-t&gt; = :term&lt;Enter&gt;
? = :help keys&lt;Enter&gt;
&lt;C-c&gt; = :prompt 'Quit?' quit&lt;Enter&gt;
&lt;C-q&gt; = :prompt 'Quit?' quit&lt;Enter&gt;
&lt;C-z&gt; = :suspend&lt;Enter&gt;

[messages]
q = :prompt 'Quit?' quit&lt;Enter&gt;

j = :next&lt;Enter&gt;
&lt;Down&gt; = :next&lt;Enter&gt;
&lt;C-d&gt; = :next 50%&lt;Enter&gt;
&lt;C-f&gt; = :next 100%&lt;Enter&gt;
&lt;PgDn&gt; = :next 100%&lt;Enter&gt;

k = :prev&lt;Enter&gt;
&lt;Up&gt; = :prev&lt;Enter&gt;
&lt;C-u&gt; = :prev 50%&lt;Enter&gt;
&lt;C-b&gt; = :prev 100%&lt;Enter&gt;
&lt;PgUp&gt; = :prev 100%&lt;Enter&gt;
g = :select 0&lt;Enter&gt;
G = :select -1&lt;Enter&gt;

J = :next-folder&lt;Enter&gt;
&lt;C-Down&gt; = :next-folder&lt;Enter&gt;
K = :prev-folder&lt;Enter&gt;
&lt;C-Up&gt; = :prev-folder&lt;Enter&gt;
H = :collapse-folder&lt;Enter&gt;
&lt;C-Left&gt; = :collapse-folder&lt;Enter&gt;
L = :expand-folder&lt;Enter&gt;
&lt;C-Right&gt; = :expand-folder&lt;Enter&gt;

v = :mark -t&lt;Enter&gt;
&lt;Space&gt; = :mark -t&lt;Enter&gt;:next&lt;Enter&gt;
V = :mark -v&lt;Enter&gt;

T = :toggle-threads&lt;Enter&gt;
zc = :fold&lt;Enter&gt;
zo = :unfold&lt;Enter&gt;
za = :fold -t&lt;Enter&gt;
zM = :fold -a&lt;Enter&gt;
zR = :unfold -a&lt;Enter&gt;
&lt;tab&gt; = :fold -t&lt;Enter&gt;

zz = :align center&lt;Enter&gt;
zt = :align top&lt;Enter&gt;
zb = :align bottom&lt;Enter&gt;

&lt;Enter&gt; = :view&lt;Enter&gt;
d = :choose -o y 'Really delete this message' delete-message&lt;Enter&gt;
D = :delete&lt;Enter&gt;
a = :archive flat&lt;Enter&gt;
A = :unmark -a&lt;Enter&gt;:mark -T&lt;Enter&gt;:archive flat&lt;Enter&gt;

C = :compose&lt;Enter&gt;
m = :compose&lt;Enter&gt;

b = :bounce&lt;space&gt;

rr = :reply -a&lt;Enter&gt;
rq = :reply -aq&lt;Enter&gt;
Rr = :reply&lt;Enter&gt;
Rq = :reply -q&lt;Enter&gt;

c = :cf&lt;space&gt;
$ = :term&lt;space&gt;
! = :term&lt;space&gt;
| = :pipe&lt;space&gt;

/ = :search&lt;space&gt;
\ = :filter&lt;space&gt;
n = :next-result&lt;Enter&gt;
N = :prev-result&lt;Enter&gt;
&lt;Esc&gt; = :clear&lt;Enter&gt;

s = :split&lt;Enter&gt;
S = :vsplit&lt;Enter&gt;

pl = :patch list&lt;Enter&gt;
pa = :patch apply &lt;Tab&gt;
pd = :patch drop &lt;Tab&gt;
pb = :patch rebase&lt;Enter&gt;
pt = :patch term&lt;Enter&gt;
ps = :patch switch &lt;Tab&gt;

[messages:folder=Drafts]
&lt;Enter&gt; = :recall&lt;Enter&gt;

[view]
/ = :toggle-key-passthrough&lt;Enter&gt;/
q = :close&lt;Enter&gt;
O = :open&lt;Enter&gt;
o = :open&lt;Enter&gt;
S = :save&lt;space&gt;
| = :pipe&lt;space&gt;
D = :delete&lt;Enter&gt;
A = :archive flat&lt;Enter&gt;

&lt;C-y&gt; = :copy-link &lt;space&gt;
&lt;C-l&gt; = :open-link &lt;space&gt;

f = :forward&lt;Enter&gt;
rr = :reply -a&lt;Enter&gt;
rq = :reply -aq&lt;Enter&gt;
Rr = :reply&lt;Enter&gt;
Rq = :reply -q&lt;Enter&gt;

H = :toggle-headers&lt;Enter&gt;
&lt;C-k&gt; = :prev-part&lt;Enter&gt;
&lt;C-Up&gt; = :prev-part&lt;Enter&gt;
&lt;C-j&gt; = :next-part&lt;Enter&gt;
&lt;C-Down&gt; = :next-part&lt;Enter&gt;
J = :next&lt;Enter&gt;
&lt;C-Right&gt; = :next&lt;Enter&gt;
K = :prev&lt;Enter&gt;
&lt;C-Left&gt; = :prev&lt;Enter&gt;

[view::passthrough]
$noinherit = true
$ex = &lt;C-x&gt;
&lt;Esc&gt; = :toggle-key-passthrough&lt;Enter&gt;

[compose]
# Keybindings used when the embedded terminal is not selected in the compose
# view
$noinherit = true
$ex = &lt;C-x&gt;
$complete = &lt;C-o&gt;
&lt;C-k&gt; = :prev-field&lt;Enter&gt;
&lt;C-Up&gt; = :prev-field&lt;Enter&gt;
&lt;C-j&gt; = :next-field&lt;Enter&gt;
&lt;C-Down&gt; = :next-field&lt;Enter&gt;
&lt;A-p&gt; = :switch-account -p&lt;Enter&gt;
&lt;C-Left&gt; = :switch-account -p&lt;Enter&gt;
&lt;A-n&gt; = :switch-account -n&lt;Enter&gt;
&lt;C-Right&gt; = :switch-account -n&lt;Enter&gt;
&lt;tab&gt; = :next-field&lt;Enter&gt;
&lt;backtab&gt; = :prev-field&lt;Enter&gt;
&lt;C-p&gt; = :prev-tab&lt;Enter&gt;
&lt;C-PgUp&gt; = :prev-tab&lt;Enter&gt;
&lt;C-n&gt; = :next-tab&lt;Enter&gt;
&lt;C-PgDn&gt; = :next-tab&lt;Enter&gt;

[compose::editor]
# Keybindings used when the embedded terminal is selected in the compose view
$noinherit = true
$ex = &lt;C-x&gt;
&lt;C-k&gt; = :prev-field&lt;Enter&gt;
&lt;C-Up&gt; = :prev-field&lt;Enter&gt;
&lt;C-j&gt; = :next-field&lt;Enter&gt;
&lt;C-Down&gt; = :next-field&lt;Enter&gt;
&lt;C-p&gt; = :prev-tab&lt;Enter&gt;
&lt;C-PgUp&gt; = :prev-tab&lt;Enter&gt;
&lt;C-n&gt; = :next-tab&lt;Enter&gt;
&lt;C-PgDn&gt; = :next-tab&lt;Enter&gt;

[compose::review]
# Keybindings used when reviewing a message to be sent
# Inline comments are used as descriptions on the review screen
y = :send&lt;Enter&gt; # Send
n = :abort&lt;Enter&gt; # Abort (discard message, no confirmation)
s = :sign&lt;Enter&gt; # Toggle signing
x = :encrypt&lt;Enter&gt; # Toggle encryption to all recipients
v = :preview&lt;Enter&gt; # Preview message
p = :postpone&lt;Enter&gt; # Postpone
q = :choose -o d discard abort -o p postpone postpone&lt;Enter&gt; # Abort or postpone
e = :edit&lt;Enter&gt; # Edit (body and headers)
a = :attach&lt;space&gt; # Add attachment
d = :detach&lt;space&gt; # Remove attachment

[terminal]
$noinherit = true
$ex = &lt;C-x&gt;

&lt;C-p&gt; = :prev-tab&lt;Enter&gt;
&lt;C-n&gt; = :next-tab&lt;Enter&gt;
&lt;C-PgUp&gt; = :prev-tab&lt;Enter&gt;
&lt;C-PgDn&gt; = :next-tab&lt;Enter&gt;</code></pre>
<h2 id="operation"><span class="section-number-2">5.</span> Operation</h2>
<p>Now that I have configured the program to my liking, I can run <code class="verbatim">aerc</code> in my terminal and see my changes reflected!</p>
<p>Personally, I keep aerc running in a terminal at all times, since it has the operation to ring a bell when a new message arrives.</p>
<figure><img src="https://img.cleberg.net/blog/20251102-aerc-macos/notification.webp" alt="An image of the bell notification on macOS from aerc."><figcaption><span class="figure-number">Figure 2: </span>Notification</figcaption></figure>
<p>The mailbox views and composition screens are fairly standard, but it does a great job at displaying information effectively.</p>
<figure><img src="https://img.cleberg.net/blog/20251102-aerc-macos/inbox.webp" alt="An image of the aerc inbox view."><figcaption><span class="figure-number">Figure 3: </span>Inbox</figcaption></figure>
<figure><img src="https://img.cleberg.net/blog/20251102-aerc-macos/compose.webp" alt="An image of Emacs being used as the composition window for aerc."><figcaption><span class="figure-number">Figure 4: </span>Compose Message</figcaption></figure>
<figure><img src="https://img.cleberg.net/blog/20251102-aerc-macos/send.webp" alt="An image of the aerc commands to send an email."><figcaption><span class="figure-number">Figure 5: </span>Send Message</figcaption></figure>
<figure><img src="https://img.cleberg.net/blog/20251102-aerc-macos/read.webp" alt="An image of an email opened in aerc's reading window."><figcaption><span class="figure-number">Figure 6: </span>Read Message</figcaption></figure>
<p>All in all, I love aerc and far prefer it to my previous client (neomutt). In certain cases, Thunderbird is more convenient, but I don't find myself opening it at all lately. I will definitely update this post in the future if I find anything extraordinary to add about aerc.</p>
]]></description>
    </item>
    <item>
      <title>Digital Garden</title>
      <link>https://cleberg.net/blog/digital-garden.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/digital-garden.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Fri, 24 Oct 2025 00:00:00 +0000</pubDate>
      <category>web</category>
      <description><![CDATA[<h2 id="what-s-a-digital-garden"><span class="section-number-2">1.</span> What's a Digital Garden?</h2>
<p>Before I start describing digital gardens, I want to show a couple examples that are distinct enough to show how varied digital gardens are.</p>
<p>The first is a website (<a href="https://avas.space">ava's space</a>) and the second is a private collection of notes, using <a href="https://www.orgroam.com/">org-roam</a>.</p>
<figure><img src="https://img.cleberg.net/blog/20251024-digital-garden/ava.webp" alt="Ava's Space, a digital garden and website by Ava."><figcaption><span class="figure-number">Figure 1: </span>avas.space</figcaption></figure>
<figure><img src="https://img.cleberg.net/blog/20251024-digital-garden/orgroam.webp" alt="A screenshot of an org-roam digital garden and collection of note files."><figcaption><span class="figure-number">Figure 2: </span>Org Roam</figcaption></figure>
<p>A digital garden is a personal space, just for you. It could serve any number of purposes, which I'll get into later, but the key is that it serves a specific purpose for yourself.</p>
<p>The primary features of a digital garden, as opposed to a personal website or blog, is that it is not inherently structured in a strict manner, it may follow a free form structure, it may look like a work-in-progress wiki.</p>
<p>At the end of the day, it defines a web page where any type of content exists and the author takes time and care to prune it in a specific manner.</p>
<h2 id="historical-context"><span class="section-number-2">2.</span> Historical Context</h2>
<p>A lot of people talk about <a href="https://www.eastgate.com/garden/Enter.html">Hypertext Gardens: Delightful Vistas</a> by Mark Bernstein as the first instance of this phrase on the internet. And while this may be true, I want to take a step further back.</p>
<p>Have you heard of a <a href="https://en.wikipedia.org/wiki/Memex">Memex</a>? This hypothetical device was described in Vannevar Bush's 1945 article "As We May Think". He envisioned a device that would be able to store all of a person's information for them - books, records, and communications. The person could then reference the Memex for any information and be guided to the correct spot. Essentially, it would the 1940's version of a mind mapping or personal knowledge system.</p>
<p>From the Memex to Hypertext Gardens to mind maps to other knowledge management systems, humans seem intent on constantly reinventing the art of information organization.</p>
<p>The modern web is the result of 30+ years of redesigning the web to streamline information. However, in this refinement, we've lost the art and beauty of personal websites where people would dump all of the information relevant to themselves.</p>
<p>Digital Gardens are a movement to bring these personal websites back and present them in a personalized fashion.</p>
<h2 id="common-uses"><span class="section-number-2">3.</span> Common Uses</h2>
<p>Before I get into <em>how</em> to build a digital garden, I want to touch on the potential uses. Everyone has their own reason for building a website and digital gardens are no exception.</p>
<p>You may want to build a digital garden for any number of reasons:</p>
<ul>
<li>Knowledge management</li>
<li>Creative exploration</li>
<li>Collaborative learning</li>
<li>Personal reflection</li>
<li>Artistic expression</li>
<li>Data hoarding</li>
<li>Social interaction</li>
</ul>
<h2 id="how-to-build-your-own-garden"><span class="section-number-2">4.</span> How to Build Your Own Garden</h2>
<p>If you do want to create your own digital garden, you can get started with a few easy steps:</p>
<ol>
<li><strong>Choose a platform</strong>: You can host a website for free on platforms like GitHub or use a more note-taking platform like Notion or Obsidian.</li>
<li><strong>Set Up the Structure</strong>: Decide how you want to organize your content. Remember the purpose of a digital garden! Plant all of the information you care about and then work to prune and clean them up as they grow.</li>
<li><strong>Start with Your Interests</strong>: A digital garden should reflect yourself. Find your passions and start from there.</li>
<li><strong>Regular Updates</strong>: A garden won't grow if you ignore it. Remember to check in and think if you want to add more, prune things out, or move things around.</li>
<li><strong>Interlinking Ideas</strong>: Like plants and ecosystems, a digital garden should link together. You may use tags or links to connect items on your own site or perhaps includes links or lists to other gardens you enjoy.</li>
</ol>
<p>By far the most important piece here is regular updates. You can always fix or change things, but the garden won't grow if you don't contribute to it.</p>
<h2 id="additional-suggestions"><span class="section-number-2">5.</span> Additional Suggestions</h2>
<p>Digital gardens are such an easy way to manage your knowledge and unleash your creativity. Instead of sticking to the usual blog format, you get a space where your ideas can grow and change over time. Whether you want to document what you’re learning, share thoughts with others, or just reflect on your journey, a digital garden can be the perfect tool.</p>
<p>I strongly encourage you to create your own today, even if it starts as private notes instead of a website! Nothing is ever too small and the point of a garden isn't to be perfect, but to be a place where you can experiment and have fun.</p>
]]></description>
    </item>
    <item>
      <title>Rocket League on macOS via CrossOver</title>
      <link>https://cleberg.net/blog/rocket-league-macos.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/rocket-league-macos.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Mon, 06 Oct 2025 00:00:00 +0000</pubDate>
      <category>linux</category>
      <description><![CDATA[<figure><img src="https://img.cleberg.net/blog/20251006-rocket-league-macos/launch.webp" alt="The Rocket League launch screen on macOS."><figcaption><span class="figure-number">Figure 1: </span>Rocket League on macOS</figcaption></figure>
<h2 id="intro"><span class="section-number-2">1.</span> Intro</h2>
<p>Rocket League isn’t natively supported on macOS, but you can run it using CrossOver, a compatibility layer that lets Windows applications run on macOS. This guide walks you through installing CrossOver, setting up the Epic Games Store (or Steam), and getting Rocket League up and running.</p>
<h2 id="install-crossover"><span class="section-number-2">2.</span> Install CrossOver</h2>
<p>To start, we will install CrossOver with <a href="https://brew.sh">Homebrew</a>.</p>
<pre><code class="language-shell">brew install --cask crossover</code></pre>
<p>Once installed, launch CrossOver and select the Try Now button. CrossOver offers a 14‑day free trial. After the trial, a full license costs $74 USD.</p>
<h2 id="set-up-the-epic-games-store-or-steam"><span class="section-number-2">3.</span> Set Up the Epic Games Store (or Steam)</h2>
<p>After opening CrossOver, click the Install button and install the Epic Games Store (or Steam, if you have Rocket League on Steam). You will need to agree to the installation prompts that pop up and it should install in just a couple minutes.</p>
<p>When the installer finishes, you’ll see a bottle (a sandboxed Windows environment) like the one below:</p>
<figure><img src="https://img.cleberg.net/blog/20251006-rocket-league-macos/bottle.webp" alt="The Epic Games Store bottle within CrossOver."><figcaption><span class="figure-number">Figure 2: </span>Epic Games Store Bottle</figcaption></figure>
<p>You can now launch the Epic application. Epic will update itself and then present the login screen:</p>
<figure><img src="https://img.cleberg.net/blog/20251006-rocket-league-macos/updater.webp" alt="The progress bar for updating the Epic Games Store bottle."><figcaption><span class="figure-number">Figure 3: </span>Epic Updater</figcaption></figure>
<figure><img src="https://img.cleberg.net/blog/20251006-rocket-league-macos/login.webp" alt="The Epic Login page."><figcaption><span class="figure-number">Figure 4: </span>Epic Login</figcaption></figure>
<h2 id="install-rocket-league"><span class="section-number-2">4.</span> Install Rocket League</h2>
<p>Sign in to your Epic account, locate Rocket League in your library, and click Install. The download and installation process will complete shortly (depending on your internet connection), and then you should be ready to play.</p>
<h2 id="play-the-game"><span class="section-number-2">5.</span> Play the Game</h2>
<p>Last but not least, launch the game from the Epic Games Store once you install it. It may take a minute or two when launching for the first time.</p>
<p>Take a look at the screenshots I was able to capture while playing on my M2 MacBook Pro with a PS5 Dualsense Edge controller:</p>
<figure><img src="https://img.cleberg.net/blog/20251006-rocket-league-macos/menu.webp" alt="The Rocket Leageu main menu."><figcaption><span class="figure-number">Figure 5: </span>Main Menu</figcaption></figure>
<figure><img src="https://img.cleberg.net/blog/20251006-rocket-league-macos/game.webp" alt="A screenshot of a replay within a Rocket League match."><figcaption><span class="figure-number">Figure 6: </span>In-Game</figcaption></figure>
<h2 id="tips-troubleshooting"><span class="section-number-2">6.</span> Tips &amp; Troubleshooting</h2>
<p>Overall, the controller support for my PS5 Dualsense Edge controller worked out of the box and the performance was excellent. However, issues can happen and I gathered some tips, in case they do.</p>
<ul>
<li><strong>Game runs slowly</strong>: In CrossOver, edit the bottle’s settings → Graphics → enable “Use DirectX 11” and increase the allocated RAM.</li>
<li><strong>Controller not detected</strong>: Install the Windows driver for your controller inside the bottle (e.g., Xbox 360 driver).</li>
<li><strong>Epic Store won’t update</strong>: Delete the EpicGamesLauncher cache folder inside the bottle (C:\Users\&lt;User&gt;\AppData\Local\EpicGamesLauncher\Saved) and restart the launcher.</li>
<li><strong>Crashes on launch</strong>: Ensure you have the latest macOS updates and that CrossOver is up‑to‑date (check “Check for Updates” in the app menu).</li>
</ul>
<h2 id="conclusion"><span class="section-number-2">7.</span> Conclusion</h2>
<p>That's it! It's a simple process that allows you to try out Rocket League on macOS for 14 and determine if you enjoy this solution enough to pay for it.</p>
<p>If you know a way to do this for free without paying for CrossOver, please reach out and let me know! I am hesitant to pay $74 simply to play Rocket League, but we shall see.</p>
<p>Happy boosting!</p>
]]></description>
    </item>
    <item>
      <title>My Privacy Toolkit</title>
      <link>https://cleberg.net/blog/privacy-toolkit.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/privacy-toolkit.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Fri, 03 Oct 2025 00:00:00 +0000</pubDate>
      <category>privacy</category>
      <description><![CDATA[<h2 id="vpn"><span class="section-number-2">1.</span> VPN</h2>
<p>I use a few different VPNs for different purposes. For general use, I use <a href="https://mullvad.net/en">Mullvad</a> due to its private account creation process, support for private payment options, and rock solid consistency. This is by far the most stable and high-speed VPN I have used over the last ~10 years.</p>
<p>I also use <a href="https://njal.la/vpn/">Njalla</a> whenever I need to use a service where Mullvad is blocked. I have found that the Njalla IP I was provisioned is not blocked anywhere, so it's useful for software that seemingly has blocked all major VPN providers. There is no client, but they provide OpenVPN and Wireguard support.</p>
<p>Finally, I use <a href="https://airvpn.org/">AirVPN</a> on my server's torrent service due to its support for port forwarding. I don't use it for any other purpose, but it works great with Transmission via Docker.</p>
<h2 id="dns"><span class="section-number-2">2.</span> DNS</h2>
<p>Using a VPN on every single device is not possible. For all of the other items on my network (IoT, Apple TVs, etc.), I enforce <a href="https://nextdns.io/">NextDNS</a> via the <a href="https://github.com/nextdns/nextdns/wiki/UnifiOS">UnifiOS script</a> they provide. This lets me control the DNS on my network, avoid the ISP's default DNS, and enforce blocklists at a LAN level for my home network.</p>
<h2 id="data-removal"><span class="section-number-2">3.</span> Data Removal</h2>
<p>I use <a href="https://www.easyoptouts.com/">Easy Opt Outs</a> due to its low price of $20 per year. There are other options that promise more utility, but I find that this service is adequate. Using this has dramatically reduced the spammy, "&lt;person&gt; info here" results on web searches.</p>
<p>Regardless, it's a low price to pay to make sure public information is not used against you and reduces the surface of information available via low-effort searches.</p>
<h2 id="passwords"><span class="section-number-2">4.</span> Passwords</h2>
<p>I use <a href="https://bitwarden.com/">Bitwarden</a> due to its use-friendly interface, which is important to the people I share secrets with. Bitwarden allows for seamless username and password generation, multi-device syncing via its own provided service, built-in password strength and duplicate analysis, wide range of device support, and general UI (after its recent UI refresh).</p>
<p>If I were only keeping passwords for myself and didn't need to support non-technical users, I would strongly prefer <a href="https://keepassxc.org/">KeePassXC</a>. This would allow me to use Syncthing or another personal syncing solution that would avoid a centralized server that controls my passwords and authentication to access the passwords.</p>
<h2 id="mfa"><span class="section-number-2">5.</span> MFA</h2>
<p>I use iOS, which is limited in options for great MFA apps. If you use Android, just use <a href="https://getaegis.app/">Aegis</a>.</p>
<p>For iOS, I currently use <a href="https://bitwarden.com/products/authenticator/">Bitwarden Authenticator</a>, which is a different app from Bitwarden. You can use this <em>without</em> linking it to a Bitwarden account and use it as a standalone app, if you're not a fan of storing your passwords and MFA methods in the same location. If you don't care, you can just use the MFA fields within Bitwarden itself.</p>
<p>The other options on iOS really aren't worth discussing, so I'll leave it here.</p>
<h2 id="communications"><span class="section-number-2">6.</span> Communications</h2>
<p>For private instant communications, I use <a href="https://signal.org/">Signal</a>. This is currently the gold standard for private direct messages. It is centralized, but it is very stable, provides forward secrecy for messages, and has a proven track record of not spilling data.</p>
<blockquote>
<p>As of 2026, I've started using <a href="https://simplex.chat/">SimpleX</a> and I think it will replace Signal for me.</p>
</blockquote>
<p>If we talk about other communication channels, I usually opt for emails encrypted with <a href="https://gnupg.org/">GPG (PGP)</a>. This isn't the best solution, but it does provide a trustworthy encryption method if you need to use email.</p>
<p>I am not a fan of the current landscape of private messaging apps outside of Signal (Matrix, Session, etc.), so I'll leave my thoughts here with Signal and PGP.</p>
<p>Want real privacy? Talk to someone in person when possible.</p>
<h2 id="browser-extensions"><span class="section-number-2">7.</span> Browser Extensions</h2>
<blockquote>
<p>As of 2026, I've completed switched over to <a href="https://www.torproject.org/">Tor</a> on my desktop and <a href="https://onionbrowser.com/">Onion Browser</a> on my phone for browsing.</p>
<p>With these browsers, I've removed all extensions and set the browsers to the highest privacy levels possible in the settings page.</p>
</blockquote>
<h3 id="firefox-desktop"><span class="section-number-3">7.1.</span> Firefox (Desktop)</h3>
<p><a href="https://ublockorigin.com/">uBlock Origin</a> is a no-brainer. This add-on provides domain-level blocking for resources, allowing you to block or allow specific domains, scripts, styles, and more with a click.</p>
<p>If you prefer to avoid mainstream websites and browse via alternative front-ends, I suggest using <a href="https://libredirect.github.io/">LibRedirect</a>. You can configure this add-on to automatically redirect your requests to privacy-respecting alternatives.</p>
<h3 id="safari-ios"><span class="section-number-3">7.2.</span> Safari (iOS)</h3>
<p>Since uBlock Origin doesn't work on Safari, I opt for <a href="https://apps.apple.com/us/app/ublock-origin-lite/id6745342698?platform=iphone">uBlock Origin Lite</a>, which is a decent alternative.</p>
<p>Similar to LibRedirect, I use <a href="https://apps.apple.com/us/app/privacy-redirect/id1578144015">Privacy Redirect</a> on iOS to redirect websites to private alternative front-ends.</p>
<h2 id="payments"><span class="section-number-2">8.</span> Payments</h2>
<p>If you're just trying to avoid your bank collecting and using information about your purchases, you can try something like <a href="https://www.privacy.com/">Privacy.com</a>, which lets you mask the purchase information from your bank.</p>
<p>If you're paying in person, I vote for paying with cash. Withdraw a certain amount per paycheck and use for all in-person payments, whenever possible.</p>
]]></description>
    </item>
    <item>
      <title>Minimalist Site: Strip It Down</title>
      <link>https://cleberg.net/blog/minimalist-website-redesign.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/minimalist-website-redesign.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Thu, 25 Sep 2025 00:00:00 +0000</pubDate>
      <category>web</category>
      <description><![CDATA[<p>I know what you're thinking: "ANOTHER blog post about redesigning the website?"</p>
<p>Yes. Another blog post about redesigning the website. I enjoy it, what can I say?</p>
<p>I wrote my latest post about redesigning from a monospace-driven, terminal-styled theme to a more natural paper-inspired theme. However, it left a nagging feeling that something was missing. What if I took it further? Was there really any reason that I had any of that CSS at all?</p>
<figure><img src="https://img.cleberg.net/blog/20250905-human-website-design/after.webp" alt="A screenshot of the old theme for cleberg.net."><figcaption><span class="figure-number">Figure 1: </span>Old Theme</figcaption></figure>
<figure><img src="https://img.cleberg.net/blog/20250925-minimalist-website-redesign/minimal.webp" alt="A screenshot of the new theme for cleberg.net."><figcaption><span class="figure-number">Figure 2: </span>New Theme</figcaption></figure>
<h2 id="inspiration"><span class="section-number-2">1.</span> Inspiration</h2>
<p>I <em>briefly</em> touched on my inspiration in the last post (hint: wabi-sabi, sho ga nai, brutalism, minimalism), but I didn't expand on the <em>why</em> for these concepts.</p>
<p>So, why? The minimalistic approach to web design has resonated with me for a long time. But why minimalism?</p>
<p>Officially, "the concept of minimalist architecture is to strip everything down to its essential quality and achieve simplicity."</p>
<p>This is a blog. It also has pages dedicated to describing who I am and what I offer. Therefore, the essential quality is the information delivered by the words and the design on your screen. To effectively communicate this information, I tried to understand how online information is best read.</p>
<p>With all of that out of the way, let's get on with it.</p>
<h2 id="core-changes"><span class="section-number-2">2.</span> Core Changes</h2>
<p>Below is a quick audit of the original style sheet and markup, and the elements I've removed or added. For more in-depth information, refer to the <a href="https://gitbay.org/cmc/cleberg.net/commit/6eb7d43fc257638583e6a4ffefefc47f730595e4">git diff</a>.</p>
<p>w*HTML*</p>
<ul>
<li>HTML is now minified</li>
<li>File tags</li>
<li>Links to site pages are moved from the <code class="verbatim">index</code> to the <code class="verbatim">about</code> page</li>
<li>Wiki was removed entirely</li>
<li>Added a few <code class="verbatim">&lt;br&gt;</code> elements to compensate for some of the CSS removals</li>
</ul>
<p><strong>CSS</strong></p>
<p>For the CSS, I removed <em>everything</em>, except the following rules.</p>
<pre><code class="language-css highlight"><span class="source css"><span class="meta selector css"><span class="entity name tag css">body</span> </span><span class="meta property-list css"><span class="punctuation section property-list css">{</span>
  <span class="meta property-name css"><span class="support type property-name css">max-width</span></span><span class="punctuation separator key-value css">:</span><span class="meta property-value css"> </span><span class="meta property-value css"><span class="constant numeric css">50<span class="keyword other unit css">em</span></span></span><span class="punctuation terminator rule css">;</span>
  <span class="meta property-name css"><span class="support type property-name css">margin</span></span><span class="punctuation separator key-value css">:</span><span class="meta property-value css"> </span><span class="meta property-value css"><span class="constant numeric css">1.5<span class="keyword other unit css">rem</span></span></span><span class="punctuation terminator rule css">;</span>
</span><span class="punctuation section property-list css">}</span>

<span class="meta selector css"><span class="entity name tag css">nav</span> <span class="entity name tag css">ul</span> </span><span class="meta property-list css"><span class="punctuation section property-list css">{</span>
    <span class="meta property-name css"><span class="support type property-name css">list-style-type</span></span><span class="punctuation separator key-value css">:</span><span class="meta property-value css"> </span><span class="meta property-value css"><span class="support constant property-value css">none</span></span><span class="punctuation terminator rule css">;</span>
    <span class="meta property-name css"><span class="support type property-name css">display</span></span><span class="punctuation separator key-value css">:</span><span class="meta property-value css"> </span><span class="meta property-value css"><span class="support constant property-value css">flex</span></span><span class="punctuation terminator rule css">;</span>
    <span class="meta property-name css"><span class="support type property-name css">padding</span></span><span class="punctuation separator key-value css">:</span><span class="meta property-value css"> </span><span class="meta property-value css"><span class="constant numeric css">0</span></span><span class="punctuation terminator rule css">;</span>
</span><span class="punctuation section property-list css">}</span>

<span class="meta selector css"><span class="entity name tag css">nav</span> <span class="entity name tag css">ul</span> <span class="entity name tag css">li</span> </span><span class="meta property-list css"><span class="punctuation section property-list css">{</span>
    <span class="meta property-name css"><span class="support type property-name css">margin-right</span></span><span class="punctuation separator key-value css">:</span><span class="meta property-value css"> </span><span class="meta property-value css"><span class="constant numeric css">0.5<span class="keyword other unit css">rem</span></span></span><span class="punctuation terminator rule css">;</span>
</span><span class="punctuation section property-list css">}</span>

<span class="meta selector css"><span class="entity name tag css">img</span> </span><span class="meta property-list css"><span class="punctuation section property-list css">{</span>
    <span class="meta property-name css"><span class="support type property-name css">border-style</span></span><span class="punctuation separator key-value css">:</span><span class="meta property-value css"> </span><span class="meta property-value css"><span class="support constant property-value css">none</span></span><span class="punctuation terminator rule css">;</span>
    <span class="meta property-name css"><span class="support type property-name css">width</span></span><span class="punctuation separator key-value css">:</span><span class="meta property-value css"> </span><span class="meta property-value css"><span class="constant numeric css">100<span class="keyword other unit css">%</span></span></span><span class="punctuation terminator rule css">;</span>
</span><span class="punctuation section property-list css">}</span>

<span class="meta selector css"><span class="entity name tag css">table</span> </span><span class="meta property-list css"><span class="punctuation section property-list css">{</span>
    <span class="meta property-name css"><span class="support type property-name css">border</span></span><span class="punctuation separator key-value css">:</span><span class="meta property-value css"> </span><span class="meta property-value css"><span class="constant numeric css">1<span class="keyword other unit css">px</span></span> <span class="support constant property-value css">solid</span> <span class="constant other color rgb-value css"><span class="punctuation definition constant css">#</span>111</span></span><span class="punctuation terminator rule css">;</span>
    <span class="meta property-name css"><span class="support type property-name css">border-collapse</span></span><span class="punctuation separator key-value css">:</span><span class="meta property-value css"> </span><span class="meta property-value css"><span class="support constant property-value css">collapse</span></span><span class="punctuation terminator rule css">;</span>
    <span class="meta property-name css"><span class="support type property-name css">width</span></span><span class="punctuation separator key-value css">:</span><span class="meta property-value css"> </span><span class="meta property-value css"><span class="constant numeric css">100<span class="keyword other unit css">%</span></span></span><span class="punctuation terminator rule css">;</span>
</span><span class="punctuation section property-list css">}</span>

<span class="meta selector css"><span class="entity name tag css">pre</span>,
<span class="entity name tag css">pre</span><span class="punctuation separator combinator css">&gt;</span><span class="entity name tag css">code</span>,
<span class="entity name tag css">code</span> </span><span class="meta property-list css"><span class="punctuation section property-list css">{</span>
    <span class="meta property-name css"><span class="support type property-name css">font-size</span></span><span class="punctuation separator key-value css">:</span><span class="meta property-value css"> </span><span class="meta property-value css"><span class="constant numeric css">0.9<span class="keyword other unit css">rem</span></span></span><span class="punctuation terminator rule css">;</span>
</span><span class="punctuation section property-list css">}</span>

<span class="meta selector css"><span class="entity name tag css">pre</span> </span><span class="meta property-list css"><span class="punctuation section property-list css">{</span>
    <span class="meta property-name css"><span class="support type property-name css">border</span></span><span class="punctuation separator key-value css">:</span><span class="meta property-value css"> </span><span class="meta property-value css"><span class="constant numeric css">1<span class="keyword other unit css">px</span></span> <span class="support constant property-value css">solid</span> <span class="constant other color rgb-value css"><span class="punctuation definition constant css">#</span>111</span></span><span class="punctuation terminator rule css">;</span>
    <span class="meta property-name css"><span class="support type property-name css">margin</span></span><span class="punctuation separator key-value css">:</span><span class="meta property-value css"> </span><span class="meta property-value css"><span class="constant numeric css">0.5<span class="keyword other unit css">rem</span></span> <span class="constant numeric css">0</span></span><span class="punctuation terminator rule css">;</span>
    <span class="meta property-name css"><span class="support type property-name css">padding</span></span><span class="punctuation separator key-value css">:</span><span class="meta property-value css"> </span><span class="meta property-value css"><span class="constant numeric css">0.5<span class="keyword other unit css">rem</span></span></span><span class="punctuation terminator rule css">;</span>
    <span class="meta property-name css"><span class="support type property-name css">overflow-x</span></span><span class="punctuation separator key-value css">:</span><span class="meta property-value css"> </span><span class="meta property-value css"><span class="support constant property-value css">auto</span></span><span class="punctuation terminator rule css">;</span>
</span><span class="punctuation section property-list css">}</span>

<span class="meta selector css"><span class="entity name tag css">time</span> </span><span class="meta property-list css"><span class="punctuation section property-list css">{</span>
    <span class="meta property-name css"><span class="support type property-name css">display</span></span><span class="punctuation separator key-value css">:</span><span class="meta property-value css"> </span><span class="meta property-value css"><span class="support constant property-value css">block</span></span><span class="punctuation terminator rule css">;</span>
</span><span class="punctuation section property-list css">}</span>

<span class="meta selector css"><span class="meta function-call css"><span class="entity other pseudo-class css"><span class="punctuation definition entity css">:</span>not</span><span class="meta group css"><span class="punctuation definition group begin css">(</span><span class="meta selector css"><span class="entity name tag css">pre</span></span></span><span class="meta group css"><span class="punctuation definition group end css">)</span></span></span><span class="punctuation separator combinator css">&gt;</span><span class="entity name tag css">code</span> </span><span class="meta property-list css"><span class="punctuation section property-list css">{</span>
    <span class="meta property-name css"><span class="support type property-name css">color</span></span><span class="punctuation separator key-value css">:</span><span class="meta property-value css"> </span><span class="meta property-value css"><span class="constant other color rgb-value css"><span class="punctuation definition constant css">#</span>f00</span></span><span class="punctuation terminator rule css">;</span>
</span><span class="punctuation section property-list css">}</span>

<span class="meta at-rule media css"><span class="keyword control at-rule media css"><span class="punctuation definition keyword css">@</span>media</span> <span class="punctuation definition group begin css">(</span>prefers-<span class="support type property-name media css">color</span>-scheme<span class="punctuation separator key-value css">:</span> dark<span class="punctuation definition group end css">)</span> </span><span class="punctuation section property-list css">{</span>
<span class="meta selector css">    <span class="entity name tag css">body</span> </span><span class="meta property-list css"><span class="punctuation section property-list css">{</span>
        <span class="meta property-name css"><span class="support type property-name css">background-color</span></span><span class="punctuation separator key-value css">:</span><span class="meta property-value css"> </span><span class="meta property-value css"><span class="constant other color rgb-value css"><span class="punctuation definition constant css">#</span>222</span></span><span class="punctuation terminator rule css">;</span>
        <span class="meta property-name css"><span class="support type property-name css">color</span></span><span class="punctuation separator key-value css">:</span><span class="meta property-value css"> </span><span class="meta property-value css"><span class="constant other color rgb-value css"><span class="punctuation definition constant css">#</span>eee</span></span><span class="punctuation terminator rule css">;</span>
</span>    <span class="punctuation section property-list css">}</span>
    
<span class="meta selector css">    <span class="entity name tag css">a</span> </span><span class="meta property-list css"><span class="punctuation section property-list css">{</span>
        <span class="meta property-name css"><span class="support type property-name css">color</span></span><span class="punctuation separator key-value css">:</span><span class="meta property-value css"> </span><span class="meta property-value css"><span class="constant other color rgb-value css"><span class="punctuation definition constant css">#</span>add8e6</span></span><span class="punctuation terminator rule css">;</span>
</span>    <span class="punctuation section property-list css">}</span>

<span class="meta selector css">    <span class="entity name tag css">pre</span> </span><span class="meta property-list css"><span class="punctuation section property-list css">{</span>
        <span class="meta property-name css"><span class="support type property-name css">border-color</span></span><span class="punctuation separator key-value css">:</span><span class="meta property-value css"> </span><span class="meta property-value css"><span class="constant other color rgb-value css"><span class="punctuation definition constant css">#</span>eee</span></span><span class="punctuation terminator rule css">;</span>
</span>    <span class="punctuation section property-list css">}</span>
<span class="punctuation section property-list css">}</span></span></code></pre>
<p>That's it. No framework, no vendor prefixes, no unnecessary selectors.</p>
<p>This gave me an almost-pure HTML site. It's freeing. It's liberating. It's comfortable.</p>
<h2 id="reading-experience-benefits"><span class="section-number-2">3.</span> Reading Experience Benefits</h2>
<p>Recent research shows that line length between 45–75 characters maximizes reading speed and comprehension. By constraining the container width to ~50 rem (≈ 100 characters), we stay close to that range while still staying wide enough for my personal preferences. Additionally, a lean stylesheet eliminates <strong>FOUC</strong> (flash‑of‑unstyled‑content) on slower networks, delivering a smoother first‑paint experience.</p>
<h2 id="final-thoughts"><span class="section-number-2">4.</span> Final Thoughts</h2>
<p>I am very pleased with the new theme and will see how it holds up to time. Based on enabling short-term server logs to debug issues (before promptly wiping it to the ether), I notice that most visitors to my site are via RSS anyway. Either way, I hope you reach out if you have an opinion; I always enjoy hearing from you.</p>
]]></description>
    </item>
    <item>
      <title>Website Redesign 2025</title>
      <link>https://cleberg.net/blog/human-website-design.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/human-website-design.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Fri, 05 Sep 2025 00:00:00 +0000</pubDate>
      <category>web</category>
      <description><![CDATA[<blockquote>
<p><em>Please note that this redesign is a work-in-progress and is not complete. The content below describes the beginning of this journey and where I think it may take me next.</em></p>
</blockquote>
<figure><img src="https://img.cleberg.net/blog/20250905-human-website-design/before.webp" alt="A screenshot of the old theme for cleberg.net."><figcaption><span class="figure-number">Figure 1: </span>The Old Theme</figcaption></figure>
<figure><img src="https://img.cleberg.net/blog/20250905-human-website-design/after.webp" alt="A screenshot of the new theme for cleberg.net."><figcaption><span class="figure-number">Figure 2: </span>The New Theme</figcaption></figure>
<h2 id="inspiration"><span class="section-number-2">1.</span> Inspiration</h2>
<p>I've written numerous times on this blog about minimalism, so it shouldn't surprise any readers here that I've redesigned my website again for even more minimalism. However, it's a bit different this time as I've historically designed my website to be very computer design driven (think monospace fonts and sharp contrasting colors), rather than focusing on designing a website for human readers.</p>
<p>I felt inspired recently to minimize my website yet again, but I couldn't figure out why I wanted to do so for a while. Finally, I think I figured it out. I have been inspired lately by concepts, such as <a href="https://en.wikipedia.org/wiki/Wabi-sabi">wabi-sabi</a>, <a href="https://en.wikipedia.org/wiki/Shikata_ga_nai">sho ga nai</a>, <a href="https://en.wikipedia.org/wiki/Brutalist_architecture">brutalism</a>, <a href="https://en.wikipedia.org/wiki/Minimalism">minimalism</a>, and related concepts.</p>
<p>This piece specifically inspired me to cut out elements on my web page that did not add value. In other places, I simply redesigned how that information was presented (e.g., creating an "About" page rather than putting that information on my home screen).</p>
<p>However, that was not the only motivation for redesigning my website. I have also recently found an interest in crafting a more human-centric design for my website.</p>
<p>In the past, it has largely been a monospace-only, sharp contrast, bold colored blog. As I grown older, I find myself more interested in naturally-occurring color palettes and focusing on legible content.</p>
<p>This blog post will explore the decisions I made and why I chose those decisions.</p>
<h2 id="function"><span class="section-number-2">2.</span> Function</h2>
<p>The first step in this journey related to the functionality of the site itself. While my site has not used JavaScript for many years, I have focused on the HTML itself.</p>
<p>A common question I challenge myself with is: "Does this element serve a function? Is it useful? Does it provide more value than distraction?"</p>
<p>With the most recent redesign, I decided to:</p>
<ul>
<li>Keep the navigation bar to five elements.</li>
<li>Move the "contact" details from the home page to a dedicated <code class="verbatim">/about/</code> page.</li>
<li>Minimize the footer to remove the build timestamp, donation links, security.txt links, and webring links.</li>
</ul>
<p>This left a focus on navigation, my blog posts, and a short list of links to relevant pages on my website.</p>
<h2 id="colors"><span class="section-number-2">3.</span> Colors</h2>
<p>Previously, I used a very direct color palette for both light and dark modes, as seen below in the CSS snippet. This used sharp colors and relied heavily on "pure" colors without tints or shades.</p>
<p>This allowed for plain blank and white contrasting elements, with basic red and blue accent colors for inline code and links, respectively.</p>
<pre><code class="language-css highlight"><span class="source css"><span class="meta selector css"><span class="entity other pseudo-class css"><span class="punctuation definition entity css">:</span>root</span> </span><span class="meta property-list css"><span class="punctuation section property-list css">{</span>
    <span class="meta property-name css"><span class="support type custom-property css"><span class="punctuation definition custom-property css">--</span><span class="support type custom-property name css">bg</span></span></span><span class="punctuation separator key-value css">:</span><span class="meta property-value css"> </span><span class="meta property-value css"><span class="constant other color rgb-value css"><span class="punctuation definition constant css">#</span>fff</span></span><span class="punctuation terminator rule css">;</span>
    <span class="meta property-name css"><span class="support type custom-property css"><span class="punctuation definition custom-property css">--</span><span class="support type custom-property name css">bg-bright</span></span></span><span class="punctuation separator key-value css">:</span><span class="meta property-value css"> </span><span class="meta property-value css"><span class="constant other color rgb-value css"><span class="punctuation definition constant css">#</span>eee</span></span><span class="punctuation terminator rule css">;</span>
    <span class="meta property-name css"><span class="support type custom-property css"><span class="punctuation definition custom-property css">--</span><span class="support type custom-property name css">fg</span></span></span><span class="punctuation separator key-value css">:</span><span class="meta property-value css"> </span><span class="meta property-value css"><span class="constant other color rgb-value css"><span class="punctuation definition constant css">#</span>111</span></span><span class="punctuation terminator rule css">;</span>
    <span class="meta property-name css"><span class="support type custom-property css"><span class="punctuation definition custom-property css">--</span><span class="support type custom-property name css">link</span></span></span><span class="punctuation separator key-value css">:</span><span class="meta property-value css"> </span><span class="meta property-value css"><span class="constant other color rgb-value css"><span class="punctuation definition constant css">#</span>00f</span></span><span class="punctuation terminator rule css">;</span>
    <span class="meta property-name css"><span class="support type custom-property css"><span class="punctuation definition custom-property css">--</span><span class="support type custom-property name css">code</span></span></span><span class="punctuation separator key-value css">:</span><span class="meta property-value css"> </span><span class="meta property-value css"><span class="constant other color rgb-value css"><span class="punctuation definition constant css">#</span>f00</span></span><span class="punctuation terminator rule css">;</span>
    <span class="meta property-name css"><span class="support type custom-property css"><span class="punctuation definition custom-property css">--</span><span class="support type custom-property name css">border</span></span></span><span class="punctuation separator key-value css">:</span><span class="meta property-value css"> </span><span class="meta property-value css"><span class="constant other color rgb-value css"><span class="punctuation definition constant css">#</span>ccc</span></span><span class="punctuation terminator rule css">;</span>
</span><span class="punctuation section property-list css">}</span>

<span class="meta at-rule media css"><span class="keyword control at-rule media css"><span class="punctuation definition keyword css">@</span>media</span> <span class="punctuation definition group begin css">(</span>prefers-<span class="support type property-name media css">color</span>-scheme<span class="punctuation separator key-value css">:</span> dark<span class="punctuation definition group end css">)</span> </span><span class="punctuation section property-list css">{</span>
<span class="meta selector css">    <span class="entity other pseudo-class css"><span class="punctuation definition entity css">:</span>root</span> </span><span class="meta property-list css"><span class="punctuation section property-list css">{</span>
        <span class="meta property-name css"><span class="support type custom-property css"><span class="punctuation definition custom-property css">--</span><span class="support type custom-property name css">bg</span></span></span><span class="punctuation separator key-value css">:</span><span class="meta property-value css"> </span><span class="meta property-value css"><span class="constant other color rgb-value css"><span class="punctuation definition constant css">#</span>121212</span></span><span class="punctuation terminator rule css">;</span>
        <span class="meta property-name css"><span class="support type custom-property css"><span class="punctuation definition custom-property css">--</span><span class="support type custom-property name css">bg-bright</span></span></span><span class="punctuation separator key-value css">:</span><span class="meta property-value css"> </span><span class="meta property-value css"><span class="constant other color rgb-value css"><span class="punctuation definition constant css">#</span>1e1e1e</span></span><span class="punctuation terminator rule css">;</span>
        <span class="meta property-name css"><span class="support type custom-property css"><span class="punctuation definition custom-property css">--</span><span class="support type custom-property name css">fg</span></span></span><span class="punctuation separator key-value css">:</span><span class="meta property-value css"> </span><span class="meta property-value css"><span class="constant other color rgb-value css"><span class="punctuation definition constant css">#</span>e0e0e0</span></span><span class="punctuation terminator rule css">;</span>
        <span class="meta property-name css"><span class="support type custom-property css"><span class="punctuation definition custom-property css">--</span><span class="support type custom-property name css">link</span></span></span><span class="punctuation separator key-value css">:</span><span class="meta property-value css"> </span><span class="meta property-value css"><span class="constant other color rgb-value css"><span class="punctuation definition constant css">#</span>8ab4f8</span></span><span class="punctuation terminator rule css">;</span>
        <span class="meta property-name css"><span class="support type custom-property css"><span class="punctuation definition custom-property css">--</span><span class="support type custom-property name css">code</span></span></span><span class="punctuation separator key-value css">:</span><span class="meta property-value css"> </span><span class="meta property-value css"><span class="constant other color rgb-value css"><span class="punctuation definition constant css">#</span>f28b82</span></span><span class="punctuation terminator rule css">;</span>
        <span class="meta property-name css"><span class="support type custom-property css"><span class="punctuation definition custom-property css">--</span><span class="support type custom-property name css">border</span></span></span><span class="punctuation separator key-value css">:</span><span class="meta property-value css"> </span><span class="meta property-value css"><span class="constant other color rgb-value css"><span class="punctuation definition constant css">#</span>333</span></span><span class="punctuation terminator rule css">;</span>
</span>    <span class="punctuation section property-list css">}</span>
<span class="punctuation section property-list css">}</span></span></code></pre>
<p>After the update, the focus of the color scheme is focused on a more natural, paper-like effect. The light mode focuses on a yellow/orange-tinted paper-like substance, with a dark red accent and straightforward design. Likewise, the dark mode scheme uses a charcoal-like color scheme with very similar accent colors.</p>
<pre><code class="language-css highlight"><span class="source css"><span class="meta selector css"><span class="entity other pseudo-class css"><span class="punctuation definition entity css">:</span>root</span> </span><span class="meta property-list css"><span class="punctuation section property-list css">{</span>
    <span class="meta property-name css"><span class="support type custom-property css"><span class="punctuation definition custom-property css">--</span><span class="support type custom-property name css">bg</span></span></span><span class="punctuation separator key-value css">:</span><span class="meta property-value css"> </span><span class="meta property-value css"><span class="constant other color rgb-value css"><span class="punctuation definition constant css">#</span>EDEDE7</span></span><span class="punctuation terminator rule css">;</span>
    <span class="meta property-name css"><span class="support type custom-property css"><span class="punctuation definition custom-property css">--</span><span class="support type custom-property name css">bg-bright</span></span></span><span class="punctuation separator key-value css">:</span><span class="meta property-value css"> </span><span class="meta property-value css"><span class="constant other color rgb-value css"><span class="punctuation definition constant css">#</span>E8D3BE</span></span><span class="punctuation terminator rule css">;</span>
    <span class="meta property-name css"><span class="support type custom-property css"><span class="punctuation definition custom-property css">--</span><span class="support type custom-property name css">fg</span></span></span><span class="punctuation separator key-value css">:</span><span class="meta property-value css"> </span><span class="meta property-value css"><span class="constant other color rgb-value css"><span class="punctuation definition constant css">#</span>201E1D</span></span><span class="punctuation terminator rule css">;</span>
    <span class="meta property-name css"><span class="support type custom-property css"><span class="punctuation definition custom-property css">--</span><span class="support type custom-property name css">link</span></span></span><span class="punctuation separator key-value css">:</span><span class="meta property-value css"> </span><span class="meta property-value css"><span class="constant other color rgb-value css"><span class="punctuation definition constant css">#</span>810208</span></span><span class="punctuation terminator rule css">;</span>
    <span class="meta property-name css"><span class="support type custom-property css"><span class="punctuation definition custom-property css">--</span><span class="support type custom-property name css">code</span></span></span><span class="punctuation separator key-value css">:</span><span class="meta property-value css"> </span><span class="meta property-value css"><span class="constant other color rgb-value css"><span class="punctuation definition constant css">#</span>810208</span></span><span class="punctuation terminator rule css">;</span>
    <span class="meta property-name css"><span class="support type custom-property css"><span class="punctuation definition custom-property css">--</span><span class="support type custom-property name css">border</span></span></span><span class="punctuation separator key-value css">:</span><span class="meta property-value css"> </span><span class="meta property-value css"><span class="constant other color rgb-value css"><span class="punctuation definition constant css">#</span>E8D3BE</span></span><span class="punctuation terminator rule css">;</span>
</span><span class="punctuation section property-list css">}</span>

<span class="meta at-rule media css"><span class="keyword control at-rule media css"><span class="punctuation definition keyword css">@</span>media</span> <span class="punctuation definition group begin css">(</span>prefers-<span class="support type property-name media css">color</span>-scheme<span class="punctuation separator key-value css">:</span> dark<span class="punctuation definition group end css">)</span> </span><span class="punctuation section property-list css">{</span>
<span class="meta selector css">    <span class="entity other pseudo-class css"><span class="punctuation definition entity css">:</span>root</span> </span><span class="meta property-list css"><span class="punctuation section property-list css">{</span>
        <span class="meta property-name css"><span class="support type custom-property css"><span class="punctuation definition custom-property css">--</span><span class="support type custom-property name css">bg</span></span></span><span class="punctuation separator key-value css">:</span><span class="meta property-value css"> </span><span class="meta property-value css"><span class="constant other color rgb-value css"><span class="punctuation definition constant css">#</span>201E1D</span></span><span class="punctuation terminator rule css">;</span>
        <span class="meta property-name css"><span class="support type custom-property css"><span class="punctuation definition custom-property css">--</span><span class="support type custom-property name css">bg-bright</span></span></span><span class="punctuation separator key-value css">:</span><span class="meta property-value css"> </span><span class="meta property-value css"><span class="constant other color rgb-value css"><span class="punctuation definition constant css">#</span>2F2F2D</span></span><span class="punctuation terminator rule css">;</span>
        <span class="meta property-name css"><span class="support type custom-property css"><span class="punctuation definition custom-property css">--</span><span class="support type custom-property name css">fg</span></span></span><span class="punctuation separator key-value css">:</span><span class="meta property-value css"> </span><span class="meta property-value css"><span class="constant other color rgb-value css"><span class="punctuation definition constant css">#</span>EDEDE7</span></span><span class="punctuation terminator rule css">;</span>
        <span class="meta property-name css"><span class="support type custom-property css"><span class="punctuation definition custom-property css">--</span><span class="support type custom-property name css">link</span></span></span><span class="punctuation separator key-value css">:</span><span class="meta property-value css"> </span><span class="meta property-value css"><span class="constant other color rgb-value css"><span class="punctuation definition constant css">#</span>D9C2A6</span></span><span class="punctuation terminator rule css">;</span>
        <span class="meta property-name css"><span class="support type custom-property css"><span class="punctuation definition custom-property css">--</span><span class="support type custom-property name css">code</span></span></span><span class="punctuation separator key-value css">:</span><span class="meta property-value css"> </span><span class="meta property-value css"><span class="constant other color rgb-value css"><span class="punctuation definition constant css">#</span>D9C2A6</span></span><span class="punctuation terminator rule css">;</span>
        <span class="meta property-name css"><span class="support type custom-property css"><span class="punctuation definition custom-property css">--</span><span class="support type custom-property name css">border</span></span></span><span class="punctuation separator key-value css">:</span><span class="meta property-value css"> </span><span class="meta property-value css"><span class="constant other color rgb-value css"><span class="punctuation definition constant css">#</span>2F2F2D</span></span><span class="punctuation terminator rule css">;</span>
</span>    <span class="punctuation section property-list css">}</span>
<span class="punctuation section property-list css">}</span></span></code></pre>
<p>I am still working on the color scheme and don't believe I'm done modifying this yet. Expect more changes, as always.</p>
<h2 id="space"><span class="section-number-2">4.</span> Space</h2>
<p>While I haven't updated the margins and padding much <em>yet</em>, I did make a few changes that affected the spacing of the site. The intent of this redesign is to keep the focus of the reader's eyes on the intended content, as well as creating a comfortable and intentional page layout.</p>
<p>That being said, let's dive into the changes I've made so far:</p>
<ul>
<li><strong>Font style</strong>: I've updated the font style from a monospace font stack to a serif font stack. This created a more natural flow across the screen and less rigid constraints on the area of the fonts.</li>
<li><strong>Font size</strong>: Related to font style, I naturally had to update the font size as well. This allows for natural reading breaks for the eyes, spacing between lines, emphasized and larger headers for visual cues, as well as fewer words being displayed on screen at once.</li>
<li><strong>Date format</strong>: I have moved the visible dates on my pages from the ISO standard (<code class="verbatim">YYYY-MM-DD</code>) to a legible, human date format. The new dates describe the months in full words, as well as the day of the week on post pages, so that you may read it as you would say it out loud. The underlying date tagging within the <code class="verbatim">&lt;date&gt;</code> element itself still follows the ISO standard, as that's meant for computers to read.</li>
</ul>
<p>With these changes, I'm pleasantly surprised at the quality improvement when reading the pages on the site.</p>
<h2 id="looking-forward"><span class="section-number-2">5.</span> Looking Forward</h2>
<p>As I said at the beginning of the post, I'm not done yet. However, I wanted to stop and reflect on the changes so far.</p>
<p>I will continue to think about changes, specifically with the following already in mind:</p>
<ul>
<li><strong>Color palettes</strong>: The current scheme is good but not great. I'd love to find a color palette that feels like reading natural paper.</li>
<li><strong>Emphasized text</strong>: Are links legible enough? Is there enough contrast between quotes, inline code, links, etc.?</li>
<li><strong>Spacing</strong>: Font sizes, padding, and potentially reducing content.</li>
<li><strong>Layout</strong>: Is there a better structure to this document that would allow for more comfortable reading?</li>
</ul>
<p>With this phase done, I am content and am joyful at the thought of continuing to refine this website. If not for any readers who may or may not even exist, at least for myself.</p>
]]></description>
    </item>
    <item>
      <title>Private iOS Apps: What I Actually Use</title>
      <link>https://cleberg.net/blog/private-ios-apps.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/private-ios-apps.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Tue, 03 Jun 2025 00:00:00 +0000</pubDate>
      <category>linux</category>
      <category>privacy</category>
      <description><![CDATA[<p>The world is evolving into a privacy nightmare, where our own devices are being used by numerous parties to constantly track and report on our activities. This is especially prevalent on iOS, where platform restrictions leave users without many options to lock down their data.</p>
<p>However, there are apps that exist that can help enhance the privacy of an iOS device. The post below details a number of privacy resources, directories, and tools for iOS.</p>
<p><strong><strong>Resource Table</strong></strong></p>
<table>
<thead>
<tr><th>Name</th><th>Type</th></tr>
</thead>
<tbody>
<tr><td><a href="https://github.com/pluja/awesome-privacy">Awesome Privacy</a></td><td>App Lists &amp; Directories</td></tr>
<tr><td><a href="https://www.privacyguides.org/en/os/ios-overview/">PrivacyGuides.org</a></td><td>App Lists &amp; Directories</td></tr>
<tr><td><a href="https://cyberinsider.com/">CyberInsider</a></td><td>Guides &amp; Educational</td></tr>
<tr><td><a href="https://ssd.eff.org/module-categories/further-learning">EFF Surveillance Self-Defense</a></td><td>Guides &amp; Educational</td></tr>
<tr><td><a href="https://osintframework.com/">OSINT Framework</a></td><td>Guides &amp; Educational</td></tr>
<tr><td><a href="https://securityplanner.consumerreports.org/">Security Planner (Consumer Reports)</a></td><td>Guides &amp; Educational</td></tr>
<tr><td><a href="https://discuss.privacyguides.net/">PrivacyGuides Forum</a></td><td>Community &amp; Discussion</td></tr>
<tr><td><a href="https://www.reddit.com/r/privacy/">r/Privacy</a></td><td>Community &amp; Discussion</td></tr>
<tr><td><a href="https://www.reddit.com/r/iosprivacy/">r/iOSPrivacy</a></td><td>Community &amp; Discussion</td></tr>
<tr><td><a href="https://tosdr.org/en/">Terms of Service; Didn't Read (ToS;DR)</a></td><td>Policy &amp; Transparency Tools</td></tr>
<tr><td><a href="https://browserleaks.com">BrowserLeaks.com</a></td><td>Privacy Testing &amp; Tools</td></tr>
<tr><td><a href="https://mullvad.net/check">Mullvad Privacy Check</a></td><td>Privacy Testing &amp; Tools</td></tr>
<tr><td><a href="https://support.apple.com/en-us/HT212025">iOS App Privacy Report (Settings)</a></td><td>Privacy Testing &amp; Tools</td></tr>
<tr><td><a href="https://privacytests.org/">PrivacyTests.org</a></td><td>Privacy Testing &amp; Tools</td></tr>
</tbody>
</table>
<blockquote>
<p><strong>Note</strong>: This list focuses solely on iOS-compatible resources and tools. No Android comparisons here as I have not used Android in many years.</p>
</blockquote>
<h2 id="email"><span class="section-number-2">1.</span> Email</h2>
<p>First, I like to consider email as my first app on a new device. However, iOS is \extremely\ lacking in this area. Certain options are private, such as Proton Mail and Tuta, but they have certain restrictions and ecosystem lock-in methods that I try to avoid.</p>
<p>Canary Mail was a decent option for a while, although a bit mysterious, but they have recently leaned into the AI hype pretty heavily, which is concerning. However, it's still one of the only options for PGP emails on iOS.</p>
<ul>
<li><a href="https://proton.me/mail">Proton Mail</a> - One of the more popular private email options available on iOS. Allows custom domains, but does not allow for IMAP/SMTP usage, so you're locked into using their apps. Open source.</li>
<li><a href="https://tuta.com/">Tuta</a> - Tuta also locks you into their clients and they do not allow you to use custom domains. Open source.</li>
<li><a href="https://canarymail.io/">Canary Mail</a> - Closed source, so you can't verify anything about what they are building into the app. However, it's one of the only options for PGP mail on iOS. Advanced features are locked behind a paywall.</li>
</ul>
<p>Another suggestion is to use a browser-based web client. You can install browser mail clients as progressive web apps (PWAs). For example, I have been using <a href="https://webmail.migadu.com">webmail.migadu.com</a> as a progressive email app for a while now and it works great for my purposes.</p>
<p>This allows for access to your email without installing an application that access native APIs or other potential data sources you may be concerned about. This is especially important if you're concerned about allowing permissions to device APIs, non-reproducible builds from the App Store, or mobile device fingerprints.</p>
<p>Lastly, <a href="https://blog.thunderbird.net/2025/05/thunderbird-for-mobile-april-2025-progress-report/">Thunderbird iOS</a> is under development. Keep an eye out for an alpha or beta release later in 2025 or early 2026. I have a feeling that once Thunderbird iOS is available, it will easily become the best option for email on iOS.</p>
<blockquote>
<p><strong>I use</strong>: Web-based email on iOS and Thunderbird on my desktop. Once Thunderbird releases for iOS, I will probably use that.</p>
</blockquote>
<h2 id="browsers"><span class="section-number-2">2.</span> Browsers</h2>
<p>Your choice of browser is very important if you're concerned with privacy. Any and all links you click will be opened in your default browser, so you need to make sure you choose the right browser and configure it properly. Trackers, ads, fingerprints, and data leaks are constant threats that should be avoided when possible.</p>
<ul>
<li><a href="https://apps.apple.com/us/app/firefox-focus-privacy-browser/id1055677337">Firefox Focus</a> - In my opinion, the best option for privacy on iOS. Automatically blocks trackers, erases data and history upon app close, and focused on private usage. However, it won't support your bookmarks or keep you logged into sites long-term.</li>
<li><a href="https://duckduckgo.com/app">DuckDuckGo</a> - Another good option, built on chromium. Like Focus, it allows you to clear all data with a button tap.</li>
<li><a href="https://onionbrowser.com/">Onion Browser</a> &amp; <a href="https://orbot.app/">Orbot</a> - Tor - what can I say? It's been the most popular privacy browser for ages for a reason and now it's available on iOS. Onion Browser is a Tor browser and Orbot can proxy any number of iOS apps through Tor. As with all Tor traffic, it will be slower than "regular" traffic.</li>
<li><a href="https://brave.com/">Brave</a> - Another chromium-based privacy browser. Can sync with other Brave browsers via a secure linking process (no account). Fully-featured and great privacy defaults. There have been some concerns in the past about the company behind Brave, but I still think it's a decent option for most people.</li>
<li><a href="https://www.apple.com/safari/">Safari</a> (with caveats) - Great option if the browsers above don't work for you. Be sure to read PrivacyGuide's <a href="https://www.privacyguides.org/en/mobile-browsers/#safari-ios">Safari</a> section for more information on what you need to do to lock it down before relying on it full time.</li>
</ul>
<blockquote>
<p><strong>I use</strong>: Hardened safari in private mode for every day use, and Onion Browser for anonymous browsing.</p>
</blockquote>
<h2 id="messaging"><span class="section-number-2">3.</span> Messaging</h2>
<p>Next up are messaging apps. If you have an iPhone, it's a good bet that you will be messaging other people on it. The threats for messaging apps tend to be metadata/data collection from cellular providers, ISPs, and Apple itself. If you want to protect the privacy of your messages, who your messaging, and the metadata around those messages (time, method, location, etc.), you'll need to think about which apps you're using.</p>
<ul>
<li><a href="https://signal.org/">Signal</a> - My personal favorite and still the gold standard for secure and private messaging. Open source, end-to-end encrypted, and runs its own private push notification infrastructure so Apple can't read your message content. A phone number is required to sign up, but you can create a username immediately after signing up and share that with others instead of sharing your phone number.</li>
<li><a href="https://simplex.chat/">SimpleX</a> - A decentralized, phone-number-free messaging system. Uses anonymous message relays and asymmetric keys.</li>
<li><a href="https://getsession.org/">Session</a> - A fork of Signal's protocol that eliminates phone numbers entirely. Routes messages through a decentralized onion network (like Tor).</li>
<li><a href="https://element.io/">Element</a> - Based on the Matrix protocol, offering decentralized, federated chat. Great for groups and communities, with optional end-to-end encryption. Other client options are available for Matrix on iOS, as well.</li>
</ul>
<blockquote>
<p><strong>I use</strong>: Signal for private chats with known people, and Matrix for group chats.</p>
</blockquote>
<h2 id="vpns-networking"><span class="section-number-2">4.</span> VPNs &amp; Networking</h2>
<p>Network traffic is where most surveillance happens. Even with encrypted messaging and browsers, your IP address and DNS queries reveal a lot about you. A good VPN or alternative network routing tool masks this, but not all VPNs are trustworthy. Avoid “free” services or those lacking transparency.</p>
<ul>
<li><a href="https://mullvad.net/">Mullvad</a> - A no-logs VPN that doesn't require an email or personal info to create an account. Consistently audited and privacy-focused. Their app is excellent on iOS.</li>
<li><a href="https://www.torproject.org/">Tor</a> - Best for anonymity rather than everyday VPN use. Routes your traffic over three relays, obscuring both source and destination. Slower, but unmatched for high-risk browsing.</li>
<li><a href="https://yggdrasilnetwork.org/installation">Yggdrasil</a> - An experimental, encrypted, peer-to-peer mesh network. Less polished for mobile but useful for hobbyists or building private networks between devices.</li>
</ul>
<p>If you can't self-host or build your own mesh, Mullvad is hands-down the easiest option here. There are other VPN options available, but I haven't tested them all so I will simply put my vote for Mullvad here and let you research other options if you don't want to use Mullvad.</p>
<blockquote>
<p><strong>I use</strong>: Mullvad for 24/7 usage, and Tor when anonymity is required.</p>
</blockquote>
<h2 id="password-management"><span class="section-number-2">5.</span> Password Management</h2>
<p>Weak and reused passwords are still the biggest risks for personal security. A good password manager makes it possible to use strong, unique credentials without memorizing them all.</p>
<ul>
<li><a href="https://bitwarden.com/">Bitwarden</a> - Open source, audited, and free to self-host (e.g., Vaultwarden). The iOS app integrates with system autofill and Face ID.</li>
<li><a href="https://keepassium.com/">KeePassium</a> - A KeePass-compatible client for iOS. Local database storage, optional cloud sync, and no external accounts. Excellent if you want full control over your credential store.</li>
<li><a href="https://keepassxc.org/">KeePassXC</a> + Syncing Solution - If you already use KeePass on desktop, sync your database with a secure method like <a href="https://cryptomator.org/">Cryptomator</a>-protected cloud storage, Syncthing, or local-only transfers.</li>
</ul>
<p>Good passwords matter are extremely important, and these apps give you control over your vault.</p>
<blockquote>
<p><strong>I use</strong>: Bitwarden Families ($40/year) to protect passwords, passkeys, TOTP codes, and secure notes for my family. If I were using a solution solely for myself, I would prefer KeePassXC + Syncthing.</p>
</blockquote>
<h2 id="multi-factor-authentication-mfa"><span class="section-number-2">6.</span> Multi-Factor Authentication (MFA)</h2>
<p>MFA is essential, but relying on SMS codes or untrusted proprietary apps defeats the point. Use open, local, encrypted authenticators where possible. Also, use passkeys if you can! I prefer passkeys, then TOTP, and then SMS/email, if other options are not possible.</p>
<ul>
<li><a href="https://bitwarden.com/products/authenticator/">Bitwarden Authenticator</a> - Integrates with the password manager or works as a standalone TOTP app. Optional encrypted backups through your Bitwarden account.</li>
<li><a href="https://ente.io/auth/">Ente Auth</a> - Open source, end-to-end encrypted TOTP manager. Syncs encrypted via Ente's infrastructure.</li>
<li><a href="https://www.tofuauth.com/">Tofu</a> - Minimal, offline-first TOTP app. No cloud, no telemetry.</li>
<li><a href="https://raivo-otp.com/">Raivo OTP</a> - Open source, native iOS app with secure iCloud backups. Clean interface.</li>
<li><a href="https://apps.apple.com/us/app/otp-auth/id659877384">OTP Auth</a> - A longstanding, trusted TOTP manager with encrypted backups and Apple Watch support. <strong>Not open source.</strong></li>
</ul>
<p>I recommend pairing one of these with strong passwords and a VPN for everyday security.</p>
<blockquote>
<p><strong>I use</strong>: Bitwarden Authenticator, previously OTP Auth.</p>
</blockquote>
<h2 id="notes-personal-data"><span class="section-number-2">7.</span> Notes &amp; Personal Data</h2>
<p>If you're storing sensitive personal notes, account details, or journal entries, opt for encrypted, local-first apps.</p>
<ul>
<li><a href="https://beorgapp.com/">Beorg</a> - An Org-mode-compatible outliner and task manager for iOS. Great for Emacs fans and those managing plaintext files.</li>
<li><a href="https://obsidian.md/">Obsidian</a> - A local Markdown-based notes app. All data stays on your device unless you opt for Obsidian Sync (or your own setup).</li>
<li><a href="https://standardnotes.com/">Standard Notes</a> - End-to-end encrypted notes, with cross-platform sync. Good if you want a straightforward, secure cloud service.</li>
<li><a href="https://joplinapp.org/">Joplin</a> - Open source, Markdown notes with optional encryption and cloud sync (Nextcloud, Dropbox, etc).</li>
</ul>
<p>These options help decouple your data from major cloud platforms while keeping notes portable and encrypted.</p>
<blockquote>
<p><strong>I use</strong>: Beorg, since I love org-mode.</p>
</blockquote>
<h2 id="photos-media"><span class="section-number-2">8.</span> Photos &amp; Media</h2>
<p>If you're using iCloud Photos, your camera roll quietly feeds metadata and images to iCloud by default. If you want to self-host or encrypt your photo library, here's what works on iOS. At a minimum, I suggest disabling iCloud for the Photos app, so the data stays local on your device.</p>
<ul>
<li><a href="https://immich.app/">Immich (self-hosted)</a> - Open source, feature-rich, self-hosted photo manager with facial recognition and live photo support. Requires a home server.</li>
<li><a href="https://ente.io/">Ente Photos</a> - End-to-end encrypted photo storage with iOS and web apps. Paid plans, but privacy-first infrastructure.</li>
</ul>
<p>Good privacy photos apps are rare on iOS — these two are the standout options right now.</p>
<blockquote>
<p><strong>I use</strong>: Immich for all photos.</p>
</blockquote>
<h2 id="encryption-utilities"><span class="section-number-2">9.</span> Encryption Utilities</h2>
<p>If you're handling sensitive files, you need a proper encryption utility to lock them down.</p>
<ul>
<li><a href="https://cryptomator.org/">Cryptomator</a> - Open source, encrypted cloud storage vaults. Integrates with most cloud providers and works locally.</li>
<li><a href="https://apps.apple.com/us/app/instant-pgp/id1497433694">Instant PGP</a> - PGP key generation, import/export, and encrypted message/file creation. Handy for old-school secure comms.</li>
</ul>
<p>If you're serious about privacy, encrypted storage and messaging layers like these are essential.</p>
<blockquote>
<p><strong>I use</strong>: Cryptomator when syncing sensitive data over Syncthing. I no longer require Instant PGP since Migadu's webmail client (SnappyMail) supports PGP.</p>
</blockquote>
<h2 id="news-social"><span class="section-number-2">10.</span> News &amp; Social</h2>
<p>News and social apps leak all kinds of usage metadata, even when you're just lurking. These tools let you follow content with less exposure.</p>
<ul>
<li><a href="https://netnewswire.com/">NetNewsWire</a> - Free, open source RSS reader for iOS.</li>
<li><a href="https://www.talklittle.com/three-cheers/">ThreeCheers</a> - Privacy-friendly Tildes client for iOS.</li>
<li><a href="https://getvoyager.app/">Voyager</a> - Clean, independent Lemmy client.</li>
<li><a href="https://joinmastodon.org/">Mastodon</a> - Federated, open source alternative to Twitter.</li>
<li><a href="https://joinpeertube.org/">PeerTube</a> - Decentralized video platform, accessible via web or PWA.</li>
<li><a href="https://pixelfed.org/">Pixelfed</a> - Federated, open source alternative to Instagram.</li>
</ul>
<p>If you're going to be online, at least let it be on your terms.</p>
<blockquote>
<p><strong>I use</strong>: NetNewsWire (via FreshRSS) for RSS feeds, Voyager for Lemmy, and Three Cheers for Tildes. I have used all of these apps and they are great, but I am not very active on social sites.</p>
</blockquote>
<h2 id="final-thoughts"><span class="section-number-2">11.</span> Final Thoughts</h2>
<p>Whether you just want to improve your privacy in small steps or you're fashioning a tinfoil hat as we speak, moving to privacy-focused services and apps does two things:</p>
<ol>
<li>It protects your privacy by ensuring that your data is being protected through the many methods mentioned above; and</li>
<li>It provides money (for paid apps), support (in terms of download count, reviews, ratings, etc.), and motivation for the developers and companies behind these apps that provide a privacy haven for users on iOS.</li>
</ol>
<p>Every app you use, every service you sign into, quietly collects and trades your data. iOS makes true anonymity harder than other platforms, but these tools and services give you a fighting chance to keep your data private.</p>
]]></description>
    </item>
    <item>
      <title>IT Audit Career: Skills That Matter</title>
      <link>https://cleberg.net/blog/it-audit-career.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/it-audit-career.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Fri, 30 May 2025 00:00:00 +0000</pubDate>
      <category>audit</category>
      <description><![CDATA[<h2 id="introduction"><span class="section-number-2">1.</span> Introduction</h2>
<p>As trends have shown, the auditing and assurance world is increasingly becoming overwhelmed with topics like <a href="https://kpmg.com/xx/en/what-we-do/services/ai/trusted-ai-framework.html">AI</a>, <a href="https://pcaobus.org/Documents/Audits-Involving-Cryptoassets-Spotlight.pdf">Digital Assets</a>, <a href="https://kpmg.com/us/en/articles/2023/building-trust-cloud-environments.html">Cloud</a>, <a href="https://kpmg.com/us/en/articles/2023/role-of-internal-audit-devops.html">DevOps</a>, and <a href="https://kpmg.com/ch/en/insights/technology/audit-transformation.html">Automation</a>.</p>
<p>While these trends are rapidly transforming businesses and industries, audit firms and departments are working hard to ensure they stay aligned with business objectives.</p>
<p>Throughout my career, I've seen topics like "AI" evolve from LLM-based projects used by data scientists to everyday tools accessible to the masses and integrated directly into business operations.</p>
<p>As an auditor, skills in emerging technologies are an invaluable asset that can translate into massive career opportunities and long-term job security.</p>
<p>I have experienced this firsthand as topics like automation, AI, cloud assurance, and DevOps have kept me in a secure position with significant potential for growth and learning.</p>
<p>In this post, I'm going to walk through the process of becoming skilled in an emerging technology and how to translate that into a rewarding audit career.</p>
<h2 id="step-1-build-a-strong-foundation-in-audit-risk"><span class="section-number-2">2.</span> Step 1: Build a Strong Foundation in Audit &amp; Risk</h2>
<p>To start, I want to note that learning about emerging technologies is only useful if you already have a base in auditing. You can't audit a cloud environment with cloud knowledge alone — you also need to understand the fundamentals of auditing.</p>
<p>If you find that you're highly technical already, focus your time on learning audit standards and guidance.</p>
<p>You can customize this to any frameworks applicable to your company or industry, but these are generally the baseline for an audit career:</p>
<ul>
<li><a href="https://www.coso.org/Pages/default.aspx">COSO</a></li>
<li><a href="https://www.nist.gov/cyberframework">NIST CSF</a></li>
<li><a href="https://www.iso.org/isoiec-27001-information-security.html">ISO/IEC 27001</a></li>
<li><a href="https://pcaobus.org/">PCAOB</a></li>
<li><a href="https://www.aicpa-cima.com/resources/assurance">AICPA</a></li>
</ul>
<p>The consistent theme throughout these frameworks is that audits rely on independent parties who provide consistent documentation, appropriate considerations of risks and responses, scoping, and reporting.</p>
<p>One of the easiest ways to get this knowledge is by doing. While it can be challenging, the concept is straightforward. If you are working in a role within a department like internal audit, external audit, risk, compliance, etc., focus on performing your role exceptionally and continuously challenge yourself to learn more about audit and risk each day you work.</p>
<h2 id="step-2-learn-the-tech-that-s-changing-the-profession"><span class="section-number-2">3.</span> Step 2: Learn the Tech That's Changing the Profession</h2>
<p>Getting to the point of this post, there's a wide range of technologies transforming the audit world. To accelerate career growth and discover a niche you enjoy, I've compiled a short list of topics that are currently (1) growing in demand, (2) have a need for more experts within the audit field, and (3) are expected to remain relevant.</p>
<ul>
<li><strong>Automation &amp; Data Analytics</strong>: Alteryx, Python, Power BI, Tableau</li>
<li><strong>Cloud</strong>: AWS, Azure, GCP, IBM</li>
<li><strong>Blockchain</strong>: Decentralization, smart contracts, chain of custody</li>
<li><strong>DevOps</strong>: Azure DevOps, CI/CD, DevSecOps, GitHub, GitLab, Jenkins</li>
<li><strong>AI/ML</strong>: AI in business, AI in auditing, AI assurance</li>
</ul>
<blockquote>
<p><strong>Pro Tip</strong>: Tackle one area at a time. You don't need to become an expert, but make sure you learn enough to conceptualize the technologies and logic behind the topics you're auditing.</p>
<p>If you focus on one at a time, you can dedicate time to that sole topic to understand it more deeply before moving on to the next.</p>
</blockquote>
<h2 id="step-3-earn-certifications-that-signal-credibility"><span class="section-number-2">4.</span> Step 3: Earn Certifications That Signal Credibility</h2>
<p>If you don't have much experience, or can't demonstrate your knowledge in a particular area due to job constraints or otherwise, you can utilize courses and certifications to boost your credibility. This is an effective way to establish credibility and demonstrate your qualifications.</p>
<ul>
<li><a href="https://www.isaca.org/credentialing/cisa">CISA (Certified Information Systems Auditor)</a>: Core certification for IT auditors covering systems, controls, governance, and assurance.</li>
<li><a href="https://learn.microsoft.com/en-us/certifications/azure-fundamentals/">Microsoft Azure Fundamentals (AZ-900)</a> / <a href="https://aws.amazon.com/certification/certified-cloud-practitioner/">AWS Certified Cloud Practitioner</a>: Entry-level cloud certifications covering core cloud concepts, services, pricing, and security.</li>
<li><a href="https://www.alteryx.com/certification/designer-core">Alteryx Designer Core Certification</a>: Validates your ability to build data prep, blending, and analytics workflows in Alteryx.</li>
<li><a href="https://www.coursera.org/professional-certificates/ibm-data-science">IBM Data Science Professional Certificate</a> (via Coursera): Teaches data science fundamentals, Python, SQL, and AI basics; popular for aspiring data auditors and analysts.</li>
<li>Entry-level technical certifications:<ul>
<li><a href="https://pythoninstitute.org/pcep">PCEP (Certified Entry-Level Python Programmer) by Python Institute</a></li>
<li><a href="https://www.edx.org/learn/artificial-intelligence">AI certifications on edX</a> covering foundations, governance, and AI ethics.</li>
<li><a href="https://www.blockchain-council.org/certifications/certified-blockchain-professional-expert/">Certified Blockchain Expert</a></li>
</ul>
</li>
</ul>
<p>I have earned the following certifications and have seen great responses throughout my career due to the credibility they provided in these focus areas:</p>
<ul>
<li>GitLab Certified Git Associate</li>
<li>GitHub Foundations</li>
<li>Alteryx Designer Core Certified</li>
<li>Microsoft Certified: Azure Fundamentals</li>
<li>Certified Information Systems Auditor (CISA)</li>
<li>Certified Entry-Level Python Programmer (PCEP)</li>
<li>Data Science Professional Certificate</li>
<li>Cybersecurity Audit Certificate</li>
</ul>
<h2 id="step-4-join-emerging-tech-projects-and-pilots"><span class="section-number-2">5.</span> Step 4: Join Emerging Tech Projects and Pilots</h2>
<p>Once you have the knowledge and, if applicable, the credentials to showcase your skills, you need the chance to network and show what you can do.</p>
<p>To do this, I recommend joining a group focused on the topic you're passionate about. Normally, this is easiest within your own company. However, sometimes you may need to seek other opportunities in your community or online to find the project that works best for you.</p>
<ul>
<li>Seek opportunities internally: AI pilots, automation and data analysis projects, blockchain initiatives.</li>
<li>If they don't exist — propose them.</li>
<li>Suggest automating risk assessments, piloting AI tools, or testing continuous assurance routines.</li>
</ul>
<p><strong>Why this matters</strong>: These projects become resume differentiators and position you for leadership roles.</p>
<h2 id="step-5-build-a-network-of-tech-savvy-auditors-consultants"><span class="section-number-2">6.</span> Step 5: Build a Network of Tech-Savvy Auditors &amp; Consultants</h2>
<p>As a segue from Step 4, ensure that you have a network of like-minded individuals who can challenge you and expose you to new ideas. This helps keep you sharp and open to innovation. Some suggestions include:</p>
<ul>
<li>Join ISACA, local AI/ML meetups, blockchain working groups.</li>
<li>Engage with emerging tech communities on LinkedIn — share posts, comment on thought leadership, or publish insights.</li>
</ul>
<h2 id="step-6-stay-curious-and-keep-learning"><span class="section-number-2">7.</span> Step 6: Stay Curious and Keep Learning</h2>
<p>Last, but not least, keep learning! While you may feel like you know everything, there's always more to explore. I enjoy revisiting known problems from different perspectives, as it's helped me grow and realize that alternative approaches often yield better results with experience.</p>
<ul>
<li>The landscape is changing rapidly — stay current on AI regulation, blockchain security, cloud assurance frameworks, or whatever interests you.</li>
<li>Subscribe to niche newsletters (e.g., The Cybersecurity 202, AI Ethics Weekly).</li>
<li>Take one course or certification per year to stay sharp.</li>
</ul>
<h2 id="closing"><span class="section-number-2">8.</span> Closing</h2>
<p>You don't need to be an engineer or software developer to thrive in technology — but you do need to understand enough to assess risk. With these steps, I have found a wonderful and fulfilling career, and I know you can too.</p>
<p>If you have any questions on how to break into tech risk and audit, feel free to reach out over email or anywhere else — I would love to connect and chat!</p>
]]></description>
    </item>
    <item>
      <title>Asahi Linux: Linux on Apple Silicon</title>
      <link>https://cleberg.net/blog/asahi-linux.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/asahi-linux.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Fri, 02 May 2025 00:00:00 +0000</pubDate>
      <category>linux</category>
      <description><![CDATA[<h2 id="trying-out-asahi-linux"><span class="section-number-2">1.</span> Trying out Asahi Linux</h2>
<p>While debating if I should find a replacement laptop and get rid of my MacBook Pro, I decided to try <a href="https://asahilinux.org/">Asahi Linux</a>.</p>
<p>To put the bottom line up front, I love the experience and support for popular features has come a long way since I originally checked out their website a few years ago.</p>
<p>From Asahi's website, as seen below, I noticed that almost all targeted features are now supported. This is a great jump from the state it was at in 2022 - 2023 when I last checked.</p>
<figure><img src="https://img.cleberg.net/blog/20250502-asahi-linux/device_support.webp" alt="Device support for Asahi Linux."><figcaption><span class="figure-number">Figure 1: </span>Asahi Linux Device Support</figcaption></figure>
<h3 id="installation"><span class="section-number-3">1.1.</span> Installation</h3>
<p>Luckily, the installation process is as simple as getting started with a single command:</p>
<pre><code class="language-shell">curl https://alx.sh | sh</code></pre>
<p>This script will walk you through the standard installation steps to define the size of the Linux partition, define your user and hostname, and give you instructions on how to boot from the new operating system (OS).</p>
<p>Once the script completes, it will ask you to completely shut down the device, boot into the Startup Options menu, and follow a handful of prompts to enable your new OS.</p>
<h3 id="initial-thoughts"><span class="section-number-3">1.2.</span> Initial Thoughts</h3>
<p>By default, the installer suggests using the KDE (as does the online community), so I opted to try KDE. Historically, I have always been a Gnome user when utilizing a fully graphical desktop environment (DE), but I'm up for trying something new.</p>
<p>KDE on Asahi works wonderfully and supports all of the generic features I'd expect from a vanilla installation:</p>
<ul>
<li>Snap to tile</li>
<li>Shell and window themes</li>
<li>Graphical updates</li>
<li>Sensible default applications (Dolphin, Firefox, KMail, Konsole, KWrite)</li>
<li>Support for battery percentages, keyboard backlight control, and miscellaneous sensor controls</li>
<li>Fast and reliable bluetooth adoption</li>
<li>Native game pad support</li>
</ul>
<p>Here's a quick look at the default desktop. In subsequent screenshots, you'll see I started using the WhiteSur theme as it provides a more comfortable layout for macOS users.</p>
<figure><img src="https://img.cleberg.net/blog/20250502-asahi-linux/kde.webp" alt="A screenshot of a terminal running fastfetch and emacs on Asahi Linux."><figcaption><span class="figure-number">Figure 2: </span>KDE</figcaption></figure>
<p>When diving into the system information panel, we can see that this machine is running Fedora Linux Asahi Remix 42 on an Apple M2 Pro laptop with 16GB of RAM.</p>
<figure><img src="https://img.cleberg.net/blog/20250502-asahi-linux/sysinfo.webp" alt="System information shows Fedora Linux Asahi Remix 42 with KDE 6.3.4."><figcaption><span class="figure-number">Figure 3: </span>System Information</figcaption></figure>
<p>As I noted above, the first thing I did after installing Asahi and taking a few screenshots was to install and change themes.</p>
<p>I prefer the WhiteSur theme, as I used this theme previously on Linux before I switched to macOS. However, I also like themes that incorporate the gruvbox color palette, as well as the Nothing theme that uses a dark black and red color palette.</p>
<figure><img src="https://img.cleberg.net/blog/20250502-asahi-linux/themes.webp" alt="Themes available by default on Asahi."><figcaption><span class="figure-number">Figure 4: </span>Themes</figcaption></figure>
<p>One of the things I use my laptop for the most is consuming media (music, television shows, movies, etc.), so I had to make sure that my bluetooth devices would connect properly.</p>
<p>As you can see in the screenshot below, my AirPods Pro 2 connect seamlessly and are available for use. By going through the normal button-holding process, I was able to pair my AirPods in about 10 seconds.</p>
<p>However, I have noticed that Asahi doesn't support some of the advanced AirPod capabilities like pausing media when you remove an AirPod from your ear. The lack of these advanced features doesn't bother me, but some people may be.</p>
<figure><img src="https://img.cleberg.net/blog/20250502-asahi-linux/bluetooth.webp" alt="Bluetooth settings showing AirPods Pro support."><figcaption><span class="figure-number">Figure 5: </span>Bluetooth</figcaption></figure>
<p>Next, I was able to connect my PS5 controller via USB-C and Asahi picked up the connect instantly in the settings menu. You can move the sticks and press all of the buttons to see if they're recognized within this settings menu.</p>
<figure><img src="https://img.cleberg.net/blog/20250502-asahi-linux/gamepad_settings.webp" alt="Gamepad settings showing PS5 input and button configurations."><figcaption><span class="figure-number">Figure 6: </span>Game Pad Settings</figcaption></figure>
<p>I had a bit of an issue launching Steam the first time, as I was getting an AVC Denial error from SELinux. To fix this, I had to manually allow the Steam application access to the requested resources:</p>
<pre><code class="language-shell">sudo ausearch -c 'passt' --raw | sudo audit2allow -M my-passt
sudo semodule -X 300 -i my-passt.pp</code></pre>
<p>While my MacBook only has 16GB of RAM, which seems to be the bare minimum required for the virtualization overhead, I was able to test one or two games before they crashed due to RAM errors.</p>
<p>However, I did confirm that my PS5 controller worked natively with these games on Steam! I don't think I will be gaming much on this laptop anyway, but it seems you should have at least the 32GB models if you want to game on Asahi.</p>
<h3 id="software-support"><span class="section-number-3">1.3.</span> Software Support</h3>
<p>One thing to keep in mind is that Apple silicon chips (M*) are based on the ARM architecture, which means you will need to install software that supports ARM (i.e., ARM64/aarch64).</p>
<p>While I have run into a handful of applications that do not have an ARM package available, it is not as difficult as it used to be to find suitable apps for all purposes on ARM.</p>
<h4 id="signal-desktop"><span class="section-number-4">1.3.1.</span> Signal Desktop</h4>
<p>One specific application that has been causing issues is <a href="https://signal.org/">Signal</a>. The download page on their website will prompt you to install their Debian-based package, which does not work on RPM-based systems (or any other distribution except Debian &amp; downstreams, such as Ubuntu).</p>
<p>There are a few different websites offering potential solutions, but I settled on the <a href="https://github.com/kenballus/asahi-signal-desktop/">asahi-signal-desktop</a> repository for now.</p>
<blockquote>
<p>One thing to note is that this script does not work with all versions of Signal. I tested out 7.53.0 and found that the installer did not work at all.</p>
<p>I had to use 7.44.0, as noted in the project's README, for the script to work.</p>
</blockquote>
<p>The installation process is simple. You can simply clone the repository and run the script:</p>
<pre><code class="language-shell">git clone https://github.com/kenballus/asahi-signal-desktop/
cd asahi-linux-desktop
./install_signal.sh 7.44.0</code></pre>
<p>At this point, Signal should work. However, I have run into constant crashing issues, so it's not a great solution.</p>
<p><a href="https://github.com/AsamK/signal-cli">signal-cli</a> may work, but I have not tested this yet on Asahi. Before I used macOS, I used <a href="https://github.com/isamert/scli">scli</a>, which provides a TUI for the signal-cli utility and it worked wonderfully.</p>
<h2 id="final-thoughts"><span class="section-number-2">2.</span> Final Thoughts</h2>
<p>I am still in the early days of testing out Asahi Linux, so I will be sure to come back and update this post occasionally, but I am very happy with the user experience so far. Everything is smooth and I am still able to experience the great hardware of the Macbook with the software of Linux.</p>
<p>In addition to the screenshots above, I have been testing out <a href="https://swaywm.org/">SwayWM</a>, which is slightly more difficult to configure after being away for Linux for a couple years. Regardless, it's working on Asahi as well and seems to be suitable for daily driving.</p>
<p>Overall, I am glad there's continued support for Asahi and will be supporting them through their Open Collective going forward. Cheers to the Asahi team on such a great product.</p>
]]></description>
    </item>
    <item>
      <title>Automating GitHub to GitLab Repository Sync</title>
      <link>https://cleberg.net/blog/git-mirror.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/git-mirror.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Sat, 05 Apr 2025 00:00:00 +0000</pubDate>
      <category>self-hosting</category>
      <description><![CDATA[<p>This is a short post detailing how I maintained repositories on GitHub and mirrors on GitLab - including both public and private repositories.</p>
<p>Since GitLab locks pull-only mirrors behind their Premium and Ultimate tiers, I found a different solution.</p>
<h2 id="creating-mirrors"><span class="section-number-2">1.</span> Creating Mirrors</h2>
<p>I'll skip the setup and just hit the bullet points:</p>
<ul>
<li>I have a plethora of GitHub repositories.</li>
<li>I used GitLab's mass-import functionality to do the initial import of my repositories from GitHub.</li>
<li>I made sure all of my GitHub repositories were cloned locally in my <code class="verbatim">~/git</code> directory.</li>
</ul>
<h2 id="setting-up-mirror-connections"><span class="section-number-2">2.</span> Setting up Mirror Connections</h2>
<p>To start, I navigated to the <code class="verbatim">~/git</code> directory, which holds all of the repositories I have on GitHub and created a shell script.</p>
<pre><code class="language-shell">cd ~/git
nano setup_mirrors.sh</code></pre>
<p>Within this shell script, I created a loop that will open each repository and add both the GitHub and GitLab SSH-style clone URIs to the <code class="verbatim">origin</code> remote.</p>
<pre><code class="language-shell">for repo in */
do
    cd $repo
    git remote set-url origin --push --add git@github.com:ccleberg/${repo%*/}.git
    git remote set-url origin --push --add git@gitlab.com:ccleberg/${repo%*/}.git
    git remote -v
    cd ..
done</code></pre>
<p>Once complete, I created another shell script to open each repository, pull any remote commits, and push local commits to both remotes.</p>
<pre><code class="language-shell">nano mirror.sh</code></pre>
<pre><code class="language-shell">for repo in */;
do
    cd $repo
    git pull --rebase origin HEAD
    git push
    cd ..
done</code></pre>
<p>Finally, enable execution of both scripts before moving on.</p>
<pre><code class="language-shell">chmod +x setup_mirrors.sh
chmod +x mirror.sh</code></pre>
<h2 id="initialize-mirrors"><span class="section-number-2">3.</span> Initialize Mirrors</h2>
<p>To use the <code class="verbatim">setup_mirrors.sh</code> script above, simply execute it from a terminal.</p>
<pre><code class="language-shell">./setup_mirrors.sh</code></pre>
<p>Once complete, each repository <em>should</em> have one fetch URI (GitHub) and two push URIs (GitHub &amp; GitLab). At this point, any <code class="verbatim">git pull</code> or <code class="verbatim">git fetch</code> commands will pull from GitHub and any <code class="verbatim">git push</code> commands will send updates to both GitHub and GitLab.</p>
<h2 id="schedule-periodic-checks"><span class="section-number-2">4.</span> Schedule Periodic Checks</h2>
<p>To utilize the <code class="verbatim">mirror.sh</code> script from the previous step, let's use crontab.</p>
<pre><code class="language-shell">crontab -e</code></pre>
<p>Within crontab, I used the schedule below to ensure the script is executed daily.</p>
<pre><code class="language-text">0 0 * * * /Users/cmc/git/mirror.sh</code></pre>
<p>This ensures that the <code class="verbatim">mirror.sh</code> file is executed daily and will push any local or GitHub commits to GitLab.</p>
<p>I have tested this by manually running <code class="verbatim">mirror.sh</code> and watching the results. There are edge cases where I will need to intervene and manually resolve merge conflicts, but it's largely autonomous, so I'm happy with the results.</p>
]]></description>
    </item>
    <item>
      <title>Email Migration: 5,000+ Emails, Proton to Migadu</title>
      <link>https://cleberg.net/blog/email-migration.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/email-migration.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Tue, 25 Feb 2025 00:00:00 +0000</pubDate>
      <category>privacy</category>
      <description><![CDATA[<h2 id="the-setup"><span class="section-number-2">1.</span> The Setup</h2>
<p>I recently migrated my emails from Proton Mail to Migadu after a failed attempt to get myself into the Proton ecosystem and wanted to detail my process, as it was far more painful than expected.</p>
<p>To give some context: I had nearly 5000 messages stored, accounting for around 2.5 GB of space.</p>
<p>Overall, this process would have taken all day had I done it in one sitting, but I decided to break it up and it lasted a couple days before I was able to say that all my messages were stored in my new account.</p>
<h2 id="exporting-messages"><span class="section-number-2">2.</span> Exporting Messages</h2>
<p>To start, I needed to export my messages from Proton Mail. As I am using macOS, I was able to use the <a href="https://proton.me/support/proton-mail-export-tool">Proton Mail Export Tool</a>. However, the downside is that this dumps every single email on your account into a single folder in the <code class="verbatim">.eml</code> format. They also export a JSON file for each message, in the case you're importing back into Proton Mail.</p>
<p>This means that anything in my Inbox, Sent, Archive, Trash, and user-created folders were all dumped out into a single folder with incomprehensible names.</p>
<p>Without a clear path to easily figure out how to re-organize my emails into a new account, I was left a bit annoyed at Proton's export process.</p>
<h2 id="importing-messages"><span class="section-number-2">3.</span> Importing Messages</h2>
<p>Left with a pile of messages and no way to discern what they were without opening each one, I decided to try and use Thunderbird to import messages into my new Migadu IMAP account.</p>
<p>This led to a dead end as my two methods failed:</p>
<ol>
<li><a href="https://addons.thunderbird.net/en-US/thunderbird/addon/importexporttools-ng/">ImportExportTools NG</a> does not work with my version of Thunderbird (135).</li>
<li>Manually dragging the <code class="verbatim">.eml</code> files onto a folder in Thunderbird worked for small batches of files, but seemed to lock up if I tried to import more than a few hundred at a time. It also seemed a bit buggy, as I ended up with many duplicate, and sometimes triplicate, messages.</li>
</ol>
<p>At this point, I decided to take a step back and use <a href="https://github.com/djcb/mu">mu</a>, a command-line utility that would index my files and sync back and forth with Migadu for me.</p>
<p>Using my blog post, <a href="https://cleberg.net/blog/mu4e.html">Email in Doom Emacs with Mu4e on macOS</a>, (and skipping the mu4e parts) I was able to set up a minimal directory connected to my Migadu IMAP account. Using my terminal, I simply moved all of my messages into the <code class="verbatim">mu</code> directory and synchronized the account, and voila, my messages synchronized successfully to the remote server and my other email clients.</p>
<p>However, the remaining issue was that I now had all 5000 messages in the Archive folder and needed to figure out how to organize them back into their proper directories.</p>
<h2 id="organizing-messages-into-folders"><span class="section-number-2">4.</span> Organizing Messages Into Folders</h2>
<p>As with any problem, I used Python as my hammer to fix the problem. I started by creating the directories required in Thunderbird, fetching them with <code class="verbatim">mbsync</code> so that they appeared in my <code class="verbatim">mu</code> directory, and using Python to organize my messages into the newly-created sub-folders.</p>
<h3 id="sent-messages"><span class="section-number-3">4.1.</span> Sent Messages</h3>
<p>I started by organizing my Sent messages. This required checking each file for the <code class="verbatim">From</code> header and moving them to the Sent folder.</p>
<pre><code class="language-shell">cd ~/.maildir/migadu/Archive/cur
nano _sent.py</code></pre>
<pre><code class="language-python highlight"><span class="source python"><span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> _sent.py
</span><span class="meta statement import python"><span class="keyword control import python">import</span> <span class="meta qualified-name python"><span class="meta generic-name python">os</span></span></span>
<span class="meta statement import python"><span class="keyword control import python">import</span> <span class="meta qualified-name python"><span class="meta generic-name python">glob</span></span></span>
<span class="meta statement import python"><span class="keyword control import python">import</span> <span class="meta qualified-name python"><span class="meta generic-name python">shutil</span></span></span>

<span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Loop through all files in the current folder
</span><span class="meta statement for python"><span class="keyword control flow for python">for</span> <span class="meta generic-name python">file</span> <span class="meta statement for python"><span class="keyword control flow for in python">in</span></span></span><span class="meta statement for python"> <span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">glob</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">glob</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">*.eml<span class="punctuation definition string end python">&quot;</span></span></span></span><span class="punctuation section arguments end python">)</span></span><span class="punctuation section block for python">:</span></span>
	<span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Create boolean to check if we should move the file
</span>	<span class="meta qualified-name python"><span class="meta generic-name python">move</span></span> <span class="keyword operator assignment python">=</span> <span class="constant language python">False</span>

	<span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Open the current file
</span>		<span class="meta qualified-name python"><span class="meta generic-name python">f</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="support function builtin python">open</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">file</span></span><span class="punctuation separator arguments python">,</span> <span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">r<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="punctuation section arguments end python">)</span></span>

	<span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> For each line in file, find the From header
</span>	<span class="meta statement for python"><span class="keyword control flow for python">for</span> <span class="meta generic-name python">line</span> <span class="meta statement for python"><span class="keyword control flow for in python">in</span></span></span><span class="meta statement for python"> <span class="meta qualified-name python"><span class="meta generic-name python">f</span></span><span class="punctuation section block for python">:</span></span>
		<span class="meta statement if python"><span class="keyword control flow conditional python">if</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">line</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">startswith</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">From:<span class="punctuation definition string end python">&quot;</span></span></span></span><span class="punctuation section arguments end python">)</span></span><span class="punctuation section block conditional python">:</span></span>
			<span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> If we find ourself, mark the message for move
</span>			<span class="meta statement if python"><span class="keyword control flow conditional python">if</span> <span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">user@example.com<span class="punctuation definition string end python">&quot;</span></span></span> <span class="keyword operator logical python">in</span> <span class="meta qualified-name python"><span class="meta generic-name python">line</span></span><span class="punctuation section block conditional python">:</span></span>
				<span class="meta qualified-name python"><span class="meta generic-name python">move</span></span> <span class="keyword operator assignment python">=</span> <span class="constant language python">True</span>

	<span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Close the file
</span>	<span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">f</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">close</span></span><span class="punctuation section arguments begin python">(</span><span class="punctuation section arguments end python">)</span></span>

	<span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Move the file, if marked for move
</span>	<span class="meta statement if python"><span class="keyword control flow conditional python">if</span> <span class="meta qualified-name python"><span class="meta generic-name python">move</span></span> <span class="keyword operator comparison python">==</span> <span class="constant language python">True</span><span class="punctuation section block conditional python">:</span></span>
		<span class="meta qualified-name python"><span class="meta generic-name python">filepath</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">os</span><span class="punctuation accessor dot python">.</span><span class="meta generic-name python">path</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">join</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">/Users/YOUR_USERNAME/.maildir/migadu/Archive/cur/<span class="punctuation definition string end python">&quot;</span></span></span><span class="punctuation separator arguments python">,</span> <span class="meta qualified-name python"><span class="meta generic-name python">file</span></span></span><span class="punctuation section arguments end python">)</span></span>
		<span class="meta qualified-name python"><span class="meta generic-name python">new_filepath</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">os</span><span class="punctuation accessor dot python">.</span><span class="meta generic-name python">path</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">join</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">/Users/YOUR_USERNAME/.maildir/migadu/Sent/cur/<span class="punctuation definition string end python">&quot;</span></span></span><span class="punctuation separator arguments python">,</span> <span class="meta qualified-name python"><span class="meta generic-name python">file</span></span></span><span class="punctuation section arguments end python">)</span></span>
		<span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">shutil</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">move</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">filepath</span></span><span class="punctuation separator arguments python">,</span> <span class="meta qualified-name python"><span class="meta generic-name python">new_filepath</span></span></span><span class="punctuation section arguments end python">)</span></span></span></code></pre>
<pre><code class="language-python highlight"><span class="source python"><span class="meta qualified-name python"><span class="meta generic-name python">python3</span></span> <span class="meta qualified-name python"><span class="meta generic-name python">_sent</span><span class="punctuation accessor dot python">.</span><span class="meta generic-name python">py</span></span></span></code></pre>
<p>The only downside to my current approach is that it was the quick and dirty option, so I re-ran it while editing the <code class="verbatim">user@example.com</code> string for each email I wanted to move. If I had wanted to create a more well-defined solution, I would have created an array of addresses to check for and have the <code class="verbatim">if</code> statement check against that array.</p>
<p>Regardless, I was able to run this with the addresses I wanted to move to the Sent folder and was soon finished.</p>
<h3 id="archive-sub-folders"><span class="section-number-3">4.2.</span> Archive Sub-Folders</h3>
<p>Next, I needed to move the remaining ~3000 messages from the Archive folder into dated sub-folders, organized as such:</p>
<ul>
<li>Archive/2016</li>
<li>…</li>
<li>Archive/2025</li>
</ul>
<p>To do this, I followed a similar approach as the method above but check for the <code class="verbatim">Date</code> header instead of the <code class="verbatim">From</code> header.</p>
<pre><code class="language-shell">cd ~/.maildir/migadu/Archive/cur
nano _archive.py</code></pre>
<p>This approach requires finding the <code class="verbatim">X-Pm-Date</code> header and splitting it by the spaces contained within. Once split into a list, we must select the fourth element, as that contains the year which will match the directory we should move it to.</p>
<p>For example, the header <code class="verbatim">X-Pm-Date: Fri, 07 Feb 2025 16:12:08 +0000</code> will be split into a list as such:</p>
<pre><code class="language-python highlight"><span class="source python"><span class="meta structure list python"><span class="punctuation section list begin python">[</span>
    <span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">X-Pm-Date:<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation separator list python">,</span> <span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> 0
</span>    <span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">Fri,<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation separator list python">,</span>       <span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> 1
</span>    <span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">07<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation separator list python">,</span>         <span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> 2
</span>    <span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">Feb<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation separator list python">,</span>        <span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> 3
</span>    <span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">2025<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation separator list python">,</span>       <span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> 4
</span>    <span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">16:12:08<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation separator list python">,</span>   <span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> 5
</span>    <span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">+0000<span class="punctuation definition string end python">&#39;</span></span></span>       <span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> 6
</span><span class="punctuation section list end python">]</span></span></span></code></pre>
<p>From this list, we select the fourth element (<code class="verbatim">2025</code>) and use that to build the destination path.</p>
<pre><code class="language-python highlight"><span class="source python"><span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> _archive.py
</span><span class="meta statement import python"><span class="keyword control import python">import</span> <span class="meta qualified-name python"><span class="meta generic-name python">os</span></span></span>
<span class="meta statement import python"><span class="keyword control import python">import</span> <span class="meta qualified-name python"><span class="meta generic-name python">glob</span></span></span>
<span class="meta statement import python"><span class="keyword control import python">import</span> <span class="meta qualified-name python"><span class="meta generic-name python">shutil</span></span></span>

<span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Loop through all files in the sub-folders under Archive
</span><span class="meta statement for python"><span class="keyword control flow for python">for</span> <span class="meta generic-name python">file</span> <span class="meta statement for python"><span class="keyword control flow for in python">in</span></span></span><span class="meta statement for python"> <span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">glob</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">glob</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">*.eml<span class="punctuation definition string end python">&quot;</span></span></span></span><span class="punctuation section arguments end python">)</span></span><span class="punctuation section block for python">:</span></span>
	<span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Create boolean to check if we should move the file
</span>	<span class="meta qualified-name python"><span class="meta generic-name python">move</span></span> <span class="keyword operator assignment python">=</span> <span class="constant language python">False</span>

	<span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Open the current file
</span>	<span class="meta qualified-name python"><span class="meta generic-name python">f</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="support function builtin python">open</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">file</span></span><span class="punctuation separator arguments python">,</span> <span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">r<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="punctuation section arguments end python">)</span></span>

	<span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> For each line in file, find the X-Pm-Date header
</span>	<span class="meta statement for python"><span class="keyword control flow for python">for</span> <span class="meta generic-name python">line</span> <span class="meta statement for python"><span class="keyword control flow for in python">in</span></span></span><span class="meta statement for python"> <span class="meta qualified-name python"><span class="meta generic-name python">f</span></span><span class="punctuation section block for python">:</span></span>
		<span class="meta statement if python"><span class="keyword control flow conditional python">if</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">line</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">startswith</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">X-Pm-Date<span class="punctuation definition string end python">&quot;</span></span></span></span><span class="punctuation section arguments end python">)</span></span><span class="punctuation section block conditional python">:</span></span>
		<span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Split the line into a list by spaces;
</span>		<span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Then select the item that contains the year
</span>			<span class="meta qualified-name python"><span class="meta generic-name python">year</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">line</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">split</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python"> <span class="punctuation definition string end python">&quot;</span></span></span></span><span class="punctuation section arguments end python">)</span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="constant numeric integer decimal python">4</span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span>
			<span class="meta qualified-name python"><span class="meta generic-name python">move</span></span> <span class="keyword operator assignment python">=</span> <span class="constant language python">True</span>

	<span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Close the file
</span>	<span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">f</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">close</span></span><span class="punctuation section arguments begin python">(</span><span class="punctuation section arguments end python">)</span></span>

	<span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Move the file, if marked for move
</span>	<span class="meta statement if python"><span class="keyword control flow conditional python">if</span> <span class="meta qualified-name python"><span class="meta generic-name python">move</span></span> <span class="keyword operator comparison python">==</span> <span class="constant language python">True</span><span class="punctuation section block conditional python">:</span></span>
		<span class="meta qualified-name python"><span class="meta generic-name python">filepath</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">os</span><span class="punctuation accessor dot python">.</span><span class="meta generic-name python">path</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">join</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">/Users/YOUR_USERNAME/.maildir/migadu/Archive/cur/<span class="punctuation definition string end python">&quot;</span></span></span><span class="punctuation separator arguments python">,</span> <span class="meta qualified-name python"><span class="meta generic-name python">file</span></span></span><span class="punctuation section arguments end python">)</span></span>
		<span class="meta qualified-name python"><span class="meta generic-name python">new_filepath</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">os</span><span class="punctuation accessor dot python">.</span><span class="meta generic-name python">path</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">join</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="storage type string python">f</span><span class="meta string interpolated python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string interpolated python"><span class="string quoted double python">/Users/YOUR_USERNAME/.maildir/migadu/Archive/</span><span class="meta interpolation python"><span class="punctuation section interpolation begin python">{</span><span class="source python embedded"><span class="meta qualified-name python"><span class="meta generic-name python">year</span></span></span></span><span class="meta interpolation python"><span class="punctuation section interpolation end python">}</span></span><span class="string quoted double python">/cur/<span class="punctuation definition string end python">&quot;</span></span></span><span class="punctuation separator arguments python">,</span> <span class="meta qualified-name python"><span class="meta generic-name python">file</span></span></span><span class="punctuation section arguments end python">)</span></span>
		<span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">shutil</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">move</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">filepath</span></span><span class="punctuation separator arguments python">,</span> <span class="meta qualified-name python"><span class="meta generic-name python">new_filepath</span></span></span><span class="punctuation section arguments end python">)</span></span></span></code></pre>
<pre><code class="language-python highlight"><span class="source python"><span class="meta qualified-name python"><span class="meta generic-name python">python3</span></span> <span class="meta qualified-name python"><span class="meta generic-name python">_archive</span><span class="punctuation accessor dot python">.</span><span class="meta generic-name python">py</span></span></span></code></pre>
<p>At this point, we've now moved all Sent messages to the Sent box and organized all messages under the Archive folder into their correct sub-folders.</p>
<p>If you exported other files, such as files from your Inbox, Trash, etc., you could follow a similar approach and determine the best header or attribute to identify them for further organization.</p>
<h3 id="synchronize-the-results"><span class="section-number-3">4.3.</span> Synchronize the Results</h3>
<p>Before synchronizing the files in their new locations, I needed to remove the characters at the end of the file name since <code class="verbatim">mu</code> appends IDs to the end of file names.</p>
<pre><code class="language-shell">cd ~/.maildir/migadu/Archive
nano _sync_prep.py</code></pre>
<p>This script prepares the <code class="verbatim">Archive</code> sub-folders for synchronization, but the same concept applies to the Sent folder, except you'd replace <code class="verbatim">*/cur/*</code> with <code class="verbatim">*</code> if this script were inside the <code class="verbatim">Sent/cur</code> directory.</p>
<pre><code class="language-python highlight"><span class="source python"><span class="meta statement import python"><span class="keyword control import python">import</span> <span class="meta qualified-name python"><span class="meta generic-name python">glob</span></span></span>
<span class="meta statement import python"><span class="keyword control import python">import</span> <span class="meta qualified-name python"><span class="meta generic-name python">shutil</span></span></span>

<span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Loop through all files in the sub-folders under Archive
</span><span class="meta statement for python"><span class="keyword control flow for python">for</span> <span class="meta generic-name python">file</span> <span class="meta statement for python"><span class="keyword control flow for in python">in</span></span></span><span class="meta statement for python"> <span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">glob</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">glob</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">*/cur/*<span class="punctuation definition string end python">&quot;</span></span></span></span><span class="punctuation section arguments end python">)</span></span><span class="punctuation section block for python">:</span></span>
	<span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Remove the characters at the end of the file name created by =mu=
</span>	<span class="meta qualified-name python"><span class="meta generic-name python">new_file</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">file</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">split</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">,U=<span class="punctuation definition string end python">&quot;</span></span></span><span class="punctuation separator arguments python">,</span><span class="constant numeric integer decimal python">1</span></span><span class="punctuation section arguments end python">)</span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="constant numeric integer decimal python">0</span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span>

	<span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Move the file to the new file name
</span>	<span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">shutil</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">move</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">file</span></span><span class="punctuation separator arguments python">,</span> <span class="meta qualified-name python"><span class="meta generic-name python">new_file</span></span></span><span class="punctuation section arguments end python">)</span></span></span></code></pre>
<pre><code class="language-shell">python3 _sync_prep.py</code></pre>
<p>Finally, we can synchronize the results.</p>
<pre><code class="language-shell">mbsync -aV</code></pre>
<h2 id="removing-duplicates"><span class="section-number-2">5.</span> Removing Duplicates</h2>
<p>My only remaining issue at the time of writing is identifying and removing duplicate messages. I have toyed with simple Python and command-line solutions to identify duplicate files, but could not get them to effectively define all the duplicates found in any specific directory.</p>
<p>I've even tried using the <a href="https://github.com/pkolaczk/fclones">fclones</a> utility, to no avail. It seems that something in the Proton export, my manual Thunderbird method attempt, or possible sync issues between Thunderbird -&gt; Migadu &lt;-&gt; mu caused duplicates where content within the message has been modified.</p>
<p>Although I now seem to be wasting space and in need of a deduplication tool, I have all of my messages migrated to my new service.</p>
]]></description>
    </item>
    <item>
      <title>Obscura VPN: A Two-Party Protocol Review</title>
      <link>https://cleberg.net/blog/obscura-vpn.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/obscura-vpn.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Tue, 11 Feb 2025 00:00:00 +0000</pubDate>
      <category>security</category>
      <description><![CDATA[<blockquote>
<p>This review is written at a high-level for users, not a technical deep-dive of VPN technologies.</p>
</blockquote>
<h2 id="what-is-obscura"><span class="section-number-2">1.</span> What is Obscura?</h2>
<p><a href="https://obscura.net/">Obscura</a> is a new VPN offering that's <a href="https://mullvad.net/en/blog/mullvad-partnered-with-obscura-vpn">partnered with Mullvad</a> to provide a unique service: a VPN that "can't log your activity" due to the fact that it uses Obscura servers for initial traffic routing and then passes off the traffic to Mullvad's WireGuard servers as exit nodes.</p>
<p>This two-party VPN protocol allows you to use Obscura to relay your traffic, but they don't see your traffic. On the other hand, the exit nodes from Mullvad will see where you're connecting but cannot tell who you are as your traffic will come directly from Obscura servers with other users.</p>
<h2 id="privacy-features"><span class="section-number-2">2.</span> Privacy Features</h2>
<p>One of the things I look for when considering a VPN are privacy features intended to benefit users. Here are the features I love about Obscura:</p>
<ul>
<li>Two-party VPN protocol with Mullvad's servers</li>
<li>No email required for sign-up</li>
<li>No credit card required, crypto options available</li>
<li>Open source <a href="https://github.com/Sovereign-Engineering/obscuravpn-client">repository</a> is available</li>
<li><a href="http://ngmmbxlzfpptluh4tbdt57prk3zxmq4ztew7l2whmg7hkqaof2nzf7id.onion/">Tor website available</a></li>
<li>Transparent display of the exit server's public key (see the Location page in the app) so you can verify with Mullvad that you're connect via a genuine Mullvad exit node using <a href="https://mullvad.net/en/servers">Mullvad's server listing</a></li>
</ul>
<h2 id="initial-impressions"><span class="section-number-2">3.</span> Initial Impressions</h2>
<h3 id="available-platforms"><span class="section-number-3">3.1.</span> Available Platforms</h3>
<p>I am testing out Obscura on macOS, as that is the only available platform. This is the biggest downside, as I would not want to support different VPNs on different devices - if I'm using Obscura, I want to use it on all of my platforms (macOS, iOS, and Ubuntu).</p>
<p>However, the macOS app is incredibly easy to install via the <code class="verbatim">.dmg</code> file available on Obscura's website. Upon first launch, you're presented with a login option and can create an account now, if you have not done so already.</p>
<h3 id="payment"><span class="section-number-3">3.2.</span> Payment</h3>
<p>Once created, the app will ask you to pay if you do not have a subscription. As far as I can tell, there is no free tier available. In my opinion, this is a good thing as I hesitate to understand how privacy-focused apps make money when they offer free services to users.</p>
<figure><img src="https://img.cleberg.net/blog/20250211-obscura-vpn/payment.webp" alt="Options to fund your Obscura account with credit card or lightning."><figcaption><span class="figure-number">Figure 1: </span>Payment</figcaption></figure>
<h3 id="connection"><span class="section-number-3">3.3.</span> Connection</h3>
<p>Once you've enrolled in either a subscription or one-time payment, Obscura will return you to the app and allow you to connect. You can choose a specific server location or automatically connect.</p>
<figure><img src="https://img.cleberg.net/blog/20250211-obscura-vpn/connect.webp" alt="Obscura macOS app on the Connection screen."><figcaption><span class="figure-number">Figure 2: </span>Initial Connection</figcaption></figure>
<figure><img src="https://img.cleberg.net/blog/20250211-obscura-vpn/toolbar.webp" alt="The Obscura VPN menu bar app on macOS shows connection status, bandwidth status, and options to debug or quit."><figcaption><span class="figure-number">Figure 3: </span>Toolbar Utility</figcaption></figure>
<h3 id="speed"><span class="section-number-3">3.4.</span> Speed</h3>
<p>The connection feels naturally smooth and I haven't experienced any disruptions or lag in my (very short) time testing out the application. To confirm, I checked a speed test while connected to a server location in my country.</p>
<p>Speed test results:</p>
<ul>
<li>85.49 Mbps (Down)</li>
<li>217.75 Mbps (Up)</li>
<li>25 ms (Ping)</li>
</ul>
<h3 id="mullvad-verification"><span class="section-number-3">3.5.</span> Mullvad Verification</h3>
<p>Lastly, I checked with Mullvad's verification tool (<code class="verbatim">mullvad.net/en/check</code>) to verify Obscura's claims that Obscura sends your traffic through Mullvad's exit nodes before connecting to your target.</p>
<p>From the image below, we can see that Mullvad confirmed my traffic to be connected through a Mullvad IP address.</p>
<figure><img src="https://img.cleberg.net/blog/20250211-obscura-vpn/mullvad-check.webp" alt="green when on Obscura."><figcaption><span class="figure-number">Figure 4: </span>Mullvad Check</figcaption></figure>
<h2 id="final-thoughts"><span class="section-number-2">4.</span> Final Thoughts</h2>
<p>Overall, I have found the app to be fast and user friendly. The privacy features are certainly compelling, but the platform has a ways to go before it can displace something like Mullvad in the privacy-focused portion of the VPN market.</p>
<p>I wish Obscura offered the following features:</p>
<ul>
<li>Available on more platforms</li>
<li>Specifics on how many devices will be allowed per account</li>
<li>More server locations, especially in countries with stronger data privacy laws</li>
<li>Options to pay with other crypto beside Bitcoin, such as Monero</li>
<li>Whitepapers or videos that walk through the technical details and show how traffic can be verified to be encrypted and connecting through the various expected nodes</li>
<li>Verifiable builds</li>
</ul>
<p>However, Obscura is a nice tool for now and I hope to see more information from the technical side to help more users gain comfort around the security and privacy of the tool.</p>
<p>Used Obscura? Send me an email and let me know your thoughts!</p>
]]></description>
    </item>
    <item>
      <title>Self-Hosting Guide: Tandoor</title>
      <link>https://cleberg.net/blog/self-hosting-tandoor.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/self-hosting-tandoor.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Thu, 23 Jan 2025 00:00:00 +0000</pubDate>
      <category>linux</category>
      <category>self-hosting</category>
      <description><![CDATA[<h2 id="overview"><span class="section-number-2">1.</span> Overview</h2>
<p><a href="https://tandoor.dev/">Tandoor</a> is a smart recipe manager web application that allows you to:</p>
<ul>
<li>Store your recipes</li>
<li>Search for recipes and ingredients</li>
<li>Share recipes with a link and permission system</li>
<li>Put recipes and ingredients into a shopping list</li>
<li>Plan your meals with a built-in calendar</li>
<li>Calculate nutritional values</li>
<li>Import recipes from websites and apps</li>
<li>Load existing recipes</li>
</ul>
<h2 id="installation"><span class="section-number-2">2.</span> Installation</h2>
<p><a href="https://docs.tandoor.dev/">The Tandoor docs</a> contain all of the relevant information needed to get start with the self-hosting process.</p>
<p>This tutorial will use Docker Compose and Nginx on Ubuntu 24.04.1.</p>
<h3 id="docker-compose"><span class="section-number-3">2.1.</span> Docker Compose</h3>
<p>On your machine, create a directory for Tandoor and copy down the <code class="verbatim">.env</code> and <code class="verbatim">docker-compose.yml</code> templates:</p>
<pre><code class="language-shell">mkdir ~/tandoor cd ~/tandoor wget
https://raw.githubusercontent.com/vabene1111/recipes/develop/.env.template -O .env wget
# Plain version of docker-compose.yml
https://raw.githubusercontent.com/vabene1111/recipes/develop/docs/install/docker/plain/docker-compose.yml</code></pre>
<p>Within these files, customize as needed.</p>
<ul>
<li><code class="verbatim">.env</code><ul>
<li>Add a <code class="verbatim">SECRET_KEY</code></li>
<li>Define the <code class="verbatim">ALLOWED_HOSTS</code></li>
<li>Set the <code class="verbatim">POSTGRES_PASSWORD</code></li>
</ul>
</li>
<li><code class="verbatim">docker-compose.yml</code><ul>
<li>Update the <code class="verbatim">ports</code> since Nginx on my host is already using port 80 (e.g. <code class="verbatim">8087:80</code>)</li>
</ul>
</li>
</ul>
<p>Once you've updated and saved the files, you can launch the container.</p>
<pre><code class="language-shell">sudo docker compose up -d</code></pre>
<p>The application is now available at <code class="verbatim">localhost:8087</code> or <code class="verbatim">ip_address:8087</code> if accessing via a different machine. If accessing via a different machine, remember to allow port <code class="verbatim">8087</code> through any existing firewalls.</p>
<h3 id="nginx-reverse-proxy"><span class="section-number-3">2.2.</span> Nginx Reverse Proxy</h3>
<p>Now that Tandoor is available locally, let's connect it to the Nginx web server running on the host machine.</p>
<blockquote>
<p>Note: I use Nginx configuration files within the <code class="verbatim">conf.d</code> directory, but you may need to use the <code class="verbatim">sites-available</code> directory, depending on your installation of Nginx.</p>
</blockquote>
<pre><code class="language-shell">cd /etc/nginx/conf.d/
sudo nano recipes.conf</code></pre>
<p>Within this file, define your website configuration. The example below is my default configuration and utilizes a wildcard certificate for <code class="verbatim">*.example.com</code> that covers all of my subdomains. If you don't have a wildcard certificate, you will need to generate an SSL certificate for your domain.</p>
<pre><code class="language-config">server {
        listen                  443 ssl;
        listen                  [::]:443 ssl;
        http2                   on;
        server_name             recipes.example.com;

        # SSL
        ssl_certificate         /etc/letsencrypt/live/example.com/fullchain.pem;
        ssl_certificate_key     /etc/letsencrypt/live/example.com/privkey.pem;
        ssl_trusted_certificate /etc/letsencrypt/live/example.com/chain.pem;

        # reverse proxy
        location / {
                proxy_pass         http://localhost:8087/;
                proxy_set_header   Host $http_host;
                proxy_set_header   X-Forwarded-Proto $scheme;
                proxy_redirect http://127.0.0.1:8080 https://recipes.example.com;
        }

        location /media/ {
                root   /media/;
                index  index.html index.htm;
        }
}

# HTTP redirect
server {
        listen      80;
        listen      [::]:80;
        server_name recipes.example.com;
        include     custom.d/letsencrypt.conf;

        if ($host ~ ^[^.]+\.example\.com$) {
                return 301 https://$host$request_uri;
        }
}</code></pre>
<p>Save and close the configuration file and then restart the web server.</p>
<pre><code class="language-shell">sudo systemctl restart nginx.service</code></pre>
<p>The app is now available on your custom domain!</p>
<h3 id="screenshots"><span class="section-number-3">2.3.</span> Screenshots</h3>
<figure><img src="https://img.cleberg.net/blog/20250123-self-hosting-tandoor/login.webp" alt="Tandoor login page."><figcaption><span class="figure-number">Figure 1: </span>Login</figcaption></figure>
<figure><img src="https://img.cleberg.net/blog/20250123-self-hosting-tandoor/recipes.webp" alt="Tandoor options to search for recipes."><figcaption><span class="figure-number">Figure 2: </span>Recipes</figcaption></figure>
<figure><img src="https://img.cleberg.net/blog/20250123-self-hosting-tandoor/mealplan.webp" alt="Calendar view to define meal plans."><figcaption><span class="figure-number">Figure 3: </span>Meal Plan</figcaption></figure>
<figure><img src="https://img.cleberg.net/blog/20250123-self-hosting-tandoor/shopping.webp" alt="Page to create or search for shopping lists."><figcaption><span class="figure-number">Figure 4: </span>Shopping Lists</figcaption></figure>
<figure><img src="https://img.cleberg.net/blog/20250123-self-hosting-tandoor/cookbook.webp" alt="Page to create a visual-style cookbook."><figcaption><span class="figure-number">Figure 5: </span>Cook Book</figcaption></figure>
<figure><img src="https://img.cleberg.net/blog/20250123-self-hosting-tandoor/import.webp" alt="Options to import recipes from other pages and auto-populate images, keywords, steps, and a description."><figcaption><span class="figure-number">Figure 6: </span>Import</figcaption></figure>
<figure><img src="https://img.cleberg.net/blog/20250123-self-hosting-tandoor/admin.webp" alt="Django administration options for the web app."><figcaption><span class="figure-number">Figure 7: </span>Administration Panel</figcaption></figure>
]]></description>
    </item>
    <item>
      <title>Self-Hosting Guide: The Lounge (IRC)</title>
      <link>https://cleberg.net/blog/self-hosting-the-lounge.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/self-hosting-the-lounge.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Sun, 29 Dec 2024 00:00:00 +0000</pubDate>
      <category>linux</category>
      <category>self-hosting</category>
      <description><![CDATA[<h2 id="the-lounge"><span class="section-number-2">1.</span> The Lounge</h2>
<p><a href="https://thelounge.chat/">The Lounge</a> is a self-hosted IRC client for the web, which supports a lot of desirable features for a modern IRC client. The Lounge supports push notifications, link previews, file uploads, always connected, multi-user support, and is available as a PWA for mobile devices.</p>
<p>I wanted to write this as I had written a post about <a href="https://cleberg.net/blog/self-hosting-convos.html">self-hosting Convos</a> and have recently migrated over to The Lounge instead.</p>
<p>If you'd like to try a demo first, head over to <a href="https://demo.thelounge.chat/">the official demo website</a>.</p>
<h3 id="installation-docker"><span class="section-number-3">1.1.</span> Installation (Docker)</h3>
<p>I install everything I can via Docker, so this tutorial will install The Lounge with the Docker Compose platform.</p>
<p>You can find the official docker version of The Lounge's repository on GitHub at <a href="https://github.com/thelounge/thelounge-docker">thelounge-docker</a>.</p>
<p>To start, let's create a directory for this app and create the <code class="verbatim">compose.yml</code> file.</p>
<pre><code class="language-shell">mkdir thelounge
cd thelounge
nano compose.yml</code></pre>
<p>Within this configuration file, you can paste the content below and customize as needed. If you want to use a different port on your machine, change the first port on the <code class="verbatim">9000:9000</code> line. Additionally, you may move the volume to a different location if required.</p>
<pre><code class="language-yaml highlight"><span class="source yaml"><span class="string unquoted plain out yaml"><span class="entity name tag yaml">services</span></span><span class="punctuation separator key-value mapping yaml">:</span>
  <span class="string unquoted plain out yaml"><span class="entity name tag yaml">thelounge</span></span><span class="punctuation separator key-value mapping yaml">:</span>
    <span class="string unquoted plain out yaml"><span class="entity name tag yaml">image</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string unquoted plain out yaml">ghcr.io/thelounge/thelounge:latest</span>
    <span class="string unquoted plain out yaml"><span class="entity name tag yaml">container_name</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string unquoted plain out yaml">thelounge</span>
    <span class="string unquoted plain out yaml"><span class="entity name tag yaml">ports</span></span><span class="punctuation separator key-value mapping yaml">:</span>
      <span class="punctuation definition block sequence item yaml">-</span> <span class="string quoted double yaml"><span class="punctuation definition string begin yaml">&quot;</span>9000:9000<span class="punctuation definition string end yaml">&quot;</span></span>
    <span class="string unquoted plain out yaml"><span class="entity name tag yaml">restart</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string unquoted plain out yaml">always</span>
    <span class="string unquoted plain out yaml"><span class="entity name tag yaml">volumes</span></span><span class="punctuation separator key-value mapping yaml">:</span>
      <span class="punctuation definition block sequence item yaml">-</span> <span class="string unquoted plain out yaml">./.thelounge:/var/opt/thelounge</span></span></code></pre>
<p>Save and close the file and you can now launch the service.</p>
<pre><code class="language-shell">sudo docker compose up -d</code></pre>
<p>The service is now available at <code class="verbatim">localhost:9000</code> or <code class="verbatim">machine_ip:9000</code> if you're browsing from a different device. Don't forget to allow the port through your machine's firewall, if you have one enabled.</p>
<figure><img src="https://img.cleberg.net/blog/20241229-thelounge/login.webp" alt="The Lounge login page with username and password fields."><figcaption><span class="figure-number">Figure 1: </span>Login</figcaption></figure>
<h3 id="nginx-reverse-proxy"><span class="section-number-3">1.2.</span> Nginx Reverse Proxy</h3>
<p>If you want to access the service via a domain name (<code class="verbatim">thelounge.example.com</code>), you can use Nginx as a reverse proxy.</p>
<p>First, create the Nginx configuration file.</p>
<pre><code class="language-shell">sudo nano /etc/nginx/conf.d/</code></pre>
<p>The configuration below assumes you have a wildcard certificate for HTTPS (:443) traffic via <code class="verbatim">example.com</code>. If you don't, you'll need to obtain an SSL certificate to use HTTPS.</p>
<pre><code class="language-configuration">upstream irc_upstream { server 127.0.0.1:9000; }

# HTTP redirect
server {
	listen      80;
	listen      [::]:80;
	server_name thelounge.example.com;
	include     custom.d/letsencrypt.conf;

	if ($host ~ ^[^.]+\.example\.com) {
		return 301 https://$host$request_uri;
	}
}

# HTTPS
server {
	listen                  443 ssl;
	listen                  [::]:443 ssl;
	http2			on;
	server_name             thelounge.example.com;

	# SSL
	ssl_certificate         /etc/letsencrypt/live/example.com/fullchain.pem;
	ssl_certificate_key     /etc/letsencrypt/live/example.com/privkey.pem;
	ssl_trusted_certificate /etc/letsencrypt/live/example.com/chain.pem;

	# reverse proxy
	location / {
	        proxy_pass           http://irc_upstream;
	        client_max_body_size 0;
	        proxy_set_header     X-Request-Base "$scheme://$host/";

		# Standard reverse proxy settings
		proxy_set_header Host $host;
		proxy_set_header Upgrade $http_upgrade;
		proxy_set_header Connection upgrade;
		proxy_set_header Accept-Encoding gzip;
		proxy_set_header X-Real-IP $remote_addr;
		proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
		proxy_set_header X-Forwarded-Proto $scheme;
		proxy_set_header X-Forwarded-Host $http_host;
		proxy_set_header X-Forwarded-Uri $request_uri;
		proxy_set_header X-Forwarded-Ssl on;
		proxy_redirect  http://  $scheme://;
		proxy_http_version 1.1;
		proxy_set_header Connection "";
		proxy_cache_bypass $cookie_session;
		proxy_no_cache $cookie_session;
		proxy_buffers 64 256k;
	}
}</code></pre>
<p>Finally, restart Nginx to see the effects.</p>
<pre><code class="language-shell">sudo systemctl restart nginx.service</code></pre>
<h3 id="initial-setup"><span class="section-number-3">1.3.</span> Initial Setup</h3>
<p>The first thing you'll need to do is create a user. You can do this with the docker container with the following command, which will ask for a password.</p>
<pre><code class="language-shell">sudo docker exec --user node -it thelounge thelounge add [username]</code></pre>
<p>Once the user has been created, you'll be able to log in to the web interface. Once created, you can change your password in the settings panel of the web interface.</p>
<p>Finally, you can connect to an IRC server with the plus (<code class="verbatim">+</code>) button at the bottom of the sidebar and connect to individual channels or users via the plus (<code class="verbatim">+</code>) button next to your server's name in the sidebar.</p>
<figure><img src="https://img.cleberg.net/blog/20241229-thelounge/new_connection.webp" alt="Settings for network, proxy, preferences, and authentication."><figcaption><span class="figure-number">Figure 2: </span>New Server Connection</figcaption></figure>
<figure><img src="https://img.cleberg.net/blog/20241229-thelounge/existing_connection.webp" alt="Libera.Chat server connection log and status."><figcaption><span class="figure-number">Figure 3: </span>Existing Server Connection</figcaption></figure>
<figure><img src="https://img.cleberg.net/blog/20241229-thelounge/channel.webp" alt="View of the #emacs channel on Libera.Chat."><figcaption><span class="figure-number">Figure 4: </span>Channel View</figcaption></figure>
]]></description>
    </item>
    <item>
      <title>Ollama Code Assistant in VS Codium</title>
      <link>https://cleberg.net/blog/continue-ollama-code-assistant.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/continue-ollama-code-assistant.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Thu, 31 Oct 2024 00:00:00 +0000</pubDate>
      <category>linux</category>
      <description><![CDATA[<h2 id="background"><span class="section-number-2">1.</span> Background</h2>
<p>As someone who doesn't do software development full time and intends to actually enjoy it as a hobby, I've been interested in the <em>concept</em> of code assistants for a while. However, I had a few issues:</p>
<ol>
<li>I'm not a full-time developer, so I wanted to actually learn all the various features and rules of the projects I was building.</li>
<li>The quality was quite low until recently.</li>
<li>I wanted to use an open-source solution. Ideally, one with a free tier so that I could test it before paying for a subscription.</li>
</ol>
<p>I recently discovered <a href="https://www.continue.dev/">Continue</a>, which allows for local LLM configurations via <a href="https://ollama.com/">Ollama</a>, so I've decided to try it out and see how helpful a code assistant can really be for someone like me, who doesn't do this professionally.</p>
<h2 id="installation"><span class="section-number-2">2.</span> Installation</h2>
<p>Installation is a quick and painless process if you already have Ollama installed, but I'll assume that we're starting from scratch.</p>
<h3 id="ollama"><span class="section-number-3">2.1.</span> Ollama</h3>
<p>First, install Ollama for your system. For macOS devices, I'd recommend using Homebrew via the following command. However, you can also visit their website and install the software manually.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">brew</span></span><span class="meta function-call arguments shell"> install ollama</span>
<span class="meta function-call shell"><span class="variable function shell">brew</span></span><span class="meta function-call arguments shell"> services start ollama</span></span></code></pre>
<p>Next, we will need to install the models requested by the Continue extension. By default, Continue asks you to install the <code class="verbatim">llama3.1:8b</code> and <code class="verbatim">starcoder2:3b</code> models. However, you can customize the configuration to specify different models, if preferred.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">ollama</span></span><span class="meta function-call arguments shell"> pull llama3.1:8b </span>
<span class="meta function-call shell"><span class="variable function shell">ollama</span></span><span class="meta function-call arguments shell"> pull starcoder2:3b</span></span></code></pre>
<p>At this point, Ollama should be running on your local machine and have two models available for use.</p>
<p>You can test this by visiting <code class="verbatim">http://localhost:11434/</code> in your browser or use cURL in your shell:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">curl</span></span><span class="meta function-call arguments shell"> http://localhost:11434</span>

<span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> If running, the response will look like this:</span><span class="comment line number-sign shell">
</span><span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> Ollama is running</span></span></code></pre>
<h3 id="continue"><span class="section-number-3">2.2.</span> Continue</h3>
<p>To get started with using Ollama as a code assistant in VS Codium, you'll first need to install the Continue extension. This extension is available for free on the Visual Studio Code marketplace and can be easily installed via the built-in Extension view.</p>
<p>Follow these steps:</p>
<ol>
<li>Open VS Codium and navigate to the Extensions view by clicking on the square icon next to the file menu or pressing <code class="verbatim">Ctrl+Shift+X</code> (Windows/Linux) or <code class="verbatim">Cmd+Shift+X</code> (Mac).</li>
<li>Search for "Continue" in the Extensions marketplace.</li>
<li>Click on the Continue extension and click Install.</li>
</ol>
<p>Once installed, restart VS Codium to ensure that the extension is properly loaded.</p>
<h2 id="continue-extension-configuration"><span class="section-number-2">3.</span> Continue: Extension Configuration</h2>
<p>When you first install Continue, it will ask which service you'll be using. If you select Ollama, it will check to make sure Ollama is running and you have installed the two default models from Ollama.</p>
<p>After this initial setup, you can open the <code class="verbatim">config.json</code> file by pressing <code class="verbatim">Cmd + p</code> and entering <code class="verbatim">&gt; Continue: Open config.json</code>. This will show a config such as the following:</p>
<pre><code class="language-json highlight"><span class="source json"><span class="meta structure dictionary json"><span class="punctuation section dictionary begin json">{</span>
  <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>models<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="meta structure array json"><span class="punctuation section array begin json">[</span>
    <span class="meta structure dictionary json"><span class="punctuation section dictionary begin json">{</span>
      <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>title<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>Llama 3.1 8B<span class="punctuation definition string end json">&quot;</span></span><span class="punctuation separator dictionary pair json">,</span></span>
      <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>provider<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>ollama<span class="punctuation definition string end json">&quot;</span></span><span class="punctuation separator dictionary pair json">,</span></span>
      <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>model<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>llama3.1:8b<span class="punctuation definition string end json">&quot;</span></span>
    </span><span class="punctuation section dictionary end json">}</span></span><span class="punctuation separator array json">,</span>
    <span class="meta structure dictionary json"><span class="punctuation section dictionary begin json">{</span>
      <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>model<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>claude-3-5-sonnet-20240620<span class="punctuation definition string end json">&quot;</span></span><span class="punctuation separator dictionary pair json">,</span></span>
      <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>provider<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>anthropic<span class="punctuation definition string end json">&quot;</span></span><span class="punctuation separator dictionary pair json">,</span></span>
      <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>apiKey<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span><span class="punctuation definition string end json">&quot;</span></span><span class="punctuation separator dictionary pair json">,</span></span>
      <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>title<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>Claude 3.5 Sonnet<span class="punctuation definition string end json">&quot;</span></span>
    </span><span class="punctuation section dictionary end json">}</span></span>
  <span class="punctuation section array end json">]</span></span><span class="punctuation separator dictionary pair json">,</span></span>
  <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>tabAutocompleteModel<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="meta structure dictionary json"><span class="punctuation section dictionary begin json">{</span>
    <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>title<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>Starcoder 3b<span class="punctuation definition string end json">&quot;</span></span><span class="punctuation separator dictionary pair json">,</span></span>
    <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>provider<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>ollama<span class="punctuation definition string end json">&quot;</span></span><span class="punctuation separator dictionary pair json">,</span></span>
    <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>model<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>starcoder2:3b<span class="punctuation definition string end json">&quot;</span></span>
  </span><span class="punctuation section dictionary end json">}</span></span><span class="punctuation separator dictionary pair json">,</span></span>
  <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>customCommands<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="meta structure array json"><span class="punctuation section array begin json">[</span>
    <span class="meta structure dictionary json"><span class="punctuation section dictionary begin json">{</span>
      <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>name<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>test<span class="punctuation definition string end json">&quot;</span></span><span class="punctuation separator dictionary pair json">,</span></span>
      <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>prompt<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>{{{ input }}}<span class="constant character escape json">\n</span><span class="constant character escape json">\n</span>Write a comprehensive set of unit tests for the selected code. It should setup, run tests that check for correctness including important edge cases, and teardown. Ensure that the tests are complete and sophisticated. Give the tests just as chat output, don&#39;t edit any file.<span class="punctuation definition string end json">&quot;</span></span><span class="punctuation separator dictionary pair json">,</span></span>
      <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>description<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>Write unit tests for highlighted code<span class="punctuation definition string end json">&quot;</span></span>
    </span><span class="punctuation section dictionary end json">}</span></span>
  <span class="punctuation section array end json">]</span></span><span class="punctuation separator dictionary pair json">,</span></span>
  <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>contextProviders<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="meta structure array json"><span class="punctuation section array begin json">[</span>
    <span class="meta structure dictionary json"><span class="punctuation section dictionary begin json">{</span>
      <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>name<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>code<span class="punctuation definition string end json">&quot;</span></span><span class="punctuation separator dictionary pair json">,</span></span>
      <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>params<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="meta structure dictionary json"><span class="punctuation section dictionary begin json">{</span><span class="punctuation section dictionary end json">}</span></span>
    </span><span class="punctuation section dictionary end json">}</span></span><span class="punctuation separator array json">,</span>
    <span class="meta structure dictionary json"><span class="punctuation section dictionary begin json">{</span>
      <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>name<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>docs<span class="punctuation definition string end json">&quot;</span></span><span class="punctuation separator dictionary pair json">,</span></span>
      <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>params<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="meta structure dictionary json"><span class="punctuation section dictionary begin json">{</span><span class="punctuation section dictionary end json">}</span></span>
    </span><span class="punctuation section dictionary end json">}</span></span><span class="punctuation separator array json">,</span>
    <span class="meta structure dictionary json"><span class="punctuation section dictionary begin json">{</span>
      <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>name<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>diff<span class="punctuation definition string end json">&quot;</span></span><span class="punctuation separator dictionary pair json">,</span></span>
      <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>params<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="meta structure dictionary json"><span class="punctuation section dictionary begin json">{</span><span class="punctuation section dictionary end json">}</span></span>
    </span><span class="punctuation section dictionary end json">}</span></span><span class="punctuation separator array json">,</span>
    <span class="meta structure dictionary json"><span class="punctuation section dictionary begin json">{</span>
      <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>name<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>terminal<span class="punctuation definition string end json">&quot;</span></span><span class="punctuation separator dictionary pair json">,</span></span>
      <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>params<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="meta structure dictionary json"><span class="punctuation section dictionary begin json">{</span><span class="punctuation section dictionary end json">}</span></span>
    </span><span class="punctuation section dictionary end json">}</span></span><span class="punctuation separator array json">,</span>
    <span class="meta structure dictionary json"><span class="punctuation section dictionary begin json">{</span>
      <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>name<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>problems<span class="punctuation definition string end json">&quot;</span></span><span class="punctuation separator dictionary pair json">,</span></span>
      <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>params<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="meta structure dictionary json"><span class="punctuation section dictionary begin json">{</span><span class="punctuation section dictionary end json">}</span></span>
    </span><span class="punctuation section dictionary end json">}</span></span><span class="punctuation separator array json">,</span>
    <span class="meta structure dictionary json"><span class="punctuation section dictionary begin json">{</span>
      <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>name<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>folder<span class="punctuation definition string end json">&quot;</span></span><span class="punctuation separator dictionary pair json">,</span></span>
      <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>params<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="meta structure dictionary json"><span class="punctuation section dictionary begin json">{</span><span class="punctuation section dictionary end json">}</span></span>
    </span><span class="punctuation section dictionary end json">}</span></span><span class="punctuation separator array json">,</span>
    <span class="meta structure dictionary json"><span class="punctuation section dictionary begin json">{</span>
      <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>name<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>codebase<span class="punctuation definition string end json">&quot;</span></span><span class="punctuation separator dictionary pair json">,</span></span>
      <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>params<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="meta structure dictionary json"><span class="punctuation section dictionary begin json">{</span><span class="punctuation section dictionary end json">}</span></span>
    </span><span class="punctuation section dictionary end json">}</span></span>
  <span class="punctuation section array end json">]</span></span><span class="punctuation separator dictionary pair json">,</span></span>
  <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>slashCommands<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="meta structure array json"><span class="punctuation section array begin json">[</span>
    <span class="meta structure dictionary json"><span class="punctuation section dictionary begin json">{</span>
      <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>name<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>edit<span class="punctuation definition string end json">&quot;</span></span><span class="punctuation separator dictionary pair json">,</span></span>
      <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>description<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>Edit selected code<span class="punctuation definition string end json">&quot;</span></span>
    </span><span class="punctuation section dictionary end json">}</span></span><span class="punctuation separator array json">,</span>
    <span class="meta structure dictionary json"><span class="punctuation section dictionary begin json">{</span>
      <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>name<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>comment<span class="punctuation definition string end json">&quot;</span></span><span class="punctuation separator dictionary pair json">,</span></span>
      <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>description<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>Write comments for the selected code<span class="punctuation definition string end json">&quot;</span></span>
    </span><span class="punctuation section dictionary end json">}</span></span><span class="punctuation separator array json">,</span>
    <span class="meta structure dictionary json"><span class="punctuation section dictionary begin json">{</span>
      <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>name<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>share<span class="punctuation definition string end json">&quot;</span></span><span class="punctuation separator dictionary pair json">,</span></span>
      <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>description<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>Export the current chat session to markdown<span class="punctuation definition string end json">&quot;</span></span>
    </span><span class="punctuation section dictionary end json">}</span></span><span class="punctuation separator array json">,</span>
    <span class="meta structure dictionary json"><span class="punctuation section dictionary begin json">{</span>
      <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>name<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>cmd<span class="punctuation definition string end json">&quot;</span></span><span class="punctuation separator dictionary pair json">,</span></span>
      <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>description<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>Generate a shell command<span class="punctuation definition string end json">&quot;</span></span>
    </span><span class="punctuation section dictionary end json">}</span></span><span class="punctuation separator array json">,</span>
    <span class="meta structure dictionary json"><span class="punctuation section dictionary begin json">{</span>
      <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>name<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>commit<span class="punctuation definition string end json">&quot;</span></span><span class="punctuation separator dictionary pair json">,</span></span>
      <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>description<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>Generate a git commit message<span class="punctuation definition string end json">&quot;</span></span>
    </span><span class="punctuation section dictionary end json">}</span></span>
  <span class="punctuation section array end json">]</span></span><span class="punctuation separator dictionary pair json">,</span></span>
  <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>embeddingsProvider<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="meta structure dictionary json"><span class="punctuation section dictionary begin json">{</span>
    <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>provider<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>ollama<span class="punctuation definition string end json">&quot;</span></span><span class="punctuation separator dictionary pair json">,</span></span>
    <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>model<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>nomic-embed-text<span class="punctuation definition string end json">&quot;</span></span>
  </span><span class="punctuation section dictionary end json">}</span></span>
</span><span class="punctuation section dictionary end json">}</span></span></span></code></pre>
<p>You can modify this file with many different customizations. Refer to the <a href="https://docs.continue.dev/customize/config">Configuration options</a> page for more information.</p>
<h2 id="use-cases"><span class="section-number-2">4.</span> Use Cases</h2>
<p>While I'm sure there are a ton of use cases that I can't think of, I decided to test it out with this blog and some basic Python scripts I am currently using. Here are the most common ones I've used so far:</p>
<ul>
<li>Improving README documentation</li>
<li>Refactor my <code class="verbatim">salary_visualization.py</code> script to align with PEP8.</li>
<li>Auto-complete thoughts and suggest further ideas for topics in this blog post.</li>
</ul>
<p>As an example, the following list of possible use cases was auto-generated by Continue:</p>
<ul>
<li>Auto-complete function names and variables: With Ollama enabled, typing a few characters into the editor will suggest matching functions or variables from the entire project.</li>
<li>Code suggestions for common tasks: Ollama can provide suggestions for common programming tasks, such as converting types or formatting code.</li>
<li>Live coding assistance: As you type, Ollama can offer live suggestions and corrections to help ensure your code is correct.</li>
</ul>
<h3 id="screenshots"><span class="section-number-3">4.1.</span> Screenshots</h3>
<p>Below are a few screenshots from my current VS Codium window:</p>
<figure><img src="https://img.cleberg.net/blog/20241031-continue-ollama-code-assistant/continue_commands.webp" alt="List of commands available from the Continue package."><figcaption><span class="figure-number">Figure 1: </span>Available Continue Commands</figcaption></figure>
<figure><img src="https://img.cleberg.net/blog/20241031-continue-ollama-code-assistant/continue_fullscreen.webp" alt="Continue chat window in full screen mode."><figcaption><span class="figure-number">Figure 2: </span>Continue Fullscreen Chat Window</figcaption></figure>
<figure><img src="https://img.cleberg.net/blog/20241031-continue-ollama-code-assistant/continue_inline_hotkeys.webp" alt="View of the Add to chat (Cmd+L) and Edit highlighted code (Cmd+I) options when typing inline."><figcaption><span class="figure-number">Figure 3: </span>Inline Hotkeys</figcaption></figure>
<figure><img src="https://img.cleberg.net/blog/20241031-continue-ollama-code-assistant/continue_inline.webp" alt="Highlighted red and green sections showing suggestions from the agent."><figcaption><span class="figure-number">Figure 4: </span>Inline Editing Suggestions</figcaption></figure>
<figure><img src="https://img.cleberg.net/blog/20241031-continue-ollama-code-assistant/continue_sidebar.webp" alt="View of the sidebar context window open side-by-side with an edited file."><figcaption><span class="figure-number">Figure 5: </span>Sidebar Context Window</figcaption></figure>
<h2 id="conclusion"><span class="section-number-2">5.</span> Conclusion</h2>
<p>As it stands, it seems that the current iteration of code completion and review models from Ollama are quite good for my use case. In particular, it is able to suggest logical continuations of my thoughts in a blog post, generate accurate documentation based on my files, explain code to me with references within the project, and align my existing files to standards.</p>
<p>However, it is not perfect. I have noticed that it often goes off in a random direction, unrelated to the intent of what I'm writing (either blogging or programming). It also struggles to understand the full context without clear, specific, repeated instructions to refer to certain files, standards, etc. while suggesting improvements.</p>
<p>All together, I think it's useful enough to suggest as an add-on tool, but I would be highly skeptical of any suggestions it provides.</p>
]]></description>
    </item>
    <item>
      <title>Self-Hosting Guide: Transmission</title>
      <link>https://cleberg.net/blog/self-hosting-transmission.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/self-hosting-transmission.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Mon, 23 Sep 2024 00:00:00 +0000</pubDate>
      <category>linux</category>
      <category>self-hosting</category>
      <description><![CDATA[<blockquote>
<p>If you're torrenting anything sensitive, I <strong>highly</strong> recommend you use a VPN. Something like mullvad-cli is incredibly simple to use and can be configured to have a "killswitch" or "lockdown mode" to ensure that if the VPN disconnects, your traffic won't be leaked to your ISP.</p>
</blockquote>
<h2 id="transmission"><span class="section-number-2">1.</span> Transmission</h2>
<p><a href="https://transmissionbt.com/">Transmission</a> is a cross-platform bittorrent client that supports running a <a href="https://linux.die.net/man/1/transmission-remote">remote control utility</a>, a <a href="https://linux.die.net/man/1/transmission-daemon">daemon service</a> for running as a background service, and a <a href="https://linux.die.net/man/1/transmission-cli">command-line client</a>.</p>
<p>Since I love torrenting Linux ISOs and providing them back to the community, let's walk through a tutorial of setting up Transmission on a headless server and connecting it to a domain name (<code class="verbatim">transmission.example.com</code>) so that we can manage our torrents remotely.</p>
<p>This tutorial assumes you have a Linux machine, have Nginx installed, and have a domain name pointing at your Linux machine.</p>
<h3 id="installation"><span class="section-number-3">1.1.</span> Installation</h3>
<p>First, let's install a couple Transmission packages on the system. We don't need the GUI components, so we'll only install the daemon and command line interface utilities.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> apt install transmission-cli transmission-common transmission-daemon</span></span></code></pre>
<p>You will need to run the program to initialize the files before you can edit the configurations, so let's run it and end the process.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> Run the program</span><span class="comment line number-sign shell">
</span><span class="meta function-call shell"><span class="variable function shell">transmission-daemon</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>e</span> <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/.local/log/transmission.log</span>

<span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> End the program after it finishes running</span><span class="comment line number-sign shell">
</span><span class="meta function-call shell"><span class="variable function shell">transmission-remote</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> --</span>exit</span></span></span></code></pre>
<h3 id="configuration"><span class="section-number-3">1.2.</span> Configuration</h3>
<p>Now that we've run the program for the first time and initialized the relevant files, let's edit those files.</p>
<blockquote>
<p>If you edit the files while Transmission is running, your changes won't be saved! Make sure to end the service, update the configuration files, and restart the service.</p>
</blockquote>
<p>To start, let's edit the main configuration file.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">nano</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/.config/transmission-daemon/settings.json</span></span></code></pre>
<p>Within this file, I suggesting skimming <strong>every</strong> option and determining if you want to change any of those options.</p>
<p>For remote access, we will focus on the following <code class="verbatim">rpc</code> options. This configuration will not require authentication, will allow any device with access (I suggest that you have a firewall restricting access) to access the service (<code class="verbatim">"rpc-bind-access": "0.0.0.0"</code>), will open the service on port <code class="verbatim">9091</code>, and will whitelist a few LAN IPs (<code class="verbatim">"rpc-whitelist": "127.0.0.1,::1,192.168.0.98,192.168.0.97"</code>).</p>
<pre><code class="language-json highlight"><span class="source json"><span class="meta structure dictionary json"><span class="punctuation section dictionary begin json">{</span>
    <span class="invalid illegal expected-dictionary-separator json">.</span><span class="invalid illegal expected-dictionary-separator json">.</span><span class="invalid illegal expected-dictionary-separator json">.</span>
    <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>rpc-authentication-required<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="constant language json">false</span><span class="punctuation separator dictionary pair json">,</span></span>
    <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>rpc-bind-address<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>0.0.0.0<span class="punctuation definition string end json">&quot;</span></span><span class="punctuation separator dictionary pair json">,</span></span>
    <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>rpc-enabled<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="constant language json">true</span><span class="punctuation separator dictionary pair json">,</span></span>
    <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>rpc-host-whitelist<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span><span class="punctuation definition string end json">&quot;</span></span><span class="punctuation separator dictionary pair json">,</span></span>
    <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>rpc-host-whitelist-enabled<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="constant language json">true</span><span class="punctuation separator dictionary pair json">,</span></span>
    <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>rpc-password<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>{7fc02520b97e054f7a15274c7cfafe3cd7330169.OQUAUS4<span class="punctuation definition string end json">&quot;</span></span><span class="punctuation separator dictionary pair json">,</span></span>
    <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>rpc-port<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="constant numeric json">9091</span><span class="punctuation separator dictionary pair json">,</span></span>
    <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>rpc-socket-mode<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>0750<span class="punctuation definition string end json">&quot;</span></span><span class="punctuation separator dictionary pair json">,</span></span>
    <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>rpc-url<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>/transmission/<span class="punctuation definition string end json">&quot;</span></span><span class="punctuation separator dictionary pair json">,</span></span>
    <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>rpc-username<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span><span class="punctuation definition string end json">&quot;</span></span><span class="punctuation separator dictionary pair json">,</span></span>
    <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>rpc-whitelist<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>127.0.0.1,::1,192.168.0.98,192.168.0.97<span class="punctuation definition string end json">&quot;</span></span><span class="punctuation separator dictionary pair json">,</span></span>
    <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>rpc-whitelist-enabled<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="constant language json">true</span><span class="punctuation separator dictionary pair json">,</span></span>
    <span class="invalid illegal expected-dictionary-separator json">.</span><span class="invalid illegal expected-dictionary-separator json">.</span><span class="invalid illegal expected-dictionary-separator json">.</span>
<span class="punctuation section dictionary end json">}</span></span></span></code></pre>
<p>Once you've finished configuring the service, start the service up again.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">transmission-daemon</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>e</span> <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/.local/log/transmission.log</span></span></code></pre>
<p>At this point, you should be able to access the website at <code class="verbatim">localhost:9091</code> (if you're browsing on the machine where Transmission is running) or <code class="verbatim">$server_ip:9091</code> (if you're browsing from a different LAN device).</p>
<p>If you want to make further changes to Transmission's configuration, I suggest doing so now. Once you start working on remote access via a reverse proxy, you'll be adding an additional layer of complexity that bring in more confusion when errors occur.</p>
<blockquote>
<p>NOTE: If you are trying to initialize <code class="verbatim">transmission-daemon</code> via <code class="verbatim">systemd</code> instead of using the manually-executed command above, you may notice that the service will timeout and fail to start.</p>
</blockquote>
<p>To fix this timeout issue, you need to edit the service file and change <code class="verbatim">Type=notify</code> to <code class="verbatim">Type=simple</code>.</p>
<pre><code class="language-shell"># Command to edit the service file:
sudo systemctl edit --full transmission-daemon.service

# Make the edit noted above and then reload the service file with this command:
sudo systemctl daemon-reload
sudo systemctl enable transmission-daemon.service
sudo systemctl start transmission-daemon.service</code></pre>
<h2 id="reverse-proxy"><span class="section-number-2">2.</span> Reverse Proxy</h2>
<p>Now that the service is running and configured properly, let's work on remote access.</p>
<p>This tutorial will use Nginx, but you can use any reverse proxy or something like Cloudflare Tunnels if that's your thing.</p>
<h3 id="configuration"><span class="section-number-3">2.1.</span> Configuration</h3>
<p>If you have Nginx installed, you should have either the <code class="verbatim">/etc/nginx/conf.d</code> or <code class="verbatim">/etc/nginx/sites-available</code> directories available to create website configuration files. This tutorial assumes the <code class="verbatim">conf.d</code> structure, but it's essentially the same except using the <code class="verbatim">sites-available</code> structure requires you to symlink your files into the <code class="verbatim">sites-enabled</code> directory.</p>
<p>Let's start by creating the website configuration file.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> nano /etc/nginx/conf.d/transmission.conf</span></span></code></pre>
<p>Within the file, you will need a configuration similar to the code below. Note that this uses SSL and requires a valid TLS/SSL certificate. You can use <a href="https://letsencrypt.org/">Let's Encrypt</a> if you don't have a certificate yet.</p>
<pre><code class="language-conf">server {
	listen                  443 ssl;
	listen                  [::]:443 ssl;
	http2			on;
	server_name             transmission.example.com;

	# SSL
	ssl_certificate         /etc/letsencrypt/live/example.com/fullchain.pem;
	ssl_certificate_key     /etc/letsencrypt/live/example.com/privkey.pem;
	ssl_trusted_certificate /etc/letsencrypt/live/example.com/chain.pem;

    # reverse proxy
	location / {
		set $upstream_transmission http://localhost:9091;
		proxy_pass $upstream_transmission;
		proxy_pass_header X-Transmission-Session-Id;
	}
}

# HTTP redirect
server {
	listen      80;
	listen      [::]:80;
	server_name transmission.example.com;

	if ($host ~ ^[^.]+\.example\.com) {
		return 301 https://$host$request_uri;
	}
}</code></pre>
<p>Once you've saved the configuration file, restart the Nginx web server to enable the remote access connection.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> systemctl restart nginx.service</span></span></code></pre>
<p>At this point, Transmission should now be available at <code class="verbatim">transmission.example.com</code>, same as it's available on the LAN.</p>
<blockquote>
<p>Pro Tip: If you dislike something about the website UI, you can edit the website's files in the <code class="verbatim">/usr/share/transmission/public_html/</code> directory. You can modify the HTML, CSS, and JS files in this directory.</p>
</blockquote>
]]></description>
    </item>
    <item>
      <title>Prometheus and Grafana Cloud for Server Monitoring</title>
      <link>https://cleberg.net/blog/prometheus-grafana-cloud.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/prometheus-grafana-cloud.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Fri, 20 Sep 2024 00:00:00 +0000</pubDate>
      <category>linux</category>
      <category>self-hosting</category>
      <description><![CDATA[<p>This tutorial will guide you through the process of:</p>
<ol>
<li>Configuring a free Grafana cloud account.</li>
<li>Installing Prometheus to store metrics.</li>
<li>Installing Node Exporter to export machine metrics for Prometheus.</li>
<li>Installing Nginx Exporter to export Nginx metrics for Prometheus.</li>
<li>Visualizing data in Grafana dashboards.</li>
<li>Configure alerts based on Grafana metrics.</li>
</ol>
<h2 id="grafana-cloud"><span class="section-number-2">1.</span> Grafana Cloud</h2>
<p>To get started, visit the <a href="https://grafana.com/auth/sign-up/create-user">Grafana website</a> and create a free account.</p>
<h3 id="prometheus-data-source"><span class="section-number-3">1.1.</span> Prometheus Data Source</h3>
<p>By default, a Prometheus data source should exist in your data sources page (<code class="verbatim">$yourOrg.grafana.net/connections/datasources</code>). If not, add a new data source using the Prometheus type.</p>
<p>Once you have a valid Prometheus data source, open the data source and note the following items:</p>
<table>
<thead>
<tr><th>Data</th><th>Example</th></tr>
</thead>
<tbody>
<tr><td>Prometheus Server URL</td><td><a href="https://prometheus-prod-13-prod-us-east-0.grafana.net/api/prom/push">https://prometheus-prod-13-prod-us-east-0.grafana.net/api/prom/push</a></td></tr>
<tr><td>User</td><td>1234567</td></tr>
<tr><td>Password</td><td>configured</td></tr>
</tbody>
</table>
<h3 id="cloud-access-policy-token"><span class="section-number-3">1.2.</span> Cloud Access Policy Token</h3>
<p>Now let's create an access token in Grafana. Navigate to the Administration &gt; Users and Access &gt; Cloud Access Policies page and create an access policy.</p>
<p>The <code class="verbatim">metrics &gt; write</code> scope must be enabled within the access policy you choose.</p>
<p>Once you have an access policy with the correct scope, click the Add Token button and be sure to copy and save the token since it will disappear once the modal window is closed.</p>
<h3 id="dashboards"><span class="section-number-3">1.3.</span> Dashboards</h3>
<p>Finally, let's create a couple dashboards so that we can easily explore the data that we will be importing from the server.</p>
<p>I recommend importing the following dashboards:</p>
<ul>
<li><a href="https://grafana.com/grafana/dashboards/1860-node-exporter-full/">Node Exporter Full</a></li>
<li><a href="https://github.com/nginxinc/nginx-prometheus-exporter/blob/main/grafana">nginx-prometheus-exporter</a></li>
<li>Prometheus 2.0 Stats</li>
</ul>
<p>Refer to the bottom of the post for dashboard screenshots!</p>
<h2 id="docker"><span class="section-number-2">2.</span> Docker</h2>
<p>On the machine that you want to observe, make sure Docker and Docker Compose are installed. This tutorial will be using Docker Compose to create a group of containers that will work together to send metrics to Grafana.</p>
<p>Let's start by creating a working directory.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">mkdir</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/prometheus</span> <span class="keyword operator logical and shell">&amp;&amp;</span> <span class="punctuation separator continuation line shell">\
</span><span class="meta function-call shell"><span class="support function cd shell">cd</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/prometheus</span>    <span class="keyword operator logical and shell">&amp;&amp;</span> <span class="punctuation separator continuation line shell">\
</span><span class="meta function-call shell"><span class="variable function shell">nano</span></span><span class="meta function-call arguments shell"> compose.yml</span></span></code></pre>
<p>Within the <code class="verbatim">compose.yml</code> file, let's paste the following:</p>
<pre><code class="language-yaml highlight"><span class="source yaml"><span class="comment line number-sign yaml"><span class="punctuation definition comment line number-sign yaml">#</span> compose.yml
</span>
<span class="string unquoted plain out yaml"><span class="entity name tag yaml">networks</span></span><span class="punctuation separator key-value mapping yaml">:</span>
  <span class="string unquoted plain out yaml"><span class="entity name tag yaml">monitoring</span></span><span class="punctuation separator key-value mapping yaml">:</span>
    <span class="string unquoted plain out yaml"><span class="entity name tag yaml">driver</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string unquoted plain out yaml">bridge</span>

<span class="string unquoted plain out yaml"><span class="entity name tag yaml">volumes</span></span><span class="punctuation separator key-value mapping yaml">:</span>
  <span class="string unquoted plain out yaml"><span class="entity name tag yaml">prometheus_data</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="meta flow-mapping yaml"><span class="punctuation definition mapping begin yaml">{</span><span class="punctuation definition mapping end yaml">}</span></span>

<span class="string unquoted plain out yaml"><span class="entity name tag yaml">services</span></span><span class="punctuation separator key-value mapping yaml">:</span>
  <span class="string unquoted plain out yaml"><span class="entity name tag yaml">nginx-exporter</span></span><span class="punctuation separator key-value mapping yaml">:</span>
    <span class="string unquoted plain out yaml"><span class="entity name tag yaml">image</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string unquoted plain out yaml">nginx/nginx-prometheus-exporter</span>
    <span class="string unquoted plain out yaml"><span class="entity name tag yaml">container_name</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string unquoted plain out yaml">nginx-exporter</span>
    <span class="string unquoted plain out yaml"><span class="entity name tag yaml">restart</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string unquoted plain out yaml">unless-stopped</span>
    <span class="string unquoted plain out yaml"><span class="entity name tag yaml">command</span></span><span class="punctuation separator key-value mapping yaml">:</span>
      <span class="punctuation definition block sequence item yaml">-</span> <span class="string quoted single yaml"><span class="punctuation definition string begin yaml">&#39;</span>--nginx.scrape-uri=http://host.docker.internal:8080/stub_status<span class="punctuation definition string end yaml">&#39;</span></span>
    <span class="string unquoted plain out yaml"><span class="entity name tag yaml">expose</span></span><span class="punctuation separator key-value mapping yaml">:</span>
      <span class="punctuation definition block sequence item yaml">-</span> <span class="constant numeric integer yaml">9113</span>
    <span class="string unquoted plain out yaml"><span class="entity name tag yaml">networks</span></span><span class="punctuation separator key-value mapping yaml">:</span>
      <span class="punctuation definition block sequence item yaml">-</span> <span class="string unquoted plain out yaml">monitoring</span>
    <span class="string unquoted plain out yaml"><span class="entity name tag yaml">extra_hosts</span></span><span class="punctuation separator key-value mapping yaml">:</span>
      <span class="punctuation definition block sequence item yaml">-</span> <span class="string unquoted plain out yaml">host.docker.internal:host-gateway</span>

  <span class="string unquoted plain out yaml"><span class="entity name tag yaml">node-exporter</span></span><span class="punctuation separator key-value mapping yaml">:</span>
    <span class="string unquoted plain out yaml"><span class="entity name tag yaml">image</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string unquoted plain out yaml">prom/node-exporter:latest</span>
    <span class="string unquoted plain out yaml"><span class="entity name tag yaml">container_name</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string unquoted plain out yaml">node-exporter</span>
    <span class="string unquoted plain out yaml"><span class="entity name tag yaml">restart</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string unquoted plain out yaml">unless-stopped</span>
    <span class="string unquoted plain out yaml"><span class="entity name tag yaml">volumes</span></span><span class="punctuation separator key-value mapping yaml">:</span>
      <span class="punctuation definition block sequence item yaml">-</span> <span class="string unquoted plain out yaml">/proc:/host/proc:ro</span>
      <span class="punctuation definition block sequence item yaml">-</span> <span class="string unquoted plain out yaml">/sys:/host/sys:ro</span>
      <span class="punctuation definition block sequence item yaml">-</span> <span class="string unquoted plain out yaml">/:/rootfs:ro</span>
    <span class="string unquoted plain out yaml"><span class="entity name tag yaml">command</span></span><span class="punctuation separator key-value mapping yaml">:</span>
      <span class="punctuation definition block sequence item yaml">-</span> <span class="string quoted single yaml"><span class="punctuation definition string begin yaml">&#39;</span>--path.procfs=/host/proc<span class="punctuation definition string end yaml">&#39;</span></span>
      <span class="punctuation definition block sequence item yaml">-</span> <span class="string quoted single yaml"><span class="punctuation definition string begin yaml">&#39;</span>--path.rootfs=/rootfs<span class="punctuation definition string end yaml">&#39;</span></span>
      <span class="punctuation definition block sequence item yaml">-</span> <span class="string quoted single yaml"><span class="punctuation definition string begin yaml">&#39;</span>--path.sysfs=/host/sys<span class="punctuation definition string end yaml">&#39;</span></span>
      <span class="punctuation definition block sequence item yaml">-</span> <span class="string quoted single yaml"><span class="punctuation definition string begin yaml">&#39;</span>--collector.filesystem.mount-points-exclude=^/(sys|proc|dev|host|etc)($$|/)<span class="punctuation definition string end yaml">&#39;</span></span>
    <span class="string unquoted plain out yaml"><span class="entity name tag yaml">expose</span></span><span class="punctuation separator key-value mapping yaml">:</span>
      <span class="punctuation definition block sequence item yaml">-</span> <span class="constant numeric integer yaml">9100</span>
    <span class="string unquoted plain out yaml"><span class="entity name tag yaml">networks</span></span><span class="punctuation separator key-value mapping yaml">:</span>
      <span class="punctuation definition block sequence item yaml">-</span> <span class="string unquoted plain out yaml">monitoring</span>

  <span class="string unquoted plain out yaml"><span class="entity name tag yaml">prometheus</span></span><span class="punctuation separator key-value mapping yaml">:</span>
    <span class="string unquoted plain out yaml"><span class="entity name tag yaml">image</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string unquoted plain out yaml">prom/prometheus:latest</span>
    <span class="string unquoted plain out yaml"><span class="entity name tag yaml">container_name</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string unquoted plain out yaml">prometheus</span>
    <span class="string unquoted plain out yaml"><span class="entity name tag yaml">restart</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string unquoted plain out yaml">unless-stopped</span>
    <span class="string unquoted plain out yaml"><span class="entity name tag yaml">volumes</span></span><span class="punctuation separator key-value mapping yaml">:</span>
      <span class="punctuation definition block sequence item yaml">-</span> <span class="string unquoted plain out yaml">./prometheus.yml:/etc/prometheus/prometheus.yml</span>
      <span class="punctuation definition block sequence item yaml">-</span> <span class="string unquoted plain out yaml">prometheus_data:/prometheus</span>
    <span class="string unquoted plain out yaml"><span class="entity name tag yaml">command</span></span><span class="punctuation separator key-value mapping yaml">:</span>
      <span class="punctuation definition block sequence item yaml">-</span> <span class="string quoted single yaml"><span class="punctuation definition string begin yaml">&#39;</span>--config.file=/etc/prometheus/prometheus.yml<span class="punctuation definition string end yaml">&#39;</span></span>
      <span class="punctuation definition block sequence item yaml">-</span> <span class="string quoted single yaml"><span class="punctuation definition string begin yaml">&#39;</span>--storage.tsdb.path=/prometheus<span class="punctuation definition string end yaml">&#39;</span></span>
      <span class="punctuation definition block sequence item yaml">-</span> <span class="string quoted single yaml"><span class="punctuation definition string begin yaml">&#39;</span>--web.console.libraries=/etc/prometheus/console_libraries<span class="punctuation definition string end yaml">&#39;</span></span>
      <span class="punctuation definition block sequence item yaml">-</span> <span class="string quoted single yaml"><span class="punctuation definition string begin yaml">&#39;</span>--web.console.templates=/etc/prometheus/consoles<span class="punctuation definition string end yaml">&#39;</span></span>
      <span class="punctuation definition block sequence item yaml">-</span> <span class="string quoted single yaml"><span class="punctuation definition string begin yaml">&#39;</span>--web.enable-lifecycle<span class="punctuation definition string end yaml">&#39;</span></span>
    <span class="string unquoted plain out yaml"><span class="entity name tag yaml">expose</span></span><span class="punctuation separator key-value mapping yaml">:</span>
      <span class="punctuation definition block sequence item yaml">-</span> <span class="constant numeric integer yaml">9090</span>
    <span class="string unquoted plain out yaml"><span class="entity name tag yaml">networks</span></span><span class="punctuation separator key-value mapping yaml">:</span>
      <span class="punctuation definition block sequence item yaml">-</span> <span class="string unquoted plain out yaml">monitoring</span></span></code></pre>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> docker compose up<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>d</span></span></span></code></pre>
<blockquote>
<p>I'm not sure if it made a difference but I also whitelisted port 8080 on my local firewall with <code class="verbatim">sudo ufw allow 8080</code>.</p>
</blockquote>
<p>Next, let's create a <code class="verbatim">prometheus.yml</code> configuration file.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">nano</span></span><span class="meta function-call arguments shell"> prometheus.yml</span></span></code></pre>
<pre><code class="language-yaml highlight"><span class="source yaml"><span class="comment line number-sign yaml"><span class="punctuation definition comment line number-sign yaml">#</span> prometheus.yml
</span>
<span class="string unquoted plain out yaml"><span class="entity name tag yaml">global</span></span><span class="punctuation separator key-value mapping yaml">:</span>
  <span class="string unquoted plain out yaml"><span class="entity name tag yaml">scrape_interval</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string unquoted plain out yaml">1m</span>

<span class="string unquoted plain out yaml"><span class="entity name tag yaml">scrape_configs</span></span><span class="punctuation separator key-value mapping yaml">:</span>
  <span class="punctuation definition block sequence item yaml">-</span> <span class="string unquoted plain out yaml"><span class="entity name tag yaml">job_name</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string quoted single yaml"><span class="punctuation definition string begin yaml">&#39;</span>prometheus<span class="punctuation definition string end yaml">&#39;</span></span>
    <span class="string unquoted plain out yaml"><span class="entity name tag yaml">scrape_interval</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string unquoted plain out yaml">1m</span>
    <span class="string unquoted plain out yaml"><span class="entity name tag yaml">static_configs</span></span><span class="punctuation separator key-value mapping yaml">:</span>
      <span class="punctuation definition block sequence item yaml">-</span> <span class="string unquoted plain out yaml"><span class="entity name tag yaml">targets</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="meta flow-sequence yaml"><span class="punctuation definition sequence begin yaml">[</span><span class="string quoted single yaml"><span class="punctuation definition string begin yaml">&#39;</span>localhost:9090<span class="punctuation definition string end yaml">&#39;</span></span><span class="punctuation definition sequence end yaml">]</span></span>

  <span class="punctuation definition block sequence item yaml">-</span> <span class="string unquoted plain out yaml"><span class="entity name tag yaml">job_name</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string quoted single yaml"><span class="punctuation definition string begin yaml">&#39;</span>node<span class="punctuation definition string end yaml">&#39;</span></span>
    <span class="string unquoted plain out yaml"><span class="entity name tag yaml">static_configs</span></span><span class="punctuation separator key-value mapping yaml">:</span>
      <span class="punctuation definition block sequence item yaml">-</span> <span class="string unquoted plain out yaml"><span class="entity name tag yaml">targets</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="meta flow-sequence yaml"><span class="punctuation definition sequence begin yaml">[</span><span class="string quoted single yaml"><span class="punctuation definition string begin yaml">&#39;</span>node-exporter:9100<span class="punctuation definition string end yaml">&#39;</span></span><span class="punctuation definition sequence end yaml">]</span></span>

  <span class="punctuation definition block sequence item yaml">-</span> <span class="string unquoted plain out yaml"><span class="entity name tag yaml">job_name</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string quoted single yaml"><span class="punctuation definition string begin yaml">&#39;</span>nginx<span class="punctuation definition string end yaml">&#39;</span></span>
    <span class="string unquoted plain out yaml"><span class="entity name tag yaml">scrape_interval</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string unquoted plain out yaml">5s</span>
    <span class="string unquoted plain out yaml"><span class="entity name tag yaml">static_configs</span></span><span class="punctuation separator key-value mapping yaml">:</span>
      <span class="punctuation definition block sequence item yaml">-</span> <span class="string unquoted plain out yaml"><span class="entity name tag yaml">targets</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="meta flow-sequence yaml"><span class="punctuation definition sequence begin yaml">[</span><span class="string quoted single yaml"><span class="punctuation definition string begin yaml">&#39;</span>nginx-exporter:9113<span class="punctuation definition string end yaml">&#39;</span></span><span class="punctuation definition sequence end yaml">]</span></span>

<span class="string unquoted plain out yaml"><span class="entity name tag yaml">remote_write</span></span><span class="punctuation separator key-value mapping yaml">:</span>
  <span class="punctuation definition block sequence item yaml">-</span> <span class="string unquoted plain out yaml"><span class="entity name tag yaml">url</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string quoted single yaml"><span class="punctuation definition string begin yaml">&#39;</span>https://prometheus-prod-13-prod-us-east-0.grafana.net/api/prom/push<span class="punctuation definition string end yaml">&#39;</span></span>
    <span class="string unquoted plain out yaml"><span class="entity name tag yaml">basic_auth</span></span><span class="punctuation separator key-value mapping yaml">:</span>
      <span class="string unquoted plain out yaml"><span class="entity name tag yaml">username</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string quoted single yaml"><span class="punctuation definition string begin yaml">&#39;</span>prometheus-grafana-username<span class="punctuation definition string end yaml">&#39;</span></span>
      <span class="string unquoted plain out yaml"><span class="entity name tag yaml">password</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string quoted single yaml"><span class="punctuation definition string begin yaml">&#39;</span>access-policy-token<span class="punctuation definition string end yaml">&#39;</span></span></span></code></pre>
<h3 id="nginx"><span class="section-number-3">2.1.</span> Nginx</h3>
<p>To enable to the Nginx statistics we need for the nginx-exporter container, we need to modify the Nginx configuration on the host.</p>
<p>More specifically, we need to create a path for the <code class="verbatim">stub_status</code> to be returned when we query port 8080 on our localhost.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> nano /etc/nginx/conf.d/default.conf</span></span></code></pre>
<pre><code class="language-conf">server {
        listen 8080;
        listen [::]:8080;

        location /stub_status {
                stub_status;
        }
}</code></pre>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> systemctl restart nginx.service</span></span></code></pre>
<h3 id="debugging"><span class="section-number-3">2.2.</span> Debugging</h3>
<p>At this point, everything should be running smoothly. If not, here are a few areas to check and see if any obvious errors exist.</p>
<p>Nginx: Curl the stub<sub>status</sub> from the Nginx web server on the host machine to see if Nginx and stub<sub>status</sub> are working properly.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">curl</span></span><span class="meta function-call arguments shell"> http://127.0.0.1:8080/stub_status</span>

<span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> EXPECTED RESULTS:</span><span class="comment line number-sign shell">
</span><span class="meta function-call shell"><span class="variable function shell">Active</span></span><span class="meta function-call arguments shell"> connections: 101</span>
<span class="meta function-call shell"><span class="variable function shell">server</span></span><span class="meta function-call arguments shell"> accepts handled requests</span>
 <span class="meta function-call shell"><span class="variable function shell">7510</span></span><span class="meta function-call arguments shell"> 7510 9654</span>
<span class="meta function-call shell"><span class="variable function shell">Reading:</span></span><span class="meta function-call arguments shell"> 0 Writing: 1 Waiting: 93</span></span></code></pre>
<p>Nginx-Exporter: Curl the exported Nginx metrics.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> Figure out the IP address of the Docker container</span><span class="comment line number-sign shell">
</span><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> docker network inspect grafana_monitoring</span>

<span class="meta function-call shell"><span class="variable function shell">...</span></span>
<span class="meta function-call shell"><span class="variable function shell"><span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>Name<span class="punctuation definition string end shell">&quot;</span></span>:</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>nginx-exporter<span class="punctuation definition string end shell">&quot;</span></span>,</span>
<span class="meta function-call shell"><span class="variable function shell"><span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>EndpointID<span class="punctuation definition string end shell">&quot;</span></span>:</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>ef999a53eb9e0753199a680f8d78db7c2a8d5f442626df0b1bb945f03b73dcdd<span class="punctuation definition string end shell">&quot;</span></span>,</span>
<span class="meta function-call shell"><span class="variable function shell"><span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>MacAddress<span class="punctuation definition string end shell">&quot;</span></span>:</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>02:42:c0:a8:40:02<span class="punctuation definition string end shell">&quot;</span></span>,</span>
<span class="meta function-call shell"><span class="variable function shell"><span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>IPv4Address<span class="punctuation definition string end shell">&quot;</span></span>:</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>192.168.64.2/20<span class="punctuation definition string end shell">&quot;</span></span>,</span>
<span class="meta function-call shell"><span class="variable function shell">...</span></span>

<span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> Curl the exported Nginx metrics</span><span class="comment line number-sign shell">
</span><span class="meta function-call shell"><span class="variable function shell">curl</span></span><span class="meta function-call arguments shell"> 192.168.64.2:9113/metrics</span>

<span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> EXPECTED RESULTS:</span><span class="comment line number-sign shell">
</span><span class="meta function-call shell"><span class="variable function shell">...</span></span>
<span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> HELP go_gc_duration_seconds A summary of the pause duration of garbage collection cycles.</span><span class="comment line number-sign shell">
</span><span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> TYPE go_gc_duration_seconds summary</span><span class="comment line number-sign shell">
</span><span class="meta function-call shell"><span class="variable function shell">go_gc_duration_seconds{quantile</span></span><span class="meta function-call arguments shell">=<span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>0<span class="punctuation definition string end shell">&quot;</span></span></span><span class="meta function-call shell"></span><span class="meta post-cmd shell">}</span> <span class="meta function-call shell"><span class="variable function shell">2.9927e-05</span></span>
<span class="meta function-call shell"><span class="variable function shell">go_gc_duration_seconds{quantile</span></span><span class="meta function-call arguments shell">=<span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>0.25<span class="punctuation definition string end shell">&quot;</span></span></span><span class="meta function-call shell"></span><span class="meta post-cmd shell">}</span> <span class="meta function-call shell"><span class="variable function shell">4.24e-05</span></span>
<span class="meta function-call shell"><span class="variable function shell">go_gc_duration_seconds{quantile</span></span><span class="meta function-call arguments shell">=<span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>0.5<span class="punctuation definition string end shell">&quot;</span></span></span><span class="meta function-call shell"></span><span class="meta post-cmd shell">}</span> <span class="meta function-call shell"><span class="variable function shell">4.8531e-05</span></span>
<span class="meta function-call shell"><span class="variable function shell">...</span></span></span></code></pre>
<p>Node-Exporter: Curl the exporter node machine metrics.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> Curl the exported Node metrics</span><span class="comment line number-sign shell">
</span><span class="meta function-call shell"><span class="variable function shell">curl</span></span><span class="meta function-call arguments shell"> 192.168.64.3:9100/metrics</span>

<span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> EXPECTED RESULTS:</span><span class="comment line number-sign shell">
</span><span class="meta function-call shell"><span class="variable function shell">...</span></span>
<span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> HELP promhttp_metric_handler_requests_total Total number of scrapes by HTTP status code.</span><span class="comment line number-sign shell">
</span><span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> TYPE promhttp_metric_handler_requests_total counter</span><span class="comment line number-sign shell">
</span><span class="meta function-call shell"><span class="variable function shell">promhttp_metric_handler_requests_total{code</span></span><span class="meta function-call arguments shell">=<span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>200<span class="punctuation definition string end shell">&quot;</span></span></span><span class="meta function-call shell"></span><span class="meta post-cmd shell">}</span> <span class="meta function-call shell"><span class="variable function shell">47</span></span>
<span class="meta function-call shell"><span class="variable function shell">promhttp_metric_handler_requests_total{code</span></span><span class="meta function-call arguments shell">=<span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>500<span class="punctuation definition string end shell">&quot;</span></span></span><span class="meta function-call shell"></span><span class="meta post-cmd shell">}</span> <span class="meta function-call shell"><span class="variable function shell">0</span></span>
<span class="meta function-call shell"><span class="variable function shell">promhttp_metric_handler_requests_total{code</span></span><span class="meta function-call arguments shell">=<span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>503<span class="punctuation definition string end shell">&quot;</span></span></span><span class="meta function-call shell"></span><span class="meta post-cmd shell">}</span> <span class="meta function-call shell"><span class="variable function shell">0</span></span>
<span class="meta function-call shell"><span class="variable function shell">...</span></span></span></code></pre>
<p>Grafana: Open the Explore panel and look to see if any metrics are coming through the Prometheus data source. If not, something on the machine is preventing data from flowing through.</p>
<h2 id="alerts-irm"><span class="section-number-2">3.</span> Alerts &amp; IRM</h2>
<p>Now that we have our data connected and visualized, we can define alerting rules and determine what Grafana should do when an alert is triggered.</p>
<h3 id="oncall"><span class="section-number-3">3.1.</span> OnCall</h3>
<figure><img src="https://img.cleberg.net/blog/20240920-prometheus-grafana-cloud/oncall.webp" alt="View of the Grafana OnCall dashboard with metrics."><figcaption><span class="figure-number">Figure 1: </span>OnCall</figcaption></figure>
<p>Within the Alerts &amp; IRM section of Grafana (<code class="verbatim">/alerts-and-incidents</code>), open the Users page.</p>
<p>The Users page allows you to configure user connections such as:</p>
<ul>
<li>Mobile App</li>
<li>Slack</li>
<li>Telegram</li>
<li>MS Teams</li>
<li>iCal</li>
<li>Google Calendar</li>
</ul>
<p>In addition to the connections of each user, you can specify how each user or team is alerted for Default Notifications and Important Notifications.</p>
<p>Finally, you can access the Schedules page within the OnCall module to schedule users and teams to be on call for specific date and time ranges. For my purposes, I put myself on-call 24/7 so that I receive all alerts.</p>
<figure><img src="https://img.cleberg.net/blog/20240920-prometheus-grafana-cloud/irm_user_info.webp" alt="View of the grafanafd88 user with notification preferences."><figcaption><span class="figure-number">Figure 2: </span>User Information</figcaption></figure>
<h3 id="alerting"><span class="section-number-3">3.2.</span> Alerting</h3>
<figure><img src="https://img.cleberg.net/blog/20240920-prometheus-grafana-cloud/alerting_insights.webp" alt="A dashboard with the current grafana-managed alert rules."><figcaption><span class="figure-number">Figure 3: </span>Alerting Insights</figcaption></figure>
<p>Now that we have defined users and team associated with an on-call schedule and configured to receive the proper alerts, let's define a rule that will generate alerts.</p>
<p>Within the Alerting section of the Alerts &amp; IRM module, you can create alert rules, contact points, and notification policies.</p>
<p>Let's start by opening the Alert Rules page and click the New Alert Rule button.</p>
<p>As shown in the image below, we will create an alert for high CPU temperature by querying the <code class="verbatim">node_hwmon_temp_celsius</code> metric from our Prometheus data source.</p>
<p>Next, we will set the threshold to be anything above 50 (degrees Celsius). Finally, we will tell Grafana to evaluate this every 1 minute via our Default evaluation group. This is connected to our Grafana email, but can be associated with any notification policy.</p>
<figure><img src="https://img.cleberg.net/blog/20240920-prometheus-grafana-cloud/new_alert.webp" alt="All available seetings when creating a new alert."><figcaption><span class="figure-number">Figure 4: </span>New Alert Rule</figcaption></figure>
<p>When the alert fires, it will generate an email (or whatever notification policy you assigned) and will look something like the following image.</p>
<figure><img src="https://img.cleberg.net/blog/20240920-prometheus-grafana-cloud/email_alert.webp" alt="High CPU Temps alert is firing."><figcaption><span class="figure-number">Figure 5: </span>Alerting Example</figcaption></figure>
<h3 id="dashboards"><span class="section-number-3">3.3.</span> Dashboards</h3>
<p>As promised above, here are some dashboard screenshots based on the configurations above.</p>
<figure><img src="https://img.cleberg.net/blog/20240920-prometheus-grafana-cloud/dashboard_nginx.webp" alt="Updated dashboard based on the new alert created above."><figcaption><span class="figure-number">Figure 6: </span>Nginx Dashboard</figcaption></figure>
<figure><img src="https://img.cleberg.net/blog/20240920-prometheus-grafana-cloud/dashboard_node.webp" alt="Metrics of server nodes, including CPU, network, and memory."><figcaption><span class="figure-number">Figure 7: </span>Node Dashboard</figcaption></figure>
<figure><img src="https://img.cleberg.net/blog/20240920-prometheus-grafana-cloud/dashboard_oncall.webp" alt="Full OnCall dashboard with metrics for alerts, mean time to respond, and more."><figcaption><span class="figure-number">Figure 8: </span>OnCall Dashboard</figcaption></figure>
<figure><img src="https://img.cleberg.net/blog/20240920-prometheus-grafana-cloud/dashboard_prometheus.webp" alt="Dashboard showing Prometheus metrics, including scrape duration, head shunks, reload count, and more."><figcaption><span class="figure-number">Figure 9: </span>Prometheus Dashboard</figcaption></figure>
]]></description>
    </item>
    <item>
      <title>Email Sentiment Analysis with n8n</title>
      <link>https://cleberg.net/blog/n8n-sentiment-analysis.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/n8n-sentiment-analysis.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Sun, 25 Aug 2024 00:00:00 +0000</pubDate>
      <category>self-hosting</category>
      <description><![CDATA[<h2 id="n8n"><span class="section-number-2">1.</span> n8n</h2>
<p>This guide will show you how to self-host <a href="https://n8n.io/">n8n</a>, a workflow automation platform, and use it to create a workflow that automatically analyzes the sentiment of all incoming emails on your account.</p>
<p>This is a completely free process that only requires that you have access to (1) an email account with IMAP/SMTP options and (2) a computer or machine where you can install and use Docker.</p>
<h3 id="installation"><span class="section-number-3">1.1.</span> Installation</h3>
<p>To get started, read the <a href="https://github.com/n8n-io/self-hosted-ai-starter-kit">self-hosted-ai-starter-kit</a> project README or simply clone the repository and set it up with Docker using the command below.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">git</span></span><span class="meta function-call arguments shell"> clone https://github.com/n8n-io/self-hosted-ai-starter-kit.git</span>
<span class="meta function-call shell"><span class="support function cd shell">cd</span></span><span class="meta function-call arguments shell"> self-hosted-ai-starter-kit</span>
<span class="meta function-call shell"><span class="variable function shell">docker</span></span><span class="meta function-call arguments shell"> compose<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> --</span>profile</span> cpu up</span></span></code></pre>
<p>This will clone the repository, start the stack of Docker containers with <code class="verbatim">compose</code>, and make the n8n web page available at <a href="https://localhost:5678">https://localhost:5678</a>. The first run will ask you to configure the administrator account for n8n.</p>
<h3 id="reverse-proxy"><span class="section-number-3">1.2.</span> Reverse Proxy</h3>
<p>If you want to use n8n from a public domain name, you'll need to configure a reverse proxy. I use Nginx on my server for reverse proxies. Nginx configuration locations and practices vary by distribution, but the following commands will show you my general reverse proxy configuration.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="support function cd shell">cd</span></span><span class="meta function-call arguments shell"> /etc/nginx/conf.d</span>
<span class="meta function-call shell"><span class="variable function shell">nano</span></span><span class="meta function-call arguments shell"> n8n.conf</span></span></code></pre>
<pre><code class="language-conf">server {
	listen                  443 ssl;
	listen                  [::]:443 ssl;
	http2			on;
	server_name             n8n.example.com;

	# SSL
	ssl_certificate         /etc/letsencrypt/live/example.com/fullchain.pem;
	ssl_certificate_key     /etc/letsencrypt/live/example.com/privkey.pem;
	ssl_trusted_certificate /etc/letsencrypt/live/example.com/chain.pem;

	# reverse proxy
	location / {
		set $upstream_n8n http://127.0.0.1:5678;

        proxy_set_header Remote-User $user;
		proxy_set_header Remote-Email $email;
		proxy_set_header Remote-Groups $groups;

		client_body_buffer_size 128k;
		proxy_next_upstream error timeout invalid_header http_500 http_502 http_503;

		send_timeout 5m;
		proxy_read_timeout 360;
		proxy_send_timeout 360;
		proxy_connect_timeout 360;

		proxy_set_header Host $host;
		proxy_set_header Upgrade $http_upgrade;
		proxy_set_header Connection upgrade;
		proxy_set_header Accept-Encoding gzip;
		proxy_set_header X-Real-IP $remote_addr;
		proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
		proxy_set_header X-Forwarded-Proto $scheme;
		proxy_set_header X-Forwarded-Host $http_host;
		proxy_set_header X-Forwarded-Uri $request_uri;
		proxy_set_header X-Forwarded-Ssl on;
		proxy_redirect  http://  $scheme://;
		proxy_http_version 1.1;
		proxy_set_header Connection "";
		proxy_cache_bypass $cookie_session;
		proxy_no_cache $cookie_session;
		proxy_buffers 64 256k;
    }

# HTTP redirect
server {
	listen      80;
	listen      [::]:80;
	server_name n8n.example.com;
	include     custom.d/letsencrypt.conf;

	if ($host ~ ^[^.]+\.example\.com$) {
		return 301 https://$host$request_uri;
	}
}</code></pre>
<p>Simply restart Nginx to ensure the new configuration is in-effect.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> systemctl restart nginx.service</span></span></code></pre>
<h3 id="workflow-configuration"><span class="section-number-3">1.3.</span> Workflow Configuration</h3>
<p>You can open the included workflow at <a href="http://localhost:5678/workflow/srOnR8PAY3u4RSwb">http://localhost:5678/workflow/srOnR8PAY3u4RSwb</a> or simply open the web interface and create a new configuration.</p>
<figure><img src="https://img.cleberg.net/blog/20240825-n8n-sentiment-analysis/workflow.webp" alt="A canvas view of the worklow, showing an email trigger, if statement, sentiment analysis via Ollama, and send email action."><figcaption><span class="figure-number">Figure 1: </span>n8n Workflow</figcaption></figure>
<p>This workflow contains the following nodes:</p>
<ol>
<li>Email Trigger (IMAP)<ul>
<li>Create an IMAP credential with your email's IMAP settings to allow n8n to monitor for new emails.</li>
</ul>
</li>
<li>If<ul>
<li>Check <code class="verbatim">{{ $json.subject }}</code> to see if it <code class="verbatim">contains</code> "n8n Sentiment Analysis" to ensure we don't re-check our own emails.</li>
</ul>
</li>
<li>Sentiment Analysis<ul>
<li>Analyze the <code class="verbatim">{{ $json.textPlain }}</code> input coming from each email.</li>
<li>Ensure you have <code class="verbatim">Include Detailed Results</code> enabled so that we can access the confidence and strength variables.</li>
</ul>
</li>
<li>Ollama Chat Model<ul>
<li>The Docker stack we used includes Ollama and Llama3, which provide the easiest way to test this workflow.</li>
</ul>
</li>
<li>Send Email<ul>
<li>Create an SMTP credential to allow n8n to send emails.</li>
<li>Subject: <code class="verbatim">n8n Sentiment Analysis: {{ $json.sentimentAnalysis.category }}</code></li>
<li>Email Format: <code class="verbatim">Text</code></li>
<li>Text (Expression): This can contain anything you want, but be sure to include the variables <code class="verbatim">{{ $json.sentimentAnalysis.category }}</code>, <code class="verbatim">{{ $json.sentimentAnalysis.strength }}</code>, and <code class="verbatim">{{ $json.sentimentAnalysis.confidence }}</code>.</li>
<li>In the additional options, I enabled the <code class="verbatim">Append n8n Attribution</code> option in the screenshots below.</li>
</ul>
</li>
</ol>
<h3 id="testing"><span class="section-number-3">1.4.</span> Testing</h3>
<p>You can use the <code class="verbatim">Test Workflow</code> button at the bottom of the canvas area to test the workflow. This relies on receiving new messages in your inbox, so be sure to send yourself a test email!</p>
<h3 id="results"><span class="section-number-3">1.5.</span> Results</h3>
<p>After testing each step noted above, n8n provided the results below - it works!</p>
<figure><img src="https://img.cleberg.net/blog/20240825-n8n-sentiment-analysis/positive_results.webp" alt="Positive&quot;."><figcaption><span class="figure-number">Figure 2: </span>Positive Results</figcaption></figure>
<figure><img src="https://img.cleberg.net/blog/20240825-n8n-sentiment-analysis/negative_results.webp" alt="Negative&quot;."><figcaption><span class="figure-number">Figure 3: </span>Negative Results</figcaption></figure>
<p>While this isn't anything earth-shattering, it does show easy it is to get started with n8n and large language models in a self-hosted environment.</p>
]]></description>
    </item>
    <item>
      <title>Org Mode Features: What I Actually Use</title>
      <link>https://cleberg.net/blog/org-mode-features.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/org-mode-features.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Sun, 11 Aug 2024 00:00:00 +0000</pubDate>
      <category>emacs</category>
      <description><![CDATA[<h2 id="cycling-folding"><span class="section-number-2">1.</span> Cycling (Folding)</h2>
<blockquote>
<p><a href="https://gitbay.org/cmc/cleberg.net/blob/main/content/blog/2024-08-11-org-mode-features.org#L7">View this section</a> in org-mode.</p>
</blockquote>
<p>My absolute top-used feature is <a href="https://orgmode.org/manual/Global-and-local-cycling.html">global and local cycling</a> and it's not even close. Being able to hit <code class="verbatim">S-TAB</code> and collapse all headings when opening a file or needing to see a file's headings is an under appreciated trait.</p>
<h3 id="local-cycling"><span class="section-number-3">1.1.</span> Local Cycling</h3>
<p>When focused on a heading, you can press <code class="verbatim">TAB</code> (<code class="verbatim">org-cycle</code>) to cycle that subtree among the states <code class="verbatim">folded</code>, <code class="verbatim">children</code>, and <code class="verbatim">subtree</code>.</p>
<pre><code class="language-txt highlight"><span class="text plain">,-&gt; FOLDED -&gt; CHILDREN -&gt; SUBTREE --.
&#39;-----------------------------------&#39;</span></code></pre>
<h3 id="global-cycling"><span class="section-number-3">1.2.</span> Global Cycling</h3>
<p>If you're looking to cycle more than one subtree or heading at a time, you can press <code class="verbatim">S-TAB</code> or <code class="verbatim">C-u TAB</code> to cycle the entire buffer among the states <code class="verbatim">overview</code>, <code class="verbatim">contents</code>, and <code class="verbatim">show all</code>.</p>
<pre><code class="language-txt highlight"><span class="text plain">,-&gt; OVERVIEW -&gt; CONTENTS -&gt; SHOW ALL --.
&#39;--------------------------------------&#39;</span></code></pre>
<h3 id="default-views"><span class="section-number-3">1.3.</span> Default Views</h3>
<p>If you need to set a default view for a certain file, you can run <code class="verbatim">C-u C-u TAB</code> to set the <code class="verbatim">org-set-startup-visibility</code>. Alternatively, just put the following at the top of the buffer:</p>
<pre><code class="language-org highlight"><span class="text org"><span class="keyword other keyword org">#+STARTUP:</span><span class="string unquoted org"> overview</span>
<span class="keyword other keyword org">#+STARTUP:</span><span class="string unquoted org"> content</span>
<span class="keyword other keyword org">#+STARTUP:</span><span class="string unquoted org"> showall</span>
<span class="keyword other keyword org">#+STARTUP:</span><span class="string unquoted org"> show2levels</span>
<span class="keyword other keyword org">#+STARTUP:</span><span class="string unquoted org"> show3levels</span>
<span class="keyword other keyword org">#+STARTUP:</span><span class="string unquoted org"> show4levels</span>
<span class="keyword other keyword org">#+STARTUP:</span><span class="string unquoted org"> show5levels</span>
<span class="keyword other keyword org">#+STARTUP:</span><span class="string unquoted org"> showeverything</span></span></code></pre>
<h2 id="lists"><span class="section-number-2">2.</span> <span class="todo TODO">TODO</span> Lists</h2>
<blockquote>
<p><a href="https://gitbay.org/cmc/cleberg.net/blob/main/content/blog/2024-08-11-org-mode-features.org#L55">View this section</a> in org-mode.</p>
</blockquote>
<p>Next up on in this post are <a href="https://orgmode.org/manual/TODO-Items.html">TODO Lists</a>. Being able to combine note taking and reminders was the primary reason I switched to org-mode in the first place.</p>
<p>TODO lists are more than just the Markdown equivalent of <code class="verbatim">- [ ] Task</code>. Instead, you can utilize org-mode's native functionality to dynamically create TODO items, have fast access to TODO states, log progress on tasks, clocking work time, prioritization, breaking down tasks into subtasks, and even using checkbox formatting as well.</p>
<h3 id="prioritizing-tasks"><span class="section-number-3">2.1.</span> Prioritizing Tasks</h3>
<p>One of my favorite ways to separate my tasks are to assign priorities. You can do this by placing a priority cookie into the headline of a TODO item.</p>
<pre><code class="language-org highlight"><span class="text org"><span class="markup heading org"><span class="punctuation definition heading org">***</span> <span class="keyword other todo org">TODO</span> <span class="constant other priority org">[#A]</span> My Task
</span><span class="markup heading org"><span class="punctuation definition heading org">***</span> <span class="keyword other todo org">TODO</span> <span class="constant other priority org">[#C]</span> My Other Task</span></span></code></pre>
<p>You can quickly shift priorities with <code class="verbatim">S-UP</code> and <code class="verbatim">S-DOWN</code>, as well as set the allowed priorities for a buffer with the following syntax:</p>
<pre><code class="language-org highlight"><span class="text org"><span class="keyword other keyword org">#+PRIORITIES:</span><span class="string unquoted org"> A C B</span>
<span class="keyword other keyword org">#+PRIORITIES:</span><span class="string unquoted org"> 1 10 5</span></span></code></pre>
<h3 id="deadlines"><span class="section-number-3">2.2.</span> Deadlines</h3>
<p>Plans can be set per task by settings special keywords with a date. You can set a <code class="verbatim">DEADLINE</code> to note when the task will appear in the agenda or set the <code class="verbatim">SCHEDULED</code> variable to note when you plan to start working on the task.</p>
<pre><code class="language-org highlight"><span class="text org"><span class="markup heading org"><span class="punctuation definition heading org">*</span> <span class="keyword other todo org">TODO</span> My Task
</span>DEADLINE: <span class="constant other timestamp org">&lt;2004-02-29 Sun&gt;</span>

<span class="markup heading org"><span class="punctuation definition heading org">*</span> My Other Task
</span>SCHEDULED: <span class="constant other timestamp org">&lt;2004-12-25 Sat&gt;</span></span></code></pre>
<p>As a side note, I use <a href="https://www.beorgapp.com/">Beorg</a> on iOS to sync and edit my org-mode files on the go. Within this app, I use the <code class="verbatim">SCHEDULED</code> variable by default and rely heavily on that variable to alert me of tasks with iOS native notifications.</p>
<h2 id="time-stamping"><span class="section-number-2">3.</span> Time Stamping</h2>
<blockquote>
<p><a href="https://gitbay.org/cmc/cleberg.net/blob/main/content/blog/2024-08-11-org-mode-features.org#L106">View this section</a> in org-mode.</p>
</blockquote>
<p>Another great feature are the <a href="https://orgmode.org/manual/Dates-and-Times.html">dates and times</a> functionalities within org-mode. Timestamps follow this format in org-mode:</p>
<pre><code class="language-org highlight"><span class="text org"><span class="markup heading org"><span class="punctuation definition heading org">*</span> An active timestamp
</span><span class="constant other timestamp org">&lt;2006-11-01 Wed 19:15&gt;</span>

<span class="markup heading org"><span class="punctuation definition heading org">*</span> An inactive timestamp
</span><span class="constant other timestamp org">[2006-11-01 Wed 19:15&gt;</span>

<span class="markup heading org"><span class="punctuation definition heading org">*</span> Repeated timestamps
</span><span class="constant other timestamp org">&lt;2006-11-01 Wed 19:15 +1m&gt;</span>

<span class="markup heading org"><span class="punctuation definition heading org">*</span> Time range
</span><span class="constant other timestamp org">&lt;2006-11-02 Thu 10:00-12:00&gt;</span>

<span class="markup heading org"><span class="punctuation definition heading org">*</span> Date range
</span><span class="constant other timestamp org">&lt;2004-08-23 Mon&gt;</span>--<span class="constant other timestamp org">&lt;2004-08-26 Thu&gt;</span></span></code></pre>
<p>In addition to the deadlines mentioned above, you can insert timestamps into any marker within the buffer with <code class="verbatim">C-c .</code> for an active timestamp and <code class="verbatim">C-c !</code> for an inactive timestamp. You can read more on <a href="https://orgmode.org/manual/Creating-Timestamps.html">creating timestamps</a> to figure out the different options available when creating timestamps.</p>
<h2 id="tags"><span class="section-number-2">4.</span> Tags</h2>
<blockquote>
<p><a href="https://gitbay.org/cmc/cleberg.net/blob/main/content/blog/2024-08-11-org-mode-features.org#L137">View this section</a> in org-mode.</p>
</blockquote>
<p>Next up are <a href="https://orgmode.org/manual/Tags.html">Tags</a>, which provide a way to document contexts within and across buffers and files.</p>
<p>You can assign tags directly to headlines or at the file level and can contain letters, numbers, underscores, and the <code class="verbatim">@</code> symbol.</p>
<pre><code class="language-org highlight"><span class="text org">,
<span class="markup heading org"><span class="punctuation definition heading org">*</span> Pick fruits off the trees      <span class="entity name tag org">:work:
</span></span><span class="markup heading org"><span class="punctuation definition heading org">**</span> Start with the orange grove   <span class="entity name tag org">:orange:tree:
</span></span><span class="markup heading org"><span class="punctuation definition heading org">***</span> <span class="keyword other todo org">TODO</span> Pick bananas last       <span class="entity name tag org">:banana:</span></span></span></code></pre>
<h3 id="filtering-and-searching-by-tag"><span class="section-number-3">4.1.</span> Filtering and Searching by Tag</h3>
<p>You can search for tags with <code class="verbatim">C-c \</code> or open the org-agenda with <code class="verbatim">M-x org-agenda m</code> and search for a tag of your choosing.</p>
<h2 id="tables"><span class="section-number-2">5.</span> Tables</h2>
<blockquote>
<p><a href="https://gitbay.org/cmc/cleberg.net/blob/main/content/blog/2024-08-11-org-mode-features.org#L161">View this section</a> in org-mode.</p>
</blockquote>
<p>One of the most inconvenient parts of writing in Markdown was dealing with tables. In org-mode, <a href="https://orgmode.org/manual/Tables.html">Tables</a> are a breeze due to Emacs's built-in table editor and formatter.</p>
<h3 id="built-in-table-editor"><span class="section-number-3">5.1.</span> Built-In Table Editor</h3>
<p>With the built-in table editor, press <code class="verbatim">C-c |</code> to convert the active region to a table or create an empty table.</p>
<p>When focused on a table, press <code class="verbatim">TAB</code> to re-align the table. There are more commands available to re-align, traverse, and edit cells and regions within tables in Emacs.</p>
<p>For example, refer to the following table. This table uses the <code class="verbatim">TBLFM</code> variable to define functions that will apply to the cells within the table. When I press <code class="verbatim">C-c C-c</code>, the table cells updated to their resulting values.</p>
<table>
<thead>
<tr><th>N</th><th>N<sup>2</sup></th><th>N<sup>3</sup></th><th>N<sup>4</sup></th><th>sqrt(n)</th><th>sqrt[4](N)</th></tr>
</thead>
<tbody>
<tr><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td></tr>
<tr><td>2</td><td>4</td><td>8</td><td>16</td><td>1.4142136</td><td>1.1892071</td></tr>
<tr><td>3</td><td>9</td><td>27</td><td>81</td><td>1.7320508</td><td>1.3160740</td></tr>
</tbody>
</table>
<h3 id="spreadsheet"><span class="section-number-3">5.2.</span> Spreadsheet</h3>
<p>If you spend a lot of time in spreadsheets, you'll appreciate the Emacs Calc package, which Emacs uses to implement spreadsheet-like capabilities within org-mode tables.</p>
<p>Read through the <a href="https://orgmode.org/manual/The-Spreadsheet.html">spreadsheet</a> documentation to learn more about field references (<code class="verbatim">@ROW$COLUMN</code>), range references (<code class="verbatim">$1..$3</code>), coordinates, formulas, and more.</p>
<p>For example, refer to the following table. Here is a table that computes the Taylor series of degree n at location x for a couple of functions. You can clear the values out of the <code class="verbatim">Result</code> column for each row, press <code class="verbatim">C-c C-c</code>, and watch as the table re-calculates the results for each.</p>
<table>
<tbody>
<tr><td>Func</td><td>n</td><td>x</td><td>Result</td></tr>
<tr><td>exp(x)</td><td>1</td><td>x</td><td>1 + x</td></tr>
<tr><td>exp(x)</td><td>2</td><td>x</td><td>1 + x + x<sup>2</sup> / 2</td></tr>
<tr><td>exp(x)</td><td>3</td><td>x</td><td>1 + x + x<sup>2</sup> / 2 + x<sup>3</sup> / 6</td></tr>
<tr><td>x<sup>2</sup>+sqrt(x)</td><td>2</td><td>x=0</td><td>x*(0.5 / 0) + x<sup>2</sup> (2 - 0.25 / 0) / 2</td></tr>
<tr><td>x<sup>2</sup>+sqrt(x)</td><td>2</td><td>x=1</td><td>2 + 2.5 x - 2.5 + 0.875 (x - 1)<sup>2</sup></td></tr>
<tr><td>tan(x)</td><td>3</td><td>x</td><td>x pi / 180 + 5.72e-8 x<sup>3</sup> pi<sup>3</sup></td></tr>
</tbody>
</table>
<p>Alternatively, you can also refer to the following table. This table will update to different values based on the <code class="verbatim">TBLFM</code> I select when I'm pressing <code class="verbatim">C-c C-c</code>. The results are <code class="verbatim">[1,2]</code> when focused on the first line and <code class="verbatim">[2,4]</code> when focused on the second line.</p>
<table>
<thead>
<tr><th>x</th><th>y</th></tr>
</thead>
<tbody>
<tr><td>1</td><td>2</td></tr>
<tr><td>2</td><td>4</td></tr>
</tbody>
</table>
<h2 id="source-code-blocks"><span class="section-number-2">6.</span> Source Code Blocks</h2>
<blockquote>
<p><a href="https://gitbay.org/cmc/cleberg.net/blob/main/content/blog/2024-08-11-org-mode-features.org#L231">View this section</a> in org-mode.</p>
</blockquote>
<h3 id="introduction-to-source-code-blocks"><span class="section-number-3">6.1.</span> Introduction to Source Code Blocks</h3>
<p>If you run a technical blog, write code frequently, or like to take notes with source code examples, you will appreciate the <a href="https://orgmode.org/manual/Working-with-Source-Code.html">source code</a> functionality of org-mode.</p>
<p>With this feature, org-mode can manage the source code you define with features such as editing, formatting, extracting, exporting, and publishing. Additionally, you can compile and execute source code dynamically within the org-mode file or buffer.</p>
<p>A full source code block uses the following structure:</p>
<pre><code class="language-org highlight"><span class="text org"><span class="keyword other keyword org">#+NAME:</span><span class="string unquoted org"> &lt;name&gt;</span>
<span class="markup raw block org"><span class="keyword control block begin org">#+BEGIN_SRC</span><span class="variable parameter org"> &lt;language&gt; &lt;switches&gt; &lt;header arguments&gt;</span>
  &lt;body&gt;
<span class="keyword control block end org">#+END_SRC</span></span></span></code></pre>
<p>You can also use inline blocks:</p>
<pre><code class="language-org highlight"><span class="text org">src_&lt;language&gt;[&lt;header arguments&gt;]{&lt;body&gt;}</span></code></pre>
<h3 id="editing-source-code-blocks"><span class="section-number-3">6.2.</span> Editing Source Code Blocks</h3>
<p>When focused on a code block, press <code class="verbatim">C-c'</code> to edit the code block in a special editor. Press <code class="verbatim">C-x C-x</code> to save the buffer and <code class="verbatim">C-c '</code> again to close the buffer.</p>
<h3 id="syntax-highlighting-and-formatting"><span class="section-number-3">6.3.</span> Syntax Highlighting and Formatting</h3>
<p>Emacs provides syntax highlighting by default within org-mode's source code blocks. Org-mode will copy the text to a temporary buffer, highlight it using the major mode relevant to the language (e.g., <a href="https://www.gnu.org/software/emacs/manual/html_mono/ccmode.html">CC Mode</a>), and then return the resulting highlighted text.</p>
<h3 id="buffer-evaluation"><span class="section-number-3">6.4.</span> Buffer Evaluation</h3>
<p>By default, org-mode will only evaluate Emacs Lisp code blocks. You will need to enable other <a href="https://orgmode.org/manual/Languages.html">languages</a> in order to evaluate code blocks written in languages other than elisp.</p>
<p>When focused on a code block, you can execute the block with <code class="verbatim">C-c C-c</code>. The results of the evaluation will appear below the code block in a <code class="verbatim">RESULTS</code> block.</p>
<p>For example, here is a code block in elisp that I have written and evaluated with org-mode inside this blog post. I will press <code class="verbatim">C-c C-c</code> and you will see the results below the code block.</p>
<pre><code class="language-elisp">(defun greet-me ()
  (message "Hello, world!"))

(greet-me)</code></pre>
<pre><code class="language-org highlight"><span class="text org"><span class="keyword other keyword org">#+RESULTS:</span>
: Hello, world!</span></code></pre>
<h2 id="exporting-and-publishing"><span class="section-number-2">7.</span> Exporting and Publishing</h2>
<blockquote>
<p><a href="https://gitbay.org/cmc/cleberg.net/blob/main/content/blog/2024-08-11-org-mode-features.org#L301">View this section</a> in org-mode.</p>
</blockquote>
<p>I would be remiss if I did not mention the native <a href="https://orgmode.org/manual/Exporting.html">exporting and publishing</a> functionality within Emacs and org-mode.</p>
<h3 id="built-in-publishing"><span class="section-number-3">7.1.</span> Built-In Publishing</h3>
<p>This functionality allows you to translate Org to the following formats (additional formats may be available via external packages):</p>
<ul>
<li>ascii (ASCII format)</li>
<li>beamer (LaTeX Beamer format)</li>
<li>html (HTML format)</li>
<li>icalendar (iCalendar format)</li>
<li>latex (LaTeX format)</li>
<li>md (Markdown format)</li>
<li>odt (OpenDocument Text format)</li>
<li>org (Org format)</li>
<li>texinfo (Texinfo format)</li>
<li><p>man (Man page format)</p>
<p>You can export with <code class="verbatim">C-c C-h</code> and then select your preferred destination format. For example, an export from org to HTML as a file would use <code class="verbatim">C-c C-e h h</code>.</p>
</li>
</ul>
<h3 id="external-publishing-tools"><span class="section-number-3">7.2.</span> External Publishing Tools</h3>
<p>If the native functionality isn't useful enough for you, there are a myriad of external <a href="https://orgmode.org/tools.html">tools</a>, including <a href="https://orgmode.org/worg/org-blog-wiki.html">blogs and wikis</a>, that work with org-mode.</p>
<h2 id="agenda"><span class="section-number-2">8.</span> Agenda</h2>
<blockquote>
<p><a href="https://gitbay.org/cmc/cleberg.net/blob/main/content/blog/2024-08-11-org-mode-features.org#L335">View this section</a> in org-mode.</p>
</blockquote>
<p>Last, but not least, are <a href="https://orgmode.org/manual/Agenda-Views.html">Agenda Views</a>. With agenda views, you can easily view your agenda of TODO items, scheduled items, projects, etc. across your collection of org-mode files.</p>
<p>Org-mode will extract all of this information from your org files (<code class="verbatim">org-agenda-files</code>) and display it within the agenda buffer.</p>
<p>You can open the agenda with <code class="verbatim">M-x org-agenda</code>. Once inside the buffer, you can use shortcuts in the <a href="https://orgmode.org/manual/Agenda-Dispatcher.html">Agenda Dispatcher</a> to quickly view calendars, TODOs, create items, filter items, and more.</p>
]]></description>
    </item>
    <item>
      <title>Running Emacs Natively on an Apple Silicon iPad</title>
      <link>https://cleberg.net/blog/emacs-on-ipad.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/emacs-on-ipad.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Thu, 11 Jul 2024 00:00:00 +0000</pubDate>
      <category>emacs</category>
      <description><![CDATA[<p>This post describes the process to install and use Emacs on the iPad Air 13-inch (M2). The iPad used in this post is running iPadOS 17.6.</p>
<h2 id="shell-application"><span class="section-number-2">1.</span> Shell Application</h2>
<p>In order to use Emacs on an iPad, you will need a terminal emulator application. I recommend <a href="https://apps.apple.com/us/app/ish-shell/id1436902243">iSH</a>, since it runs a version of Alpine Linux within the app itself and will allow you to install packages that you need.</p>
<figure><img src="https://img.cleberg.net/blog/20240711-emacs-on-ipad/ish.webp" alt="The iSH shell on iPad."><figcaption><span class="figure-number">Figure 1: </span>iSH Application</figcaption></figure>
<h2 id="require-packages"><span class="section-number-2">2.</span> Require Packages</h2>
<p>I started by adding the required packages directly within iSH. Emacs should install dependencies by default, but I include a few other packages that I use in my terminal as well.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">apk</span></span><span class="meta function-call arguments shell"> add emacs ripgrep fd findutils</span></span></code></pre>
<figure><img src="https://img.cleberg.net/blog/20240711-emacs-on-ipad/dependencies.webp" alt="apk add emacs ripgrep rf findutils within iSH."><figcaption><span class="figure-number">Figure 2: </span>Package Installation</figcaption></figure>
<h2 id="emacs"><span class="section-number-2">3.</span> Emacs</h2>
<p>Once this is complete, you should be able to run Emacs natively on your iPad. It's effective, but can be slow at times.</p>
<p>I attempted to also install Doom Emacs, which technically worked, but was so incredibly slow and buggy that I was not even able to take screenshots. Someone smarter than me could likely get it to work with a little tinkering.</p>
<h3 id="melpa"><span class="section-number-3">3.1.</span> MELPA</h3>
<p>You also have to remember to hook up MELPA yourself in the <code class="verbatim">.emacs</code> file to be able to search through their 5700+ packages instead of just ELPA packages. If you don't, you will only have access to ELPA packages like the ones below.</p>
<figure><img src="https://img.cleberg.net/blog/20240711-emacs-on-ipad/melpa.webp" alt="A full list of all packages available when searching MELPA."><figcaption><span class="figure-number">Figure 3: </span>package-install</figcaption></figure>
<p>Once you have MELPA, you can install packages like the <code class="verbatim">dashboard</code> package shown below.</p>
<figure><img src="https://img.cleberg.net/blog/20240711-emacs-on-ipad/dashboard.webp" alt="An example of the emacs-dashboard package."><figcaption><span class="figure-number">Figure 4: </span>emacs-dashboard</figcaption></figure>
<h3 id="speed"><span class="section-number-3">3.2.</span> Speed</h3>
<p>While Emacs will run on my iPad, it's not perfect. The largest issue on my iPad is speed - loading Emacs takes 6-7 seconds and installing the <code class="verbatim">magit</code> package took 129 seconds.</p>
<p>I haven't played around enough to optimize loading times and poke around to see why the network requests take so long, but it's a big enough issue that I wouldn't see casual Emacs users dealing with the lag.</p>
]]></description>
    </item>
    <item>
      <title>Ubuntu: Migrate GPG Keys to trusted.gpg.d</title>
      <link>https://cleberg.net/blog/deprecated-trusted-gpg-fix.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/deprecated-trusted-gpg-fix.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Wed, 19 Jun 2024 00:00:00 +0000</pubDate>
      <category>linux</category>
      <description><![CDATA[<h2 id="system-warning"><span class="section-number-2">1.</span> System Warning</h2>
<p>When running an update on an Ubuntu system, you may have run into a system warning that looks like the example below.</p>
<pre><code class="language-txt highlight"><span class="text plain">W: https://dl.yarnpkg.com/debian/dists/stable/InRelease: Key is stored in legacy
trusted.gpg keyring (/etc/apt/trusted.gpg), see the DEPRECATION section in
apt-key(8) for details.</span></code></pre>
<p>While this example references the <code class="verbatim">yarn</code> package, the warning message is the same for any repository using the deprecated <code class="verbatim">trusted.gpg</code> key ring.</p>
<p>The issue arises from managing keys with the <code class="verbatim">apt-key</code> command, which utilizes the <code class="verbatim">/etc/apt/trusted.gpg</code> file by default. Instead, Ubuntu has moved to managing key rings with individual <code class="verbatim">.gpg</code> files in the <code class="verbatim">/etc/apt/trusted.gpg.d/</code> directory.</p>
<p>To fix this issue, let's check to see which keys are using the <code class="verbatim">trusted.gpg</code> key ring and move them into their own dedicated key ring.</p>
<h2 id="finding-all-keys-in-the-keyring"><span class="section-number-2">2.</span> Finding All Keys in the Keyring</h2>
<p>Let's start by simply listing the keys used by the <code class="verbatim">apt</code> commands. To do this, run the following command.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> apt-key list</span></span></code></pre>
<p>This command will show an output similar to the one below. You may see additional keys in the <code class="verbatim">/etc/apt/trusted.gpg.d/</code> directory - this is where we will be moving any keys currently found in the <code class="verbatim">trusted.gpg</code> key ring.</p>
<p>In the below example, we can see that this system has four different GPG keys stored within the <code class="verbatim">trusted.gpg</code> key ring. Let's go ahead and move them into their own files.</p>
<pre><code class="language-txt highlight"><span class="text plain">Warning: apt-key is deprecated. Manage keyring files in trusted.gpg.d instead
(see apt-key(8)).

/etc/apt/trusted.gpg
--------------------
pub   rsa2048 2011-08-19 [SC] [expires: 2027-05-24]
      573B FD6B 3D8F BC64 1079  A6AB ABF5 BD82 7BD9 BF62
uid           [ unknown] nginx signing key &lt;signing-key@nginx.com&gt;

pub   rsa4096 2016-10-05 [SC]
      72EC F46A 56B4 AD39 C907  BBB7 1646 B01B 86E5 0310
uid           [ unknown] Yarn Packaging &lt;yarn@dan.cx&gt;
sub   rsa4096 2016-10-05 [E]
sub   rsa4096 2019-01-02 [S] [expires: 2026-01-23]
sub   rsa4096 2019-01-11 [S] [expires: 2026-01-23]

pub   rsa4096 2024-05-29 [SC]
      8540 A6F1 8833 A80E 9C16  53A4 2FD2 1310 B49F 6B46
uid           [ unknown] nginx signing key &lt;signing-key-2@nginx.com&gt;

pub   rsa4096 2024-05-29 [SC]
      9E9B E90E ACBC DE69 FE9B  204C BCDC D8A3 8D88 A2B3
uid           [ unknown] nginx signing key &lt;signing-key-3@nginx.com&gt;</span></code></pre>
<h2 id="moving-keys-to-the-proper-location"><span class="section-number-2">3.</span> Moving Keys to the Proper Location</h2>
<h3 id="exporting-keys-to-new-files"><span class="section-number-3">3.1.</span> Exporting Keys to New Files</h3>
<p>Now that we know the keys, we will need to move them into their own key ring. We can do this by copying the last eight (8) characters from the key's signature and exporting it from this key ring into its own.</p>
<p>Using the yarn example from the beginning, here's the command to move this key into its own key ring.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> apt-key export 86E50310</span> <span class="keyword operator logical pipe shell">|</span> <span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> gpg<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> --</span>dearmor</span><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>o</span> /etc/apt/trusted.gpg.d/yarn.gpg</span></span></code></pre>
<p>You can repeat this process for any other keys, such as the <code class="verbatim">nginx</code> keys in the example above.</p>
<h3 id="cleaning-up"><span class="section-number-3">3.2.</span> Cleaning Up</h3>
<p>If you run <code class="verbatim">sudo apt-key list</code> again, you should see the keys within their own key rings:</p>
<pre><code class="language-txt highlight"><span class="text plain">/etc/apt/trusted.gpg.d/nginx-archive-keyring.gpg
------------------------------------------------
pub   rsa4096 2024-05-29 [SC]
      8540 A6F1 8833 A80E 9C16  53A4 2FD2 1310 B49F 6B46
uid           [ unknown] nginx signing key &lt;signing-key-2@nginx.com&gt;

pub   rsa2048 2011-08-19 [SC] [expires: 2027-05-24]
      573B FD6B 3D8F BC64 1079  A6AB ABF5 BD82 7BD9 BF62
uid           [ unknown] nginx signing key &lt;signing-key@nginx.com&gt;

pub   rsa4096 2024-05-29 [SC]
      9E9B E90E ACBC DE69 FE9B  204C BCDC D8A3 8D88 A2B3
uid           [ unknown] nginx signing key &lt;signing-key-3@nginx.com&gt;

/etc/apt/trusted.gpg.d/yarn.gpg
-------------------------------
pub   rsa4096 2016-10-05 [SC]
      72EC F46A 56B4 AD39 C907  BBB7 1646 B01B 86E5 0310
uid           [ unknown] Yarn Packaging &lt;yarn@dan.cx&gt;
sub   rsa4096 2016-10-05 [E]
sub   rsa4096 2019-01-02 [S] [expires: 2026-01-23]
sub   rsa4096 2019-01-11 [S] [expires: 2026-01-23]</span></code></pre>
<p>Once you have verified that the keys are valid and stored in their own key rings, you can archive the <code class="verbatim">trusted.gpg</code> file and run a system update to test the new files.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> mv /etc/apt/trusted.gpg /etc/apt/trusted.gpg.bkp</span>
<span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> apt update</span></span></code></pre>
<p>Once you've verified that updates work as expected and that the keys are working as intended, you can delete the <code class="verbatim">.bkp</code> file created above. If you're storing keys that are not easily re-attainable, I suggest keeping the <code class="verbatim">.bkp</code> file stored in a safe location until you are positive that you no longer need it.</p>
]]></description>
    </item>
    <item>
      <title>OrbStack on macOS: Running Ubuntu</title>
      <link>https://cleberg.net/blog/ubuntu-on-macos.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/ubuntu-on-macos.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Fri, 03 May 2024 00:00:00 +0000</pubDate>
      <category>linux</category>
      <description><![CDATA[<p>Being a macOS user who previously used Linux for many years, I often find myself searching for alternatives to the Linux-native tools and methods that I had become used to over the years.</p>
<p>Luckily, there's an option to simply use Linux directly on your macOS device without having to boot the whole device into Linux or having to SSH into another Linux machine.</p>
<p>In this post, I use <a href="https://orbstack.dev/">OrbStack</a> to create an Ubuntu Linux machine to take advantage of the Linux system.</p>
<h2 id="installing-orbstack"><span class="section-number-2">1.</span> Installing OrbStack</h2>
<p>OrbStack has a <a href="https://orbstack.dev/download">download page</a> if you prefer to use <code class="verbatim">*.dmg</code> files to install applications.</p>
<p>Personally, I prefer to install everything through Homebrew. For OrbStack, run the following to install the application via Homebrew:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">brew</span></span><span class="meta function-call arguments shell"> install orbstack</span></span></code></pre>
<h2 id="creating-a-linux-machine"><span class="section-number-2">2.</span> Creating a Linux Machine</h2>
<p>Once installed, you can launch OrbStack and create a Linux machine in a matter of seconds. The creation dialog defaults to Ubuntu.</p>
<figure><img src="https://img.cleberg.net/blog/20240503-ubuntu-on-macos/create.webp" alt="A popup within OrbStack to create a new machine with a custom name, distribution, version, and CPU type."><figcaption><span class="figure-number">Figure 1: </span>OrbStack's Linux Machine Creation Page</figcaption></figure>
<h2 id="launching-the-machine"><span class="section-number-2">3.</span> Launching the Machine</h2>
<p>Once created, the dialog will close and you will be presented with your new list of machines. Simply double-click on a machine to run it.</p>
<p>When you run the machine for the first time, it may warn you that a program is attempting to run a shell script. You can choose to manually inspect this shell script via the provided path if you wish. When you're comfortable with the script, you can toggle the <code class="verbatim">Suppress this message permanently</code> button and click OK to run the machine.</p>
<blockquote>
<p><strong>Quick Tip</strong>!</p>
<p>You will always be able to launch the OrbStack application and control the machine via the Machines page, but you can also use the OrbStack icon in the macOS menu bar to quickly control the machine without launching OrbStack itself.</p>
</blockquote>
<h2 id="working-in-linux"><span class="section-number-2">4.</span> Working in Linux</h2>
<p>Once successful, OrbStack will launch your default terminal and log you into the Linux machine you created above.</p>
<p>In the example below, we can see that the machine is using <code class="verbatim">Linux ubuntu 6.9.6</code> and operates similar to a fresh Ubuntu install on bare metal.</p>
<figure><img src="https://img.cleberg.net/blog/20240503-ubuntu-on-macos/cli.webp" alt="uname -a command."><figcaption><span class="figure-number">Figure 2: </span>Ubuntu CLI</figcaption></figure>
<p>You can also click the machine's folder icon in OrbStack to open the machine's file system within macOS's native Files app. Within Files, you can double-click to open any files and they will open in the macOS defaults for those file types (e.g., TextEdit).</p>
<figure><img src="https://img.cleberg.net/blog/20240503-ubuntu-on-macos/files.webp" alt="The Ubuntu machine's files available within the macOS Files app."><figcaption><span class="figure-number">Figure 3: </span>Ubuntu Files</figcaption></figure>
<p>Here's an example of opening the <code class="verbatim">test.md</code> file in the screenshot above, which defaults to opening in Xcode on my system.</p>
<figure><img src="https://img.cleberg.net/blog/20240503-ubuntu-on-macos/xcode.webp" alt="An example of editing the test.md file in Xcode."><figcaption><span class="figure-number">Figure 4: </span>Ubuntu Files</figcaption></figure>
<h3 id="test-examples"><span class="section-number-3">4.1.</span> Test Examples</h3>
<p>As a quick example of the system, I installed <code class="verbatim">neofetch</code>, switched to the <code class="verbatim">zsh</code> shell, and ran a few common commands.</p>
<figure><img src="https://img.cleberg.net/blog/20240503-ubuntu-on-macos/test.webp" alt="An example of the date, pwd, and neofetch commands."><figcaption><span class="figure-number">Figure 5: </span>Test Examples</figcaption></figure>
<h2 id="thoughts"><span class="section-number-2">5.</span> Thoughts</h2>
<p>The installation, creation, and launch processes are seamless and provide an easy way to test or use Linux on macOS with little to no hassle.</p>
<p>The shell and file integrations are incredibly snappy and I have not experienced any lag so far. Further, being able to open files in the Files app allows for me to use macOS native applications, such as TextEdit for quick editing without having to resort to other programs that may not be as familiar to macOS users.</p>
<p>I love this method and will be happily looking for further use cases to apply.</p>
]]></description>
    </item>
    <item>
      <title>mu4e with Doom Emacs on macOS</title>
      <link>https://cleberg.net/blog/mu4e.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/mu4e.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Thu, 18 Apr 2024 00:00:00 +0000</pubDate>
      <category>emacs</category>
      <category>linux</category>
      <description><![CDATA[<p>This post was heavily inspired by <a href="https://macowners.club/posts/email-emacs-mu4e-macos/">Email setup in Emacs with Mu4e on macOS</a>, but with my own tweaks for a single-account configuration and some Doom-specific configurations.</p>
<h2 id="overview"><span class="section-number-2">1.</span> Overview</h2>
<p><a href="https://github.com/emacsmirror/mu4e">Mu4e</a> is an Emacs-based email client based on <a href="https://www.djcbsoftware.nl/code/mu/">mu</a>, an indexer that stores email in the Maildir format.</p>
<p>This blog post covers the installation of Mu4e in Doom Emacs on macOS. This guide should be very similar to GNU Emacs and Linux-based systems, with a few tweaks required in the various configuration files.</p>
<h2 id="installation"><span class="section-number-2">2.</span> Installation</h2>
<h3 id="prerequisites"><span class="section-number-3">2.1.</span> Prerequisites</h3>
<h4 id="create-the-folder-structure"><span class="section-number-4">2.1.1.</span> Create the Folder Structure</h4>
<p>Start by creating the base folder structure:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">mkdir</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/.maildir</span>
<span class="meta function-call shell"><span class="variable function shell">mkdir</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/.maildir/example      <span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> use whatever name you want to call your email account</span><span class="comment line number-sign shell">
</span></span><span class="meta function-call shell"><span class="variable function shell">mkdir</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/.maildir/certificates <span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> used to store system root certificates</span></span></span></code></pre>
<h4 id="store-email-account-passwords-in-macos-keychain"><span class="section-number-4">2.1.2.</span> Store Email Account Passwords in macOS Keychain</h4>
<p>Next, I will be using the macOS Keychain to store my email account passwords using the command below.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">security</span></span><span class="meta function-call arguments shell"> add-generic-password<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>s</span> mu4e-example<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>a</span> you@example.com<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>w</span></span></span></code></pre>
<p>This will prompt you to input your password twice to confirm. Keep the <code class="verbatim">mu4e-example</code> name in mind, as you will need to reference it later in the IMAP and SMTP configuration files.</p>
<h4 id="store-root-certificates"><span class="section-number-4">2.1.3.</span> Store Root Certificates</h4>
<p>In order to use IMAP and SMTP, we need to provide certificates to the local services. We will use the macOS defaults for this.</p>
<ol>
<li>Open <code class="verbatim">Keychain Access.app</code>.</li>
<li>Select <code class="verbatim">System Roots</code> in the sidebar.</li>
<li>Select all items with <code class="verbatim">CMD + a</code>.</li>
<li>Export selected items with <code class="verbatim">SHIFT + CMD + a</code> to the file <code class="verbatim">~/.maildir/certificates/root-certificates.pem</code>.</li>
</ol>
<h4 id="install-dependencies"><span class="section-number-4">2.1.4.</span> Install Dependencies</h4>
<p>Install <code class="verbatim">mbsync</code> (via <code class="verbatim">isync</code>) to fetch emails via IMAP, <code class="verbatim">mu</code> to index emails, and <code class="verbatim">msmtp</code> to send emails via SMTP.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">brew</span></span><span class="meta function-call arguments shell"> install mu isync msmtp</span></span></code></pre>
<h3 id="installing-mu4e"><span class="section-number-3">2.2.</span> Installing Mu4e</h3>
<p>Within Doom Emacs, we can install Mu4e by enabling the package.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">nano</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/.doom.d/init.el</span></span></code></pre>
<p>In this file, uncomment the <code class="verbatim">mu4e</code> line within the <code class="verbatim">:email</code> section. You can also enable the <code class="verbatim">+org</code> and <code class="verbatim">+gmail</code> options if you prefer.</p>
<pre><code class="language-lisp highlight"><span class="source lisp"><span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span>doom! :input
       ...
       :email
       mu4e
       <span class="comment line semicolon lisp"><span class="punctuation definition comment lisp">;</span>;(mu4e +org +gmail)
</span>       ...
       <span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span>default <span class="keyword operator arithmetic lisp">+</span>bindings <span class="keyword operator arithmetic lisp">+</span>smartparens<span class="punctuation definition group end lisp">)</span></span><span class="punctuation definition group end lisp">)</span></span></span></code></pre>
<h2 id="configuration"><span class="section-number-2">3.</span> Configuration</h2>
<p>As an overall suggestion, I create the following configuration files in the <code class="verbatim">~/.maildir</code> directory and using symlinks to their proper locations so that I can backup and restore these files easily.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">touch</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/.maildir/.mbsyncrc</span> <span class="keyword operator logical and shell">&amp;&amp;</span> <span class="punctuation separator continuation line shell">\
</span><span class="meta function-call shell"><span class="variable function shell">touch</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/.maildir/.msmtprc</span>  <span class="keyword operator logical and shell">&amp;&amp;</span> <span class="punctuation separator continuation line shell">\
</span><span class="meta function-call shell"><span class="variable function shell">ln</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>s</span> /Users/username/.maildir/.mbsyncrc /Users/username/.mbsyncrc</span> <span class="keyword operator logical and shell">&amp;&amp;</span> <span class="punctuation separator continuation line shell">\
</span><span class="meta function-call shell"><span class="variable function shell">ln</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>s</span> /Users/username/.maildir/.msmtprc /Users/username/.msmtprc</span></span></code></pre>
<p>You can also create these files in your home directory and skip the symlinking process above.</p>
<h3 id="imap"><span class="section-number-3">3.1.</span> IMAP</h3>
<p>Next, let's configure <code class="verbatim">mbsync</code> in the file created above. Paste the following information and customize it to match your mail provider's information.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">nano</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/.maildir/.mbsyncrc</span></span></code></pre>
<pre><code class="language-conf">IMAPAccount example
Host imap.example.com
User dummy@example.com
PassCmd "security find-generic-password -s mu4e-example -a dummy@example.com -w"
Port 993
SSLType IMAPS
AuthMechs Login
CertificateFile ~/.maildir/certificates/root-certificates.pem

IMAPStore example-remote
Account example

MaildirStore example-local
SubFolders Verbatim
Path ~/.maildir/example/
Inbox ~/.maildir/example/INBOX

Channel example
Far :example-remote:
Near :example-local:
Patterns *
Create Near
Sync All
Expunge Both
SyncState *</code></pre>
<h3 id="smtp"><span class="section-number-3">3.2.</span> SMTP</h3>
<p>Next, let's configured <code class="verbatim">msmtprc</code> in the file created above. Paste the following information and customize it to match your mail provider's information.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">nano</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/.maildir/.msmtprc</span></span></code></pre>
<pre><code class="language-conf"># Set default values for all the accounts.
defaults
logfile ~/.maildir/msmtp.log
tls_trust_file ~/.maildir/certificates/root-certificates.pem

# ======================================================================

account startmail
auth on
host smtp.startmail.com
port 465
protocol smtp
from hello@cleberg.net
user hello@cleberg.net
passwordeval security find-generic-password -s startmail -a hello@cleberg.net -w
tls on
tls_starttls off

# ======================================================================

account default : startmail</code></pre>
<h3 id="doom-emacs"><span class="section-number-3">3.3.</span> Doom Emacs</h3>
<p>Finally, we need to configure Doom Emacs to use the proper packages and set some variables and functions.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">nano</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/.doom.d/config.el</span></span></code></pre>
<pre><code class="language-lisp highlight"><span class="source lisp"><span class="comment line semicolon lisp"><span class="punctuation definition comment lisp">;</span>; load packages and programs
</span><span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span><span class="support function lisp">use-package</span> mu4e
  :<span class="support function lisp">load</span><span class="keyword operator arithmetic lisp">-</span>path  <span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>/Users/username/.emacs.d/modules/email/mu4e/<span class="punctuation definition string end lisp">&quot;</span></span><span class="punctuation definition group end lisp">)</span></span>
<span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span><span class="support function lisp">require</span> &#39;smtpmail<span class="punctuation definition group end lisp">)</span></span>
<span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span><span class="support function lisp">setq</span> mu4e<span class="keyword operator arithmetic lisp">-</span>mu<span class="keyword operator arithmetic lisp">-</span>binary <span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span>executable<span class="keyword operator arithmetic lisp">-</span><span class="support function lisp">find</span> <span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>mu<span class="punctuation definition string end lisp">&quot;</span></span><span class="punctuation definition group end lisp">)</span></span><span class="punctuation definition group end lisp">)</span></span>

<span class="comment line semicolon lisp"><span class="punctuation definition comment lisp">;</span>; set base directory
</span><span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span><span class="support function lisp">setq</span> mu4e<span class="keyword operator arithmetic lisp">-</span>maildir <span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>~/.maildir<span class="punctuation definition string end lisp">&quot;</span></span><span class="punctuation definition group end lisp">)</span></span>

<span class="comment line semicolon lisp"><span class="punctuation definition comment lisp">;</span>; sync imap servers
</span><span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span><span class="support function lisp">setq</span> mu4e<span class="keyword operator arithmetic lisp">-</span><span class="support function lisp">get</span><span class="keyword operator arithmetic lisp">-</span>mail<span class="keyword operator arithmetic lisp">-</span>command <span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span>concat <span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span>executable<span class="keyword operator arithmetic lisp">-</span><span class="support function lisp">find</span> <span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>mbsync<span class="punctuation definition string end lisp">&quot;</span></span><span class="punctuation definition group end lisp">)</span></span> <span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span> -a<span class="punctuation definition string end lisp">&quot;</span></span><span class="punctuation definition group end lisp">)</span></span><span class="punctuation definition group end lisp">)</span></span>

<span class="comment line semicolon lisp"><span class="punctuation definition comment lisp">;</span>; how often to sync in seconds
</span><span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span><span class="support function lisp">setq</span> mu4e<span class="keyword operator arithmetic lisp">-</span>update<span class="keyword operator arithmetic lisp">-</span>interval <span class="constant numeric lisp">300</span><span class="punctuation definition group end lisp">)</span></span>

<span class="comment line semicolon lisp"><span class="punctuation definition comment lisp">;</span>; save attachments to defined directory
</span><span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span><span class="support function lisp">setq</span> mu4e<span class="keyword operator arithmetic lisp">-</span>attachment<span class="keyword operator arithmetic lisp">-</span>dir <span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>~/Downloads<span class="punctuation definition string end lisp">&quot;</span></span><span class="punctuation definition group end lisp">)</span></span>

<span class="comment line semicolon lisp"><span class="punctuation definition comment lisp">;</span>; rename files when moving - needed for mbsync:
</span><span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span><span class="support function lisp">setq</span> mu4e<span class="keyword operator arithmetic lisp">-</span>change<span class="keyword operator arithmetic lisp">-</span>filenames<span class="keyword operator arithmetic lisp">-</span><span class="keyword control lisp">when</span><span class="keyword operator arithmetic lisp">-</span>moving <span class="constant language lisp">t</span><span class="punctuation definition group end lisp">)</span></span>

<span class="comment line semicolon lisp"><span class="punctuation definition comment lisp">;</span>; list of your email adresses:
</span><span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span><span class="support function lisp">setq</span> mu4e<span class="keyword operator arithmetic lisp">-</span>user<span class="keyword operator arithmetic lisp">-</span>mail<span class="keyword operator arithmetic lisp">-</span>address<span class="keyword operator arithmetic lisp">-</span><span class="support function lisp">list</span> &#39;<span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span><span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>you@example.com<span class="punctuation definition string end lisp">&quot;</span></span><span class="punctuation definition group end lisp">)</span></span><span class="punctuation definition group end lisp">)</span></span>

<span class="comment line semicolon lisp"><span class="punctuation definition comment lisp">;</span>; check your ~/.maildir to see naming of subdirectories
</span><span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span><span class="support function lisp">setq</span>   mu4e<span class="keyword operator arithmetic lisp">-</span>maildir<span class="keyword operator arithmetic lisp">-</span>shortcuts
        &#39;<span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span><span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span><span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>/example/INBOX<span class="punctuation definition string end lisp">&quot;</span></span> . ?e<span class="punctuation definition group end lisp">)</span></span>
          <span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span><span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>/example/Sent<span class="punctuation definition string end lisp">&quot;</span></span> . ?E<span class="punctuation definition group end lisp">)</span></span><span class="punctuation definition group end lisp">)</span></span><span class="punctuation definition group end lisp">)</span></span>

<span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span><span class="support function lisp">setq</span> mu4e<span class="keyword operator arithmetic lisp">-</span>contexts
      `<span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span>,<span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span>make<span class="keyword operator arithmetic lisp">-</span>mu4e<span class="keyword operator arithmetic lisp">-</span>context
          :name <span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>example<span class="punctuation definition string end lisp">&quot;</span></span>
          :enter<span class="keyword operator arithmetic lisp">-</span>func
          <span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span><span class="support function lisp">lambda</span> <span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span><span class="punctuation definition group end lisp">)</span></span> <span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span>mu4e<span class="keyword operator arithmetic lisp">-</span>message <span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>Enter you@example.com context<span class="punctuation definition string end lisp">&quot;</span></span><span class="punctuation definition group end lisp">)</span></span><span class="punctuation definition group end lisp">)</span></span>
          :leave<span class="keyword operator arithmetic lisp">-</span>func
          <span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span><span class="support function lisp">lambda</span> <span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span><span class="punctuation definition group end lisp">)</span></span> <span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span>mu4e<span class="keyword operator arithmetic lisp">-</span>message <span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>Leave you@example.com context<span class="punctuation definition string end lisp">&quot;</span></span><span class="punctuation definition group end lisp">)</span></span><span class="punctuation definition group end lisp">)</span></span>
          :match<span class="keyword operator arithmetic lisp">-</span>func
          <span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span><span class="support function lisp">lambda</span> <span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span>msg<span class="punctuation definition group end lisp">)</span></span>
            <span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span><span class="keyword control lisp">when</span> msg
              <span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span>mu4e<span class="keyword operator arithmetic lisp">-</span>message<span class="keyword operator arithmetic lisp">-</span>contact<span class="keyword operator arithmetic lisp">-</span>field<span class="keyword operator arithmetic lisp">-</span>matches msg
                                                  :<span class="keyword control lisp">to</span> <span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>you@example.com<span class="punctuation definition string end lisp">&quot;</span></span><span class="punctuation definition group end lisp">)</span></span><span class="punctuation definition group end lisp">)</span></span><span class="punctuation definition group end lisp">)</span></span>
          :vars &#39;<span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span><span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span>user<span class="keyword operator arithmetic lisp">-</span>mail<span class="keyword operator arithmetic lisp">-</span>address . <span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>you@example.com<span class="punctuation definition string end lisp">&quot;</span></span><span class="punctuation definition group end lisp">)</span></span>
                  <span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span>user<span class="keyword operator arithmetic lisp">-</span>full<span class="keyword operator arithmetic lisp">-</span>name . <span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>Christian Cleberg<span class="punctuation definition string end lisp">&quot;</span></span><span class="punctuation definition group end lisp">)</span></span>
                  <span class="comment line semicolon lisp"><span class="punctuation definition comment lisp">;</span>; check your ~/.maildir to see how the subdirectories are called
</span>                  <span class="comment line semicolon lisp"><span class="punctuation definition comment lisp">;</span>; e.g `ls ~/.maildir/example&#39;
</span>                  <span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span>mu4e<span class="keyword operator arithmetic lisp">-</span>drafts<span class="keyword operator arithmetic lisp">-</span>folder . <span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>/example/Drafts<span class="punctuation definition string end lisp">&quot;</span></span><span class="punctuation definition group end lisp">)</span></span>
                  <span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span>mu4e<span class="keyword operator arithmetic lisp">-</span>refile<span class="keyword operator arithmetic lisp">-</span>folder . <span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>/example/Archive<span class="punctuation definition string end lisp">&quot;</span></span><span class="punctuation definition group end lisp">)</span></span>
                  <span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span>mu4e<span class="keyword operator arithmetic lisp">-</span>sent<span class="keyword operator arithmetic lisp">-</span>folder . <span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>/example/Sent<span class="punctuation definition string end lisp">&quot;</span></span><span class="punctuation definition group end lisp">)</span></span>
                  <span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span>mu4e<span class="keyword operator arithmetic lisp">-</span>trash<span class="keyword operator arithmetic lisp">-</span>folder . <span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>/example/Trash<span class="punctuation definition string end lisp">&quot;</span></span><span class="punctuation definition group end lisp">)</span></span><span class="punctuation definition group end lisp">)</span></span><span class="punctuation definition group end lisp">)</span></span><span class="punctuation definition group end lisp">)</span></span><span class="punctuation definition group end lisp">)</span></span>

<span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span><span class="support function lisp">setq</span> mu4e<span class="keyword operator arithmetic lisp">-</span>context<span class="keyword operator arithmetic lisp">-</span>policy &#39;pick<span class="keyword operator arithmetic lisp">-</span><span class="support function lisp">first</span><span class="punctuation definition group end lisp">)</span></span> <span class="comment line semicolon lisp"><span class="punctuation definition comment lisp">;</span>; start with the first (default) context;
</span><span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span><span class="support function lisp">setq</span> mu4e<span class="keyword operator arithmetic lisp">-</span>compose<span class="keyword operator arithmetic lisp">-</span>context<span class="keyword operator arithmetic lisp">-</span>policy &#39;ask<span class="punctuation definition group end lisp">)</span></span> <span class="comment line semicolon lisp"><span class="punctuation definition comment lisp">;</span>; ask for context if no context matches;
</span>
<span class="comment line semicolon lisp"><span class="punctuation definition comment lisp">;</span>; gpg encryptiom &amp; decryption:
</span><span class="comment line semicolon lisp"><span class="punctuation definition comment lisp">;</span>; this can be left alone
</span><span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span><span class="support function lisp">require</span> &#39;epa<span class="keyword operator arithmetic lisp">-</span>file<span class="punctuation definition group end lisp">)</span></span>
<span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span>epa<span class="keyword operator arithmetic lisp">-</span>file<span class="keyword operator arithmetic lisp">-</span>enable<span class="punctuation definition group end lisp">)</span></span>
<span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span><span class="support function lisp">setq</span> epa<span class="keyword operator arithmetic lisp">-</span>pinentry<span class="keyword operator arithmetic lisp">-</span>mode &#39;loopback<span class="punctuation definition group end lisp">)</span></span>
<span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span>auth<span class="keyword operator arithmetic lisp">-</span>source<span class="keyword operator arithmetic lisp">-</span>forget<span class="keyword operator arithmetic lisp">-</span>all<span class="keyword operator arithmetic lisp">-</span>cached<span class="punctuation definition group end lisp">)</span></span>

<span class="comment line semicolon lisp"><span class="punctuation definition comment lisp">;</span>; don&#39;t keep message compose buffers around after sending:
</span><span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span><span class="support function lisp">setq</span> message<span class="keyword operator arithmetic lisp">-</span>kill<span class="keyword operator arithmetic lisp">-</span>buffer<span class="keyword operator arithmetic lisp">-</span>on<span class="keyword operator arithmetic lisp">-</span>exit <span class="constant language lisp">t</span><span class="punctuation definition group end lisp">)</span></span>

<span class="comment line semicolon lisp"><span class="punctuation definition comment lisp">;</span>; send function:
</span><span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span><span class="support function lisp">setq</span> send<span class="keyword operator arithmetic lisp">-</span>mail<span class="keyword operator arithmetic lisp">-</span>function &#39;sendmail<span class="keyword operator arithmetic lisp">-</span>send<span class="keyword operator arithmetic lisp">-</span>it
      message<span class="keyword operator arithmetic lisp">-</span>send<span class="keyword operator arithmetic lisp">-</span>mail<span class="keyword operator arithmetic lisp">-</span>function &#39;sendmail<span class="keyword operator arithmetic lisp">-</span>send<span class="keyword operator arithmetic lisp">-</span>it<span class="punctuation definition group end lisp">)</span></span>

<span class="comment line semicolon lisp"><span class="punctuation definition comment lisp">;</span>; send program:
</span><span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span><span class="support function lisp">setq</span> sendmail<span class="keyword operator arithmetic lisp">-</span>program <span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span>executable<span class="keyword operator arithmetic lisp">-</span><span class="support function lisp">find</span> <span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>msmtp<span class="punctuation definition string end lisp">&quot;</span></span><span class="punctuation definition group end lisp">)</span></span><span class="punctuation definition group end lisp">)</span></span>

<span class="comment line semicolon lisp"><span class="punctuation definition comment lisp">;</span>; select the right sender email from the context.
</span><span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span><span class="support function lisp">setq</span> message<span class="keyword operator arithmetic lisp">-</span>sendmail<span class="keyword operator arithmetic lisp">-</span>envelope<span class="keyword operator arithmetic lisp">-</span><span class="keyword control lisp">from</span> &#39;header<span class="punctuation definition group end lisp">)</span></span>

<span class="comment line semicolon lisp"><span class="punctuation definition comment lisp">;</span>; mu4e cc &amp; bcc
</span><span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span>add<span class="keyword operator arithmetic lisp">-</span>hook &#39;mu4e<span class="keyword operator arithmetic lisp">-</span>compose<span class="keyword operator arithmetic lisp">-</span>mode<span class="keyword operator arithmetic lisp">-</span>hook
          <span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span><span class="meta function lisp"><span class="storage type function-type lisp">defun</span> <span class="entity name function lisp">timu</span></span><span class="keyword operator arithmetic lisp">/</span>add<span class="keyword operator arithmetic lisp">-</span>cc<span class="keyword operator arithmetic lisp">-</span><span class="keyword operator logical lisp">and</span><span class="keyword operator arithmetic lisp">-</span>bcc <span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span><span class="punctuation definition group end lisp">)</span></span>
            <span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>My Function to automatically add Cc &amp; Bcc: headers.
    This is in the mu4e compose mode.<span class="punctuation definition string end lisp">&quot;</span></span>
            <span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span>save<span class="keyword operator arithmetic lisp">-</span>excursion <span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span>message<span class="keyword operator arithmetic lisp">-</span>add<span class="keyword operator arithmetic lisp">-</span>header <span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>Cc:<span class="constant character escape lisp">\n</span><span class="punctuation definition string end lisp">&quot;</span></span><span class="punctuation definition group end lisp">)</span></span><span class="punctuation definition group end lisp">)</span></span>
            <span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span>save<span class="keyword operator arithmetic lisp">-</span>excursion <span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span>message<span class="keyword operator arithmetic lisp">-</span>add<span class="keyword operator arithmetic lisp">-</span>header <span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>Bcc:<span class="constant character escape lisp">\n</span><span class="punctuation definition string end lisp">&quot;</span></span><span class="punctuation definition group end lisp">)</span></span><span class="punctuation definition group end lisp">)</span></span><span class="punctuation definition group end lisp">)</span></span><span class="punctuation definition group end lisp">)</span></span>

<span class="comment line semicolon lisp"><span class="punctuation definition comment lisp">;</span>; mu4e address completion
</span><span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span>add<span class="keyword operator arithmetic lisp">-</span>hook &#39;mu4e<span class="keyword operator arithmetic lisp">-</span>compose<span class="keyword operator arithmetic lisp">-</span>mode<span class="keyword operator arithmetic lisp">-</span>hook &#39;company<span class="keyword operator arithmetic lisp">-</span>mode<span class="punctuation definition group end lisp">)</span></span></span></code></pre>
<p>Be sure to sync Doom to update the current configurations.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">doom</span></span><span class="meta function-call arguments shell"> sync</span></span></code></pre>
<p>If you have Doom open, execute <code class="verbatim">SPC h r r</code> to reload the new configurations.</p>
<h2 id="initial-sync"><span class="section-number-2">4.</span> Initial Sync</h2>
<p>Once you have configured all of the relevant files, you can perform an initial sync. Note that you can perform syncing within Mu4e itself after this.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">mbsync</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>aV</span></span></span></code></pre>
<p>Once you sync the data, you can index the emails.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">mu</span></span><span class="meta function-call arguments shell"> init<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>m</span> <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/.maildir<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> --</span>my-address</span> you@example.com</span> <span class="keyword operator logical and shell">&amp;&amp;</span> <span class="punctuation separator continuation line shell">\
</span><span class="meta function-call shell"><span class="variable function shell">mu</span></span><span class="meta function-call arguments shell"> index</span></span></code></pre>
<p>The emails will now to be ready to use!</p>
<h2 id="screenshots"><span class="section-number-2">5.</span> Screenshots</h2>
<p>You can now launch Doom and open Mu4e with <code class="verbatim">SPC o m</code>. You can also explore the Mu4e options with <code class="verbatim">SPC : mu4e</code>.</p>
<p>The home page shows various options and metadata about the account you've opened.</p>
<figure><img src="https://img.cleberg.net/blog/20240418-mu4e/mu4e.webp" alt="The mu4e homepage within iTerm2, showing the basics, bookmarks, maildirs, and misc sections."><figcaption><span class="figure-number">Figure 1: </span>Mu4e Home Page</figcaption></figure>
]]></description>
    </item>
    <item>
      <title>Local Web Dev Server with Docker and Nginx</title>
      <link>https://cleberg.net/blog/docker-local-web-server.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/docker-local-web-server.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Mon, 08 Apr 2024 00:00:00 +0000</pubDate>
      <category>self-hosting</category>
      <category>web</category>
      <description><![CDATA[<p>When developing websites locally, I often use a simple Python web server to observe the changes.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">python3</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>m</span> http.server</span></span></code></pre>
<p>However, this approach has its limitations. For example, this approach does not enable logging or access controls. You also need to customize <code class="verbatim">SimpleHTTPServer</code> if you have advanced needs from your web server.</p>
<p>So, I went to find an alternative that is almost as easy and far more extensible and found Docker Desktop to be a suitable replacement.</p>
<h2 id="docker-desktop"><span class="section-number-2">1.</span> Docker Desktop</h2>
<h3 id="installation"><span class="section-number-3">1.1.</span> Installation</h3>
<p><a href="https://www.docker.com/products/docker-desktop/">Docker Desktop</a> is a desktop GUI for the phenomenal Docker container software. This allows you to manage containers, images, volumes, environments, and extensions via an easy-to-use GUI.</p>
<p>To install, open the link above and click the <code class="verbatim">Download</code> button for your platform. I'm going through this process on an M2 Macbook, so I downloaded the Mac - Apple Chip version.</p>
<p>Open the installer and follow the installation process until the application finishes the installation process.</p>
<figure><img src="https://img.cleberg.net/blog/20240408-docker-local-web-server/docker-desktop.webp" alt="The Containers home page of the Docker Desktop app on macOS."><figcaption><span class="figure-number">Figure 1: </span>Docker Desktop on macOS</figcaption></figure>
<h3 id="creating-an-nginx-container"><span class="section-number-3">1.2.</span> Creating an Nginx Container</h3>
<p>I prefer to use the command line to create containers, so the following commands will be input via the terminal.</p>
<p>The following command will create a container, using the <code class="verbatim">nginx</code> image:</p>
<ol>
<li><code class="verbatim">-d</code>: Run this container as a daemon (detach)</li>
<li><code class="verbatim">-p</code>: Allocate a port in the format <code class="verbatim">&lt;external&gt;:&lt;internal&gt;</code></li>
<li><code class="verbatim">-i</code>: Keep STDIN open even if not attached</li>
<li><code class="verbatim">-t</code>: Allocate a pseudo-TTY</li>
<li><code class="verbatim">-p</code>: Allocate a port in the format <code class="verbatim">&lt;external&gt;:&lt;internal&gt;</code></li>
<li><code class="verbatim">--rm</code>: Remove the container once it's done running</li>
</ol>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">docker</span></span><span class="meta function-call arguments shell"> run<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>it</span><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> --</span>rm</span><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>d</span><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>p</span> 8000:80<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> --</span>name</span> web nginx</span></span></code></pre>
<p>You can navigate to <a href="http://localhost:8000">http://localhost:8000</a> to see the resulting page.</p>
<figure><img src="https://img.cleberg.net/blog/20240408-docker-local-web-server/default-container.webp" alt="Welcome to nginx! page viewable at localhost:8000."><figcaption><span class="figure-number">Figure 2: </span>Default Nginx Container</figcaption></figure>
<h3 id="customizing-the-nginx-container"><span class="section-number-3">1.3.</span> Customizing the Nginx Container</h3>
<p>Now that I have a container running the Nginx web server, I need to link some volumes so that I can modify the site configuration and provide the web files to serve.</p>
<p>Let's start with the new command, which adds two volumes:</p>
<ol>
<li><code class="verbatim">&lt;your_content&gt;:/usr/share/nginx/html</code>: This is the directory where you will provide the web pages for the server to serve.</li>
<li><code class="verbatim">&lt;your_config&gt;:/etc/nginx/conf.d/default.conf</code>: This is the Nginx configuration file for your site.</li>
</ol>
<p>To see the updates, you can delete the previous container in the GUI or run <code class="verbatim">docker stop web</code> to stop the container. Once stopped, you can run the new <code class="verbatim">docker run</code> command below.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">docker</span></span><span class="meta function-call arguments shell"> run<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>it</span><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>d</span><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>p</span> 8000:80<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> --</span>name</span> web<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>v</span> <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/Source/cleberg.net/.build:/usr/share/nginx/html<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>v</span> <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/Source/cleberg.net/nginx-config.conf:/etc/nginx/conf.d/default.conf nginx</span></span></code></pre>
<p>Here's an example of my development configuration file.</p>
<pre><code class="language-conf"># nginx-config.conf
server {
       server_name cleberg.net www.cleberg.net;

       root /usr/share/nginx/html;
       index index.html;
       autoindex on;

       access_log  /var/log/nginx/cleberg.net.access.log;
       error_log  /var/log/nginx/cleberg.net.error.log;

       location / {
                try_files $uri $uri/ =404;
       }

       listen [::]:80;
       listen 80;
}</code></pre>
<figure><img src="https://img.cleberg.net/blog/20240408-docker-local-web-server/custom-container.webp" alt="A view of cleberg.net on the localhost, as the docker container is pointing to the cleberg.net repository directory."><figcaption><span class="figure-number">Figure 3: </span>Deploying My Website via Docker</figcaption></figure>
<h2 id="customizing-deployment-actions"><span class="section-number-2">2.</span> Customizing Deployment Actions</h2>
<p>I am currently blogging with <a href="https://emacs.love/weblorg/">weblorg</a>, which uses a custom <code class="verbatim">publish.el</code> file to build the static site. Within this file, I have configured my deployment process to check for the <code class="verbatim">ENV</code> variable in the shell and if it's set to <code class="verbatim">prod</code>, the script will set the base URLs to <code class="verbatim">https://cleberg.net</code>. If not, it sets the base URLs to <code class="verbatim">localhost:8000</code> (which matches the port used in the container above).</p>
<p>Therefore, I have modified my <code class="verbatim">build.sh</code> script to build with <code class="verbatim">localhost</code> URLs if <code class="verbatim">ENV</code> is not set to <code class="verbatim">prod</code>. It also prevents the build process from sending the built files to the production web server.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell">!/bin/bash</span><span class="comment line number-sign shell">
</span>
<span class="keyword control if begin shell">if</span> <span class="support function test begin shell">[</span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">ENV</span></span><span class="punctuation definition string end shell">&quot;</span></span> <span class="keyword operator logical shell">==</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>prod<span class="punctuation definition string end shell">&quot;</span></span> <span class="support function test end shell">]</span></span><span class="keyword operator logical continue shell">;</span> <span class="keyword control if then shell">then</span>
    <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>Environment = Production<span class="punctuation definition string end shell">&quot;</span></span></span>              <span class="keyword operator logical and shell">&amp;&amp;</span> <span class="punctuation separator continuation line shell">\
</span>    <span class="meta function-call shell"><span class="variable function shell">rm</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>rf</span> .build/<span class="keyword operator regexp quantifier shell">*</span></span>                              <span class="keyword operator logical and shell">&amp;&amp;</span> <span class="punctuation separator continuation line shell">\
</span>    <span class="meta function-call shell"><span class="variable function shell">emacs</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> --</span>script</span> publish.el</span>                    <span class="keyword operator logical and shell">&amp;&amp;</span> <span class="punctuation separator continuation line shell">\
</span>    <span class="meta function-call shell"><span class="variable function shell">scp</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>r</span> .build/<span class="keyword operator regexp quantifier shell">*</span> ubuntu:/var/www/cleberg.net/</span>
<span class="keyword control if else shell">else</span>
    <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>Environment = Development<span class="punctuation definition string end shell">&quot;</span></span></span>             <span class="keyword operator logical and shell">&amp;&amp;</span> <span class="punctuation separator continuation line shell">\
</span>    <span class="meta function-call shell"><span class="variable function shell">rm</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>rf</span> .build/<span class="keyword operator regexp quantifier shell">*</span></span>                              <span class="keyword operator logical and shell">&amp;&amp;</span> <span class="punctuation separator continuation line shell">\
</span>    <span class="meta function-call shell"><span class="variable function shell">emacs</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> --</span>script</span> publish.el</span>
<span class="meta function-call shell"><span class="variable function shell">fi</span></span></span></code></pre>
<p>You can modify the container in numerous ways and this approach allows you to create complex scenarios for your web development purposes. I highly recommend switching over to a container-based approach for simple, local web development.</p>
]]></description>
    </item>
    <item>
      <title>OneNote to Org: Escape the Microsoft Format</title>
      <link>https://cleberg.net/blog/convert-onenote-to-markdown.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/convert-onenote-to-markdown.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Sat, 06 Apr 2024 00:00:00 +0000</pubDate>
      <category>emacs</category>
      <description><![CDATA[<p>If you're looking to convert your OneNote content to another format, such as Markdown or Org-Mode, you're in luck. I use a solution that doesn't require other programs, such as Evernote or Notion. Personally, I used this solution on a managed corporate laptop that doesn't allow installation of other programs like these.</p>
<p>This solution uses OneNote and Pandoc on Windows 10.</p>
<h2 id="export-onenote-content-to-word"><span class="section-number-2">1.</span> Export OneNote Content to Word</h2>
<p>To start, export any pages or tabs from OneNote to the Word format (<code class="verbatim">.docx</code>):</p>
<ol>
<li>Open OneNote desktop.</li>
<li>Select <code class="verbatim">File</code> and then <code class="verbatim">Export</code>.</li>
<li>Select the scope of content to export, such as <code class="verbatim">Tab</code> or <code class="verbatim">Page</code>.</li>
<li>Name and save the file in an easy to remember location. I recommend your Downloads or Desktop folder.</li>
</ol>
<p>See below for a visual walkthrough of the export process.</p>
<h2 id="download-pandoc"><span class="section-number-2">2.</span> Download Pandoc</h2>
<p>Start by downloading Pandoc from their <a href="https://github.com/jgm/pandoc/releases">GitHub releases</a> page. I cannot install <code class="verbatim">.msi</code> files on my corporate laptop, so I downloaded the <code class="verbatim">pandoc-3.1.12.3-windows-x86_64.zip</code> file, which contains a simple <code class="verbatim">.exe</code> file that you do not need to install - you will simply run it from the command line below.</p>
<p>Once downloaded, unzip the archive and move the <code class="verbatim">pandoc.exe</code> file to the same folder where your Word documents were saved above. If you prefer, you can move this file to an easier location, such as <code class="verbatim">C:\Users\youruser\Downloads</code>.</p>
<h2 id="convert-word-to-markdown"><span class="section-number-2">3.</span> Convert Word to Markdown</h2>
<p>In this example, I will be converting the Word documents to Markdown, but Pandoc supports <a href="https://github.com/jgm/pandoc?tab=readme-ov-file#the-universal-markup-converter">a ton of different formats for conversion</a>. Choose the format you prefer and then modify the following commands as needed.</p>
<p>To perform the conversion, open the Command Prompt. If you can't find it, open the start menu and search for it.</p>
<p>Within the command prompt, navigate to the directory where you stored the <code class="verbatim">pandoc.exe</code> file and the Word documents.</p>
<pre><code class="language-ps1">cd "C:\Users\yourusername\Downloads"</code></pre>
<p>You can verify that you're in the correct directory with the <code class="verbatim">dir</code> command.</p>
<pre><code class="language-ps1">dir</code></pre>
<p>Once you have verified that you have the command prompt open in the correct directory with the <code class="verbatim">pandoc.exe</code> and the Word documents, you can run the following loop to convert all Word documents to Markdown.</p>
<pre><code class="language-ps1">for %f in (*.docx) do (pandoc.exe --extract-media=. --wrap=preserve "%f" -o "%f.md")</code></pre>
<p>This loop will perform the following actions:</p>
<ol>
<li>Find all documents matching the pattern <code class="verbatim">*.docx</code>, which means all Word documents ending with that file extension.</li>
<li>Iterate through all files found in step 1.</li>
<li>For each file, perform the pandoc command.</li>
<li>Within the pandoc command, <code class="verbatim">--extract-media</code> saves all media found in the files to the current folder, with pandoc automatically creating a <code class="verbatim">media</code> subfolder to hold all images.</li>
<li>Within the pandoc command, <code class="verbatim">--wrap=preserve</code> will attempt to prseerve the wrapping from the source document.</li>
<li>Within the pandoc command, the final step is to specify the output path with <code class="verbatim">-o</code>. This option adds the <code class="verbatim">.md</code> file extension to recognize the output files as Markdown files.</li>
</ol>
<p>If you want to export to another format, simply specify the <code class="verbatim">-f==/</code>–from== and <code class="verbatim">-t==/</code>–to== options.</p>
<p>For example, you can convert the Word document to org-mode. You can also convert to one format and subsequently convert to other formats as needed.</p>
<pre><code class="language-ps1">pandoc.exe -f docx -t org file.docx</code></pre>
]]></description>
    </item>
    <item>
      <title>Blogging with Emacs Org Mode and weblorg</title>
      <link>https://cleberg.net/blog/org-blog.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/org-blog.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Fri, 29 Mar 2024 00:00:00 +0000</pubDate>
      <category>emacs</category>
      <category>web</category>
      <description><![CDATA[<p>First and foremost, apologies to those who subscribe via RSS as I know that my feed duplicated itself when I moved this blog over to org-mode last night.</p>
<p>This post focuses specifically on the configuration and tools I use to blog from Emacs with Org-Mode and does not focus on Emacs or Org-Mode themselves. Refer to the post I wrote about <a href="https://cleberg.net/blog/doom-emacs-org-mode.html">Doom Emacs &amp; Org-Mode</a> for more information about my base Emacs configuration.</p>
<h2 id="weblorg"><span class="section-number-2">1.</span> Weblorg</h2>
<p>The first step in blogging with Org-Mode is to choose a method to convert the source files to HTML and publish them. The Worg site maintains a nice list of <a href="https://orgmode.org/worg/org-blog-wiki.html">Blogs and Wikis with Org</a>, but the tools are inevitably different and opinionated, so you'll need to find what works for you.</p>
<p>I tried using Jekyll, Hugo, ox-hugo, Nikola, Blorg, org-static-blog, and the native org-publish functions before finally settling on Weblorg. For one reason or another, the other solutions were a drastic step down from my previous workflow that used <a href="https://www.getzola.org/">Zola</a> with Markdown content.</p>
<p><a href="https://github.com/emacs-love/weblorg">Weblorg</a> is a static site generator for <a href="https://orgmode.org/">org-mode</a>, built for use within <a href="https://www.gnu.org/software/emacs/">Emacs</a>. Since it's written in Emacs Lisp, there's no need to install other languages or frameworks to get started. More than that, you can write in any editor you please and simply invoke the Emacs build process with the <code class="verbatim">--script</code> parameter instead of requiring you to blog inside Emacs.</p>
<h3 id="installation"><span class="section-number-3">1.1.</span> Installation</h3>
<p>The <a href="https://emacs.love/weblorg/doc/index.html">Getting Started</a> page details broad installation requirements. I am using Doom Emacs on macOS, which requires you to add the package to the <code class="verbatim">~/.doom.d/packages.el</code> file and configure the <code class="verbatim">publish.el</code> file slightly differently.</p>
<p>To start, add the <code class="verbatim">htmlize</code> and <code class="verbatim">weblorg</code> packages to Doom, sync the changes, and reload.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">nano</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/.doom.d/packages.el</span></span></code></pre>
<pre><code class="language-lisp highlight"><span class="source lisp"><span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span>package! htmlize<span class="punctuation definition group end lisp">)</span></span>
<span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span>package! weblorg<span class="punctuation definition group end lisp">)</span></span></span></code></pre>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">doom</span></span><span class="meta function-call arguments shell"> sync</span></span></code></pre>
<p>Either re-open Emacs or hit <code class="verbatim">SPC h r r</code> to reload the changes.</p>
<h3 id="configuration"><span class="section-number-3">1.2.</span> Configuration</h3>
<p>Now that I've installed weblorg, I need to configure the project. I'll start by navigating to my site's source code and creating a <code class="verbatim">publish.el</code> file.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="support function cd shell">cd</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/Source/cleberg.net</span> <span class="keyword operator logical and shell">&amp;&amp;</span> <span class="meta function-call shell"><span class="variable function shell">nano</span></span><span class="meta function-call arguments shell"> publish.el</span></span></code></pre>
<p>Since I'm using Doom, Emacs will not automatically load the packages I need later in the build process. To compensate, my <code class="verbatim">publish.el</code> file needs to explicitly tell Emacs where Doom stores the <code class="verbatim">htmlize</code>, <code class="verbatim">weblorg</code>, and <code class="verbatim">templatel</code> packages.</p>
<pre><code class="language-lisp highlight"><span class="source lisp"><span class="comment line semicolon lisp"><span class="punctuation definition comment lisp">;</span>; explicity load packages since I&#39;m using Doom Emacs
</span><span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span>add<span class="keyword operator arithmetic lisp">-</span><span class="keyword control lisp">to</span><span class="keyword operator arithmetic lisp">-</span><span class="support function lisp">list</span> &#39;<span class="support function lisp">load</span><span class="keyword operator arithmetic lisp">-</span>path <span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>~/.emacs.d/.local/straight/repos/emacs-htmlize<span class="punctuation definition string end lisp">&quot;</span></span><span class="punctuation definition group end lisp">)</span></span>
<span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span>add<span class="keyword operator arithmetic lisp">-</span><span class="keyword control lisp">to</span><span class="keyword operator arithmetic lisp">-</span><span class="support function lisp">list</span> &#39;<span class="support function lisp">load</span><span class="keyword operator arithmetic lisp">-</span>path <span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>~/.emacs.d/.local/straight/repos/weblorg<span class="punctuation definition string end lisp">&quot;</span></span><span class="punctuation definition group end lisp">)</span></span>
<span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span>add<span class="keyword operator arithmetic lisp">-</span><span class="keyword control lisp">to</span><span class="keyword operator arithmetic lisp">-</span><span class="support function lisp">list</span> &#39;<span class="support function lisp">load</span><span class="keyword operator arithmetic lisp">-</span>path <span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>~/.emacs.d/.local/straight/repos/templatel<span class="punctuation definition string end lisp">&quot;</span></span><span class="punctuation definition group end lisp">)</span></span>
<span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span><span class="support function lisp">require</span> &#39;htmlize<span class="punctuation definition group end lisp">)</span></span>
<span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span><span class="support function lisp">require</span> &#39;weblorg<span class="punctuation definition group end lisp">)</span></span>

<span class="comment line semicolon lisp"><span class="punctuation definition comment lisp">;</span>; defaults to http://localhost:8000
</span><span class="comment line semicolon lisp"><span class="punctuation definition comment lisp">;</span>; To build with the custom URL below, call:
</span><span class="comment line semicolon lisp"><span class="punctuation definition comment lisp">;</span>;;; ENV=prod emacs --script publish.el
</span><span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span><span class="keyword control lisp">if</span> <span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span><span class="support function lisp">string</span><span class="keyword operator comparison lisp">=</span> <span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span>getenv <span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>ENV<span class="punctuation definition string end lisp">&quot;</span></span><span class="punctuation definition group end lisp">)</span></span> <span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>prod<span class="punctuation definition string end lisp">&quot;</span></span><span class="punctuation definition group end lisp">)</span></span>
 <span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span><span class="support function lisp">setq</span> weblorg<span class="keyword operator arithmetic lisp">-</span>default<span class="keyword operator arithmetic lisp">-</span>url <span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>https://cleberg.net<span class="punctuation definition string end lisp">&quot;</span></span><span class="punctuation definition group end lisp">)</span></span><span class="punctuation definition group end lisp">)</span></span>

<span class="comment line semicolon lisp"><span class="punctuation definition comment lisp">;</span>; site metadata
</span><span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span>weblorg<span class="keyword operator arithmetic lisp">-</span>site
 :theme <span class="constant language lisp">nil</span>
 :template<span class="keyword operator arithmetic lisp">-</span>vars &#39;<span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span><span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span><span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>site_name<span class="punctuation definition string end lisp">&quot;</span></span> . <span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>cleberg.net<span class="punctuation definition string end lisp">&quot;</span></span><span class="punctuation definition group end lisp">)</span></span>
                  <span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span><span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>site_owner<span class="punctuation definition string end lisp">&quot;</span></span> . <span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>hello@cleberg.net<span class="punctuation definition string end lisp">&quot;</span></span><span class="punctuation definition group end lisp">)</span></span>
                  <span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span><span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>site_description<span class="punctuation definition string end lisp">&quot;</span></span> . <span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>Just a blip of ones and zeroes.<span class="punctuation definition string end lisp">&quot;</span></span><span class="punctuation definition group end lisp">)</span></span><span class="punctuation definition group end lisp">)</span></span><span class="punctuation definition group end lisp">)</span></span>

<span class="comment line semicolon lisp"><span class="punctuation definition comment lisp">;</span>; route for rendering the index page of the website
</span><span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span>weblorg<span class="keyword operator arithmetic lisp">-</span>route
 :name <span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>index<span class="punctuation definition string end lisp">&quot;</span></span>
 :input<span class="keyword operator arithmetic lisp">-</span>pattern <span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>content/index.org<span class="punctuation definition string end lisp">&quot;</span></span>
 :template <span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>index.html<span class="punctuation definition string end lisp">&quot;</span></span>
 :output <span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>.build/index.html<span class="punctuation definition string end lisp">&quot;</span></span>
 :url <span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>/<span class="punctuation definition string end lisp">&quot;</span></span><span class="punctuation definition group end lisp">)</span></span>

<span class="comment line semicolon lisp"><span class="punctuation definition comment lisp">;</span>; route for rendering each blog post
</span><span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span>weblorg<span class="keyword operator arithmetic lisp">-</span>route
 :name <span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>blog<span class="punctuation definition string end lisp">&quot;</span></span>
 :input<span class="keyword operator arithmetic lisp">-</span>pattern <span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>content/blog/*.org<span class="punctuation definition string end lisp">&quot;</span></span>
 :template <span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>post.html<span class="punctuation definition string end lisp">&quot;</span></span>
 :output <span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>.build/blog/{{ slug }}.html<span class="punctuation definition string end lisp">&quot;</span></span>
 :url <span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>/blog/{{ slug }}.html<span class="punctuation definition string end lisp">&quot;</span></span><span class="punctuation definition group end lisp">)</span></span>

<span class="comment line semicolon lisp"><span class="punctuation definition comment lisp">;</span>; route for rendering the index page of the blog
</span><span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span>weblorg<span class="keyword operator arithmetic lisp">-</span>route
 :name <span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>blog-index<span class="punctuation definition string end lisp">&quot;</span></span>
 :input<span class="keyword operator arithmetic lisp">-</span>pattern <span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>content/blog/*.org<span class="punctuation definition string end lisp">&quot;</span></span>
 :input<span class="keyword operator arithmetic lisp">-</span>aggregate <span class="constant character lisp"><span class="punctuation definition constant lisp">#</span>&#39;weblorg-input-aggregate-all-desc</span>
 :template <span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>blog.html<span class="punctuation definition string end lisp">&quot;</span></span>
 :output <span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>.build/blog/index.html<span class="punctuation definition string end lisp">&quot;</span></span>
 :url <span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>/blog/<span class="punctuation definition string end lisp">&quot;</span></span><span class="punctuation definition group end lisp">)</span></span>

<span class="comment line semicolon lisp"><span class="punctuation definition comment lisp">;</span>; route for rendering each wiki post
</span><span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span>weblorg<span class="keyword operator arithmetic lisp">-</span>route
 :name <span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>wiki<span class="punctuation definition string end lisp">&quot;</span></span>
 :input<span class="keyword operator arithmetic lisp">-</span>pattern <span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>content/wiki/*.org<span class="punctuation definition string end lisp">&quot;</span></span>
 :template <span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>post.html<span class="punctuation definition string end lisp">&quot;</span></span>
 :output <span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>.build/wiki/{{ slug }}.html<span class="punctuation definition string end lisp">&quot;</span></span>
 :url <span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>/wiki/{{ slug }}.html<span class="punctuation definition string end lisp">&quot;</span></span><span class="punctuation definition group end lisp">)</span></span>

<span class="comment line semicolon lisp"><span class="punctuation definition comment lisp">;</span>; route for rendering the index page of the wiki
</span><span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span>weblorg<span class="keyword operator arithmetic lisp">-</span>route
 :name <span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>wiki-index<span class="punctuation definition string end lisp">&quot;</span></span>
 :input<span class="keyword operator arithmetic lisp">-</span>pattern <span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>content/wiki/*.org<span class="punctuation definition string end lisp">&quot;</span></span>
 :input<span class="keyword operator arithmetic lisp">-</span>aggregate <span class="constant character lisp"><span class="punctuation definition constant lisp">#</span>&#39;weblorg-input-aggregate-all</span>
 :template <span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>wiki.html<span class="punctuation definition string end lisp">&quot;</span></span>
 :output <span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>.build/wiki/index.html<span class="punctuation definition string end lisp">&quot;</span></span>
 :url <span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>/wiki/<span class="punctuation definition string end lisp">&quot;</span></span><span class="punctuation definition group end lisp">)</span></span>

<span class="comment line semicolon lisp"><span class="punctuation definition comment lisp">;</span>; routes for rendering all other pages
</span><span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span>weblorg<span class="keyword operator arithmetic lisp">-</span>route
 :name <span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>pages<span class="punctuation definition string end lisp">&quot;</span></span>
 :input<span class="keyword operator arithmetic lisp">-</span>pattern <span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>content/*.org<span class="punctuation definition string end lisp">&quot;</span></span>
 :template <span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>page.html<span class="punctuation definition string end lisp">&quot;</span></span>
 :output <span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>.build/{{ slug }}.html<span class="punctuation definition string end lisp">&quot;</span></span>
 :url <span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>/{{ slug }}.html<span class="punctuation definition string end lisp">&quot;</span></span><span class="punctuation definition group end lisp">)</span></span>

<span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span>weblorg<span class="keyword operator arithmetic lisp">-</span>route
 :name <span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>salary<span class="punctuation definition string end lisp">&quot;</span></span>
 :input<span class="keyword operator arithmetic lisp">-</span>pattern <span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>content/salary/*.org<span class="punctuation definition string end lisp">&quot;</span></span>
 :template <span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>page.html<span class="punctuation definition string end lisp">&quot;</span></span>
 :output <span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>.build/salary/{{ slug }}.html<span class="punctuation definition string end lisp">&quot;</span></span>
 :url <span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>/salary/{{ slug }}.html<span class="punctuation definition string end lisp">&quot;</span></span><span class="punctuation definition group end lisp">)</span></span>

<span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span>weblorg<span class="keyword operator arithmetic lisp">-</span>route
 :name <span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>services<span class="punctuation definition string end lisp">&quot;</span></span>
 :input<span class="keyword operator arithmetic lisp">-</span>pattern <span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>content/services/*.org<span class="punctuation definition string end lisp">&quot;</span></span>
 :template <span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>page.html<span class="punctuation definition string end lisp">&quot;</span></span>
 :output <span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>.build/services/{{ slug }}.html<span class="punctuation definition string end lisp">&quot;</span></span>
 :url <span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>/services/{{ slug }}.html<span class="punctuation definition string end lisp">&quot;</span></span><span class="punctuation definition group end lisp">)</span></span>

<span class="comment line semicolon lisp"><span class="punctuation definition comment lisp">;</span>; RSS Feed
</span><span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span>weblorg<span class="keyword operator arithmetic lisp">-</span>route
 :name <span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>rss<span class="punctuation definition string end lisp">&quot;</span></span>
 :input<span class="keyword operator arithmetic lisp">-</span>pattern <span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>content/blog/*.org<span class="punctuation definition string end lisp">&quot;</span></span>
 :input<span class="keyword operator arithmetic lisp">-</span>aggregate <span class="constant character lisp"><span class="punctuation definition constant lisp">#</span>&#39;weblorg-input-aggregate-all-desc</span>
 :template <span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>feed.xml<span class="punctuation definition string end lisp">&quot;</span></span>
 :output <span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>.build/feed.xml<span class="punctuation definition string end lisp">&quot;</span></span>
 :url <span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>/feed.xml<span class="punctuation definition string end lisp">&quot;</span></span><span class="punctuation definition group end lisp">)</span></span>

<span class="comment line semicolon lisp"><span class="punctuation definition comment lisp">;</span>; route for static assets that also copies files to .build directory
</span><span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span>weblorg<span class="keyword operator arithmetic lisp">-</span>copy<span class="keyword operator arithmetic lisp">-</span>static
 :output <span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>.build/{{ file }}<span class="punctuation definition string end lisp">&quot;</span></span>
 :url <span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>/{{ file }}<span class="punctuation definition string end lisp">&quot;</span></span><span class="punctuation definition group end lisp">)</span></span>

<span class="comment line semicolon lisp"><span class="punctuation definition comment lisp">;</span>; fire the engine and export all the files declared in the routes above
</span><span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span>weblorg<span class="keyword operator arithmetic lisp">-</span><span class="support function lisp">export</span><span class="punctuation definition group end lisp">)</span></span></span></code></pre>
<h2 id="project"><span class="section-number-2">2.</span> Project</h2>
<h3 id="structure"><span class="section-number-3">2.1.</span> Structure</h3>
<p>The project structure for weblorg is highly customizable and the main restriction is that the <code class="verbatim">publish.el</code> file must point to the correct paths.</p>
<p>For my blog, I prefer to keep the blog content out of the top-level directory. This results in the following structure (shortened for brevity):</p>
<pre><code class="language-txt highlight"><span class="text plain">.build/
content/
    blog/
        example-blog-post.org
        index.org
    wiki/
        example-wiki-post.org
        index.org
    index.org
    other-example-page.org
theme/
    static/
        styles.css
        robots.txt
    templates/
        base.html
        blog.html
        index.html
        page.html
        post.html
        wiki.html
build.sh
publish.el</span></code></pre>
<p>This is simply my preferred structure and you can alter it to fit your needs. The key here really is that you can customize at will, as long as the <code class="verbatim">publish.el</code> file matches.</p>
<h3 id="build-deploy"><span class="section-number-3">2.2.</span> Build &amp; Deploy</h3>
<p>Once you're content with the status of the project, you're ready to build and deploy the blog.</p>
<p>My process utilizes a <code class="verbatim">build.sh</code> script that combines the steps I take every time.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">touch</span></span><span class="meta function-call arguments shell"> build.sh</span> <span class="keyword operator logical and shell">&amp;&amp;</span> <span class="meta function-call shell"><span class="variable function shell">chmod</span></span><span class="meta function-call arguments shell"> +x build.sh</span> <span class="keyword operator logical and shell">&amp;&amp;</span> <span class="meta function-call shell"><span class="variable function shell">nano</span></span><span class="meta function-call arguments shell"> build.sh</span></span></code></pre>
<p>Within this script, I do the following:</p>
<ol>
<li>Remove any files within the <code class="verbatim">.build</code> directory that I use to store published files.</li>
<li>Set the environment variable to <code class="verbatim">prod</code> to ensure the <code class="verbatim">base_url</code> matches my configuration in <code class="verbatim">publish.el</code>.</li>
<li>Build the site with Emacs &amp; <code class="verbatim">publish.el</code>.</li>
<li>Use <code class="verbatim">scp</code> to copy files to my site's public directory on my server.</li>
</ol>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">rm</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>rf</span> .build/<span class="keyword operator regexp quantifier shell">*</span></span> <span class="keyword operator logical and shell">&amp;&amp;</span> <span class="punctuation separator continuation line shell">\
</span><span class="meta function-call shell"><span class="variable function shell">ENV</span></span><span class="meta function-call arguments shell">=prod emacs--script publish.el</span> <span class="keyword operator logical and shell">&amp;&amp;</span> <span class="punctuation separator continuation line shell">\
</span><span class="meta function-call shell"><span class="variable function shell">scp</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>r</span> .build/<span class="keyword operator regexp quantifier shell">*</span> ubuntu:/var/www/cleberg.net/</span></span></code></pre>
<h4 id="time-to-build"><span class="section-number-4">2.2.1.</span> Time to Build</h4>
<p>My only current complaints are:</p>
<ol>
<li>Errors messages are not helpful. It takes work to determine what the error is and where it's coming from. I generally have to sit and watch the build process to see the file that weblorg publishes right before the error occurred.</li>
<li>The build process re-builds every single file on each run, which takes a long time for a blog of my size. See below for the last time I measured.</li>
</ol>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"></span><span class="meta function-call arguments shell"><span class="keyword operator assignment redirection shell">&gt;</span> time ./build.sh</span>

<span class="meta function-call shell"><span class="variable function shell">./build.sh</span></span><span class="meta function-call arguments shell">  35.46s user 0.59s system 85<span class="meta group expansion job shell"><span class="punctuation definition variable job shell">%</span></span> cpu 41.965 total</span></span></code></pre>
<p>Overall, I have thoroughly enjoyed using weblog and will continue to use it going forward until I find something better.</p>
]]></description>
    </item>
    <item>
      <title>Self-Hosting Guide: DDNS Updater</title>
      <link>https://cleberg.net/blog/self-hosting-ddns-updater.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/self-hosting-ddns-updater.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Fri, 15 Mar 2024 00:00:00 +0000</pubDate>
      <category>linux</category>
      <category>self-hosting</category>
      <description><![CDATA[<figure><img src="https://img.cleberg.net/blog/20240315-ddns-updater/ddns.webp" alt="An example of the DDNS Updater app running and showing that cleberg.net's IP has been updated on Cloudflare."><figcaption><span class="figure-number">Figure 1: </span>DDNS Updater Web View</figcaption></figure>
<p><a href="https://github.com/qdm12/ddns-updater">DDNS Updater</a> is a program to keep DNS A and/or AAAA records updated for multiple DNS providers.</p>
<p>If you've read any of my other posts, you'll notice that I have been searching for and using a few different DDNS updating solutions for years. You'll also notice that I love any projects that offer a Docker Compose solution.</p>
<p>Luckily, DDNS Updater fits both of these preferences.</p>
<h2 id="installation"><span class="section-number-2">1.</span> Installation</h2>
<p>To get started, always make sure to review the project's <a href="https://github.com/qdm12/ddns-updater/blob/master/README.md">README</a>. I'll be documenting my steps below, but they may have changed by the time you read this.</p>
<p>The first step is to set up the directories and files required for the project.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">mkdir</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/ddns-updater</span>
<span class="meta function-call shell"><span class="variable function shell">mkdir</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/ddns-updater/data</span>
<span class="meta function-call shell"><span class="variable function shell">touch</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/ddns-updater/data/config.json</span></span></code></pre>
<h3 id="configuration"><span class="section-number-3">1.1.</span> Configuration</h3>
<p>The main configuration you need to update is the <code class="verbatim">data/config.json</code> file. There is a large list of supported providers in the README, but I'm going to use Cloudflare in this example.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">nano</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/ddns-updater/data/config.json</span></span></code></pre>
<p>When setting up the configuration for Cloudflare, you'll need the following:</p>
<ul>
<li>Required Parameters<ul>
<li><code class="verbatim">"zone_identifier"</code> is the Zone ID of your site from the domain overview page</li>
<li><code class="verbatim">"host"</code> is your host and can be <code class="verbatim">"@"</code>, a subdomain or the wildcard <code class="verbatim">"*"</code>. See <a href="https://github.com/qdm12/ddns-updater/issues/243#issuecomment-928313949">this issue comment for context</a>.</li>
<li><code class="verbatim">"ttl"</code> integer value for record TTL in seconds (specify 1 for automatic)</li>
<li>One of the following (<a href="https://developers.cloudflare.com/fundamentals/api/get-started/">how to find API keys</a>):<ul>
<li>Email <code class="verbatim">"email"</code> and Global API Key <code class="verbatim">"key"</code></li>
<li>User service key <code class="verbatim">"user_service_key"</code></li>
<li>API Token <code class="verbatim">"token"</code>, configured with DNS edit permissions for your DNS name's zone</li>
</ul>
</li>
</ul>
</li>
<li>Optional Parameters<ul>
<li><code class="verbatim">"proxied"</code> can be set to <code class="verbatim">true</code> to use the proxy services of Cloudflare</li>
<li><code class="verbatim">"ip_version"</code> can be <code class="verbatim">ipv4</code> (A records), or <code class="verbatim">ipv6</code> (AAAA records) or <code class="verbatim">ipv4 or ipv6</code> (update one of the two, depending on the public ip found). It defaults to <code class="verbatim">ipv4 or ipv6</code>.</li>
<li><code class="verbatim">"ipv6_suffix"</code> is the IPv6 interface identifier suffix to use. It can be for example <code class="verbatim">0:0:0:0:72ad:8fbb:a54e:bedd/64</code>. If left empty, it defaults to no suffix and the raw public IPv6 address obtained is used in the record updating.</li>
</ul>
</li>
</ul>
<pre><code class="language-conf">{
  "settings": [
    {
      "provider": "cloudflare",
      "zone_identifier": "some id",
      "domain": "domain.com",
      "host": "@",
      "ttl": 1,
      "proxied": true,
      "token": "yourtoken",
      "ip_version": "ipv4",
      "ipv6_suffix": ""
    }
  ]
}</code></pre>
<p>Once you have configured the provider of your choice, correct the file and directory permissions and ownership.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="support function cd shell">cd</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/ddns_updater</span>
<span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> Owned by user ID of Docker container (1000)</span><span class="comment line number-sign shell">
</span><span class="meta function-call shell"><span class="variable function shell">chown</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>R</span> 1000 data</span>
<span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> all access (for creating json database file data/updates.json)</span><span class="comment line number-sign shell">
</span><span class="meta function-call shell"><span class="variable function shell">chmod</span></span><span class="meta function-call arguments shell"> 700 data</span>
<span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> read access only</span><span class="comment line number-sign shell">
</span><span class="meta function-call shell"><span class="variable function shell">chmod</span></span><span class="meta function-call arguments shell"> 400 data/config.json</span></span></code></pre>
<h3 id="docker-compose"><span class="section-number-3">1.2.</span> Docker Compose</h3>
<p>After creating the project structure, let's create the <code class="verbatim">docker-compose.yml</code> file.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">nano</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/ddns_-pdater/docker-compose.yml</span></span></code></pre>
<pre><code class="language-config">version: "3.7"
services:
  ddns-updater:
    image: qmcgaw/ddns-updater
    container_name: ddns-updater
    network_mode: bridge
    ports:
      - 8097:8000/tcp # Change the 8097 value to whichever port you want to use
    volumes:
      - ./data:/updater/data
    environment:
      - CONFIG=
      - PERIOD=5m
      - UPDATE_COOLDOWN_PERIOD=5m
      - PUBLICIP_FETCHERS=all
      - PUBLICIP_HTTP_PROVIDERS=all
      - PUBLICIPV4_HTTP_PROVIDERS=all
      - PUBLICIPV6_HTTP_PROVIDERS=all
      - PUBLICIP_DNS_PROVIDERS=all
      - PUBLICIP_DNS_TIMEOUT=3s
      - HTTP_TIMEOUT=10s

      # Web UI
      - LISTENING_ADDRESS=:8000
      - ROOT_URL=/

      # Backup
      - BACKUP_PERIOD=0 # 0 to disable
      - BACKUP_DIRECTORY=/updater/data

      # Other
      - LOG_LEVEL=info
      - LOG_CALLER=hidden
      - SHOUTRRR_ADDRESSES=
    restart: always</code></pre>
<p>After configuring your preferences in the <code class="verbatim">docker-compose.yml</code>, launch the container.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="support function cd shell">cd</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/ddns-updater</span>
<span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> docker-compose up<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>d</span></span></span></code></pre>
<p>If you've launched this on your local machine, you can launch <code class="verbatim">localhost:8097</code> in your browser to see the results.</p>
<h3 id="nginx-reverse-proxy"><span class="section-number-3">1.3.</span> Nginx Reverse Proxy</h3>
<p>If you launched this service on a server, other machine, or just want to access it remotely via a domain name, you can use Nginx as a reverse proxy to expose the service publicly.</p>
<p>Start by creating the Nginx configuration file.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> nano /etc/nginx/sites-available/ddns</span></span></code></pre>
<p>Here's a basic example that should work properly.</p>
<pre><code class="language-conf">server {
    # If using 443, remember to include your ssl_certificate
    # and ssl_certificate_key
    listen [::]:80;
    listen 80;
    server_name ddns.example.com;

    location / {
        set $upstream_ao http://127.0.0.1:9380;
        proxy_pass $upstream_ao;

        # May need some additional proxy_* parameters,
        # see the full example below if necessary
    }
}</code></pre>
<p>Here's a full example that uses my Authelia authentication service to require authentication before someone can access the web page.</p>
<pre><code class="language-conf">server {
    if ($host ~ ^[^.]+\.example\.com$) {
        return 301 https://$host$request_uri;
    }

    listen [::]:80;
    listen 80;
    server_name ddns.example.com;
    return 404;
}

server {
    listen [::]:443 ssl http2;
    listen 443 ssl http2;
    server_name ddns.example.com;
    access_log  /var/log/nginx/ddns.access.log;
    error_log   /var/log/nginx/ddns.error.log;

    add_header X-Content-Type-Options "nosniff";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Frame-Options "DENY";
    add_header Strict-Transport-Security "max-age=63072000; includeSubDomains";
    add_header Referrer-Policy "no-referrer";

    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
    include /etc/letsencrypt/options-ssl-nginx.conf;
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;

    location /authelia {
        internal;
        set $upstream_authelia http://127.0.0.1:9091/api/verify; #change the IP and Port to match the IP and Port of your Authelia container
        proxy_pass_request_body off;
        proxy_pass $upstream_authelia;
        proxy_set_header Content-Length "";

        # Timeout if the real server is dead
        proxy_next_upstream error timeout invalid_header http_500 http_502 http_503;
        client_body_buffer_size 128k;
        proxy_set_header Host $host;
        proxy_set_header X-Original-URL $scheme://$http_host$request_uri;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Forwarded-Host $http_host;
        proxy_set_header X-Forwarded-Uri $request_uri;
        proxy_set_header X-Forwarded-Ssl on;
        proxy_redirect  http://  $scheme://;
        proxy_http_version 1.1;
        proxy_set_header Connection "";
        proxy_cache_bypass $cookie_session;
        proxy_no_cache $cookie_session;
        proxy_buffers 4 32k;

        send_timeout 5m;
        proxy_read_timeout 240;
        proxy_send_timeout 240;
        proxy_connect_timeout 240;
    }

    location / {
        set $upstream_ddns http://127.0.0.1:8097; #change ddns to match your container name: $upstream_some-container-name or $upstream_somecontainername
        proxy_pass $upstream_ddns; #change ddns to match your container name: $upstream_some-container-name or $upstream_somecontainername

        auth_request /authelia;
        auth_request_set $target_url https://$http_host$request_uri;
        auth_request_set $user $upstream_http_remote_user;
        auth_request_set $email $upstream_http_remote_email;
        auth_request_set $groups $upstream_http_remote_groups;
        proxy_set_header Remote-User $user;
        proxy_set_header Remote-Email $email;
        proxy_set_header Remote-Groups $groups;

        error_page 401 =302 https://auth.example.com/?rd=$target_url; #change this to match your authentication domain/subdomain

        client_body_buffer_size 128k;

        proxy_next_upstream error timeout invalid_header http_500 http_502 http_503;

        send_timeout 5m;
        proxy_read_timeout 360;
        proxy_send_timeout 360;
        proxy_connect_timeout 360;

        proxy_set_header Host $host;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection upgrade;
        proxy_set_header Accept-Encoding gzip;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Forwarded-Host $http_host;
        proxy_set_header X-Forwarded-Uri $request_uri;
        proxy_set_header X-Forwarded-Ssl on;
        proxy_redirect  http://  $scheme://;
        proxy_http_version 1.1;
        proxy_set_header Connection "";
        proxy_cache_bypass $cookie_session;
        proxy_no_cache $cookie_session;
        proxy_buffers 64 256k;

        # set_real_ip_from 192.168.1.0/16; #make sure this matches your network setup
        # real_ip_header CF-Connecting-IP;
        # real_ip_recursive on;
    }
}</code></pre>
<p>When complete, simply link the file and restart the web server.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> ln<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>s</span> /etc/nginx/sites-available/ddns /etc/nginx/sites-enabled/ddns</span>
<span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> systemctl restart nginx.service</span></span></code></pre>
<p>Your ddns-updater service will now be available via <code class="verbatim">ddns.example.com</code>!</p>
]]></description>
    </item>
    <item>
      <title>Doom Emacs and Org Mode Setup</title>
      <link>https://cleberg.net/blog/doom-emacs.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/doom-emacs.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Wed, 13 Mar 2024 00:00:00 +0000</pubDate>
      <category>emacs</category>
      <description><![CDATA[<h2 id="screenshots"><span class="section-number-2">1.</span> Screenshots</h2>
<p>These screenshots are showing a project opened with projectile, a treemacs side pane open with the project contents, multiple buffers tiled next to each other, and the help pane open at the bottom.</p>
<p>The themes are <code class="verbatim">doom-homage-white</code> and <code class="verbatim">doom-homage-black</code>.</p>
<figure><img src="https://img.cleberg.net/blog/20240314-doom-emacs/light.webp" alt="An example of the doom-homage-white theme on the Doom dashboard."><figcaption><span class="figure-number">Figure 1: </span>Doom Emacs Light Mode</figcaption></figure>
<figure><img src="https://img.cleberg.net/blog/20240314-doom-emacs/dark.webp" alt="An example of the doom-homage-black theme on the Doom dashboard."><figcaption><span class="figure-number">Figure 2: </span>Doom Emacs Dark Mode</figcaption></figure>
<h2 id="getting-started"><span class="section-number-2">2.</span> Getting Started</h2>
<p>I have been switching back and forth between <a href="https://en.wikipedia.org/wiki/Markdown">markdown</a> and <a href="https://en.wikipedia.org/wiki/Org-mode">org-mode</a> recently for my personal note taking, wiki, and even this blog. As a result, I have been stumbling further into the world of Emacs and found myself at a point where I now prefer to do most of my basic editing within Emacs.</p>
<p>I'll leave the markdown vs. org-mode debate for another post, but I love org-mode's extensibility and interactive nature within Emacs, but it becomes very unwieldy in any other client implementation of org-mode - especially on iOS. On the flip side, markdown is limited in functionality and fractured into different standards, but it's simple and popular enough that there are a plethora of great clients to choose from that will get the job done.</p>
<p>For now, I want to focus on how I have been using Emacs and some of the things that would have helped me learn it faster had I known where to start.</p>
<h3 id="installation"><span class="section-number-3">2.1.</span> Installation</h3>
<p>This post focuses on <a href="https://github.com/doomemacs/doomemacs">Doom Emacs</a>, which is an Emacs framework that provides an alternative experience to the vanilla <a href="https://www.gnu.org/software/emacs/">GNU Emacs</a>.</p>
<p>The <a href="https://github.com/doomemacs/doomemacs/blob/master/docs/getting_started.org">Getting Started Guide</a> has an extremely detailed walkthrough of installation for all systems, so please refer to that guide for up-to-date instructions.</p>
<p>I chose to install on macOS, using the Homebrew option with the <code class="verbatim">railwaycat/emacsmacport</code> version of Emacs.</p>
<p>Once the program is installed, you can run the program by typing <code class="verbatim">emacs</code> in a terminal. If you installed a version of Emacs that supports both a GUI and TUI, you will have to run <code class="verbatim">emacs -nw</code> to get the TUI instead of the default GUI.</p>
<h3 id="configuration"><span class="section-number-3">2.2.</span> Configuration</h3>
<p>Once installed, you can configure Doom by editing the files within the <code class="verbatim">~/.doom.d/</code> directory. This directory holds four files:</p>
<ol>
<li><code class="verbatim">config.el</code> - Personal configuration file</li>
<li><code class="verbatim">custom.el</code> - Custom set variables</li>
<li><code class="verbatim">init.el</code> - Doom modules and load order, must run <code class="verbatim">doom sync</code> after modifying</li>
<li><code class="verbatim">packages.el</code> - Declare packages to install in this file, then run <code class="verbatim">doom sync</code> to install</li>
</ol>
<p>I only needed a few customizations for my configuration, so I'll list them below.</p>
<pre><code class="language-lisp highlight"><span class="source lisp"><span class="comment line semicolon lisp"><span class="punctuation definition comment lisp">;</span>; ~/.doom.d/config.el
</span><span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span><span class="support function lisp">setq</span> doom<span class="keyword operator arithmetic lisp">-</span>theme &#39;doom<span class="keyword operator arithmetic lisp">-</span>homage<span class="keyword operator arithmetic lisp">-</span>black<span class="punctuation definition group end lisp">)</span></span>
<span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span><span class="support function lisp">setq</span> display<span class="keyword operator arithmetic lisp">-</span>line<span class="keyword operator arithmetic lisp">-</span>numbers<span class="keyword operator arithmetic lisp">-</span>type <span class="constant language lisp">t</span><span class="punctuation definition group end lisp">)</span></span>
<span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span><span class="support function lisp">setq</span> org<span class="keyword operator arithmetic lisp">-</span><span class="support function lisp">directory</span> <span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>~/Documents/Notes/<span class="punctuation definition string end lisp">&quot;</span></span><span class="punctuation definition group end lisp">)</span></span>

<span class="comment line semicolon lisp"><span class="punctuation definition comment lisp">;</span>; lengthy org-publish directives at the bottom of the file</span></span></code></pre>
<pre><code class="language-lisp highlight"><span class="source lisp"><span class="comment line semicolon lisp"><span class="punctuation definition comment lisp">;</span>; ~/.doom.d/init.el
</span><span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span>doom! :input
       :completion
       company           <span class="comment line semicolon lisp"><span class="punctuation definition comment lisp">;</span> the ultimate code completion backend
</span>       vertico           <span class="comment line semicolon lisp"><span class="punctuation definition comment lisp">;</span> the search engine of the future
</span>
       :ui
       doom              <span class="comment line semicolon lisp"><span class="punctuation definition comment lisp">;</span> what makes DOOM look the way it does
</span>       doom<span class="keyword operator arithmetic lisp">-</span>dashboard    <span class="comment line semicolon lisp"><span class="punctuation definition comment lisp">;</span> a nifty splash screen for Emacs
</span>       <span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span>emoji <span class="keyword operator arithmetic lisp">+</span>unicode<span class="punctuation definition group end lisp">)</span></span>  <span class="comment line semicolon lisp"><span class="punctuation definition comment lisp">;</span> 🙂
</span>       hl<span class="keyword operator arithmetic lisp">-</span>todo           <span class="comment line semicolon lisp"><span class="punctuation definition comment lisp">;</span> highlight TODO/FIXME/NOTE/DEPRECATED/HACK/REVIEW
</span>       minimap           <span class="comment line semicolon lisp"><span class="punctuation definition comment lisp">;</span> show a map of the code on the side
</span>       modeline          <span class="comment line semicolon lisp"><span class="punctuation definition comment lisp">;</span> snazzy, Atom-inspired modeline, plus API
</span>       ophints           <span class="comment line semicolon lisp"><span class="punctuation definition comment lisp">;</span> highlight the region an operation acts on
</span>       <span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span>popup <span class="keyword operator arithmetic lisp">+</span>defaults<span class="punctuation definition group end lisp">)</span></span>   <span class="comment line semicolon lisp"><span class="punctuation definition comment lisp">;</span> tame sudden yet inevitable temporary windows
</span>       tabs              <span class="comment line semicolon lisp"><span class="punctuation definition comment lisp">;</span> a tab bar for Emacs
</span>       treemacs          <span class="comment line semicolon lisp"><span class="punctuation definition comment lisp">;</span> a project drawer, like neotree but cooler
</span>       <span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span>vc<span class="keyword operator arithmetic lisp">-</span>gutter <span class="keyword operator arithmetic lisp">+</span>pretty<span class="punctuation definition group end lisp">)</span></span> <span class="comment line semicolon lisp"><span class="punctuation definition comment lisp">;</span> vcs diff in the fringe
</span>       vi<span class="keyword operator arithmetic lisp">-</span>tilde<span class="keyword operator arithmetic lisp">-</span>fringe   <span class="comment line semicolon lisp"><span class="punctuation definition comment lisp">;</span> fringe tildes to mark beyond EOB
</span>       workspaces        <span class="comment line semicolon lisp"><span class="punctuation definition comment lisp">;</span> tab emulation, persistence &amp; separate workspaces
</span>
       :editor
       <span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span>evil <span class="keyword operator arithmetic lisp">+</span>everywhere<span class="punctuation definition group end lisp">)</span></span><span class="comment line semicolon lisp"><span class="punctuation definition comment lisp">;</span> come to the dark side, we have cookies
</span>       file<span class="keyword operator arithmetic lisp">-</span>templates    <span class="comment line semicolon lisp"><span class="punctuation definition comment lisp">;</span> auto-snippets for empty files
</span>       fold              <span class="comment line semicolon lisp"><span class="punctuation definition comment lisp">;</span> (nigh) universal code folding
</span>       snippets          <span class="comment line semicolon lisp"><span class="punctuation definition comment lisp">;</span> my elves. They type so I don&#39;t have to
</span>
       :emacs
       dired             <span class="comment line semicolon lisp"><span class="punctuation definition comment lisp">;</span> making dired pretty [functional]
</span>       electric          <span class="comment line semicolon lisp"><span class="punctuation definition comment lisp">;</span> smarter, keyword-based electric-indent
</span>       undo              <span class="comment line semicolon lisp"><span class="punctuation definition comment lisp">;</span> persistent, smarter undo for your inevitable mistakes
</span>       vc                <span class="comment line semicolon lisp"><span class="punctuation definition comment lisp">;</span> version-control and Emacs, sitting in a tree
</span>
       :term
       term              <span class="comment line semicolon lisp"><span class="punctuation definition comment lisp">;</span> basic terminal emulator for Emacs
</span>
       :checkers
       syntax              <span class="comment line semicolon lisp"><span class="punctuation definition comment lisp">;</span> tasing you for every semicolon you forget
</span>
       :tools
       <span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span><span class="support function lisp">eval</span> <span class="keyword operator arithmetic lisp">+</span>overlay<span class="punctuation definition group end lisp">)</span></span>     <span class="comment line semicolon lisp"><span class="punctuation definition comment lisp">;</span> run code, run (also, repls)
</span>       lookup              <span class="comment line semicolon lisp"><span class="punctuation definition comment lisp">;</span> navigate your code and its documentation
</span>       magit             <span class="comment line semicolon lisp"><span class="punctuation definition comment lisp">;</span> a git porcelain for Emacs
</span>
       :os
       <span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span>:<span class="keyword control lisp">if</span> <span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span>featurep :system &#39;macos<span class="punctuation definition group end lisp">)</span></span> macos<span class="punctuation definition group end lisp">)</span></span>  <span class="comment line semicolon lisp"><span class="punctuation definition comment lisp">;</span> improve compatibility with macOS
</span>
       :lang
       common<span class="keyword operator arithmetic lisp">-</span>lisp       <span class="comment line semicolon lisp"><span class="punctuation definition comment lisp">;</span> if you&#39;ve seen one lisp, you&#39;ve seen them all
</span>       emacs<span class="keyword operator arithmetic lisp">-</span>lisp        <span class="comment line semicolon lisp"><span class="punctuation definition comment lisp">;</span> drown in parentheses
</span>       markdown          <span class="comment line semicolon lisp"><span class="punctuation definition comment lisp">;</span> writing docs for people to ignore
</span>       org               <span class="comment line semicolon lisp"><span class="punctuation definition comment lisp">;</span> organize your plain life in plain text
</span>       python            <span class="comment line semicolon lisp"><span class="punctuation definition comment lisp">;</span> beautiful is better than ugly
</span>       sh                  <span class="comment line semicolon lisp"><span class="punctuation definition comment lisp">;</span> she sells {ba,z,fi}sh shells on the C xor
</span>
       :app
       irc               <span class="comment line semicolon lisp"><span class="punctuation definition comment lisp">;</span> how neckbeards socialize
</span>       <span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span>rss <span class="keyword operator arithmetic lisp">+</span>org<span class="punctuation definition group end lisp">)</span></span>        <span class="comment line semicolon lisp"><span class="punctuation definition comment lisp">;</span> emacs as an RSS reader
</span>
       <span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span>default <span class="keyword operator arithmetic lisp">+</span>bindings <span class="keyword operator arithmetic lisp">+</span>smartparens<span class="punctuation definition group end lisp">)</span></span><span class="punctuation definition group end lisp">)</span></span></span></code></pre>
<p>If you're editing these files within Doom directly, remember to run <code class="verbatim">SPC h r r</code> to reload the configuration. Also remember to run <code class="verbatim">doom sync</code> for any changes to the <code class="verbatim">init.el</code> or <code class="verbatim">packages.el</code> files.</p>
<h2 id="basic-functionality"><span class="section-number-2">3.</span> Basic Functionality</h2>
<p>I kept a cheat sheet note open at first with all of the basic functions typed out, copied as I went through the tutorial. After a little while, I no longer needed it. I highly recommend writing down the most applicable shortcuts for your preferred functionality and refer back to it until you've memorized it.</p>
<p>Memorizing the shortcuts will differ based on the type of Emacs framework being used. Personally, migrating from vanilla Emacs to Doom Emacs simplified everything by a large factor and instantly enabled me to start working on my projects, eliminating most of the hurdles I was running into. The vanilla emacs hotkeys became obnoxious and I actually stopped using Emacs entirely for about a month before trying Doom.</p>
<p>For me, the first logical step is to interact with the local filesystem. To do this, I needed to know how to open directories, open files, save files, discard changes, close files, and switch between open files. Here are some example shortcuts I've written down in order to accomplish file-based actions.</p>
<table>
<thead>
<tr><th>Doom Hotkey</th><th>Emacs Hotkey</th><th>Description</th></tr>
</thead>
<tbody>
<tr><td><code class="verbatim">SPC :</code></td><td><code class="verbatim">C-x</code></td><td>Run functions</td></tr>
<tr><td><code class="verbatim">SPC f f</code></td><td><code class="verbatim">C-x f</code></td><td>Open file in buffer</td></tr>
<tr><td><code class="verbatim">SPC f d</code></td><td><code class="verbatim">C-x d</code></td><td>Open directory with <code class="verbatim">dired</code></td></tr>
<tr><td><code class="verbatim">i</code></td><td><code class="verbatim">C-x C-q</code></td><td>Edit current buffer (insert mode)</td></tr>
<tr><td><code class="verbatim">q</code></td><td><code class="verbatim">C-x C-q</code></td><td>Quit out of insert mode</td></tr>
<tr><td><code class="verbatim">SPC f s</code></td><td><code class="verbatim">C-x s</code></td><td>Save current buffer</td></tr>
<tr><td><code class="verbatim">SPC b k</code></td><td><code class="verbatim">C-x k</code></td><td>Kill current buffer</td></tr>
<tr><td><code class="verbatim">SPC w h/j/k/l</code></td><td><code class="verbatim">C-x o</code><sup class="footnote-ref"><a id="fnr-1" href="#fn-1">1</a></sup></td><td>Move left/down/up/right to next buffer</td></tr>
</tbody>
</table>
<p>In general, when in Doom, you can press <code class="verbatim">SPC</code> and wait a second for the help pane to appear with all available hotkey options. For example, you can press <code class="verbatim">SPC</code>, wait for the help pane, and then select a key such as <code class="verbatim">g</code> to enter the git help pane and explore further command options.</p>
<h2 id="editing"><span class="section-number-2">4.</span> Editing</h2>
<p>Next in my process is to dive into editing for any languages I'm currently using. In this post, I will just cover Markdown and Org-Mode but I have also been slowly adoping some Python and general web dev tools as well.</p>
<h3 id="markdown"><span class="section-number-3">4.1.</span> Markdown</h3>
<figure><img src="https://img.cleberg.net/blog/20240314-doom-emacs/markdown.webp" alt="An editing buffer opened to a markdown file."><figcaption><span class="figure-number">Figure 3: </span>Markdown Preview</figcaption></figure>
<p>Markdown is fairly simple as the syntax is limited, so just make sure the <code class="verbatim">~/.doom.d/init.el</code> includes the <code class="verbatim">markdown</code> declaration in the <code class="verbatim">:lang</code> section.</p>
<p>This package includes the following hotkey menus. The insert and toggle menu expands further, allowing you to insert various markdown elements and toggle things like link hiding.</p>
<table>
<thead>
<tr><th>Doom Hotkey</th><th>Function</th></tr>
</thead>
<tbody>
<tr><td><code class="verbatim">SPC m '</code></td><td>markdown-edit-code-block</td></tr>
<tr><td><code class="verbatim">SPC m e</code></td><td>markdown-export</td></tr>
<tr><td><code class="verbatim">SPC m i</code></td><td>+insert</td></tr>
<tr><td><code class="verbatim">SPC m o</code></td><td>markdown-open</td></tr>
<tr><td><code class="verbatim">SPC m p</code></td><td>markdown-preview</td></tr>
<tr><td><code class="verbatim">SPC m t</code></td><td>+toggle</td></tr>
<tr><td><code class="verbatim">SPC : markdown-table-align</code></td><td>markdown-table-align</td></tr>
</tbody>
</table>
<h3 id="org-mode"><span class="section-number-3">4.2.</span> Org-Mode</h3>
<figure><img src="https://img.cleberg.net/blog/20240314-doom-emacs/org.webp" alt="An editing buffer opened to an org-mode file."><figcaption><span class="figure-number">Figure 4: </span>Org-Mode Preview</figcaption></figure>
<p>Similar to the markdown section above, ensure that the <code class="verbatim">~/.doom.d/init.el</code> includes the <code class="verbatim">org</code> declaration in the <code class="verbatim">:lang</code> section.</p>
<p>There are a few hot keys, but a quick search with <code class="verbatim">SPC : org</code> shows that there are 865 possible org-related functions you can run. I won't possibly be able to list them all, so I will simply cover a few of the basic commands I use myself.</p>
<table>
<thead>
<tr><th>Doom Hotkey</th><th>Function</th></tr>
</thead>
<tbody>
<tr><td><code class="verbatim">SPC m t</code></td><td>org-todo</td></tr>
<tr><td><code class="verbatim">SPC n t</code></td><td>org-todo-list</td></tr>
<tr><td><code class="verbatim">SPC o A</code></td><td>org-agenda</td></tr>
<tr><td><code class="verbatim">SPC X</code></td><td>org-capture</td></tr>
<tr><td><code class="verbatim">SPC m p p</code></td><td>org-priority</td></tr>
<tr><td><code class="verbatim">SPC m d s</code></td><td>org-schedule</td></tr>
<tr><td><code class="verbatim">TAB</code></td><td>org-cycle</td></tr>
<tr><td><code class="verbatim">SHIFT TAB</code></td><td>Collapse/open all headings in buffer</td></tr>
<tr><td><code class="verbatim">M-q</code></td><td>Format/wrap current section</td></tr>
<tr><td><code class="verbatim">M-Left/Right</code></td><td>Demote/promote current heading</td></tr>
<tr><td><code class="verbatim">M-Down/Up</code></td><td>Shift current heading section down/up</td></tr>
</tbody>
</table>
<ol>
<li><p>Org-Publish</p>
<p>Org includes a <a href="https://orgmode.org/manual/Publishing.html">publishing management system</a> by default that allows you to export org files to Org, iCalendar, HTML, LaTex, Markdown, ODT, and Plain Text. Most of these can be exported into another buffer and opened, or simply to an external file.</p>
<p>While inside an org file, simply run <code class="verbatim">SPC m e</code> or <code class="verbatim">M-x org-export-dispatch</code> to open the export menu. This menu will show all options and ask you to select an option. If you want to export to HTML, simply press <code class="verbatim">h</code> and then <code class="verbatim">H</code> (As HTML buffer), <code class="verbatim">h</code> (As HTML file), or <code class="verbatim">o</code> (As HTML file and open).</p>
</li>
<li><p>Projects</p>
<p>Some publishing options are easier with a defined project in Emacs. To create a project within Emacs, I use two methods:</p>
<ol>
<li>Add the project via the projectile command <code class="verbatim">SPC p a</code>. Does not always work for me.</li>
<li>Add an empty <code class="verbatim">.projectile</code> file in the project root.</li>
</ol>
<p>Once a project has been created, you can create custom publishing actions within your <code class="verbatim">~/.doom.d/config.el</code> file. For example, here's a test project I created to try and convert this blog to org-mode recently.</p>
<pre><code class="language-lisp highlight"><span class="source lisp"><span class="comment line semicolon lisp"><span class="punctuation definition comment lisp">;</span>; org-publish
</span><span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span><span class="support function lisp">require</span> &#39;ox<span class="keyword operator arithmetic lisp">-</span>publish<span class="punctuation definition group end lisp">)</span></span>

<span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span><span class="meta function lisp"><span class="storage type function-type lisp">defun</span> <span class="entity name function lisp">my</span></span><span class="keyword operator arithmetic lisp">/</span>org<span class="keyword operator arithmetic lisp">-</span>sitemap<span class="keyword operator arithmetic lisp">-</span>date<span class="keyword operator arithmetic lisp">-</span>entry<span class="keyword operator arithmetic lisp">-</span><span class="support function lisp">format</span> <span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span>entry style project<span class="punctuation definition group end lisp">)</span></span> <span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>Format ENTRY in
  org-publish PROJECT Sitemap format ENTRY ENTRY STYLE format that includes
  date.<span class="punctuation definition string end lisp">&quot;</span></span> <span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span><span class="keyword control lisp">let</span> <span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span><span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span>filename <span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span>org<span class="keyword operator arithmetic lisp">-</span>publish<span class="keyword operator arithmetic lisp">-</span><span class="support function lisp">find</span><span class="keyword operator arithmetic lisp">-</span>title entry project<span class="punctuation definition group end lisp">)</span></span><span class="punctuation definition group end lisp">)</span></span><span class="punctuation definition group end lisp">)</span></span> <span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span><span class="keyword control lisp">if</span> <span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span><span class="keyword operator comparison lisp">=</span> <span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span><span class="support function lisp">length</span>
  filename<span class="punctuation definition group end lisp">)</span></span> <span class="constant numeric lisp">0</span><span class="punctuation definition group end lisp">)</span></span> <span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span><span class="support function lisp">format</span> <span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>*%s*<span class="punctuation definition string end lisp">&quot;</span></span> entry<span class="punctuation definition group end lisp">)</span></span> <span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span><span class="support function lisp">format</span> <span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>{{{timestamp(%s)}}}
  [[file:%s][%s]]<span class="punctuation definition string end lisp">&quot;</span></span> <span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span><span class="support function lisp">format</span><span class="keyword operator arithmetic lisp">-</span><span class="support function lisp">time</span><span class="keyword operator arithmetic lisp">-</span><span class="support function lisp">string</span> <span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>%Y-%m-%d<span class="punctuation definition string end lisp">&quot;</span></span> <span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span>org<span class="keyword operator arithmetic lisp">-</span>publish<span class="keyword operator arithmetic lisp">-</span><span class="support function lisp">find</span><span class="keyword operator arithmetic lisp">-</span>date entry
  project<span class="punctuation definition group end lisp">)</span></span><span class="punctuation definition group end lisp">)</span></span> entry filename<span class="punctuation definition group end lisp">)</span></span><span class="punctuation definition group end lisp">)</span></span><span class="punctuation definition group end lisp">)</span></span><span class="punctuation definition group end lisp">)</span></span>

<span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span><span class="support function lisp">setq</span> org<span class="keyword operator arithmetic lisp">-</span><span class="support function lisp">export</span><span class="keyword operator arithmetic lisp">-</span>global<span class="keyword operator arithmetic lisp">-</span>macros &#39;<span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span><span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span><span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>timestamp<span class="punctuation definition string end lisp">&quot;</span></span> . <span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>@@html:&lt;time datetime=&#39;[$1]&#39;
      class=&#39;timestamp&#39;&gt;[$1]&lt;/time&gt;@@<span class="punctuation definition string end lisp">&quot;</span></span><span class="punctuation definition group end lisp">)</span></span><span class="punctuation definition group end lisp">)</span></span><span class="punctuation definition group end lisp">)</span></span>

<span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span><span class="support function lisp">setq</span> org<span class="keyword operator arithmetic lisp">-</span>publish<span class="keyword operator arithmetic lisp">-</span>project<span class="keyword operator arithmetic lisp">-</span>alist
      `<span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span><span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span><span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>blog<span class="punctuation definition string end lisp">&quot;</span></span>
         :base<span class="keyword operator arithmetic lisp">-</span><span class="support function lisp">directory</span> <span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>~/Source/cleberg.net/<span class="punctuation definition string end lisp">&quot;</span></span>
         :base<span class="keyword operator arithmetic lisp">-</span>extension <span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>org<span class="punctuation definition string end lisp">&quot;</span></span>
         :recursive <span class="constant language lisp">t</span>
         :publishing<span class="keyword operator arithmetic lisp">-</span><span class="support function lisp">directory</span> <span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>~/Source/cleberg.net/public/<span class="punctuation definition string end lisp">&quot;</span></span>
         :publishing<span class="keyword operator arithmetic lisp">-</span>function org<span class="keyword operator arithmetic lisp">-</span>html<span class="keyword operator arithmetic lisp">-</span>publish<span class="keyword operator arithmetic lisp">-</span><span class="keyword control lisp">to</span><span class="keyword operator arithmetic lisp">-</span>html
         <span class="comment line semicolon lisp"><span class="punctuation definition comment lisp">;</span>; HTML5
</span>         :html<span class="keyword operator arithmetic lisp">-</span>doctype <span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>html5<span class="punctuation definition string end lisp">&quot;</span></span>
         :html<span class="keyword operator arithmetic lisp">-</span>html5<span class="keyword operator arithmetic lisp">-</span>fancy <span class="constant language lisp">t</span>
         <span class="comment line semicolon lisp"><span class="punctuation definition comment lisp">;</span>; Disable some Org&#39;s HTML defaults
</span>         :html<span class="keyword operator arithmetic lisp">-</span>head<span class="keyword operator arithmetic lisp">-</span>include<span class="keyword operator arithmetic lisp">-</span>scripts <span class="constant language lisp">nil</span>
         :html<span class="keyword operator arithmetic lisp">-</span>head<span class="keyword operator arithmetic lisp">-</span>include<span class="keyword operator arithmetic lisp">-</span>default<span class="keyword operator arithmetic lisp">-</span>style <span class="constant language lisp">nil</span>
         :section<span class="keyword operator arithmetic lisp">-</span>numbers <span class="constant language lisp">nil</span>
         :<span class="keyword control lisp">with</span><span class="keyword operator arithmetic lisp">-</span>title <span class="constant language lisp">nil</span>
         <span class="comment line semicolon lisp"><span class="punctuation definition comment lisp">;</span>; Sitemap
</span>         :auto<span class="keyword operator arithmetic lisp">-</span>sitemap <span class="constant language lisp">t</span>
         :sitemap<span class="keyword operator arithmetic lisp">-</span>title: <span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>Sitemap<span class="punctuation definition string end lisp">&quot;</span></span>
         :sitemap<span class="keyword operator arithmetic lisp">-</span><span class="support function lisp">sort</span><span class="keyword operator arithmetic lisp">-</span>files anti<span class="keyword operator arithmetic lisp">-</span>chronologically
         <span class="comment line semicolon lisp"><span class="punctuation definition comment lisp">;</span> :sitemap-function my/org-sitemap-date-entry-format
</span>         <span class="comment line semicolon lisp"><span class="punctuation definition comment lisp">;</span>; Customize HTML output
</span>         :html<span class="keyword operator arithmetic lisp">-</span>divs <span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span><span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span>preamble <span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>header<span class="punctuation definition string end lisp">&quot;</span></span> <span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>preamble<span class="punctuation definition string end lisp">&quot;</span></span><span class="punctuation definition group end lisp">)</span></span>
                     <span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span>content <span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>main<span class="punctuation definition string end lisp">&quot;</span></span> <span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>content<span class="punctuation definition string end lisp">&quot;</span></span><span class="punctuation definition group end lisp">)</span></span>
                     <span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span>postamble <span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>footer<span class="punctuation definition string end lisp">&quot;</span></span> <span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>postamble<span class="punctuation definition string end lisp">&quot;</span></span><span class="punctuation definition group end lisp">)</span></span><span class="punctuation definition group end lisp">)</span></span>
         :html<span class="keyword operator arithmetic lisp">-</span>head <span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>&lt;meta name=&#39;theme-color&#39; content=&#39;#111&#39; media=&#39;(prefers-color-scheme: dark)&#39;&gt;
                     &lt;meta name=&#39;theme-color&#39; content=&#39;#fff&#39; media=&#39;(prefers-color-scheme: light)&#39;&gt;
                     &lt;link rel=&#39;stylesheet&#39; href=&#39;/syntax-theme-dark.css&#39; media=&#39;(prefers-color-scheme: dark)&#39;&gt;
                     &lt;link rel=&#39;stylesheet&#39; href=&#39;/syntax-theme-light.css&#39; media=&#39;(prefers-color-scheme: light)&#39;&gt;
                     &lt;link rel=&#39;stylesheet&#39; href=&#39;/styles.css&#39; type=&#39;text/css&#39;&gt;<span class="punctuation definition string end lisp">&quot;</span></span>
         :html<span class="keyword operator arithmetic lisp">-</span>preamble <span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>&lt;nav class=&#39;site-nav&#39; aria-label=&#39;site-nav&#39; role=&#39;navigation&#39;&gt;
                &lt;ul&gt;
                        &lt;li&gt;&lt;a href=&#39;/&#39;&gt;Home&lt;/a&gt;&lt;/li&gt;
                        &lt;li&gt;&lt;a href=&#39;/blog/&#39;&gt;Blog&lt;/a&gt;&lt;/li&gt;
                        &lt;li&gt;&lt;a href=&#39;/services/&#39;&gt;Services&lt;/a&gt;&lt;/li&gt;
                        &lt;li&gt;&lt;a href=&#39;/wiki/&#39;&gt;Wiki&lt;/a&gt;&lt;/li&gt;
                &lt;/ul&gt;&lt;/nav&gt;
                &lt;h1&gt;%t&lt;/h1&gt;
                &lt;time datetime=&#39;%d&#39;&gt;%d&lt;/time&gt;<span class="punctuation definition string end lisp">&quot;</span></span>
         :html<span class="keyword operator arithmetic lisp">-</span>postamble <span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>
                &lt;p&gt;Last build: %T&lt;/p&gt;
                &lt;p&gt;Created with %c&lt;/p&gt;<span class="punctuation definition string end lisp">&quot;</span></span>
        <span class="punctuation definition group end lisp">)</span></span>

        <span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span><span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>static<span class="punctuation definition string end lisp">&quot;</span></span>
         :base<span class="keyword operator arithmetic lisp">-</span><span class="support function lisp">directory</span> <span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>~/Source/cleberg.net/static/<span class="punctuation definition string end lisp">&quot;</span></span>
         :base<span class="keyword operator arithmetic lisp">-</span>extension <span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>css<span class="constant character escape lisp">\\</span>|txt<span class="constant character escape lisp">\\</span>|jpg<span class="constant character escape lisp">\\</span>|gif<span class="constant character escape lisp">\\</span>|png<span class="punctuation definition string end lisp">&quot;</span></span>
         :recursive <span class="constant language lisp">t</span>
         :publishing<span class="keyword operator arithmetic lisp">-</span><span class="support function lisp">directory</span>  <span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>~/Source/cleberg.net/public/<span class="punctuation definition string end lisp">&quot;</span></span>
         :publishing<span class="keyword operator arithmetic lisp">-</span>function org<span class="keyword operator arithmetic lisp">-</span>publish<span class="keyword operator arithmetic lisp">-</span>attachment<span class="punctuation definition group end lisp">)</span></span>

        <span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span><span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>cleberg.net<span class="punctuation definition string end lisp">&quot;</span></span> :components <span class="meta group lisp"><span class="punctuation definition group begin lisp">(</span><span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>blog<span class="punctuation definition string end lisp">&quot;</span></span> <span class="string quoted double lisp"><span class="punctuation definition string begin lisp">&quot;</span>static<span class="punctuation definition string end lisp">&quot;</span></span><span class="punctuation definition group end lisp">)</span></span><span class="punctuation definition group end lisp">)</span></span><span class="punctuation definition group end lisp">)</span></span><span class="punctuation definition group end lisp">)</span></span></span></code></pre>
</li>
</ol>
<h2 id="general-thoughts"><span class="section-number-2">5.</span> General Thoughts</h2>
<p>I have enjoyed Doom Emacs (far more than GNU Emacs) and will likely continue to use it as my main editor for the time being. Org-Mode is certainly the largest factor here, as I far prefer it over Markdown due to its inherent features and detailed markup options. However, working with org-mode on iOS has been a pain and I will have to see if there's an easier way to resolve those issues or if going back to separate Markdown, Reminders, and Calendar apps is easier to work with than an all-in-one org solution.</p>
<section class="footnotes" aria-label="Footnotes">
<hr>
<ol>
<li id="fn-1"><p>Doom's evil-window functionality is a bit different from GNU Emacs, but you can always switch to the "other" buffer with <code class="verbatim">C-x o</code> or <code class="verbatim">C-x b</code> to get a list of buffers to select.</p>
 <a class="footnote-back" href="#fnr-1" aria-label="Back to reference 1">&#8617;</a></li>
</ol>
</section>
]]></description>
    </item>
    <item>
      <title>Self-Hosting Guide: Otter Wiki</title>
      <link>https://cleberg.net/blog/self-hosting-otter-wiki.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/self-hosting-otter-wiki.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Wed, 21 Feb 2024 00:00:00 +0000</pubDate>
      <category>linux</category>
      <category>self-hosting</category>
      <description><![CDATA[<h2 id="an-otter-wiki"><span class="section-number-2">1.</span> An Otter Wiki</h2>
<p><a href="https://otterwiki.com/">An Otter Wiki</a> is an easy to use wiki software that takes almost no effort to set up and maintain.</p>
<h2 id="installation"><span class="section-number-2">2.</span> Installation</h2>
<p>To install An Otter Wiki, I'm going to use Docker Compose to create the container and then use Nginx as a reverse proxy to allow external access via a subdomain I own.</p>
<h3 id="docker-compose"><span class="section-number-3">2.1.</span> Docker Compose</h3>
<p>Start by creating a directory for the container's files.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">mkdir</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/otterwiki</span></span></code></pre>
<p>Next, create the <code class="verbatim">docker-compose.yml</code> file to define the container's parameters.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">nano</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/otterwiki/docker-compose.yml</span></span></code></pre>
<p>Within the file, paste the following content. You can read the project's documentation if you want to further override or customize the container.</p>
<pre><code class="language-conf">version: '3'
services:
  otterwiki:
    image: redimp/otterwiki:2
    restart: unless-stopped
    # Internal port must be assigned to port 80
    # External port can be customized
    ports:
      - 8337:80
    volumes:
      - ./app-data:/app-data</code></pre>
<p>Once the file is saved and closed, you can launch the container.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="support function cd shell">cd</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/otterwiki</span>
<span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> docker-compose up<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>d</span></span></span></code></pre>
<p>The container is now available at <code class="verbatim">localhost:8337</code>. Next, we will use Nginx to serve this app externally.</p>
<h3 id="nginx"><span class="section-number-3">2.2.</span> Nginx</h3>
<p>To access the app externally, let's set up a reverse proxy. I'll start by creating the Nginx configuration file for my wiki.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> nano /etc/nginx/sites-available/wiki</span></span></code></pre>
<p>Within the file, I have saved the following content. This assumes you already have a TLS/SSL cert to use with this subdomain. If not, simply remove the <code class="verbatim">ssl_*</code> variables, remove the <code class="verbatim">80</code> server block, and change the <code class="verbatim">443</code> server block to <code class="verbatim">80</code> to serve the app without SSL.</p>
<pre><code class="language-conf">server {
    if ($host ~ ^[^.]+\.example\.com$) {
        return 301 https://$host$request_uri;
    }

    listen [::]:80;
    listen 80;
    server_name wiki.example.com;
    return 404;
}

server {
    listen [::]:443 ssl http2;
    listen 443 ssl http2;
    server_name wiki.example.com;
    access_log  /var/log/nginx/wiki.access.log;
    error_log   /var/log/nginx/wiki.error.log;

    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
    include /etc/letsencrypt/options-ssl-nginx.conf;
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;

    location / {
            set $upstream_wiki http://127.0.0.1:8337;
            proxy_pass $upstream_wiki;

        proxy_set_header Host $http_host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Host $http_host;
    }
}</code></pre>
<p>Save and close the configuration file. On Nginx, we need to symlink the file to enable it.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> ln<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>s</span> /etc/nginx/sites-available/wiki /etc/nginx/sites-enabled/wiki</span></span></code></pre>
<p>Once enabled, restart the Nginx server to start serving the app externally.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> systemctl restart nginx.service</span></span></code></pre>
]]></description>
    </item>
    <item>
      <title>Ubuntu Emergency Mode: Bad /etc/fstab Fix</title>
      <link>https://cleberg.net/blog/ubuntu-emergency-mode.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/ubuntu-emergency-mode.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Tue, 13 Feb 2024 00:00:00 +0000</pubDate>
      <category>linux</category>
      <description><![CDATA[<h2 id="the-problem"><span class="section-number-2">1.</span> The Problem</h2>
<p>I recently <a href="zfs.html">migrated my hard drives to a ZFS pool</a> and found myself stuck in Ubuntu's emergency mode after the first reboot I performed after creating the ZFS pool.</p>
<p>My server was stuck in the boot process and showed the following error on the screen:</p>
<pre><code class="language-txt highlight"><span class="text plain">You are in emergency mode.
After logging in, type &quot;journalctl -xb&quot; to view system logs,
&quot;systemctl reboot&quot; to reboot, &quot;systemctl default&quot;
or ^D to try again to boot into default mode&quot;.</span></code></pre>
<p>After rebooting the server and watching the logs scroll on a monitor, I noticed the root cause was related to a very long search for certain drives. I kept seeing errors like this:</p>
<pre><code class="language-txt highlight"><span class="text plain">[ TIME ] Timed out waiting of device dev-disk-by/[disk-uuid]</span></code></pre>
<p>I realized that I had not removed the <code class="verbatim">/etc/fstab</code> references that asked Ubuntu to mount two disks on boot, but I had recently changed those disks to be part of my ZFS pool instead. Therefore, Ubuntu was trying to identify and mount a disk that was not available.</p>
<p>Now that we have an idea of the issue, let's move to solution.</p>
<h2 id="the-solution"><span class="section-number-2">2.</span> The Solution</h2>
<p>In order to fix the issue, I waited until I was allowed to type the root user's password, and then I executed the following command:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">nano</span></span><span class="meta function-call arguments shell"> /etc/fstab</span></span></code></pre>
<p>Within the <code class="verbatim">fstab</code> file, I needed to comment/remove the following lines at the bottom of the file. You can comment-out a line by prepending a <code class="verbatim">#</code> symbol at the beginning of the line. You can also delete the line entirely.</p>
<pre><code class="language-conf"># What it looked like when running into the issue:
UUID=B64E53824E5339F7 /mnt/white-01 ntfs-3g uid=1000,gid=1000 0 0
UUID=E69867E59867B32B /mnt/white-02 ntfs-3g uid=1000,gid=1000 0 0

# What I changed it to, in order to fix the issue:
# UUID=B64E53824E5339F7 /mnt/white-01 ntfs-3g uid=1000,gid=1000 0 0
# UUID=E69867E59867B32B /mnt/white-02 ntfs-3g uid=1000,gid=1000 0 0</code></pre>
<p>Once removing the lines above from the <code class="verbatim">/etc/fstab</code> file, save and exit the file by hitting the <code class="verbatim">Ctrl</code> + <code class="verbatim">x</code> key combo.</p>
<p>You can now hit <code class="verbatim">Ctrl</code> + <code class="verbatim">D</code> to continue, or reboot:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">systemctl</span></span><span class="meta function-call arguments shell"> reboot</span></span></code></pre>
<p>Once rebooted, I was able to watch the machine boot properly and launch to the TTY login screen without errors!</p>
]]></description>
    </item>
    <item>
      <title>ZFS Storage Pools on Ubuntu</title>
      <link>https://cleberg.net/blog/zfs.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/zfs.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Tue, 06 Feb 2024 00:00:00 +0000</pubDate>
      <category>linux</category>
      <description><![CDATA[<p>This post details the process I used to create ZFS pools, datasets, and snapshots on Ubuntu Server.</p>
<p>I found the following pages very helpful while going through this process:</p>
<ul>
<li><a href="https://ubuntu.com/tutorials/setup-zfs-storage-pool">Setup a ZFS storage pool</a></li>
<li><a href="https://wiki.ubuntu.com/Kernel/Reference/ZFS">Kernel/Reference/ZFS</a></li>
<li><a href="https://blog.victormendonca.com/2020/11/03/zfs-for-dummies/">ZFS for Dummies</a></li>
</ul>
<h2 id="installation"><span class="section-number-2">1.</span> Installation</h2>
<p>To start, I installed the ZFS package with the following command:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> apt install zfsutils-linux</span></span></code></pre>
<p>Once installed, you can check the version to see if it installed correctly.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"></span><span class="meta function-call arguments shell"><span class="keyword operator assignment redirection shell">&gt;</span> zsf<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> --</span>version</span></span>

<span class="meta function-call shell"><span class="variable function shell">zfs-2.1.5-1ubuntu6<span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>22.04.2</span></span>
<span class="meta function-call shell"><span class="variable function shell">zfs-kmod-2.1.5-1ubuntu6<span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>22.04.1</span></span></span></code></pre>
<h2 id="zfs-configuration"><span class="section-number-2">2.</span> ZFS Configuration</h2>
<p>Now that ZFS is installed, we can create and configure the pool.</p>
<p>You have various options for configuring ZFS pools that all come different pros and cons. I suggest visiting the links at the top of this post or searching online for the best configuration for your use-case.</p>
<ul>
<li>Striped VDEVs (Raid0)</li>
<li>Mirrored VDEVs (Raid1)</li>
<li>Striped Mirrored VDEVs (Raid10)</li>
<li>RAIDz (Raid5)</li>
<li>RAIDz2 (Raidd6)</li>
<li>RAIDz3</li>
<li>Nested RAIDz (Raid50, Raid60)</li>
</ul>
<p>I will be using Raid10 in this guide. However, the majority of the steps are the same regardless of your chosen pool configuration.</p>
<h3 id="creating-the-pool"><span class="section-number-3">2.1.</span> Creating the Pool</h3>
<p>To start, let's list the disks available to use. You can use <code class="verbatim">fdisk</code> command to see all available disks.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> fdisk<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>l</span></span></span></code></pre>
<p>Or, if you currently have them mounted, you can use the <code class="verbatim">df</code> command to view your disks.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"></span><span class="meta function-call arguments shell"><span class="keyword operator assignment redirection shell">&gt;</span> sudo df<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>h</span></span>

<span class="meta function-call shell"><span class="variable function shell">Filesystem</span></span><span class="meta function-call arguments shell">      Size  Used Avail Use<span class="meta group expansion job shell"><span class="punctuation definition variable job shell">%</span></span> Mounted on</span>
<span class="meta function-call shell"><span class="variable function shell">...</span></span>
<span class="meta function-call shell"><span class="variable function shell">/dev/sda1</span></span><span class="meta function-call arguments shell">       7.3T   28K  6.9T   1<span class="meta group expansion job shell"><span class="punctuation definition variable job shell">%</span></span> /mnt/red-01</span>
<span class="meta function-call shell"><span class="variable function shell">/dev/sdb1</span></span><span class="meta function-call arguments shell">       7.3T  144G  6.8T   3<span class="meta group expansion job shell"><span class="punctuation definition variable job shell">%</span></span> /mnt/red-02</span>
<span class="meta function-call shell"><span class="variable function shell">/dev/sdc1</span></span><span class="meta function-call arguments shell">       7.3T  5.5T  1.9T  75<span class="meta group expansion job shell"><span class="punctuation definition variable job shell">%</span></span> /mnt/white-02</span>
<span class="meta function-call shell"><span class="variable function shell">/dev/sdd1</span></span><span class="meta function-call arguments shell">       9.1T  8.7T  435G  96<span class="meta group expansion job shell"><span class="punctuation definition variable job shell">%</span></span> /mnt/white-01</span>
<span class="meta function-call shell"><span class="variable function shell">/dev/sde1</span></span><span class="meta function-call arguments shell">       7.3T   28K  6.9T   1<span class="meta group expansion job shell"><span class="punctuation definition variable job shell">%</span></span> /mnt/red-03</span>
<span class="meta function-call shell"><span class="variable function shell">/dev/sdf1</span></span><span class="meta function-call arguments shell">       7.3T   28K  6.9T   1<span class="meta group expansion job shell"><span class="punctuation definition variable job shell">%</span></span> /mnt/red-04</span></span></code></pre>
<p>If you're going to use mounted disks, make sure to umount them before creating the pool.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> umount /dev/sda1</span>
<span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> umount /dev/sdb1</span></span></code></pre>
<p>Now that I've identified the disks I want to use and have them unmounted, let's create the pool. For this example, I will call it <code class="verbatim">tank</code>.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> zpool create<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>f</span><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>m</span> /mnt/pool tank mirror /dev/sda /dev/sdb</span></span></code></pre>
<p>See below for the results of the new ZFS pool named <code class="verbatim">tank</code>, with a vdev automatically named <code class="verbatim">mirror-0</code>.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"></span><span class="meta function-call arguments shell"><span class="keyword operator assignment redirection shell">&gt;</span> zfs list</span>

<span class="meta function-call shell"><span class="variable function shell">NAME</span></span><span class="meta function-call arguments shell">   USED  AVAIL     REFER  MOUNTPOINT</span>
<span class="meta function-call shell"><span class="variable function shell">tank</span></span><span class="meta function-call arguments shell">   396K  7.14T       96K  /tank</span></span></code></pre>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"></span><span class="meta function-call arguments shell"><span class="keyword operator assignment redirection shell">&gt;</span> zpool status</span>

  <span class="meta function-call shell"><span class="variable function shell">pool:</span></span><span class="meta function-call arguments shell"> tank</span>
 <span class="meta function-call shell"><span class="variable function shell">state:</span></span><span class="meta function-call arguments shell"> ONLINE</span>
<span class="meta function-call shell"><span class="variable function shell">config:</span></span>

    <span class="meta function-call shell"><span class="variable function shell">NAME</span></span><span class="meta function-call arguments shell">        STATE     READ WRITE CKSUM</span>
    <span class="meta function-call shell"><span class="variable function shell">tank</span></span><span class="meta function-call arguments shell">        ONLINE       0     0     0</span>
      <span class="meta function-call shell"><span class="variable function shell">mirror-0</span></span><span class="meta function-call arguments shell">  ONLINE       0     0     0</span>
        <span class="meta function-call shell"><span class="variable function shell">sda</span></span><span class="meta function-call arguments shell">     ONLINE       0     0     0</span>
        <span class="meta function-call shell"><span class="variable function shell">sdb</span></span><span class="meta function-call arguments shell">     ONLINE       0     0     0</span>

<span class="meta function-call shell"><span class="variable function shell">errors:</span></span><span class="meta function-call arguments shell"> No known data errors</span></span></code></pre>
<p>We can also look at the mounted filesystem to see where the pool is mounted and some quick stats.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"></span><span class="meta function-call arguments shell"><span class="keyword operator assignment redirection shell">&gt;</span> df<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>h</span></span>

<span class="meta function-call shell"><span class="variable function shell">Filesystem</span></span><span class="meta function-call arguments shell">      Size  Used Avail Use<span class="meta group expansion job shell"><span class="punctuation definition variable job shell">%</span></span> Mounted on</span>
<span class="meta function-call shell"><span class="variable function shell">...</span></span>
<span class="meta function-call shell"><span class="variable function shell">tank</span></span><span class="meta function-call arguments shell">            7.2T  128K  7.2T   1<span class="meta group expansion job shell"><span class="punctuation definition variable job shell">%</span></span> /tank</span></span></code></pre>
<h3 id="expanding-the-pool"><span class="section-number-3">2.2.</span> Expanding the Pool</h3>
<p>If you want to expand this pool, you will need to add a new VDEV to the pool. Since I am using 2 disks per VDEV, I will need to add a new 2-disk VDEV to the existing <code class="verbatim">tank</code> pool.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> zpool add tank mirror /dev/sdX /dev/sdY</span></span></code></pre>
<p>If you're adding disks of different sizes, you'll need to use the <code class="verbatim">-f</code> flag. Keep in mind that the max size will be limited to the smallest disk added.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> zpool add<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>f</span> tank mirror /dev/sdX /dev/sdY</span></span></code></pre>
<p>I added two 8TB hard drives and this process took around 10 seconds to complete.</p>
<p>When viewing the pool again, you can see that the pool has now doubled in size. We have 14.3 TB usable space and the same space used for mirroring.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"></span><span class="meta function-call arguments shell"><span class="keyword operator assignment redirection shell">&gt;</span> zfs list</span>

<span class="meta function-call shell"><span class="variable function shell">NAME</span></span><span class="meta function-call arguments shell">         USED  AVAIL     REFER  MOUNTPOINT</span>
<span class="meta function-call shell"><span class="variable function shell">tank</span></span><span class="meta function-call arguments shell">         145G  14.3T      104K  /tank</span>
<span class="meta function-call shell"><span class="variable function shell">tank/cloud</span></span><span class="meta function-call arguments shell">   145G  14.3T      145G  /tank/cloud</span>
<span class="meta function-call shell"><span class="variable function shell">tank/media</span></span><span class="meta function-call arguments shell">    96K  14.3T       96K  /tank/media</span></span></code></pre>
<h4 id="converting-disks"><span class="section-number-4">2.2.1.</span> Converting Disks</h4>
<p>Some disks, such as NTFS-formatted drives, will need to be partitioned and formatted prior to being added to the pool.</p>
<p>Start by identifying the disks you want to format and add to the pool.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> fdisk<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>l</span></span> <span class="keyword operator logical pipe shell">|</span> <span class="meta function-call shell"><span class="variable function shell">grep</span></span><span class="meta function-call arguments shell"> /dev</span></span></code></pre>
<p>I am going to format my <code class="verbatim">/dev/sdc</code> and <code class="verbatim">/dev/sdd</code> disks with the <code class="verbatim">fdisk</code> command.</p>
<p>See below for instructions on how to use <code class="verbatim">fdisk</code>. Here's what I did to create basic Linux formatted disks:</p>
<ul>
<li><code class="verbatim">g</code> : Create GPT partition table</li>
<li><code class="verbatim">n</code> : Create a new partition, hit Enter for all default options</li>
<li><code class="verbatim">t</code> : Change partition type to <code class="verbatim">20</code> for <code class="verbatim">Linux filesystem</code></li>
<li><code class="verbatim">w</code> : Write the changes to disk and exit</li>
</ul>
<p>I repeated this process for both disks.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"></span><span class="meta function-call arguments shell"><span class="keyword operator assignment redirection shell">&gt;</span> sudo fdisk /dev/sdc</span>

<span class="meta function-call shell"><span class="variable function shell">Welcome</span></span><span class="meta function-call arguments shell"> to fdisk (util-linux 2.37.2</span><span class="meta function-call shell"></span><span class="meta post-cmd shell">)</span><span class="meta function-call shell"><span class="support function dot shell">.</span></span><span class="meta function-call arguments shell"> Changes will remain in memory only, until</span>
<span class="meta function-call shell"><span class="variable function shell">you</span></span><span class="meta function-call arguments shell"> decide to write them. Be careful before using the write command.</span>

<span class="meta function-call shell"><span class="variable function shell">This</span></span><span class="meta function-call arguments shell"> disk is currently in use - repartitioning is probably a bad idea. It<span class="string quoted single shell"><span class="punctuation definition string begin shell">&#39;</span>s
recommended to umount all file systems, and swapoff all swap partitions on this
disk.


Command (m for help): m

Help:

  GPT
   M   enter protective/hybrid MBR

  Generic
   d   delete a partition
   F   list free unpartitioned space
   l   list known partition types
   n   add a new partition
   p   print the partition table
   t   change a partition type
   v   verify the partition table
   i   print information about a partition

  Misc
   m   print this menu
   x   extra functionality (experts only)

  Script
   I   load disk layout from sfdisk script file
   O   dump disk layout to sfdisk script file

  Save &amp; Exit
   w   write table to disk and exit
   q   quit without saving changes

  Create a new label
   g   create a new empty GPT partition table
   G   create a new empty SGI (IRIX) partition table
   o   create a new empty DOS partition table
   s   create a new empty Sun partition table</span></span></span></code></pre>
<p>Once the drives are formatted, we can add these disks to the pool.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> zpool add tank mirror /dev/sdc /dev/sdd</span></span></code></pre>
<p>When we list the pool again, we can see that our size is now updated to approximately 22TB. This represents my hard drives totalling 45.6TB when shown with <code class="verbatim">fdisk -l</code>, with a Raid10 configuration using 22TB for mirroring and 22TB of usable space.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"></span><span class="meta function-call arguments shell"><span class="keyword operator assignment redirection shell">&gt;</span> zfs list</span>

<span class="meta function-call shell"><span class="variable function shell">NAME</span></span><span class="meta function-call arguments shell">         USED  AVAIL     REFER  MOUNTPOINT</span>
<span class="meta function-call shell"><span class="variable function shell">tank</span></span><span class="meta function-call arguments shell">         145G  21.7T      104K  /tank</span>
<span class="meta function-call shell"><span class="variable function shell">tank/cloud</span></span><span class="meta function-call arguments shell">   145G  21.7T      145G  /tank/cloud</span>
<span class="meta function-call shell"><span class="variable function shell">tank/media</span></span><span class="meta function-call arguments shell">   145GT 21.7T       96K  /tank/media</span></span></code></pre>
<h3 id="creating-datasets"><span class="section-number-3">2.3.</span> Creating Datasets</h3>
<p>According to <a href="https://docs.oracle.com/cd/E18752_01/html/819-5461/ftyue.html">ZFS Terminology</a>, a <code class="verbatim">dataset</code> can refer to “clones, file systems, snapshots, and volumes.</p>
<p>For this guide, I will use the <code class="verbatim">dataset</code> term to refer to file systems created under a pool.</p>
<p>Within my <code class="verbatim">tank</code> pool, I am going to create some datasets to help organize my files. This will give me location to store data rather than simply dumping everything at the <code class="verbatim">/tank/</code> location.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> zfs create tank/cloud</span>
<span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> zfs create tank/media</span></span></code></pre>
<p>Once created, you can see these datasets in the output of your pool list:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"></span><span class="meta function-call arguments shell"><span class="keyword operator assignment redirection shell">&gt;</span> zfs list</span>
<span class="meta function-call shell"><span class="variable function shell">NAME</span></span><span class="meta function-call arguments shell">         USED  AVAIL     REFER  MOUNTPOINT</span>
<span class="meta function-call shell"><span class="variable function shell">tank</span></span><span class="meta function-call arguments shell">         752K  7.14T      104K  /tank</span>
<span class="meta function-call shell"><span class="variable function shell">tank/cloud</span></span><span class="meta function-call arguments shell">    96K  7.14T       96K  /tank/cloud</span>
<span class="meta function-call shell"><span class="variable function shell">tank/media</span></span><span class="meta function-call arguments shell">    96K  7.14T       96K  /tank/media</span></span></code></pre>
<h3 id="creating-snapshots"><span class="section-number-3">2.4.</span> Creating Snapshots</h3>
<p>Next, let's create our first snapshot. We can do this by calling the <code class="verbatim">snapshot</code> command and give it an output name. I will be throwing the current date and time into my example.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> zfs snapshot tank@<span class="meta group expansion command parens shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section parens begin shell">(</span><span class="meta function-call shell"><span class="variable function shell">date</span></span><span class="meta function-call arguments shell"> <span class="string quoted single shell"><span class="punctuation definition string begin shell">&#39;</span>+%Y-%m-%d_%H-%M<span class="punctuation definition string end shell">&#39;</span></span></span><span class="punctuation section parens end shell">)</span></span></span></span></code></pre>
<p>We can list the snapshots in our pool with the following command:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"></span><span class="meta function-call arguments shell"><span class="keyword operator assignment redirection shell">&gt;</span> zfs list<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>t</span> snapshot</span>
<span class="meta function-call shell"><span class="variable function shell">NAME</span></span><span class="meta function-call arguments shell">                    USED  AVAIL     REFER  MOUNTPOINT</span>
<span class="meta function-call shell"><span class="variable function shell">tank@2024-02-06_19-41</span></span><span class="meta function-call arguments shell">     0B      -      104K  -</span></span></code></pre>
<h3 id="destroy-snapshots"><span class="section-number-3">2.5.</span> Destroy Snapshots</h3>
<p>You can always destroy snapshots that are no longer needed:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> zfs destroy tank@2024-02-06_19-41</span></span></code></pre>
<p>Once deleted, they will no longer appear in the list:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"></span><span class="meta function-call arguments shell"><span class="keyword operator assignment redirection shell">&gt;</span> zfs list<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>t</span> snapshot</span>
<span class="meta function-call shell"><span class="variable function shell">no</span></span><span class="meta function-call arguments shell"> datasets available</span></span></code></pre>
<h2 id="my-thoughts-on-zfs-so-far"><span class="section-number-2">3.</span> My Thoughts on ZFS So Far</h2>
<ul>
<li>I sacrificed 25TB to be able to mirror my data, but I feel more comfortable with the potential to save my data by quickly replacing a disk if I need to.</li>
<li>The set-up was surprisingly easy and fast.</li>
<li>Disk I/O is fast as well. I was worried that the data transfer speeds would be slower due to the RAID configuration.</li>
<li>Media streaming and transcoding has seen no noticeable drop in performance.</li>
<li>My only limitation really is the number of HDD bays in my server HDD cage.</li>
</ul>
]]></description>
    </item>
    <item>
      <title>Omaha Crime Data: 8 Years in Tableau</title>
      <link>https://cleberg.net/blog/tableau-dashboard.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/tableau-dashboard.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Sat, 27 Jan 2024 00:00:00 +0000</pubDate>
      <category>web</category>
      <description><![CDATA[<p>In this project, I am going to show you how to use Tableau Public for free to create simple dashboards.</p>
<p>I will be creating simple visuals from an Omaha crime data set and combining them to create the dashboard below. You can view this dashboard interactively online here: <a href="https://public.tableau.com/app/profile/c.c7042/viz/OmahaCrimeData2015-2023/OmahaCrimeData2015-2023#1">Omaha Crime Data (2015 - 2023)</a>.</p>
<figure><img src="https://img.cleberg.net/blog/20240127-tableau-dashboard/dashboard.webp" alt="A Tableau dashboard showing a map of Omaha with a dot for each crime, a bar chart with totals per crime category, and a line chart showing a timeline of crime totals by month."><figcaption><span class="figure-number">Figure 1: </span>Tableau Dashboard</figcaption></figure>
<h2 id="gather-the-data"><span class="section-number-2">1.</span> Gather the Data</h2>
<p>You can download incident data from the Omaha Police Department on their <a href="https://police.cityofomaha.org/crime-information/incident-data-download">Incident Data Download</a> page. They currently have files for the years 2015 through 2023.</p>
<p>Each file will be downloaded as a CSV file, approximately 3 MB - 8 MB.</p>
<h2 id="clean-and-transform-the-data"><span class="section-number-2">2.</span> Clean and Transform the Data</h2>
<p>I have used Python to combine the files into a single CSV file, as well as adding a custom <code class="verbatim">datetime</code> column. You could do this step in any software you prefer, but I prefer Python as its free, easy to use, and has a plethora of support resources online.</p>
<p>Start by opening a terminal, navigating to your Downloads directory, and creating a python script.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="support function cd shell">cd</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/Downloads</span>
<span class="meta function-call shell"><span class="variable function shell">nano</span></span><span class="meta function-call arguments shell"> data_processing.py</span></span></code></pre>
<p>Within the Python script, paste the following:</p>
<pre><code class="language-python highlight"><span class="source python"><span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Import modules
</span><span class="meta statement import python"><span class="keyword control import python">import</span> <span class="meta qualified-name python"><span class="meta generic-name python">pandas</span></span> <span class="keyword control import as python">as</span> <span class="meta qualified-name python"><span class="meta generic-name python">pd</span></span></span>
<span class="meta statement import python"><span class="keyword control import python">import</span> <span class="meta qualified-name python"><span class="meta generic-name python">glob</span></span></span>
<span class="meta statement import python"><span class="keyword control import python">import</span> <span class="meta qualified-name python"><span class="meta generic-name python">os</span></span></span>

<span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Import the data
</span><span class="meta qualified-name python"><span class="meta generic-name python">path</span></span> <span class="keyword operator assignment python">=</span> <span class="storage type string python">r</span><span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python"><span class="source regexp python">~/Downloads/<span class="keyword operator quantifier regexp">*</span><span class="constant character character-class regexp">.</span>csv</span><span class="punctuation definition string end python">&quot;</span></span></span>
<span class="meta qualified-name python"><span class="meta generic-name python">files</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">glob</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">glob</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">path</span></span></span><span class="punctuation section arguments end python">)</span></span>

<span class="meta qualified-name python"><span class="support type python">list</span></span> <span class="keyword operator assignment python">=</span> <span class="meta structure list python"><span class="punctuation section list begin python">[</span><span class="punctuation section list end python">]</span></span>

<span class="meta statement for python"><span class="keyword control flow for python">for</span> <span class="meta generic-name python">file</span> <span class="meta statement for python"><span class="keyword control flow for in python">in</span></span></span><span class="meta statement for python"> <span class="meta qualified-name python"><span class="meta generic-name python">files</span></span><span class="punctuation section block for python">:</span></span>
    <span class="meta qualified-name python"><span class="meta generic-name python">df_tmp</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">pd</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">read_csv</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">file</span></span></span><span class="punctuation section arguments end python">)</span></span>
    <span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">li</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">append</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">df_tmp</span></span></span><span class="punctuation section arguments end python">)</span></span>

<span class="meta qualified-name python"><span class="meta generic-name python">df</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">pd</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">concat</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta qualified-name python"><span class="support type python">list</span></span><span class="punctuation separator arguments python">,</span> <span class="variable parameter python">axis</span><span class="keyword operator assignment python">=</span><span class="constant numeric integer decimal python">0</span><span class="punctuation separator arguments python">,</span> <span class="variable parameter python">ignore_index</span><span class="keyword operator assignment python">=</span><span class="constant language python">True</span></span><span class="punctuation section arguments end python">)</span></span>

<span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Create a combined datetime column
</span><span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">df</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">datetime<span class="punctuation definition string end python">&quot;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">pd</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">to_datetime</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python">
    <span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">df</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">date<span class="punctuation definition string end python">&quot;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span> <span class="keyword operator arithmetic python">+</span> <span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python"> <span class="punctuation definition string end python">&quot;</span></span></span> <span class="keyword operator arithmetic python">+</span> <span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">df</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">time<span class="punctuation definition string end python">&quot;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span><span class="punctuation separator arguments python">,</span>
    <span class="variable parameter python">format</span><span class="keyword operator assignment python">=</span><span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python"><span class="constant other placeholder python">%m</span>/<span class="constant other placeholder python">%d</span>/<span class="constant other placeholder python">%Y</span> <span class="constant other placeholder python">%H</span>:<span class="constant other placeholder python">%M</span>:<span class="constant other placeholder python">%S</span><span class="punctuation definition string end python">&quot;</span></span></span>
</span><span class="punctuation section arguments end python">)</span></span>
<span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">df</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">head</span></span><span class="punctuation section arguments begin python">(</span><span class="punctuation section arguments end python">)</span></span>

<span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Export the combined data
</span><span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">df</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">to_csv</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="storage type string python">r</span><span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python"><span class="source regexp python">~/Downloads/combined_incidents<span class="constant character character-class regexp">.</span>csv</span><span class="punctuation definition string end python">&quot;</span></span></span></span><span class="punctuation section arguments end python">)</span></span></span></code></pre>
<p>Once pasted, save and close the file. You can execute the file like so:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">python3</span></span><span class="meta function-call arguments shell"> data_processing.py</span></span></code></pre>
<p>After this, you should have a combined data file that contains all incidents between 2015 and 2023. Mine was approximately 55 MB.</p>
<h2 id="tableau-public"><span class="section-number-2">3.</span> Tableau Public</h2>
<p><a href="https://public.tableau.com/">Tableau Public</a> is a free-to-use web application that allows you to create visualizations by uploading data sources. Note that there's no way to keep the data and visualizations private, so don't upload anything private.</p>
<p>After creating an account, you can click the <code class="verbatim">Create</code> &gt; <code class="verbatim">Web Authoring</code> link to create your first visualization.</p>
<h3 id="upload-the-data"><span class="section-number-3">3.1.</span> Upload the Data</h3>
<p>Once you've opened your first project, Tableau will ask you to connect to your data. For this project, click the <code class="verbatim">Upload from computer</code> button and select the CSV file previously combined in the step above.</p>
<p>Once connected, you can refresh the preview of the data with the <code class="verbatim">Refresh Data Source</code> button in the toolbar.</p>
<p>If you need to edit any of the data types, column names, etc., you can do so now. Once complete, generate an extract so that you can start creating visualizations.</p>
<h3 id="create-visualizations"><span class="section-number-3">3.2.</span> Create Visualizations</h3>
<p>To start, create a worksheet in the toolbar at the bottom of the screen.</p>
<p>Within this screen, select a column from the <code class="verbatim">Data</code> side bar on the left and drag it into the <code class="verbatim">Columns</code> or <code class="verbatim">Rows</code> area of the canvas.</p>
<p>See below for the map visualization. You can recreate this by adding the following fields:</p>
<ul>
<li><code class="verbatim">Columns</code>: Lon</li>
<li><code class="verbatim">Rows</code>: Lat</li>
<li><code class="verbatim">Marks</code>:<ul>
<li>Description</li>
<li>Datetime</li>
</ul>
</li>
<li><code class="verbatim">Filters</code>: Datetime</li>
</ul>
<p>You can repeat this process for each visualization you want to create. Explore your options by dragging data fields to different areas and by opening the field options to explore what operations can be performed on different data types (e.g., average, count, etc.).</p>
<h3 id="create-dashboard"><span class="section-number-3">3.3.</span> Create Dashboard</h3>
<p>To create a dashboard, click the button on the toolbar at the bottom of the screen. Within the dashboard, drag each sheet from the left side bar onto the dashboard canvas.</p>
<h3 id="formatting"><span class="section-number-3">3.4.</span> Formatting</h3>
<p>You can explore a ton of different formatting options throughout the worksheets and dashboard. Specifically for maps, you can alter the map layers, background, and visible features through the <code class="verbatim">Map</code> menu in the top file menu of the editing screen.</p>
<p>In the finished dashboard below, I opted for a dark mode with a map that showed county lines and city names.</p>
<p>There's a ton of other options available to be used in a dashboard like this, but this project shows a quick preview of what you can do in Tableau Public.</p>
<figure><img src="https://img.cleberg.net/blog/20240127-tableau-dashboard/dashboard.webp" alt="A Tableau dashboard showing a map of Omaha with a dot for each crime, a bar chart with totals per crime category, and a line chart showing a timeline of crime totals by month."><figcaption><span class="figure-number">Figure 2: </span>Tableau Dashboard</figcaption></figure>
]]></description>
    </item>
    <item>
      <title>Audit Dashboard: Alteryx and Power BI</title>
      <link>https://cleberg.net/blog/audit-dashboard.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/audit-dashboard.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Fri, 26 Jan 2024 00:00:00 +0000</pubDate>
      <category>audit</category>
      <description><![CDATA[<p>Alteryx and Power BI are powerful tools that can help turn your old-school audit trackers into interactive tools that provide useful insights and potential action plans.</p>
<p>With these tools, we are going to build a dashboard that can effectively communicate project status.</p>
<h2 id="requirements"><span class="section-number-2">1.</span> Requirements</h2>
<p>This project assumes the following:</p>
<ul>
<li>You have access to Alteryx Designer and Power BI Desktop.<ul>
<li>If you only have Power BI Desktop, you may need to perform some analysis in Power BI instead of Alteryx.</li>
</ul>
</li>
<li>Your data is in a format that can be imported into Alteryx and/or Power BI.</li>
<li>You have a basic understanding of data types and visualization.</li>
</ul>
<h2 id="alteryx-data-preparation-analysis"><span class="section-number-2">2.</span> Alteryx: Data Preparation &amp; Analysis</h2>
<h3 id="import-data"><span class="section-number-3">2.1.</span> Import Data</h3>
<p>With Alteryx, importing data is easy with the use of the <code class="verbatim">Input Data</code> tool. Simply drag this tool onto the canvas from the <code class="verbatim">In/Out</code> tab in the Ribbon to create it as a node.</p>
<p>You can choose the File Format manually or simply connect to your file/database and let Alteryx determine the format for you. For this example, we will be importing an Excel file and changing the <code class="verbatim">Start Data Import on Line</code> variable to <code class="verbatim">2</code>.</p>
<h3 id="transform-data"><span class="section-number-3">2.2.</span> Transform Data</h3>
<p>Next, let's replace null data and remove whitespace to clean up our data. We can do this with the <code class="verbatim">Data Cleansing</code> tool in the <code class="verbatim">Preparation</code> tab in the Ribbon.</p>
<p>Ensure that the following options are enabled:</p>
<ul>
<li>Replace Nulls<ul>
<li>Replace with Blanks (String Fields)</li>
<li>Replace with 0 (Numeric Fields)</li>
</ul>
</li>
<li>Remove Unwanted Characters<ul>
<li>Leading and Trailing Whitespace</li>
</ul>
</li>
</ul>
<p>For our next step, we will transform the date fields from strings to datetime format. Add a <code class="verbatim">Datetime</code> tool for each field you want to transform - in the example below, I am using the tool twice for the "Started On" and "Submitted On" fields.</p>
<p>Now that the dates are in the correct format, let's perform a calculation based on those fields. Start by adding a <code class="verbatim">Filter</code> tool, naming a new Output Column, and pasting the formula below into it (the two fields used in this formula must match the output of the <code class="verbatim">Datetime</code> tools above):</p>
<p>```txt DateTimeDiff([SubmittedOn<sub>Out</sub>],[StartedOn<sub>Out</sub>], "days") ```</p>
<h3 id="export-data"><span class="section-number-3">2.3.</span> Export Data</h3>
<p>Finalize the process by exporting the transformed data set to a new file, for use in the following visualization step.</p>
<h2 id="power-bi-data-visualization"><span class="section-number-2">3.</span> Power BI: Data Visualization</h2>
<h3 id="import-data"><span class="section-number-3">3.1.</span> Import Data</h3>
<p>To start, open the Power BI Desktop application. Upon first use, Power BI will ask if you want to open an existing dashboard or import new data.</p>
<p>As we are creating our first dashboard, let's import our data. In my example below, I'm importing data from the "Tracker" sheet of the Excel file I'm using for this project.</p>
<p>During this process, I also imported the export from the Alteryx workflow above. Therefore, we have two different files available for use in our dashboard.</p>
<h3 id="add-visuals"><span class="section-number-3">3.2.</span> Add Visuals</h3>
<p>To create the dashboard, you will need to follow the list instructions below and format as needed.</p>
<p>Instructions to create the visuals above:</p>
<ul>
<li><code class="verbatim">Text Box</code>: Explain the name and purpose of the dashboard. You can also add images and logos at the top of the dashboard.</li>
<li><code class="verbatim">Donut Chart</code>: Overall status of the project.<ul>
<li><code class="verbatim">Legend</code>: Status</li>
<li><code class="verbatim">Values</code>: Count of Status</li>
</ul>
</li>
<li><code class="verbatim">Stacked Column Chart</code>: Task count by assignee.<ul>
<li><code class="verbatim">X-axis</code>: Preparer</li>
<li><code class="verbatim">Y-axis</code>: Count of Control ID</li>
<li><code class="verbatim">Legend</code>: Status</li>
</ul>
</li>
<li><code class="verbatim">Treemap</code>: Top N client submitters by average days to submit.<ul>
<li><code class="verbatim">Details</code>: Preparer</li>
<li><code class="verbatim">Values</code>: Sum of Avg<sub>DaysToSubmit</sub></li>
</ul>
</li>
<li><code class="verbatim">Line Chart</code>: Projected vs. actual hours over time.</li>
<li><code class="verbatim">Clustered Bar Chart</code>: Projected vs. actual hours per person.</li>
<li><code class="verbatim">Slicer &amp; Table</code> - Upcoming due dates.<ul>
<li><code class="verbatim">Slicer</code>:<ul>
<li><code class="verbatim">Values</code>: Date Due</li>
</ul>
</li>
<li><code class="verbatim">Table</code>:<ul>
<li><code class="verbatim">Columns</code>: Count of Control ID, Date Due, Preparer, Status</li>
</ul>
</li>
</ul>
</li>
</ul>
<h3 id="format-the-dashboard"><span class="section-number-3">3.3.</span> Format the Dashboard</h3>
<p>You can choose a theme in the View tab of the Ribbon. You can even browse for custom JSON files that define themes, such as ones found online or custom ones created by your organization.</p>
<p>For each visual, you can click the <code class="verbatim">Format</code> button in the <code class="verbatim">Visualizations</code> side pane and explore the options. You can custom options such as:</p>
<ul>
<li>Visual<ul>
<li>Legend</li>
<li>Colors</li>
<li>Data labels</li>
<li>Category labels</li>
</ul>
</li>
<li>General<ul>
<li>Properties</li>
<li>Title</li>
<li>Effects</li>
<li>Header icons</li>
<li>Tooltips</li>
<li>Alt text</li>
</ul>
</li>
</ul>
<p>You can always look online for inspiration when trying to decide how best to organize and style your dashboard.</p>
<h2 id="sharing-the-results"><span class="section-number-2">4.</span> Sharing the Results</h2>
<p>Generally, you have a few different options for sharing your dashboards with others:</p>
<ol>
<li>Export the dashboard as a PDF in the file menu of Power BI. This will export all tabs and visuals as they are set when the export button is pressed. You will lose all interactivity with this option.</li>
<li>Send the full Power BI file to those you wish to share the dashboard. This will retain all settings and interactivity. However, you will also need to send the source files if they need to refresh the dashboard and you will need to re-send the files if you make updates.</li>
<li>Store the dashboard in a synced location, such as a shared drive or Microsoft Teams. Depending on how a user configures their local Windows paths, the data source paths may not be compatible for all users with such a setup.</li>
</ol>
]]></description>
    </item>
    <item>
      <title>Local LLM: Run the Model, Keep the Data</title>
      <link>https://cleberg.net/blog/local-llm.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/local-llm.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Sat, 13 Jan 2024 00:00:00 +0000</pubDate>
      <category>linux</category>
      <category>privacy</category>
      <description><![CDATA[<h2 id="requirements"><span class="section-number-2">1.</span> Requirements</h2>
<p>I've recently started playing with large language models (LLMs), mostly in the popular chatbot form, as part of my job and have decided to see if there's a consistent and reliable way to interact with these models on Apple devices without sacrificing privacy or requiring in-depth technical setup.</p>
<p>My requirements for this test:</p>
<ul>
<li>Open source platform</li>
<li>On-device model files</li>
<li>Minimal required configuration</li>
<li>Preferably pre-built, but a simple build process is acceptable</li>
</ul>
<p>I tested a handful of apps and have summarized my favorite (so far) for macOS and iOS below.</p>
<blockquote>
<p>TL;DR - Here are the two that met my requirements and I have found the easiest to install and use so far:</p>
</blockquote>
<ul>
<li>macOS: <a href="https://ollama.ai/">Ollama</a></li>
<li>iOS : <a href="https://llmfarm.site/">LLM Farm</a></li>
</ul>
<h2 id="macos"><span class="section-number-2">2.</span> macOS</h2>
<p><a href="https://ollama.ai/">Ollama</a> is a simple Go application for macOS and Linux that can run various LLMs locally.</p>
<p>For macOS, you can download the application on the <a href="https://ollama.ai/download/mac">Ollama download page</a> and install it by unzipping the <code class="verbatim">Ollama.app</code> file and moving it to the <code class="verbatim">Applications</code> folder.</p>
<p>If you prefer the command line, you can run these commands after the download finished:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="support function cd shell">cd</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/Downloads</span> <span class="keyword operator logical and shell">&amp;&amp;</span> <span class="punctuation separator continuation line shell">\
</span><span class="meta function-call shell"><span class="variable function shell">unzip</span></span><span class="meta function-call arguments shell"> Ollama-darwin.zip</span> <span class="keyword operator logical and shell">&amp;&amp;</span> <span class="punctuation separator continuation line shell">\
</span><span class="meta function-call shell"><span class="variable function shell">mv</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/Downloads/Ollama.app /Applications/</span></span></code></pre>
<p>After running the app, the app will ask you to open a terminal and run the default <code class="verbatim">llama2</code> model, which will open an interactive chat session in the terminal. You can start using the application at this point.</p>
<p>If you don't want to use the default <code class="verbatim">llama2</code> model, you can download and run additional models found on the <a href="https://ollama.ai/library">Models</a> page.</p>
<p>To see the information for the currently-used model, you can run the <code class="verbatim">/show info</code> command in the chat.</p>
<h3 id="community-integrations"><span class="section-number-3">2.1.</span> Community Integrations</h3>
<p>I highly recommend browsing the <a href="https://github.com/jmorganca/ollama#community-integrations">Community Integrations</a> section of the project to see how you would prefer to extend Ollama beyond a simple command-line interface. There are options for APIs, browser UIs, advanced terminal configurations, and more.</p>
<h2 id="ios"><span class="section-number-2">3.</span> iOS</h2>
<p>While there are a handful of decent macOS options, it was quite difficult to find an iOS app that offered an open source platform without an extensive configuration and building process. I found LLM Farm to be decent enough in quality to sit at the top of my list - however, it's definitely not user friendly enough for me to consider using it on a daily basis.</p>
<p><a href="https://llmfarm.site/">LLM Farm</a> is available on TestFlight, so there's no manual build process required. However, you can view the <a href="https://github.com/guinmoon/LLMFarm">LLMFarm repository</a> if you wish.</p>
<p>The caveat is that you will have to manually download the model files from the links in the <a href="https://github.com/guinmoon/LLMFarm/blob/main/models.md">models.md</a> file to your iPhone to use the app - there's currently no option in the app to reach out and grab the latest version of any supported model.</p>
<p>Once you have a file downloaded, you simply create a new chat and select the downloaded model file and ensure the inference matches the requirement in the <code class="verbatim">models.md</code> file.</p>
<p><a href="https://github.com/AugustDev/enchanted">Enchanted</a> is also an iOS app for private AI models, but it requires a public-facing Ollama API, which did not meet my "on device requirement." Nonetheless, it's an interesting looking app and I will likely set it up to test soon.</p>
]]></description>
    </item>
    <item>
      <title>macOS Customization: Terminal, Tiling WM, Widgets</title>
      <link>https://cleberg.net/blog/macos-customization.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/macos-customization.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Tue, 09 Jan 2024 00:00:00 +0000</pubDate>
      <category>linux</category>
      <description><![CDATA[<p>I have been using macOS more than Linux lately, so I wrote this post to describe some simple options to customize macOS beyond the normal built-in settings menu.</p>
<p>While not all-encompassing, the options below should be a good start for anyone looking to dive down the rabbit hole.</p>
<h2 id="basics"><span class="section-number-2">1.</span> Basics</h2>
<h3 id="package-management"><span class="section-number-3">1.1.</span> Package Management</h3>
<p>To install a lot of software on macOS, you will need <a href="https://brew.sh/">Homebrew</a>. You can use their installation script to get started. Simply open the <code class="verbatim">Terminal</code> application and paste the following snippet:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">/bin/bash</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>c</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion command parens shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section parens begin shell">(</span><span class="meta function-call shell"><span class="variable function shell">curl</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>fsSL</span> https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh</span><span class="punctuation section parens end shell">)</span></span><span class="punctuation definition string end shell">&quot;</span></span></span></span></code></pre>
<p>This will allow you to easily install and manage applications and other software easily through the <code class="verbatim">brew</code> command.</p>
<h3 id="terminal"><span class="section-number-3">1.2.</span> Terminal</h3>
<p>If you're serious about customizing your macOS system, I highly recommend installing a terminal emulator that you like and if you're not comfortable on the command line yet, start learning. A lot of customization options require you to edit hidden files, which is easiest in a terminal.</p>
<p>There are options like iTerm2, Kitty, Alacritty, Hyper, Warp, or the built-in Terminal app.</p>
<p>I use <a href="https://iterm2.com/">iTerm2</a>, which can be installed with Homebrew:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">brew</span></span><span class="meta function-call arguments shell"> install iterm2</span></span></code></pre>
<p>To install color schemes, such as the Dracula scheme, you visit <a href="https://iterm2colorschemes.com/">iTerm Themes</a> and follow their installation instructions to install any of the themes.</p>
<h2 id="desktop"><span class="section-number-2">2.</span> Desktop</h2>
<h3 id="window-management"><span class="section-number-3">2.1.</span> Window Management</h3>
<p><a href="https://github.com/koekeishiya/yabai">yabai</a> is a tiling window manager for macOS. While other window managers exist, I found that most of them struggled to create logical layouts and to allow me to easily move windows around the screen.</p>
<p>Some advanced settings for yabai are only available if partially disable System Integrity Protection (SIP). However, I chose not to do this and it hasn't affected my basic usage of yabai at all.</p>
<p>Refer to the <a href="https://github.com/koekeishiya/yabai/wiki/Installing-yabai-(latest-release)">yabai wiki</a> for installation instructions. You will need to ensure that yabai is allowed to access the accessibility and screen recording APIs.</p>
<h3 id="keyboard-shortcuts"><span class="section-number-3">2.2.</span> Keyboard Shortcuts</h3>
<p><a href="https://github.com/koekeishiya/skhd">skhd</a> is a simple hotkey daemon that allows you to define hotkeys in a file for usage on your system.</p>
<p>Installation is simple:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">brew</span></span><span class="meta function-call arguments shell"> install koekeishiya/formulae/skhd</span>
<span class="meta function-call shell"><span class="variable function shell">skhd</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> --</span>start-service</span></span></span></code></pre>
<p>After installation, be sure to allow <code class="verbatim">skhd</code> access to the accessibility API in the macOS privacy settings.</p>
<p>You can configure your hotkeys in the <code class="verbatim">~/.config/skhd/skhdrc</code> file:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">nano</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/.config/skhd/skhdrc</span></span></code></pre>
<p>For example, I have hotkeys to open my browser and terminal:</p>
<pre><code class="language-conf"># Terminal
cmd - return : /Applications/iTerm.app/Contents/MacOS/iTerm2

# Browser
cmd + shift - return : /Applications/LibreWolf.app/Contents/MacOS/librewolf</code></pre>
<h3 id="widgets"><span class="section-number-3">2.3.</span> Widgets</h3>
<p><a href="https://github.com/felixhageloh/uebersicht/">uebersicht</a> is a handy desktop-based widget tool with a plethora of community-made widgets available in the <a href="https://tracesof.net/uebersicht-widgets/">widgets gallery</a>. You can also write your own widgets with this tool.</p>
<p>To install, simply download the latest release from the <a href="https://tracesof.net/uebersicht/">uebersicht website</a> and copy it to the Applications folder.</p>
<p>See below for an example of the <a href="https://tracesof.net/uebersicht-widgets/#Mond">Mond</a> widget in action.</p>
<h3 id="status-bar"><span class="section-number-3">2.4.</span> Status Bar</h3>
<p><a href="https://github.com/FelixKratz/SketchyBar">SketchyBar</a> is a customizable replacement for the macOS status or menu bar.</p>
<p>You can browse a discussion where various users shared their <a href="https://github.com/FelixKratz/SketchyBar/discussions/47?sort=top">configurations</a> for inspiration or to copy their dotfiles.</p>
<h3 id="dock"><span class="section-number-3">2.5.</span> Dock</h3>
<p>The easiest way to customize the dock is to install <a href="https://ubarapp.com/">uBar</a>, which uses a Windows-like menu bar as the default style.</p>
<p>However, the built-in macOS dock cannot be disabled and can only be set to "always hidden". This can be annoying as it will pop out any time your mouse cursor passes closely to the dock edge of the screen. Because of this, I simply use the built-in dock instead of customizing it with third-party software.</p>
<p>Regardless, see below for the default installation style of uBar.</p>
<h3 id="application-icons"><span class="section-number-3">2.6.</span> Application Icons</h3>
<p>You can also customize the icon of any application in macOS, which will show up in Finder, the Dock, Launchpad, search results, etc. I recommend using <a href="https://macosicons.com/">macOSicons</a> to download icons you want, and then apply them by following this process.</p>
<ol>
<li>Open the Finder application.</li>
<li>Navigate to the <code class="verbatim">Applications</code> folder.</li>
<li>Right-click an application of your choice, and select <code class="verbatim">Get Info</code>.</li>
<li>Drag the image you downloaded on top of the application's icon at the top of information window (you will see a green "plus" symbol when you're hovering over it).</li>
<li>Release the new icon on top of the old icon and it will update!</li>
</ol>
]]></description>
    </item>
    <item>
      <title>Don&#x27;t Say Hello</title>
      <link>https://cleberg.net/blog/dont-say-hello.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/dont-say-hello.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Mon, 08 Jan 2024 00:00:00 +0000</pubDate>
      <category>privacy</category>
      <description><![CDATA[<p>I recently came back from a winter break and have started working again… only to immediately run into the dilemma of people sending me cliffhanger messages again.</p>
<h2 id="no-hello"><span class="section-number-2">1.</span> No Hello</h2>
<p>A year or two ago, I discovered <a href="https://nohello.net/en/">no hello</a> and have thought about it often since then. I've even sent it to a few people since then (who wouldn't take offense to it).</p>
<p>I work in a fast-paced environment where efficiency is extremely valuable. Therefore, I have always held a deep displeasure for conversations where people start with "Hello" and then.</p>
<p>I searched back through my work messages and found that I received ~50 messages from ~10 people last year from people that contained "hi", "hey", or "hello" and did not contain any indication of the purpose of the conversation. I also noticed that a few of the users were responsible for the large majority of the cliffhangers.</p>
<p>There's no real point to this post, just a desperate request for people to please stop doing this.</p>
]]></description>
    </item>
    <item>
      <title>NextDNS on Unifi Dream Machine</title>
      <link>https://cleberg.net/blog/unifi-nextdns.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/unifi-nextdns.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Sun, 03 Dec 2023 00:00:00 +0000</pubDate>
      <category>linux</category>
      <category>self-hosting</category>
      <description><![CDATA[<h2 id="overview"><span class="section-number-2">1.</span> Overview</h2>
<p>I recently installed NextDNS on my Unifi Dream Machine router using the <a href="https://github.com/nextdns/nextdns/wiki/UnifiOS">UnifiOS</a> wiki page on NextDNS's GitHub repository.</p>
<p>As a result of this, I wanted to write down the process in case the wiki or installer ever gets lost.</p>
<h2 id="wiki"><span class="section-number-2">2.</span> Wiki</h2>
<p>The following is copied from the wiki page linked above, with one difference in the <code class="verbatim">ssh</code> command.</p>
<p>Install instructions for Unifi Dream Machine (UDM) standard and pro routers.</p>
<h3 id="install"><span class="section-number-3">2.1.</span> Install</h3>
<p>Enable SSH:</p>
<ul>
<li>Go to your unifi admin interface and select your device (not the controller settings, but the Dream Machine settings)</li>
<li>Click on "Settings" at the bottom of the page</li>
<li>Go to the "Advanced" section on the left pan</li>
<li>Enable SSH</li>
<li>Set a SSH password</li>
</ul>
<p>Connect to your router using <code class="verbatim">ssh root@xxx.xxx.xxx.xxx</code> with the password you configured.</p>
<p>Run the following command and follow the instructions:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sh</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>c</span> <span class="string quoted single shell"><span class="punctuation definition string begin shell">&#39;</span>sh -c &quot;$(curl -sL https://nextdns.io/install)&quot;<span class="punctuation definition string end shell">&#39;</span></span></span></span></code></pre>
<p>Note: Queries from the UDM itself won't be routed to NextDNS nor encrypted due to current system limitation. All traffic from other devices on then network will.</p>
<h3 id="upgrade"><span class="section-number-3">2.2.</span> Upgrade</h3>
<p>To upgrade to the last version, simply re-run the installer above. If a new version is available, the upgrade action will added to the list of possible actions.</p>
<h3 id="uninstall"><span class="section-number-3">2.3.</span> Uninstall</h3>
<p>To uninstall, re-run the installer above and select "Remove" in the menu.</p>
<h3 id="troubleshooting"><span class="section-number-3">2.4.</span> Troubleshooting</h3>
<p>If the installation fail, please the installer in debug mode and contact us at team@nextdns.io with the transcript of the installation:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sh</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>c</span> <span class="string quoted single shell"><span class="punctuation definition string begin shell">&#39;</span>DEBUG=1 sh -c &quot;$(curl -sL https://nextdns.io/install)&quot;<span class="punctuation definition string end shell">&#39;</span></span></span></span></code></pre>
<h4 id="content-filtering-conflict"><span class="section-number-4">2.4.1.</span> Content Filtering Conflict</h4>
<p>NextDNS CLI and the UDM Content Filtering or the Ad Blocking features are incompatible. If you want to use NextDNS CLI, please make sure they are disabled.</p>
<p>To disable Content Filtering, go to Settings &gt; Network, then for each network, set the Content Filtering feature to None</p>
<p>To disable Ad Blocking, go to Settings &gt; Application Firewall. In the General tab, uncheck the Ad Blocking checkbox.</p>
<h4 id="apt-error"><span class="section-number-4">2.4.2.</span> APT Error</h4>
<p>If you get an apt error as follow:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">E:</span></span><span class="meta function-call arguments shell"> Failed to fetch http://security.debian.org/dists/stretch/updates/main/binary-arm64/Packages  404  Not Found <span class="keyword control regexp set begin shell">[</span>IP: 151.101.70.132 80<span class="keyword control regexp set end shell">]</span></span></span></code></pre>
<p>You may try to following:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sed</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>i</span><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>e</span> <span class="string quoted single shell"><span class="punctuation definition string begin shell">&#39;</span>s/deb.debian.org/archive.debian.org/g<span class="punctuation definition string end shell">&#39;</span></span> <span class="punctuation separator continuation line shell">\
</span><span class="variable parameter option shell"><span class="punctuation definition parameter shell">       -</span>e</span> <span class="string quoted single shell"><span class="punctuation definition string begin shell">&#39;</span>s|security.debian.org|archive.debian.org/|g<span class="punctuation definition string end shell">&#39;</span></span> <span class="punctuation separator continuation line shell">\
</span><span class="variable parameter option shell"><span class="punctuation definition parameter shell">       -</span>e</span> <span class="string quoted single shell"><span class="punctuation definition string begin shell">&#39;</span>/stretch-updates/d<span class="punctuation definition string end shell">&#39;</span></span> /etc/apt/sources.list</span></span></code></pre>
<h3 id="install-sh"><span class="section-number-3">2.5.</span> install.sh</h3>
<p>Here are the contents of the <code class="verbatim">install.sh</code> file used above, as of 2023-12-03:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell">!/bin/sh</span><span class="comment line number-sign shell">
</span>
<span class="meta function shell"><span class="entity name function shell">main</span><span class="punctuation section parens begin shell">(</span><span class="punctuation section parens end shell">)</span> <span class="punctuation section braces begin shell">{</span>
    <span class="variable other readwrite assignment shell">OS</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell"><span class="meta group expansion command parens shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section parens begin shell">(</span><span class="meta function-call shell"><span class="variable function shell">detect_os</span></span><span class="punctuation section parens end shell">)</span></span></span>
    <span class="variable other readwrite assignment shell">GOARCH</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell"><span class="meta group expansion command parens shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section parens begin shell">(</span><span class="meta function-call shell"><span class="variable function shell">detect_goarch</span></span><span class="punctuation section parens end shell">)</span></span></span>
    <span class="variable other readwrite assignment shell">GOOS</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell"><span class="meta group expansion command parens shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section parens begin shell">(</span><span class="meta function-call shell"><span class="variable function shell">detect_goos</span></span><span class="punctuation section parens end shell">)</span></span></span>
    <span class="variable other readwrite assignment shell">NEXTDNS_BIN</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell"><span class="meta group expansion command parens shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section parens begin shell">(</span><span class="meta function-call shell"><span class="variable function shell">bin_location</span></span><span class="punctuation section parens end shell">)</span></span></span>
    <span class="variable other readwrite assignment shell">INSTALL_RELEASE</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell"><span class="meta group expansion command parens shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section parens begin shell">(</span><span class="meta function-call shell"><span class="variable function shell">get_release</span></span><span class="punctuation section parens end shell">)</span></span></span>

<span class="meta function-call shell">    <span class="storage modifier shell">export</span> <span class="variable other readwrite assignment shell">NEXTDNS_INSTALLER</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell">1</span></span>

    <span class="meta function-call shell"><span class="variable function shell">log_info</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>OS: <span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">OS</span></span><span class="punctuation definition string end shell">&quot;</span></span></span>
    <span class="meta function-call shell"><span class="variable function shell">log_info</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>GOARCH: <span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">GOARCH</span></span><span class="punctuation definition string end shell">&quot;</span></span></span>
    <span class="meta function-call shell"><span class="variable function shell">log_info</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>GOOS: <span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">GOOS</span></span><span class="punctuation definition string end shell">&quot;</span></span></span>
    <span class="meta function-call shell"><span class="variable function shell">log_info</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>NEXTDNS_BIN: <span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">NEXTDNS_BIN</span></span><span class="punctuation definition string end shell">&quot;</span></span></span>
    <span class="meta function-call shell"><span class="variable function shell">log_info</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>INSTALL_RELEASE: <span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">INSTALL_RELEASE</span></span><span class="punctuation definition string end shell">&quot;</span></span></span>

    <span class="keyword control if begin shell">if</span> <span class="support function test begin shell">[</span><span class="meta function-call arguments shell"> <span class="variable parameter option shell"><span class="punctuation definition parameter shell">-</span>z</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">OS</span></span><span class="punctuation definition string end shell">&quot;</span></span> <span class="support function test end shell">]</span></span> <span class="keyword operator logical or shell">||</span> <span class="support function test begin shell">[</span><span class="meta function-call arguments shell"> <span class="variable parameter option shell"><span class="punctuation definition parameter shell">-</span>z</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">GOARCH</span></span><span class="punctuation definition string end shell">&quot;</span></span> <span class="support function test end shell">]</span></span> <span class="keyword operator logical or shell">||</span> <span class="support function test begin shell">[</span><span class="meta function-call arguments shell"> <span class="variable parameter option shell"><span class="punctuation definition parameter shell">-</span>z</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">GOOS</span></span><span class="punctuation definition string end shell">&quot;</span></span> <span class="support function test end shell">]</span></span> <span class="keyword operator logical or shell">||</span> <span class="support function test begin shell">[</span><span class="meta function-call arguments shell"> <span class="variable parameter option shell"><span class="punctuation definition parameter shell">-</span>z</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">NEXTDNS_BIN</span></span><span class="punctuation definition string end shell">&quot;</span></span> <span class="support function test end shell">]</span></span> <span class="keyword operator logical or shell">||</span> <span class="support function test begin shell">[</span><span class="meta function-call arguments shell"> <span class="variable parameter option shell"><span class="punctuation definition parameter shell">-</span>z</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">INSTALL_RELEASE</span></span><span class="punctuation definition string end shell">&quot;</span></span> <span class="support function test end shell">]</span></span><span class="keyword operator logical continue shell">;</span> <span class="keyword control if then shell">then</span>
        <span class="meta function-call shell"><span class="variable function shell">log_error</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>Cannot detect running environment.<span class="punctuation definition string end shell">&quot;</span></span></span>
        <span class="meta function-call shell"><span class="support function exit shell">exit</span></span><span class="meta function-call arguments shell"> 1</span>
    <span class="keyword control if end shell">fi</span>

    <span class="keyword control case begin shell">case</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">RUN_COMMAND</span></span><span class="punctuation definition string end shell">&quot;</span></span> <span class="keyword control case in shell">in</span>
    install<span class="keyword operator logical shell">|</span>upgrade<span class="keyword operator logical shell">|</span>uninstall<span class="keyword operator logical shell">|</span>configure<span class="keyword control case item shell">)</span> <span class="meta function-call shell"><span class="variable function shell"><span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">RUN_COMMAND</span></span><span class="punctuation definition string end shell">&quot;</span></span></span></span><span class="keyword operator logical continue shell">;</span> <span class="meta function-call shell"><span class="support function exit shell">exit</span></span> <span class="punctuation terminator case shell">;;</span>
    <span class="keyword control case end shell">esac</span>

    <span class="keyword control while shell">while</span> <span class="meta function-call shell"><span class="variable function shell">true</span></span><span class="keyword operator logical continue shell">;</span> <span class="keyword control do shell">do</span>
        <span class="variable other readwrite assignment shell">CURRENT_RELEASE</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell"><span class="meta group expansion command parens shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section parens begin shell">(</span><span class="meta function-call shell"><span class="variable function shell">get_current_release</span></span><span class="punctuation section parens end shell">)</span></span></span>
        <span class="meta function-call shell"><span class="variable function shell">log_debug</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>Start install loop with CURRENT_RELEASE=<span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">CURRENT_RELEASE</span></span><span class="punctuation definition string end shell">&quot;</span></span></span>

        <span class="keyword control if begin shell">if</span> <span class="support function test begin shell">[</span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">CURRENT_RELEASE</span></span><span class="punctuation definition string end shell">&quot;</span></span> <span class="support function test end shell">]</span></span><span class="keyword operator logical continue shell">;</span> <span class="keyword control if then shell">then</span>
            <span class="keyword control if begin shell">if</span> <span class="keyword operator logical shell">!</span> <span class="meta function-call shell"><span class="variable function shell">is_version_current</span></span><span class="keyword operator logical continue shell">;</span> <span class="keyword control if then shell">then</span>
                <span class="meta function-call shell"><span class="variable function shell">log_debug</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>NextDNS is out of date (<span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">CURRENT_RELEASE</span></span> != <span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">INSTALL_RELEASE</span></span>)<span class="punctuation definition string end shell">&quot;</span></span></span>
                <span class="meta function-call shell"><span class="variable function shell">menu</span></span><span class="meta function-call arguments shell"> <span class="punctuation separator continuation line shell">\
</span>                    u <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>Upgrade NextDNS from <span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">CURRENT_RELEASE</span></span> to <span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">INSTALL_RELEASE</span></span><span class="punctuation definition string end shell">&quot;</span></span> upgrade <span class="punctuation separator continuation line shell">\
</span>                    c <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>Configure NextDNS<span class="punctuation definition string end shell">&quot;</span></span> configure <span class="punctuation separator continuation line shell">\
</span>                    r <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>Remove NextDNS<span class="punctuation definition string end shell">&quot;</span></span> uninstall <span class="punctuation separator continuation line shell">\
</span>                    e <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>Exit<span class="punctuation definition string end shell">&quot;</span></span> exit</span>
            <span class="keyword control if else shell">else</span>
                <span class="meta function-call shell"><span class="variable function shell">log_debug</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>NextDNS is up to date (<span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">CURRENT_RELEASE</span></span>)<span class="punctuation definition string end shell">&quot;</span></span></span>
                <span class="meta function-call shell"><span class="variable function shell">menu</span></span><span class="meta function-call arguments shell"> <span class="punctuation separator continuation line shell">\
</span>                    c <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>Configure NextDNS<span class="punctuation definition string end shell">&quot;</span></span> configure <span class="punctuation separator continuation line shell">\
</span>                    r <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>Remove NextDNS<span class="punctuation definition string end shell">&quot;</span></span> uninstall <span class="punctuation separator continuation line shell">\
</span>                    e <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>Exit<span class="punctuation definition string end shell">&quot;</span></span> exit</span>
            <span class="keyword control if end shell">fi</span>
        <span class="keyword control if else shell">else</span>
            <span class="meta function-call shell"><span class="variable function shell">log_debug</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>NextDNS is not installed<span class="punctuation definition string end shell">&quot;</span></span></span>
            <span class="meta function-call shell"><span class="variable function shell">menu</span></span><span class="meta function-call arguments shell"> <span class="punctuation separator continuation line shell">\
</span>                i <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>Install NextDNS<span class="punctuation definition string end shell">&quot;</span></span> install <span class="punctuation separator continuation line shell">\
</span>                e <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>Exit<span class="punctuation definition string end shell">&quot;</span></span> exit</span>
        <span class="keyword control if end shell">fi</span>
    <span class="keyword control done shell">done</span>
<span class="punctuation section braces end shell">}</span></span>

<span class="meta function shell"><span class="entity name function shell">install</span><span class="punctuation section parens begin shell">(</span><span class="punctuation section parens end shell">)</span> <span class="punctuation section braces begin shell">{</span>
    <span class="keyword control if begin shell">if</span> <span class="support function test begin shell">[</span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion command parens shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section parens begin shell">(</span><span class="meta function-call shell"><span class="variable function shell">get_current_release</span></span><span class="punctuation section parens end shell">)</span></span><span class="punctuation definition string end shell">&quot;</span></span> <span class="support function test end shell">]</span></span><span class="keyword operator logical continue shell">;</span> <span class="keyword control if then shell">then</span>
        <span class="meta function-call shell"><span class="variable function shell">log_info</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>Already installed<span class="punctuation definition string end shell">&quot;</span></span></span>
        <span class="meta function-call shell"><span class="keyword control return shell">return</span></span>
    <span class="keyword control if end shell">fi</span>
    <span class="keyword control if begin shell">if</span> <span class="meta function-call shell"><span class="variable function shell">type</span></span><span class="meta function-call arguments shell">=<span class="meta group expansion command parens shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section parens begin shell">(</span><span class="meta function-call shell"><span class="variable function shell">install_type</span></span><span class="punctuation section parens end shell">)</span></span></span><span class="keyword operator logical continue shell">;</span> <span class="keyword control if then shell">then</span>
        <span class="meta function-call shell"><span class="variable function shell">log_info</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>Installing NextDNS...<span class="punctuation definition string end shell">&quot;</span></span></span>
        <span class="meta function-call shell"><span class="variable function shell">log_debug</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>Using <span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">type</span></span> install type<span class="punctuation definition string end shell">&quot;</span></span></span>
        <span class="keyword control if begin shell">if</span> <span class="meta function-call shell"><span class="variable function shell"><span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>install_<span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">type</span></span><span class="punctuation definition string end shell">&quot;</span></span></span></span><span class="keyword operator logical continue shell">;</span> <span class="keyword control if then shell">then</span>
            <span class="keyword control if begin shell">if</span> <span class="support function test begin shell">[</span><span class="meta function-call arguments shell"> <span class="keyword operator logical shell">!</span> <span class="variable parameter option shell"><span class="punctuation definition parameter shell">-</span>x</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">NEXTDNS_BIN</span></span><span class="punctuation definition string end shell">&quot;</span></span> <span class="support function test end shell">]</span></span><span class="keyword operator logical continue shell">;</span> <span class="keyword control if then shell">then</span>
                <span class="meta function-call shell"><span class="variable function shell">log_error</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>Installation failed: binary not installed in <span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">NEXTDNS_BIN</span></span><span class="punctuation definition string end shell">&quot;</span></span></span>
                <span class="meta function-call shell"><span class="keyword control return shell">return</span></span><span class="meta function-call arguments shell"> 1</span>
            <span class="keyword control if end shell">fi</span>
            <span class="meta function-call shell"><span class="variable function shell">configure</span></span>
            <span class="meta function-call shell"><span class="variable function shell">post_install</span></span>
            <span class="meta function-call shell"><span class="support function exit shell">exit</span></span><span class="meta function-call arguments shell"> 0</span>
        <span class="keyword control if end shell">fi</span>
    <span class="keyword control if else shell">else</span>
        <span class="meta function-call shell"><span class="keyword control return shell">return</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable language shell">?</span></span></span>
    <span class="keyword control if end shell">fi</span>
<span class="punctuation section braces end shell">}</span></span>

<span class="meta function shell"><span class="entity name function shell">upgrade</span><span class="punctuation section parens begin shell">(</span><span class="punctuation section parens end shell">)</span> <span class="punctuation section braces begin shell">{</span>
    <span class="keyword control if begin shell">if</span> <span class="support function test begin shell">[</span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion command parens shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section parens begin shell">(</span><span class="meta function-call shell"><span class="variable function shell">get_current_release</span></span><span class="punctuation section parens end shell">)</span></span><span class="punctuation definition string end shell">&quot;</span></span> <span class="keyword operator logical shell">=</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">INSTALL_RELEASE</span></span><span class="punctuation definition string end shell">&quot;</span></span> <span class="support function test end shell">]</span></span><span class="keyword operator logical continue shell">;</span> <span class="keyword control if then shell">then</span>
        <span class="meta function-call shell"><span class="variable function shell">log_info</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>Already on the latest version<span class="punctuation definition string end shell">&quot;</span></span></span>
        <span class="meta function-call shell"><span class="keyword control return shell">return</span></span>
    <span class="keyword control if end shell">fi</span>
    <span class="keyword control if begin shell">if</span> <span class="meta function-call shell"><span class="variable function shell">type</span></span><span class="meta function-call arguments shell">=<span class="meta group expansion command parens shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section parens begin shell">(</span><span class="meta function-call shell"><span class="variable function shell">install_type</span></span><span class="punctuation section parens end shell">)</span></span></span><span class="keyword operator logical continue shell">;</span> <span class="keyword control if then shell">then</span>
        <span class="meta function-call shell"><span class="variable function shell">log_info</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>Upgrading NextDNS...<span class="punctuation definition string end shell">&quot;</span></span></span>
        <span class="meta function-call shell"><span class="variable function shell">log_debug</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>Using <span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">type</span></span> install type<span class="punctuation definition string end shell">&quot;</span></span></span>
        <span class="meta function-call shell"><span class="variable function shell"><span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>upgrade_<span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">type</span></span><span class="punctuation definition string end shell">&quot;</span></span></span></span>
    <span class="keyword control if else shell">else</span>
        <span class="meta function-call shell"><span class="keyword control return shell">return</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable language shell">?</span></span></span>
    <span class="keyword control if end shell">fi</span>
<span class="punctuation section braces end shell">}</span></span>

<span class="meta function shell"><span class="entity name function shell">uninstall</span><span class="punctuation section parens begin shell">(</span><span class="punctuation section parens end shell">)</span> <span class="punctuation section braces begin shell">{</span>
    <span class="keyword control if begin shell">if</span> <span class="meta function-call shell"><span class="variable function shell">type</span></span><span class="meta function-call arguments shell">=<span class="meta group expansion command parens shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section parens begin shell">(</span><span class="meta function-call shell"><span class="variable function shell">install_type</span></span><span class="punctuation section parens end shell">)</span></span></span><span class="keyword operator logical continue shell">;</span> <span class="keyword control if then shell">then</span>
        <span class="meta function-call shell"><span class="variable function shell">log_info</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>Uninstalling NextDNS...<span class="punctuation definition string end shell">&quot;</span></span></span>
        <span class="meta function-call shell"><span class="variable function shell">log_debug</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>Using <span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">type</span></span> uninstall type<span class="punctuation definition string end shell">&quot;</span></span></span>
        <span class="meta function-call shell"><span class="variable function shell"><span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>uninstall_<span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">type</span></span><span class="punctuation definition string end shell">&quot;</span></span></span></span>
    <span class="keyword control if else shell">else</span>
        <span class="meta function-call shell"><span class="keyword control return shell">return</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable language shell">?</span></span></span>
    <span class="keyword control if end shell">fi</span>
<span class="punctuation section braces end shell">}</span></span>

<span class="meta function shell"><span class="entity name function shell">precheck</span><span class="punctuation section parens begin shell">(</span><span class="punctuation section parens end shell">)</span> <span class="punctuation section braces begin shell">{</span>
    <span class="keyword control if begin shell">if</span> <span class="support function test begin shell">[</span><span class="meta function-call arguments shell"> <span class="variable parameter option shell"><span class="punctuation definition parameter shell">-</span>e</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>/data/unifi<span class="punctuation definition string end shell">&quot;</span></span> <span class="support function test end shell">]</span></span> <span class="keyword operator logical and shell">&amp;&amp;</span> <span class="support function test begin shell">[</span><span class="meta function-call arguments shell"> <span class="variable parameter option shell"><span class="punctuation definition parameter shell">-</span>f</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>/run/dnsfilter/dnsfilter<span class="punctuation definition string end shell">&quot;</span></span> <span class="support function test end shell">]</span></span><span class="keyword operator logical continue shell">;</span> <span class="keyword control if then shell">then</span>
        <span class="meta function-call shell"><span class="variable function shell">log_warn</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>UDM Content Filtering and/or Ad Blocking feature is enabled.<span class="punctuation definition string end shell">&quot;</span></span></span>
    <span class="meta function-call shell"><span class="variable function shell">log_warn</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>Please disable it to use NextDNS.<span class="punctuation definition string end shell">&quot;</span></span></span>
        <span class="meta function-call shell"><span class="variable function shell">log_warn</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="punctuation definition string end shell">&quot;</span></span></span>
        <span class="meta function-call shell"><span class="variable function shell">log_warn</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>  To disable Content Filtering, go to Settings &gt; Network.<span class="punctuation definition string end shell">&quot;</span></span></span>
        <span class="meta function-call shell"><span class="variable function shell">log_warn</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>  For each network, set the Content Filtering feature to None.<span class="punctuation definition string end shell">&quot;</span></span></span>
    <span class="meta function-call shell"><span class="variable function shell">log_warn</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="punctuation definition string end shell">&quot;</span></span></span>
    <span class="meta function-call shell"><span class="variable function shell">log_warn</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>  To disable Ad Blocking, go to Settings &gt; Application Firewall<span class="punctuation definition string end shell">&quot;</span></span></span>
    <span class="meta function-call shell"><span class="variable function shell">log_warn</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>  In the General tab, uncheck the Ad Blocking checkbox.<span class="punctuation definition string end shell">&quot;</span></span></span>
        <span class="meta function-call shell"><span class="variable function shell">log_warn</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="punctuation definition string end shell">&quot;</span></span></span>
        <span class="keyword control while shell">while</span> <span class="support function test begin shell">[</span><span class="meta function-call arguments shell"> <span class="variable parameter option shell"><span class="punctuation definition parameter shell">-</span>f</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>/run/dnsfilter/dnsfilter<span class="punctuation definition string end shell">&quot;</span></span> <span class="support function test end shell">]</span></span><span class="keyword operator logical continue shell">;</span> <span class="keyword control do shell">do</span>
            <span class="meta function-call shell"><span class="variable function shell">sleep</span></span><span class="meta function-call arguments shell"> 1</span>
        <span class="keyword control done shell">done</span>
        <span class="meta function-call shell"><span class="variable function shell">log_info</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>Content Filtering feature successfuly disabled.<span class="punctuation definition string end shell">&quot;</span></span></span>
    <span class="keyword control if end shell">fi</span>
<span class="punctuation section braces end shell">}</span></span>

<span class="meta function shell"><span class="entity name function shell">configure</span><span class="punctuation section parens begin shell">(</span><span class="punctuation section parens end shell">)</span> <span class="punctuation section braces begin shell">{</span>
    <span class="meta function-call shell"><span class="variable function shell">log_debug</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>Start configure<span class="punctuation definition string end shell">&quot;</span></span></span>
    <span class="meta function-call shell"><span class="variable function shell">precheck</span></span>
    <span class="variable other readwrite assignment shell">args</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell"><span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="punctuation definition string end shell">&quot;</span></span></span>
<span class="meta function shell">    <span class="entity name function shell">add_arg</span><span class="punctuation section parens begin shell">(</span><span class="punctuation section parens end shell">)</span> <span class="punctuation section braces begin shell">{</span>
        <span class="keyword control for shell">for</span><span class="meta group for shell"> value <span class="keyword control in shell">in</span> <span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">2</span></span></span><span class="keyword operator logical continue shell">;</span> <span class="keyword control do shell">do</span>
            <span class="meta function-call shell"><span class="variable function shell">log_debug</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>Add arg -<span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">1</span></span>=<span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">value</span></span><span class="punctuation definition string end shell">&quot;</span></span></span>
            <span class="variable other readwrite assignment shell">args</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell"><span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">args</span></span> -<span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">1</span></span>=<span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">value</span></span><span class="punctuation definition string end shell">&quot;</span></span></span>
        <span class="keyword control done shell">done</span>
    <span class="punctuation section braces end shell">}</span></span>
<span class="meta function shell">    <span class="entity name function shell">add_arg_bool_ask</span><span class="punctuation section parens begin shell">(</span><span class="punctuation section parens end shell">)</span> <span class="punctuation section braces begin shell">{</span>
        <span class="variable other readwrite assignment shell">arg</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell"><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">1</span></span></span>
        <span class="variable other readwrite assignment shell">msg</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell"><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">2</span></span></span>
        <span class="variable other readwrite assignment shell">default</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell"><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">3</span></span></span>
        <span class="keyword control if begin shell">if</span> <span class="support function test begin shell">[</span><span class="meta function-call arguments shell"> <span class="variable parameter option shell"><span class="punctuation definition parameter shell">-</span>z</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">default</span></span><span class="punctuation definition string end shell">&quot;</span></span> <span class="support function test end shell">]</span></span><span class="keyword operator logical continue shell">;</span> <span class="keyword control if then shell">then</span>
            <span class="variable other readwrite assignment shell">default</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell"><span class="meta group expansion command parens shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section parens begin shell">(</span><span class="meta function-call shell"><span class="variable function shell">get_config_bool</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">arg</span></span><span class="punctuation definition string end shell">&quot;</span></span></span><span class="punctuation section parens end shell">)</span></span></span>
        <span class="keyword control if end shell">fi</span>
        <span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> shellcheck disable=SC2046</span><span class="comment line number-sign shell">
</span>        <span class="meta function-call shell"><span class="variable function shell">add_arg</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">arg</span></span><span class="punctuation definition string end shell">&quot;</span></span> <span class="meta group expansion command parens shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section parens begin shell">(</span><span class="meta function-call shell"><span class="variable function shell">ask_bool</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">msg</span></span><span class="punctuation definition string end shell">&quot;</span></span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">default</span></span><span class="punctuation definition string end shell">&quot;</span></span></span><span class="punctuation section parens end shell">)</span></span></span>
    <span class="punctuation section braces end shell">}</span></span>
    <span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> Use profile from now on</span><span class="comment line number-sign shell">
</span>    <span class="meta function-call shell"><span class="variable function shell">add_arg</span></span><span class="meta function-call arguments shell"> profile <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion command parens shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section parens begin shell">(</span><span class="meta function-call shell"><span class="variable function shell">get_profile_id</span></span><span class="punctuation section parens end shell">)</span></span><span class="punctuation definition string end shell">&quot;</span></span></span>

    <span class="meta function-call shell"><span class="variable function shell">doc</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>Sending your devices name lets you filter analytics and logs by device.<span class="punctuation definition string end shell">&quot;</span></span></span>
    <span class="meta function-call shell"><span class="variable function shell">add_arg_bool_ask</span></span><span class="meta function-call arguments shell"> report-client-info <span class="string quoted single shell"><span class="punctuation definition string begin shell">&#39;</span>Report device name?<span class="punctuation definition string end shell">&#39;</span></span> true</span>

    <span class="keyword control case begin shell">case</span> <span class="meta group expansion command parens shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section parens begin shell">(</span><span class="meta function-call shell"><span class="variable function shell">guess_host_type</span></span><span class="punctuation section parens end shell">)</span></span> <span class="keyword control case in shell">in</span>
    router<span class="keyword control case item shell">)</span>
        <span class="meta function-call shell"><span class="variable function shell">add_arg</span></span><span class="meta function-call arguments shell"> setup-router true</span>
        <span class="punctuation terminator case shell">;;</span>
    unsure<span class="keyword control case item shell">)</span>
        <span class="meta function-call shell"><span class="variable function shell">doc</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>Accept DNS request from other network hosts.<span class="punctuation definition string end shell">&quot;</span></span></span>
        <span class="keyword control if begin shell">if</span> <span class="support function test begin shell">[</span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion command parens shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section parens begin shell">(</span><span class="meta function-call shell"><span class="variable function shell">get_config_bool</span></span><span class="meta function-call arguments shell"> setup-router</span><span class="punctuation section parens end shell">)</span></span><span class="punctuation definition string end shell">&quot;</span></span> <span class="keyword operator logical shell">=</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>true<span class="punctuation definition string end shell">&quot;</span></span> <span class="support function test end shell">]</span></span><span class="keyword operator logical continue shell">;</span> <span class="keyword control if then shell">then</span>
            <span class="variable other readwrite assignment shell">router_default</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell">true</span>
        <span class="keyword control if end shell">fi</span>
        <span class="keyword control if begin shell">if</span> <span class="support function test begin shell">[</span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion command parens shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section parens begin shell">(</span><span class="meta function-call shell"><span class="variable function shell">ask_bool</span></span><span class="meta function-call arguments shell"> <span class="string quoted single shell"><span class="punctuation definition string begin shell">&#39;</span>Setup as a router?<span class="punctuation definition string end shell">&#39;</span></span> <span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">router_default</span></span></span><span class="punctuation section parens end shell">)</span></span><span class="punctuation definition string end shell">&quot;</span></span> <span class="keyword operator logical shell">=</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>true<span class="punctuation definition string end shell">&quot;</span></span> <span class="support function test end shell">]</span></span><span class="keyword operator logical continue shell">;</span> <span class="keyword control if then shell">then</span>
            <span class="meta function-call shell"><span class="variable function shell">add_arg</span></span><span class="meta function-call arguments shell"> setup-router true</span>
        <span class="keyword control if end shell">fi</span>
        <span class="punctuation terminator case shell">;;</span>
    <span class="keyword control case end shell">esac</span>

    <span class="meta function-call shell"><span class="variable function shell">doc</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>Make NextDNS CLI cache responses. This improves latency and reduces the amount<span class="punctuation definition string end shell">&quot;</span></span></span>
    <span class="meta function-call shell"><span class="variable function shell">doc</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>of queries sent to NextDNS.<span class="punctuation definition string end shell">&quot;</span></span></span>
    <span class="keyword control if begin shell">if</span> <span class="support function test begin shell">[</span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion command parens shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section parens begin shell">(</span><span class="meta function-call shell"><span class="variable function shell">guess_host_type</span></span><span class="punctuation section parens end shell">)</span></span><span class="punctuation definition string end shell">&quot;</span></span> <span class="keyword operator logical shell">=</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>router<span class="punctuation definition string end shell">&quot;</span></span> <span class="support function test end shell">]</span></span><span class="keyword operator logical continue shell">;</span> <span class="keyword control if then shell">then</span>
        <span class="meta function-call shell"><span class="variable function shell">doc</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>Note that enabling this feature will disable dnsmasq for DNS to avoid double<span class="punctuation definition string end shell">&quot;</span></span></span>
        <span class="meta function-call shell"><span class="variable function shell">doc</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>caching.<span class="punctuation definition string end shell">&quot;</span></span></span>
    <span class="keyword control if end shell">fi</span>
    <span class="keyword control if begin shell">if</span> <span class="support function test begin shell">[</span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion command parens shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section parens begin shell">(</span><span class="meta function-call shell"><span class="variable function shell">get_config</span></span><span class="meta function-call arguments shell"> cache-size</span><span class="punctuation section parens end shell">)</span></span><span class="punctuation definition string end shell">&quot;</span></span> <span class="keyword operator logical shell">!=</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>0<span class="punctuation definition string end shell">&quot;</span></span> <span class="support function test end shell">]</span></span><span class="keyword operator logical continue shell">;</span> <span class="keyword control if then shell">then</span>
        <span class="variable other readwrite assignment shell">cache_default</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell">true</span>
    <span class="keyword control if end shell">fi</span>
    <span class="keyword control if begin shell">if</span> <span class="support function test begin shell">[</span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion command parens shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section parens begin shell">(</span><span class="meta function-call shell"><span class="variable function shell">ask_bool</span></span><span class="meta function-call arguments shell"> <span class="string quoted single shell"><span class="punctuation definition string begin shell">&#39;</span>Enable caching?<span class="punctuation definition string end shell">&#39;</span></span> <span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">cache_default</span></span></span><span class="punctuation section parens end shell">)</span></span><span class="punctuation definition string end shell">&quot;</span></span> <span class="keyword operator logical shell">=</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>true<span class="punctuation definition string end shell">&quot;</span></span> <span class="support function test end shell">]</span></span><span class="keyword operator logical continue shell">;</span> <span class="keyword control if then shell">then</span>
        <span class="meta function-call shell"><span class="variable function shell">add_arg</span></span><span class="meta function-call arguments shell"> cache-size <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>10MB<span class="punctuation definition string end shell">&quot;</span></span></span>

        <span class="meta function-call shell"><span class="variable function shell">doc</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>Instant refresh will force low TTL on responses sent to clients so they rely<span class="punctuation definition string end shell">&quot;</span></span></span>
        <span class="meta function-call shell"><span class="variable function shell">doc</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>on CLI DNS cache. This will allow changes on your NextDNS config to be applied<span class="punctuation definition string end shell">&quot;</span></span></span>
        <span class="meta function-call shell"><span class="variable function shell">doc</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>on your LAN hosts without having to wait for their cache to expire.<span class="punctuation definition string end shell">&quot;</span></span></span>
        <span class="keyword control if begin shell">if</span> <span class="support function test begin shell">[</span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion command parens shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section parens begin shell">(</span><span class="meta function-call shell"><span class="variable function shell">get_config</span></span><span class="meta function-call arguments shell"> max-ttl</span><span class="punctuation section parens end shell">)</span></span><span class="punctuation definition string end shell">&quot;</span></span> <span class="keyword operator logical shell">=</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>5s<span class="punctuation definition string end shell">&quot;</span></span> <span class="support function test end shell">]</span></span><span class="keyword operator logical continue shell">;</span> <span class="keyword control if then shell">then</span>
            <span class="variable other readwrite assignment shell">instant_refresh_default</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell">true</span>
        <span class="keyword control if end shell">fi</span>
        <span class="keyword control if begin shell">if</span> <span class="support function test begin shell">[</span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion command parens shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section parens begin shell">(</span><span class="meta function-call shell"><span class="variable function shell">ask_bool</span></span><span class="meta function-call arguments shell"> <span class="string quoted single shell"><span class="punctuation definition string begin shell">&#39;</span>Enable instant refresh?<span class="punctuation definition string end shell">&#39;</span></span> <span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">instant_refresh_default</span></span></span><span class="punctuation section parens end shell">)</span></span><span class="punctuation definition string end shell">&quot;</span></span> <span class="keyword operator logical shell">=</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>true<span class="punctuation definition string end shell">&quot;</span></span> <span class="support function test end shell">]</span></span><span class="keyword operator logical continue shell">;</span> <span class="keyword control if then shell">then</span>
            <span class="meta function-call shell"><span class="variable function shell">add_arg</span></span><span class="meta function-call arguments shell"> max-ttl <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>5s<span class="punctuation definition string end shell">&quot;</span></span></span>
        <span class="keyword control if end shell">fi</span>
    <span class="keyword control if end shell">fi</span>

    <span class="keyword control if begin shell">if</span> <span class="support function test begin shell">[</span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion command parens shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section parens begin shell">(</span><span class="meta function-call shell"><span class="variable function shell">guess_host_type</span></span><span class="punctuation section parens end shell">)</span></span><span class="punctuation definition string end shell">&quot;</span></span> <span class="keyword operator logical shell">!=</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>router<span class="punctuation definition string end shell">&quot;</span></span> <span class="support function test end shell">]</span></span><span class="keyword operator logical continue shell">;</span> <span class="keyword control if then shell">then</span>
        <span class="meta function-call shell"><span class="variable function shell">doc</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>Changes DNS settings of the host automatically when NextDNS is started.<span class="punctuation definition string end shell">&quot;</span></span></span>
        <span class="meta function-call shell"><span class="variable function shell">doc</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>If you say no here, you will have to manually configure DNS to 127.0.0.1.<span class="punctuation definition string end shell">&quot;</span></span></span>
        <span class="meta function-call shell"><span class="variable function shell">add_arg_bool_ask</span></span><span class="meta function-call arguments shell"> auto-activate <span class="string quoted single shell"><span class="punctuation definition string begin shell">&#39;</span>Automatically setup local host DNS?<span class="punctuation definition string end shell">&#39;</span></span> true</span>
    <span class="keyword control if end shell">fi</span>
    <span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> shellcheck disable=SC2086</span><span class="comment line number-sign shell">
</span>    <span class="meta function-call shell"><span class="variable function shell">asroot</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">NEXTDNS_BIN</span></span><span class="punctuation definition string end shell">&quot;</span></span> install <span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">args</span></span></span>
<span class="punctuation section braces end shell">}</span></span>

<span class="meta function shell"><span class="entity name function shell">post_install</span><span class="punctuation section parens begin shell">(</span><span class="punctuation section parens end shell">)</span> <span class="punctuation section braces begin shell">{</span>
    <span class="meta function-call shell"><span class="variable function shell">println</span></span>
    <span class="meta function-call shell"><span class="variable function shell">println</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>Congratulations! NextDNS is now installed.<span class="punctuation definition string end shell">&quot;</span></span></span>
    <span class="meta function-call shell"><span class="variable function shell">println</span></span>
    <span class="meta function-call shell"><span class="variable function shell">println</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>To upgrade/uninstall, run this command again and select the appropriate option.<span class="punctuation definition string end shell">&quot;</span></span></span>
    <span class="meta function-call shell"><span class="variable function shell">println</span></span>
    <span class="meta function-call shell"><span class="variable function shell">println</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>You can use the NextDNS command to control the daemon.<span class="punctuation definition string end shell">&quot;</span></span></span>
    <span class="meta function-call shell"><span class="variable function shell">println</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>Here are a few important commands to know:<span class="punctuation definition string end shell">&quot;</span></span></span>
    <span class="meta function-call shell"><span class="variable function shell">println</span></span>
    <span class="meta function-call shell"><span class="variable function shell">println</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span># Start, stop, restart the daemon:<span class="punctuation definition string end shell">&quot;</span></span></span>
    <span class="meta function-call shell"><span class="variable function shell">println</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>nextdns start<span class="punctuation definition string end shell">&quot;</span></span></span>
    <span class="meta function-call shell"><span class="variable function shell">println</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>nextdns stop<span class="punctuation definition string end shell">&quot;</span></span></span>
    <span class="meta function-call shell"><span class="variable function shell">println</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>nextdns restart<span class="punctuation definition string end shell">&quot;</span></span></span>
    <span class="meta function-call shell"><span class="variable function shell">println</span></span>
    <span class="meta function-call shell"><span class="variable function shell">println</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span># Configure the local host to point to NextDNS or not:<span class="punctuation definition string end shell">&quot;</span></span></span>
    <span class="meta function-call shell"><span class="variable function shell">println</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>nextdns activate<span class="punctuation definition string end shell">&quot;</span></span></span>
    <span class="meta function-call shell"><span class="variable function shell">println</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>nextdns deactivate<span class="punctuation definition string end shell">&quot;</span></span></span>
    <span class="meta function-call shell"><span class="variable function shell">println</span></span>
    <span class="meta function-call shell"><span class="variable function shell">println</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span># Explore daemon logs:<span class="punctuation definition string end shell">&quot;</span></span></span>
    <span class="meta function-call shell"><span class="variable function shell">println</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>nextdns log<span class="punctuation definition string end shell">&quot;</span></span></span>
    <span class="meta function-call shell"><span class="variable function shell">println</span></span>
    <span class="meta function-call shell"><span class="variable function shell">println</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span># For more commands, use:<span class="punctuation definition string end shell">&quot;</span></span></span>
    <span class="meta function-call shell"><span class="variable function shell">println</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>nextdns help<span class="punctuation definition string end shell">&quot;</span></span></span>
    <span class="meta function-call shell"><span class="variable function shell">println</span></span>
<span class="punctuation section braces end shell">}</span></span>

<span class="meta function shell"><span class="entity name function shell">install_bin</span><span class="punctuation section parens begin shell">(</span><span class="punctuation section parens end shell">)</span> <span class="punctuation section braces begin shell">{</span>
    <span class="variable other readwrite assignment shell">bin_path</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell"><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">NEXTDNS_BIN</span></span></span>
    <span class="keyword control if begin shell">if</span> <span class="support function test begin shell">[</span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">1</span></span><span class="punctuation definition string end shell">&quot;</span></span> <span class="support function test end shell">]</span></span><span class="keyword operator logical continue shell">;</span> <span class="keyword control if then shell">then</span>
        <span class="variable other readwrite assignment shell">bin_path</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell"><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">1</span></span></span>
    <span class="keyword control if end shell">fi</span>
    <span class="meta function-call shell"><span class="variable function shell">log_debug</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>Installing <span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">INSTALL_RELEASE</span></span> binary for <span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">GOOS</span></span>/<span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">GOARCH</span></span> to <span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">bin_path</span></span><span class="punctuation definition string end shell">&quot;</span></span></span>
    <span class="keyword control case begin shell">case</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">INSTALL_RELEASE</span></span><span class="punctuation definition string end shell">&quot;</span></span> <span class="keyword control case in shell">in</span>
    <span class="keyword operator regexp quantifier shell">*</span>/<span class="keyword operator regexp quantifier shell">*</span><span class="keyword control case item shell">)</span>
        <span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> Snapshot</span><span class="comment line number-sign shell">
</span>        <span class="variable other readwrite assignment shell">branch</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell"><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section expansion parameter begin shell">{</span></span><span class="meta group expansion parameter shell"><span class="variable other readwrite shell">INSTALL_RELEASE<span class="keyword operator expansion shell">%</span></span></span><span class="meta group expansion parameter shell">/<span class="keyword operator regexp quantifier shell">*</span></span><span class="meta group expansion parameter shell"><span class="punctuation section expansion parameter end shell">}</span></span></span>
        <span class="variable other readwrite assignment shell">hash</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell"><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section expansion parameter begin shell">{</span></span><span class="meta group expansion parameter shell"><span class="variable other readwrite shell">INSTALL_RELEASE<span class="keyword operator expansion shell">#</span></span></span><span class="meta group expansion parameter shell"><span class="keyword operator regexp quantifier shell">*</span>/</span><span class="meta group expansion parameter shell"><span class="punctuation section expansion parameter end shell">}</span></span></span>
        <span class="variable other readwrite assignment shell">url</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell"><span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>https://snapshot.nextdns.io/<span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section expansion parameter begin shell">{</span></span><span class="meta group expansion parameter shell"><span class="variable other readwrite shell">branch</span></span><span class="meta group expansion parameter shell"><span class="punctuation section expansion parameter end shell">}</span></span>/nextdns-<span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section expansion parameter begin shell">{</span></span><span class="meta group expansion parameter shell"><span class="variable other readwrite shell">hash</span></span><span class="meta group expansion parameter shell"><span class="punctuation section expansion parameter end shell">}</span></span>_<span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section expansion parameter begin shell">{</span></span><span class="meta group expansion parameter shell"><span class="variable other readwrite shell">GOOS</span></span><span class="meta group expansion parameter shell"><span class="punctuation section expansion parameter end shell">}</span></span>_<span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section expansion parameter begin shell">{</span></span><span class="meta group expansion parameter shell"><span class="variable other readwrite shell">GOARCH</span></span><span class="meta group expansion parameter shell"><span class="punctuation section expansion parameter end shell">}</span></span>.tar.gz<span class="punctuation definition string end shell">&quot;</span></span></span>
        <span class="punctuation terminator case shell">;;</span>
    <span class="keyword operator regexp quantifier shell">*</span><span class="keyword control case item shell">)</span>
        <span class="variable other readwrite assignment shell">url</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell"><span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>https://github.com/nextdns/nextdns/releases/download/v<span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section expansion parameter begin shell">{</span></span><span class="meta group expansion parameter shell"><span class="variable other readwrite shell">INSTALL_RELEASE</span></span><span class="meta group expansion parameter shell"><span class="punctuation section expansion parameter end shell">}</span></span>/nextdns_<span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section expansion parameter begin shell">{</span></span><span class="meta group expansion parameter shell"><span class="variable other readwrite shell">INSTALL_RELEASE</span></span><span class="meta group expansion parameter shell"><span class="punctuation section expansion parameter end shell">}</span></span>_<span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section expansion parameter begin shell">{</span></span><span class="meta group expansion parameter shell"><span class="variable other readwrite shell">GOOS</span></span><span class="meta group expansion parameter shell"><span class="punctuation section expansion parameter end shell">}</span></span>_<span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section expansion parameter begin shell">{</span></span><span class="meta group expansion parameter shell"><span class="variable other readwrite shell">GOARCH</span></span><span class="meta group expansion parameter shell"><span class="punctuation section expansion parameter end shell">}</span></span>.tar.gz<span class="punctuation definition string end shell">&quot;</span></span></span>
        <span class="punctuation terminator case shell">;;</span>
    <span class="keyword control case end shell">esac</span>
    <span class="meta function-call shell"><span class="variable function shell">log_debug</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>Downloading <span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">url</span></span><span class="punctuation definition string end shell">&quot;</span></span></span>
    <span class="meta function-call shell"><span class="variable function shell">asroot</span></span><span class="meta function-call arguments shell"> mkdir<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>p</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion command parens shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section parens begin shell">(</span><span class="meta function-call shell"><span class="variable function shell">dirname</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">bin_path</span></span><span class="punctuation definition string end shell">&quot;</span></span></span><span class="punctuation section parens end shell">)</span></span><span class="punctuation definition string end shell">&quot;</span></span></span> <span class="keyword operator logical and shell">&amp;&amp;</span>
        <span class="meta function-call shell"><span class="variable function shell">curl</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>sL</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">url</span></span><span class="punctuation definition string end shell">&quot;</span></span></span> <span class="keyword operator logical pipe shell">|</span> <span class="meta function-call shell"><span class="variable function shell">asroot</span></span><span class="meta function-call arguments shell"> sh<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>c</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>tar Ozxf - nextdns &gt; <span class="punctuation definition string end shell">&quot;</span></span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">bin_path</span></span><span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="punctuation definition string end shell">&quot;</span></span></span> <span class="keyword operator logical and shell">&amp;&amp;</span>
        <span class="meta function-call shell"><span class="variable function shell">asroot</span></span><span class="meta function-call arguments shell"> chmod 755 <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">bin_path</span></span><span class="punctuation definition string end shell">&quot;</span></span></span>
<span class="punctuation section braces end shell">}</span></span>

<span class="meta function shell"><span class="entity name function shell">upgrade_bin</span><span class="punctuation section parens begin shell">(</span><span class="punctuation section parens end shell">)</span> <span class="punctuation section braces begin shell">{</span>
    <span class="variable other readwrite assignment shell">tmp</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell"><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">NEXTDNS_BIN</span></span>.tmp</span>
    <span class="keyword control if begin shell">if</span> <span class="meta function-call shell"><span class="variable function shell">install_bin</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">tmp</span></span><span class="punctuation definition string end shell">&quot;</span></span></span><span class="keyword operator logical continue shell">;</span> <span class="keyword control if then shell">then</span>
        <span class="meta function-call shell"><span class="variable function shell">asroot</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">NEXTDNS_BIN</span></span><span class="punctuation definition string end shell">&quot;</span></span> uninstall</span>
        <span class="meta function-call shell"><span class="variable function shell">asroot</span></span><span class="meta function-call arguments shell"> mv <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">tmp</span></span><span class="punctuation definition string end shell">&quot;</span></span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">NEXTDNS_BIN</span></span><span class="punctuation definition string end shell">&quot;</span></span></span>
        <span class="meta function-call shell"><span class="variable function shell">asroot</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">NEXTDNS_BIN</span></span><span class="punctuation definition string end shell">&quot;</span></span> install</span>
    <span class="keyword control if end shell">fi</span>
    <span class="meta function-call shell"><span class="variable function shell">log_debug</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>Removing spurious temporary install file<span class="punctuation definition string end shell">&quot;</span></span></span>
    <span class="meta function-call shell"><span class="variable function shell">asroot</span></span><span class="meta function-call arguments shell"> rm<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>rf</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">tmp</span></span><span class="punctuation definition string end shell">&quot;</span></span></span>
<span class="punctuation section braces end shell">}</span></span>

<span class="meta function shell"><span class="entity name function shell">uninstall_bin</span><span class="punctuation section parens begin shell">(</span><span class="punctuation section parens end shell">)</span> <span class="punctuation section braces begin shell">{</span>
    <span class="meta function-call shell"><span class="variable function shell">asroot</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">NEXTDNS_BIN</span></span><span class="punctuation definition string end shell">&quot;</span></span> uninstall</span>
    <span class="meta function-call shell"><span class="variable function shell">asroot</span></span><span class="meta function-call arguments shell"> rm<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>f</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">NEXTDNS_BIN</span></span><span class="punctuation definition string end shell">&quot;</span></span></span>
<span class="punctuation section braces end shell">}</span></span>

<span class="meta function shell"><span class="entity name function shell">install_rpm</span><span class="punctuation section parens begin shell">(</span><span class="punctuation section parens end shell">)</span> <span class="punctuation section braces begin shell">{</span>
    <span class="meta function-call shell"><span class="variable function shell">asroot</span></span><span class="meta function-call arguments shell"> curl<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>Ls</span> https://repo.nextdns.io/nextdns.repo<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>o</span> /etc/yum.repos.d/nextdns.repo</span> <span class="keyword operator logical and shell">&amp;&amp;</span>
        <span class="meta function-call shell"><span class="variable function shell">asroot</span></span><span class="meta function-call arguments shell"> yum install<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>y</span> nextdns</span>
<span class="punctuation section braces end shell">}</span></span>

<span class="meta function shell"><span class="entity name function shell">upgrade_rpm</span><span class="punctuation section parens begin shell">(</span><span class="punctuation section parens end shell">)</span> <span class="punctuation section braces begin shell">{</span>
    <span class="meta function-call shell"><span class="variable function shell">asroot</span></span><span class="meta function-call arguments shell"> yum update<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>y</span> nextdns</span>
<span class="punctuation section braces end shell">}</span></span>

<span class="meta function shell"><span class="entity name function shell">uninstall_rpm</span><span class="punctuation section parens begin shell">(</span><span class="punctuation section parens end shell">)</span> <span class="punctuation section braces begin shell">{</span>
    <span class="meta function-call shell"><span class="variable function shell">asroot</span></span><span class="meta function-call arguments shell"> yum remove<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>y</span> nextdns</span>
<span class="punctuation section braces end shell">}</span></span>

<span class="meta function shell"><span class="entity name function shell">install_zypper</span><span class="punctuation section parens begin shell">(</span><span class="punctuation section parens end shell">)</span> <span class="punctuation section braces begin shell">{</span>
    <span class="keyword control if begin shell">if</span> <span class="meta function-call shell"><span class="variable function shell">asroot</span></span><span class="meta function-call arguments shell"> zypper repos</span> <span class="keyword operator logical pipe shell">|</span> <span class="meta function-call shell"><span class="variable function shell">grep</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>q</span> nextdns <span class="keyword operator assignment redirection shell">&gt;</span>/dev/null</span><span class="keyword operator logical continue shell">;</span> <span class="keyword control if then shell">then</span>
        <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>Repository nextdns already exists. Skipping adding repository...<span class="punctuation definition string end shell">&quot;</span></span></span>
    <span class="keyword control if else shell">else</span>
        <span class="meta function-call shell"><span class="variable function shell">asroot</span></span><span class="meta function-call arguments shell"> zypper ar<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>f</span><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>r</span> https://repo.nextdns.io/nextdns.repo nextdns</span>
    <span class="keyword control if end shell">fi</span>
    <span class="meta function-call shell"><span class="variable function shell">asroot</span></span><span class="meta function-call arguments shell"> zypper refresh</span> <span class="keyword operator logical and shell">&amp;&amp;</span> <span class="meta function-call shell"><span class="variable function shell">asroot</span></span><span class="meta function-call arguments shell"> zypper in<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>y</span> nextdns</span>
<span class="punctuation section braces end shell">}</span></span>

<span class="meta function shell"><span class="entity name function shell">upgrade_zypper</span><span class="punctuation section parens begin shell">(</span><span class="punctuation section parens end shell">)</span> <span class="punctuation section braces begin shell">{</span>
    <span class="meta function-call shell"><span class="variable function shell">asroot</span></span><span class="meta function-call arguments shell"> zypper up nextdns</span>
<span class="punctuation section braces end shell">}</span></span>

<span class="meta function shell"><span class="entity name function shell">uninstall_zypper</span><span class="punctuation section parens begin shell">(</span><span class="punctuation section parens end shell">)</span> <span class="punctuation section braces begin shell">{</span>
    <span class="meta function-call shell"><span class="variable function shell">asroot</span></span><span class="meta function-call arguments shell"> zypper remove<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>y</span> nextdns</span>
    <span class="keyword control case begin shell">case</span> <span class="meta group expansion command parens shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section parens begin shell">(</span><span class="meta function-call shell"><span class="variable function shell">ask_bool</span></span><span class="meta function-call arguments shell"> <span class="string quoted single shell"><span class="punctuation definition string begin shell">&#39;</span>Do you want to remove the repository from the repositories list?<span class="punctuation definition string end shell">&#39;</span></span> true</span><span class="punctuation section parens end shell">)</span></span> <span class="keyword control case in shell">in</span>
    true<span class="keyword control case item shell">)</span>
        <span class="meta function-call shell"><span class="variable function shell">asroot</span></span><span class="meta function-call arguments shell"> zypper removerepo nextdns</span>
        <span class="punctuation terminator case shell">;;</span>
    <span class="keyword control case end shell">esac</span>
<span class="punctuation section braces end shell">}</span></span>

<span class="meta function shell"><span class="entity name function shell">install_deb</span><span class="punctuation section parens begin shell">(</span><span class="punctuation section parens end shell">)</span> <span class="punctuation section braces begin shell">{</span>
    <span class="keyword control if begin shell">if</span> <span class="support function test begin shell">[</span><span class="meta function-call arguments shell"> <span class="variable parameter option shell"><span class="punctuation definition parameter shell">-</span>f</span> /etc/default/ubnt-dpkg-cache <span class="support function test end shell">]</span></span><span class="keyword operator logical continue shell">;</span> <span class="keyword control if then shell">then</span>
        <span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> On UnifiOS 2, make sure the package is persisted over upgrades</span><span class="comment line number-sign shell">
</span>        <span class="meta function-call shell"><span class="variable function shell">sed</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>e</span> <span class="string quoted single shell"><span class="punctuation definition string begin shell">&#39;</span>/^DPKG_CACHE_UBNT_PKGS+=&quot; nextdns&quot;/{:a;n;ba;q}<span class="punctuation definition string end shell">&#39;</span></span> <span class="punctuation separator continuation line shell">\
</span><span class="variable parameter option shell"><span class="punctuation definition parameter shell">            -</span>e</span> <span class="string quoted single shell"><span class="punctuation definition string begin shell">&#39;</span>$aDPKG_CACHE_UBNT_PKGS+=&quot; nextdns&quot;<span class="punctuation definition string end shell">&#39;</span></span> <span class="punctuation separator continuation line shell">\
</span><span class="variable parameter option shell"><span class="punctuation definition parameter shell">            -</span>i</span> /etc/default/ubnt-dpkg-cache</span>
    <span class="keyword control if end shell">fi</span>

    <span class="meta function-call shell"><span class="variable function shell">install_deb_keyring</span></span> <span class="keyword operator logical and shell">&amp;&amp;</span>
        <span class="meta function-call shell"><span class="variable function shell">asroot</span></span><span class="meta function-call arguments shell"> sh<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>c</span> <span class="string quoted single shell"><span class="punctuation definition string begin shell">&#39;</span>echo &quot;deb [signed-by=/etc/apt/keyrings/nextdns.gpg] https://repo.nextdns.io/deb stable main&quot; &gt; /etc/apt/sources.list.d/nextdns.list<span class="punctuation definition string end shell">&#39;</span></span></span> <span class="keyword operator logical and shell">&amp;&amp;</span>
        <span class="punctuation definition compound begin shell">(</span><span class="meta function-call shell"><span class="variable function shell">dpkg</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> --</span>compare-versions</span> <span class="meta group expansion command parens shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section parens begin shell">(</span><span class="meta function-call shell"><span class="variable function shell">dpkg-query</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> --</span>showformat</span><span class="keyword operator assignment option shell">=</span><span class="string quoted single shell"><span class="punctuation definition string begin shell">&#39;</span>${Version}<span class="punctuation definition string end shell">&#39;</span></span><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> --</span>show</span> apt</span><span class="punctuation section parens end shell">)</span></span> ge 1.1</span> <span class="keyword operator logical or shell">||</span>
         <span class="meta function-call shell"><span class="variable function shell">asroot</span></span><span class="meta function-call arguments shell"> ln<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>s</span> /etc/apt/keyrings/nextdns.gpg /etc/apt/trusted.gpg.d/.</span><span class="punctuation definition compound end shell">)</span> <span class="keyword operator logical and shell">&amp;&amp;</span>
        <span class="punctuation definition compound begin shell">(</span><span class="meta function-call shell"><span class="variable function shell">test</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">OS</span></span><span class="punctuation definition string end shell">&quot;</span></span> = <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>debian<span class="punctuation definition string end shell">&quot;</span></span></span> <span class="keyword operator logical and shell">&amp;&amp;</span> <span class="meta function-call shell"><span class="variable function shell">asroot</span></span><span class="meta function-call arguments shell"> apt-get<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>y</span> install apt-transport-https</span> <span class="keyword operator logical or shell">||</span> <span class="meta function-call shell"><span class="variable function shell">true</span></span><span class="punctuation definition compound end shell">)</span> <span class="keyword operator logical and shell">&amp;&amp;</span>
        <span class="meta function-call shell"><span class="variable function shell">asroot</span></span><span class="meta function-call arguments shell"> apt-get update</span> <span class="keyword operator logical and shell">&amp;&amp;</span>
        <span class="meta function-call shell"><span class="variable function shell">asroot</span></span><span class="meta function-call arguments shell"> apt-get install<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>y</span> nextdns</span>
<span class="punctuation section braces end shell">}</span></span>

<span class="meta function shell"><span class="entity name function shell">install_deb_keyring</span><span class="punctuation section parens begin shell">(</span><span class="punctuation section parens end shell">)</span> <span class="punctuation section braces begin shell">{</span>
    <span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> Fallback on curl, some debian based distrib don&#39;t have wget while debian</span><span class="comment line number-sign shell">
</span>    <span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> doesn&#39;t have curl by default.</span><span class="comment line number-sign shell">
</span>    <span class="meta function-call shell"><span class="variable function shell">asroot</span></span><span class="meta function-call arguments shell"> mkdir<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>p</span> /etc/apt/keyrings</span>
    <span class="punctuation definition compound begin shell">(</span> <span class="meta function-call shell"><span class="variable function shell">asroot</span></span><span class="meta function-call arguments shell"> wget<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>qO</span> /etc/apt/keyrings/nextdns.gpg https://repo.nextdns.io/nextdns.gpg</span> <span class="keyword operator logical or shell">||</span>
      <span class="meta function-call shell"><span class="variable function shell">asroot</span></span><span class="meta function-call arguments shell"> curl<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>sfL</span> https://repo.nextdns.io/nextdns.gpg<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>o</span> /etc/apt/keyrings/nextdns.gpg </span><span class="punctuation definition compound end shell">)</span> <span class="keyword operator logical and shell">&amp;&amp;</span>
        <span class="meta function-call shell"><span class="variable function shell">asroot</span></span><span class="meta function-call arguments shell"> chmod 0644 /etc/apt/keyrings/nextdns.gpg</span>
<span class="punctuation section braces end shell">}</span></span>

<span class="meta function shell"><span class="entity name function shell">upgrade_deb</span><span class="punctuation section parens begin shell">(</span><span class="punctuation section parens end shell">)</span> <span class="punctuation section braces begin shell">{</span>
    <span class="meta function-call shell"><span class="variable function shell">install_deb_keyring</span></span> <span class="keyword operator logical and shell">&amp;&amp;</span>
        <span class="meta function-call shell"><span class="variable function shell">asroot</span></span><span class="meta function-call arguments shell"> apt-get update</span> <span class="keyword operator logical and shell">&amp;&amp;</span>
        <span class="meta function-call shell"><span class="variable function shell">asroot</span></span><span class="meta function-call arguments shell"> apt-get install<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>y</span> nextdns</span>
<span class="punctuation section braces end shell">}</span></span>

<span class="meta function shell"><span class="entity name function shell">uninstall_deb</span><span class="punctuation section parens begin shell">(</span><span class="punctuation section parens end shell">)</span> <span class="punctuation section braces begin shell">{</span>
    <span class="meta function-call shell"><span class="variable function shell">asroot</span></span><span class="meta function-call arguments shell"> apt-get remove<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>y</span> nextdns</span>
<span class="punctuation section braces end shell">}</span></span>

<span class="meta function shell"><span class="entity name function shell">install_apk</span><span class="punctuation section parens begin shell">(</span><span class="punctuation section parens end shell">)</span> <span class="punctuation section braces begin shell">{</span>
    <span class="variable other readwrite assignment shell">repo</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell">https://repo.nextdns.io/apk</span>
    <span class="meta function-call shell"><span class="variable function shell">asroot</span></span><span class="meta function-call arguments shell"> wget<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>O</span> /etc/apk/keys/nextdns.pub https://repo.nextdns.io/nextdns.pub</span> <span class="keyword operator logical and shell">&amp;&amp;</span>
        <span class="punctuation definition compound begin shell">(</span><span class="meta function-call shell"><span class="variable function shell">grep</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>v</span> <span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">repo</span></span> /etc/apk/repositories</span><span class="keyword operator logical continue shell">;</span> <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">repo</span></span></span><span class="punctuation definition compound end shell">)</span> <span class="keyword operator logical pipe shell">|</span> <span class="meta function-call shell"><span class="variable function shell">asroot</span></span><span class="meta function-call arguments shell"> tee /etc/apk/repositories <span class="keyword operator assignment redirection shell">&gt;</span>/dev/null</span> <span class="keyword operator logical and shell">&amp;&amp;</span>
        <span class="meta function-call shell"><span class="variable function shell">asroot</span></span><span class="meta function-call arguments shell"> apk update</span> <span class="keyword operator logical and shell">&amp;&amp;</span>
        <span class="meta function-call shell"><span class="variable function shell">asroot</span></span><span class="meta function-call arguments shell"> apk add nextdns</span>
<span class="punctuation section braces end shell">}</span></span>

<span class="meta function shell"><span class="entity name function shell">upgrade_apk</span><span class="punctuation section parens begin shell">(</span><span class="punctuation section parens end shell">)</span> <span class="punctuation section braces begin shell">{</span>
    <span class="meta function-call shell"><span class="variable function shell">asroot</span></span><span class="meta function-call arguments shell"> apk update</span> <span class="keyword operator logical and shell">&amp;&amp;</span> <span class="meta function-call shell"><span class="variable function shell">asroot</span></span><span class="meta function-call arguments shell"> apk upgrade nextdns</span>
<span class="punctuation section braces end shell">}</span></span>

<span class="meta function shell"><span class="entity name function shell">uninstall_apk</span><span class="punctuation section parens begin shell">(</span><span class="punctuation section parens end shell">)</span> <span class="punctuation section braces begin shell">{</span>
    <span class="meta function-call shell"><span class="variable function shell">asroot</span></span><span class="meta function-call arguments shell"> apk del nextdns</span>
<span class="punctuation section braces end shell">}</span></span>

<span class="meta function shell"><span class="entity name function shell">install_arch</span><span class="punctuation section parens begin shell">(</span><span class="punctuation section parens end shell">)</span> <span class="punctuation section braces begin shell">{</span>
    <span class="meta function-call shell"><span class="variable function shell">asroot</span></span><span class="meta function-call arguments shell"> pacman<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>Sy</span> yay</span> <span class="keyword operator logical and shell">&amp;&amp;</span>
        <span class="meta function-call shell"><span class="variable function shell">yay</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>Sy</span> nextdns</span>
<span class="punctuation section braces end shell">}</span></span>

<span class="meta function shell"><span class="entity name function shell">upgrade_arch</span><span class="punctuation section parens begin shell">(</span><span class="punctuation section parens end shell">)</span> <span class="punctuation section braces begin shell">{</span>
    <span class="meta function-call shell"><span class="variable function shell">yay</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>Suy</span> nextdns</span>
<span class="punctuation section braces end shell">}</span></span>

<span class="meta function shell"><span class="entity name function shell">uninstall_arch</span><span class="punctuation section parens begin shell">(</span><span class="punctuation section parens end shell">)</span> <span class="punctuation section braces begin shell">{</span>
    <span class="meta function-call shell"><span class="variable function shell">asroot</span></span><span class="meta function-call arguments shell"> pacman<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>R</span> nextdns</span>
<span class="punctuation section braces end shell">}</span></span>

<span class="meta function shell"><span class="entity name function shell">install_merlin_path</span><span class="punctuation section parens begin shell">(</span><span class="punctuation section parens end shell">)</span> <span class="punctuation section braces begin shell">{</span>
    <span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> Add next to Merlin&#39;s path</span><span class="comment line number-sign shell">
</span>    <span class="meta function-call shell"><span class="variable function shell">mkdir</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>p</span> /tmp/opt/sbin</span>
    <span class="meta function-call shell"><span class="variable function shell">ln</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>sf</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">NEXTDNS_BIN</span></span><span class="punctuation definition string end shell">&quot;</span></span> /tmp/opt/sbin/nextdns</span>
<span class="punctuation section braces end shell">}</span></span>

<span class="meta function shell"><span class="entity name function shell">install_merlin</span><span class="punctuation section parens begin shell">(</span><span class="punctuation section parens end shell">)</span> <span class="punctuation section braces begin shell">{</span>
    <span class="keyword control if begin shell">if</span> <span class="meta function-call shell"><span class="variable function shell">install_bin</span></span><span class="keyword operator logical continue shell">;</span> <span class="keyword control if then shell">then</span>
        <span class="meta function-call shell"><span class="variable function shell">install_merlin_path</span></span>
    <span class="keyword control if end shell">fi</span>
<span class="punctuation section braces end shell">}</span></span>

<span class="meta function shell"><span class="entity name function shell">uninstall_merlin</span><span class="punctuation section parens begin shell">(</span><span class="punctuation section parens end shell">)</span> <span class="punctuation section braces begin shell">{</span>
    <span class="meta function-call shell"><span class="variable function shell">uninstall_bin</span></span>
    <span class="meta function-call shell"><span class="variable function shell">rm</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>f</span> /tmp/opt/sbin/nextdns</span>
<span class="punctuation section braces end shell">}</span></span>

<span class="meta function shell"><span class="entity name function shell">upgrade_merlin</span><span class="punctuation section parens begin shell">(</span><span class="punctuation section parens end shell">)</span> <span class="punctuation section braces begin shell">{</span>
    <span class="keyword control if begin shell">if</span> <span class="meta function-call shell"><span class="variable function shell">upgrade_bin</span></span><span class="keyword operator logical continue shell">;</span> <span class="keyword control if then shell">then</span>
        <span class="meta function-call shell"><span class="variable function shell">install_merlin_path</span></span>
    <span class="keyword control if end shell">fi</span>
<span class="punctuation section braces end shell">}</span></span>

<span class="meta function shell"><span class="entity name function shell">install_openwrt</span><span class="punctuation section parens begin shell">(</span><span class="punctuation section parens end shell">)</span> <span class="punctuation section braces begin shell">{</span>
    <span class="meta function-call shell"><span class="variable function shell">opkg</span></span><span class="meta function-call arguments shell"> update</span> <span class="keyword operator logical and shell">&amp;&amp;</span>
        <span class="meta function-call shell"><span class="variable function shell">opkg</span></span><span class="meta function-call arguments shell"> install nextdns</span>
    <span class="variable other readwrite assignment shell">rt</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell"><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable language shell">?</span></span></span>
    <span class="keyword control if begin shell">if</span> <span class="support function test begin shell">[</span><span class="meta function-call arguments shell"> <span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">rt</span></span> <span class="variable parameter option shell"><span class="punctuation definition parameter shell">-</span>eq</span> 0 <span class="support function test end shell">]</span></span><span class="keyword operator logical continue shell">;</span> <span class="keyword control if then shell">then</span>
        <span class="keyword control case begin shell">case</span> <span class="meta group expansion command parens shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section parens begin shell">(</span><span class="meta function-call shell"><span class="variable function shell">ask_bool</span></span><span class="meta function-call arguments shell"> <span class="string quoted single shell"><span class="punctuation definition string begin shell">&#39;</span>Install the GUI?<span class="punctuation definition string end shell">&#39;</span></span> true</span><span class="punctuation section parens end shell">)</span></span> <span class="keyword control case in shell">in</span>
        true<span class="keyword control case item shell">)</span>
            <span class="meta function-call shell"><span class="variable function shell">opkg</span></span><span class="meta function-call arguments shell"> install luci-app-nextdns</span>
            <span class="variable other readwrite assignment shell">rt</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell"><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable language shell">?</span></span></span>
            <span class="punctuation terminator case shell">;;</span>
        <span class="keyword control case end shell">esac</span>
    <span class="keyword control if end shell">fi</span>
    <span class="meta function-call shell"><span class="keyword control return shell">return</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">rt</span></span></span>
<span class="punctuation section braces end shell">}</span></span>

<span class="meta function shell"><span class="entity name function shell">upgrade_openwrt</span><span class="punctuation section parens begin shell">(</span><span class="punctuation section parens end shell">)</span> <span class="punctuation section braces begin shell">{</span>
    <span class="meta function-call shell"><span class="variable function shell">opkg</span></span><span class="meta function-call arguments shell"> update</span> <span class="keyword operator logical and shell">&amp;&amp;</span>
        <span class="meta function-call shell"><span class="variable function shell">opkg</span></span><span class="meta function-call arguments shell"> upgrade nextdns</span>
<span class="punctuation section braces end shell">}</span></span>

<span class="meta function shell"><span class="entity name function shell">uninstall_openwrt</span><span class="punctuation section parens begin shell">(</span><span class="punctuation section parens end shell">)</span> <span class="punctuation section braces begin shell">{</span>
    <span class="meta function-call shell"><span class="variable function shell">opkg</span></span><span class="meta function-call arguments shell"> remove nextdns</span>
<span class="punctuation section braces end shell">}</span></span>

<span class="meta function shell"><span class="entity name function shell">install_ddwrt</span><span class="punctuation section parens begin shell">(</span><span class="punctuation section parens end shell">)</span> <span class="punctuation section braces begin shell">{</span>
    <span class="keyword control if begin shell">if</span> <span class="support function test begin shell">[</span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion command parens shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section parens begin shell">(</span><span class="meta function-call shell"><span class="variable function shell">nvram</span></span><span class="meta function-call arguments shell"> get enable_jffs2</span><span class="punctuation section parens end shell">)</span></span><span class="punctuation definition string end shell">&quot;</span></span> <span class="keyword operator logical shell">=</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>0<span class="punctuation definition string end shell">&quot;</span></span> <span class="support function test end shell">]</span></span><span class="keyword operator logical continue shell">;</span> <span class="keyword control if then shell">then</span>
        <span class="meta function-call shell"><span class="variable function shell">log_error</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>JFFS support not enabled<span class="punctuation definition string end shell">&quot;</span></span></span>
        <span class="meta function-call shell"><span class="variable function shell">log_info</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>To enabled JFFS:<span class="punctuation definition string end shell">&quot;</span></span></span>
        <span class="meta function-call shell"><span class="variable function shell">log_info</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span> 1. On the router web page click on Administration.<span class="punctuation definition string end shell">&quot;</span></span></span>
        <span class="meta function-call shell"><span class="variable function shell">log_info</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span> 2. Scroll down until you see JFFS2 Support section.<span class="punctuation definition string end shell">&quot;</span></span></span>
        <span class="meta function-call shell"><span class="variable function shell">log_info</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span> 3. Click Enable JFFS.<span class="punctuation definition string end shell">&quot;</span></span></span>
        <span class="meta function-call shell"><span class="variable function shell">log_info</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span> 4. Click Save.<span class="punctuation definition string end shell">&quot;</span></span></span>
        <span class="meta function-call shell"><span class="variable function shell">log_info</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span> 5. Wait couple seconds, then click Apply.<span class="punctuation definition string end shell">&quot;</span></span></span>
        <span class="meta function-call shell"><span class="variable function shell">log_info</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span> 6. Wait again. Go back to the Enable JFFS section, and enable Clean JFFS.<span class="punctuation definition string end shell">&quot;</span></span></span>
        <span class="meta function-call shell"><span class="variable function shell">log_info</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span> 7. Do not click Save. Click Apply instead.<span class="punctuation definition string end shell">&quot;</span></span></span>
        <span class="meta function-call shell"><span class="variable function shell">log_info</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span> 8. Wait till you get the web-GUI back, then disable Clean JFFS again.<span class="punctuation definition string end shell">&quot;</span></span></span>
        <span class="meta function-call shell"><span class="variable function shell">log_info</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span> 9. Click Save.<span class="punctuation definition string end shell">&quot;</span></span></span>
        <span class="meta function-call shell"><span class="variable function shell">log_info</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>10. Relaunch this installer.<span class="punctuation definition string end shell">&quot;</span></span></span>
        <span class="meta function-call shell"><span class="support function exit shell">exit</span></span><span class="meta function-call arguments shell"> 1</span>
    <span class="keyword control if end shell">fi</span>
    <span class="meta function-call shell"><span class="variable function shell">mkdir</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>p</span> /jffs/nextdns</span> <span class="keyword operator logical and shell">&amp;&amp;</span>
        <span class="meta function-call shell"><span class="variable function shell">openssl_get</span></span><span class="meta function-call arguments shell"> https://curl.haxx.se/ca/cacert.pem</span> <span class="keyword operator logical pipe shell">|</span> <span class="meta function-call shell"><span class="variable function shell">http_body</span></span><span class="meta function-call arguments shell"> <span class="keyword operator assignment redirection shell">&gt;</span> /jffs/nextdns/ca.pem</span> <span class="keyword operator logical and shell">&amp;&amp;</span>
        <span class="meta function-call shell"><span class="variable function shell">install_bin</span></span>
<span class="punctuation section braces end shell">}</span></span>

<span class="meta function shell"><span class="entity name function shell">upgrade_ddwrt</span><span class="punctuation section parens begin shell">(</span><span class="punctuation section parens end shell">)</span> <span class="punctuation section braces begin shell">{</span>
    <span class="meta function-call shell"><span class="variable function shell">upgrade_bin</span></span>
<span class="punctuation section braces end shell">}</span></span>

<span class="meta function shell"><span class="entity name function shell">uninstall_ddwrt</span><span class="punctuation section parens begin shell">(</span><span class="punctuation section parens end shell">)</span> <span class="punctuation section braces begin shell">{</span>
    <span class="meta function-call shell"><span class="variable function shell">uninstall_bin</span></span>
    <span class="meta function-call shell"><span class="variable function shell">rm</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>rf</span> /jffs/nextdns</span>
<span class="punctuation section braces end shell">}</span></span>

<span class="meta function shell"><span class="entity name function shell">install_brew</span><span class="punctuation section parens begin shell">(</span><span class="punctuation section parens end shell">)</span> <span class="punctuation section braces begin shell">{</span>
    <span class="meta function-call shell"><span class="variable function shell">silent_exec</span></span><span class="meta function-call arguments shell"> brew install nextdns/tap/nextdns</span>
<span class="punctuation section braces end shell">}</span></span>

<span class="meta function shell"><span class="entity name function shell">upgrade_brew</span><span class="punctuation section parens begin shell">(</span><span class="punctuation section parens end shell">)</span> <span class="punctuation section braces begin shell">{</span>
    <span class="meta function-call shell"><span class="variable function shell">silent_exec</span></span><span class="meta function-call arguments shell"> brew upgrade nextdns/tap/nextdns</span>
    <span class="meta function-call shell"><span class="variable function shell">asroot</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">NEXTDNS_BIN</span></span><span class="punctuation definition string end shell">&quot;</span></span> install</span>
<span class="punctuation section braces end shell">}</span></span>

<span class="meta function shell"><span class="entity name function shell">uninstall_brew</span><span class="punctuation section parens begin shell">(</span><span class="punctuation section parens end shell">)</span> <span class="punctuation section braces begin shell">{</span>
    <span class="meta function-call shell"><span class="variable function shell">silent_exec</span></span><span class="meta function-call arguments shell"> brew uninstall nextdns/tap/nextdns</span>
<span class="punctuation section braces end shell">}</span></span>

<span class="meta function shell"><span class="entity name function shell">install_freebsd</span><span class="punctuation section parens begin shell">(</span><span class="punctuation section parens end shell">)</span> <span class="punctuation section braces begin shell">{</span>
    <span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> TODO: port install</span><span class="comment line number-sign shell">
</span>    <span class="meta function-call shell"><span class="variable function shell">install_bin</span></span>
<span class="punctuation section braces end shell">}</span></span>

<span class="meta function shell"><span class="entity name function shell">upgrade_freebsd</span><span class="punctuation section parens begin shell">(</span><span class="punctuation section parens end shell">)</span> <span class="punctuation section braces begin shell">{</span>
    <span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> TODO: port upgrade</span><span class="comment line number-sign shell">
</span>    <span class="meta function-call shell"><span class="variable function shell">upgrade_bin</span></span>
<span class="punctuation section braces end shell">}</span></span>

<span class="meta function shell"><span class="entity name function shell">uninstall_freebsd</span><span class="punctuation section parens begin shell">(</span><span class="punctuation section parens end shell">)</span> <span class="punctuation section braces begin shell">{</span>
    <span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> TODO: port uninstall</span><span class="comment line number-sign shell">
</span>    <span class="meta function-call shell"><span class="variable function shell">uninstall_bin</span></span>
<span class="punctuation section braces end shell">}</span></span>

<span class="meta function shell"><span class="entity name function shell">install_pfsense</span><span class="punctuation section parens begin shell">(</span><span class="punctuation section parens end shell">)</span> <span class="punctuation section braces begin shell">{</span>
    <span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> TODO: port install + UI</span><span class="comment line number-sign shell">
</span>    <span class="meta function-call shell"><span class="variable function shell">install_bin</span></span>
<span class="punctuation section braces end shell">}</span></span>

<span class="meta function shell"><span class="entity name function shell">upgrade_pfsense</span><span class="punctuation section parens begin shell">(</span><span class="punctuation section parens end shell">)</span> <span class="punctuation section braces begin shell">{</span>
    <span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> TODO: port upgrade</span><span class="comment line number-sign shell">
</span>    <span class="meta function-call shell"><span class="variable function shell">upgrade_bin</span></span>
<span class="punctuation section braces end shell">}</span></span>

<span class="meta function shell"><span class="entity name function shell">uninstall_pfsense</span><span class="punctuation section parens begin shell">(</span><span class="punctuation section parens end shell">)</span> <span class="punctuation section braces begin shell">{</span>
    <span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> TODO: port uninstall</span><span class="comment line number-sign shell">
</span>    <span class="meta function-call shell"><span class="variable function shell">uninstall_bin</span></span>
<span class="punctuation section braces end shell">}</span></span>

<span class="meta function shell"><span class="entity name function shell">install_opnsense</span><span class="punctuation section parens begin shell">(</span><span class="punctuation section parens end shell">)</span> <span class="punctuation section braces begin shell">{</span>
    <span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> TODO: port install + UI</span><span class="comment line number-sign shell">
</span>    <span class="meta function-call shell"><span class="variable function shell">install_bin</span></span>
<span class="punctuation section braces end shell">}</span></span>

<span class="meta function shell"><span class="entity name function shell">upgrade_opnsense</span><span class="punctuation section parens begin shell">(</span><span class="punctuation section parens end shell">)</span> <span class="punctuation section braces begin shell">{</span>
    <span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> TODO: port upgrade</span><span class="comment line number-sign shell">
</span>    <span class="meta function-call shell"><span class="variable function shell">upgrade_bin</span></span>
<span class="punctuation section braces end shell">}</span></span>

<span class="meta function shell"><span class="entity name function shell">uninstall_opnsense</span><span class="punctuation section parens begin shell">(</span><span class="punctuation section parens end shell">)</span> <span class="punctuation section braces begin shell">{</span>
    <span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> TODO: port uninstall</span><span class="comment line number-sign shell">
</span>    <span class="meta function-call shell"><span class="variable function shell">uninstall_bin</span></span>
<span class="punctuation section braces end shell">}</span></span>

<span class="meta function shell"><span class="entity name function shell">ubios_install_source</span><span class="punctuation section parens begin shell">(</span><span class="punctuation section parens end shell">)</span> <span class="punctuation section braces begin shell">{</span>
    <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>deb [signed-by=/etc/apt/keyrings/nextdns.gpg] https://repo.nextdns.io/deb stable main<span class="punctuation definition string end shell">&quot;</span></span> <span class="keyword operator assignment redirection shell">&gt;</span> /data/nextdns.list</span>
    <span class="meta function-call shell"><span class="variable function shell">podman</span></span><span class="meta function-call arguments shell"> exec unifi-os mv /data/nextdns.list /etc/apt/sources.list.d/nextdns.list</span>
    <span class="meta function-call shell"><span class="variable function shell">rm</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>f</span> /tmp/nextdns.list</span>
    <span class="meta function-call shell"><span class="variable function shell">podman</span></span><span class="meta function-call arguments shell"> exec unifi-os apt-get install<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>y</span> gnupg1 curl</span>
    <span class="meta function-call shell"><span class="variable function shell">podman</span></span><span class="meta function-call arguments shell"> exec unifi-os mkdir<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>p</span> /etc/apt/keyrings/</span>
    <span class="meta function-call shell"><span class="variable function shell">podman</span></span><span class="meta function-call arguments shell"> exec unifi-os curl<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>sfL</span> https://repo.nextdns.io/nextdns.gpg<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>o</span> /etc/apt/keyrings/nextdns.gpg</span>
    <span class="meta function-call shell"><span class="variable function shell">podman</span></span><span class="meta function-call arguments shell"> exec unifi-os apt-get update<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>o</span> Dir::Etc::sourcelist=<span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>sources.list.d/nextdns.list<span class="punctuation definition string end shell">&quot;</span></span><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>o</span> Dir::Etc::sourceparts=<span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>-<span class="punctuation definition string end shell">&quot;</span></span><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>o</span> APT::Get::List-Cleanup=<span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>0<span class="punctuation definition string end shell">&quot;</span></span></span>
<span class="punctuation section braces end shell">}</span></span>

<span class="meta function shell"><span class="entity name function shell">install_ubios</span><span class="punctuation section parens begin shell">(</span><span class="punctuation section parens end shell">)</span> <span class="punctuation section braces begin shell">{</span>
    <span class="meta function-call shell"><span class="variable function shell">ubios_install_source</span></span>
    <span class="meta function-call shell"><span class="variable function shell">podman</span></span><span class="meta function-call arguments shell"> exec unifi-os apt-get install<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>y</span> nextdns</span>
<span class="punctuation section braces end shell">}</span></span>

<span class="meta function shell"><span class="entity name function shell">upgrade_ubios</span><span class="punctuation section parens begin shell">(</span><span class="punctuation section parens end shell">)</span> <span class="punctuation section braces begin shell">{</span>
    <span class="meta function-call shell"><span class="variable function shell">ubios_install_source</span></span>
    <span class="meta function-call shell"><span class="variable function shell">podman</span></span><span class="meta function-call arguments shell"> exec unifi-os apt-get install<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> --</span>only-upgrade</span><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>y</span> nextdns</span>
<span class="punctuation section braces end shell">}</span></span>

<span class="meta function shell"><span class="entity name function shell">uninstall_ubios</span><span class="punctuation section parens begin shell">(</span><span class="punctuation section parens end shell">)</span> <span class="punctuation section braces begin shell">{</span>
    <span class="meta function-call shell"><span class="variable function shell">podman</span></span><span class="meta function-call arguments shell"> exec unifi-os apt-get remove<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>y</span> nextdns</span>
<span class="punctuation section braces end shell">}</span></span>

<span class="meta function shell"><span class="entity name function shell">install_ubios_snapshot</span><span class="punctuation section parens begin shell">(</span><span class="punctuation section parens end shell">)</span> <span class="punctuation section braces begin shell">{</span>
    <span class="variable other readwrite assignment shell">branch</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell"><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section expansion parameter begin shell">{</span></span><span class="meta group expansion parameter shell"><span class="variable other readwrite shell">INSTALL_RELEASE<span class="keyword operator expansion shell">%</span></span></span><span class="meta group expansion parameter shell">/<span class="keyword operator regexp quantifier shell">*</span></span><span class="meta group expansion parameter shell"><span class="punctuation section expansion parameter end shell">}</span></span></span>
    <span class="variable other readwrite assignment shell">hash</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell"><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section expansion parameter begin shell">{</span></span><span class="meta group expansion parameter shell"><span class="variable other readwrite shell">INSTALL_RELEASE<span class="keyword operator expansion shell">#</span></span></span><span class="meta group expansion parameter shell"><span class="keyword operator regexp quantifier shell">*</span>/</span><span class="meta group expansion parameter shell"><span class="punctuation section expansion parameter end shell">}</span></span></span>
    <span class="variable other readwrite assignment shell">url</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell"><span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>https://snapshot.nextdns.io/<span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section expansion parameter begin shell">{</span></span><span class="meta group expansion parameter shell"><span class="variable other readwrite shell">branch</span></span><span class="meta group expansion parameter shell"><span class="punctuation section expansion parameter end shell">}</span></span>/nextdns-<span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section expansion parameter begin shell">{</span></span><span class="meta group expansion parameter shell"><span class="variable other readwrite shell">hash</span></span><span class="meta group expansion parameter shell"><span class="punctuation section expansion parameter end shell">}</span></span>_<span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section expansion parameter begin shell">{</span></span><span class="meta group expansion parameter shell"><span class="variable other readwrite shell">GOOS</span></span><span class="meta group expansion parameter shell"><span class="punctuation section expansion parameter end shell">}</span></span>_<span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section expansion parameter begin shell">{</span></span><span class="meta group expansion parameter shell"><span class="variable other readwrite shell">GOARCH</span></span><span class="meta group expansion parameter shell"><span class="punctuation section expansion parameter end shell">}</span></span>.tar.gz<span class="punctuation definition string end shell">&quot;</span></span></span>
    <span class="meta function-call shell"><span class="variable function shell">podman</span></span><span class="meta function-call arguments shell"> exec unifi-os sh<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>c</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>curl -o- <span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">url</span></span> | tar Ozxf - nextdns &gt; /usr/bin/nextdns; /usr/bin/nextdns install<span class="punctuation definition string end shell">&quot;</span></span></span>
<span class="punctuation section braces end shell">}</span></span>

<span class="meta function shell"><span class="entity name function shell">upgrade_ubios_snapshot</span><span class="punctuation section parens begin shell">(</span><span class="punctuation section parens end shell">)</span> <span class="punctuation section braces begin shell">{</span>
    <span class="meta function-call shell"><span class="variable function shell">/data/nextdns</span></span><span class="meta function-call arguments shell"> uninstall</span>
    <span class="meta function-call shell"><span class="variable function shell">install_ubios_snapshot</span></span>
<span class="punctuation section braces end shell">}</span></span>

<span class="meta function shell"><span class="entity name function shell">install_type</span><span class="punctuation section parens begin shell">(</span><span class="punctuation section parens end shell">)</span> <span class="punctuation section braces begin shell">{</span>
    <span class="keyword control if begin shell">if</span> <span class="support function test begin shell">[</span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">FORCE_INSTALL_TYPE</span></span><span class="punctuation definition string end shell">&quot;</span></span> <span class="support function test end shell">]</span></span><span class="keyword operator logical continue shell">;</span> <span class="keyword control if then shell">then</span>
        <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">FORCE_INSTALL_TYPE</span></span><span class="punctuation definition string end shell">&quot;</span></span></span><span class="keyword operator logical continue shell">;</span> <span class="meta function-call shell"><span class="keyword control return shell">return</span></span><span class="meta function-call arguments shell"> 0</span>
    <span class="keyword control if end shell">fi</span>
    <span class="keyword control case begin shell">case</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">INSTALL_RELEASE</span></span><span class="punctuation definition string end shell">&quot;</span></span> <span class="keyword control case in shell">in</span>
    <span class="keyword operator regexp quantifier shell">*</span>/<span class="keyword operator regexp quantifier shell">*</span><span class="keyword control case item shell">)</span>
        <span class="keyword control case begin shell">case</span> <span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">OS</span></span> <span class="keyword control case in shell">in</span>
        ubios<span class="keyword control case item shell">)</span>
            <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>ubios_snapshot<span class="punctuation definition string end shell">&quot;</span></span></span><span class="keyword operator logical continue shell">;</span> <span class="meta function-call shell"><span class="keyword control return shell">return</span></span><span class="meta function-call arguments shell"> 0</span>
            <span class="punctuation terminator case shell">;;</span>
        <span class="keyword operator regexp quantifier shell">*</span><span class="keyword control case item shell">)</span>
            <span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> Snapshot mode always use binary install</span><span class="comment line number-sign shell">
</span>            <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>bin<span class="punctuation definition string end shell">&quot;</span></span></span><span class="keyword operator logical continue shell">;</span> <span class="meta function-call shell"><span class="keyword control return shell">return</span></span><span class="meta function-call arguments shell"> 0</span>
            <span class="punctuation terminator case shell">;;</span>
        <span class="keyword control case end shell">esac</span>
    <span class="keyword control case end shell">esac</span>
    <span class="keyword control case begin shell">case</span> <span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">OS</span></span> <span class="keyword control case in shell">in</span>
    centos<span class="keyword operator logical shell">|</span>fedora<span class="keyword operator logical shell">|</span>rhel<span class="keyword control case item shell">)</span>
        <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>rpm<span class="punctuation definition string end shell">&quot;</span></span></span>
        <span class="punctuation terminator case shell">;;</span>
    opensuse-tumbleweed<span class="keyword operator logical shell">|</span>opensuse-leap<span class="keyword operator logical shell">|</span>opensuse<span class="keyword control case item shell">)</span>
        <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>zypper<span class="punctuation definition string end shell">&quot;</span></span></span>
        <span class="punctuation terminator case shell">;;</span>
    debian<span class="keyword operator logical shell">|</span>ubuntu<span class="keyword operator logical shell">|</span>elementary<span class="keyword operator logical shell">|</span>raspbian<span class="keyword operator logical shell">|</span>linuxmint<span class="keyword operator logical shell">|</span>pop<span class="keyword operator logical shell">|</span>neon<span class="keyword operator logical shell">|</span>sparky<span class="keyword operator logical shell">|</span>vyos<span class="keyword operator logical shell">|</span>Deepin<span class="keyword control case item shell">)</span>
        <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>deb<span class="punctuation definition string end shell">&quot;</span></span></span>
        <span class="punctuation terminator case shell">;;</span>
    alpine<span class="keyword control case item shell">)</span>
        <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>apk<span class="punctuation definition string end shell">&quot;</span></span></span>
        <span class="punctuation terminator case shell">;;</span>
    arch<span class="keyword operator logical shell">|</span>manjaro<span class="keyword operator logical shell">|</span>steamos<span class="keyword control case item shell">)</span>
        <span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell">echo &quot;arch&quot; # TODO: fix AUR install</span><span class="comment line number-sign shell">
</span>        <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>bin<span class="punctuation definition string end shell">&quot;</span></span></span>
        <span class="punctuation terminator case shell">;;</span>
    openwrt<span class="keyword control case item shell">)</span>
        <span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> shellcheck disable=SC1091</span><span class="comment line number-sign shell">
</span>        <span class="meta function-call shell"><span class="support function dot shell">.</span></span><span class="meta function-call arguments shell"> /etc/os-release</span>
        <span class="variable other readwrite assignment shell">major</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell"><span class="meta group expansion command parens shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section parens begin shell">(</span><span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">VERSION_ID</span></span><span class="punctuation definition string end shell">&quot;</span></span></span> <span class="keyword operator logical pipe shell">|</span> <span class="meta function-call shell"><span class="variable function shell">cut</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>d</span>.<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>f1</span></span><span class="punctuation section parens end shell">)</span></span></span>
        <span class="keyword control case begin shell">case</span> <span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">major</span></span> <span class="keyword control case in shell">in</span>
            <span class="keyword operator regexp quantifier shell">*</span><span class="keyword control regexp set begin shell">[</span><span class="keyword operator logical not shell">!</span>0<span class="keyword operator word shell">-</span>9<span class="keyword control regexp set end shell">]</span><span class="keyword operator regexp quantifier shell">*</span><span class="keyword control case item shell">)</span>
                <span class="keyword control if begin shell">if</span> <span class="support function test begin shell">[</span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">VERSION_ID</span></span><span class="punctuation definition string end shell">&quot;</span></span> <span class="keyword operator logical shell">=</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>19.07.0-rc1<span class="punctuation definition string end shell">&quot;</span></span> <span class="support function test end shell">]</span></span><span class="keyword operator logical continue shell">;</span> <span class="keyword control if then shell">then</span>
                    <span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> No opkg support before 19.07.0-rc2</span><span class="comment line number-sign shell">
</span>                    <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>bin<span class="punctuation definition string end shell">&quot;</span></span></span>
                <span class="keyword control if else shell">else</span>
                    <span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> Likely &#39;snapshot&#39; build in this case, but still &gt; major version 19</span><span class="comment line number-sign shell">
</span>                    <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>openwrt<span class="punctuation definition string end shell">&quot;</span></span></span>
                <span class="keyword control if end shell">fi</span>
                <span class="punctuation terminator case shell">;;</span>
            <span class="keyword operator regexp quantifier shell">*</span><span class="keyword control case item shell">)</span>
                <span class="keyword control if begin shell">if</span> <span class="support function test begin shell">[</span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">major</span></span><span class="punctuation definition string end shell">&quot;</span></span> <span class="variable parameter option shell"><span class="punctuation definition parameter shell">-</span>lt</span> 19 <span class="support function test end shell">]</span></span><span class="keyword operator logical continue shell">;</span> <span class="keyword control if then shell">then</span>
                    <span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> No opkg support before 19.07.0-rc2</span><span class="comment line number-sign shell">
</span>                    <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>bin<span class="punctuation definition string end shell">&quot;</span></span></span>
                <span class="keyword control if else shell">else</span>
                    <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>openwrt<span class="punctuation definition string end shell">&quot;</span></span></span>
                <span class="keyword control if end shell">fi</span>
                <span class="punctuation terminator case shell">;;</span>
        <span class="keyword control case end shell">esac</span>
        <span class="punctuation terminator case shell">;;</span>
    asuswrt-merlin<span class="keyword control case item shell">)</span>
        <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>merlin<span class="punctuation definition string end shell">&quot;</span></span></span>
        <span class="punctuation terminator case shell">;;</span>
    edgeos<span class="keyword operator logical shell">|</span>synology<span class="keyword operator logical shell">|</span>clear-linux-os<span class="keyword operator logical shell">|</span>solus<span class="keyword operator logical shell">|</span>openbsd<span class="keyword operator logical shell">|</span>netbsd<span class="keyword operator logical shell">|</span>overthebox<span class="keyword control case item shell">)</span>
        <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>bin<span class="punctuation definition string end shell">&quot;</span></span></span>
        <span class="punctuation terminator case shell">;;</span>
    ddwrt<span class="keyword control case item shell">)</span>
        <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>ddwrt<span class="punctuation definition string end shell">&quot;</span></span></span>
        <span class="punctuation terminator case shell">;;</span>
    darwin<span class="keyword control case item shell">)</span>
        <span class="keyword control if begin shell">if</span> <span class="support function test begin shell">[</span><span class="meta function-call arguments shell"> <span class="variable parameter option shell"><span class="punctuation definition parameter shell">-</span>x</span> /usr/local/bin/brew <span class="support function test end shell">]</span></span> <span class="keyword operator logical or shell">||</span> <span class="support function test begin shell">[</span><span class="meta function-call arguments shell"> <span class="variable parameter option shell"><span class="punctuation definition parameter shell">-</span>x</span> /opt/homebrew/bin/brew <span class="support function test end shell">]</span></span><span class="keyword operator logical continue shell">;</span> <span class="keyword control if then shell">then</span>
            <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>brew<span class="punctuation definition string end shell">&quot;</span></span></span>
        <span class="keyword control if else shell">else</span>
            <span class="meta function-call shell"><span class="variable function shell">log_debug</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>Homebrew not installed, fallback on binary install<span class="punctuation definition string end shell">&quot;</span></span></span>
            <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>bin<span class="punctuation definition string end shell">&quot;</span></span></span>
        <span class="keyword control if end shell">fi</span>
        <span class="punctuation terminator case shell">;;</span>
    freebsd<span class="keyword control case item shell">)</span>
        <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>freebsd<span class="punctuation definition string end shell">&quot;</span></span></span>
        <span class="punctuation terminator case shell">;;</span>
    pfsense<span class="keyword control case item shell">)</span>
        <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>pfsense<span class="punctuation definition string end shell">&quot;</span></span></span>
        <span class="punctuation terminator case shell">;;</span>
    opnsense<span class="keyword control case item shell">)</span>
        <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>opnsense<span class="punctuation definition string end shell">&quot;</span></span></span>
        <span class="punctuation terminator case shell">;;</span>
    ubios<span class="keyword control case item shell">)</span>
        <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>ubios<span class="punctuation definition string end shell">&quot;</span></span></span>
        <span class="punctuation terminator case shell">;;</span>
    gentoo<span class="keyword control case item shell">)</span>
        <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>bin<span class="punctuation definition string end shell">&quot;</span></span></span>
        <span class="punctuation terminator case shell">;;</span>
    void<span class="keyword control case item shell">)</span>
        <span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> TODO: pkg for xbps</span><span class="comment line number-sign shell">
</span>        <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>bin<span class="punctuation definition string end shell">&quot;</span></span></span>
        <span class="punctuation terminator case shell">;;</span>
    <span class="keyword operator regexp quantifier shell">*</span><span class="keyword control case item shell">)</span>
        <span class="meta function-call shell"><span class="variable function shell">log_error</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>Unsupported installation for <span class="meta group expansion command parens shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section parens begin shell">(</span><span class="meta function-call shell"><span class="variable function shell">detect_os</span></span><span class="punctuation section parens end shell">)</span></span><span class="punctuation definition string end shell">&quot;</span></span></span>
        <span class="meta function-call shell"><span class="keyword control return shell">return</span></span><span class="meta function-call arguments shell"> 1</span>
        <span class="punctuation terminator case shell">;;</span>
    <span class="keyword control case end shell">esac</span>
<span class="punctuation section braces end shell">}</span></span>

<span class="meta function shell"><span class="entity name function shell">get_config</span><span class="punctuation section parens begin shell">(</span><span class="punctuation section parens end shell">)</span> <span class="punctuation section braces begin shell">{</span>
    <span class="meta function-call shell"><span class="variable function shell"><span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">NEXTDNS_BIN</span></span><span class="punctuation definition string end shell">&quot;</span></span></span></span><span class="meta function-call arguments shell"> config</span> <span class="keyword operator logical pipe shell">|</span> <span class="meta function-call shell"><span class="variable function shell">grep</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>E</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>^<span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">1</span></span> <span class="punctuation definition string end shell">&quot;</span></span></span> <span class="keyword operator logical pipe shell">|</span> <span class="meta function-call shell"><span class="variable function shell">cut</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>d</span><span class="string quoted single shell"><span class="punctuation definition string begin shell">&#39;</span> <span class="punctuation definition string end shell">&#39;</span></span><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>f</span> 2</span>
<span class="punctuation section braces end shell">}</span></span>

<span class="meta function shell"><span class="entity name function shell">get_config_bool</span><span class="punctuation section parens begin shell">(</span><span class="punctuation section parens end shell">)</span> <span class="punctuation section braces begin shell">{</span>
    <span class="variable other readwrite assignment shell">val</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell"><span class="meta group expansion command parens shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section parens begin shell">(</span><span class="meta function-call shell"><span class="variable function shell">get_config</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">1</span></span><span class="punctuation definition string end shell">&quot;</span></span></span><span class="punctuation section parens end shell">)</span></span></span>
    <span class="keyword control case begin shell">case</span> <span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">val</span></span> <span class="keyword control case in shell">in</span>
        true<span class="keyword operator logical shell">|</span>false<span class="keyword control case item shell">)</span>
            <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">val</span></span><span class="punctuation definition string end shell">&quot;</span></span></span>
            <span class="punctuation terminator case shell">;;</span>
    <span class="keyword control case end shell">esac</span>
    <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">2</span></span><span class="punctuation definition string end shell">&quot;</span></span></span>
<span class="punctuation section braces end shell">}</span></span>

<span class="meta function shell"><span class="entity name function shell">get_profile_id</span><span class="punctuation section parens begin shell">(</span><span class="punctuation section parens end shell">)</span> <span class="punctuation section braces begin shell">{</span>
    <span class="meta function-call shell"><span class="variable function shell">log_debug</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>Get profile ID<span class="punctuation definition string end shell">&quot;</span></span></span>
    <span class="keyword control if begin shell">if</span> <span class="support function test begin shell">[</span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">CONFIG_ID</span></span><span class="punctuation definition string end shell">&quot;</span></span> <span class="support function test end shell">]</span></span><span class="keyword operator logical continue shell">;</span> <span class="keyword control if then shell">then</span>
        <span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> backward compat</span><span class="comment line number-sign shell">
</span>        <span class="variable other readwrite assignment shell">PROFILE_ID</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell"><span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">CONFIG_ID</span></span><span class="punctuation definition string end shell">&quot;</span></span></span>
    <span class="keyword control if end shell">fi</span>
    <span class="keyword control while shell">while</span> <span class="support function test begin shell">[</span><span class="meta function-call arguments shell"> <span class="variable parameter option shell"><span class="punctuation definition parameter shell">-</span>z</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">PROFILE_ID</span></span><span class="punctuation definition string end shell">&quot;</span></span> <span class="support function test end shell">]</span></span><span class="keyword operator logical continue shell">;</span> <span class="keyword control do shell">do</span>
        <span class="variable other readwrite assignment shell">default</span><span class="keyword operator assignment shell">=</span>
        <span class="variable other readwrite assignment shell">prev_id</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell"><span class="meta group expansion command parens shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section parens begin shell">(</span><span class="meta function-call shell"><span class="variable function shell">get_config</span></span><span class="meta function-call arguments shell"> profile</span><span class="punctuation section parens end shell">)</span></span></span>
        <span class="keyword control if begin shell">if</span> <span class="support function test begin shell">[</span><span class="meta function-call arguments shell"> <span class="variable parameter option shell"><span class="punctuation definition parameter shell">-</span>z</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">prev_id</span></span><span class="punctuation definition string end shell">&quot;</span></span> <span class="support function test end shell">]</span></span><span class="keyword operator logical continue shell">;</span> <span class="keyword control if then shell">then</span>
            <span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> backward compat</span><span class="comment line number-sign shell">
</span>            <span class="variable other readwrite assignment shell">prev_id</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell"><span class="meta group expansion command parens shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section parens begin shell">(</span><span class="meta function-call shell"><span class="variable function shell">get_config</span></span><span class="meta function-call arguments shell"> config</span><span class="punctuation section parens end shell">)</span></span></span>
        <span class="keyword control if end shell">fi</span>
        <span class="keyword control if begin shell">if</span> <span class="support function test begin shell">[</span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">prev_id</span></span><span class="punctuation definition string end shell">&quot;</span></span> <span class="support function test end shell">]</span></span><span class="keyword operator logical continue shell">;</span> <span class="keyword control if then shell">then</span>
            <span class="meta function-call shell"><span class="variable function shell">log_debug</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>Previous profile ID: <span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">prev_id</span></span><span class="punctuation definition string end shell">&quot;</span></span></span>
            <span class="variable other readwrite assignment shell">default</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell"><span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span> (default=<span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">prev_id</span></span>)<span class="punctuation definition string end shell">&quot;</span></span></span>
        <span class="keyword control if end shell">fi</span>
        <span class="meta function-call shell"><span class="variable function shell">print</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>NextDNS Profile ID%s: <span class="punctuation definition string end shell">&quot;</span></span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">default</span></span><span class="punctuation definition string end shell">&quot;</span></span></span>
        <span class="meta function-call shell"><span class="support function read shell">read</span></span><span class="meta function-call arguments shell"> <span class="variable parameter option shell"><span class="punctuation definition parameter shell">-</span>r</span> id</span>
        <span class="keyword control if begin shell">if</span> <span class="support function test begin shell">[</span><span class="meta function-call arguments shell"> <span class="variable parameter option shell"><span class="punctuation definition parameter shell">-</span>z</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">id</span></span><span class="punctuation definition string end shell">&quot;</span></span> <span class="support function test end shell">]</span></span><span class="keyword operator logical continue shell">;</span> <span class="keyword control if then shell">then</span>
            <span class="variable other readwrite assignment shell">id</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell"><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">prev_id</span></span></span>
        <span class="keyword control if end shell">fi</span>
        <span class="keyword control if begin shell">if</span> <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">id</span></span><span class="punctuation definition string end shell">&quot;</span></span></span> <span class="keyword operator logical pipe shell">|</span> <span class="meta function-call shell"><span class="variable function shell">grep</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>qE</span> <span class="string quoted single shell"><span class="punctuation definition string begin shell">&#39;</span>^[0-9a-f]{6}$<span class="punctuation definition string end shell">&#39;</span></span></span><span class="keyword operator logical continue shell">;</span> <span class="keyword control if then shell">then</span>
            <span class="variable other readwrite assignment shell">PROFILE_ID</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell"><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">id</span></span></span>
            <span class="keyword control break shell">break</span>
        <span class="keyword control if else shell">else</span>
            <span class="meta function-call shell"><span class="variable function shell">log_error</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>Invalid profile ID.<span class="punctuation definition string end shell">&quot;</span></span></span>
            <span class="meta function-call shell"><span class="variable function shell">println</span></span>
            <span class="meta function-call shell"><span class="variable function shell">println</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>ID format is 6 alphanumerical lowercase characters (example: 123abc).<span class="punctuation definition string end shell">&quot;</span></span></span>
            <span class="meta function-call shell"><span class="variable function shell">println</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>Your ID can be found on the Setup tab of https://my.nextdns.io.<span class="punctuation definition string end shell">&quot;</span></span></span>
            <span class="meta function-call shell"><span class="variable function shell">println</span></span>
        <span class="keyword control if end shell">fi</span>
    <span class="keyword control done shell">done</span>
    <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">PROFILE_ID</span></span><span class="punctuation definition string end shell">&quot;</span></span></span>
<span class="punctuation section braces end shell">}</span></span>

<span class="meta function shell"><span class="entity name function shell">log_debug</span><span class="punctuation section parens begin shell">(</span><span class="punctuation section parens end shell">)</span> <span class="punctuation section braces begin shell">{</span>
    <span class="keyword control if begin shell">if</span> <span class="support function test begin shell">[</span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">DEBUG</span></span><span class="punctuation definition string end shell">&quot;</span></span> <span class="keyword operator logical shell">=</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>1<span class="punctuation definition string end shell">&quot;</span></span> <span class="support function test end shell">]</span></span><span class="keyword operator logical continue shell">;</span> <span class="keyword control if then shell">then</span>
        <span class="meta function-call shell"><span class="support function printf shell">printf</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>\033[30;1mDEBUG: %s\033[0m\n<span class="punctuation definition string end shell">&quot;</span></span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable language shell">*</span></span><span class="punctuation definition string end shell">&quot;</span></span> <span class="keyword operator assignment redirection shell">&gt;&amp;</span><span class="constant numeric integer decimal file-descriptor shell">2</span>
</span>    <span class="keyword control if end shell">fi</span>
<span class="punctuation section braces end shell">}</span></span>

<span class="meta function shell"><span class="entity name function shell">log_info</span><span class="punctuation section parens begin shell">(</span><span class="punctuation section parens end shell">)</span> <span class="punctuation section braces begin shell">{</span>
    <span class="meta function-call shell"><span class="support function printf shell">printf</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>INFO: %s\n<span class="punctuation definition string end shell">&quot;</span></span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable language shell">*</span></span><span class="punctuation definition string end shell">&quot;</span></span> <span class="keyword operator assignment redirection shell">&gt;&amp;</span><span class="constant numeric integer decimal file-descriptor shell">2</span>
</span><span class="punctuation section braces end shell">}</span></span>

<span class="meta function shell"><span class="entity name function shell">log_warn</span><span class="punctuation section parens begin shell">(</span><span class="punctuation section parens end shell">)</span> <span class="punctuation section braces begin shell">{</span>
    <span class="meta function-call shell"><span class="support function printf shell">printf</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>\033[33mWARN: %s\033[0m\n<span class="punctuation definition string end shell">&quot;</span></span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable language shell">*</span></span><span class="punctuation definition string end shell">&quot;</span></span> <span class="keyword operator assignment redirection shell">&gt;&amp;</span><span class="constant numeric integer decimal file-descriptor shell">2</span>
</span><span class="punctuation section braces end shell">}</span></span>

<span class="meta function shell"><span class="entity name function shell">log_error</span><span class="punctuation section parens begin shell">(</span><span class="punctuation section parens end shell">)</span> <span class="punctuation section braces begin shell">{</span>
    <span class="meta function-call shell"><span class="support function printf shell">printf</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>\033[31mERROR: %s\033[0m\n<span class="punctuation definition string end shell">&quot;</span></span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable language shell">*</span></span><span class="punctuation definition string end shell">&quot;</span></span> <span class="keyword operator assignment redirection shell">&gt;&amp;</span><span class="constant numeric integer decimal file-descriptor shell">2</span>
</span><span class="punctuation section braces end shell">}</span></span>

<span class="meta function shell"><span class="entity name function shell">print</span><span class="punctuation section parens begin shell">(</span><span class="punctuation section parens end shell">)</span> <span class="punctuation section braces begin shell">{</span>
    <span class="variable other readwrite assignment shell">format</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell"><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">1</span></span></span>
    <span class="keyword control if begin shell">if</span> <span class="support function test begin shell">[</span><span class="meta function-call arguments shell"> <span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable language shell">#</span></span> <span class="variable parameter option shell"><span class="punctuation definition parameter shell">-</span>gt</span> 0 <span class="support function test end shell">]</span></span><span class="keyword operator logical continue shell">;</span> <span class="keyword control if then shell">then</span>
        <span class="meta function-call shell"><span class="support function shift shell">shift</span></span>
    <span class="keyword control if end shell">fi</span>
    <span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> shellcheck disable=SC2059</span><span class="comment line number-sign shell">
</span>    <span class="meta function-call shell"><span class="support function printf shell">printf</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">format</span></span><span class="punctuation definition string end shell">&quot;</span></span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable language shell">@</span></span><span class="punctuation definition string end shell">&quot;</span></span> <span class="keyword operator assignment redirection shell">&gt;&amp;</span><span class="constant numeric integer decimal file-descriptor shell">2</span>
</span><span class="punctuation section braces end shell">}</span></span>

<span class="meta function shell"><span class="entity name function shell">println</span><span class="punctuation section parens begin shell">(</span><span class="punctuation section parens end shell">)</span> <span class="punctuation section braces begin shell">{</span>
    <span class="variable other readwrite assignment shell">format</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell"><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">1</span></span></span>
    <span class="keyword control if begin shell">if</span> <span class="support function test begin shell">[</span><span class="meta function-call arguments shell"> <span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable language shell">#</span></span> <span class="variable parameter option shell"><span class="punctuation definition parameter shell">-</span>gt</span> 0 <span class="support function test end shell">]</span></span><span class="keyword operator logical continue shell">;</span> <span class="keyword control if then shell">then</span>
        <span class="meta function-call shell"><span class="support function shift shell">shift</span></span>
    <span class="keyword control if end shell">fi</span>
    <span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> shellcheck disable=SC2059</span><span class="comment line number-sign shell">
</span>    <span class="meta function-call shell"><span class="support function printf shell">printf</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">format</span></span>\n<span class="punctuation definition string end shell">&quot;</span></span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable language shell">@</span></span><span class="punctuation definition string end shell">&quot;</span></span> <span class="keyword operator assignment redirection shell">&gt;&amp;</span><span class="constant numeric integer decimal file-descriptor shell">2</span>
</span><span class="punctuation section braces end shell">}</span></span>

<span class="meta function shell"><span class="entity name function shell">doc</span><span class="punctuation section parens begin shell">(</span><span class="punctuation section parens end shell">)</span> <span class="punctuation section braces begin shell">{</span>
    <span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> shellcheck disable=SC2059</span><span class="comment line number-sign shell">
</span>    <span class="meta function-call shell"><span class="support function printf shell">printf</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>\033[30;1m%s\033[0m\n<span class="punctuation definition string end shell">&quot;</span></span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable language shell">*</span></span><span class="punctuation definition string end shell">&quot;</span></span> <span class="keyword operator assignment redirection shell">&gt;&amp;</span><span class="constant numeric integer decimal file-descriptor shell">2</span>
</span><span class="punctuation section braces end shell">}</span></span>

<span class="meta function shell"><span class="entity name function shell">menu</span><span class="punctuation section parens begin shell">(</span><span class="punctuation section parens end shell">)</span> <span class="punctuation section braces begin shell">{</span>
    <span class="keyword control while shell">while</span> <span class="meta function-call shell"><span class="variable function shell">true</span></span><span class="keyword operator logical continue shell">;</span> <span class="keyword control do shell">do</span>
        <span class="variable other readwrite assignment shell">n</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell">0</span>
        <span class="variable other readwrite assignment shell">default</span><span class="keyword operator assignment shell">=</span>
        <span class="keyword control for shell">for</span><span class="meta group for shell"> item <span class="keyword control in shell">in</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable language shell">@</span></span><span class="punctuation definition string end shell">&quot;</span></span></span><span class="keyword operator logical continue shell">;</span> <span class="keyword control do shell">do</span>
            <span class="keyword control case begin shell">case</span> <span class="meta group expansion arithmetic shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section parens begin shell">((</span>n<span class="keyword operator arithmetic shell">%</span><span class="constant numeric integer decimal shell">3</span><span class="punctuation section parens end shell">))</span></span> <span class="keyword control case in shell">in</span>
            0<span class="keyword control case item shell">)</span>
                <span class="variable other readwrite assignment shell">key</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell"><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">item</span></span></span>
                <span class="keyword control if begin shell">if</span> <span class="support function test begin shell">[</span><span class="meta function-call arguments shell"> <span class="variable parameter option shell"><span class="punctuation definition parameter shell">-</span>z</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">default</span></span><span class="punctuation definition string end shell">&quot;</span></span> <span class="support function test end shell">]</span></span><span class="keyword operator logical continue shell">;</span> <span class="keyword control if then shell">then</span>
                    <span class="variable other readwrite assignment shell">default</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell"><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">key</span></span></span>
                <span class="keyword control if end shell">fi</span>
                <span class="punctuation terminator case shell">;;</span>
            1<span class="keyword control case item shell">)</span>
                <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">key</span></span>) <span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">item</span></span><span class="punctuation definition string end shell">&quot;</span></span></span>
                <span class="punctuation terminator case shell">;;</span>
            <span class="keyword control case end shell">esac</span>
            <span class="variable other readwrite assignment shell">n</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell"><span class="meta group expansion arithmetic shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section parens begin shell">((</span>n<span class="keyword operator arithmetic shell">+</span><span class="constant numeric integer decimal shell">1</span><span class="punctuation section parens end shell">))</span></span></span>
        <span class="keyword control done shell">done</span>
        <span class="meta function-call shell"><span class="variable function shell">print</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>Choice (default=%s): <span class="punctuation definition string end shell">&quot;</span></span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">default</span></span><span class="punctuation definition string end shell">&quot;</span></span></span>
        <span class="meta function-call shell"><span class="support function read shell">read</span></span><span class="meta function-call arguments shell"> <span class="variable parameter option shell"><span class="punctuation definition parameter shell">-</span>r</span> choice</span>
        <span class="keyword control if begin shell">if</span> <span class="support function test begin shell">[</span><span class="meta function-call arguments shell"> <span class="variable parameter option shell"><span class="punctuation definition parameter shell">-</span>z</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">choice</span></span><span class="punctuation definition string end shell">&quot;</span></span> <span class="support function test end shell">]</span></span><span class="keyword operator logical continue shell">;</span> <span class="keyword control if then shell">then</span>
            <span class="variable other readwrite assignment shell">choice</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell"><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">default</span></span></span>
        <span class="keyword control if end shell">fi</span>
        <span class="variable other readwrite assignment shell">n</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell">0</span>
        <span class="keyword control for shell">for</span><span class="meta group for shell"> item <span class="keyword control in shell">in</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable language shell">@</span></span><span class="punctuation definition string end shell">&quot;</span></span></span><span class="keyword operator logical continue shell">;</span> <span class="keyword control do shell">do</span>
            <span class="keyword control case begin shell">case</span> <span class="meta group expansion arithmetic shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section parens begin shell">((</span>n<span class="keyword operator arithmetic shell">%</span><span class="constant numeric integer decimal shell">3</span><span class="punctuation section parens end shell">))</span></span> <span class="keyword control case in shell">in</span>
            0<span class="keyword control case item shell">)</span>
                <span class="variable other readwrite assignment shell">key</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell"><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">item</span></span></span>
                <span class="punctuation terminator case shell">;;</span>
            2<span class="keyword control case item shell">)</span>
                <span class="keyword control if begin shell">if</span> <span class="support function test begin shell">[</span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">key</span></span><span class="punctuation definition string end shell">&quot;</span></span> <span class="keyword operator logical shell">=</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">choice</span></span><span class="punctuation definition string end shell">&quot;</span></span> <span class="support function test end shell">]</span></span><span class="keyword operator logical continue shell">;</span> <span class="keyword control if then shell">then</span>
                    <span class="keyword control if begin shell">if</span> <span class="keyword operator logical shell">!</span> <span class="meta function-call shell"><span class="variable function shell"><span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">item</span></span><span class="punctuation definition string end shell">&quot;</span></span></span></span><span class="keyword operator logical continue shell">;</span> <span class="keyword control if then shell">then</span>
                        <span class="meta function-call shell"><span class="variable function shell">log_error</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">item</span></span>: exit <span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable language shell">?</span></span><span class="punctuation definition string end shell">&quot;</span></span></span>
                    <span class="keyword control if end shell">fi</span>
                    <span class="keyword control break shell">break</span><span class="meta function-call arguments shell"> 2</span>
                <span class="keyword control if end shell">fi</span>
                <span class="punctuation terminator case shell">;;</span>
            <span class="keyword control case end shell">esac</span>
            <span class="variable other readwrite assignment shell">n</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell"><span class="meta group expansion arithmetic shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section parens begin shell">((</span>n<span class="keyword operator arithmetic shell">+</span><span class="constant numeric integer decimal shell">1</span><span class="punctuation section parens end shell">))</span></span></span>
        <span class="keyword control done shell">done</span>
        <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>Invalid choice<span class="punctuation definition string end shell">&quot;</span></span></span>
    <span class="keyword control done shell">done</span>
<span class="punctuation section braces end shell">}</span></span>

<span class="meta function shell"><span class="entity name function shell">ask_bool</span><span class="punctuation section parens begin shell">(</span><span class="punctuation section parens end shell">)</span> <span class="punctuation section braces begin shell">{</span>
    <span class="variable other readwrite assignment shell">msg</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell"><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">1</span></span></span>
    <span class="variable other readwrite assignment shell">default</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell"><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">2</span></span></span>
    <span class="keyword control case begin shell">case</span> <span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">default</span></span> <span class="keyword control case in shell">in</span>
    true<span class="keyword control case item shell">)</span>
        <span class="variable other readwrite assignment shell">msg</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell"><span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">msg</span></span> [Y|n]: <span class="punctuation definition string end shell">&quot;</span></span></span>
        <span class="punctuation terminator case shell">;;</span>
    false<span class="keyword control case item shell">)</span>
        <span class="variable other readwrite assignment shell">msg</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell"><span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">msg</span></span> [y|N]: <span class="punctuation definition string end shell">&quot;</span></span></span>
        <span class="punctuation terminator case shell">;;</span>
    <span class="keyword operator regexp quantifier shell">*</span><span class="keyword control case item shell">)</span>
        <span class="variable other readwrite assignment shell">msg</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell"><span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">msg</span></span> (y/n): <span class="punctuation definition string end shell">&quot;</span></span></span>
    <span class="keyword control case end shell">esac</span>
    <span class="keyword control while shell">while</span> <span class="meta function-call shell"><span class="variable function shell">true</span></span><span class="keyword operator logical continue shell">;</span> <span class="keyword control do shell">do</span>
        <span class="meta function-call shell"><span class="variable function shell">print</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>%s<span class="punctuation definition string end shell">&quot;</span></span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">msg</span></span><span class="punctuation definition string end shell">&quot;</span></span></span>
        <span class="meta function-call shell"><span class="support function read shell">read</span></span><span class="meta function-call arguments shell"> <span class="variable parameter option shell"><span class="punctuation definition parameter shell">-</span>r</span> answer</span>
        <span class="keyword control if begin shell">if</span> <span class="support function test begin shell">[</span><span class="meta function-call arguments shell"> <span class="variable parameter option shell"><span class="punctuation definition parameter shell">-</span>z</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">answer</span></span><span class="punctuation definition string end shell">&quot;</span></span> <span class="support function test end shell">]</span></span><span class="keyword operator logical continue shell">;</span> <span class="keyword control if then shell">then</span>
            <span class="variable other readwrite assignment shell">answer</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell"><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">default</span></span></span>
        <span class="keyword control if end shell">fi</span>
        <span class="keyword control case begin shell">case</span> <span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">answer</span></span> <span class="keyword control case in shell">in</span>
        y<span class="keyword operator logical shell">|</span>Y<span class="keyword operator logical shell">|</span>yes<span class="keyword operator logical shell">|</span>YES<span class="keyword operator logical shell">|</span>true<span class="keyword control case item shell">)</span>
            <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>true<span class="punctuation definition string end shell">&quot;</span></span></span>
            <span class="meta function-call shell"><span class="keyword control return shell">return</span></span><span class="meta function-call arguments shell"> 0</span>
            <span class="punctuation terminator case shell">;;</span>
        n<span class="keyword operator logical shell">|</span>N<span class="keyword operator logical shell">|</span>no<span class="keyword operator logical shell">|</span>NO<span class="keyword operator logical shell">|</span>false<span class="keyword control case item shell">)</span>
            <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>false<span class="punctuation definition string end shell">&quot;</span></span></span>
            <span class="meta function-call shell"><span class="keyword control return shell">return</span></span><span class="meta function-call arguments shell"> 0</span>
            <span class="punctuation terminator case shell">;;</span>
        <span class="keyword operator regexp quantifier shell">*</span><span class="keyword control case item shell">)</span>
            <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>Invalid input, use yes or no<span class="punctuation definition string end shell">&quot;</span></span></span>
            <span class="punctuation terminator case shell">;;</span>
        <span class="keyword control case end shell">esac</span>
    <span class="keyword control done shell">done</span>
<span class="punctuation section braces end shell">}</span></span>

<span class="meta function shell"><span class="entity name function shell">detect_endiannes</span><span class="punctuation section parens begin shell">(</span><span class="punctuation section parens end shell">)</span> <span class="punctuation section braces begin shell">{</span>
    <span class="keyword control if begin shell">if</span> <span class="keyword operator logical shell">!</span> <span class="meta function-call shell"><span class="variable function shell">hexdump</span></span><span class="meta function-call arguments shell"> /dev/null <span class="constant numeric integer decimal file-descriptor shell">2</span><span class="keyword operator assignment redirection shell">&gt;</span>/dev/null</span><span class="keyword operator logical continue shell">;</span> <span class="keyword control if then shell">then</span>
        <span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> Some firmwares do not contain hexdump, for those, try to detect endianness</span><span class="comment line number-sign shell">
</span>        <span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> differently.</span><span class="comment line number-sign shell">
</span>        <span class="keyword control case begin shell">case</span> <span class="meta group expansion command parens shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section parens begin shell">(</span><span class="meta function-call shell"><span class="variable function shell">cat</span></span><span class="meta function-call arguments shell"> /proc/cpuinfo</span><span class="punctuation section parens end shell">)</span></span> <span class="keyword control case in shell">in</span>
        <span class="keyword operator regexp quantifier shell">*</span>BCM5300<span class="keyword operator regexp quantifier shell">*</span><span class="keyword control case item shell">)</span>
            <span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> RT-AC66U does not support Merlin version over 380.70 which</span><span class="comment line number-sign shell">
</span>            <span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> lacks hexdump command.</span><span class="comment line number-sign shell">
</span>            <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>le<span class="punctuation definition string end shell">&quot;</span></span></span>
            <span class="punctuation terminator case shell">;;</span>
        <span class="keyword operator regexp quantifier shell">*</span><span class="keyword control case item shell">)</span>
            <span class="meta function-call shell"><span class="variable function shell">log_error</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>Cannot determine endianness<span class="punctuation definition string end shell">&quot;</span></span></span>
            <span class="meta function-call shell"><span class="keyword control return shell">return</span></span><span class="meta function-call arguments shell"> 1</span>
            <span class="punctuation terminator case shell">;;</span>
        <span class="keyword control case end shell">esac</span>
        <span class="meta function-call shell"><span class="keyword control return shell">return</span></span><span class="meta function-call arguments shell"> 0</span>
    <span class="keyword control if end shell">fi</span>
    <span class="keyword control case begin shell">case</span> <span class="meta group expansion command parens shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section parens begin shell">(</span><span class="meta function-call shell"><span class="variable function shell">hexdump</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>s</span> 5<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>n</span> 1<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>e</span> <span class="string quoted single shell"><span class="punctuation definition string begin shell">&#39;</span>&quot;%x&quot;<span class="punctuation definition string end shell">&#39;</span></span> /bin/sh</span> <span class="keyword operator logical pipe shell">|</span> <span class="meta function-call shell"><span class="variable function shell">head</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>c1</span></span><span class="punctuation section parens end shell">)</span></span> <span class="keyword control case in shell">in</span>
    1<span class="keyword control case item shell">)</span>
        <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>le<span class="punctuation definition string end shell">&quot;</span></span></span>
        <span class="punctuation terminator case shell">;;</span>
    2<span class="keyword control case item shell">)</span>
        <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="punctuation definition string end shell">&quot;</span></span></span>
        <span class="punctuation terminator case shell">;;</span>
    <span class="keyword control case end shell">esac</span>
<span class="punctuation section braces end shell">}</span></span>

<span class="meta function shell"><span class="entity name function shell">detect_goarch</span><span class="punctuation section parens begin shell">(</span><span class="punctuation section parens end shell">)</span> <span class="punctuation section braces begin shell">{</span>
    <span class="keyword control if begin shell">if</span> <span class="support function test begin shell">[</span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">FORCE_GOARCH</span></span><span class="punctuation definition string end shell">&quot;</span></span> <span class="support function test end shell">]</span></span><span class="keyword operator logical continue shell">;</span> <span class="keyword control if then shell">then</span>
        <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">FORCE_GOARCH</span></span><span class="punctuation definition string end shell">&quot;</span></span></span><span class="keyword operator logical continue shell">;</span> <span class="meta function-call shell"><span class="keyword control return shell">return</span></span><span class="meta function-call arguments shell"> 0</span>
    <span class="keyword control if end shell">fi</span>
    <span class="keyword control case begin shell">case</span> <span class="meta group expansion command parens shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section parens begin shell">(</span><span class="meta function-call shell"><span class="variable function shell">uname</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>m</span></span><span class="punctuation section parens end shell">)</span></span> <span class="keyword control case in shell">in</span>
    x86_64<span class="keyword operator logical shell">|</span>amd64<span class="keyword control case item shell">)</span>
        <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>amd64<span class="punctuation definition string end shell">&quot;</span></span></span>
        <span class="punctuation terminator case shell">;;</span>
    i386<span class="keyword operator logical shell">|</span>i686<span class="keyword control case item shell">)</span>
        <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>386<span class="punctuation definition string end shell">&quot;</span></span></span>
        <span class="punctuation terminator case shell">;;</span>
    arm<span class="keyword control case item shell">)</span>
        <span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> FreeBSD does not include arm version</span><span class="comment line number-sign shell">
</span>        <span class="keyword control case begin shell">case</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion command parens shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section parens begin shell">(</span><span class="meta function-call shell"><span class="variable function shell">sysctl</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>b</span> hw.model <span class="constant numeric integer decimal file-descriptor shell">2</span><span class="keyword operator assignment redirection shell">&gt;</span>/dev/null</span><span class="punctuation section parens end shell">)</span></span><span class="punctuation definition string end shell">&quot;</span></span> <span class="keyword control case in shell">in</span>
        <span class="keyword operator regexp quantifier shell">*</span>A9<span class="keyword operator regexp quantifier shell">*</span><span class="keyword control case item shell">)</span>
            <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>armv7<span class="punctuation definition string end shell">&quot;</span></span></span>
            <span class="punctuation terminator case shell">;;</span>
        <span class="keyword operator regexp quantifier shell">*</span><span class="keyword control case item shell">)</span>
            <span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> Unknown version, fallback to the lowest</span><span class="comment line number-sign shell">
</span>            <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>armv5<span class="punctuation definition string end shell">&quot;</span></span></span>
            <span class="punctuation terminator case shell">;;</span>
        <span class="keyword control case end shell">esac</span>
        <span class="punctuation terminator case shell">;;</span>
    armv5<span class="keyword operator regexp quantifier shell">*</span><span class="keyword control case item shell">)</span>
        <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>armv5<span class="punctuation definition string end shell">&quot;</span></span></span>
        <span class="punctuation terminator case shell">;;</span>
    armv6<span class="keyword operator regexp quantifier shell">*</span><span class="keyword operator logical shell">|</span>armv7<span class="keyword operator regexp quantifier shell">*</span><span class="keyword control case item shell">)</span>
        <span class="keyword control if begin shell">if</span> <span class="meta function-call shell"><span class="variable function shell">grep</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>q</span> vfp /proc/cpuinfo <span class="constant numeric integer decimal file-descriptor shell">2</span><span class="keyword operator assignment redirection shell">&gt;</span>/dev/null</span><span class="keyword operator logical continue shell">;</span> <span class="keyword control if then shell">then</span>
            <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>armv<span class="meta group expansion command parens shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section parens begin shell">(</span><span class="meta function-call shell"><span class="variable function shell">uname</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>m</span></span> <span class="keyword operator logical pipe shell">|</span> <span class="meta function-call shell"><span class="variable function shell">sed</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>e</span> <span class="string quoted single shell"><span class="punctuation definition string begin shell">&#39;</span>s/[[:alpha:]]//g<span class="punctuation definition string end shell">&#39;</span></span></span><span class="punctuation section parens end shell">)</span></span><span class="punctuation definition string end shell">&quot;</span></span></span>
        <span class="keyword control if else shell">else</span>
            <span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> Soft floating point</span><span class="comment line number-sign shell">
</span>            <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>armv5<span class="punctuation definition string end shell">&quot;</span></span></span>
        <span class="keyword control if end shell">fi</span>
        <span class="punctuation terminator case shell">;;</span>
    aarch64<span class="keyword control case item shell">)</span>
        <span class="keyword control case begin shell">case</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion command parens shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section parens begin shell">(</span><span class="meta function-call shell"><span class="variable function shell">uname</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>o</span> <span class="constant numeric integer decimal file-descriptor shell">2</span><span class="keyword operator assignment redirection shell">&gt;</span>/dev/null</span><span class="punctuation section parens end shell">)</span></span><span class="punctuation definition string end shell">&quot;</span></span> <span class="keyword control case in shell">in</span>
        ASUSWRT-Merlin<span class="keyword operator regexp quantifier shell">*</span><span class="keyword control case item shell">)</span>
            <span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> XXX when using arm64 build on ASUS AC66U and ACG86U, we get Go error:</span><span class="comment line number-sign shell">
</span>            <span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> &quot;out of memory allocating heap arena metadata&quot;.</span><span class="comment line number-sign shell">
</span>            <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>armv7<span class="punctuation definition string end shell">&quot;</span></span></span>
            <span class="punctuation terminator case shell">;;</span>
        <span class="keyword operator regexp quantifier shell">*</span><span class="keyword control case item shell">)</span>
            <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>arm64<span class="punctuation definition string end shell">&quot;</span></span></span>
            <span class="punctuation terminator case shell">;;</span>
        <span class="keyword control case end shell">esac</span>
        <span class="punctuation terminator case shell">;;</span>
    armv8<span class="keyword operator regexp quantifier shell">*</span><span class="keyword operator logical shell">|</span>arm64<span class="keyword control case item shell">)</span>
        <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>arm64<span class="punctuation definition string end shell">&quot;</span></span></span>
        <span class="punctuation terminator case shell">;;</span>
    mips<span class="keyword operator regexp quantifier shell">*</span><span class="keyword control case item shell">)</span>
        <span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> TODO: detect hardfloat</span><span class="comment line number-sign shell">
</span>        <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion command parens shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section parens begin shell">(</span><span class="meta function-call shell"><span class="variable function shell">uname</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>m</span></span><span class="punctuation section parens end shell">)</span></span><span class="meta group expansion command parens shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section parens begin shell">(</span><span class="meta function-call shell"><span class="variable function shell">detect_endiannes</span></span><span class="punctuation section parens end shell">)</span></span>_softfloat<span class="punctuation definition string end shell">&quot;</span></span></span>
        <span class="punctuation terminator case shell">;;</span>
    <span class="keyword operator regexp quantifier shell">*</span><span class="keyword control case item shell">)</span>
        <span class="meta function-call shell"><span class="variable function shell">log_error</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>Unsupported GOARCH: <span class="meta group expansion command parens shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section parens begin shell">(</span><span class="meta function-call shell"><span class="variable function shell">uname</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>m</span></span><span class="punctuation section parens end shell">)</span></span><span class="punctuation definition string end shell">&quot;</span></span></span>
        <span class="meta function-call shell"><span class="keyword control return shell">return</span></span><span class="meta function-call arguments shell"> 1</span>
        <span class="punctuation terminator case shell">;;</span>
    <span class="keyword control case end shell">esac</span>
<span class="punctuation section braces end shell">}</span></span>

<span class="meta function shell"><span class="entity name function shell">detect_goos</span><span class="punctuation section parens begin shell">(</span><span class="punctuation section parens end shell">)</span> <span class="punctuation section braces begin shell">{</span>
    <span class="keyword control if begin shell">if</span> <span class="support function test begin shell">[</span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">FORCE_GOOS</span></span><span class="punctuation definition string end shell">&quot;</span></span> <span class="support function test end shell">]</span></span><span class="keyword operator logical continue shell">;</span> <span class="keyword control if then shell">then</span>
        <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">FORCE_GOOS</span></span><span class="punctuation definition string end shell">&quot;</span></span></span><span class="keyword operator logical continue shell">;</span> <span class="meta function-call shell"><span class="keyword control return shell">return</span></span><span class="meta function-call arguments shell"> 0</span>
    <span class="keyword control if end shell">fi</span>
    <span class="keyword control case begin shell">case</span> <span class="meta group expansion command parens shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section parens begin shell">(</span><span class="meta function-call shell"><span class="variable function shell">uname</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>s</span></span><span class="punctuation section parens end shell">)</span></span> <span class="keyword control case in shell">in</span>
    Linux<span class="keyword control case item shell">)</span>
        <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>linux<span class="punctuation definition string end shell">&quot;</span></span></span>
        <span class="punctuation terminator case shell">;;</span>
    Darwin<span class="keyword control case item shell">)</span>
        <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>darwin<span class="punctuation definition string end shell">&quot;</span></span></span>
        <span class="punctuation terminator case shell">;;</span>
    FreeBSD<span class="keyword control case item shell">)</span>
        <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>freebsd<span class="punctuation definition string end shell">&quot;</span></span></span>
        <span class="punctuation terminator case shell">;;</span>
    NetBSD<span class="keyword control case item shell">)</span>
        <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>netbsd<span class="punctuation definition string end shell">&quot;</span></span></span>
        <span class="punctuation terminator case shell">;;</span>
    OpenBSD<span class="keyword control case item shell">)</span>
        <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>openbsd<span class="punctuation definition string end shell">&quot;</span></span></span>
        <span class="punctuation terminator case shell">;;</span>
    <span class="keyword operator regexp quantifier shell">*</span><span class="keyword control case item shell">)</span>
        <span class="meta function-call shell"><span class="variable function shell">log_error</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>Unsupported GOOS: <span class="meta group expansion command parens shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section parens begin shell">(</span><span class="meta function-call shell"><span class="variable function shell">uname</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>s</span></span><span class="punctuation section parens end shell">)</span></span><span class="punctuation definition string end shell">&quot;</span></span></span>
        <span class="meta function-call shell"><span class="keyword control return shell">return</span></span><span class="meta function-call arguments shell"> 1</span>
    <span class="keyword control case end shell">esac</span>
<span class="punctuation section braces end shell">}</span></span>

<span class="meta function shell"><span class="entity name function shell">detect_os</span><span class="punctuation section parens begin shell">(</span><span class="punctuation section parens end shell">)</span> <span class="punctuation section braces begin shell">{</span>
    <span class="keyword control if begin shell">if</span> <span class="support function test begin shell">[</span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">FORCE_OS</span></span><span class="punctuation definition string end shell">&quot;</span></span> <span class="support function test end shell">]</span></span><span class="keyword operator logical continue shell">;</span> <span class="keyword control if then shell">then</span>
        <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">FORCE_OS</span></span><span class="punctuation definition string end shell">&quot;</span></span></span><span class="keyword operator logical continue shell">;</span> <span class="meta function-call shell"><span class="keyword control return shell">return</span></span><span class="meta function-call arguments shell"> 0</span>
    <span class="keyword control if end shell">fi</span>
    <span class="keyword control case begin shell">case</span> <span class="meta group expansion command parens shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section parens begin shell">(</span><span class="meta function-call shell"><span class="variable function shell">uname</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>s</span></span><span class="punctuation section parens end shell">)</span></span> <span class="keyword control case in shell">in</span>
    Linux<span class="keyword control case item shell">)</span>
        <span class="keyword control case begin shell">case</span> <span class="meta group expansion command parens shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section parens begin shell">(</span><span class="meta function-call shell"><span class="variable function shell">uname</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>o</span></span><span class="punctuation section parens end shell">)</span></span> <span class="keyword control case in shell">in</span>
        GNU/Linux<span class="keyword operator logical shell">|</span>Linux<span class="keyword control case item shell">)</span>
            <span class="keyword control if begin shell">if</span> <span class="meta function-call shell"><span class="variable function shell">grep</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>q</span><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>e</span> <span class="string quoted single shell"><span class="punctuation definition string begin shell">&#39;</span>^EdgeRouter<span class="punctuation definition string end shell">&#39;</span></span><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>e</span> <span class="string quoted single shell"><span class="punctuation definition string begin shell">&#39;</span>^UniFiSecurityGateway<span class="punctuation definition string end shell">&#39;</span></span> /etc/version <span class="constant numeric integer decimal file-descriptor shell">2</span><span class="keyword operator assignment redirection shell">&gt;</span> /dev/null</span><span class="keyword operator logical continue shell">;</span> <span class="keyword control if then shell">then</span>
                <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>edgeos<span class="punctuation definition string end shell">&quot;</span></span></span><span class="keyword operator logical continue shell">;</span> <span class="meta function-call shell"><span class="keyword control return shell">return</span></span><span class="meta function-call arguments shell"> 0</span>
            <span class="keyword control if end shell">fi</span>
            <span class="keyword control if begin shell">if</span> <span class="meta function-call shell"><span class="variable function shell">uname</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>u</span> <span class="constant numeric integer decimal file-descriptor shell">2</span><span class="keyword operator assignment redirection shell">&gt;</span>/dev/null</span> <span class="keyword operator logical pipe shell">|</span> <span class="meta function-call shell"><span class="variable function shell">grep</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>q</span> <span class="string quoted single shell"><span class="punctuation definition string begin shell">&#39;</span>^synology<span class="punctuation definition string end shell">&#39;</span></span></span><span class="keyword operator logical continue shell">;</span> <span class="keyword control if then shell">then</span>
                <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>synology<span class="punctuation definition string end shell">&quot;</span></span></span><span class="keyword operator logical continue shell">;</span> <span class="meta function-call shell"><span class="keyword control return shell">return</span></span><span class="meta function-call arguments shell"> 0</span>
            <span class="keyword control if end shell">fi</span>
            <span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> shellcheck disable=SC1091</span><span class="comment line number-sign shell">
</span>            <span class="variable other readwrite assignment shell">dist</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell"><span class="meta group expansion command parens shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section parens begin shell">(</span><span class="meta function-call shell"><span class="support function dot shell">.</span></span><span class="meta function-call arguments shell"> /etc/os-release</span><span class="keyword operator logical continue shell">;</span> <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">ID</span></span><span class="punctuation definition string end shell">&quot;</span></span></span><span class="punctuation section parens end shell">)</span></span></span>
            <span class="keyword control case begin shell">case</span> <span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">dist</span></span> <span class="keyword control case in shell">in</span>
            ubios<span class="keyword control case item shell">)</span>
                <span class="keyword control if begin shell">if</span> <span class="support function test begin shell">[</span><span class="meta function-call arguments shell"> <span class="variable parameter option shell"><span class="punctuation definition parameter shell">-</span>z</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion command parens shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section parens begin shell">(</span><span class="meta function-call shell"><span class="support function command shell">command</span></span><span class="meta function-call arguments shell"> <span class="variable parameter option shell"><span class="punctuation definition parameter shell">-</span>v</span> podman</span><span class="punctuation section parens end shell">)</span></span><span class="punctuation definition string end shell">&quot;</span></span> <span class="support function test end shell">]</span></span><span class="keyword operator logical continue shell">;</span> <span class="keyword control if then shell">then</span>
                    <span class="meta function-call shell"><span class="variable function shell">log_error</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>This version of UnifiOS is not supported. Make sure you run version 1.7.0 or above.<span class="punctuation definition string end shell">&quot;</span></span></span>
                    <span class="meta function-call shell"><span class="keyword control return shell">return</span></span><span class="meta function-call arguments shell"> 1</span>
                <span class="keyword control if end shell">fi</span>
                <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">dist</span></span><span class="punctuation definition string end shell">&quot;</span></span></span><span class="keyword operator logical continue shell">;</span> <span class="meta function-call shell"><span class="keyword control return shell">return</span></span><span class="meta function-call arguments shell"> 0</span>
                <span class="punctuation terminator case shell">;;</span>
            debian<span class="keyword operator logical shell">|</span>ubuntu<span class="keyword operator logical shell">|</span>elementary<span class="keyword operator logical shell">|</span>raspbian<span class="keyword operator logical shell">|</span>centos<span class="keyword operator logical shell">|</span>fedora<span class="keyword operator logical shell">|</span>rhel<span class="keyword operator logical shell">|</span>arch<span class="keyword operator logical shell">|</span>manjaro<span class="keyword operator logical shell">|</span>openwrt<span class="keyword operator logical shell">|</span>clear-linux-os<span class="keyword operator logical shell">|</span>linuxmint<span class="keyword operator logical shell">|</span>opensuse-tumbleweed<span class="keyword operator logical shell">|</span>opensuse-leap<span class="keyword operator logical shell">|</span>opensuse<span class="keyword operator logical shell">|</span>solus<span class="keyword operator logical shell">|</span>pop<span class="keyword operator logical shell">|</span>neon<span class="keyword operator logical shell">|</span>overthebox<span class="keyword operator logical shell">|</span>sparky<span class="keyword operator logical shell">|</span>vyos<span class="keyword operator logical shell">|</span>void<span class="keyword operator logical shell">|</span>alpine<span class="keyword operator logical shell">|</span>Deepin<span class="keyword operator logical shell">|</span>gentoo<span class="keyword operator logical shell">|</span>steamos<span class="keyword control case item shell">)</span>
                <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">dist</span></span><span class="punctuation definition string end shell">&quot;</span></span></span><span class="keyword operator logical continue shell">;</span> <span class="meta function-call shell"><span class="keyword control return shell">return</span></span><span class="meta function-call arguments shell"> 0</span>
                <span class="punctuation terminator case shell">;;</span>
            <span class="keyword control case end shell">esac</span>
            <span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> shellcheck disable=SC1091</span><span class="comment line number-sign shell">
</span>            <span class="keyword control for shell">for</span><span class="meta group for shell"> dist <span class="keyword control in shell">in</span> <span class="meta group expansion command parens shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section parens begin shell">(</span><span class="meta function-call shell"><span class="support function dot shell">.</span></span><span class="meta function-call arguments shell"> /etc/os-release</span><span class="keyword operator logical continue shell">;</span> <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">ID_LIKE</span></span><span class="punctuation definition string end shell">&quot;</span></span></span><span class="punctuation section parens end shell">)</span></span></span><span class="keyword operator logical continue shell">;</span> <span class="keyword control do shell">do</span>
                <span class="keyword control case begin shell">case</span> <span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">dist</span></span> <span class="keyword control case in shell">in</span>
                debian<span class="keyword operator logical shell">|</span>ubuntu<span class="keyword operator logical shell">|</span>rhel<span class="keyword operator logical shell">|</span>fedora<span class="keyword operator logical shell">|</span>openwrt<span class="keyword control case item shell">)</span>
                    <span class="meta function-call shell"><span class="variable function shell">log_debug</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>Using ID_LIKE<span class="punctuation definition string end shell">&quot;</span></span></span>
                    <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">dist</span></span><span class="punctuation definition string end shell">&quot;</span></span></span><span class="keyword operator logical continue shell">;</span> <span class="meta function-call shell"><span class="keyword control return shell">return</span></span><span class="meta function-call arguments shell"> 0</span>
                    <span class="punctuation terminator case shell">;;</span>
                <span class="keyword control case end shell">esac</span>
            <span class="keyword control done shell">done</span>
            <span class="punctuation terminator case shell">;;</span>
        ASUSWRT-Merlin<span class="keyword operator regexp quantifier shell">*</span><span class="keyword control case item shell">)</span>
            <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>asuswrt-merlin<span class="punctuation definition string end shell">&quot;</span></span></span><span class="keyword operator logical continue shell">;</span> <span class="meta function-call shell"><span class="keyword control return shell">return</span></span><span class="meta function-call arguments shell"> 0</span>
            <span class="punctuation terminator case shell">;;</span>
        DD-WRT<span class="keyword control case item shell">)</span>
            <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>ddwrt<span class="punctuation definition string end shell">&quot;</span></span></span><span class="keyword operator logical continue shell">;</span> <span class="meta function-call shell"><span class="keyword control return shell">return</span></span><span class="meta function-call arguments shell"> 0</span>
        <span class="keyword control case end shell">esac</span>
        <span class="punctuation terminator case shell">;;</span>
    Darwin<span class="keyword control case item shell">)</span>
        <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>darwin<span class="punctuation definition string end shell">&quot;</span></span></span><span class="keyword operator logical continue shell">;</span> <span class="meta function-call shell"><span class="keyword control return shell">return</span></span><span class="meta function-call arguments shell"> 0</span>
        <span class="punctuation terminator case shell">;;</span>
    FreeBSD<span class="keyword control case item shell">)</span>
        <span class="keyword control if begin shell">if</span> <span class="support function test begin shell">[</span><span class="meta function-call arguments shell"> <span class="variable parameter option shell"><span class="punctuation definition parameter shell">-</span>f</span> /etc/platform <span class="support function test end shell">]</span></span><span class="keyword operator logical continue shell">;</span> <span class="keyword control if then shell">then</span>
            <span class="keyword control case begin shell">case</span> <span class="meta group expansion command parens shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section parens begin shell">(</span><span class="meta function-call shell"><span class="variable function shell">cat</span></span><span class="meta function-call arguments shell"> /etc/platform</span><span class="punctuation section parens end shell">)</span></span> <span class="keyword control case in shell">in</span>
            pfSense<span class="keyword control case item shell">)</span>
                <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>pfsense<span class="punctuation definition string end shell">&quot;</span></span></span><span class="keyword operator logical continue shell">;</span> <span class="meta function-call shell"><span class="keyword control return shell">return</span></span><span class="meta function-call arguments shell"> 0</span>
                <span class="punctuation terminator case shell">;;</span>
            <span class="keyword control case end shell">esac</span>
        <span class="keyword control if end shell">fi</span>
        <span class="keyword control if begin shell">if</span> <span class="support function test begin shell">[</span><span class="meta function-call arguments shell"> <span class="variable parameter option shell"><span class="punctuation definition parameter shell">-</span>x</span> /usr/local/sbin/opnsense-version <span class="support function test end shell">]</span></span><span class="keyword operator logical continue shell">;</span> <span class="keyword control if then shell">then</span>
            <span class="keyword control case begin shell">case</span> <span class="meta group expansion command parens shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section parens begin shell">(</span><span class="meta function-call shell"><span class="variable function shell">/usr/local/sbin/opnsense-version</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>N</span></span><span class="punctuation section parens end shell">)</span></span> <span class="keyword control case in shell">in</span>
            OPNsense<span class="keyword control case item shell">)</span>
                <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>opnsense<span class="punctuation definition string end shell">&quot;</span></span></span><span class="keyword operator logical continue shell">;</span> <span class="meta function-call shell"><span class="keyword control return shell">return</span></span><span class="meta function-call arguments shell"> 0</span>
                <span class="punctuation terminator case shell">;;</span>
            <span class="keyword control case end shell">esac</span>
        <span class="keyword control if end shell">fi</span>
        <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>freebsd<span class="punctuation definition string end shell">&quot;</span></span></span><span class="keyword operator logical continue shell">;</span> <span class="meta function-call shell"><span class="keyword control return shell">return</span></span><span class="meta function-call arguments shell"> 0</span>
        <span class="punctuation terminator case shell">;;</span>
    NetBSD<span class="keyword control case item shell">)</span>
        <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>netbsd<span class="punctuation definition string end shell">&quot;</span></span></span><span class="keyword operator logical continue shell">;</span> <span class="meta function-call shell"><span class="keyword control return shell">return</span></span><span class="meta function-call arguments shell"> 0</span>
        <span class="punctuation terminator case shell">;;</span>
    OpenBSD<span class="keyword control case item shell">)</span>
        <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>openbsd<span class="punctuation definition string end shell">&quot;</span></span></span><span class="keyword operator logical continue shell">;</span> <span class="meta function-call shell"><span class="keyword control return shell">return</span></span><span class="meta function-call arguments shell"> 0</span>
        <span class="punctuation terminator case shell">;;</span>
    <span class="keyword operator regexp quantifier shell">*</span><span class="keyword control case item shell">)</span>
    <span class="keyword control case end shell">esac</span>
    <span class="meta function-call shell"><span class="variable function shell">log_error</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>Unsupported OS: <span class="meta group expansion command parens shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section parens begin shell">(</span><span class="meta function-call shell"><span class="variable function shell">uname</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>o</span></span><span class="punctuation section parens end shell">)</span></span> <span class="meta group expansion command parens shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section parens begin shell">(</span><span class="meta function-call shell"><span class="variable function shell">grep</span></span><span class="meta function-call arguments shell"> ID <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>/etc/os-release<span class="punctuation definition string end shell">&quot;</span></span> <span class="constant numeric integer decimal file-descriptor shell">2</span><span class="keyword operator assignment redirection shell">&gt;</span>/dev/null</span> <span class="keyword operator logical pipe shell">|</span> <span class="meta function-call shell"><span class="variable function shell">xargs</span></span><span class="punctuation section parens end shell">)</span></span><span class="punctuation definition string end shell">&quot;</span></span></span>
    <span class="meta function-call shell"><span class="keyword control return shell">return</span></span><span class="meta function-call arguments shell"> 1</span>
<span class="punctuation section braces end shell">}</span></span>

<span class="meta function shell"><span class="entity name function shell">guess_host_type</span><span class="punctuation section parens begin shell">(</span><span class="punctuation section parens end shell">)</span> <span class="punctuation section braces begin shell">{</span>
    <span class="keyword control if begin shell">if</span> <span class="support function test begin shell">[</span><span class="meta function-call arguments shell"> <span class="variable parameter option shell"><span class="punctuation definition parameter shell">-</span>d</span> /data/unifi <span class="support function test end shell">]</span></span><span class="keyword operator logical continue shell">;</span> <span class="keyword control if then shell">then</span>
        <span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> Special case when installer is run from inside the ubios podman</span><span class="comment line number-sign shell">
</span>        <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>router<span class="punctuation definition string end shell">&quot;</span></span></span><span class="keyword operator logical continue shell">;</span> <span class="meta function-call shell"><span class="keyword control return shell">return</span></span><span class="meta function-call arguments shell"> 0</span>
    <span class="keyword control if end shell">fi</span>

    <span class="keyword control case begin shell">case</span> <span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">OS</span></span> <span class="keyword control case in shell">in</span>
    pfsense<span class="keyword operator logical shell">|</span>opnsense<span class="keyword operator logical shell">|</span>openwrt<span class="keyword operator logical shell">|</span>asuswrt-merlin<span class="keyword operator logical shell">|</span>edgeos<span class="keyword operator logical shell">|</span>ddwrt<span class="keyword operator logical shell">|</span>synology<span class="keyword operator logical shell">|</span>overthebox<span class="keyword operator logical shell">|</span>ubios<span class="keyword control case item shell">)</span>
        <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>router<span class="punctuation definition string end shell">&quot;</span></span></span>
        <span class="punctuation terminator case shell">;;</span>
    darwin<span class="keyword operator logical shell">|</span>steamos<span class="keyword control case item shell">)</span>
        <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>workstation<span class="punctuation definition string end shell">&quot;</span></span></span>
        <span class="punctuation terminator case shell">;;</span>
    <span class="keyword operator regexp quantifier shell">*</span><span class="keyword control case item shell">)</span>
        <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>unsure<span class="punctuation definition string end shell">&quot;</span></span></span>
        <span class="punctuation terminator case shell">;;</span>
    <span class="keyword control case end shell">esac</span>
<span class="punctuation section braces end shell">}</span></span>

<span class="meta function shell"><span class="entity name function shell">asroot</span><span class="punctuation section parens begin shell">(</span><span class="punctuation section parens end shell">)</span> <span class="punctuation section braces begin shell">{</span>
    <span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> Some platform (Merlin) do not have the &quot;id&quot; command and $USER report a non root username with uid 0.</span><span class="comment line number-sign shell">
</span>    <span class="keyword control if begin shell">if</span> <span class="support function test begin shell">[</span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion command parens shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section parens begin shell">(</span><span class="meta function-call shell"><span class="variable function shell">grep</span></span><span class="meta function-call arguments shell"> <span class="string quoted single shell"><span class="punctuation definition string begin shell">&#39;</span>^Uid:<span class="punctuation definition string end shell">&#39;</span></span> /proc/<span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable language shell">$</span></span>/status <span class="constant numeric integer decimal file-descriptor shell">2</span><span class="keyword operator assignment redirection shell">&gt;</span>/dev/null</span><span class="keyword operator logical pipe shell">|</span><span class="meta function-call shell"><span class="variable function shell">cut</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>f2</span></span><span class="punctuation section parens end shell">)</span></span><span class="punctuation definition string end shell">&quot;</span></span> <span class="keyword operator logical shell">=</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>0<span class="punctuation definition string end shell">&quot;</span></span> <span class="support function test end shell">]</span></span> <span class="keyword operator logical or shell">||</span> <span class="support function test begin shell">[</span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">USER</span></span><span class="punctuation definition string end shell">&quot;</span></span> <span class="keyword operator logical shell">=</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>root<span class="punctuation definition string end shell">&quot;</span></span> <span class="support function test end shell">]</span></span> <span class="keyword operator logical or shell">||</span> <span class="support function test begin shell">[</span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion command parens shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section parens begin shell">(</span><span class="meta function-call shell"><span class="variable function shell">id</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>u</span> <span class="constant numeric integer decimal file-descriptor shell">2</span><span class="keyword operator assignment redirection shell">&gt;</span>/dev/null</span><span class="punctuation section parens end shell">)</span></span><span class="punctuation definition string end shell">&quot;</span></span> <span class="keyword operator logical shell">=</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>0<span class="punctuation definition string end shell">&quot;</span></span> <span class="support function test end shell">]</span></span><span class="keyword operator logical continue shell">;</span> <span class="keyword control if then shell">then</span>
        <span class="meta function-call shell"><span class="variable function shell"><span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable language shell">@</span></span><span class="punctuation definition string end shell">&quot;</span></span></span></span>
    <span class="keyword control if elif shell">elif</span> <span class="support function test begin shell">[</span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion command parens shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section parens begin shell">(</span><span class="meta function-call shell"><span class="support function command shell">command</span></span><span class="meta function-call arguments shell"> <span class="variable parameter option shell"><span class="punctuation definition parameter shell">-</span>v</span> sudo <span class="constant numeric integer decimal file-descriptor shell">2</span><span class="keyword operator assignment redirection shell">&gt;</span>/dev/null</span><span class="punctuation section parens end shell">)</span></span><span class="punctuation definition string end shell">&quot;</span></span> <span class="support function test end shell">]</span></span><span class="keyword operator logical continue shell">;</span> <span class="keyword control if then shell">then</span>
        <span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable language shell">@</span></span><span class="punctuation definition string end shell">&quot;</span></span></span>
    <span class="keyword control if else shell">else</span>
        <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>Root required<span class="punctuation definition string end shell">&quot;</span></span></span>
        <span class="meta function-call shell"><span class="variable function shell">su</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>m</span> root<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>c</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable language shell">*</span></span><span class="punctuation definition string end shell">&quot;</span></span></span>
    <span class="keyword control if end shell">fi</span>
<span class="punctuation section braces end shell">}</span></span>

<span class="meta function shell"><span class="entity name function shell">silent_exec</span><span class="punctuation section parens begin shell">(</span><span class="punctuation section parens end shell">)</span> <span class="punctuation section braces begin shell">{</span>
    <span class="keyword control if begin shell">if</span> <span class="support function test begin shell">[</span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">DEBUG</span></span><span class="punctuation definition string end shell">&quot;</span></span> <span class="keyword operator logical shell">=</span> 1 <span class="support function test end shell">]</span></span><span class="keyword operator logical continue shell">;</span> <span class="keyword control if then shell">then</span>
        <span class="meta function-call shell"><span class="variable function shell"><span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable language shell">@</span></span><span class="punctuation definition string end shell">&quot;</span></span></span></span>
    <span class="keyword control if else shell">else</span>
        <span class="keyword control if begin shell">if</span> <span class="keyword operator logical shell">!</span> <span class="meta function-call shell"><span class="variable function shell">out</span></span><span class="meta function-call arguments shell">=<span class="meta group expansion command parens shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section parens begin shell">(</span><span class="meta function-call shell"><span class="variable function shell"><span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable language shell">@</span></span><span class="punctuation definition string end shell">&quot;</span></span></span></span><span class="meta function-call arguments shell"> <span class="constant numeric integer decimal file-descriptor shell">2</span><span class="keyword operator assignment redirection shell">&gt;&amp;</span><span class="constant numeric integer decimal file-descriptor shell">1</span></span><span class="punctuation section parens end shell">)</span></span></span><span class="keyword operator logical continue shell">;</span> <span class="keyword control if then shell">then</span>
            <span class="variable other readwrite assignment shell">rt</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell"><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable language shell">?</span></span></span>
            <span class="meta function-call shell"><span class="variable function shell">println</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>\033[30;1m%s\033[0m<span class="punctuation definition string end shell">&quot;</span></span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">out</span></span><span class="punctuation definition string end shell">&quot;</span></span></span>
            <span class="meta function-call shell"><span class="keyword control return shell">return</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">rt</span></span></span>
        <span class="keyword control if end shell">fi</span>
    <span class="keyword control if end shell">fi</span>
<span class="punctuation section braces end shell">}</span></span>

<span class="meta function shell"><span class="entity name function shell">bin_location</span><span class="punctuation section parens begin shell">(</span><span class="punctuation section parens end shell">)</span> <span class="punctuation section braces begin shell">{</span>
    <span class="keyword control case begin shell">case</span> <span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">OS</span></span> <span class="keyword control case in shell">in</span>
    centos<span class="keyword operator logical shell">|</span>fedora<span class="keyword operator logical shell">|</span>rhel<span class="keyword operator logical shell">|</span>debian<span class="keyword operator logical shell">|</span>ubuntu<span class="keyword operator logical shell">|</span>elementary<span class="keyword operator logical shell">|</span>raspbian<span class="keyword operator logical shell">|</span>arch<span class="keyword operator logical shell">|</span>manjaro<span class="keyword operator logical shell">|</span>clear-linux-os<span class="keyword operator logical shell">|</span>linuxmint<span class="keyword operator logical shell">|</span>opensuse-tumbleweed<span class="keyword operator logical shell">|</span>opensuse-leap<span class="keyword operator logical shell">|</span>opensuse<span class="keyword operator logical shell">|</span>solus<span class="keyword operator logical shell">|</span>pop<span class="keyword operator logical shell">|</span>neon<span class="keyword operator logical shell">|</span>sparky<span class="keyword operator logical shell">|</span>vyos<span class="keyword operator logical shell">|</span>void<span class="keyword operator logical shell">|</span>alpine<span class="keyword operator logical shell">|</span>Deepin<span class="keyword operator logical shell">|</span>gentoo<span class="keyword control case item shell">)</span>
        <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>/usr/bin/nextdns<span class="punctuation definition string end shell">&quot;</span></span></span>
        <span class="punctuation terminator case shell">;;</span>
    openwrt<span class="keyword operator logical shell">|</span>overthebox<span class="keyword control case item shell">)</span>
        <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>/usr/sbin/nextdns<span class="punctuation definition string end shell">&quot;</span></span></span>
        <span class="punctuation terminator case shell">;;</span>
    synology<span class="keyword control case item shell">)</span>
        <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>/usr/local/bin/nextdns<span class="punctuation definition string end shell">&quot;</span></span></span>
    <span class="punctuation terminator case shell">;;</span>
    darwin<span class="keyword control case item shell">)</span>
    <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion command parens shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section parens begin shell">(</span><span class="meta function-call shell"><span class="variable function shell">brew</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> --</span>prefix</span> <span class="constant numeric integer decimal file-descriptor shell">2</span><span class="keyword operator assignment redirection shell">&gt;</span>/dev/null</span> <span class="keyword operator logical or shell">||</span> <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> /usr/local</span><span class="punctuation section parens end shell">)</span></span>/bin/nextdns<span class="punctuation definition string end shell">&quot;</span></span></span>
        <span class="punctuation terminator case shell">;;</span>
    asuswrt-merlin<span class="keyword operator logical shell">|</span>ddwrt<span class="keyword control case item shell">)</span>
        <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>/jffs/nextdns/nextdns<span class="punctuation definition string end shell">&quot;</span></span></span>
        <span class="punctuation terminator case shell">;;</span>
    freebsd<span class="keyword operator logical shell">|</span>pfsense<span class="keyword operator logical shell">|</span>opnsense<span class="keyword operator logical shell">|</span>netbsd<span class="keyword operator logical shell">|</span>openbsd<span class="keyword control case item shell">)</span>
        <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>/usr/local/sbin/nextdns<span class="punctuation definition string end shell">&quot;</span></span></span>
        <span class="punctuation terminator case shell">;;</span>
    edgeos<span class="keyword control case item shell">)</span>
        <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>/config/nextdns/nextdns<span class="punctuation definition string end shell">&quot;</span></span></span>
        <span class="punctuation terminator case shell">;;</span>
    ubios<span class="keyword control case item shell">)</span>
        <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>/data/nextdns<span class="punctuation definition string end shell">&quot;</span></span></span>
        <span class="punctuation terminator case shell">;;</span>
    steamos<span class="keyword control case item shell">)</span>
        <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">HOME</span></span>/.local/bin/nextdns<span class="punctuation definition string end shell">&quot;</span></span></span>
        <span class="punctuation terminator case shell">;;</span>
    <span class="keyword operator regexp quantifier shell">*</span><span class="keyword control case item shell">)</span>
        <span class="meta function-call shell"><span class="variable function shell">log_error</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>Unknown bin location for <span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">OS</span></span><span class="punctuation definition string end shell">&quot;</span></span></span>
        <span class="punctuation terminator case shell">;;</span>
    <span class="keyword control case end shell">esac</span>
<span class="punctuation section braces end shell">}</span></span>

<span class="meta function shell"><span class="entity name function shell">is_version_current</span><span class="punctuation section parens begin shell">(</span><span class="punctuation section parens end shell">)</span> <span class="punctuation section braces begin shell">{</span>
    <span class="keyword control case begin shell">case</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">INSTALL_RELEASE</span></span><span class="punctuation definition string end shell">&quot;</span></span> <span class="keyword control case in shell">in</span>
    <span class="keyword operator regexp quantifier shell">*</span>/<span class="keyword operator regexp quantifier shell">*</span><span class="keyword control case item shell">)</span>
        <span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> Snapshot</span><span class="comment line number-sign shell">
</span>        <span class="variable other readwrite assignment shell">hash</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell"><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section expansion parameter begin shell">{</span></span><span class="meta group expansion parameter shell"><span class="variable other readwrite shell">INSTALL_RELEASE<span class="keyword operator expansion shell">#</span></span></span><span class="meta group expansion parameter shell"><span class="keyword operator regexp quantifier shell">*</span>/</span><span class="meta group expansion parameter shell"><span class="punctuation section expansion parameter end shell">}</span></span></span>
        <span class="meta function-call shell"><span class="variable function shell">test</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>0.0.0-<span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">hash</span></span><span class="punctuation definition string end shell">&quot;</span></span> = <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">CURRENT_RELEASE</span></span><span class="punctuation definition string end shell">&quot;</span></span></span>
        <span class="punctuation terminator case shell">;;</span>
    <span class="keyword operator regexp quantifier shell">*</span><span class="keyword control case item shell">)</span>
        <span class="meta function-call shell"><span class="variable function shell">test</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">INSTALL_RELEASE</span></span><span class="punctuation definition string end shell">&quot;</span></span> = <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">CURRENT_RELEASE</span></span><span class="punctuation definition string end shell">&quot;</span></span></span>
        <span class="punctuation terminator case shell">;;</span>
    <span class="keyword control case end shell">esac</span>
<span class="punctuation section braces end shell">}</span></span>

<span class="meta function shell"><span class="entity name function shell">get_current_release</span><span class="punctuation section parens begin shell">(</span><span class="punctuation section parens end shell">)</span> <span class="punctuation section braces begin shell">{</span>
    <span class="keyword control if begin shell">if</span> <span class="support function test begin shell">[</span><span class="meta function-call arguments shell"> <span class="variable parameter option shell"><span class="punctuation definition parameter shell">-</span>x</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">NEXTDNS_BIN</span></span><span class="punctuation definition string end shell">&quot;</span></span> <span class="support function test end shell">]</span></span><span class="keyword operator logical continue shell">;</span> <span class="keyword control if then shell">then</span>
        <span class="meta function-call shell"><span class="variable function shell"><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">NEXTDNS_BIN</span></span></span></span><span class="meta function-call arguments shell"> version</span><span class="keyword operator logical pipe shell">|</span><span class="meta function-call shell"><span class="variable function shell">cut</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>d</span><span class="string quoted single shell"><span class="punctuation definition string begin shell">&#39;</span> <span class="punctuation definition string end shell">&#39;</span></span><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>f</span> 3</span>
    <span class="keyword control if end shell">fi</span>
<span class="punctuation section braces end shell">}</span></span>

<span class="meta function shell"><span class="entity name function shell">get_release</span><span class="punctuation section parens begin shell">(</span><span class="punctuation section parens end shell">)</span> <span class="punctuation section braces begin shell">{</span>
    <span class="keyword control if begin shell">if</span> <span class="support function test begin shell">[</span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">NEXTDNS_VERSION</span></span><span class="punctuation definition string end shell">&quot;</span></span> <span class="support function test end shell">]</span></span><span class="keyword operator logical continue shell">;</span> <span class="keyword control if then shell">then</span>
        <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">NEXTDNS_VERSION</span></span><span class="punctuation definition string end shell">&quot;</span></span></span>
    <span class="keyword control if else shell">else</span>
        <span class="keyword control for shell">for</span><span class="meta group for shell"> cmd <span class="keyword control in shell">in</span> curl wget openssl true</span><span class="keyword operator logical continue shell">;</span> <span class="keyword control do shell">do</span>
            <span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> command is the &quot;right&quot; way but may be compiled out of busybox shell</span><span class="comment line number-sign shell">
</span>            <span class="meta function-call shell"><span class="variable function shell">!</span></span><span class="meta function-call arguments shell"> command<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>v</span> <span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">cmd</span></span> <span class="keyword operator assignment redirection shell">&gt;</span> /dev/null <span class="constant numeric integer decimal file-descriptor shell">2</span><span class="keyword operator assignment redirection shell">&gt;&amp;</span><span class="constant numeric integer decimal file-descriptor shell">1</span> </span><span class="keyword operator logical or shell">||</span> <span class="keyword control break shell">break</span>
            <span class="meta function-call shell"><span class="variable function shell">!</span></span><span class="meta function-call arguments shell"> which <span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">cmd</span></span> <span class="keyword operator assignment redirection shell">&gt;</span> /dev/null <span class="constant numeric integer decimal file-descriptor shell">2</span><span class="keyword operator assignment redirection shell">&gt;&amp;</span><span class="constant numeric integer decimal file-descriptor shell">1</span> </span><span class="keyword operator logical or shell">||</span> <span class="keyword control break shell">break</span>
        <span class="keyword control done shell">done</span>
        <span class="keyword control case begin shell">case</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">cmd</span></span><span class="punctuation definition string end shell">&quot;</span></span> <span class="keyword control case in shell">in</span>
        curl<span class="keyword control case item shell">)</span> <span class="variable other readwrite assignment shell">cmd</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell"><span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>curl -A curl -s<span class="punctuation definition string end shell">&quot;</span></span></span> <span class="punctuation terminator case shell">;;</span>
        wget<span class="keyword control case item shell">)</span> <span class="variable other readwrite assignment shell">cmd</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell"><span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>wget -qO- -U curl<span class="punctuation definition string end shell">&quot;</span></span></span> <span class="punctuation terminator case shell">;;</span>
        openssl<span class="keyword control case item shell">)</span> <span class="variable other readwrite assignment shell">cmd</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell"><span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>openssl_get<span class="punctuation definition string end shell">&quot;</span></span></span> <span class="punctuation terminator case shell">;;</span>
        <span class="keyword operator regexp quantifier shell">*</span><span class="keyword control case item shell">)</span>
            <span class="meta function-call shell"><span class="variable function shell">log_error</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>Cannot retrieve latest version<span class="punctuation definition string end shell">&quot;</span></span></span>
            <span class="meta function-call shell"><span class="keyword control return shell">return</span></span>
            <span class="punctuation terminator case shell">;;</span>
        <span class="keyword control case end shell">esac</span>
        <span class="variable other readwrite assignment shell">v</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell"><span class="meta group expansion command parens shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section parens begin shell">(</span><span class="meta function-call shell"><span class="variable function shell"><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">cmd</span></span></span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>https://api.github.com/repos/nextdns/nextdns/releases/latest<span class="punctuation definition string end shell">&quot;</span></span></span> <span class="keyword operator logical pipe shell">|</span> <span class="punctuation separator continuation line shell">\
</span>            <span class="meta function-call shell"><span class="variable function shell">grep</span></span><span class="meta function-call arguments shell"> <span class="string quoted single shell"><span class="punctuation definition string begin shell">&#39;</span>&quot;tag_name&quot;:<span class="punctuation definition string end shell">&#39;</span></span></span> <span class="keyword operator logical pipe shell">|</span> <span class="meta function-call shell"><span class="variable function shell">esed</span></span><span class="meta function-call arguments shell"> <span class="string quoted single shell"><span class="punctuation definition string begin shell">&#39;</span>s/.*&quot;([^&quot;]+)&quot;.*/\1/<span class="punctuation definition string end shell">&#39;</span></span></span> <span class="keyword operator logical pipe shell">|</span> <span class="meta function-call shell"><span class="variable function shell">sed</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>e</span> <span class="string quoted single shell"><span class="punctuation definition string begin shell">&#39;</span>s/^v//<span class="punctuation definition string end shell">&#39;</span></span></span><span class="punctuation section parens end shell">)</span></span></span>
        <span class="keyword control if begin shell">if</span> <span class="support function test begin shell">[</span><span class="meta function-call arguments shell"> <span class="variable parameter option shell"><span class="punctuation definition parameter shell">-</span>z</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">v</span></span><span class="punctuation definition string end shell">&quot;</span></span> <span class="support function test end shell">]</span></span><span class="keyword operator logical continue shell">;</span> <span class="keyword control if then shell">then</span>
            <span class="meta function-call shell"><span class="variable function shell">log_error</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>Cannot get latest version: <span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">out</span></span><span class="punctuation definition string end shell">&quot;</span></span></span>
        <span class="keyword control if end shell">fi</span>
        <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">v</span></span><span class="punctuation definition string end shell">&quot;</span></span></span>
    <span class="keyword control if end shell">fi</span>
<span class="punctuation section braces end shell">}</span></span>

<span class="meta function shell"><span class="entity name function shell">esed</span><span class="punctuation section parens begin shell">(</span><span class="punctuation section parens end shell">)</span> <span class="punctuation section braces begin shell">{</span>
    <span class="keyword control if begin shell">if</span> <span class="punctuation definition compound begin shell">(</span><span class="meta function-call shell"><span class="support function echo shell">echo</span></span> <span class="keyword operator logical pipe shell">|</span> <span class="meta function-call shell"><span class="variable function shell">sed</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>E</span> <span class="string quoted single shell"><span class="punctuation definition string begin shell">&#39;</span><span class="punctuation definition string end shell">&#39;</span></span> <span class="keyword operator assignment redirection shell">&gt;</span>/dev/null <span class="constant numeric integer decimal file-descriptor shell">2</span><span class="keyword operator assignment redirection shell">&gt;&amp;</span><span class="constant numeric integer decimal file-descriptor shell">1</span></span><span class="punctuation definition compound end shell">)</span><span class="keyword operator logical continue shell">;</span> <span class="keyword control if then shell">then</span>
        <span class="meta function-call shell"><span class="variable function shell">sed</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>E</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable language shell">@</span></span><span class="punctuation definition string end shell">&quot;</span></span></span>
    <span class="keyword control if else shell">else</span>
        <span class="meta function-call shell"><span class="variable function shell">sed</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>r</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable language shell">@</span></span><span class="punctuation definition string end shell">&quot;</span></span></span>
    <span class="keyword control if end shell">fi</span>
<span class="punctuation section braces end shell">}</span></span>

<span class="meta function shell"><span class="entity name function shell">http_redirect</span><span class="punctuation section parens begin shell">(</span><span class="punctuation section parens end shell">)</span> <span class="punctuation section braces begin shell">{</span>
    <span class="keyword control while shell">while</span> <span class="meta function-call shell"><span class="support function read shell">read</span></span><span class="meta function-call arguments shell"> <span class="variable parameter option shell"><span class="punctuation definition parameter shell">-</span>r</span> header</span><span class="keyword operator logical continue shell">;</span> <span class="keyword control do shell">do</span>
        <span class="keyword control case begin shell">case</span> <span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">header</span></span> <span class="keyword control case in shell">in</span>
            Location:<span class="keyword operator regexp quantifier shell">*</span><span class="keyword control case item shell">)</span>
                <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section expansion parameter begin shell">{</span></span><span class="meta group expansion parameter shell"><span class="variable other readwrite shell">header<span class="keyword operator expansion shell">#</span></span></span><span class="meta group expansion parameter shell">Location: </span><span class="meta group expansion parameter shell"><span class="punctuation section expansion parameter end shell">}</span></span><span class="punctuation definition string end shell">&quot;</span></span></span>
                <span class="meta function-call shell"><span class="keyword control return shell">return</span></span>
            <span class="punctuation terminator case shell">;;</span>
        <span class="keyword control case end shell">esac</span>
        <span class="keyword control if begin shell">if</span> <span class="support function test begin shell">[</span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">header</span></span><span class="punctuation definition string end shell">&quot;</span></span> <span class="keyword operator logical shell">=</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="punctuation definition string end shell">&quot;</span></span> <span class="support function test end shell">]</span></span><span class="keyword operator logical continue shell">;</span> <span class="keyword control if then shell">then</span>
            <span class="keyword control break shell">break</span>
        <span class="keyword control if end shell">fi</span>
    <span class="keyword control done shell">done</span>
    <span class="meta function-call shell"><span class="variable function shell">cat</span></span><span class="meta function-call arguments shell"> <span class="keyword operator assignment redirection shell">&gt;</span> /dev/null</span>
    <span class="meta function-call shell"><span class="keyword control return shell">return</span></span><span class="meta function-call arguments shell"> 1</span>
<span class="punctuation section braces end shell">}</span></span>

<span class="meta function shell"><span class="entity name function shell">http_body</span><span class="punctuation section parens begin shell">(</span><span class="punctuation section parens end shell">)</span> <span class="punctuation section braces begin shell">{</span>
    <span class="meta function-call shell"><span class="variable function shell">sed</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>n</span> <span class="string quoted single shell"><span class="punctuation definition string begin shell">&#39;</span>/^\r/,$p<span class="punctuation definition string end shell">&#39;</span></span></span> <span class="keyword operator logical pipe shell">|</span> <span class="meta function-call shell"><span class="variable function shell">sed</span></span><span class="meta function-call arguments shell"> 1d</span>
<span class="punctuation section braces end shell">}</span></span>

<span class="meta function shell"><span class="entity name function shell">openssl_get</span><span class="punctuation section parens begin shell">(</span><span class="punctuation section parens end shell">)</span> <span class="punctuation section braces begin shell">{</span>
    <span class="variable other readwrite assignment shell">host</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell"><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section expansion parameter begin shell">{</span></span><span class="meta group expansion parameter shell"><span class="variable other readwrite shell">1<span class="keyword operator expansion shell">#</span></span></span><span class="meta group expansion parameter shell">https://<span class="keyword operator regexp quantifier shell">*</span></span><span class="meta group expansion parameter shell"><span class="punctuation section expansion parameter end shell">}</span></span></span> <span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> https://dom.com/path -&gt; dom.com/path</span><span class="comment line number-sign shell">
</span>    <span class="variable other readwrite assignment shell">path</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell">/<span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section expansion parameter begin shell">{</span></span><span class="meta group expansion parameter shell"><span class="variable other readwrite shell">host<span class="keyword operator expansion shell">#</span></span></span><span class="meta group expansion parameter shell"><span class="keyword operator regexp quantifier shell">*</span>/</span><span class="meta group expansion parameter shell"><span class="punctuation section expansion parameter end shell">}</span></span></span>    <span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> dom.com/path -&gt; /path</span><span class="comment line number-sign shell">
</span>    <span class="variable other readwrite assignment shell">host</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell"><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section expansion parameter begin shell">{</span></span><span class="meta group expansion parameter shell"><span class="variable other readwrite shell">host<span class="keyword operator expansion shell">%</span></span></span><span class="meta group expansion parameter shell"><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">path</span></span></span><span class="meta group expansion parameter shell"><span class="punctuation section expansion parameter end shell">}</span></span></span>  <span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> dom.com/path -&gt; dom.com</span><span class="comment line number-sign shell">
</span>    <span class="meta function-call shell"><span class="support function printf shell">printf</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>GET %s HTTP/1.0\nHost: %s\nUser-Agent: curl\n\n<span class="punctuation definition string end shell">&quot;</span></span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">path</span></span><span class="punctuation definition string end shell">&quot;</span></span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">host</span></span><span class="punctuation definition string end shell">&quot;</span></span></span> <span class="keyword operator logical pipe shell">|</span>
        <span class="meta function-call shell"><span class="variable function shell">openssl</span></span><span class="meta function-call arguments shell"> s_client<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>quiet</span><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>connect</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">host</span></span>:443<span class="punctuation definition string end shell">&quot;</span></span> <span class="constant numeric integer decimal file-descriptor shell">2</span><span class="keyword operator assignment redirection shell">&gt;</span>/dev/null</span>
<span class="punctuation section braces end shell">}</span></span>

<span class="meta function-call shell"><span class="support function umask shell">umask</span></span><span class="meta function-call arguments shell"> 0022</span>
<span class="meta function-call shell"><span class="variable function shell">main</span></span></span></code></pre>
]]></description>
    </item>
    <item>
      <title>Signal CLI (scli) on Alpine</title>
      <link>https://cleberg.net/blog/scli.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/scli.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Wed, 08 Nov 2023 00:00:00 +0000</pubDate>
      <category>linux</category>
      <description><![CDATA[<p><a href="https://github.com/isamert/scli">scli</a> is a command-line tool that allows you to connect to your Signal messenger account. This program utilizes a two-pane display that shows you chats on the left and the focused conversation on the right.</p>
<p>This guide will show you how to install <code class="verbatim">scli</code> and its dependencies on Alpine Linux, which requires some extra work due to musl.</p>
<p>If you're using a non-musl system, you can likely following the <code class="verbatim">scli</code> README and download the packaged binaries for an easier installation process.</p>
<h2 id="dependencies"><span class="section-number-2">1.</span> Dependencies</h2>
<p>In order to use <code class="verbatim">scli</code>, you need a few dependencies:</p>
<ul>
<li><code class="verbatim">openjdk17-jre</code> - Used as a dependency for the <code class="verbatim">signal-cli</code> tool. Version may vary.</li>
<li><code class="verbatim">signal-cli</code> - Used as the backbone of the <code class="verbatim">scli</code> tool.</li>
<li><code class="verbatim">findutils</code> - Replaces the standard Busybox version of <code class="verbatim">xargs</code>.</li>
<li><code class="verbatim">urwid</code> - A console user interface library for Python.</li>
<li><code class="verbatim">urwid-readline</code> - For GNU emacs-like keybinds on the input line.</li>
<li><code class="verbatim">qrencode</code> - Displays a QR code in the terminal to link the device using your phone. Not necessary if you're only linking on desktop and can copy/paste the connection URL.</li>
</ul>
<p>Let's start by installing the packages available via Alpine's repositories. Be sure to install the latest version of <code class="verbatim">openjdk</code>. If you run into Java-related issues, uninstall <code class="verbatim">openjdk</code> and install an older version.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">doas</span></span><span class="meta function-call arguments shell"> apk add openjdk17-jre findutils qrencode</span></span></code></pre>
<p>Next, let's install <code class="verbatim">signal-cli</code>. Be sure to export the version of <code class="verbatim">signal-cli</code> that you want. I use version <code class="verbatim">0.12.4</code> below, but that may be outdated by the time you're reading this.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="storage modifier shell">export</span> <span class="variable other readwrite assignment shell">VERSION</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell"><span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>0.12.4<span class="punctuation definition string end shell">&quot;</span></span></span></span>
<span class="meta function-call shell"><span class="variable function shell">wget</span></span><span class="meta function-call arguments shell"> https://github.com/AsamK/signal-cli/releases/download/v<span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section expansion parameter begin shell">{</span></span><span class="meta group expansion parameter shell"><span class="variable other readwrite shell">VERSION</span></span><span class="meta group expansion parameter shell"><span class="punctuation section expansion parameter end shell">}</span></span><span class="punctuation definition string end shell">&quot;</span></span>/signal-cli-<span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section expansion parameter begin shell">{</span></span><span class="meta group expansion parameter shell"><span class="variable other readwrite shell">VERSION</span></span><span class="meta group expansion parameter shell"><span class="punctuation section expansion parameter end shell">}</span></span><span class="punctuation definition string end shell">&quot;</span></span>.tar.gz</span>
<span class="meta function-call shell"><span class="variable function shell">doas</span></span><span class="meta function-call arguments shell"> tar xf signal-cli-<span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section expansion parameter begin shell">{</span></span><span class="meta group expansion parameter shell"><span class="variable other readwrite shell">VERSION</span></span><span class="meta group expansion parameter shell"><span class="punctuation section expansion parameter end shell">}</span></span><span class="punctuation definition string end shell">&quot;</span></span>.tar.gz<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>C</span> /opt</span>
<span class="meta function-call shell"><span class="variable function shell">doas</span></span><span class="meta function-call arguments shell"> ln<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>sf</span> /opt/signal-cli-<span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section expansion parameter begin shell">{</span></span><span class="meta group expansion parameter shell"><span class="variable other readwrite shell">VERSION</span></span><span class="meta group expansion parameter shell"><span class="punctuation section expansion parameter end shell">}</span></span><span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>/bin/signal/cli /usr/local/bin</span></span></span></code></pre>
<p>Finally, install the <code class="verbatim">urwid</code> packages using the Python packaging utility.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">pip3</span></span><span class="meta function-call arguments shell"> install urwid urwid-readline</span></span></code></pre>
<h2 id="installation"><span class="section-number-2">2.</span> Installation</h2>
<p>Now that we have all of the dependencies we need, we can install <code class="verbatim">scli</code>. Start by simply cloning the repository.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">git</span></span><span class="meta function-call arguments shell"> clone https://github.com/isamert/scli</span></span></code></pre>
<p>When I cloned this repository on 2023-11-08, I found a bug in the logic that required a fix. You must edit the <code class="verbatim">scli</code> file and replace the one instance of <code class="verbatim">RLIMIT_OFILE</code> with <code class="verbatim">RLIMIT_NOFILE</code>.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="support function cd shell">cd</span></span><span class="meta function-call arguments shell"> scli</span>
<span class="meta function-call shell"><span class="variable function shell">nano</span></span><span class="meta function-call arguments shell"> scli</span></span></code></pre>
<p>Once complete, you can move this program to anywhere on your <code class="verbatim">$PATH</code>. I chose the following directory.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">doas</span></span><span class="meta function-call arguments shell"> mv scli /usr/local/bin/scli</span></span></code></pre>
<h2 id="initial-setup"><span class="section-number-2">3.</span> Initial Setup</h2>
<p>Now that everything is installed, we can login and configure the client. Start by generating a connection link.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">signal-cli</span></span><span class="meta function-call arguments shell"> link<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>n</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>YOUR-DEVICE-NICKNAME<span class="punctuation definition string end shell">&quot;</span></span></span> <span class="keyword operator logical pipe shell">|</span> <span class="meta function-call shell"><span class="variable function shell">tee</span></span><span class="meta function-call arguments shell"> <span class="keyword operator assignment redirection process shell">&gt;</span><span class="punctuation section parens begin shell">(</span><span class="meta function-call shell"><span class="variable function shell">xargs</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>L</span> 1 qrencode<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>t</span> utf8</span><span class="punctuation section parens end shell">)</span></span></span></code></pre>
<p>This will generate a connection link and related QR code for you to use to link the devices together. Once complete, <strong>wait patiently</strong> for the connection process to finish.</p>
<p>Once it completes, it will exit and return you to the prompt. From here, you need to perform an initial <code class="verbatim">receive</code> command to start things off. The <code class="verbatim">USERNAME</code> variable should be your phone number, such as <code class="verbatim">+15551237890</code>.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">signal-cli</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>u</span> USERNAME receive</span></span></code></pre>
<p>Also be sure to test the daemon to ensure it works properly. If no errors occur, it's working. If you run into errors because you're not running a DBUS session, see my notes below.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">signal-cli</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>u</span> USERNAME daemon</span></span></code></pre>
<p>Once the initial reception is complete, you are ready to use <code class="verbatim">scli</code>.</p>
<p>This process will differ depending on your desktop environment (DE). If you are running a DE, you likely have a DBUS session running already and can simply launch the program.</p>
<p>However, if you're like me and running your computer straight on the TTY without a DE, you'll need to start a DBUS session for this program.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> If you&#39;re not running a DBUS session yet, you need to start one for scli</span><span class="comment line number-sign shell">
</span><span class="meta function-call shell"><span class="variable function shell">dbus-run-session</span></span><span class="meta function-call arguments shell"><span class="keyword operator end-of-options shell"> --</span></span><span class="meta function-call arguments shell"> scli</span>

<span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> OR - If you&#39;re already running a DBUS session, simply run scli</span><span class="comment line number-sign shell">
</span><span class="meta function-call shell"><span class="variable function shell">scli</span></span></span></code></pre>
<h2 id="configuration"><span class="section-number-2">4.</span> Configuration</h2>
<p>Lastly, there are a number of configuration options that you can pass via the command or in the <code class="verbatim">~/.config/sclirc</code> file. See the GitHub README for more information on configuration options.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">nano</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/.config/sclirc</span></span></code></pre>
<pre><code class="language-conf"># ~/.config/sclirc

wrap-at = 80
enable-notifications = true</code></pre>
<p>That's it! Following this guide, I have a functional <code class="verbatim">scli</code> program that successfully sends messages to my contacts and myself!</p>
]]></description>
    </item>
    <item>
      <title>Self-Hosting Guide: AnonymousOverflow</title>
      <link>https://cleberg.net/blog/self-hosting-anonymousoverflow.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/self-hosting-anonymousoverflow.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Tue, 17 Oct 2023 00:00:00 +0000</pubDate>
      <category>linux</category>
      <category>self-hosting</category>
      <description><![CDATA[<h2 id="overview"><span class="section-number-2">1.</span> Overview</h2>
<p>I recently launched an instance of AnonymousOverflow at <code class="verbatim">ao.cleberg.net</code> and wanted to write a brief post on how easy it is to install with Docker Compose and Nginx.</p>
<p>This guide uses Ubuntu server, Docker Compose, and Nginx as a reverse proxy.</p>
<h2 id="installation"><span class="section-number-2">2.</span> Installation</h2>
<h3 id="docker-compose"><span class="section-number-3">2.1.</span> Docker Compose</h3>
<p>To install AnonymousOverflow, start by creating a directory for the application and create its <code class="verbatim">docker-compose.yml</code> file.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">mkdir</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/anonymousoverflow</span> <span class="keyword operator logical and shell">&amp;&amp;</span> <span class="meta function-call shell"><span class="support function cd shell">cd</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/anonymousoverflow</span>
<span class="meta function-call shell"><span class="variable function shell">nano</span></span><span class="meta function-call arguments shell"> docker-compose.yml</span></span></code></pre>
<p>Within this file, paste the following information. Be sure to change the <code class="verbatim">APP_URL</code>, <code class="verbatim">JWT_SIGNING_SECRET</code>, and <code class="verbatim">ports</code> to match your needs.</p>
<pre><code class="language-yaml highlight"><span class="source yaml"><span class="string unquoted plain out yaml"><span class="entity name tag yaml">version</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string quoted double yaml"><span class="punctuation definition string begin yaml">&quot;</span>3<span class="punctuation definition string end yaml">&quot;</span></span>

<span class="string unquoted plain out yaml"><span class="entity name tag yaml">services</span></span><span class="punctuation separator key-value mapping yaml">:</span>
    <span class="string unquoted plain out yaml"><span class="entity name tag yaml">anonymousoverflow</span></span><span class="punctuation separator key-value mapping yaml">:</span>
        <span class="string unquoted plain out yaml"><span class="entity name tag yaml">container_name</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string quoted double yaml"><span class="punctuation definition string begin yaml">&quot;</span>app<span class="punctuation definition string end yaml">&quot;</span></span>
        <span class="string unquoted plain out yaml"><span class="entity name tag yaml">image</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string quoted double yaml"><span class="punctuation definition string begin yaml">&quot;</span>ghcr.io/httpjamesm/anonymousoverflow:release<span class="punctuation definition string end yaml">&quot;</span></span>
        <span class="string unquoted plain out yaml"><span class="entity name tag yaml">environment</span></span><span class="punctuation separator key-value mapping yaml">:</span>
            <span class="punctuation definition block sequence item yaml">-</span> <span class="string unquoted plain out yaml">APP_URL=https://ao.example.com</span>
            <span class="punctuation definition block sequence item yaml">-</span> <span class="string unquoted plain out yaml">JWT_SIGNING_SECRET=secret</span> <span class="comment line number-sign yaml"><span class="punctuation definition comment line number-sign yaml">#</span>pwgen 40 1
</span>        <span class="string unquoted plain out yaml"><span class="entity name tag yaml">ports</span></span><span class="punctuation separator key-value mapping yaml">:</span>
            <span class="punctuation definition block sequence item yaml">-</span> <span class="string quoted double yaml"><span class="punctuation definition string begin yaml">&quot;</span>9380:8080<span class="punctuation definition string end yaml">&quot;</span></span>
        <span class="string unquoted plain out yaml"><span class="entity name tag yaml">restart</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string quoted double yaml"><span class="punctuation definition string begin yaml">&quot;</span>always<span class="punctuation definition string end yaml">&quot;</span></span></span></code></pre>
<p>Save and exit the file when complete. You can now launch the container and access it via your local network.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> docker-compose up<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>d</span></span></span></code></pre>
<h3 id="nginx-reverse-proxy"><span class="section-number-3">2.2.</span> Nginx Reverse Proxy</h3>
<p>If you want to access this service outside the local network, I recommend using Nginx as a reverse proxy.</p>
<p>Let's start by creating a configuration file.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> nano /etc/nginx/sites-available/ao</span></span></code></pre>
<p>Within this file, paste the following content and replace <code class="verbatim">ao.example.com</code> with your URL. You may need to update the SSL certificate statements if your certificates are in a different location.</p>
<pre><code class="language-conf">server {
    if ($host ~ ^[^.]+\.cleberg\.net$) {
        return 301 https://$host$request_uri;
    }

    listen [::]:80;
    listen 80;
    server_name ao.example.com;
    return 404;
}

server {
    listen [::]:443 ssl http2;
    listen 443 ssl http2;
    server_name ao.example.com;
    access_log  /var/log/nginx/ao.access.log;
    error_log   /var/log/nginx/ao.error.log;

    add_header X-Content-Type-Options "nosniff";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Frame-Options "DENY";
    add_header Strict-Transport-Security "max-age=63072000; includeSubDomains";
    add_header Referrer-Policy "no-referrer";

    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
    include /etc/letsencrypt/options-ssl-nginx.conf;
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;

    location / {
        set $upstream_ao http://127.0.0.1:9380;
        proxy_pass $upstream_ao;

        proxy_set_header Host $host;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection upgrade;
        proxy_set_header Accept-Encoding gzip;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Forwarded-Host $http_host;
        proxy_set_header X-Forwarded-Uri $request_uri;
        proxy_set_header X-Forwarded-Ssl on;
        proxy_redirect  http://  $scheme://;
        proxy_http_version 1.1;
        proxy_set_header Connection "";
        proxy_cache_bypass $cookie_session;
        proxy_no_cache $cookie_session;
        proxy_buffers 64 256k;
    }
}</code></pre>
<p>Save and exit the file when complete. On Ubuntu, you will need to symlink the configuration file before it will be recognized by Nginx. Once complete, simply restart the web server.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> ln<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>s</span> /etc/nginx/sites-available/ao /etc/nginx/sites-enabled/ao</span>
<span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> systemctl restart nginx.service</span></span></code></pre>
<p>The website will now be available publicly.</p>
]]></description>
    </item>
    <item>
      <title>Alpine Linux SSH Hardening</title>
      <link>https://cleberg.net/blog/alpine-ssh-hardening.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/alpine-ssh-hardening.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Sun, 15 Oct 2023 00:00:00 +0000</pubDate>
      <category>linux</category>
      <category>security</category>
      <description><![CDATA[<h2 id="overview"><span class="section-number-2">1.</span> Overview</h2>
<p>This guide follows the standard <a href="https://www.ssh-audit.com/hardening_guides.html">ssh-audit</a> hardening guide, tweaked for Alpine Linux.</p>
<h2 id="hardening-guide"><span class="section-number-2">2.</span> Hardening Guide</h2>
<p>These steps must be performed as root. You can try to use <code class="verbatim">doas</code> or <code class="verbatim">sudo</code>, but there may be issues.</p>
<ol>
<li>Re-generate the RSA and ED25519 keys</li>
</ol>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">rm</span></span><span class="meta function-call arguments shell"> /etc/ssh/ssh_host_<span class="keyword operator regexp quantifier shell">*</span></span>
<span class="meta function-call shell"><span class="variable function shell">ssh-keygen</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>t</span> rsa<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>b</span> 4096<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>f</span> /etc/ssh/ssh_host_rsa_key<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>N</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="punctuation definition string end shell">&quot;</span></span></span>
<span class="meta function-call shell"><span class="variable function shell">ssh-keygen</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>t</span> ed25519<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>f</span> /etc/ssh/ssh_host_ed25519_key<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>N</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="punctuation definition string end shell">&quot;</span></span></span></span></code></pre>
<ol>
<li value="2">Remove small Diffie-Hellman moduli</li>
</ol>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">awk</span></span><span class="meta function-call arguments shell"> <span class="string quoted single shell"><span class="punctuation definition string begin shell">&#39;</span>$5 &gt;= 3071<span class="punctuation definition string end shell">&#39;</span></span> /etc/ssh/moduli <span class="keyword operator assignment redirection shell">&gt;</span> /etc/ssh/moduli.safe</span>
<span class="meta function-call shell"><span class="variable function shell">mv</span></span><span class="meta function-call arguments shell"> /etc/ssh/moduli.safe /etc/ssh/moduli</span></span></code></pre>
<ol>
<li value="3">Enable the RSA and ED25519 HostKey directives in the /etc/ssh/sshd<sub>config</sub> file</li>
</ol>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sed</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>i</span> <span class="string quoted single shell"><span class="punctuation definition string begin shell">&#39;</span>s/^\#HostKey \/etc\/ssh\/ssh_host_\(rsa\|ed25519\)_key$/HostKey \/etc\/ssh\/ssh_host_\1_key/g<span class="punctuation definition string end shell">&#39;</span></span> /etc/ssh/sshd_config</span></span></code></pre>
<ol>
<li value="4">Restrict supported key exchange, cipher, and MAC algorithms</li>
</ol>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="variable parameter option shell"><span class="punctuation definition parameter shell">-</span>e</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>\n# Restrict key exchange, cipher, and MAC algorithms, as per sshaudit.com\n# hardening guide.\nKexAlgorithms sntrup761x25519-sha512@openssh.com,curve25519-sha256,curve25519-sha256@libssh.org,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group-exchange-sha256\nCiphers chacha20-poly1305@openssh.com,aes256-gcm@openssh.com,aes128-gcm@openssh.com,aes256-ctr,aes192-ctr,aes128-ctr\nMACs hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,umac-128-etm@openssh.com\nHostKeyAlgorithms ssh-ed25519,ssh-ed25519-cert-v01@openssh.com,sk-ssh-ed25519@openssh.com,sk-ssh-ed25519-cert-v01@openssh.com,rsa-sha2-512,rsa-sha2-512-cert-v01@openssh.com,rsa-sha2-256,rsa-sha2-256-cert-v01@openssh.com<span class="punctuation definition string end shell">&quot;</span></span> <span class="keyword operator assignment redirection shell">&gt;</span> /etc/ssh/sshd_config.d/ssh-audit_hardening.conf</span></span></code></pre>
<ol>
<li value="5">Include the /etc/ssh/sshd<sub>config</sub>.d directory</li>
</ol>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="variable parameter option shell"><span class="punctuation definition parameter shell">-</span>e</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>Include /etc/ssh/sshd_config.d/*.conf<span class="punctuation definition string end shell">&quot;</span></span> <span class="keyword operator assignment redirection shell">&gt;</span> /etc/ssh/sshd_config</span></span></code></pre>
<ol>
<li value="6">Restart OpenSSH server</li>
</ol>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">rc-service</span></span><span class="meta function-call arguments shell"> sshd restart</span></span></code></pre>
<h2 id="testing-ssh"><span class="section-number-2">3.</span> Testing SSH</h2>
<p>You can test the results with the <code class="verbatim">ssh-audit</code> python script.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">pip3</span></span><span class="meta function-call arguments shell"> install ssh-audit</span>
<span class="meta function-call shell"><span class="variable function shell">ssh-audit</span></span><span class="meta function-call arguments shell"> localhost</span></span></code></pre>
<p>If everything succeeded, the results will show as all green. If anything is yellow, orange, or red, you may need to tweak additional settings.</p>
]]></description>
    </item>
    <item>
      <title>Self-Hosting Guide: Authelia</title>
      <link>https://cleberg.net/blog/self-hosting-authelia.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/self-hosting-authelia.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Wed, 11 Oct 2023 00:00:00 +0000</pubDate>
      <category>linux</category>
      <category>security</category>
      <category>self-hosting</category>
      <description><![CDATA[<h2 id="overview"><span class="section-number-2">1.</span> Overview</h2>
<p><a href="https://www.authelia.com/">Authelia</a> is an open-source authentication service that allows you to place a portal between end users on the internet and self-hosted services on your server.</p>
<p>You can require one factor (username+password) or two factor authentication for any such user before allowing them to access a specific service on your domain.</p>
<p>This guide will walk through a standard installation of Authelia for <code class="verbatim">example.com</code>, using <code class="verbatim">auth.example.com</code> as Authelia's authentication domain and <code class="verbatim">teddit.example.com</code> as the website we want to protect behind the authentication portal.</p>
<h2 id="prerequisites"><span class="section-number-2">2.</span> Prerequisites</h2>
<p>This guide assumes you have the following already set-up:</p>
<ul>
<li>A registered domain with DNS pointing to your server.</li>
<li>A subdomain for Authelia (<code class="verbatim">auth.example.com</code>) and a subdomain to protect via Authelia (<code class="verbatim">app.example.com</code>).</li>
<li>A working Nginx web server.</li>
<li>Docker and docker-compose installed.</li>
</ul>
<h2 id="installation"><span class="section-number-2">3.</span> Installation</h2>
<p>This guide will walk through each installation step one-by-one, starting with the container and finishing by cleaning up external access via an Nginx reverse proxy.</p>
<h3 id="docker-compose"><span class="section-number-3">3.1.</span> Docker-Compose</h3>
<p>To start, create a directory for Authelia and create a <code class="verbatim">docker-compose.yml</code> file.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">mkdir</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/authelia</span>
<span class="meta function-call shell"><span class="variable function shell">nano</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/authelia/docker-compose.yml</span></span></code></pre>
<p>Within this file, paste the following content. If you prefer a different local port, modify the port on the left side of the colon on the <code class="verbatim">9091:9091</code> line. Be sure to modify the <code class="verbatim">TZ</code> variable to your timezone.</p>
<pre><code class="language-yml highlight"><span class="source yaml"><span class="string unquoted plain out yaml"><span class="entity name tag yaml">version</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string quoted double yaml"><span class="punctuation definition string begin yaml">&quot;</span>3.3<span class="punctuation definition string end yaml">&quot;</span></span>

<span class="string unquoted plain out yaml"><span class="entity name tag yaml">services</span></span><span class="punctuation separator key-value mapping yaml">:</span>
    <span class="string unquoted plain out yaml"><span class="entity name tag yaml">authelia</span></span><span class="punctuation separator key-value mapping yaml">:</span>
        <span class="string unquoted plain out yaml"><span class="entity name tag yaml">image</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string unquoted plain out yaml">authelia/authelia</span>
        <span class="string unquoted plain out yaml"><span class="entity name tag yaml">container_name</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string unquoted plain out yaml">authelia</span>
        <span class="string unquoted plain out yaml"><span class="entity name tag yaml">volumes</span></span><span class="punctuation separator key-value mapping yaml">:</span>
            <span class="punctuation definition block sequence item yaml">-</span> <span class="string unquoted plain out yaml">./config:/config</span>
        <span class="string unquoted plain out yaml"><span class="entity name tag yaml">ports</span></span><span class="punctuation separator key-value mapping yaml">:</span>
            <span class="punctuation definition block sequence item yaml">-</span> <span class="string unquoted plain out yaml">9091:9091</span>
        <span class="string unquoted plain out yaml"><span class="entity name tag yaml">environment</span></span><span class="punctuation separator key-value mapping yaml">:</span>
            <span class="punctuation definition block sequence item yaml">-</span> <span class="string unquoted plain out yaml">TZ=America/Chicago</span></span></code></pre>
<p>Start the container with docker-compose:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> docker-compose up<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>d</span></span></span></code></pre>
<p>After the first start, the container will automatically exit and require you to modify the app's configuration files before continuing. Read on to learn more.</p>
<h3 id="authelia-configuration"><span class="section-number-3">3.2.</span> Authelia Configuration</h3>
<p>To configure Authelia before we restart the container, we need to open the <code class="verbatim">config</code> directory and modify the files. Start by editing the <code class="verbatim">configuration.yml</code> file, where all of Authelia's settings are stored.</p>
<p>My personal preference is to copy the original configuration file to a backup file and edit a fresh copy.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> cp <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/authelia/config/configuration.yml <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/authelia/config/configuration.yml.bk</span>
<span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> nano <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/authelia/config/configuration.yml</span></span></code></pre>
<p>Within the blank <code class="verbatim">configuration.yml</code> file, paste the following information. You will need to make quite a few updates, so be sure to read each line carefully and modify as necessary.</p>
<p>The major required changes are:</p>
<ul>
<li>Any instances of <code class="verbatim">example.com</code> should be replaced by your domain.</li>
<li><code class="verbatim">jwt_secret</code> - Use the <code class="verbatim">pwgen 40 1</code> command to generate a secret for yourself.</li>
<li><code class="verbatim">access_control</code> - Set the Authelia domain to bypass here, as well as any subdomains you want to protect.</li>
<li><code class="verbatim">session</code> &gt; <code class="verbatim">secret</code> - Use the <code class="verbatim">pwgen 40 1</code> command to generate a secret for yourself.</li>
<li><code class="verbatim">regulation</code> - Set the variables here to restrict login attempts and bans.</li>
<li><code class="verbatim">storage</code> &gt; <code class="verbatim">encryption_key</code> - Use the <code class="verbatim">pwgen 40 1</code> command to generate a secret for yourself.</li>
<li><code class="verbatim">smtp</code> - If you have access to an SMTP service, set up the information here to active outgoing emails.</li>
</ul>
<pre><code class="language-yml highlight"><span class="source yaml"><span class="comment line number-sign yaml"><span class="punctuation definition comment line number-sign yaml">#</span> yamllint disable rule:comments-indentation
</span><span class="entity other document begin yaml">---</span>
<span class="comment line number-sign yaml"><span class="punctuation definition comment line number-sign yaml">#</span>##############################################################################
</span><span class="comment line number-sign yaml"><span class="punctuation definition comment line number-sign yaml">#</span>                           Authelia Configuration                            #
</span><span class="comment line number-sign yaml"><span class="punctuation definition comment line number-sign yaml">#</span>##############################################################################
</span>
<span class="string unquoted plain out yaml"><span class="entity name tag yaml">theme</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string unquoted plain out yaml">dark</span>
<span class="string unquoted plain out yaml"><span class="entity name tag yaml">jwt_secret</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string unquoted plain out yaml">aiS5iedaiv6eeVaideeLeich5roo6ohvaf3Vee1a</span> <span class="comment line number-sign yaml"><span class="punctuation definition comment line number-sign yaml">#</span> pwgen 40 1
</span>
<span class="string unquoted plain out yaml"><span class="entity name tag yaml">default_redirection_url</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string unquoted plain out yaml">https://example.com</span>

<span class="string unquoted plain out yaml"><span class="entity name tag yaml">server</span></span><span class="punctuation separator key-value mapping yaml">:</span>
    <span class="string unquoted plain out yaml"><span class="entity name tag yaml">host</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="constant numeric float yaml">0.0.0.0</span>
    <span class="string unquoted plain out yaml"><span class="entity name tag yaml">port</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="constant numeric integer yaml">9091</span>
    <span class="string unquoted plain out yaml"><span class="entity name tag yaml">path</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string quoted double yaml"><span class="punctuation definition string begin yaml">&quot;</span><span class="punctuation definition string end yaml">&quot;</span></span>
    <span class="string unquoted plain out yaml"><span class="entity name tag yaml">read_buffer_size</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="constant numeric integer yaml">4096</span>
    <span class="string unquoted plain out yaml"><span class="entity name tag yaml">write_buffer_size</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="constant numeric integer yaml">4096</span>
    <span class="string unquoted plain out yaml"><span class="entity name tag yaml">enable_pprof</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="constant language boolean yaml">false</span>
    <span class="string unquoted plain out yaml"><span class="entity name tag yaml">enable_expvars</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="constant language boolean yaml">false</span>
    <span class="string unquoted plain out yaml"><span class="entity name tag yaml">disable_healthcheck</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="constant language boolean yaml">false</span>
    <span class="string unquoted plain out yaml"><span class="entity name tag yaml">tls</span></span><span class="punctuation separator key-value mapping yaml">:</span>
        <span class="string unquoted plain out yaml"><span class="entity name tag yaml">key</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string quoted double yaml"><span class="punctuation definition string begin yaml">&quot;</span><span class="punctuation definition string end yaml">&quot;</span></span>
        <span class="string unquoted plain out yaml"><span class="entity name tag yaml">certificate</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string quoted double yaml"><span class="punctuation definition string begin yaml">&quot;</span><span class="punctuation definition string end yaml">&quot;</span></span>

<span class="string unquoted plain out yaml"><span class="entity name tag yaml">log</span></span><span class="punctuation separator key-value mapping yaml">:</span>
    <span class="string unquoted plain out yaml"><span class="entity name tag yaml">level</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string unquoted plain out yaml">debug</span>

<span class="string unquoted plain out yaml"><span class="entity name tag yaml">totp</span></span><span class="punctuation separator key-value mapping yaml">:</span>
    <span class="string unquoted plain out yaml"><span class="entity name tag yaml">issuer</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string unquoted plain out yaml">example.com</span>
    <span class="string unquoted plain out yaml"><span class="entity name tag yaml">period</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="constant numeric integer yaml">30</span>
    <span class="string unquoted plain out yaml"><span class="entity name tag yaml">skew</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="constant numeric integer yaml">1</span>

<span class="string unquoted plain out yaml"><span class="entity name tag yaml">authentication_backend</span></span><span class="punctuation separator key-value mapping yaml">:</span>
    <span class="string unquoted plain out yaml"><span class="entity name tag yaml">disable_reset_password</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="constant language boolean yaml">false</span>
    <span class="string unquoted plain out yaml"><span class="entity name tag yaml">refresh_interval</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string unquoted plain out yaml">5m</span>
    <span class="string unquoted plain out yaml"><span class="entity name tag yaml">file</span></span><span class="punctuation separator key-value mapping yaml">:</span>
        <span class="string unquoted plain out yaml"><span class="entity name tag yaml">path</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string unquoted plain out yaml">/config/users_database.yml</span>
        <span class="string unquoted plain out yaml"><span class="entity name tag yaml">password</span></span><span class="punctuation separator key-value mapping yaml">:</span>
            <span class="string unquoted plain out yaml"><span class="entity name tag yaml">algorithm</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string unquoted plain out yaml">argon2id</span>
            <span class="string unquoted plain out yaml"><span class="entity name tag yaml">iterations</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="constant numeric integer yaml">1</span>
            <span class="string unquoted plain out yaml"><span class="entity name tag yaml">key_length</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="constant numeric integer yaml">32</span>
            <span class="string unquoted plain out yaml"><span class="entity name tag yaml">salt_length</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="constant numeric integer yaml">16</span>
            <span class="string unquoted plain out yaml"><span class="entity name tag yaml">memory</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="constant numeric integer yaml">1024</span>
            <span class="string unquoted plain out yaml"><span class="entity name tag yaml">parallelism</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="constant numeric integer yaml">8</span>

<span class="string unquoted plain out yaml"><span class="entity name tag yaml">access_control</span></span><span class="punctuation separator key-value mapping yaml">:</span>
    <span class="string unquoted plain out yaml"><span class="entity name tag yaml">default_policy</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string unquoted plain out yaml">deny</span>
    <span class="string unquoted plain out yaml"><span class="entity name tag yaml">rules</span></span><span class="punctuation separator key-value mapping yaml">:</span>
        <span class="punctuation definition block sequence item yaml">-</span> <span class="string unquoted plain out yaml"><span class="entity name tag yaml">domain</span></span><span class="punctuation separator key-value mapping yaml">:</span>
              <span class="punctuation definition block sequence item yaml">-</span> <span class="string quoted double yaml"><span class="punctuation definition string begin yaml">&quot;</span>auth.example.com<span class="punctuation definition string end yaml">&quot;</span></span>
          <span class="string unquoted plain out yaml"><span class="entity name tag yaml">policy</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string unquoted plain out yaml">bypass</span>
        <span class="punctuation definition block sequence item yaml">-</span> <span class="string unquoted plain out yaml"><span class="entity name tag yaml">domain</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string quoted double yaml"><span class="punctuation definition string begin yaml">&quot;</span>teddit.example.com<span class="punctuation definition string end yaml">&quot;</span></span>
          <span class="string unquoted plain out yaml"><span class="entity name tag yaml">policy</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string unquoted plain out yaml">one_factor</span>

<span class="string unquoted plain out yaml"><span class="entity name tag yaml">session</span></span><span class="punctuation separator key-value mapping yaml">:</span>
    <span class="string unquoted plain out yaml"><span class="entity name tag yaml">name</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string unquoted plain out yaml">authelia_session</span>
    <span class="string unquoted plain out yaml"><span class="entity name tag yaml">secret</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string unquoted plain out yaml">aiS5iedaiv6eeVaideeLeich5roo6ohvaf3Vee1a</span> <span class="comment line number-sign yaml"><span class="punctuation definition comment line number-sign yaml">#</span> pwgen 40 1
</span>    <span class="string unquoted plain out yaml"><span class="entity name tag yaml">expiration</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="constant numeric integer yaml">3600</span>
    <span class="string unquoted plain out yaml"><span class="entity name tag yaml">inactivity</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="constant numeric integer yaml">300</span>
    <span class="string unquoted plain out yaml"><span class="entity name tag yaml">domain</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string unquoted plain out yaml">example.com</span>

<span class="string unquoted plain out yaml"><span class="entity name tag yaml">regulation</span></span><span class="punctuation separator key-value mapping yaml">:</span>
    <span class="string unquoted plain out yaml"><span class="entity name tag yaml">max_retries</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="constant numeric integer yaml">5</span>
    <span class="string unquoted plain out yaml"><span class="entity name tag yaml">find_time</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string unquoted plain out yaml">10m</span>
    <span class="string unquoted plain out yaml"><span class="entity name tag yaml">ban_time</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string unquoted plain out yaml">12h</span>

<span class="string unquoted plain out yaml"><span class="entity name tag yaml">storage</span></span><span class="punctuation separator key-value mapping yaml">:</span>
    <span class="string unquoted plain out yaml"><span class="entity name tag yaml">local</span></span><span class="punctuation separator key-value mapping yaml">:</span>
        <span class="string unquoted plain out yaml"><span class="entity name tag yaml">path</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string unquoted plain out yaml">/config/db.sqlite3</span>
    <span class="string unquoted plain out yaml"><span class="entity name tag yaml">encryption_key</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string unquoted plain out yaml">aiS5iedaiv6eeVaideeLeich5roo6ohvaf3Vee1a</span> <span class="comment line number-sign yaml"><span class="punctuation definition comment line number-sign yaml">#</span> pwgen 40 1
</span>
<span class="string unquoted plain out yaml"><span class="entity name tag yaml">notifier</span></span><span class="punctuation separator key-value mapping yaml">:</span>
    <span class="string unquoted plain out yaml"><span class="entity name tag yaml">disable_startup_check</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="constant language boolean yaml">true</span>
    <span class="string unquoted plain out yaml"><span class="entity name tag yaml">smtp</span></span><span class="punctuation separator key-value mapping yaml">:</span>
        <span class="string unquoted plain out yaml"><span class="entity name tag yaml">username</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string unquoted plain out yaml">user@example.com</span>
        <span class="string unquoted plain out yaml"><span class="entity name tag yaml">password</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string unquoted plain out yaml">password</span>
        <span class="string unquoted plain out yaml"><span class="entity name tag yaml">host</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string unquoted plain out yaml">smtp.example.com</span>
        <span class="string unquoted plain out yaml"><span class="entity name tag yaml">port</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="constant numeric integer yaml">465</span>
        <span class="string unquoted plain out yaml"><span class="entity name tag yaml">sender</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string unquoted plain out yaml">user@example.com</span>
        <span class="string unquoted plain out yaml"><span class="entity name tag yaml">identifier</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string unquoted plain out yaml">example.com</span>
        <span class="string unquoted plain out yaml"><span class="entity name tag yaml">subject</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string quoted double yaml"><span class="punctuation definition string begin yaml">&quot;</span>[Authelia] {title}<span class="punctuation definition string end yaml">&quot;</span></span>
        <span class="string unquoted plain out yaml"><span class="entity name tag yaml">startup_check_address</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string unquoted plain out yaml">user@example.com</span>
        <span class="string unquoted plain out yaml"><span class="entity name tag yaml">disable_require_tls</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="constant language boolean yaml">false</span>
        <span class="string unquoted plain out yaml"><span class="entity name tag yaml">disable_html_emails</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="constant language boolean yaml">true</span>
        <span class="string unquoted plain out yaml"><span class="entity name tag yaml">tls</span></span><span class="punctuation separator key-value mapping yaml">:</span>
            <span class="string unquoted plain out yaml"><span class="entity name tag yaml">skip_verify</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="constant language boolean yaml">false</span>
            <span class="string unquoted plain out yaml"><span class="entity name tag yaml">minimum_version</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string unquoted plain out yaml">TLS1.2</span></span></code></pre>
<h3 id="authelia-users"><span class="section-number-3">3.3.</span> Authelia Users</h3>
<p>Next, create the users file for authentication.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> nano <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/authelia/config/users_database.yml</span></span></code></pre>
<p>Within the file, you will need to create an entry for each user that needs access to Authelia. The <code class="verbatim">my_username</code> entry will be the username used on the login page.</p>
<p>To generate the password, go to <a href="https://argon2.online">Argon2 Hash Generator</a>, generate a random salt, and make sure the rest of the settings match the <code class="verbatim">authentication_backend</code> section of <code class="verbatim">configuration.yml</code> file.</p>
<pre><code class="language-yaml highlight"><span class="source yaml"><span class="string unquoted plain out yaml"><span class="entity name tag yaml">users</span></span><span class="punctuation separator key-value mapping yaml">:</span>
    <span class="string unquoted plain out yaml"><span class="entity name tag yaml">my_username</span></span><span class="punctuation separator key-value mapping yaml">:</span>
        <span class="string unquoted plain out yaml"><span class="entity name tag yaml">displayname</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string quoted double yaml"><span class="punctuation definition string begin yaml">&quot;</span>My User<span class="punctuation definition string end yaml">&quot;</span></span>
        <span class="comment line number-sign yaml"><span class="punctuation definition comment line number-sign yaml">#</span> Generated at https://argon2.online/ -- match the settings in
</span>        <span class="comment line number-sign yaml"><span class="punctuation definition comment line number-sign yaml">#</span> the `authentication_backend` section of configuration.yml
</span>        <span class="string unquoted plain out yaml"><span class="entity name tag yaml">password</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string quoted double yaml"><span class="punctuation definition string begin yaml">&quot;</span><span class="punctuation definition string end yaml">&quot;</span></span>
        <span class="string unquoted plain out yaml"><span class="entity name tag yaml">email</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string unquoted plain out yaml">email@example.com</span>
        <span class="string unquoted plain out yaml"><span class="entity name tag yaml">groups</span></span><span class="punctuation separator key-value mapping yaml">:</span>
            <span class="punctuation definition block sequence item yaml">-</span> <span class="string unquoted plain out yaml">admins</span>
            <span class="punctuation definition block sequence item yaml">-</span> <span class="string unquoted plain out yaml">dev</span></span></code></pre>
<p>Once the app is configured, restart the container from scratch.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="support function cd shell">cd</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/authelia</span>
<span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> docker-compose down</span> <span class="keyword operator logical and shell">&amp;&amp;</span> <span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> docker-compose up<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>d</span></span></span></code></pre>
<h3 id="nginx-authelia-domain"><span class="section-number-3">3.4.</span> Nginx: Authelia Domain</h3>
<p>Once the container is running and configured, the final step is to configure external access to the server via Nginx reverse proxy.</p>
<p>Start by creating the Authelia domain.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> nano /etc/nginx/sites-available/auth</span></span></code></pre>
<p>Within this file, paste the following information and be sure to update <code class="verbatim">example.com</code> to your domain. Make sure the <code class="verbatim">$upstream_authelia</code> variable matches the location of your Authelia container.</p>
<pre><code class="language-conf">server {
    if ($host ~ ^[^.]+\.example\.com$) {
        return 301 https://$host$request_uri;
    }

    listen [::]:80;
    listen 80;
    server_name auth.example.com;
    return 404;
}

server {
    listen [::]:443 ssl http2;
    listen 443 ssl http2;
    server_name auth.example.com;
    access_log  /var/log/nginx/auth.access.log;
    error_log   /var/log/nginx/auth.error.log;

    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
    include /etc/letsencrypt/options-ssl-nginx.conf;
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;

    location / {
        set $upstream_authelia http://127.0.0.1:9091;
        proxy_pass $upstream_authelia;
        client_body_buffer_size 128k;

        proxy_next_upstream error timeout invalid_header http_500 http_502 http_503;

        send_timeout 5m;
        proxy_read_timeout 360;
        proxy_send_timeout 360;
        proxy_connect_timeout 360;

        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Forwarded-Host $http_host;
        proxy_set_header X-Forwarded-Uri $request_uri;
        proxy_set_header X-Forwarded-Ssl on;
        proxy_redirect  http://  $scheme://;
        proxy_http_version 1.1;
        proxy_set_header Connection "";
        proxy_cache_bypass $cookie_session;
        proxy_no_cache $cookie_session;
        proxy_buffers 64 256k;
    }

}</code></pre>
<p>Next, symlink the file and restart Nginx. If there are errors, be sure to resolve those before moving on.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> ln<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>s</span> /etc/nginx/sites-available/auth /etc/nginx/sites-enabled/auth</span>
<span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> systemctl restart nginx.service</span></span></code></pre>
<h3 id="nginx-protected-domain-s"><span class="section-number-3">3.5.</span> Nginx: Protected Domain(s)</h3>
<p>Now that Authelia is accessible externally, you need to configure the domain you intend to protect with Authelia. In this example, I'm protecting <code class="verbatim">teddit.example.com</code>.</p>
<p>Similar to the process above, paste the content and update the relevant variables.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> nano /etc/nginx/sites-available/teddit</span></span></code></pre>
<pre><code class="language-conf">server {
    if ($host ~ ^[^.]+\.example\.com$) {
        return 301 https://$host$request_uri;
    }

    listen [::]:80;
    listen 80;
    server_name teddit.example.com;
    return 404;
}

server {
    listen [::]:443 ssl http2;
    listen 443 ssl http2;
    server_name teddit.example.com;
    access_log  /var/log/nginx/teddit.access.log;
    error_log   /var/log/nginx/teddit.error.log;

    add_header X-Content-Type-Options "nosniff";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Frame-Options "DENY";
    add_header Strict-Transport-Security "max-age=63072000; includeSubDomains";
    add_header Referrer-Policy "no-referrer";

    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
    include /etc/letsencrypt/options-ssl-nginx.conf;
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;

    location /authelia {
        internal;
        set $upstream_authelia http://127.0.0.1:9091/api/verify;
        proxy_pass_request_body off;
        proxy_pass $upstream_authelia;
        proxy_set_header Content-Length "";

        proxy_next_upstream error timeout invalid_header http_500 http_502 http_503;
        client_body_buffer_size 128k;
        proxy_set_header Host $host;
        proxy_set_header X-Original-URL $scheme://$http_host$request_uri;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Forwarded-Host $http_host;
        proxy_set_header X-Forwarded-Uri $request_uri;
        proxy_set_header X-Forwarded-Ssl on;
        proxy_redirect  http://  $scheme://;
        proxy_http_version 1.1;
        proxy_set_header Connection "";
        proxy_cache_bypass $cookie_session;
        proxy_no_cache $cookie_session;
        proxy_buffers 4 32k;

        send_timeout 5m;
        proxy_read_timeout 240;
        proxy_send_timeout 240;
        proxy_connect_timeout 240;
    }

    location / {
        set $upstream_teddit http://127.0.0.1:8686;
        proxy_pass $upstream_teddit;

        auth_request /authelia;
        auth_request_set $target_url https://$http_host$request_uri;
        auth_request_set $user $upstream_http_remote_user;
        auth_request_set $email $upstream_http_remote_email;
        auth_request_set $groups $upstream_http_remote_groups;
        proxy_set_header Remote-User $user;
        proxy_set_header Remote-Email $email;
        proxy_set_header Remote-Groups $groups;

        error_page 401 =302 https://auth.example.com/?rd=$target_url;

        client_body_buffer_size 128k;

        proxy_next_upstream error timeout invalid_header http_500 http_502 http_503;

        send_timeout 5m;
        proxy_read_timeout 360;
        proxy_send_timeout 360;
        proxy_connect_timeout 360;

        proxy_set_header Host $host;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection upgrade;
        proxy_set_header Accept-Encoding gzip;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Forwarded-Host $http_host;
        proxy_set_header X-Forwarded-Uri $request_uri;
        proxy_set_header X-Forwarded-Ssl on;
        proxy_redirect  http://  $scheme://;
        proxy_http_version 1.1;
        proxy_set_header Connection "";
        proxy_cache_bypass $cookie_session;
        proxy_no_cache $cookie_session;
        proxy_buffers 64 256k;
    }
}</code></pre>
<p>Same as before, symlink the file and restart Nginx.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> ln<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>s</span> /etc/nginx/sites-available/teddit /etc/nginx/sites-enabled/teddit</span>
<span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> systemctl restart nginx.service</span></span></code></pre>
<h2 id="results"><span class="section-number-2">4.</span> Results</h2>
<p>When visiting the protected domain, you will now be redirected to your authentication domain and presented with the Authelia login portal.</p>
<figure><img src="https://img.cleberg.net/blog/20231010-authelia/authelia_portal.webp" alt="A view of the Authelia login page, requiring a username and password."><figcaption><span class="figure-number">Figure 1: </span>Authelia Portal</figcaption></figure>
<p>Once you've successfully authenticated, you can visit your authentication domain directly and see that you're currently authenticated to any domain protected by Authelia.</p>
<figure><img src="https://img.cleberg.net/blog/20231010-authelia/authelia_success.webp" alt="A view of the success page when succesfully authenticated."><figcaption><span class="figure-number">Figure 2: </span>Authelia Success</figcaption></figure>
]]></description>
    </item>
    <item>
      <title>Digital Minimalism: Fewer Inputs, More Signal</title>
      <link>https://cleberg.net/blog/digital-minimalism.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/digital-minimalism.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Wed, 04 Oct 2023 00:00:00 +0000</pubDate>
      <category>linux</category>
      <category>privacy</category>
      <description><![CDATA[<p>I've written <a href="/garden/">a note about minimalism</a> before, but I wanted to dedicate some time to reflect on digital minimalism and how I've been able to minimize the impact of digital devices in my life.</p>
<blockquote>
<p>These changes crept up on us and happened fast, before we had a chance to step back and ask what we really wanted out of the rapid advances of the past decade. We added new technologies to the periphery of our experience for minor reasons, then woke one morning to discover that they had colonized the core of our daily life. We didn't, in other words, sign up for the digital world in which we're currently entrenched; we seem to have stumbled backward into it.</p>
<p><em>(Digital Minimalism, 2019)</em></p>
</blockquote>
<h2 id="the-principles-of-digital-minimalism"><span class="section-number-2">1.</span> The Principles of Digital Minimalism</h2>
<p>As noted in Cal Newport's book, <em>Digital Minimalism</em>, there are three main principles to digital minimalism that I tend to agree with:</p>
<ol>
<li>Clutter is costly.<ul>
<li>Digital minimalists recognize that cluttering their time and attention with too many devices, apps, and services creates an overall negative cost that can swamp the small benefits that each individual item provides in isolation.</li>
</ul>
</li>
<li>Optimization is important.<ul>
<li>Digital minimalists believe that deciding a particular technology supports something they value is only the first step. To truly extract its full potential benefit, it's necessary to think carefully about how they'll use the technology.</li>
</ul>
</li>
<li>Intentionality is satisfying.<ul>
<li>Digital minimalists derive significant satisfaction from their general commitment to being more intentional about how they engage with new technologies. This source of satisfaction is independent of the specific decisions they make and is one of the biggest reasons that minimalism tends to be immensely meaningful to its practitioners.</li>
</ul>
</li>
</ol>
<h2 id="taking-action"><span class="section-number-2">2.</span> Taking Action</h2>
<p>In order to put the logic into practice, I've created a few new habits and continued performing old habits that are working well:</p>
<h3 id="using-devices-with-intention"><span class="section-number-3">2.1.</span> Using Devices With Intention</h3>
<ul>
<li>I already rarely use "social media", mostly limited to forums such as Hacker News and Tildes, so I've just tweaked my behavior to stop looking for content in those places when I'm bored.</li>
<li>Use devices with intention. Each time I pick up a digital device, there should be an intention to use the device to improve my current situation. No more endless scrolling or searching for something to interest me.</li>
</ul>
<h3 id="prevent-distractions"><span class="section-number-3">2.2.</span> Prevent Distractions</h3>
<ul>
<li>Disable (most) notifications on all devices. I spent 15-30 minutes going through the notifications on my phone, watch, and computer to ensure that only a select few apps have the ability to interrupt me: Calendar, Messages, Phone, Reminders, &amp; Signal.</li>
<li>Disable badges for any apps except the ones mentioned in the bullet above.</li>
<li>Set-up focus profiles across devices so that I can enable different modes, such as Personal when I only want to see notifications from people I care about or Do Not Disturb, where absolutely nothing can interrupt me.</li>
<li>Clean up my home screens. This one was quite easy as I already maintain a minimalist set-up, but I went extreme by limiting my phone to just eight apps on the home screen and four in the dock. If I need another app, I'll have to search or use the app library.</li>
<li>Remove the work profile from my phone. This was a tough decision as having my work profile on my device definitely makes my life easier at times, but it also has quite a negative effect when I'm "always online" and can see the notifications and team activity 24/7. I believe creating a distinct barrier between my work and personal devices will be beneficial in the end.</li>
</ul>
<h3 id="creating-alternative-activities"><span class="section-number-3">2.3.</span> Creating Alternative Activities</h3>
<p>This is the most difficult piece, as most of my hobbies and interests lie in the digital world. However, I'm making a concerted effort to put devices down unless necessary and force myself to perform other activities in the physical world instead.</p>
<p>I've started with a few basics that are always readily available to me:</p>
<ul>
<li>Do a chore, such as organizing or cleaning.</li>
<li>Read a book, study a piece of art, etc.</li>
<li>Exercise or get outdoors.</li>
<li>Participate in a hobby, such as photography, birding, disc golf, etc.</li>
<li>Let yourself be bored and wander into creativity.</li>
</ul>
<h2 id="making-progress"><span class="section-number-2">3.</span> Making Progress</h2>
<p>I'll be taking notes as I continue down this journey and hope to see positive trends. I've always been a minimalist in the physical world and it feels refreshing to filter out the clutter that has come to dominate my digital life over the years.</p>
<p>I'm excited to see where this journey leads.</p>
]]></description>
    </item>
    <item>
      <title>SQL Scripts for Auditing User Privileges</title>
      <link>https://cleberg.net/blog/audit-sql-scripts.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/audit-sql-scripts.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Tue, 19 Sep 2023 00:00:00 +0000</pubDate>
      <category>audit</category>
      <description><![CDATA[<h2 id="overview"><span class="section-number-2">1.</span> Overview</h2>
<p>When you have to scope a database into your engagement, you may be curious how to best extract the information from the database. While there are numerous different methods to extract this type of information, I'm going to show an example of how to gather all users and privileges from three main database types: Oracle, Microsoft SQL, and MySQL.</p>
<h2 id="oracle"><span class="section-number-2">2.</span> Oracle</h2>
<p>You can use the following SQL script to see all users and their privileges in an Oracle database:</p>
<pre><code class="language-sql highlight"><span class="source sql"><span class="keyword other DML sql">SELECT</span>
    grantee <span class="keyword other alias sql">AS</span> <span class="string quoted double sql"><span class="punctuation definition string begin sql">&quot;</span>User<span class="punctuation definition string end sql">&quot;</span></span>,
    privilege <span class="keyword other alias sql">AS</span> <span class="string quoted double sql"><span class="punctuation definition string begin sql">&quot;</span>Privilege<span class="punctuation definition string end sql">&quot;</span></span>
<span class="keyword other DML sql">FROM</span>
    dba_sys_privs
<span class="keyword other DML sql">WHERE</span>
    grantee <span class="keyword other data-integrity sql">IN</span> (<span class="keyword other DML sql">SELECT DISTINCT</span> grantee <span class="keyword other DML sql">FROM</span> dba_sys_privs)
<span class="keyword other DML sql">UNION ALL</span>
<span class="keyword other DML sql">SELECT</span>
    grantee <span class="keyword other alias sql">AS</span> <span class="string quoted double sql"><span class="punctuation definition string begin sql">&quot;</span>User<span class="punctuation definition string end sql">&quot;</span></span>,
    privilege <span class="keyword other alias sql">AS</span> <span class="string quoted double sql"><span class="punctuation definition string begin sql">&quot;</span>Privilege<span class="punctuation definition string end sql">&quot;</span></span>
<span class="keyword other DML sql">FROM</span>
    dba_tab_privs
<span class="keyword other DML sql">WHERE</span>
    grantee <span class="keyword other data-integrity sql">IN</span> (<span class="keyword other DML sql">SELECT DISTINCT</span> grantee <span class="keyword other DML sql">FROM</span> dba_tab_privs);</span></code></pre>
<p>This script queries the <code class="verbatim">dba_sys_privs</code> and <code class="verbatim">dba_tab_privs</code> views to retrieve system and table-level privileges respectively. It then combines the results using <code class="verbatim">UNION ALL</code> to show all users and their associated privileges. Please note that this method does not extract information from the <code class="verbatim">dba_role_privs</code> table - use the method below for that data.</p>
<p>Please note that you might need appropriate privileges (e.g., DBA privileges) to access these views, and you should exercise caution when querying system tables in a production Oracle database.</p>
<h3 id="alternative-oracle-query"><span class="section-number-3">2.1.</span> Alternative Oracle Query</h3>
<p>You can also extract each table's information separately and perform processing outside the database to explore and determine the information necessary for the audit:</p>
<pre><code class="language-sql highlight"><span class="source sql"><span class="keyword other DML sql">SELECT</span> <span class="keyword operator star sql">*</span><span class="keyword operator star sql">*</span> <span class="keyword other DML sql">FROM</span> <span class="constant other database-name sql">sys</span>.<span class="constant other table-name sql">dba_role_privs</span>;
<span class="keyword other DML sql">SELECT</span> <span class="keyword operator star sql">*</span><span class="keyword operator star sql">*</span> <span class="keyword other DML sql">FROM</span> <span class="constant other database-name sql">sys</span>.<span class="constant other table-name sql">dba_sys_privs</span>;
<span class="keyword other DML sql">SELECT</span> <span class="keyword operator star sql">*</span><span class="keyword operator star sql">*</span> <span class="keyword other DML sql">FROM</span> <span class="constant other database-name sql">sys</span>.<span class="constant other table-name sql">dba_tab_privs</span>;
<span class="keyword other DML sql">SELECT</span> <span class="keyword operator star sql">*</span><span class="keyword operator star sql">*</span> <span class="keyword other DML sql">FROM</span> <span class="constant other database-name sql">sys</span>.<span class="constant other table-name sql">dba_users</span>;</span></code></pre>
<h2 id="microsoft-sql"><span class="section-number-2">3.</span> Microsoft SQL</h2>
<p>You can use the following SQL script to see all users and their privileges in a Microsoft SQL Server database (<a href="https://stackoverflow.com/a/30040784">source</a>):</p>
<pre><code class="language-sql highlight"><span class="source sql"><span class="comment block c"><span class="punctuation definition comment sql">/*</span>
Security Audit Report
1) List all access provisioned to a sql user or windows user/group directly
2) List all access provisioned to a sql user or windows user/group through a database or application role
3) List all access provisioned to the public role

Columns Returned:
UserName        : SQL or Windows/Active Directory user account.  This could also be an Active Directory group.
UserType        : Value will be either &#39;SQL User&#39; or &#39;Windows User&#39;.  This reflects the type of user defined for the
                  SQL Server user account.
DatabaseUserName: Name of the associated user as defined in the database user account.  The database user may not be the
                  same as the server user.
Role            : The role name.  This will be null if the associated permissions to the object are defined at directly
                  on the user account, otherwise this will be the name of the role that the user is a member of.
PermissionType  : Type of permissions the user/role has on an object. Examples could include CONNECT, EXECUTE, SELECT
                  DELETE, INSERT, ALTER, CONTROL, TAKE OWNERSHIP, VIEW DEFINITION, etc.
                  This value may not be populated for all roles.  Some built in roles have implicit permission
                  definitions.
PermissionState : Reflects the state of the permission type, examples could include GRANT, DENY, etc.
                  This value may not be populated for all roles.  Some built in roles have implicit permission
                  definitions.
ObjectType      : Type of object the user/role is assigned permissions on.  Examples could include USER_TABLE,
                  SQL_SCALAR_FUNCTION, SQL_INLINE_TABLE_VALUED_FUNCTION, SQL_STORED_PROCEDURE, VIEW, etc.
                  This value may not be populated for all roles.  Some built in roles have implicit permission
                  definitions.
ObjectName      : Name of the object that the user/role is assigned permissions on.
                  This value may not be populated for all roles.  Some built in roles have implicit permission
                  definitions.
ColumnName      : Name of the column of the object that the user/role is assigned permissions on. This value
                  is only populated if the object is a table, view or a table value function.
*/</span>

<span class="comment line double-dash sql"><span class="punctuation definition comment sql">--</span>List all access provisioned to a sql user or windows user/group directly
</span><span class="keyword other DML sql">SELECT</span>
    [UserName] <span class="keyword operator comparison sql">=</span> <span class="keyword other DML sql">CASE</span> princ.[type]
                    <span class="keyword other DML sql">WHEN</span> <span class="string quoted single sql"><span class="punctuation definition string begin sql">&#39;</span>S<span class="punctuation definition string end sql">&#39;</span></span> <span class="keyword other DML sql">THEN</span> princ.[name]
                    <span class="keyword other DML sql">WHEN</span> <span class="string quoted single sql"><span class="punctuation definition string begin sql">&#39;</span>U<span class="punctuation definition string end sql">&#39;</span></span> <span class="keyword other DML sql">THEN</span> ulogin.[name] COLLATE Latin1_General_CI_AI
                 <span class="keyword other DML sql">END</span>,
    [UserType] <span class="keyword operator comparison sql">=</span> <span class="keyword other DML sql">CASE</span> princ.[type]
                    <span class="keyword other DML sql">WHEN</span> <span class="string quoted single sql"><span class="punctuation definition string begin sql">&#39;</span>S<span class="punctuation definition string end sql">&#39;</span></span> <span class="keyword other DML sql">THEN</span> <span class="string quoted single sql"><span class="punctuation definition string begin sql">&#39;</span>SQL User<span class="punctuation definition string end sql">&#39;</span></span>
                    <span class="keyword other DML sql">WHEN</span> <span class="string quoted single sql"><span class="punctuation definition string begin sql">&#39;</span>U<span class="punctuation definition string end sql">&#39;</span></span> <span class="keyword other DML sql">THEN</span> <span class="string quoted single sql"><span class="punctuation definition string begin sql">&#39;</span>Windows User<span class="punctuation definition string end sql">&#39;</span></span>
                 <span class="keyword other DML sql">END</span>,
    [DatabaseUserName] <span class="keyword operator comparison sql">=</span> princ.[name],
    [Role] <span class="keyword operator comparison sql">=</span> <span class="keyword other DDL create II sql">null</span>,
    [PermissionType] <span class="keyword operator comparison sql">=</span> perm.[permission_name],
    [PermissionState] <span class="keyword operator comparison sql">=</span> perm.[state_desc],
    [ObjectType] <span class="keyword operator comparison sql">=</span> <span class="constant other database-name sql">obj</span>.<span class="constant other table-name sql">type_desc</span>,<span class="comment line double-dash sql"><span class="punctuation definition comment sql">--</span>perm.[class_desc],
</span>    [ObjectName] <span class="keyword operator comparison sql">=</span> OBJECT_NAME(<span class="constant other database-name sql">perm</span>.<span class="constant other table-name sql">major_id</span>),
    [ColumnName] <span class="keyword operator comparison sql">=</span> col.[name]
<span class="keyword other DML sql">FROM</span>
    <span class="comment line double-dash sql"><span class="punctuation definition comment sql">--</span>database user
</span>    <span class="constant other database-name sql">sys</span>.<span class="constant other table-name sql">database_principals</span> princ
<span class="keyword other DML sql">LEFT JOIN</span>
    <span class="comment line double-dash sql"><span class="punctuation definition comment sql">--</span>Login accounts
</span>    <span class="constant other database-name sql">sys</span>.<span class="constant other table-name sql">login_token</span> ulogin <span class="keyword other DDL create II sql">on</span> princ.[sid] <span class="keyword operator comparison sql">=</span> ulogin.[sid]
<span class="keyword other DML sql">LEFT JOIN</span>
    <span class="comment line double-dash sql"><span class="punctuation definition comment sql">--</span>Permissions
</span>    <span class="constant other database-name sql">sys</span>.<span class="constant other table-name sql">database_permissions</span> perm <span class="keyword other DDL create II sql">ON</span> perm.[grantee_principal_id] <span class="keyword operator comparison sql">=</span> princ.[principal_id]
<span class="keyword other DML sql">LEFT JOIN</span>
    <span class="comment line double-dash sql"><span class="punctuation definition comment sql">--</span>Table columns
</span>    <span class="constant other database-name sql">sys</span>.<span class="constant other table-name sql">columns</span> col <span class="keyword other DDL create II sql">ON</span> col.[object_id] <span class="keyword operator comparison sql">=</span> <span class="constant other database-name sql">perm</span>.<span class="constant other table-name sql">major_id</span>
                    <span class="keyword other DML sql">AND</span> col.[column_id] <span class="keyword operator comparison sql">=</span> perm.[minor_id]
<span class="keyword other DML sql">LEFT JOIN</span>
    <span class="constant other database-name sql">sys</span>.<span class="constant other table-name sql">objects</span> obj <span class="keyword other DDL create II sql">ON</span> perm.[major_id] <span class="keyword operator comparison sql">=</span> obj.[object_id]
<span class="keyword other DML sql">WHERE</span>
    princ.[type] <span class="keyword other data-integrity sql">in</span> (<span class="string quoted single sql"><span class="punctuation definition string begin sql">&#39;</span>S<span class="punctuation definition string end sql">&#39;</span></span>,<span class="string quoted single sql"><span class="punctuation definition string begin sql">&#39;</span>U<span class="punctuation definition string end sql">&#39;</span></span>)
<span class="keyword other DML sql">UNION</span>
<span class="comment line double-dash sql"><span class="punctuation definition comment sql">--</span>List all access provisioned to a sql user or windows user/group through a database or application role
</span><span class="keyword other DML sql">SELECT</span>
    [UserName] <span class="keyword operator comparison sql">=</span> <span class="keyword other DML sql">CASE</span> memberprinc.[type]
                    <span class="keyword other DML sql">WHEN</span> <span class="string quoted single sql"><span class="punctuation definition string begin sql">&#39;</span>S<span class="punctuation definition string end sql">&#39;</span></span> <span class="keyword other DML sql">THEN</span> memberprinc.[name]
                    <span class="keyword other DML sql">WHEN</span> <span class="string quoted single sql"><span class="punctuation definition string begin sql">&#39;</span>U<span class="punctuation definition string end sql">&#39;</span></span> <span class="keyword other DML sql">THEN</span> ulogin.[name] COLLATE Latin1_General_CI_AI
                 <span class="keyword other DML sql">END</span>,
    [UserType] <span class="keyword operator comparison sql">=</span> <span class="keyword other DML sql">CASE</span> memberprinc.[type]
                    <span class="keyword other DML sql">WHEN</span> <span class="string quoted single sql"><span class="punctuation definition string begin sql">&#39;</span>S<span class="punctuation definition string end sql">&#39;</span></span> <span class="keyword other DML sql">THEN</span> <span class="string quoted single sql"><span class="punctuation definition string begin sql">&#39;</span>SQL User<span class="punctuation definition string end sql">&#39;</span></span>
                    <span class="keyword other DML sql">WHEN</span> <span class="string quoted single sql"><span class="punctuation definition string begin sql">&#39;</span>U<span class="punctuation definition string end sql">&#39;</span></span> <span class="keyword other DML sql">THEN</span> <span class="string quoted single sql"><span class="punctuation definition string begin sql">&#39;</span>Windows User<span class="punctuation definition string end sql">&#39;</span></span>
                 <span class="keyword other DML sql">END</span>,
    [DatabaseUserName] <span class="keyword operator comparison sql">=</span> memberprinc.[name],
    [Role] <span class="keyword operator comparison sql">=</span> roleprinc.[name],
    [PermissionType] <span class="keyword operator comparison sql">=</span> perm.[permission_name],
    [PermissionState] <span class="keyword operator comparison sql">=</span> perm.[state_desc],
    [ObjectType] <span class="keyword operator comparison sql">=</span> <span class="constant other database-name sql">obj</span>.<span class="constant other table-name sql">type_desc</span>,<span class="comment line double-dash sql"><span class="punctuation definition comment sql">--</span>perm.[class_desc],
</span>    [ObjectName] <span class="keyword operator comparison sql">=</span> OBJECT_NAME(<span class="constant other database-name sql">perm</span>.<span class="constant other table-name sql">major_id</span>),
    [ColumnName] <span class="keyword operator comparison sql">=</span> col.[name]
<span class="keyword other DML sql">FROM</span>
    <span class="comment line double-dash sql"><span class="punctuation definition comment sql">--</span>Role/member associations
</span>    <span class="constant other database-name sql">sys</span>.<span class="constant other table-name sql">database_role_members</span> members
<span class="keyword other DML sql">JOIN</span>
    <span class="comment line double-dash sql"><span class="punctuation definition comment sql">--</span>Roles
</span>    <span class="constant other database-name sql">sys</span>.<span class="constant other table-name sql">database_principals</span> roleprinc <span class="keyword other DDL create II sql">ON</span> roleprinc.[principal_id] <span class="keyword operator comparison sql">=</span> members.[role_principal_id]
<span class="keyword other DML sql">JOIN</span>
    <span class="comment line double-dash sql"><span class="punctuation definition comment sql">--</span>Role members (database users)
</span>    <span class="constant other database-name sql">sys</span>.<span class="constant other table-name sql">database_principals</span> memberprinc <span class="keyword other DDL create II sql">ON</span> memberprinc.[principal_id] <span class="keyword operator comparison sql">=</span> members.[member_principal_id]
<span class="keyword other DML sql">LEFT JOIN</span>
    <span class="comment line double-dash sql"><span class="punctuation definition comment sql">--</span>Login accounts
</span>    <span class="constant other database-name sql">sys</span>.<span class="constant other table-name sql">login_token</span> ulogin <span class="keyword other DDL create II sql">on</span> memberprinc.[sid] <span class="keyword operator comparison sql">=</span> ulogin.[sid]
<span class="keyword other DML sql">LEFT JOIN</span>
    <span class="comment line double-dash sql"><span class="punctuation definition comment sql">--</span>Permissions
</span>    <span class="constant other database-name sql">sys</span>.<span class="constant other table-name sql">database_permissions</span> perm <span class="keyword other DDL create II sql">ON</span> perm.[grantee_principal_id] <span class="keyword operator comparison sql">=</span> roleprinc.[principal_id]
<span class="keyword other DML sql">LEFT JOIN</span>
    <span class="comment line double-dash sql"><span class="punctuation definition comment sql">--</span>Table columns
</span>    <span class="constant other database-name sql">sys</span>.<span class="constant other table-name sql">columns</span> col <span class="keyword other DDL create II sql">on</span> col.[object_id] <span class="keyword operator comparison sql">=</span> <span class="constant other database-name sql">perm</span>.<span class="constant other table-name sql">major_id</span>
                    <span class="keyword other DML sql">AND</span> col.[column_id] <span class="keyword operator comparison sql">=</span> perm.[minor_id]
<span class="keyword other DML sql">LEFT JOIN</span>
    <span class="constant other database-name sql">sys</span>.<span class="constant other table-name sql">objects</span> obj <span class="keyword other DDL create II sql">ON</span> perm.[major_id] <span class="keyword operator comparison sql">=</span> obj.[object_id]
<span class="keyword other DML sql">UNION</span>
<span class="comment line double-dash sql"><span class="punctuation definition comment sql">--</span>List all access provisioned to the public role, which everyone gets by default
</span><span class="keyword other DML sql">SELECT</span>
    [UserName] <span class="keyword operator comparison sql">=</span> <span class="string quoted single sql"><span class="punctuation definition string begin sql">&#39;</span>{All Users}<span class="punctuation definition string end sql">&#39;</span></span>,
    [UserType] <span class="keyword operator comparison sql">=</span> <span class="string quoted single sql"><span class="punctuation definition string begin sql">&#39;</span>{All Users}<span class="punctuation definition string end sql">&#39;</span></span>,
    [DatabaseUserName] <span class="keyword operator comparison sql">=</span> <span class="string quoted single sql"><span class="punctuation definition string begin sql">&#39;</span>{All Users}<span class="punctuation definition string end sql">&#39;</span></span>,
    [Role] <span class="keyword operator comparison sql">=</span> roleprinc.[name],
    [PermissionType] <span class="keyword operator comparison sql">=</span> perm.[permission_name],
    [PermissionState] <span class="keyword operator comparison sql">=</span> perm.[state_desc],
    [ObjectType] <span class="keyword operator comparison sql">=</span> <span class="constant other database-name sql">obj</span>.<span class="constant other table-name sql">type_desc</span>,<span class="comment line double-dash sql"><span class="punctuation definition comment sql">--</span>perm.[class_desc],
</span>    [ObjectName] <span class="keyword operator comparison sql">=</span> OBJECT_NAME(<span class="constant other database-name sql">perm</span>.<span class="constant other table-name sql">major_id</span>),
    [ColumnName] <span class="keyword operator comparison sql">=</span> col.[name]
<span class="keyword other DML sql">FROM</span>
    <span class="comment line double-dash sql"><span class="punctuation definition comment sql">--</span>Roles
</span>    <span class="constant other database-name sql">sys</span>.<span class="constant other table-name sql">database_principals</span> roleprinc
<span class="keyword other DML sql">LEFT JOIN</span>
    <span class="comment line double-dash sql"><span class="punctuation definition comment sql">--</span>Role permissions
</span>    <span class="constant other database-name sql">sys</span>.<span class="constant other table-name sql">database_permissions</span> perm <span class="keyword other DDL create II sql">ON</span> perm.[grantee_principal_id] <span class="keyword operator comparison sql">=</span> roleprinc.[principal_id]
<span class="keyword other DML sql">LEFT JOIN</span>
    <span class="comment line double-dash sql"><span class="punctuation definition comment sql">--</span>Table columns
</span>    <span class="constant other database-name sql">sys</span>.<span class="constant other table-name sql">columns</span> col <span class="keyword other DDL create II sql">on</span> col.[object_id] <span class="keyword operator comparison sql">=</span> <span class="constant other database-name sql">perm</span>.<span class="constant other table-name sql">major_id</span>
                    <span class="keyword other DML sql">AND</span> col.[column_id] <span class="keyword operator comparison sql">=</span> perm.[minor_id]
<span class="keyword other DML sql">JOIN</span>
    <span class="comment line double-dash sql"><span class="punctuation definition comment sql">--</span>All objects
</span>    <span class="constant other database-name sql">sys</span>.<span class="constant other table-name sql">objects</span> obj <span class="keyword other DDL create II sql">ON</span> obj.[object_id] <span class="keyword operator comparison sql">=</span> perm.[major_id]
<span class="keyword other DML sql">WHERE</span>
    <span class="comment line double-dash sql"><span class="punctuation definition comment sql">--</span>Only roles
</span>    roleprinc.[type] <span class="keyword operator comparison sql">=</span> <span class="string quoted single sql"><span class="punctuation definition string begin sql">&#39;</span>R<span class="punctuation definition string end sql">&#39;</span></span> <span class="keyword other DML sql">AND</span>
    <span class="comment line double-dash sql"><span class="punctuation definition comment sql">--</span>Only public role
</span>    roleprinc.[name] <span class="keyword operator comparison sql">=</span> <span class="string quoted single sql"><span class="punctuation definition string begin sql">&#39;</span>public<span class="punctuation definition string end sql">&#39;</span></span> <span class="keyword other DML sql">AND</span>
    <span class="comment line double-dash sql"><span class="punctuation definition comment sql">--</span>Only objects of ours, not the MS objects
</span>    <span class="constant other database-name sql">obj</span>.<span class="constant other table-name sql">is_ms_shipped</span> <span class="keyword operator comparison sql">=</span> <span class="constant numeric sql">0</span>
<span class="keyword other DML sql">ORDER BY</span>
    princ.[Name],
    OBJECT_NAME(<span class="constant other database-name sql">perm</span>.<span class="constant other table-name sql">major_id</span>),
    col.[name],
    perm.[permission_name],
    perm.[state_desc],
    <span class="constant other database-name sql">obj</span>.<span class="constant other table-name sql">type_desc</span><span class="comment line double-dash sql"><span class="punctuation definition comment sql">--</span>perm.[class_desc]</span></span></code></pre>
<h2 id="mysql"><span class="section-number-2">4.</span> MySQL</h2>
<p>You can use the following SQL script to see all users and their privileges in a MySQL database:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">mysql</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>u</span> root<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>p</span></span></span></code></pre>
<p>Find all users and hosts with access to the database:</p>
<pre><code class="language-sql highlight"><span class="source sql"><span class="keyword other DML sql">SELECT</span> <span class="keyword operator star sql">*</span><span class="keyword operator star sql">*</span> <span class="keyword other DML sql">FROM</span> <span class="constant other database-name sql">information_schema</span>.<span class="constant other table-name sql">user_privileges</span>;</span></code></pre>
<p>This script retrieves user information and their associated database-level privileges from the <code class="verbatim">information_schema.user_privileges</code> table in MySQL. It lists various privileges such as SELECT, INSERT, UPDATE, DELETE, CREATE, and more for each user and database combination.</p>
<p>Please note that you may need appropriate privileges (e.g., <code class="verbatim">SELECT</code> privileges on <code class="verbatim">information_schema.user_privileges</code>) to access this information in a MySQL database. Additionally, some privileges like GRANT OPTION, EXECUTE, EVENT, and TRIGGER may not be relevant for all users and databases.</p>
<h3 id="alternative-mysql-query"><span class="section-number-3">4.1.</span> Alternative MySQL Query</h3>
<p>You can also grab individual sets of data from MySQL if you prefer to join them after extraction. I have marked the queries below with <code class="verbatim">SELECT ...</code> and excluded most <code class="verbatim">WHERE</code> clauses for brevity. You should determine the relevant privileges in-scope and query for those privileges to reduce the length of time to query.</p>
<pre><code class="language-sql highlight"><span class="source sql"><span class="comment line double-dash sql"><span class="punctuation definition comment sql">--</span> Global Permissions
</span><span class="keyword other DML sql">SELECT</span> ... <span class="keyword other DML sql">FROM</span> <span class="constant other database-name sql">mysql</span>.<span class="constant other table-name sql">user</span>;

<span class="comment line double-dash sql"><span class="punctuation definition comment sql">--</span> Database Permissions
</span><span class="keyword other DML sql">SELECT</span> ... <span class="keyword other DML sql">FROM</span> <span class="constant other database-name sql">mysql</span>.<span class="constant other table-name sql">db</span>
<span class="keyword other DML sql">WHERE</span> db <span class="keyword operator comparison sql">=</span> @db_name;

<span class="comment line double-dash sql"><span class="punctuation definition comment sql">--</span> Table Permissions
</span><span class="keyword other DML sql">SELECT</span> ... <span class="keyword other DML sql">FROM</span> <span class="constant other database-name sql">mysql</span>.<span class="constant other table-name sql">tables</span>
<span class="keyword other DML sql">WHERE</span> db <span class="keyword operator comparison sql">=</span> @db_name;

<span class="comment line double-dash sql"><span class="punctuation definition comment sql">--</span> Column Permissions
</span><span class="keyword other DML sql">SELECT</span> ... <span class="keyword other DML sql">FROM</span> <span class="constant other database-name sql">mysql</span>.<span class="constant other table-name sql">columns_priv</span>
<span class="keyword other DML sql">WHERE</span> db <span class="keyword operator comparison sql">=</span> @db_name;

<span class="comment line double-dash sql"><span class="punctuation definition comment sql">--</span> Password Configuration
</span>SHOW GLOBAL VARIABLES <span class="keyword other DML sql">LIKE</span> <span class="string quoted single sql"><span class="punctuation definition string begin sql">&#39;</span>validate_password%<span class="punctuation definition string end sql">&#39;</span></span>;
SHOW VARIABLES <span class="keyword other DML sql">LIKE</span> <span class="string quoted single sql"><span class="punctuation definition string begin sql">&#39;</span>validate_password%<span class="punctuation definition string end sql">&#39;</span></span>;</span></code></pre>
]]></description>
    </item>
    <item>
      <title>Self-Hosting Guide: GitWeb</title>
      <link>https://cleberg.net/blog/self-hosting-gitweb.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/self-hosting-gitweb.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Fri, 15 Sep 2023 00:00:00 +0000</pubDate>
      <category>linux</category>
      <category>self-hosting</category>
      <description><![CDATA[<h2 id="overview"><span class="section-number-2">1.</span> Overview</h2>
<p><a href="https://git-scm.com/book/en/v2/Git-on-the-Server-GitWeb">GitWeb</a> is a simple web-based visualizer for git repositories. By default, GitWeb will only run with the <code class="verbatim">lighttpd</code> or <code class="verbatim">webrick</code> web servers.</p>
<p>However, this guide will show you how to keep GitWeb running in the background and display information for all repositories in a chosen directory.</p>
<h2 id="install-dependencies"><span class="section-number-2">2.</span> Install Dependencies</h2>
<p>To start, you'll need install the following packages:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> apt install git gitweb fcgiwrap nginx</span></span></code></pre>
<h2 id="configure-nginx"><span class="section-number-2">3.</span> Configure Nginx</h2>
<p>Once installed, create an Nginx configuration file.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> nano /etc/nginx/sites-available/git.example.com</span></span></code></pre>
<pre><code class="language-conf">server {
        listen 80;
        server_name example.com;

        location /index.cgi {
                root /usr/share/gitweb/;
                include fastcgi_params;
                gzip off;
                fastcgi_param SCRIPT_NAME $uri;
                fastcgi_param GITWEB_CONFIG /etc/gitweb.conf;
                fastcgi_pass  unix:/var/run/fcgiwrap.socket;
        }

        location / {
                root /usr/share/gitweb/;
                index index.cgi;
        }
}</code></pre>
<p>To make the configuration active, you need to symlink it and then restart Nginx.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> ln<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>s</span> /etc/nginx/sites-available/git.example.com /etc/nginx/sites-enabled/git.example.com</span>
<span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> systemctl restart nginx.service</span></span></code></pre>
<p>The GitWeb application should now be available via the URL you set in the Nginx configuration above.</p>
<h2 id="customize-gitweb"><span class="section-number-2">4.</span> Customize GitWeb</h2>
<p>If you need to, you can customize many things about Gitweb by editing the <a href="https://git-scm.com/docs/gitweb.conf">gitweb.conf</a> file.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> nano /etc/gitweb.conf</span></span></code></pre>
]]></description>
    </item>
    <item>
      <title>Agile Auditing</title>
      <link>https://cleberg.net/blog/agile-auditing.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/agile-auditing.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Fri, 18 Aug 2023 00:00:00 +0000</pubDate>
      <category>audit</category>
      <description><![CDATA[<h2 id="what-is-agile-auditing"><span class="section-number-2">1.</span> What is Agile Auditing?</h2>
<p><a href="https://en.wikipedia.org/wiki/Agile_software_development">Agile</a>, the collaborative philosophy behind many software development methods, has been picking up steam as a beneficial tool to use in the external and internal auditing world.</p>
<p>This blog post will walk through commonly used terms within Agile, Scrum, and Kanban in order to translate these terms and roles into audit-specific terms.</p>
<p>Whether your team is in charge of a financial statement audit, an attestation (SOC 1, SOC 2, etc.), or a unique internal audit, the terms used throughout this post should still apply.</p>
<h2 id="agile"><span class="section-number-2">2.</span> Agile</h2>
<p>To start, I'll take a look at Agile.</p>
<blockquote>
<p>The Agile methodology is a project management approach that involves breaking the project into phases and emphasizes continuous collaboration and improvement. Teams follow a cycle of planning, executing, and evaluating.</p>
</blockquote>
<p>While this approach may seem familiar to what audit teams have historically done, an audit team must make distinct changes in their mentality and how they approach and manage a project.</p>
<h3 id="agile-values"><span class="section-number-3">2.1.</span> Agile Values</h3>
<p>The Agile Manifesto, written in 2001 at a summit in Utah, contain a set of four main values that comprise the Agile approach:</p>
<ol>
<li>Individuals and interactions over processes and tools.</li>
<li>Working software over comprehensive documentation.</li>
<li>Customer collaboration over contract negotiation.</li>
<li>Responding to change over following a plan.</li>
</ol>
<p>Beyond the four values, <a href="https://agilemanifesto.org/principles.html">twelve principles</a> were also written as part of the summit.</p>
<p>In order to relate these values to an audit or attestation engagement, we need to shift the focus from software development to the main goal of an engagement: completing sufficient audit testing to address to relevant risks over the processes and controls at hand.</p>
<p>Audit Examples:</p>
<ul>
<li>Engagement teams must value the team members, client contacts, and their interactions over the historical processes and tools that have been used.</li>
<li>Engagement teams must value a final report that contains sufficient audit documentation over excessive documentation or scope creep.</li>
<li>Engagement teams must collaborate with the audit clients as much as feasible to ensure that both sides are constantly updated with current knowledge of the engagement's status and any potential findings, rather than waiting for pre-set meetings or the end of the engagement to communicate.</li>
<li>Engagement teams must be able to respond to change in an engagement's schedule, scope, or environment to ensure that the project is completed in a timely manner and that all relevant areas are tested.<ul>
<li>In terms of an audit department's portfolio, they must be able to respond to changes in their company's or client's environment and be able to dynamically change their audit plan accordingly.</li>
</ul>
</li>
</ul>
<h2 id="scrum"><span class="section-number-2">3.</span> Scrum</h2>
<p>The above section discusses the high-level details of the Agile philosophy and how an audit team can potentially mold that mindset into the audit world, but how does a team implement these ideas?</p>
<p>There are many methods that use an Agile mindset, but I prefer <a href="https://en.wikipedia.org/wiki/Scrum_(software_development)">Scrum</a>. Scrum is a framework based on Agile that enables a team to work through a project through a series of roles, ceremonies, artifacts, and values.</p>
<p>Let's dive into each of these individually.</p>
<h3 id="scrum-team"><span class="section-number-3">3.1.</span> Scrum Team</h3>
<p>A scrum project is only as good as the team running the project. Standard scrum teams are separated into three distinct areas:</p>
<ol>
<li><strong>Product Owner (Client Contact)</strong>: The client contact is the audit equivalent of the product owner in Scrum. They are responsible for partnering with the engagement or audit team to ensure progress is being made, priorities are established, and clear guidance is given when questions or findings arise within each sprint.</li>
<li><strong>Scrum Master (Engagement Lead)</strong>: The engagement or audit team lead is responsible for coaching the team and the client contact on the scrum process, tracking team progress against plan, scheduling necessary resources, and helping remove obstacles.</li>
<li><strong>Scrum Developers (Engagement Members)</strong>: The engagement or audit team is the set of team members responsible for getting the work done. These team members will work on each task, report progress, resolve obstacles, and collaborate with other team members and the client contact to ensure goals are being met.</li>
</ol>
<h3 id="scrum-ceremonies"><span class="section-number-3">3.2.</span> Scrum Ceremonies</h3>
<p>Scrum ceremonies are events that are performed on a regular basis.</p>
<ol>
<li><strong>Sprint Planning</strong>: The team works together to plan the upcoming sprint goal and which user stories (tasks) will be added to the sprint to achieve that goal.</li>
<li><strong>Sprint</strong>: The time period, typically at least one week and no more than one month in length, where the team works on the stories and anything in the backlog.</li>
<li><strong>Daily Scrum</strong>: A very short meeting held each day, typically 15 minutes, to quickly emphasize alignment on the sprint goal and plan the next 24 hours. Each team member may share what they did the day before, what they'll do today, and any obstacles to their work.</li>
<li><strong>Sprint Review</strong>: At the end of each sprint, the team will gather and discuss the progress, obstacles, and backlog from the previous sprint.</li>
<li><strong>Sprint Retrospective</strong>: More specific than the sprint review, the retrospective is meant to discuss what worked and what did not work during the sprint. This may be processes, tools, people, or even things related to the Scrum ceremonies.</li>
</ol>
<p>One additional ceremony that may be applicable is organizing the backlog. This is typically the responsibility of the engagement leader and is meant to prioritize and clarify what needs to be done to complete items in the backlog.</p>
<h3 id="artifacts"><span class="section-number-3">3.3.</span> Artifacts</h3>
<p>While artifacts are generally not customizable in the audit world (i.e., each control test must include some kind of working paper with evidence supporting the test results), I wanted to include some quick notes on associating scrum artifact terms with an audit.</p>
<ol>
<li><strong>Product Backlog</strong>: This is the overall backlog of unfinished audit tasks from all prior sprints.</li>
<li><strong>Sprint Backlog</strong>: This is the backlog of unfinished audit tasks from one individual sprint.</li>
<li><strong>Increment</strong>: This is the output of each sprint - generally this is best thought of as any documentation prepared during the sprint, such as risk assessments, control working papers, deficiency analysis, etc.</li>
</ol>
<h2 id="kanban"><span class="section-number-2">4.</span> Kanban</h2>
<p>Last but not least, Kanban is a methodology that relies on boards to categorize work into distinct, descriptive categories that allow an agile or scrum team to effectively plan the work of a sprint or project.</p>
<p>See Atlassian's <a href="https://www.atlassian.com/agile/kanban">Kanban</a> page for more information.</p>
]]></description>
    </item>
    <item>
      <title>Plex Transcoder Errors: Subtitle Fix</title>
      <link>https://cleberg.net/blog/plex-transcoder-errors.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/plex-transcoder-errors.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Wed, 19 Jul 2023 00:00:00 +0000</pubDate>
      <category>linux</category>
      <category>self-hosting</category>
      <description><![CDATA[<h2 id="plex-transcoder-error"><span class="section-number-2">1.</span> Plex Transcoder Error</h2>
<p>Occasionally, you may see an error in your Plex client that references a failure with the transcoder conversion process. The specific error wording is:</p>
<pre><code class="language-txt highlight"><span class="text plain">Conversion failed. The transcoder failed to start up.</span></code></pre>
<h2 id="debugging-the-cause"><span class="section-number-2">2.</span> Debugging the Cause</h2>
<p>In order to get a better look at what is causing the error, I'm going to observe the Plex console while the error occurs. To do this, open the Plex web client, go to <code class="verbatim">Settings</code> &gt; <code class="verbatim">Manage</code> &gt; <code class="verbatim">Console</code>. Now, try to play the title again and watch to see which errors occur.</p>
<p>In my case, you can see the errors below are related to a subtitle file (<code class="verbatim">.srt</code>) causing the transcoder to crash.</p>
<pre><code class="language-txt highlight"><span class="text plain">Jul 19, 2023 16:49:34.945 [140184571120440] Error — Couldn&#39;t find the file to stream: /movies/Movie Title (2021)/Movie Title (2021).srt
Jul 19, 2023 16:49:34.947 [140184532732728] Error — [Req#7611/Transcode/42935159-67C1-4192-9336-DDC6F7BC9330] Error configuring transcoder: TPU: Failed to download sub-stream to temporary file
Jul 19, 2023 16:49:35.225 [140184532732728] Warning — [Req#760d/Transcode] Got a request to stop a transcode session without a valid session GUID.
Jul 19, 2023 16:49:45.561 [140184532732728] Info — [Req#7648] AutoUpdate: no updates available
Jul 19, 2023 16:51:23.402 [140184510081848] Info — Library section 1 (Movies) will be updated because of a change in &quot;/movies/Movie Title (2021)/Movie Title (2021).srt&quot;</span></code></pre>
<h2 id="solving-the-error"><span class="section-number-2">3.</span> Solving the Error</h2>
<p>In my case, I simply removed the subtitle file because it was not critical to keep. You may also avoid this by turning off subtitles if you don't want to delete the file.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">rm</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>rf</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>/movies/Movie Title (2021)/Movie Title (2021).srt<span class="punctuation definition string end shell">&quot;</span></span></span></span></code></pre>
<p>Once the subtitle is removed from the directory or subtitles are turned off, try to play the title again. At this point, it should play without error. If not, reopen or refresh your Plex client and the Plex server:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> systemctl restart plexmediaserver.service</span></span></code></pre>
<h2 id="related-discussion"><span class="section-number-2">4.</span> Related Discussion</h2>
<p>Looking at <a href="https://forums.plex.tv/t/subtitles-crashing-plex-transcoder-samsung-q80-tv-with-or-without-hardware-transcode/741441/2">a related Plex forum post</a>, it seems that <code class="verbatim">.srt</code> subtitles are the core issue here. However, Plex does not seem to have a resolution that fixes these errors.</p>
<p>Unfortunately, I would suggest converting subtitle formats, burning the subtitles into the title, or simply removing subtitles when they cause crashes.</p>
]]></description>
    </item>
    <item>
      <title>Mullvad WireGuard with LAN Access</title>
      <link>https://cleberg.net/blog/wireguard-lan.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/wireguard-lan.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Wed, 12 Jul 2023 00:00:00 +0000</pubDate>
      <category>security</category>
      <category>self-hosting</category>
      <description><![CDATA[<h2 id="download-configuration-files-from-mullvad"><span class="section-number-2">1.</span> Download Configuration Files from Mullvad</h2>
<p>To begin, you'll need <a href="https://mullvad.net/account/wireguard-config">Wireguard configuration files from Mullvad</a>. You can choose any of the options as you download them. For example, I enabled the kill switch, selected all countries, and selected a few content filters.</p>
<p>Once downloaded, unzip the files and move them to the Wireguard folder on your system.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="support function cd shell">cd</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/Downloads</span>
<span class="meta function-call shell"><span class="variable function shell">unzip</span></span><span class="meta function-call arguments shell"> mullvad_wireguard_linux_all_all.zip</span>
<span class="meta function-call shell"><span class="variable function shell">doas</span></span><span class="meta function-call arguments shell"> mv <span class="keyword operator regexp quantifier shell">*</span>.conf /etc/wireguard/</span></span></code></pre>
<h3 id="configuration-file-layout"><span class="section-number-3">1.1.</span> Configuration File Layout</h3>
<p>The default configuration files will look something like this:</p>
<pre><code class="language-conf">[Interface]
# Device: &lt;redacted&gt;
PrivateKey = &lt;redacted&gt;
Address = &lt;redacted&gt;
DNS = &lt;redacted&gt;
PostUp = iptables -I OUTPUT ! -o %i -m mark ! --mark $(wg show %i fwmark) -m addrtype ! --dst-type LOCAL -j REJECT &amp;&amp; ip6tables -I OUTPUT ! -o %i -m mark ! --mark $(wg show %i fwmark) -m addrtype ! --dst-type LOCAL -j REJECT
PreDown = iptables -D OUTPUT ! -o %i -m mark ! --mark $(wg show %i fwmark) -m addrtype ! --dst-type LOCAL -j REJECT &amp;&amp; ip6tables -D OUTPUT ! -o %i -m mark ! --mark $(wg show %i fwmark) -m addrtype ! --dst-type LOCAL -j REJECT

[Peer]
PublicKey = &lt;redacted&gt;
AllowedIPs = &lt;redacted&gt;
Endpoint = &lt;redacted&gt;</code></pre>
<blockquote>
<p>Note: If you didn't select the kill switch option, you won't see the <code class="verbatim">PostUp</code> and <code class="verbatim">PreDown</code> lines. In this case, you'll need to modify the script below to simply append those lines to the <code class="verbatim">[Interface]</code> block.</p>
</blockquote>
<h2 id="editing-the-configuration-files"><span class="section-number-2">2.</span> Editing the Configuration Files</h2>
<p>Once you have the files, you'll need to edit them and replace the <code class="verbatim">PostUp</code> and <code class="verbatim">PreDown</code> lines to enable LAN access.</p>
<p>I recommend that you do this process as root, since you'll need to be able to access files in <code class="verbatim">/etc/wireguard</code>, which are generally owned by root. You can also try using <code class="verbatim">sudo</code> or <code class="verbatim">doas</code>, but I didn't test that scenario so you may need to adjust, as necessary.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">su</span></span></span></code></pre>
<p>Create the Python file that we'll be using to update the Wireguard configuration files.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">nano</span></span><span class="meta function-call arguments shell"> replace.py</span></span></code></pre>
<p>Within the Python file, copy and paste the logic below. This script will open a directory, loop through every configuration file within the directory, and replace the <code class="verbatim">PostUp</code> and <code class="verbatim">PreDown</code> lines with the new LAN-enabled iptables commands.</p>
<blockquote>
<p>Note: If your LAN is on a subnet other than <code class="verbatim">192.168.1.0/24</code>, you'll need to update the Python script below appropriately.</p>
</blockquote>
<pre><code class="language-python highlight"><span class="source python"><span class="meta statement import python"><span class="keyword control import python">import</span> <span class="meta qualified-name python"><span class="meta generic-name python">os</span></span></span>
<span class="meta statement import python"><span class="keyword control import python">import</span> <span class="meta qualified-name python"><span class="meta generic-name python">fileinput</span></span></span>

<span class="meta function-call python"><span class="meta qualified-name python"><span class="support function builtin python">print</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">--- starting ---<span class="punctuation definition string end python">&quot;</span></span></span></span><span class="punctuation section arguments end python">)</span></span>

<span class="meta qualified-name python"><span class="support function builtin python">dir</span></span> <span class="keyword operator assignment python">=</span> <span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">/etc/wireguard/<span class="punctuation definition string end python">&quot;</span></span></span>

<span class="meta statement for python"><span class="keyword control flow for python">for</span> <span class="meta generic-name python">file</span> <span class="meta statement for python"><span class="keyword control flow for in python">in</span></span></span><span class="meta statement for python"> <span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">os</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">listdir</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta qualified-name python"><span class="support function builtin python">dir</span></span></span><span class="punctuation section arguments end python">)</span></span><span class="punctuation section block for python">:</span></span>
    <span class="meta function-call python"><span class="meta qualified-name python"><span class="support function builtin python">print</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">os</span><span class="punctuation accessor dot python">.</span><span class="meta generic-name python">path</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">join</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta qualified-name python"><span class="support function builtin python">dir</span></span><span class="punctuation separator arguments python">,</span> <span class="meta qualified-name python"><span class="meta generic-name python">file</span></span></span><span class="punctuation section arguments end python">)</span></span></span><span class="punctuation section arguments end python">)</span></span>
    <span class="meta statement for python"><span class="keyword control flow for python">for</span> <span class="meta generic-name python">line</span> <span class="meta statement for python"><span class="keyword control flow for in python">in</span></span></span><span class="meta statement for python"> <span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">fileinput</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">input</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">os</span><span class="punctuation accessor dot python">.</span><span class="meta generic-name python">path</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">join</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta qualified-name python"><span class="support function builtin python">dir</span></span><span class="punctuation separator arguments python">,</span> <span class="meta qualified-name python"><span class="meta generic-name python">file</span></span></span><span class="punctuation section arguments end python">)</span></span><span class="punctuation separator arguments python">,</span> <span class="variable parameter python">inplace</span><span class="keyword operator assignment python">=</span><span class="constant language python">True</span></span><span class="punctuation section arguments end python">)</span></span><span class="punctuation section block for python">:</span></span>
        <span class="meta statement if python"><span class="keyword control flow conditional python">if</span> <span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">PostUp<span class="punctuation definition string end python">&quot;</span></span></span> <span class="keyword operator logical python">in</span> <span class="meta qualified-name python"><span class="meta generic-name python">line</span></span><span class="punctuation section block conditional python">:</span></span>
            <span class="meta function-call python"><span class="meta qualified-name python"><span class="support function builtin python">print</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">PostUp = iptables -I OUTPUT ! -o <span class="constant other placeholder python">%i</span> -m mark ! --mark $(wg show <span class="constant other placeholder python">%i</span> fwmark) -m addrtype ! --dst-type LOCAL ! -d 192.168.1.0/24 -j REJECT &amp;&amp; ip6tables -I OUTPUT ! -o <span class="constant other placeholder python">%i</span> -m mark ! --mark $(wg show <span class="constant other placeholder python">%i</span> fwmark) -m addrtype ! --dst-type LOCAL -j REJECT<span class="punctuation definition string end python">&quot;</span></span></span></span><span class="punctuation section arguments end python">)</span></span>
        <span class="meta statement conditional python"><span class="keyword control flow conditional python">elif</span></span> <span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">PreDown<span class="punctuation definition string end python">&quot;</span></span></span> <span class="keyword operator logical python">in</span> <span class="meta qualified-name python"><span class="meta generic-name python">line</span></span><span class="punctuation separator annotation variable python">:</span>
            <span class="meta function-call python"><span class="meta qualified-name python"><span class="support function builtin python">print</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">PreDown = iptables -D OUTPUT ! -o <span class="constant other placeholder python">%i</span> -m mark ! --mark $(wg show <span class="constant other placeholder python">%i</span> fwmark) -m addrtype ! --dst-type LOCAL ! -d 192.168.1.0/24 -j REJECT &amp;&amp; ip6tables -D OUTPUT ! -o <span class="constant other placeholder python">%i</span> -m mark ! --mark $(wg show <span class="constant other placeholder python">%i</span> fwmark) -m addrtype ! --dst-type LOCAL -j REJECT<span class="punctuation definition string end python">&quot;</span></span></span></span><span class="punctuation section arguments end python">)</span></span>
        <span class="meta statement conditional python"><span class="keyword control flow conditional python">else</span><span class="punctuation section block python">:</span></span>
            <span class="meta function-call python"><span class="meta qualified-name python"><span class="support function builtin python">print</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">line</span></span><span class="punctuation separator arguments python">,</span> <span class="variable parameter python">end</span><span class="keyword operator assignment python">=</span><span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string end python">&quot;</span></span></span></span><span class="punctuation section arguments end python">)</span></span>

<span class="meta function-call python"><span class="meta qualified-name python"><span class="support function builtin python">print</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">--- done ---<span class="punctuation definition string end python">&quot;</span></span></span></span><span class="punctuation section arguments end python">)</span></span></span></code></pre>
<p>Once you're done, save and close the file. You can now run the Python script and watch as each file is updated.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">python3</span></span><span class="meta function-call arguments shell"> replace.py</span></span></code></pre>
<p>To confirm it worked, you can <code class="verbatim">cat</code> one of the configuration files to inspect the new logic and connect to one to test it out.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">cat</span></span><span class="meta function-call arguments shell"> /etc/wireguard/us-chi-wg-001.conf</span></span></code></pre>
<p>The configuration files should now look like this:</p>
<pre><code class="language-conf">[Interface]
# Device: &lt;redacted&gt;
PrivateKey = &lt;redacted&gt;
Address = &lt;redacted&gt;
DNS = &lt;redacted&gt;
PostUp = iptables -I OUTPUT ! -o %i -m mark ! --mark $(wg show %i fwmark) -m addrtype ! --dst-type LOCAL ! -d 192.168.1.0/24 -j REJECT &amp;&amp; ip6tables -I OUTPUT ! -o %i -m mark ! --mark $(wg show %i fwmark) -m addrtype ! --dst-type LOCAL -j REJECT
PreDown = iptables -D OUTPUT ! -o %i -m mark ! --mark $(wg show %i fwmark) -m addrtype ! --dst-type LOCAL ! -d 192.168.1.0/24 -j REJECT &amp;&amp; ip6tables -D OUTPUT ! -o %i -m mark ! --mark $(wg show %i fwmark) -m addrtype ! --dst-type LOCAL -j REJECT

[Peer]
PublicKey = &lt;redacted&gt;
AllowedIPs = &lt;redacted&gt;
Endpoint = &lt;redacted&gt;</code></pre>
<p>If you connect to a Wireguard interface, such as <code class="verbatim">us-chi-wg-001</code>, you can test your SSH functionality and see that it works even while on the VPN.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">wg-quick</span></span><span class="meta function-call arguments shell"> up us-chi-wg-001</span>
<span class="meta function-call shell"><span class="variable function shell">ssh</span></span><span class="meta function-call arguments shell"> user@lan-host</span></span></code></pre>
<p>To confirm your VPN connection, you can curl Mullvad's connection API:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">curl</span></span><span class="meta function-call arguments shell"> https://am.i.mullvad.net/connected</span>
<span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> You are connected to Mullvad (server us-chi-wg-001). Your IP address is &lt;redacted&gt;</span></span></code></pre>
]]></description>
    </item>
    <item>
      <title>Self-Hosting Guide: Voyager for Lemmy</title>
      <link>https://cleberg.net/blog/self-hosting-voyager.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/self-hosting-voyager.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Fri, 30 Jun 2023 00:00:00 +0000</pubDate>
      <category>linux</category>
      <category>self-hosting</category>
      <description><![CDATA[<h2 id="installation-guide"><span class="section-number-2">1.</span> Installation Guide</h2>
<p><a href="https://github.com/aeharding/voyager">Voyager</a> is a mobile-first Lemmy web client, based on iOS design standards. It follows very closely to Apollo's design.</p>
<p>This post is a guide showing how I was able to build and launch my own instance of Voyager via Docker Compose.</p>
<h3 id="clone-the-repository"><span class="section-number-3">1.1.</span> Clone the Repository</h3>
<p>Start by cloning the repository and entering it:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">git</span></span><span class="meta function-call arguments shell"> clone https://github.com/aeharding/voyager</span>
<span class="meta function-call shell"><span class="support function cd shell">cd</span></span><span class="meta function-call arguments shell"> voyager</span></span></code></pre>
<h3 id="build-the-image"><span class="section-number-3">1.2.</span> Build the Image</h3>
<p>With this repository, you can build the image yourself without any further configuration. When complete, it'll give you the image ID for you to run.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> docker build .</span>
<span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> Successfully built 5f00723cb5be</span></span></code></pre>
<p>With the image ID above, you can run the container and pass the requested port <code class="verbatim">5314</code> through or use a custom port, if you wish.</p>
<p>You can also set the <code class="verbatim">CUSTOM_LEMMY_SERVERS</code> environment variable if you want to add to the default suggested login servers. This must be set with a comma separated list of suggested servers. The first instance in the list will be the default view for logged-out users.</p>
<p>I will be using a <code class="verbatim">docker-compose.yml</code> file to run this container, instead of a <code class="verbatim">docker run</code> command.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">nano</span></span><span class="meta function-call arguments shell"> docker-compose.yml</span></span></code></pre>
<pre><code class="language-conf">version: "2"
services:
  voyager:
    image: 5f00723cb5be
    restart: always
    ports:
      - "&lt;custom_port&gt;:5314"
    environment:
      - CUSTOM_LEMMY_SERVERS=lemmy.dbzer0.com,lemmy.world,lemmy.ml,beehaw.org</code></pre>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> docker-compose up<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>d</span></span></span></code></pre>
<p>The web app will now be available at the following address: <code class="verbatim">&lt;machine_ip&gt;:&lt;custom_port&gt;</code>. If you are running it on your local device, try <code class="verbatim">localhost:&lt;custom_port&gt;</code>.</p>
<h3 id="reverse-proxy"><span class="section-number-3">1.3.</span> Reverse Proxy</h3>
<p>If you want to visit this app via an external URL or domain name, you'll need to set up a reverse proxy. The example below uses Nginx as a reverse proxy.</p>
<p>Simply create the configuration file, paste the contents below, save the file, symlink the file, and restart Nginx.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> nano /etc/nginx/sites-available/voyager</span></span></code></pre>
<pre><code class="language-conf">server {
    if ($host ~ ^[^.]+\.example\.com$) {
        return 301 https://$host$request_uri;
    }

    listen [::]:80;
    listen 80;
    server_name voyager.example.com;
    return 404;
}

server {
    listen [::]:443 ssl http2;
    listen 443 ssl http2;
    server_name voyager.example.com;
    access_log  /var/log/nginx/voyager.access.log;
    error_log   /var/log/nginx/voyager.error.log;

    location / {
        proxy_http_version 1.1;
        proxy_pass http://localhost:5314;
        proxy_set_header Host $host;
    }

    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
    include /etc/letsencrypt/options-ssl-nginx.conf;
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
}</code></pre>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> ln sudo ln<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>s</span> /etc/nginx/sites-available/voyager /etc/nginx/sites-enabled/voyager</span>
<span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> systemctl restart nginx.service</span></span></code></pre>
<p>The site will now be available at the <code class="verbatim">server_name</code> you specified above!</p>
<p>I ran an instance at <code class="verbatim">voyager.cleberg.net</code>, which is no longer online.</p>
]]></description>
    </item>
    <item>
      <title>Backblaze B2 Backups</title>
      <link>https://cleberg.net/blog/backblaze-b2.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/backblaze-b2.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Wed, 28 Jun 2023 00:00:00 +0000</pubDate>
      <category>self-hosting</category>
      <description><![CDATA[<h2 id="overview"><span class="section-number-2">1.</span> Overview</h2>
<p>Backblaze <a href="https://www.backblaze.com/b2/cloud-storage.html">B2 Cloud Storage</a> is an inexpensive and reliable on-demand cloud storage and backup solution.</p>
<p>The service starts at $5/TB/month ($0.005/GB/month) with a download rate of $0.01/GB/month.</p>
<p>However, there are free tiers:</p>
<ul>
<li>The first 10 GB of storage is free.</li>
<li>The first 1 GB of data downloaded each day is free.</li>
<li>Class A transactions are free.</li>
<li>The first 2500 Class B transactions each day are free.</li>
<li>The first 2500 Class C transactions each day are free.</li>
</ul>
<p>You can see which API calls fall into categories A, B, or C here: <a href="https://www.backblaze.com/b2/b2-transactions-price.html">Pricing Organized by API Calls</a>.</p>
<p>For someone like me, who wants an offsite backup of their server's <code class="verbatim">/home/</code> directory and various other server configs that fall under 10 GB total, Backblaze is a great solution from a financial perspective.</p>
<h2 id="create-an-account"><span class="section-number-2">2.</span> Create An Account</h2>
<p>To start with Backblaze, you'll need to <a href="https://www.backblaze.com/b2/sign-up.html">create a free account</a> - no payment method is required to sign up.</p>
<p>Once you have an account, you can test out the service with their web GUI, their mobile app, or their CLI tool. I'm going to use the CLI tool below to test a file upload and then sync an entire directory to my Backblaze bucket.</p>
<h2 id="create-a-bucket"><span class="section-number-2">3.</span> Create a Bucket</h2>
<p>Before you can start uploading, you need to create a bucket. If you're familiar with other object storage services, this will feel familiar. If not, it's pretty simple to create one.</p>
<p>As their webpage says:</p>
<blockquote>
<p>A bucket is a container that holds files that are uploaded into B2 Cloud Storage. The bucket name must be globally unique and must have a minimum of 6 characters. A limit of 100 buckets may be created per account. An unlimited number of files may be uploaded into a bucket.</p>
</blockquote>
<p>Once you click the <code class="verbatim">Create a Bucket</code> button on their webpage or mobile app, you need to provide the following:</p>
<ul>
<li>Bucket Unique Name</li>
<li>Files in Bucket are: <code class="verbatim">Private</code> or <code class="verbatim">Public</code></li>
<li>Default Encryption: <code class="verbatim">Disable</code> or <code class="verbatim">Enable</code></li>
<li>Object Lock: <code class="verbatim">Disable</code> or <code class="verbatim">Enable</code></li>
</ul>
<p>For my bucket, I created a private bucket with encryption enabled and object lock disabled.</p>
<p>Once your bucket is created, you can test the upload/download feature on their web GUI or mobile app! At this point, you have a fully functional bucket and account.</p>
<h2 id="linux-cli-tool"><span class="section-number-2">4.</span> Linux CLI Tool</h2>
<h3 id="installation"><span class="section-number-3">4.1.</span> Installation</h3>
<p>To install the <code class="verbatim">b2</code> CLI tool, you'll need to download it from the <a href="https://www.backblaze.com/docs/cloud-storage-command-line-tools">CLI Tools</a> page. I recommend copying the URL from the link that says <code class="verbatim">Linux</code> and using wget to download it, as shown below.</p>
<p>Once downloaded, make the file executable and move it to a location on your <code class="verbatim">$PATH</code>, so that you can execute that command from anywhere on the machine.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">wget</span></span><span class="meta function-call arguments shell"> <span class="keyword operator assignment redirection shell">&lt;</span>b2_cli_url<span class="keyword operator assignment redirection shell">&gt;</span>
</span><span class="meta function-call shell"><span class="variable function shell">chmod</span></span><span class="meta function-call arguments shell"> +x b2_linux</span>
<span class="meta function-call shell"><span class="variable function shell">mv</span></span><span class="meta function-call arguments shell"> b2_linux /usr/bin/b2</span></span></code></pre>
<h3 id="log-in"><span class="section-number-3">4.2.</span> Log In</h3>
<p>The first step after installation is to log in. To do this, execute the following command and provide your <code class="verbatim">&lt;applicationKeyId&gt;</code> and <code class="verbatim">&lt;applicationKey&gt;</code>.</p>
<p>If you don't want to provide these values in the command itself, you can simply execute the base command and it will request them in an interactive prompt.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> if you want to provide the keys directly:</span><span class="comment line number-sign shell">
</span><span class="meta function-call shell"><span class="variable function shell">b2</span></span><span class="meta function-call arguments shell"> authorize-account <span class="keyword control regexp set begin shell">[</span>&lt;applicationKeyId&gt;<span class="keyword control regexp set end shell">]</span> <span class="keyword control regexp set begin shell">[</span>&lt;applicationKey&gt;<span class="keyword control regexp set end shell">]</span></span>

<span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> or, if you don&#39;t want your keys in your shell history:</span><span class="comment line number-sign shell">
</span><span class="meta function-call shell"><span class="variable function shell">b2</span></span><span class="meta function-call arguments shell"> authorize-account</span></span></code></pre>
<h3 id="upload-a-test-file"><span class="section-number-3">4.3.</span> Upload a Test File</h3>
<p>In order to test the functionality of the CLI tool, I'll start by uploading a single test file to the bucket I created above. We can do this with the <code class="verbatim">upload_file</code> function.</p>
<p>The command is issued as follows:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">b2</span></span><span class="meta function-call arguments shell"> upload_file <span class="keyword operator assignment redirection shell">&lt;</span>bucket_name<span class="keyword operator assignment redirection shell">&gt;</span> <span class="keyword operator assignment redirection shell">&lt;</span>local_file<span class="keyword operator assignment redirection shell">&gt;</span> <span class="keyword operator assignment redirection shell">&lt;</span>remote_file<span class="keyword operator assignment redirection shell">&gt;</span></span></span></code></pre>
<p>In my situation, I executed the following command with my username.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">b2</span></span><span class="meta function-call arguments shell"> upload_file my_unique_bucket /home/<span class="keyword operator assignment redirection shell">&lt;</span>user<span class="keyword operator assignment redirection shell">&gt;</span>/test.md test.md</span></span></code></pre>
<p>To confirm that the file was uploaded successfully, list the files in your bucket:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">b2</span></span><span class="meta function-call arguments shell"> ls <span class="keyword operator assignment redirection shell">&lt;</span>bucket_name<span class="keyword operator assignment redirection shell">&gt;</span></span></span></code></pre>
<pre><code class="language-txt highlight"><span class="text plain">test.md</span></code></pre>
<h3 id="sync-a-directory"><span class="section-number-3">4.4.</span> Sync a Directory</h3>
<p>If you have numerous files, you can use the <code class="verbatim">sync</code> function to perform functionality similar to <code class="verbatim">rsync</code>, where you can check what's in your bucket and sync anything that is new or modified.</p>
<p>The command is issued as follows:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">b2</span></span><span class="meta function-call arguments shell"> sync <span class="keyword operator assignment redirection shell">&lt;</span>source file location<span class="keyword operator assignment redirection shell">&gt;</span> <span class="keyword operator assignment redirection shell">&lt;</span>B2 bucket destination<span class="keyword operator assignment redirection shell">&gt;</span></span></span></code></pre>
<p>In my case, I can sync my user's entire home directory to my bucket without specifying any of the files directly:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">b2</span></span><span class="meta function-call arguments shell"> sync /home/<span class="keyword operator assignment redirection shell">&lt;</span>user<span class="keyword operator assignment redirection shell">&gt;</span>/ <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>b2://&lt;bucketName&gt;/home/&lt;user&gt;<span class="punctuation definition string end shell">&quot;</span></span></span></span></code></pre>
<h2 id="caveats"><span class="section-number-2">5.</span> Caveats</h2>
<h3 id="timing-of-updates-to-the-web-gui"><span class="section-number-3">5.1.</span> Timing of Updates to the Web GUI</h3>
<p>When performing actions over a bucket, there is a slight delay in the web GUI when inspecting a bucket or its file. Note that simple actions such as uploading or deleting files may have a delay of a few minutes up to 24 hours. In my experience (&lt;10 GB and ~20,000 files), any actions took only a few minutes to update across clients.</p>
<h3 id="symlinks"><span class="section-number-3">5.2.</span> Symlinks</h3>
<p>Note that symlinks are resolved by b2, so if you have a link from <code class="verbatim">/home/&lt;user&gt;/nas-storage</code> that symlinks out to a <code class="verbatim">/mnt/nas-storage</code> folder that has 10TB of data, <code class="verbatim">b2</code> will resolve that link and start uploading all 10TB of data linked within the folder.</p>
<p>If you're not sure if you have any symlinks, a symlink will look like this (note the <code class="verbatim">-&gt;</code> symbol):</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"></span><span class="meta function-call arguments shell"><span class="keyword operator assignment redirection shell">&gt;</span> ls<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>lha</span></span>
<span class="meta function-call shell"><span class="variable function shell">lrwxrwxrwx</span></span><span class="meta function-call arguments shell">  1 root root   20 Jun 28 13:32 nas -<span class="keyword operator assignment redirection shell">&gt;</span> /mnt/nas-storage/</span></span></code></pre>
<p>You can recursively find symlink in a path with the following command:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">ls</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>lR</span> /path/to/search</span> <span class="keyword operator logical pipe shell">|</span> <span class="meta function-call shell"><span class="variable function shell">grep</span></span><span class="meta function-call arguments shell"> <span class="string quoted single shell"><span class="punctuation definition string begin shell">&#39;</span>^l<span class="punctuation definition string end shell">&#39;</span></span></span></span></code></pre>
]]></description>
    </item>
    <item>
      <title>Self-Hosting Guide: Convos</title>
      <link>https://cleberg.net/blog/self-hosting-convos.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/self-hosting-convos.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Fri, 23 Jun 2023 00:00:00 +0000</pubDate>
      <category>linux</category>
      <category>self-hosting</category>
      <description><![CDATA[<h2 id="convos"><span class="section-number-2">1.</span> Convos</h2>
<p><a href="https://convos.chat/">Convos</a> is an always-online web client for IRC. It has a few features that made it attractive to me as a self-hosted option:</p>
<ul>
<li>Extremely simple Docker Compose installation method.</li>
<li>Runs in the background and monitors chats even while you're not logged in.</li>
<li>Neatly organized sidebar for conversation and client settings.</li>
<li>Ability to connect to different hosts and create profiles for hosts.</li>
<li>By default, registration is closed to the public. You can enable public registration on the Settings page or generate invitation links on the Users page.</li>
<li>Customization of the client theme, organization name and URL, admin email, and video service.</li>
</ul>
<h2 id="docker-installation"><span class="section-number-2">2.</span> Docker Installation</h2>
<p>To install Convos, simply create a directory and a <code class="verbatim">docker-compose.yml</code> file:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">mkdir</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/convos</span> <span class="keyword operator logical and shell">&amp;&amp;</span> <span class="meta function-call shell"><span class="support function cd shell">cd</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/convos</span>
<span class="meta function-call shell"><span class="variable function shell">nano</span></span><span class="meta function-call arguments shell"> docker-compose.yml</span></span></code></pre>
<p>With the <code class="verbatim">docker-compose.yml</code> file open, paste the configuration below into the file. You can customize the host port to be something unique, such as <code class="verbatim">21897:3000</code>. You can also change the <code class="verbatim">data</code> folder to be a docker volume instead, if you prefer.</p>
<pre><code class="language-config">version: '3'

services:
  convos:
    image: 'convos/convos:stable'
    ports:
      - '3000:3000'
    volumes:
      - './data:/data'
    environment:
      - CONVOS_REVERSE_PROXY=1
    restart: always</code></pre>
<p>Save the <code class="verbatim">docker-compose.yml</code> file and bring the container up:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> docker-compose up<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>d</span></span></span></code></pre>
<p>At this point, Convos is available at <code class="verbatim">&lt;server_ip&gt;:3000</code> but not available to the public.</p>
<h2 id="nginx-reverse-proxy"><span class="section-number-2">3.</span> Nginx Reverse Proxy</h2>
<p>If you're using Nginx, you can create a configuration file for the convos application. Start by opening the file:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">nano</span></span><span class="meta function-call arguments shell"> /etc/nginx/sites-available/convos</span></span></code></pre>
<p>Within the nginx configuration file, paste the following content and be sure to update <code class="verbatim">convos.example.com</code> to match your domain and <code class="verbatim">127.0.0.1:3000</code> to match the port you opened in the <code class="verbatim">docker-compose.yml</code> file.</p>
<pre><code class="language-config"># Host and port where convos is running
upstream convos_upstream { server 127.0.0.1:3000; }

server {
    if ($host ~ ^[^.]+\.example\.com$) {
        return 301 https://$host$request_uri;
    }

    listen [::]:80;
    listen 80;
    server_name convos.example.com;
    return 404;
}

server {
    listen [::]:443 ssl http2;
    listen 443 ssl http2;
    server_name convos.example.com;
    access_log  /var/log/nginx/convos.access.log;
    error_log   /var/log/nginx/convos.error.log;

    location / {
        proxy_pass http://convos_upstream;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        client_max_body_size 0;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Request-Base "$scheme://$host/";
    }

    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
    include /etc/letsencrypt/options-ssl-nginx.conf;
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
}</code></pre>
<p>Once the file is saved, link it to the <code class="verbatim">sites-enabled</code> directory and restart Nginx.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> ln<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>s</span> /etc/nginx/sites-available/convos /etc/nginx/sites-enabled/convos</span>
<span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> systemctl restart nginx.service</span></span></code></pre>
<h2 id="screenshots"><span class="section-number-2">4.</span> Screenshots</h2>
<p>See the screenshots below for an example of the Convos homepage and an excerpt of the chat screen.</p>
<p>There are numerous themes to choose from; the theme shown in the images below is Dracula.</p>
<figure><img src="https://img.cleberg.net/blog/20230623-convos/convos_home.webp" alt="The Convos login page, requiring an email and password."><figcaption><span class="figure-number">Figure 1: </span>Convos Home</figcaption></figure>
<figure><img src="https://img.cleberg.net/blog/20230623-convos/convos_chat.webp" alt="An example of the #org-mode channel on Libera.Chat."><figcaption><span class="figure-number">Figure 2: </span>Convos Chat</figcaption></figure>
<h2 id="registering-a-nickname"><span class="section-number-2">5.</span> Registering a Nickname</h2>
<p>Hop into the server channel so that you can message NickServ. In the case of Convos, the default sever is libera.chat. Simply click the <code class="verbatim">libera</code> conversation at the top of the sidebar to open it. Once the chat is open, you can claim a nickname by typing:</p>
<pre><code class="language-txt highlight"><span class="text plain">/nick &lt;nick&gt;</span></code></pre>
<p>If the nickname is available, and you'd like to register the nickname to yourself, you'll need to type another command:</p>
<pre><code class="language-txt highlight"><span class="text plain">/msg NickServ REGISTER
&lt;password&gt; &lt;email&gt;</span></code></pre>
<p>On libera.chat, the server will send a confirmation email with a command that you must message in IRC to verify registration of the nickname:</p>
<pre><code class="language-txt highlight"><span class="text plain">/msg NickServ VERIFY REGISTER &lt;nick&gt; &lt;verification_code&gt;</span></code></pre>
<p>Once entered, the server should confirm registration of the nickname to the supplied email with the password specified.</p>
]]></description>
    </item>
    <item>
      <title>Byobu: tmux with Less Configuration Overhead</title>
      <link>https://cleberg.net/blog/byobu.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/byobu.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Fri, 23 Jun 2023 00:00:00 +0000</pubDate>
      <category>linux</category>
      <category>self-hosting</category>
      <description><![CDATA[<h2 id="byobu"><span class="section-number-2">1.</span> Byobu</h2>
<p><a href="https://www.byobu.org">byobu</a> is a command-line tool that allows you to use numerous screens within a single terminal emulator instance. More specifically, it's a text based window manager, using either <code class="verbatim">screen</code> or <code class="verbatim">tmux</code>.</p>
<p>This post is mostly just a self-reference as I explore byobu, so I may come back later and update this post with more content.</p>
<h3 id="screenshot"><span class="section-number-3">1.1.</span> Screenshot</h3>
<p>Take a look below at my current multi-window set-up in byobu while I write this blog post:</p>
<figure><img src="https://img.cleberg.net/blog/20230623-byobu/byobu.webp" alt="The Byobu multiplexer with both nano and eww opened."><figcaption><span class="figure-number">Figure 1: </span>byobu</figcaption></figure>
<h4 id="keybindings"><span class="section-number-4">1.1.1.</span> Keybindings</h4>
<p>You can open the help menu with either of the following commands; they will both open the same manpage:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">byobu</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> --</span>help</span></span>
<span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> or</span><span class="comment line number-sign shell">
</span><span class="meta function-call shell"><span class="variable function shell">man</span></span><span class="meta function-call arguments shell"> byobu</span></span></code></pre>
<p>While the manpage contains a ton of information about the functionality of byobu (such as status notifications, sessions, and windows), the first location to explore should be the keybindings section.</p>
<p>The keybindings are configured as follows:</p>
<pre><code class="language-txt highlight"><span class="text plain">byobu  keybindings  can be user defined in /usr/share/byobu/keybindings/ (or
within .screenrc if byobu-export was used). The common key bindings are:

F2 - Create a new window
F3 - Move to previous window
F4 - Move to next window
F5 - Reload profile
F6 - Detach from this session
F7 - Enter copy/scrollback mode
F8 - Re-title a window
F9 - Configuration Menu
F12 -  Lock this terminal
shift-F2 - Split the screen horizontally
ctrl-F2 - Split the screen vertically
shift-F3 - Shift the focus to the previous split region
shift-F4 - Shift the focus to the next split region
shift-F5 - Join all splits
ctrl-F6 - Remove this split
ctrl-F5 - Reconnect GPG and SSH sockets
shift-F6 - Detach, but do not logout
alt-pgup - Enter scrollback mode
alt-pgdn - Enter scrollback mode
Ctrl-a $ - show detailed status
Ctrl-a R - Reload profile
Ctrl-a ! - Toggle key bindings on and off
Ctrl-a k - Kill the current window
Ctrl-a ~ - Save the current window&#39;s scrollback buffer</span></code></pre>
]]></description>
    </item>
    <item>
      <title>Audit Testing Review Checklist</title>
      <link>https://cleberg.net/blog/audit-review-template.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/audit-review-template.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Tue, 20 Jun 2023 00:00:00 +0000</pubDate>
      <category>audit</category>
      <description><![CDATA[<h2 id="overview"><span class="section-number-2">1.</span> Overview</h2>
<p>This post is a <em>very</em> brief overview on the basic process to review audit test results, focusing on work done as part of a financial statement audit (FSA) or service organization controls (SOC) report.</p>
<p>While there are numerous different things to review and look for - all varying wildly depending on the report, client, and tester - this list serves as a solid base foundation for a reviewer.</p>
<p>I have used this throughout my career as a starting point to my reviews, and it has worked wonders for creating a consistent and objective template to my reviews. The goal is to keep this base high-level enough to be used on a wide variety of engagements, while still ensuring that all key areas are covered.</p>
<h2 id="review-template"><span class="section-number-2">2.</span> Review Template</h2>
<ol>
<li class="off"><code>[&nbsp;]</code> Check all documents for spelling and grammar.</li>
<li class="off"><code>[&nbsp;]</code> Ensure all acronyms are fully explained upon first use.</li>
<li class="off"><code>[&nbsp;]</code> For all people referenced, use their full names and job titles upon first use.</li>
<li class="off"><code>[&nbsp;]</code> All supporting documents must cross-reference to the lead sheet and vice-versa.</li>
<li class="off"><code>[&nbsp;]</code> Verify that the control has been adequately tested:<ul>
<li class="off"><code>[&nbsp;]</code> <strong>Test of Design</strong>: Did the tester obtain information regarding how the control should perform normally and abnormally (e.g., emergency scenarios)?</li>
<li class="off"><code>[&nbsp;]</code> <strong>Test of Operating Effectiveness</strong>: Did the tester inquire, observe, inspect, or re-perform sufficient evidence to support their conclusion over the control? Inquiry alone is not adequate!</li>
</ul>
</li>
<li class="off"><code>[&nbsp;]</code> For any information used in the control, whether by the control operator or by the tester, did the tester appropriately document the source (system or person), extraction method, parameters, and completeness and accuracy (C&amp;A)?<ul>
<li class="off"><code>[&nbsp;]</code> For any reports, queries, etc. used in the extraction, did the tester include a copy and notate C&amp;A considerations?</li>
</ul>
</li>
<li class="off"><code>[&nbsp;]</code> Did the tester document the specific criteria that the control is being tested against?</li>
<li class="off"><code>[&nbsp;]</code> Did the tester notate in the supporting documents where each criterion was satisfied?</li>
<li class="off"><code>[&nbsp;]</code> If testing specific policies or procedures, are the documents adequate?<ul>
<li class="off"><code>[&nbsp;]</code> e.g., a test to validate that a review of policy XYZ occurs periodically should also evaluate the sufficiency of the policy itself, if meant to cover the risk that such a policy does not exist and is not reviewed.</li>
</ul>
</li>
<li class="off"><code>[&nbsp;]</code> Does the test cover the appropriate period under review?<ul>
<li class="off"><code>[&nbsp;]</code> If the test is meant to cover only a portion of the audit period, do other controls exist to mitigate the risks that exist for the remainder of the period?</li>
</ul>
</li>
<li class="off"><code>[&nbsp;]</code> For any computer-aided audit tools (CAATs) or other automation techniques used in the test, is the use of such tools explained and appropriately documented?</li>
<li class="off"><code>[&nbsp;]</code> If prior-period documentation exists, are there any missing pieces of evidence that would further enhance the quality of the test?</li>
<li class="off"><code>[&nbsp;]</code> Was any information discovered during the walkthrough or inquiry phase that was not incorporated into the test?</li>
<li class="off"><code>[&nbsp;]</code> Are there new rules or expectations from your company's internal guidance or your regulatory bodies that would affect the audit approach for this control?</li>
<li class="off"><code>[&nbsp;]</code> Was an exception, finding, or deficiency identified as a result of this test?<ul>
<li class="off"><code>[&nbsp;]</code> Was the control deficient in design, operation, or both?</li>
<li class="off"><code>[&nbsp;]</code> What was the root cause of the finding?</li>
<li class="off"><code>[&nbsp;]</code> Does the finding indicate other findings or potential fraud?</li>
<li class="off"><code>[&nbsp;]</code> What's the severity and scope of the finding?</li>
<li class="off"><code>[&nbsp;]</code> Do other controls exist as a form of compensation against the finding's severity, and do they mitigate the risk within the control objective?</li>
<li class="off"><code>[&nbsp;]</code> Does the finding exist at the end of the period, or was it resolved within the audit period?</li>
</ul>
</li>
</ol>
]]></description>
    </item>
    <item>
      <title>Blocking Malicious IPs on Unifi</title>
      <link>https://cleberg.net/blog/unifi-ip-blocklist.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/unifi-ip-blocklist.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Sun, 18 Jun 2023 00:00:00 +0000</pubDate>
      <category>linux</category>
      <category>self-hosting</category>
      <description><![CDATA[<h2 id="identifying-abusive-ips"><span class="section-number-2">1.</span> Identifying Abusive IPs</h2>
<p>If you're like me and use Unifi network equipment at the edge of the network you manage, you may know that Unifi is only somewhat decent at identifying and blocking IPs that represent abusive or threat actors.</p>
<p>While Unifi has a <a href="https://help.ui.com/hc/en-us/articles/360006893234-UniFi-Gateway-Threat-Management">threat management</a> tool inside their Network application, it can be lacking in functionality and identification. For example, I have my UDM Pro set to identify and block almost all categories of threats available within the Unifi settings. However, I regularly identify abusive actors on my web server via the server logs.</p>
<p>In addition, I have identified IP addresses and subnets directly within Unifi's logs that the UDM did not block for whatever reason.</p>
<p>This guide is meant to be another step in the process to manually block abusive IP addresses or subnets that you have identified but are not being automatically blocked yet.</p>
<h2 id="create-an-ip-group-profile"><span class="section-number-2">2.</span> Create an IP Group Profile</h2>
<p>To start, login to the Unifi machine's web GUI and navigate to the Network app &gt; Settings &gt; Profiles.</p>
<p>Within this page, choose the <code class="verbatim">IP Groups</code> tab and click <code class="verbatim">Create New</code>.</p>
<p>Each IP Group profile can be used as one of three options:</p>
<ol>
<li>Port Group</li>
<li>IPv4 Address/Subnet</li>
<li>IPv6 Address/Subnet</li>
</ol>
<p>In this example, I'm creating an IPv4 Address/Subnet group and adding a few different IP addresses and a subnet. Once you've added all IP addresses and subnets, click the <code class="verbatim">Apply</code> button that should appear at the bottom.</p>
<p>At this point, the IPv4 Address/Subnet has been created but not yet used.</p>
<h2 id="drop-ip-group-profile-via-the-unifi-firewall"><span class="section-number-2">3.</span> Drop IP Group Profile via the Unifi Firewall</h2>
<p>To instruct the Unifi machine to block the profile we just created, we need to navigate to the Network app &gt; Settings &gt; Firewall &amp; Security.</p>
<p>Within this screen, find the Firewall Rules table and click <code class="verbatim">Create Entry</code>. This entry should contain the following settings:</p>
<ul>
<li>Type: <code class="verbatim">Internet In</code></li>
<li>Description: <code class="verbatim">&lt;Your Custom Rule&gt;</code></li>
<li>Rule Applied: <code class="verbatim">Before Predefined Rules</code></li>
<li>Action: <code class="verbatim">Drop</code></li>
<li>Source Type: <code class="verbatim">Port/IP Group</code></li>
<li>IPv4 Address Group: <code class="verbatim">&lt;Name of the Group Profile You Created Above&gt;</code></li>
</ul>
<p>Customize the remaining configurations to your liking, and then save and enable the firewall rule.</p>
<p>Once enabled, the Unifi machine will be able to drop all incoming connections from the defined IP addresses and subnets within the created profile.</p>
<blockquote>
<p>As a personal aside to this topic, I'm looking for a convenient way to update the firewall rules or profiles remotely (within the LAN) from the web server to accelerate this process. If you have an idea on how to automatically update Unifi IP groups or firewall rules, let me know!</p>
</blockquote>
]]></description>
    </item>
    <item>
      <title>Self-Hosting Guide: Baikal</title>
      <link>https://cleberg.net/blog/self-hosting-baikal.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/self-hosting-baikal.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Thu, 08 Jun 2023 00:00:00 +0000</pubDate>
      <category>linux</category>
      <category>self-hosting</category>
      <description><![CDATA[<h2 id="what-is-baikal"><span class="section-number-2">1.</span> What is Baikal?</h2>
<p><a href="https://sabre.io/baikal/">Baikal</a> is a lightweight CalDAV + CardDAV server that you can self-host on your own machine. While I have tried (&amp; failed) to get this CalDAV + CardDAV server running before, it was quite easy this time. Not really sure what I did differently this time, but I'm documenting my process here to ensure I don't forget.</p>
<h2 id="installation"><span class="section-number-2">2.</span> Installation</h2>
<p>First, create a folder on your server and open a <code class="verbatim">docker-compose.yml</code> file for editing:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">mkdir</span></span><span class="meta function-call arguments shell"> baikal</span> <span class="keyword operator logical and shell">&amp;&amp;</span> <span class="meta function-call shell"><span class="support function cd shell">cd</span></span><span class="meta function-call arguments shell"> baikal</span>
<span class="meta function-call shell"><span class="variable function shell">nano</span></span><span class="meta function-call arguments shell"> docker-compose.yml</span></span></code></pre>
<p>Within this file, you'll need to paste the information below. You can customize the <code class="verbatim">ports</code> section to use any port on your server to pass through to port 80 in the container. You can also edit the <code class="verbatim">volumes</code> section to use docker volumes instead of local folders.</p>
<pre><code class="language-conf">version: "2"
services:
  baikal:
    image: ckulka/baikal:nginx
    restart: always
    ports:
      - "8567:80"
    volumes:
      - ./config:/var/www/baikal/config
      - ./data:/var/www/baikal/Specific</code></pre>
<p>Once finished with editing, save and close the file. Then, launch the docker container:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> docker-compose up<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>d</span></span></span></code></pre>
<h2 id="initial-setup"><span class="section-number-2">3.</span> Initial Setup</h2>
<p>As long as no issues came up when starting the container, you should be able to visit the server's set-up page at <code class="verbatim">http://&lt;server_ip&gt;:&lt;port&gt;</code>. The application will ask you to create an administrator account and choose the database type for your storage. Personally, I opted to use SQLite.</p>
<p>Make sure the administrator credentials are adequate to protect against common attacks.</p>
<h2 id="creating-users"><span class="section-number-2">4.</span> Creating Users</h2>
<p>Once you've set up the application, you will be greeted by the Dashboard page, which will show the version of the app, status of the admin/CalDAV/CardDAV services, and the number of users, calendars, events, address books, and contacts.</p>
<p>To create a new user, navigate to the <code class="verbatim">Users and resources</code> page. This process is as simple as entering a username, password, and email.</p>
<p>Once a user has been created, you can create any number of calendars and address books for user, as well as inspect their information.</p>
<h2 id="setting-up-a-public-url"><span class="section-number-2">5.</span> Setting Up a Public URL</h2>
<p>Once your application is working locally, you can open access remotely via a URL by using a reverse-proxy like Nginx.</p>
<p>As a prerequisite, you must own a domain name and set up DNS records to point a domain name to the server hosting Baikal.</p>
<p>Start by navigating to your web server's configuration directory and create a new file for this application.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="support function cd shell">cd</span></span><span class="meta function-call arguments shell"> /etc/nginx/sites-available/</span>
<span class="meta function-call shell"><span class="variable function shell">nano</span></span><span class="meta function-call arguments shell"> dav</span></span></code></pre>
<p>Within this file, paste in the configuration from below and change <code class="verbatim">dav.example.com</code> to match the URL you'll be using.</p>
<pre><code class="language-conf">server {
        if ($host ~ ^[^.]+\.example\.com$) {
                return 301 https://$host$request_uri;
        }

        listen [::]:80;
        listen 80;
        server_name dav.example.com;
        return 404;
}

server {
        listen [::]:443 ssl http2;
        listen 443 ssl http2;
        server_name dav.example.com;
        access_log  /var/log/nginx/dav.access.log;
        error_log   /var/log/nginx/dav.error.log;

        location / {
                proxy_http_version 1.1;
                proxy_pass http://localhost:8567;
                proxy_set_header Host $host;
        }

        ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
        include /etc/letsencrypt/options-ssl-nginx.conf;
        ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
}</code></pre>
<p>For Nginx on Ubuntu, you'll need to symlink the configuration file to the <code class="verbatim">sites-enabled</code> directory and then restart Nginx.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> ln<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>s</span> /etc/nginx/sites-available/dav /etc/nginx/sites-enabled/dav</span>
<span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> systemctl restart nginx.service</span></span></code></pre>
<p>At this point, the Baikal server should be available over the internet at the URL configured above!</p>
<h2 id="configuring-clients"><span class="section-number-2">6.</span> Configuring Clients</h2>
<p>Lastly, configuring clients and applications is essential to making sure the DAV server is being fully utilized.</p>
<p>You can also use the <code class="verbatim">Users and resources</code> page to inspect a user's personal link to their calendars and address books by clicking the info (i) button. It will show a URI like <code class="verbatim">/dav.php/calendars/your-user/default/</code>.</p>
<p>However, I found that the following URL works for most applications: <code class="verbatim">/dav.php/principals/your-user/</code>.</p>
<p>I used the <code class="verbatim">principals</code> URL above for Thunderbird (calendar, tasks, and contacts), as well as iOS (calendar, tasks, and contacts) and everything works flawlessly so far.</p>
<p>Syncing is quick between the server and clients, and I haven't seen any disruptions in the service or data integrity.</p>
]]></description>
    </item>
    <item>
      <title>Nginx Traffic Analysis with GoAccess and GeoIP</title>
      <link>https://cleberg.net/blog/goaccess-geoip.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/goaccess-geoip.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Thu, 08 Jun 2023 00:00:00 +0000</pubDate>
      <category>self-hosting</category>
      <category>web</category>
      <description><![CDATA[<h2 id="overview"><span class="section-number-2">1.</span> Overview</h2>
<p><a href="https://goaccess.io/">GoAccess</a> is an open source real-time web log analyzer and interactive viewer that runs in a terminal in *nix systems or through your browser.</p>
<h2 id="installation"><span class="section-number-2">2.</span> Installation</h2>
<p>To start, you'll need to install GoAccess for your OS. Here's an example for Debian-based distros:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> apt install goaccess</span></span></code></pre>
<p>Next, find any number of the MaxMind GeoIP database files on GitHub or another file hosting website. We're going to use P3TERX's version in this example:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">wget</span></span><span class="meta function-call arguments shell"> https://github.com/P3TERX/GeoLite.mmdb/raw/download/GeoLite2-City.mmdb</span></span></code></pre>
<p>Be sure to save this file in an easy to remember location!</p>
<h2 id="usage"><span class="section-number-2">3.</span> Usage</h2>
<p>In order to utilize the full capabilities of GoAccess and MMDB, start with the command template below and customize as necessary. This will export an HTML view of the GoAccess dashboard, showing all relevant information related to that site's access log. You can also omit the <code class="verbatim">-o output.html</code> parameter if you prefer to view the data within the CLI instead of creating an HTML file.</p>
<p>With the addition of the GeoIP Database parameter, section <code class="verbatim">16 - Geo Location</code> will be added with the various countries that are associated with the collected IP addresses.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">zcat</span></span><span class="meta function-call arguments shell"> /var/log/nginx/example.access.log.<span class="keyword operator regexp quantifier shell">*</span>.gz</span> <span class="keyword operator logical pipe shell">|</span> <span class="meta function-call shell"><span class="variable function shell">goaccess</span></span><span class="meta function-call arguments shell">     <span class="punctuation separator continuation line shell">\
</span><span class="variable parameter option shell"><span class="punctuation definition parameter shell">--</span>geoip-database</span><span class="keyword operator assignment option shell">=</span>/home/user/GeoLite2-City.mmdb             <span class="punctuation separator continuation line shell">\
</span><span class="variable parameter option shell"><span class="punctuation definition parameter shell">--</span>date-format</span><span class="keyword operator assignment option shell">=</span><span class="meta group expansion job shell"><span class="punctuation definition variable job shell">%</span><span class="variable other readwrite shell">d</span></span>/<span class="meta group expansion job shell"><span class="punctuation definition variable job shell">%</span><span class="variable other readwrite shell">b</span></span>/<span class="meta group expansion job shell"><span class="punctuation definition variable job shell">%</span><span class="variable other readwrite shell">Y</span></span>                                     <span class="punctuation separator continuation line shell">\
</span><span class="variable parameter option shell"><span class="punctuation definition parameter shell">--</span>time-format</span><span class="keyword operator assignment option shell">=</span><span class="meta group expansion job shell"><span class="punctuation definition variable job shell">%</span><span class="variable other readwrite shell">H</span></span>:<span class="meta group expansion job shell"><span class="punctuation definition variable job shell">%</span><span class="variable other readwrite shell">M</span></span>:<span class="meta group expansion job shell"><span class="punctuation definition variable job shell">%</span><span class="variable other readwrite shell">S</span></span>                                     <span class="punctuation separator continuation line shell">\
</span><span class="variable parameter option shell"><span class="punctuation definition parameter shell">--</span>log-format</span><span class="keyword operator assignment option shell">=</span>COMBINED                                      <span class="punctuation separator continuation line shell">\
</span><span class="variable parameter option shell"><span class="punctuation definition parameter shell">-</span>o</span> output.html                                             <span class="punctuation separator continuation line shell">\
</span>/var/log/nginx/example.access.log -</span></span></code></pre>
]]></description>
    </item>
    <item>
      <title>Burnout</title>
      <link>https://cleberg.net/blog/burnout.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/burnout.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Mon, 22 May 2023 00:00:00 +0000</pubDate>
      <category>personal</category>
      <description><![CDATA[<h2 id="re-burnout"><span class="section-number-2">1.</span> RE: Burnout</h2>
<p>I recently read <a href="https://drewdevault.com/2023/05/01/2023-05-01-Burnout.html">Drew DeVault's post on burnout</a> around the same time I was pulling out of a burnout rut myself earlier this month. Finally, seeing the light at the end of my burnout tunnel made me want to write my first post back on this topic.</p>
<h2 id="busy-seasons-on-busy-seasons"><span class="section-number-2">2.</span> Busy Seasons on Busy Seasons</h2>
<p>My career deals with busy seasons, generally driven by client demand. This last year, I dealt with a harsh busy season from Aug to Oct 2022 to issue a few SOC reports for the period ending 2022-09-30. Immediately following that, I had to pivot and found another busy season from Oct to Jan for financial statement audits ending on 2022-12-31. Then again, supporting other clients from Jan to Mar 2023, followed by my current client workload aiming for SOC reports due on 2023-06-30.</p>
<p>The result? A busy season that has lasted from August 2022 through today. I will likely be rushing throughout the next month or two before I have a brief break and need to focus on the 2023-09-30 SOC reports again. While auditing and consulting always involve a busy season, this is the first time I've had one last 9+ months without a break.</p>
<p>While it's been tough, I have a handful of breaks pre-planned throughout this next cycle and should be able to moderate the level of commitment required for each client.</p>
<h2 id="refocusing"><span class="section-number-2">3.</span> Refocusing</h2>
<p>Outside of work, I finally have time to work on hobbies such as this website, programming, athletics, games, etc.</p>
<p>You may have noticed my absence if you're in the same channels, forums, and rooms that I am, but I should finally be active again.</p>
<p>I'm hoping to break an item out of my backlog soon and start working on building a new project or hack around with a stale one.</p>
]]></description>
    </item>
    <item>
      <title>Hare Lang: Notes from First Contact</title>
      <link>https://cleberg.net/blog/exploring-hare.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/exploring-hare.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Thu, 02 Feb 2023 00:00:00 +0000</pubDate>
      <category>linux</category>
      <description><![CDATA[<h2 id="a-quick-note"><span class="section-number-2">1.</span> A Quick Note</h2>
<p>By no means am I a professional developer, so this post will be rather short. I won't be going into depth on the specification or anything that technical.</p>
<p>Instead, I will simply be talking about how I (a relatively basic hobbyist programmer) have been playing with Hare and what intrigues me about the language.</p>
<h2 id="hare"><span class="section-number-2">2.</span> Hare</h2>
<p>The <a href="https://harelang.org">Hare</a> programming language is a straightforward language that should look familiar if you've ever programmed with C, Rust, or other languages that aim to build software at the system-level.</p>
<p>The Hare homepage states the following:</p>
<blockquote>
<p>Hare is a systems programming language designed to be simple, stable, and robust. Hare uses a static type system, manual memory management, and minimal runtime. It is well-suited to writing operating systems, system tools, compilers, networking software, and other low-level, high performance tasks.</p>
</blockquote>
<p>I have found this all to be true while playing with it for the first time today. In the next few sections, I'm going to walk through my installation and first program.</p>
<h3 id="installation"><span class="section-number-3">2.1.</span> Installation</h3>
<p>I'm currently running Alpine Linux on my Thinkpad, so the installation was quite easy as there is a package for Hare in the <code class="verbatim">apk</code> repositories.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">doas</span></span><span class="meta function-call arguments shell"> apk add hare hare-doc</span></span></code></pre>
<p>However, I was able to install Hare from scratch on Fedora Linux a short while ago, which was also very easy to do. If you need further instructions and Hare doesn't have a package on your system, take a look at the <a href="https://harelang.org/installation/">Hare Installation</a> page.</p>
<h3 id="creating-a-test-project"><span class="section-number-3">2.2.</span> Creating a Test Project</h3>
<p>In order to play with the language, I created <a href="https://gitbay.org/cmc/learn/tree/main/hare">learn/hare</a> and will be putting any of my Hare-related adventures in here.</p>
<p>Luckily, Hare doesn't require any complex set-up tools or build environment. Once you have Hare installed, you simply need to create a file ending with <code class="verbatim">.ha</code> and you can run a Hare program.</p>
<p>I created a file called <code class="verbatim">rgb.ha</code> in order to test out the random number generation and passing parameters between functions.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">nano</span></span><span class="meta function-call arguments shell"> rgb.ha</span></span></code></pre>
<p>Within this file, I was able to easily import a few of the <a href="https://harelang.org/tutorials/stdlib/">standard library modules</a>: <code class="verbatim">fmt</code>, <code class="verbatim">math::random</code>, and <code class="verbatim">datetime</code>.</p>
<p>With these modules, I created two functions:</p>
<ol>
<li><code class="verbatim">main</code>: This function calls the <code class="verbatim">generate_rgb</code> function and then prints out the returned values.</li>
<li><code class="verbatim">generate_rgb</code>: This function uses the current Unix epoch time to generate a pseudo-random value and uses this value to create three more random values between 0 and 255. These three numbers represent a color in RGB format.</li>
</ol>
<blockquote>
<p><strong>Note</strong>: Some syntax coloring may look odd, as Zola currently doesn't have a syntax highlighting theme for Hare. Instead, I'm using the C theme, which may not be exactly accurate when coloring the code below.</p>
</blockquote>
<pre><code class="language-C highlight"><span class="source c">use datetime<span class="punctuation terminator c">;</span>
use fmt<span class="punctuation terminator c">;</span>
use math:<span class="keyword operator ternary c">:</span>random<span class="punctuation terminator c">;</span>

export fn <span class="meta function c"><span class="entity name function c">main</span></span><span class="meta function parameters c"><span class="meta group c"><span class="punctuation section group begin c">(</span></span></span><span class="meta function parameters c"><span class="meta group c"><span class="punctuation section group end c">)</span></span></span><span class="meta function c"> </span><span class="storage type c">void</span> <span class="keyword operator assignment c">=</span> <span class="meta block c"><span class="punctuation section block begin c">{</span>
    <span class="storage modifier c">const</span> rgb <span class="keyword operator assignment c">=</span> <span class="meta function-call c"><span class="variable function c">generate_rgb</span><span class="meta group c"><span class="punctuation section group begin c">(</span></span></span><span class="meta function-call c"></span><span class="meta function-call c"><span class="meta group c"><span class="punctuation section group end c">)</span></span></span><span class="punctuation terminator c">;</span>
    fmt:<span class="keyword operator ternary c">:</span><span class="meta function-call c"><span class="variable function c">printfln</span><span class="meta group c"><span class="punctuation section group begin c">(</span></span></span><span class="meta function-call c"><span class="meta group c"><span class="string quoted double c"><span class="punctuation definition string begin c">&quot;</span>RGB: ({}, {}, {})<span class="punctuation definition string end c">&quot;</span></span><span class="punctuation separator c">,</span> rgb<span class="meta brackets c"><span class="punctuation section brackets begin c">[</span><span class="constant numeric c">0</span><span class="punctuation section brackets end c">]</span></span><span class="punctuation separator c">,</span> rgb<span class="meta brackets c"><span class="punctuation section brackets begin c">[</span><span class="constant numeric c">1</span><span class="punctuation section brackets end c">]</span></span><span class="punctuation separator c">,</span> rgb<span class="meta brackets c"><span class="punctuation section brackets begin c">[</span><span class="constant numeric c">2</span><span class="punctuation section brackets end c">]</span></span></span></span><span class="meta function-call c"><span class="meta group c"><span class="punctuation section group end c">)</span></span></span><span class="keyword operator arithmetic c">!</span><span class="punctuation terminator c">;</span>
<span class="punctuation section block end c">}</span></span><span class="punctuation terminator c">;</span>

fn <span class="meta function c"><span class="entity name function c">generate_rgb</span></span><span class="meta function parameters c"><span class="meta group c"><span class="punctuation section group begin c">(</span></span></span><span class="meta function parameters c"><span class="meta group c"><span class="punctuation section group end c">)</span></span></span><span class="meta function c"> </span><span class="meta brackets c"><span class="punctuation section brackets begin c">[</span><span class="punctuation section brackets end c">]</span></span>u64 <span class="keyword operator assignment c">=</span> <span class="meta block c"><span class="punctuation section block begin c">{</span>
    <span class="comment line double-slash c"><span class="punctuation definition comment c">//</span> Use the current Unix epoch time as the seed value
</span>    let datetime <span class="keyword operator assignment c">=</span> datetime:<span class="keyword operator ternary c">:</span><span class="meta function-call c"><span class="variable function c">epochunix</span><span class="meta group c"><span class="punctuation section group begin c">(</span></span></span><span class="meta function-call c"><span class="meta group c"><span class="keyword operator c">&amp;</span>datetime:<span class="keyword operator ternary c">:</span><span class="meta function-call c"><span class="variable function c">now</span><span class="meta group c"><span class="punctuation section group begin c">(</span></span></span><span class="meta function-call c"></span><span class="meta function-call c"><span class="meta group c"><span class="punctuation section group end c">)</span></span></span></span></span><span class="meta function-call c"><span class="meta group c"><span class="punctuation section group end c">)</span></span></span><span class="punctuation terminator c">;</span>

    <span class="comment line double-slash c"><span class="punctuation definition comment c">//</span> Generate initial pseudo-random value
</span>    <span class="comment line double-slash c"><span class="punctuation definition comment c">//</span> You must cast the datetime from int to u64
</span>    let x <span class="keyword operator assignment c">=</span> random:<span class="keyword operator ternary c">:</span><span class="meta function-call c"><span class="variable function c">init</span><span class="meta group c"><span class="punctuation section group begin c">(</span></span></span><span class="meta function-call c"><span class="meta group c">datetime<span class="keyword operator ternary c">:</span> u64</span></span><span class="meta function-call c"><span class="meta group c"><span class="punctuation section group end c">)</span></span></span><span class="punctuation terminator c">;</span>

    <span class="comment line double-slash c"><span class="punctuation definition comment c">//</span> Generate RGB values between (0, 255) using pseudo-random init value
</span>    let r <span class="keyword operator assignment c">=</span> random:<span class="keyword operator ternary c">:</span><span class="meta function-call c"><span class="variable function c">u64n</span><span class="meta group c"><span class="punctuation section group begin c">(</span></span></span><span class="meta function-call c"><span class="meta group c"><span class="keyword operator c">&amp;</span>x<span class="punctuation separator c">,</span> <span class="constant numeric c">255</span></span></span><span class="meta function-call c"><span class="meta group c"><span class="punctuation section group end c">)</span></span></span><span class="punctuation terminator c">;</span>
    let g <span class="keyword operator assignment c">=</span> random:<span class="keyword operator ternary c">:</span><span class="meta function-call c"><span class="variable function c">u64n</span><span class="meta group c"><span class="punctuation section group begin c">(</span></span></span><span class="meta function-call c"><span class="meta group c"><span class="keyword operator c">&amp;</span>x<span class="punctuation separator c">,</span> <span class="constant numeric c">255</span></span></span><span class="meta function-call c"><span class="meta group c"><span class="punctuation section group end c">)</span></span></span><span class="punctuation terminator c">;</span>
    let b <span class="keyword operator assignment c">=</span> random:<span class="keyword operator ternary c">:</span><span class="meta function-call c"><span class="variable function c">u64n</span><span class="meta group c"><span class="punctuation section group begin c">(</span></span></span><span class="meta function-call c"><span class="meta group c"><span class="keyword operator c">&amp;</span>x<span class="punctuation separator c">,</span> <span class="constant numeric c">255</span></span></span><span class="meta function-call c"><span class="meta group c"><span class="punctuation section group end c">)</span></span></span><span class="punctuation terminator c">;</span>

    <span class="comment line double-slash c"><span class="punctuation definition comment c">//</span> Structure data as array and return
</span>    let rgb_array<span class="keyword operator ternary c">:</span> <span class="meta brackets c"><span class="punctuation section brackets begin c">[</span><span class="constant numeric c">3</span><span class="punctuation section brackets end c">]</span></span>u64 <span class="keyword operator assignment c">=</span> <span class="meta brackets c"><span class="punctuation section brackets begin c">[</span>r<span class="punctuation separator c">,</span> g<span class="punctuation separator c">,</span> b<span class="punctuation section brackets end c">]</span></span><span class="punctuation terminator c">;</span>
    <span class="keyword control c">return</span> rgb_array<span class="punctuation terminator c">;</span>
<span class="punctuation section block end c">}</span></span><span class="punctuation terminator c">;</span></span></code></pre>
<h3 id="running-a-program"><span class="section-number-3">2.3.</span> Running a Program</h3>
<p>Once you have a Hare file written and ready to run, you simply need to run it:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">hare</span></span><span class="meta function-call arguments shell"> run file.ha</span></span></code></pre>
<p>You can also compile the program into an executable:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">hare</span></span><span class="meta function-call arguments shell"> build<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>o</span> example file.ha</span>
<span class="meta function-call shell"><span class="variable function shell">./example</span></span></span></code></pre>
<h3 id="initial-thoughts"><span class="section-number-3">2.4.</span> Initial Thoughts</h3>
<ol>
<li><p>Documentation Improvements Would Help</p>
<p>While I was able to piece everything together eventually, the biggest downfall right now in Hare's documentation. For such a new project, the documentation is in a great spot. However, bare specifications don't help as much as a brief examples section would.</p>
<p>For example, it took me a while to figure out what the <code class="verbatim">u64n</code> function was looking for. I could tell that it took two parameters and the second was my max value (255), but couldn't figure out what the first value should be. Eventually, I inspected the <code class="verbatim">random.ha</code> file in the <a href="https://git.sr.ht/~sircmpwn/hare/tree/master/item/math/random/random.ha">Hare source code</a> and found the test suite that helped me discover that it needed an <code class="verbatim">init()</code> value in the form of <code class="verbatim">&amp;var</code>.</p>
</li>
<li><p>More Basic Modules</p>
<p>This is another point that comes from Hare being new and awaiting more contributions, but there are some basic functions that I would personally enjoy seeing in Hare, such as one to convert decimal (base 10) values to hexadecimal (base 16).</p>
<p>If I'm feeling comfortable with my math, I may work on the list of functions I want and see if any can make it into the Hare source code.</p>
</li>
<li><p>Overall Thoughts</p>
<p>Overall, I actually really enjoy Hare. It's not as tedious to get a project up and running as Rust, but it's also simpler and more user-friendly than learning C. I am going to continue playing with it and see if I can make anything of particular value.</p>
</li>
</ol>
]]></description>
    </item>
    <item>
      <title>Self-Hosting Guide: wger</title>
      <link>https://cleberg.net/blog/self-hosting-wger.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/self-hosting-wger.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Sat, 28 Jan 2023 00:00:00 +0000</pubDate>
      <category>linux</category>
      <category>self-hosting</category>
      <description><![CDATA[<h2 id="wger-the-self-hosted-workout-manager"><span class="section-number-2">1.</span> Wger: The Self-Hosted Workout Manager</h2>
<p><a href="https://wger.de">Wger Workout Manager</a> is a fitness tracking tool for those who enjoy self-hosting their data. You can also register an account on their main website if you'd prefer to try without self-hosting.</p>
<h3 id="features"><span class="section-number-3">1.1.</span> Features</h3>
<p>I didn't see a full listing of features anywhere, so I compiled this list of my own after installing wger:</p>
<ol>
<li>Dashboard<ul>
<li>Dashboard view of Workout Schedule, Nutrition Plan, Weight Graph, &amp; last 5 Weight Logs</li>
</ul>
</li>
<li>Training<ul>
<li>Workout Log</li>
<li>Workout Schedule</li>
<li>Calendar (shows weight logs and Bad/Neutral/Good days)</li>
<li>Gallery (shows images you upload)</li>
<li>Workout templates</li>
<li>Public templates</li>
<li>Exercises</li>
</ul>
</li>
<li>Nutrition<ul>
<li>Nutrition plans</li>
<li>BMI calculator</li>
<li>Daily calories calculator</li>
<li>Ingredient overview</li>
</ul>
</li>
<li>Body Weight<ul>
<li>Weight overview</li>
</ul>
</li>
</ol>
<h3 id="documentation"><span class="section-number-3">1.2.</span> Documentation</h3>
<p>In order to self-host wger, I opted to use the Docker version of the application. You can read the README within the <a href="https://github.com/wger-project/docker">wger-project/docker</a> project on GitHub for information and installation instructions.</p>
<h3 id="installation"><span class="section-number-3">1.3.</span> Installation</h3>
<p>To start the installation, I created a folder for wger and started creating the three necessary files:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">mkdir</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/wger</span> <span class="keyword operator logical and shell">&amp;&amp;</span> <span class="meta function-call shell"><span class="variable function shell">mkdir</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/wger/config</span>
<span class="meta function-call shell"><span class="variable function shell">touch</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/wger/docker-compose.yml</span> <span class="keyword operator logical and shell">&amp;&amp;</span> <span class="punctuation separator continuation line shell">\
</span><span class="meta function-call shell"><span class="variable function shell">touch</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/wger/config/prod.env</span> <span class="keyword operator logical and shell">&amp;&amp;</span> <span class="punctuation separator continuation line shell">\
</span><span class="meta function-call shell"><span class="variable function shell">touch</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/wger/config/nginx.conf</span></span></code></pre>
<p>Once you have the folders and files created, you will need to copy the contents of the <code class="verbatim">docker-compose.yml</code>, <code class="verbatim">prod.env</code>, and <code class="verbatim">nginx.conf</code> from the GitHub link above.</p>
<p>A few notes to explain the changes I made to the default files:</p>
<ul>
<li>I updated the <code class="verbatim">ALLOW_REGISTRAION</code> variable in <code class="verbatim">prod.env</code> to <code class="verbatim">False</code> after I created an account via my LAN connection, <strong>before</strong> I connected this app to a publicly-available domain.</li>
<li>I uncommented and updated <code class="verbatim">CSRF_TRUSTED_ORIGINS</code> to be equal to the public version of this app: <code class="verbatim">https://wger.example.com</code>.</li>
<li>I updated the port within <code class="verbatim">docker-compose.yml</code>, within the <code class="verbatim">nginx</code> block. The port I updated this to will be reflected in my nginx configuration file on the server (NOT the wger nginx.conf file).</li>
</ul>
<h3 id="deploy"><span class="section-number-3">1.4.</span> Deploy</h3>
<p>Once all files are created and modified to your needs, simply start the container.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">docker-compose</span></span><span class="meta function-call arguments shell"> up<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>d</span></span></span></code></pre>
<p>You can now visit the website on your LAN by going to <code class="verbatim">localhost:YOUR_PORT</code> or by the server's IP, if you're not on the same machine that is running the container.</p>
<p>If you wish to connect this app to a public domain name, you'll need to point an <code class="verbatim">A</code> DNS record from the domain to your server's public IP. You'll then need to create a configuration file for whichever web server or reverse proxy you're using.</p>
<p>Wger's README suggests the following reverse proxy configuration for Nginx:</p>
<pre><code class="language-conf">upstream wger {
    # This port should match the port in the `nginx` block of docker-compose.yml
    # If the container is running on this same machine, replace this with
    # server 127.0.0.1:8080
    server 123.456.789.0:8080;
}

server {
    listen 80;
    listen [::]:443 ssl;
    listen 443 ssl;

    location / {
        proxy_pass http://wger;
        proxy_set_header Host $http_host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_redirect off;
    }

    server_name my.domain.example.com;

    ssl_certificate /path/to/https/certificate.crt;
    ssl_certificate_key /path/to/https/certificate.key;
}</code></pre>
<h2 id="thoughts-on-wger"><span class="section-number-2">2.</span> Thoughts on Wger</h2>
<p>I'm still playing around with the app itself, but it seems to be a solid all-around workout manager, weight log, and food log.</p>
<p>I like that the weight log graph is fluid and updates quickly. You can also import or export data in CSV format if you'd like to move your data elsewhere.</p>
<p>The workout manager is slightly odd, as it requires you to enter sets and reps for each exercise when you enter it into the plan. Then, when you add a log entry for performing a workout, you then add what you actually performed, in terms of reps and weight.</p>
<p>I haven't tried the food log yet and I likely will not, at least for a while. I have no need for a food log or calorie tracker at the moment.</p>
]]></description>
    </item>
    <item>
      <title>Random Mullvad WireGuard on Startup</title>
      <link>https://cleberg.net/blog/random-wireguard.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/random-wireguard.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Mon, 23 Jan 2023 00:00:00 +0000</pubDate>
      <category>linux</category>
      <category>security</category>
      <category>self-hosting</category>
      <description><![CDATA[<h2 id="mullvad-wireguard"><span class="section-number-2">1.</span> Mullvad Wireguard</h2>
<p>If you're using an OS that does not support one of Mullvad's apps, you're likely using the Wireguard configuration files instead.</p>
<p>If not, the first step is to visit Mullvad's <a href="https://mullvad.net/en/account/#/wireguard-config">Wireguard configuration files</a> page and download a ZIP of the configuration files you want to use.</p>
<p>Personally, I downloaded all configuration files across the world and chose my connections using the script below.</p>
<p>Once the files are downloaded, unzip them and move them to your preferred location:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="support function cd shell">cd</span></span><span class="meta function-call arguments shell"> Downloads</span>
<span class="meta function-call shell"><span class="variable function shell">unzip</span></span><span class="meta function-call arguments shell"> mullvad_wireguard_linux_all_all.zip</span>
<span class="meta function-call shell"><span class="variable function shell">mkdir</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/mullvad</span> <span class="keyword operator logical and shell">&amp;&amp;</span> <span class="meta function-call shell"><span class="variable function shell">mv</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/Downloads/<span class="keyword operator regexp quantifier shell">*</span>.conf <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/mullvad/</span></span></code></pre>
<h4 id="creating-a-script-to-connect-to-a-random-host"><span class="section-number-4">1.0.1.</span> Creating a Script to Connect to a Random Host</h4>
<p>Once you have a folder of Wireguard configuration files from Mullvad, you can create a script to randomly connect to any one of the locations.</p>
<p>Start by creating a shell script - mine is called <code class="verbatim">vpn.sh</code>.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">nano</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/vpn.sh</span></span></code></pre>
<p>Within this script, you can paste the following info. Note that I specify <code class="verbatim">us-*</code> in my script, which means that it will only consider US-based VPN locations. You can alter this or simply change it <code class="verbatim">*</code> to consider all locations.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell">!/bin/sh</span><span class="comment line number-sign shell">
</span>
<span class="meta function-call shell"><span class="variable function shell">ls</span></span><span class="meta function-call arguments shell"> /home/<span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">USER</span></span>/mullvad/us-<span class="keyword operator regexp quantifier shell">*</span><span class="keyword operator regexp quantifier shell">*</span></span> <span class="keyword operator logical pipe shell">|</span><span class="meta function-call shell"><span class="variable function shell">sort</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>R</span></span> <span class="keyword operator logical pipe shell">|</span><span class="meta function-call shell"><span class="variable function shell">tail</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>n</span> 1</span> <span class="keyword operator logical pipe shell">|</span><span class="keyword control while shell">while</span> <span class="meta function-call shell"><span class="support function read shell">read</span></span><span class="meta function-call arguments shell"> file</span><span class="keyword operator logical continue shell">;</span> <span class="keyword control do shell">do</span>
    <span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> Replace `doas` with `sudo` if your machine uses `sudo`,</span><span class="comment line number-sign shell">
</span>    <span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> or remove `doas` if users don&#39;t need to su to run wg-quick</span><span class="comment line number-sign shell">
</span>    <span class="meta function-call shell"><span class="variable function shell">doas</span></span><span class="meta function-call arguments shell"> wg-quick up <span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">file</span></span></span><span class="keyword operator logical continue shell">;</span>
    <span class="meta function-call shell"><span class="support function printf shell">printf</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>\nCreated Mullvad wireguard connection with file: <span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">file</span></span><span class="punctuation definition string end shell">&quot;</span></span></span><span class="keyword operator logical continue shell">;</span>
    <span class="meta function-call shell"><span class="support function printf shell">printf</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>\n\nPrinting new IP info:\n<span class="punctuation definition string end shell">&quot;</span></span></span>
    <span class="meta function-call shell"><span class="variable function shell">curl</span></span><span class="meta function-call arguments shell"> https://am.i.mullvad.net/connected</span>
<span class="meta function-call shell"><span class="variable function shell">done</span></span></span></code></pre>
<p>Once you've modified the script to your liking, add executable permissions and run the script:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">chmod</span></span><span class="meta function-call arguments shell"> +x <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/vpn.sh</span>
<span class="meta function-call shell"><span class="variable function shell"><span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/vpn.sh</span></span></span></code></pre>
<p>The output should look like the following:</p>
<pre><code class="language-txt highlight"><span class="text plain">doas (user@host) password:

# ... The script will process all of the iptables and wg commands here

Created Mullvad wireguard connection with file: /home/user/mullvad/us-nyc-wg-210.conf

Printing new IP info:
You are connected to Mullvad (server country-city-wg-num). Your IP address is 12.345.678.99</span></code></pre>
<p>That's all there is to it. You can see your new location and IP via the <code class="verbatim">printf</code> and <code class="verbatim">curl</code> commands included in the script.</p>
<p>You can also go to the <a href="https://mullvad.net/en/check/">Connection Check ​| Mullvad</a> page to see if you are fully connected to Mullvad and if any leaks exist.</p>
<h2 id="disconnecting-from-the-wireguard-connection"><span class="section-number-2">2.</span> Disconnecting from the Wireguard Connection</h2>
<p>If you forget which connection you're using, you can execute the following command to see where Wireguard is currently connected:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">wg</span></span><span class="meta function-call arguments shell"> show</span></span></code></pre>
<p>This command will show you the Wireguard interfaces and should output a connection like so: <code class="verbatim">interface: us-lax-wg-104</code>.</p>
<p>Once you have this, just disconnect using that files' full path:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">wg-quick</span></span><span class="meta function-call arguments shell"> down /home/user/mullvad/us-lax-wg-104.conf</span></span></code></pre>
<p>I have a TODO item on figuring out how to easily export an environment variable that contains the configuration file's full name, so that I can just execute the following:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> Ideal situation if I can export the $file variable to the environment</span><span class="comment line number-sign shell">
</span><span class="meta function-call shell"><span class="variable function shell">wg-quick</span></span><span class="meta function-call arguments shell"> down <span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">file</span></span></span></span></code></pre>
<p>If you have an idea on how to do this, email me!</p>
]]></description>
    </item>
    <item>
      <title>Flatpak Symlinks: Shorten the Command</title>
      <link>https://cleberg.net/blog/flatpak-symlinks.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/flatpak-symlinks.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Sat, 21 Jan 2023 00:00:00 +0000</pubDate>
      <category>linux</category>
      <description><![CDATA[<h2 id="running-flatpak-apps-should-be-faster"><span class="section-number-2">1.</span> Running Flatpak Apps Should Be Faster</h2>
<p>If you're like me and use Flatpak for those pesky apps that cannot run on your system for one reason or another, you likely get annoyed with opening a terminal and manually running the Flatpak app with the lengthy <code class="verbatim">flatpak run ...</code> command.</p>
<p>In the past, I manually created aliases in my <code class="verbatim">.zshrc</code> file for certain apps. For example, an alias would look like the example below.</p>
<p>This would allow me to run the command fast within the terminal, but it wouldn't allow me to run it in an application launcher.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> ~/.zshrc</span><span class="comment line number-sign shell">
</span><span class="meta function-call shell"><span class="support function alias shell">alias</span> <span class="entity name function alias shell">librewolf</span> <span class="keyword operator assignment shell">=</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>flatpak run io.gitlab.librewolf-community<span class="punctuation definition string end shell">&quot;</span></span></span></span></code></pre>
<p>However, I now use a much faster and better method that integrates with the tiling WMs I use and their application launchers - <code class="verbatim">dmenu</code> and <code class="verbatim">bemenu</code>.</p>
<h2 id="creating-symlinks-for-flatpak-apps"><span class="section-number-2">2.</span> Creating Symlinks for Flatpak Apps</h2>
<p>Let's use the example of Librewolf below. I can install the application like so:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">flatpak</span></span><span class="meta function-call arguments shell"> install flathub io.gitlab.librewolf-community</span></span></code></pre>
<p>Once installed, I can create a symlink to link the flatpak app to my new symlink in a location commonly included in your PATH. In this case, I chose <code class="verbatim">/usr/bin</code>. You may need to choose a different location if <code class="verbatim">/usr/bin</code> isn't in your PATH.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">ln</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>s</span> /var/lib/flatpak/exports/bin/io.gitlab.librewolf-community /usr/bin/librewolf</span></span></code></pre>
<p>Once complete, you should be able to launch the app using the command name you chose above in the symlink (<code class="verbatim">librewolf</code>) from a terminal or from your application launcher!</p>
]]></description>
    </item>
    <item>
      <title>Fedora i3: Remove the Login Manager</title>
      <link>https://cleberg.net/blog/fedora-login-manager.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/fedora-login-manager.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Sun, 08 Jan 2023 00:00:00 +0000</pubDate>
      <category>linux</category>
      <description><![CDATA[<h2 id="fedora-i3-s-login-manager"><span class="section-number-2">1.</span> Fedora i3's Login Manager</h2>
<p>Since I use the i3 spin of Fedora Workstation, I don't like to have a login manager installed by default. As of the current version of Fedora i3, the default login manager is LightDM.</p>
<p>If this is no longer the case, you can search for currently-installed packages with the following command and see if you can identify a different login manager.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> dnf list installed</span></span></code></pre>
<h2 id="removing-the-login-manager"><span class="section-number-2">2.</span> Removing the Login Manager</h2>
<p>In order to remove the login manager, simply uninstall the package.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> dnf remove lightdm</span></span></code></pre>
<h2 id="launching-i3-manually"><span class="section-number-2">3.</span> Launching i3 Manually</h2>
<p>In order to launch i3 manually, you need to set up your X session properly. To start, create or edit the <code class="verbatim">~/.xinitrc</code> file to include the following at the bottom.</p>
<pre><code class="language-config">exec i3</code></pre>
<p>Now, whenever you log in to the TTY, you can launch your desktop with the following command.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">startx</span></span></span></code></pre>
]]></description>
    </item>
    <item>
      <title>Mass Unlike All Tumblr Posts</title>
      <link>https://cleberg.net/blog/mass-unlike-tumblr-posts.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/mass-unlike-tumblr-posts.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Thu, 05 Jan 2023 00:00:00 +0000</pubDate>
      <category>linux</category>
      <category>personal</category>
      <description><![CDATA[<h2 id="the-dilemma"><span class="section-number-2">1.</span> The Dilemma</h2>
<p>The dilemma I had was pretty simple: I wanted to unlike all the posts I have liked on Tumblr so that I could follow a new focus on blogs and start fresh. Otherwise, Tumblr will keep recommending content based on your previous likes.</p>
<h2 id="the-solution"><span class="section-number-2">2.</span> The Solution</h2>
<p>I searched the web for a while and noted that most solutions referenced Tumblr setting and dashboard pages that no longer exist. Additionally, I did not want to install a third party extension to do this, as some suggested.</p>
<p>Luckily, I used Javascript for a while a few years ago and figured it would be easy enough to script a solution, as long as Tumblr had a system for the unlike buttons.</p>
<h3 id="identifying-unlike-buttons"><span class="section-number-3">2.1.</span> Identifying Unlike Buttons</h3>
<p>Tumblr's unlike buttons are structured as you can see in the following code block. All unlike buttons have an <code class="verbatim">aria-label</code> with a value of <code class="verbatim">Unlike</code>.</p>
<pre><code class="language-html highlight"><span class="text html basic"><span class="meta tag inline form html"><span class="punctuation definition tag begin html">&lt;</span><span class="entity name tag inline form html">button</span> <span class="meta attribute-with-value class html"><span class="entity other attribute-name class html">class</span><span class="punctuation separator key-value html">=</span></span><span class="meta attribute-with-value class html"><span class="string quoted double html"><span class="punctuation definition string begin html">&quot;</span></span></span><span class="meta attribute-with-value class html"><span class="string quoted double html"><span class="meta class-name html">TRX6J</span><span class="punctuation definition string end html">&quot;</span></span></span> <span class="meta attribute-with-value html"><span class="entity other attribute-name html">aria-label</span><span class="punctuation separator key-value html">=</span></span><span class="meta attribute-with-value html"><span class="string quoted double html"><span class="punctuation definition string begin html">&quot;</span>Unlike<span class="punctuation definition string end html">&quot;</span></span></span><span class="punctuation definition tag end html">&gt;</span></span>
    <span class="meta tag inline any html"><span class="punctuation definition tag begin html">&lt;</span><span class="entity name tag inline any html">span</span> <span class="meta attribute-with-value class html"><span class="entity other attribute-name class html">class</span><span class="punctuation separator key-value html">=</span></span><span class="meta attribute-with-value class html"><span class="string quoted double html"><span class="punctuation definition string begin html">&quot;</span></span></span><span class="meta attribute-with-value class html"><span class="string quoted double html"><span class="meta class-name html">EvhBA B1Z5w ztpfZ</span><span class="punctuation definition string end html">&quot;</span></span></span> <span class="meta attribute-with-value html"><span class="entity other attribute-name html">tabindex</span><span class="punctuation separator key-value html">=</span></span><span class="meta attribute-with-value html"><span class="string quoted double html"><span class="punctuation definition string begin html">&quot;</span>-1<span class="punctuation definition string end html">&quot;</span></span></span><span class="punctuation definition tag end html">&gt;</span></span>
        <span class="meta tag other html"><span class="punctuation definition tag begin html">&lt;</span><span class="entity name tag other html">svg</span>
            <span class="meta attribute-with-value html"><span class="entity other attribute-name html">xmlns</span><span class="punctuation separator key-value html">=</span></span><span class="meta attribute-with-value html"><span class="string quoted double html"><span class="punctuation definition string begin html">&quot;</span>http://www.w3.org/2000/svg<span class="punctuation definition string end html">&quot;</span></span></span>
            <span class="meta attribute-with-value html"><span class="entity other attribute-name html">height</span><span class="punctuation separator key-value html">=</span></span><span class="meta attribute-with-value html"><span class="string quoted double html"><span class="punctuation definition string begin html">&quot;</span>21<span class="punctuation definition string end html">&quot;</span></span></span>
            <span class="meta attribute-with-value html"><span class="entity other attribute-name html">width</span><span class="punctuation separator key-value html">=</span></span><span class="meta attribute-with-value html"><span class="string quoted double html"><span class="punctuation definition string begin html">&quot;</span>23<span class="punctuation definition string end html">&quot;</span></span></span>
            <span class="meta attribute-with-value html"><span class="entity other attribute-name html">role</span><span class="punctuation separator key-value html">=</span></span><span class="meta attribute-with-value html"><span class="string quoted double html"><span class="punctuation definition string begin html">&quot;</span>presentation<span class="punctuation definition string end html">&quot;</span></span></span>
        <span class="punctuation definition tag end html">&gt;</span></span>
            <span class="meta tag other html"><span class="punctuation definition tag begin html">&lt;</span><span class="entity name tag other html">use</span> <span class="meta attribute-with-value html"><span class="entity other attribute-name html">href</span><span class="punctuation separator key-value html">=</span></span><span class="meta attribute-with-value html"><span class="string quoted double html"><span class="punctuation definition string begin html">&quot;</span>#managed-icon__like-filled<span class="punctuation definition string end html">&quot;</span></span></span><span class="punctuation definition tag end html">&gt;</span></span><span class="meta tag other html"><span class="punctuation definition tag begin html">&lt;/</span><span class="entity name tag other html">use</span><span class="punctuation definition tag end html">&gt;</span></span>
        <span class="meta tag other html"><span class="punctuation definition tag begin html">&lt;/</span><span class="entity name tag other html">svg</span><span class="punctuation definition tag end html">&gt;</span></span>
    <span class="meta tag inline any html"><span class="punctuation definition tag begin html">&lt;/</span><span class="entity name tag inline any html">span</span><span class="punctuation definition tag end html">&gt;</span></span>
<span class="meta tag inline form html"><span class="punctuation definition tag begin html">&lt;/</span><span class="entity name tag inline form html">button</span><span class="punctuation definition tag end html">&gt;</span></span></span></code></pre>
<h3 id="running-a-script-to-unlike-all-likes"><span class="section-number-3">2.2.</span> Running a Script to Unlike All Likes</h3>
<p>To run this script, you will need to load the <a href="https://www.tumblr.com/likes">Likes | Tumblr</a> page while logged in to your account.</p>
<p>Further, be sure to scroll down to the bottom and force Tumblr to load more posts so that this script unlikes more posts at a time.</p>
<p>Once you are logged in and the page is loaded, open the Developer Tools and be sure you're on the "Console" tab. It should look something like this (this is in Firefox, Chromium should be similar):</p>
<figure><img src="https://img.cleberg.net/blog/20230105-mass-unlike-tumblr-posts/dev_console.webp" alt="Firefox Dev Tools' Console tab will allow you to paste this command."><figcaption><span class="figure-number">Figure 1: </span>Firefox Dev Tools</figcaption></figure>
<p>All you need to do is paste the following snippet into the dev console. This code will collect all unlike buttons (<code class="verbatim">elements</code>) and then click each button to unlike it.</p>
<p>Optionally, you can comment-out the line <code class="verbatim">elements[i].click();</code> and uncomment the <code class="verbatim">console.log()</code> lines to simply print out information without performing any actions. This can be useful to debug issues or confirm that the code below isn't doing anything you don't want it to.</p>
<pre><code class="language-javascript highlight"><span class="source js"><span class="storage type js">const</span> <span class="variable other readwrite js">elements</span> <span class="keyword operator assignment js">=</span> <span class="support type object dom js">document</span><span class="punctuation accessor js">.</span><span class="meta function-call method js"><span class="variable function js">querySelectorAll</span><span class="meta group js"><span class="punctuation section group js">(</span><span class="string quoted single js"><span class="punctuation definition string begin js">&#39;</span>[aria-label=&quot;Unlike&quot;]<span class="punctuation definition string end js">&#39;</span></span></span><span class="meta group js"><span class="punctuation section group js">)</span></span></span><span class="punctuation terminator statement js">;</span>
<span class="comment line double-slash js"><span class="punctuation definition comment js">//</span> console.log(elements); // 👉 [button]
</span>
<span class="meta for js"><span class="keyword control loop js">for</span> <span class="meta group js"><span class="punctuation section group js">(</span><span class="storage type js">let</span> <span class="variable other readwrite js">i</span> <span class="keyword operator assignment js">=</span> <span class="constant numeric js">0</span><span class="punctuation terminator statement js">;</span> <span class="variable other readwrite js">i</span> <span class="keyword operator relational js">&lt;</span> <span class="variable other object js">elements</span><span class="punctuation accessor js">.</span><span class="meta property object js">length</span><span class="punctuation terminator statement js">;</span> <span class="variable other readwrite js">i</span><span class="keyword operator arithmetic js">++</span><span class="punctuation section group js">)</span></span> <span class="meta block js"><span class="punctuation section block js">{</span>
    <span class="comment line double-slash js"><span class="punctuation definition comment js">//</span> console.log(elements[i]);
</span>    <span class="variable other object js">elements</span><span class="meta brackets js"><span class="punctuation section brackets js">[</span><span class="variable other readwrite js">i</span><span class="punctuation section brackets js">]</span></span><span class="punctuation accessor js">.</span><span class="meta function-call method js"><span class="support function dom js">click</span><span class="meta group js"><span class="punctuation section group js">(</span></span><span class="meta group js"><span class="punctuation section group js">)</span></span></span><span class="punctuation terminator statement js">;</span>
</span><span class="meta block js"><span class="punctuation section block js">}</span></span></span></span></code></pre>
<h2 id="results"><span class="section-number-2">3.</span> Results</h2>
<p>The results were quick for my situation, as it unliked ~200 posts within 2-3 seconds. I am not sure how this will perform on larger sets of likes (or if Tumblr has a limit to unliking posts).</p>
<p>You can see the below screenshot showing that I pasted the snippet into the console, pressed Enter, and then the posts are automatically unliked.</p>
<figure><img src="https://img.cleberg.net/blog/20230105-mass-unlike-tumblr-posts/script_results.webp" alt="undefined when run in the console."><figcaption><span class="figure-number">Figure 2: </span>Script Results</figcaption></figure>
<p>Thinking about this further, I would bet that this would be fairly simple to package into a browser add-on so that users could install the add-on, go to their Likes page, and click a button to run the script. Food for thought.</p>
]]></description>
    </item>
    <item>
      <title>Website Updates 2023</title>
      <link>https://cleberg.net/blog/recent-website-changes.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/recent-website-changes.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Tue, 03 Jan 2023 00:00:00 +0000</pubDate>
      <category>personal</category>
      <category>web</category>
      <description><![CDATA[<h2 id="the-state-of-this-website"><span class="section-number-2">1.</span> The State of This Website</h2>
<p>Over the years, this website has changed URLs, styles, content focus, and much more. However, it seems that I am never done, as I am yet again changing this page to fit my current needs and wants.</p>
<p>While this site was already minimal (~12kb), it contained a lot of disorganized content and some poorly chosen color schemes.</p>
<p>The recent updates attempt to fix these items while focusing on what I truly care about here: the content within each page.</p>
<h2 id="recent-changes"><span class="section-number-2">2.</span> Recent Changes</h2>
<p>I've made quite a few changes to the style of this website today, both in the CSS and in the HTML.</p>
<p>Here are some of the key takeaways from today's changes:</p>
<ol>
<li>Reduce the width of the website from <code class="verbatim">60em</code> to <code class="verbatim">40em</code>.</li>
<li>Remove breadcrumb navigation and replaced with a simple "Return Home" link when visiting anything other than the homepage.</li>
<li>Remove syntax highlighting from code blocks. CSS now loads from a single file.</li>
<li>Move blog posts on the homepage to the top, pushing tertiary content down.</li>
<li>Update font-family from <code class="verbatim">monospace</code> to <code class="verbatim">sans-serif</code> for readability.</li>
</ol>
<h2 id="future-focus"><span class="section-number-2">3.</span> Future Focus</h2>
<h3 id="accessibility"><span class="section-number-3">3.1.</span> Accessibility</h3>
<p>My main focus amidst all the changes this past year was accessibility. I tried to improve the accessibility of all pages on this site as well as I know how. For example, I added aria labels to identify different navigation menus in November.</p>
<p>I want to continue this in 2023 and learn more about the accessibility features I can utilize to help those who may need them.</p>
<h3 id="content-first"><span class="section-number-3">3.2.</span> Content First</h3>
<p>Beyond accessibility, I am making a concerted effort to bring the content of this site to the forefront and push the tertiary information (e.g., About Me, Services, etc.) down below the content.</p>
<p>Further, I want to review and edit previous blog posts for grammar, accuracy, dead links, and more. Where necessary, I may even add a blurb at the top of old posts that are no longer accurate or helpful.</p>
<h3 id="style"><span class="section-number-3">3.3.</span> Style</h3>
<p>As always, I will be searching for ways to reduce distractions and bring a minimalistic approach to this site. While there are certainly more drastic measures I could take, such as making this a <a href="https://shinobi.bt.ht">Shinobi Website</a> or a <a href="https://nocss.club">No CSS Website</a>, I prefer to keep some modern features here.</p>
<p>Two ideas have been floating around in my head, but I am not sure how I feel about these approaches yet:</p>
<ol>
<li>Going all-in with Emacs org-mode and creating a script to auto-publish all my blog posts from org-mode to plain HTML files and then letting my CSS style it after the fact.</li>
<li>Focus on publishing for Gemini or Gopher and then utilize a conversion program to translate the pages to HTML.</li>
</ol>
<h2 id="looking-back"><span class="section-number-2">4.</span> Looking Back</h2>
<p>As I sit here and finalize the changes, as well as this post, I am happy with the current state of this website. It's certainly a long way from my first attempts (parallax background images, anyone?) and it's good to see the progress.</p>
<p>I can only hope and work hard to ensure that I make more meaningful progress by this time next year.</p>
]]></description>
    </item>
    <item>
      <title>Alpine Desktop with Sway</title>
      <link>https://cleberg.net/blog/alpine-desktop.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/alpine-desktop.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Fri, 23 Dec 2022 00:00:00 +0000</pubDate>
      <category>linux</category>
      <description><![CDATA[<h2 id="isn-t-alpine-linux-for-servers"><span class="section-number-2">1.</span> Isn't Alpine Linux for Servers?</h2>
<p>This is a question I see a lot when people are presented with an example of Alpine Linux running as a desktop operating system (OS).</p>
<p>While Alpine is small, fast, and minimal, that doesn't stop it from functioning at a productive level for desktop users.</p>
<p>This post is documentation of how I installed and modified Alpine Linux to become my daily desktop OS.</p>
<h2 id="installation"><span class="section-number-2">2.</span> Installation</h2>
<p>Note that I cover the installation of Alpine Linux in my other post, so I won't repeat it here: <a href="https://cleberg.net/blog/alpine-linux.html">Alpine Linux Essentials: Installing and Setting Up a Secure Minimal Server</a>.</p>
<p>Basically, get a bootable USB (Universal Serial Bus) device or whatever you prefer with Alpine on it, boot the optical disc image (ISO), and run the setup script.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">setup-alpine</span></span></span></code></pre>
<p>Once you have gone through all the options and installer finishes without errors, reboot.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">reboot</span></span></span></code></pre>
<h2 id="initial-setup"><span class="section-number-2">3.</span> Initial Setup</h2>
<p>Once Alpine is installed and the machine has rebooted, login is as root initially or <code class="verbatim">su</code> to root once you log in as your user. From here, you should start by updating and upgrading the system in case the ISO was not fully up-to-date.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> Update and upgrade system</span><span class="comment line number-sign shell">
</span><span class="meta function-call shell"><span class="variable function shell">apk</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>U</span> update</span> <span class="keyword operator logical and shell">&amp;&amp;</span> <span class="meta function-call shell"><span class="variable function shell">apk</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>U</span> upgrade</span>

<span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> Add an editor so we can enable the community repository</span><span class="comment line number-sign shell">
</span><span class="meta function-call shell"><span class="variable function shell">apk</span></span><span class="meta function-call arguments shell"> add nano</span></span></code></pre>
<p>You need to uncomment the <code class="verbatim">community</code> repository for your version of Alpine Linux.</p>
<p>For v3.17, the <code class="verbatim">repositories</code> file should look like this:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">nano</span></span><span class="meta function-call arguments shell"> /etc/apk/repositories</span></span></code></pre>
<pre><code class="language-conf">#/media/sda/apks
http://mirrors.gigenet.com/alpinelinux/v3.17/main
http://mirrors.gigenet.com/alpinelinux/v3.17/community
#http://mirrors.gigenet.com/alpinelinux/edge/main
#http://mirrors.gigenet.com/alpinelinux/edge/community
#http://mirrors.gigenet.com/alpinelinux/edge/testing</code></pre>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> Add the rest of your packages</span><span class="comment line number-sign shell">
</span><span class="meta function-call shell"><span class="variable function shell">apk</span></span><span class="meta function-call arguments shell"> add linux-firmware iwd doas git curl wget</span>

<span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> Add yourself to the wheel group so you can use the doas command</span><span class="comment line number-sign shell">
</span><span class="meta function-call shell"><span class="variable function shell">adduser</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">USER</span></span> wheel</span></span></code></pre>
<h2 id="window-manager-desktop"><span class="section-number-2">4.</span> Window Manager (Desktop)</h2>
<p>The <a href="https://wiki.alpinelinux.org/wiki/Sway">Sway installation guide</a> has everything you need to get Sway working on Alpine.</p>
<p>However, I'll include a brief list of the commands I ran and their purpose for posterity here.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> Add eudev and set it up</span><span class="comment line number-sign shell">
</span><span class="meta function-call shell"><span class="variable function shell">apk</span></span><span class="meta function-call arguments shell"> add eudev</span>
<span class="meta function-call shell"><span class="variable function shell">setup-devd</span></span><span class="meta function-call arguments shell"> udev</span>

<span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> Since I have Radeon graphics, I need the following packages</span><span class="comment line number-sign shell">
</span><span class="meta function-call shell"><span class="variable function shell">apk</span></span><span class="meta function-call arguments shell"> add mesa-dri-gallium mesa-va-gallium</span>

<span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> Add user to applicable groups</span><span class="comment line number-sign shell">
</span><span class="meta function-call shell"><span class="variable function shell">adduser</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">USER</span></span> input</span>
<span class="meta function-call shell"><span class="variable function shell">adduser</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">USER</span></span> video</span>

<span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> Add a font package</span><span class="comment line number-sign shell">
</span><span class="meta function-call shell"><span class="variable function shell">apk</span></span><span class="meta function-call arguments shell"> add ttf-dejavu</span>

<span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> Add the seatd daemon</span><span class="comment line number-sign shell">
</span><span class="meta function-call shell"><span class="variable function shell">apk</span></span><span class="meta function-call arguments shell"> add seatd</span>
<span class="meta function-call shell"><span class="variable function shell">rc-update</span></span><span class="meta function-call arguments shell"> add seatd</span>
<span class="meta function-call shell"><span class="variable function shell">rc-service</span></span><span class="meta function-call arguments shell"> seatd start</span>

<span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> Add user to seat group</span><span class="comment line number-sign shell">
</span><span class="meta function-call shell"><span class="variable function shell">adduser</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">USER</span></span> seat</span>

<span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> Add elogind</span><span class="comment line number-sign shell">
</span><span class="meta function-call shell"><span class="variable function shell">apk</span></span><span class="meta function-call arguments shell"> add elogind polkit-elogind</span>
<span class="meta function-call shell"><span class="variable function shell">rc-update</span></span><span class="meta function-call arguments shell"> add elogind</span>
<span class="meta function-call shell"><span class="variable function shell">rc-service</span></span><span class="meta function-call arguments shell"> elogind start</span>

<span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> Finally, add sway and dependencies</span><span class="comment line number-sign shell">
</span><span class="meta function-call shell"><span class="variable function shell">apk</span></span><span class="meta function-call arguments shell"> add sway sway-doc</span>
<span class="meta function-call shell"><span class="variable function shell">apk</span></span><span class="meta function-call arguments shell"> add                <span class="constant character escape shell">\ </span># Install optional dependencies:</span>
    <span class="meta function-call shell"><span class="variable function shell">xwayland</span></span><span class="meta function-call arguments shell">             <span class="constant character escape shell">\ </span># recommended for compatibility reasons</span>
    <span class="meta function-call shell"><span class="variable function shell">foot</span></span><span class="meta function-call arguments shell">                 <span class="constant character escape shell">\ </span># default terminal emulator</span>
    <span class="meta function-call shell"><span class="variable function shell">bemenu</span></span><span class="meta function-call arguments shell">               <span class="constant character escape shell">\ </span># wayland menu</span>
    <span class="meta function-call shell"><span class="variable function shell">swaylock</span></span><span class="meta function-call arguments shell"> swaylockd   <span class="constant character escape shell">\ </span># lockscreen tool</span>
    <span class="meta function-call shell"><span class="variable function shell">swaybg</span></span><span class="meta function-call arguments shell">               <span class="constant character escape shell">\ </span># wallpaper daemon</span>
    <span class="meta function-call shell"><span class="variable function shell">swayidle               <span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> idle management (DPMS) daemon</span></span></span></span></code></pre>
<p>Once you have the packages installed and set-up, you need to export the <code class="verbatim">XDG_RUNTIME_DIR</code> upon login. To do this, edit your <code class="verbatim">.profile</code> file.</p>
<p>If you use another shell, such as <code class="verbatim">zsh</code>, you need to edit that shell's profile (e.g., <code class="verbatim">~/.zprofile</code>)!</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">nano</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/.profile</span></span></code></pre>
<p>Within the file, paste this:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="keyword control if begin shell">if</span> <span class="meta function-call shell"><span class="variable function shell">test</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>z</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section expansion parameter begin shell">{</span></span><span class="meta group expansion parameter shell"><span class="variable other readwrite shell">XDG_RUNTIME_DIR</span></span><span class="meta group expansion parameter shell"><span class="punctuation section expansion parameter end shell">}</span></span><span class="punctuation definition string end shell">&quot;</span></span></span><span class="keyword operator logical continue shell">;</span> <span class="keyword control if then shell">then</span>
<span class="meta function-call shell">  <span class="storage modifier shell">export</span> <span class="variable other readwrite assignment shell">XDG_RUNTIME_DIR</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell">/tmp/<span class="meta group expansion command parens shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section parens begin shell">(</span><span class="meta function-call shell"><span class="variable function shell">id</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>u</span></span><span class="punctuation section parens end shell">)</span></span>-runtime-dir</span></span>
  <span class="keyword control if begin shell">if</span> <span class="keyword operator logical shell">!</span> <span class="meta function-call shell"><span class="variable function shell">test</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>d</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section expansion parameter begin shell">{</span></span><span class="meta group expansion parameter shell"><span class="variable other readwrite shell">XDG_RUNTIME_DIR</span></span><span class="meta group expansion parameter shell"><span class="punctuation section expansion parameter end shell">}</span></span><span class="punctuation definition string end shell">&quot;</span></span></span><span class="keyword operator logical continue shell">;</span> <span class="keyword control if then shell">then</span>
    <span class="meta function-call shell"><span class="variable function shell">mkdir</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section expansion parameter begin shell">{</span></span><span class="meta group expansion parameter shell"><span class="variable other readwrite shell">XDG_RUNTIME_DIR</span></span><span class="meta group expansion parameter shell"><span class="punctuation section expansion parameter end shell">}</span></span><span class="punctuation definition string end shell">&quot;</span></span></span>
    <span class="meta function-call shell"><span class="variable function shell">chmod</span></span><span class="meta function-call arguments shell"> 0700 <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section expansion parameter begin shell">{</span></span><span class="meta group expansion parameter shell"><span class="variable other readwrite shell">XDG_RUNTIME_DIR</span></span><span class="meta group expansion parameter shell"><span class="punctuation section expansion parameter end shell">}</span></span><span class="punctuation definition string end shell">&quot;</span></span></span>
  <span class="keyword control if end shell">fi</span>
<span class="meta function-call shell"><span class="variable function shell">fi</span></span></span></code></pre>
<p>Once that's complete, you can launch Sway manually.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">dbus-run-session</span></span><span class="meta function-call arguments shell"><span class="keyword operator end-of-options shell"> --</span></span><span class="meta function-call arguments shell"> sway</span></span></code></pre>
<h3 id="personal-touches"><span class="section-number-3">4.1.</span> Personal Touches</h3>
<p>I also added the following packages, per my personal preferences and situation.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">doas</span></span><span class="meta function-call arguments shell"> apk add brightnessctl   <span class="constant character escape shell">\ </span># Brightness controller</span>
             <span class="meta function-call shell"><span class="variable function shell">zsh</span></span><span class="meta function-call arguments shell">             <span class="constant character escape shell">\ </span># Shell</span>
             <span class="meta function-call shell"><span class="variable function shell">firefox</span></span><span class="meta function-call arguments shell">         <span class="constant character escape shell">\ </span># Browser</span>
             <span class="meta function-call shell"><span class="variable function shell">syncthing</span></span><span class="meta function-call arguments shell">       <span class="constant character escape shell">\ </span># File sync service</span>
             <span class="meta function-call shell"><span class="variable function shell">wireguard-tools</span></span><span class="meta function-call arguments shell"> <span class="constant character escape shell">\ </span># Wireguard VPN</span>
             <span class="meta function-call shell"><span class="variable function shell">gomuks</span></span><span class="meta function-call arguments shell">          <span class="constant character escape shell">\ </span># CLI Matrix client</span>
             <span class="meta function-call shell"><span class="variable function shell">neomutt</span></span><span class="meta function-call arguments shell">         <span class="constant character escape shell">\ </span># CLI email client</span>
             <span class="meta function-call shell"><span class="variable function shell">thunderbird</span></span><span class="meta function-call arguments shell">     <span class="constant character escape shell">\ </span># GUI email client</span>
             <span class="meta function-call shell"><span class="variable function shell">gnupg             <span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> GPG key manager</span></span></span></span></code></pre>
<p>From here, I use my Syncthing storage to pull all the configuration files I stored from prior desktops, such as my dotfiles.</p>
<h2 id="resolving-issues"><span class="section-number-2">5.</span> Resolving Issues</h2>
<h3 id="wifi-issues"><span class="section-number-3">5.1.</span> WiFi Issues</h3>
<p>I initially tried to set up my Wi-Fi the standard way with <code class="verbatim">iwd</code>, but it didn't work.</p>
<p>Here is what I initially tried (I did all of this as <code class="verbatim">root</code>):</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">apk</span></span><span class="meta function-call arguments shell"> add iwd</span>
<span class="meta function-call shell"><span class="variable function shell">rc-service</span></span><span class="meta function-call arguments shell"> iwd start</span>
<span class="meta function-call shell"><span class="variable function shell">iwctl</span></span><span class="meta function-call arguments shell"> station wlan0 connect <span class="keyword operator assignment redirection shell">&lt;</span>SSID<span class="keyword operator assignment redirection shell">&gt;</span> # This will prompt for the password</span>
<span class="meta function-call shell"><span class="variable function shell">rc-update</span></span><span class="meta function-call arguments shell"> add iwd boot</span> <span class="keyword operator logical and shell">&amp;&amp;</span> <span class="meta function-call shell"><span class="variable function shell">rc-update</span></span><span class="meta function-call arguments shell"> add dbus boot</span></span></code></pre>
<p>Then, I added the Wi-Fi entry to the bottom of the networking interface file:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">nano</span></span><span class="meta function-call arguments shell"> /etc/network/interfaces</span></span></code></pre>
<pre><code class="language-conf">auto wlan0
iface wlan0 inet dhcp</code></pre>
<p>Finally, restart the networking service:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">rc-service</span></span><span class="meta function-call arguments shell"> networking restart</span></span></code></pre>
<p>My Wi-Fi interface would receive an internet protocol (IP) address from the router, but it could not ping anything in the network. To solve the Wi-Fi issues, I originally upgraded to Alpine's <code class="verbatim">edge</code> repositories, which was unnecessary.</p>
<p>Really, the solution was to enable the <code class="verbatim">NameResolvingService=resolvconf</code> in <code class="verbatim">/etc/iwd/main.conf</code>.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">doas</span></span><span class="meta function-call arguments shell"> nano /etc/iwd/main.conf</span></span></code></pre>
<pre><code class="language-conf">[Network]

NameResolvingService=resolvconf</code></pre>
<p>Once I finished this process, my Wi-Fi is working flawlessly.</p>
<h3 id="sound-issues"><span class="section-number-3">5.2.</span> Sound Issues</h3>
<p>Same as with the Wi-Fi, I had no sound and could not control the mute/unmute or volume buttons on my laptop.</p>
<p>To resolve this, I installed <a href="https://wiki.alpinelinux.org/wiki/PipeWire">pipewire</a>.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> Add your user to the following groups</span><span class="comment line number-sign shell">
</span><span class="meta function-call shell"><span class="variable function shell">addgroup</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">USER</span></span> audio</span>
<span class="meta function-call shell"><span class="variable function shell">addgroup</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">USER</span></span> video</span>

<span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> Install pipewire and other useful packages</span><span class="comment line number-sign shell">
</span><span class="meta function-call shell"><span class="variable function shell">apk</span></span><span class="meta function-call arguments shell"> add pipewire wireplumber pipewire-pulse pipewire-jack pipewire-alsa</span></span></code></pre>
<p>Finally, I needed to add <code class="verbatim">/usr/libexec/pipewire-launcher</code> to my <code class="verbatim">.config/sway/config</code> file so that Pipewire would run every time I launched sway.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">nano</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/.config/sway/config</span></span></code></pre>
<pre><code class="language-conf"># Run pipewire audio server
exec /usr/libexec/pipewire-launcher

# Example audio button controls
bindsym XF86AudioRaiseVolume exec --no-startup-id pactl set-sink-volume @DEFAULT_SINK@ +5%
bindsym XF86AudioLowerVolume exec --no-startup-id pactl set-sink-volume @DEFAULT_SINK@ -5%
bindsym XF86AudioMute exec --no-startup-id pactl set-sink-mute @DEFAULT_SINK@ toggle
bindsym XF86AudioMicMute exec --no-startup-id pactl set-source-mute @DEFAULT_SOURCE@ toggle</code></pre>
<p>Note that I do not use bluetooth or screen sharing, so I won't cover those options in this post.</p>
<p>Other than these issues, I have a working Alpine desktop. No other complaints thus far!</p>
]]></description>
    </item>
    <item>
      <title>Suckless Simple Terminal on Fedora</title>
      <link>https://cleberg.net/blog/st.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/st.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Sat, 17 Dec 2022 00:00:00 +0000</pubDate>
      <category>linux</category>
      <description><![CDATA[<h2 id="st"><span class="section-number-2">1.</span> st</h2>
<p><a href="https://st.suckless.org">st</a> standards for Simple Terminal, a simple terminal implementation for X made by the <a href="https://suckless.org">suckless</a> team.</p>
<p>This post walks through the dependencies needed and process to build and install <code class="verbatim">st</code> on Fedora Workstation.</p>
<h3 id="obtain-files"><span class="section-number-3">1.1.</span> Obtain Files</h3>
<p>To start, obtain the source files for <code class="verbatim">st</code> via <code class="verbatim">git clone</code>.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">mkdir</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/suckless</span> <span class="keyword operator logical and shell">&amp;&amp;</span> <span class="meta function-call shell"><span class="support function cd shell">cd</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/suckless</span>
<span class="meta function-call shell"><span class="variable function shell">git</span></span><span class="meta function-call arguments shell"> clone https://git.suckless.org/st</span> <span class="keyword operator logical and shell">&amp;&amp;</span> <span class="meta function-call shell"><span class="support function cd shell">cd</span></span><span class="meta function-call arguments shell"> st</span></span></code></pre>
<h3 id="dependencies"><span class="section-number-3">1.2.</span> Dependencies</h3>
<p>Once you have the files and are in the <code class="verbatim">st</code> directory, ensure the following packages are installed.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> dnf update</span> <span class="keyword operator logical and shell">&amp;&amp;</span> <span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> dnf upgrade</span>
<span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> dnf install gcc patch libX11-devel libXft-devel</span></span></code></pre>
<h3 id="building"><span class="section-number-3">1.3.</span> Building</h3>
<p>Before building, ensure that you read the README file.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">cat</span></span><span class="meta function-call arguments shell"> README</span></span></code></pre>
<p>Once you've read the instructions, open the <code class="verbatim">config.mk</code> file and ensure it matches your setup. If you're not sure, leave the default options within the file.</p>
<p>Finally, you can build <code class="verbatim">st</code> with the following command. Ensure you run as root (e.g., <code class="verbatim">sudo</code>) or else you may not end up with a usable application file.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> make clean install</span></span></code></pre>
<h3 id="customization-patches"><span class="section-number-3">1.4.</span> Customization (Patches)</h3>
<p>Note that customizing <code class="verbatim">st</code> requires you to modify the source files or to download one of the <a href="https://st.suckless.org/patches/">available patches</a> for suckless.org.</p>
<p>If you've already installed <code class="verbatim">st</code> and want to customize or install a patch, start by uninstalling the current program.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="support function cd shell">cd</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/suckless/st</span>
<span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> make uninstall</span></span></code></pre>
<p>Next, grab the <code class="verbatim">&lt;path&gt;.diff</code> file from the page of the patch you chose. For example, I will be using the <a href="https://st.suckless.org/patches/defaultfontsize/">defaultfontsize</a> patch in the below example.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">wget</span></span><span class="meta function-call arguments shell"> https://st.suckless.org/patches/defaultfontsize/st-defaultfontsize-20210225-4ef0cbd.diff</span></span></code></pre>
<p>Once the file is downloaded inside the <code class="verbatim">st</code> folder, apply the patch and re-install the program. You may need to install the <code class="verbatim">patch</code> command if you don't have it installed already (you should have installed it above).</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">patch</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>i</span> st-defaultfontsize-20210225-4ef0cbd.diff</span>
<span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> make clean install</span></span></code></pre>
<p>Once installed, you can use the default font size patch to launch <code class="verbatim">st</code> with any font size you wish:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">st</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>z</span> 16</span></span></code></pre>
]]></description>
    </item>
    <item>
      <title>Nginx Wildcard Redirects</title>
      <link>https://cleberg.net/blog/nginx-wildcard-redirect.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/nginx-wildcard-redirect.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Wed, 07 Dec 2022 00:00:00 +0000</pubDate>
      <category>web</category>
      <description><![CDATA[<h2 id="problem"><span class="section-number-2">1.</span> Problem</h2>
<p>I recently migrated domains and replaced the old webpage with a simple info page with instructions to users on how to edit their bookmarks and URLs to get to the page they were seeking.</p>
<p>This was not ideal as it left the work up to the user and may have caused friction for users who accessed my RSS (Really Simple Syndication) feed.</p>
<h2 id="solution"><span class="section-number-2">2.</span> Solution</h2>
<p>Instead, I finally found a solution that allows me to redirect both subdomains AND trailing content. For example, both of these URLs now redirect properly using the logic I'll explain below:</p>
<pre><code class="language-txt highlight"><span class="text plain"># Example 1 - Simple base domain redirect with trailing content
https://domain1.com/blog/alpine-linux/ -&gt; https://domain2.com/blog/alpine-linux/

# Example 2 - Complex redirect with both a subdomain and trailing content
https://libreddit.domain1.com/r/history/comments/7z8cbg/new_discovery_mode_turns_video_game_assassins/
-&gt;
https://libreddit.domain2.com/r/history/comments/7z8cbg/new_discovery_mode_turns_video_game_assassins/</span></code></pre>
<p>Go ahead, try the URLs (uniform resource locators) if you want to test them.</p>
<h3 id="nginx-config"><span class="section-number-3">2.1.</span> Nginx Config</h3>
<p>To make this possible. I needed to configure a proper redirect scheme in my Nginx configuration.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">doas</span></span><span class="meta function-call arguments shell"> nano /etc/nginx/http.d/domain1.conf</span></span></code></pre>
<p>Within this file, I had one block configured to redirect HTTP requests to HTTPS for the base domain and all subdomains.</p>
<pre><code class="language-conf">server {
        listen [::]:80;
        listen 80;
        server_name domain1.com *.domain1.com;

        if ($host = domain1.com) {
                return 301 https://$host$request_uri;
        }

        if ($host = *.domain1.com) {
                return 301 https://$host$request_uri;
        }

        return 404;
}</code></pre>
<p>For the base domain, I have another <code class="verbatim">server</code> block dedicated to redirecting all base domain requests. You can see that the <code class="verbatim">rewrite</code> line is instructing Nginx to gather all trailing content and append it to the new <code class="verbatim">domain2.com</code> URL.</p>
<pre><code class="language-conf">server {
        listen [::]:443 ssl http2;
        listen 443 ssl http2;

        server_name domain1.com;

        rewrite ^/(.*)$ https://domain2.com/$1 permanent;

        ssl_certificate     /etc/letsencrypt/live/domain1.com/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/domain1.com/privkey.pem;
}</code></pre>
<p>Finally, the tricky part is figuring out how to tell Nginx to redirect while keeping both a subdomain and trailing content intact. I found that the easiest way to do this is to give it a <code class="verbatim">server</code> block of its own.</p>
<p>Within this block, we need to do some regex on the <code class="verbatim">server_name</code> line before we can rewrite anything. This creates a variable called <code class="verbatim">subdomain</code>.</p>
<p>Once the server gets to the <code class="verbatim">rewrite</code> line, it pulls the <code class="verbatim">subdomain</code> variable from above and uses it on the new <code class="verbatim">domain2.com</code> domain before appending the trailing content (<code class="verbatim">$request_uri</code>).</p>
<pre><code class="language-conf">server {
        listen [::]:443 ssl http2;
        listen 443 ssl http2;

        server_name ~^(?&lt;subdomain&gt;\w+)\.domain1\.com$;

        rewrite ^ https://$subdomain.domain2.com$request_uri permanent;

        ssl_certificate     /etc/letsencrypt/live/domain1.com/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/domain1.com/privkey.pem;
}</code></pre>
<p>That's all there is to it. With this, I simply restarted Nginx and watched the redirections work in-action.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">doas</span></span><span class="meta function-call arguments shell"> rc-service nginx restart</span></span></code></pre>
<p>Looking back on it, I wish I had done this sooner. Who knows how many people went looking for my sites or bookmarks and gave up when they saw the redirect instructions page.</p>
<p>Oh well, it's done now. Live and learn.</p>
]]></description>
    </item>
    <item>
      <title>Nginx Gzip: Compress Text, Nothing Else</title>
      <link>https://cleberg.net/blog/nginx-compression.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/nginx-compression.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Thu, 01 Dec 2022 00:00:00 +0000</pubDate>
      <category>linux</category>
      <category>web</category>
      <description><![CDATA[<h2 id="text-compression"><span class="section-number-2">1.</span> Text Compression</h2>
<p>Text compression allows a web server to serve text-based resources faster than uncompressed data. This can speed up things like First Contentful Paint, Tie to Interactive, and Speed Index.</p>
<h2 id="enable-nginx-compression-with-gzip"><span class="section-number-2">2.</span> Enable Nginx Compression with gzip</h2>
<p>In order to enable text compression on Nginx, we need to enable it within the configuration file:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">nano</span></span><span class="meta function-call arguments shell"> /etc/nginx/nginx.conf</span></span></code></pre>
<p>Within the <code class="verbatim">http</code> block, find the section that shows something like the block below. This is the default gzip configuration I found in my <code class="verbatim">nginx.conf</code> file on Alpine Linux 3.17. Yours may look slightly different, just make sure that you're not creating any duplicate gzip options.</p>
<pre><code class="language-conf"># Enable gzipping of responses.
#gzip on;

# Set the Vary HTTP header as defined in the RFC 2616. Default is 'off'.
gzip_vary on;</code></pre>
<p>Remove the default gzip lines and replace them with the following:</p>
<pre><code class="language-conf"># Enable gzipping of responses.
gzip on;
gzip_vary on;
gzip_min_length 10240;
gzip_proxied expired no-cache no-store private auth;
gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/xml;
gzip_disable "MSIE [1-6]";</code></pre>
<h2 id="explanations-of-ngx-httpgzipmodule-options"><span class="section-number-2">3.</span> Explanations of ngx<sub>httpgzipmodule</sub> Options</h2>
<p>Each of the lines above enables a different aspect of the gzip response for Nginx. Here are the full explanations:</p>
<ul>
<li><code class="verbatim">gzip</code>: Enables or disables gzipping of responses.</li>
<li><code class="verbatim">gzip_vary</code>: Enables or disables inserting the "Vary: Accept-Encoding" response header field if the directives gzip, gzip<sub>static</sub>, or gunzip are active.</li>
<li><code class="verbatim">gzip_min_length</code>: Sets the minimum length of a response that will be gzipped. The length is determined only from the "Content-Length" response header field.</li>
<li><code class="verbatim">gzip_proxied</code>: Enables or disables gzipping of responses for proxied requests depending on the request and response. The fact that the request is proxied is determined by the presence of the "Via" request header field.</li>
<li><code class="verbatim">gzip_types</code>: Enables gzipping of responses for the specified MIME types in addition to "text/html". The special value "*" matches any MIME type (0.8.29). Responses with the "text/html" type are always compressed.</li>
<li><code class="verbatim">gzip_disable</code>: Disables gzipping of responses for requests with "User-Agent" header fields matching any of the specified regular expressions.<ul>
<li>The special mask "msie6" (0.7.12) corresponds to the regular expression "MSIE [4-6].", but works faster. Starting from version 0.8.11, "MSIE 6.0; … SV1" is excluded from this mask.</li>
</ul>
</li>
</ul>
<p>More information on these directives and their options can be found on the <a href="https://nginx.org/en/docs/http/ngx_http_gzip_module.html">Module ngx<sub>httpgzipmodule</sub></a> page in Nginx's documentation.</p>
]]></description>
    </item>
    <item>
      <title>Nginx Referrer Ban List</title>
      <link>https://cleberg.net/blog/nginx-referrer-ban-list.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/nginx-referrer-ban-list.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Tue, 29 Nov 2022 00:00:00 +0000</pubDate>
      <category>linux</category>
      <category>web</category>
      <description><![CDATA[<h2 id="creating-the-ban-list"><span class="section-number-2">1.</span> Creating the Ban List</h2>
<p>In order to ban list referral domains or websites with Nginx, you need to create a ban list file. The file below will accept regexes for different domains or websites you wish to block.</p>
<p>First, create the file in your nginx directory:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">doas</span></span><span class="meta function-call arguments shell"> nano /etc/nginx/banlist.conf</span></span></code></pre>
<p>Next, paste the following contents in and fill out the regexes with whichever domains you're blocking.</p>
<pre><code class="language-conf"># /etc/nginx/banlist.conf

map $http_referer $bad_referer {
    hostnames;

    default                           0;

    # Put regexes for undesired referrers here
    "~news.ycombinator.com"           1;
}</code></pre>
<h2 id="configuring-nginx"><span class="section-number-2">2.</span> Configuring Nginx</h2>
<p>In order for the ban list to work, Nginx needs to know it exists and how to handle it. For this, edit the <code class="verbatim">nginx.conf</code> file.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">doas</span></span><span class="meta function-call arguments shell"> nano /etc/nginx/nginx.conf</span></span></code></pre>
<p>Within this file, find the <code class="verbatim">http</code> block and add your ban list file location to the end of the block.</p>
<pre><code class="language-conf"># /etc/nginx/nginx.conf

http {
  ...

  # Include ban list
  include /etc/nginx/banlist.conf;
}</code></pre>
<h2 id="enabling-the-ban-list"><span class="section-number-2">3.</span> Enabling the Ban List</h2>
<p>Finally, we need to take action when a bad referral site is found. To do so, edit the configuration file for your website. For example, I have all website configuration files in the <code class="verbatim">http.d</code> directory. You may have them in the <code class="verbatim">sites-available</code> directory on some distributions.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">doas</span></span><span class="meta function-call arguments shell"> nano /etc/nginx/http.d/example.com.conf</span></span></code></pre>
<p>Within each website's configuration file, edit the <code class="verbatim">server</code> blocks that are listening to ports 80 and 443 and create a check for the <code class="verbatim">$bad_referrer</code> variable we created in the ban list file.</p>
<p>If a matching site is found, you can return any <a href="https://en.wikipedia.org/wiki/List_of_HTTP_status_codes">HTTP Status Code</a> you want. Code 403 (Forbidden) is logical in this case since you are preventing a client connection due to a banned domain.</p>
<pre><code class="language-conf">server {
  ...

  # If a referral site is banned, return an error
  if ($bad_referer) {
    return 403;
  }

  ...
}</code></pre>
<h2 id="restart-nginx"><span class="section-number-2">4.</span> Restart Nginx</h2>
<p>Lastly, restart Nginx to enable all changes made.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">doas</span></span><span class="meta function-call arguments shell"> rc-service nginx restart</span></span></code></pre>
<h2 id="testing-results"><span class="section-number-2">5.</span> Testing Results</h2>
<p>In order to test the results, let's curl the contents of our site. To start, I'll curl the site normally:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">curl</span></span><span class="meta function-call arguments shell"> https://cleberg.net</span></span></code></pre>
<p>The HTML contents of the page come back successfully:</p>
<pre><code class="language-html highlight"><span class="text html basic"><span class="meta tag sgml html"><span class="punctuation definition tag html">&lt;!</span><span class="meta tag sgml doctype html"><span class="entity name tag doctype html">doctype</span> html</span><span class="punctuation definition tag html">&gt;</span></span>...<span class="meta tag structure any html"><span class="punctuation definition tag begin html">&lt;/</span><span class="entity name tag structure any html">html</span><span class="punctuation definition tag end html">&gt;</span></span></span></code></pre>
<p>Next, let's include a banned referrer:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">curl</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> --</span>referer</span> https://news.ycombinator.com https://cleberg.net</span></span></code></pre>
<p>This time, I'm met with a 403 Forbidden response page. That means we are successful and any clients being referred from a banned domain will be met with this same response code.</p>
<pre><code class="language-html highlight"><span class="text html basic"><span class="meta tag structure any html"><span class="punctuation definition tag begin html">&lt;</span><span class="entity name tag structure any html">html</span><span class="punctuation definition tag end html">&gt;</span></span>
    <span class="meta tag structure any html"><span class="punctuation definition tag begin html">&lt;</span><span class="entity name tag structure any html">head</span><span class="punctuation definition tag end html">&gt;</span></span>
        <span class="meta tag inline any html"><span class="punctuation definition tag begin html">&lt;</span><span class="entity name tag inline any html">title</span><span class="punctuation definition tag end html">&gt;</span></span>403 Forbidden<span class="meta tag inline any html"><span class="punctuation definition tag begin html">&lt;/</span><span class="entity name tag inline any html">title</span><span class="punctuation definition tag end html">&gt;</span></span>
    <span class="meta tag structure any html"><span class="punctuation definition tag begin html">&lt;/</span><span class="entity name tag structure any html">head</span><span class="punctuation definition tag end html">&gt;</span></span>
    <span class="meta tag structure any html"><span class="punctuation definition tag begin html">&lt;</span><span class="entity name tag structure any html">body</span><span class="punctuation definition tag end html">&gt;</span></span>
        <span class="meta tag block any html"><span class="punctuation definition tag begin html">&lt;</span><span class="entity name tag block any html">center</span><span class="punctuation definition tag end html">&gt;</span></span><span class="meta tag block any html"><span class="punctuation definition tag begin html">&lt;</span><span class="entity name tag block any html">h1</span><span class="punctuation definition tag end html">&gt;</span></span>403 Forbidden<span class="meta tag block any html"><span class="punctuation definition tag begin html">&lt;/</span><span class="entity name tag block any html">h1</span><span class="punctuation definition tag end html">&gt;</span></span><span class="meta tag block any html"><span class="punctuation definition tag begin html">&lt;/</span><span class="entity name tag block any html">center</span><span class="punctuation definition tag end html">&gt;</span></span>
        <span class="meta tag block any html"><span class="punctuation definition tag begin html">&lt;</span><span class="entity name tag block any html">hr</span><span class="punctuation definition tag end html"> /&gt;</span></span>
        <span class="meta tag block any html"><span class="punctuation definition tag begin html">&lt;</span><span class="entity name tag block any html">center</span><span class="punctuation definition tag end html">&gt;</span></span>nginx<span class="meta tag block any html"><span class="punctuation definition tag begin html">&lt;/</span><span class="entity name tag block any html">center</span><span class="punctuation definition tag end html">&gt;</span></span>
    <span class="meta tag structure any html"><span class="punctuation definition tag begin html">&lt;/</span><span class="entity name tag structure any html">body</span><span class="punctuation definition tag end html">&gt;</span></span>
<span class="meta tag structure any html"><span class="punctuation definition tag begin html">&lt;/</span><span class="entity name tag structure any html">html</span><span class="punctuation definition tag end html">&gt;</span></span></span></code></pre>
]]></description>
    </item>
    <item>
      <title>Server Build: Rack Hardware, Consumer Parts</title>
      <link>https://cleberg.net/blog/server-build.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/server-build.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Sun, 27 Nov 2022 00:00:00 +0000</pubDate>
      <category>linux</category>
      <description><![CDATA[<h2 id="the-dilemma"><span class="section-number-2">1.</span> The Dilemma</h2>
<p>For years, I have been using desktops and a Raspberry Pi as the backbone of my homelab. I have always wanted to move toward a single dedicated server that could handle all of my tasks, but was often put off by the complexity of the choices (and financial roadblocks at some times).</p>
<p>However, after purchasing a small server rack this past year, I have been researching to see what kind of rack-mounted server I could buy. I initially bought a Dell R720XD loaded up with everything I could ever want in a server - but I did not care for it. It was far too loud, and the age of the CPU/RAM was something I wanted to improve upon.</p>
<p>After returning the R720XD, I decided that I wanted to build my own server with modern, consumer-grade PC components. This time, I am very happy with the results of my server.</p>
<h2 id="components"><span class="section-number-2">2.</span> Components</h2>
<p>I'll start by listing all the components I used for this server build:</p>
<ul>
<li><strong>Case</strong>: <a href="https://www.rosewill.com/rosewill-rsv-r4100u-black/p/9SIA072GJ92825">Rosewill RSV-R4100U 4U Server Chassis Rackmount Case</a></li>
<li><strong>Motherboard</strong>: <a href="https://nzxt.com/product/n7-b550">NZXT B550</a></li>
<li><strong>CPU</strong>: AMD Ryzen 7 5700G with Radeon Graphics</li>
<li><strong>GPU</strong>: N/A - I specifically chose one of the few AMD CPUs that support onboard graphics.</li>
<li><strong>RAM</strong>: 64GB RAM (2x32GB) <em>Max of 128GB RAM on this motherboard</em></li>
<li><strong>Boot Drive</strong>: Western Digital 500GB M.2 NVME SSD</li>
<li><strong>HDD Bay</strong>:<ul>
<li>10TB WD White <em>(shucked, moved from previous server)</em></li>
<li>8TB WD White <em>(shucked, moved from previous server)</em></li>
<li>2 x 8TB WD Red Plus <em>(Black Friday lined up perfectly with this build, so I grabbed two of these)</em></li>
</ul>
</li>
<li><strong>PSU</strong>: Corsair RM850 PSU</li>
<li><strong>Extras</strong>:<ul>
<li>Corsair TM3Q Thermal Paste</li>
<li>Noctua 120mm fan <em>(replacement for front case fan)</em></li>
<li>2 x Noctua 80mm fans <em>(replacement for rear case fans)</em></li>
<li>CableMatters 6Gbps SATA Cables</li>
</ul>
</li>
</ul>
<h2 id="building-the-server"><span class="section-number-2">3.</span> Building the Server</h2>
<p>This took quite a while for me to build (in my opinion of time), totaling around 3 hours from start to finish. The case has some peculiar construction, so you have to completely remove the ODD &amp; HDD cages to install the motherboard and other components first.</p>
<p>Now, I've never built a computer of any kind before, so I was quite nervous. Personally, the only challenging part was getting the CPU cooler to screw into the motherboard without sliding the thermal paste around too much underneath. I'm still not entirely sure if I did a great job of it, but nothing's broken yet.</p>
<p>The main components were all fine and simple. However, installing the hard drives is slightly tedious as I need to power off the server and completely unscrew the HDD cage to install or remove any drives. Additionally, the drives are screwed directly into the metal cage with small screws, which are quite a bit different from the HDD trays I'm used to in other machines.</p>
<p>Seeing that the cases with hot-swap bays were 3-4x the price, I'm okay dealing with the tedium of removing the cage to install new drives.</p>
<h2 id="software"><span class="section-number-2">4.</span> Software</h2>
<p>I'm not going to dive into the software as I have done so in other recent posts. However, I wanted to note that I am using Alpine Linux on this server and hosting most services inside Docker. No virtual machines (VMs) and very few bare-metal services.</p>
<h2 id="the-results"><span class="section-number-2">5.</span> The Results</h2>
<p>How did my build turn out? Well, after migrating my other servers and their services over, I found that my server is blazing fast. The heaviest of my applications, Plex, is handled with ease. Even 4k streaming seems to be effortless.</p>
<p>I am very happy with the results and will likely continue to improve on this server as the years go by rather than buying another used server online.</p>
<h3 id="mistakes-i-made"><span class="section-number-3">5.1.</span> Mistakes I Made</h3>
<p>This post wouldn't be complete unless I wrote about the mistakes I made while building. The only real mistake I made beyond a "whoops I dropped a screw" related to airflow and fan direction.</p>
<p>While installing the two new hard drives that showed up on 2022-11-30 and getting ready to install the case in my rack, I noticed that the hard drive temperatures were quite high.</p>
<p>I used the <code class="verbatim">smartctl</code> command for each of my drives (<code class="verbatim">/dev/sda</code> through <code class="verbatim">/dev/sdd</code>):</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">doas</span></span><span class="meta function-call arguments shell"> smartctl<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>a</span> /dev/sda</span> <span class="keyword operator logical pipe shell">|</span> <span class="meta function-call shell"><span class="variable function shell">grep</span></span><span class="meta function-call arguments shell"> Temperature_Celsius</span></span></code></pre>
<p>The results were unusual - all four drives were idling at ~44-46 degrees Celsius. The only drive that was cooler was my 10TB drive, which was at 38 degrees Celsius. I noted that this 10TB drive was also closest to the case fan.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">ID#</span></span><span class="meta function-call arguments shell"> ATTRIBUTE_NAME          FLAG     VALUE WORST THRESH TYPE      UPDATED  WHEN_FAILED RAW_VALUE</span>
<span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> /dev/sda</span><span class="comment line number-sign shell">
</span><span class="meta function-call shell"><span class="variable function shell">194</span></span><span class="meta function-call arguments shell"> Temperature_Celsius     0x0002   147   147   000    Old_age   Always       -     44 (Min/Max 22/46</span><span class="meta function-call shell"></span><span class="meta post-cmd shell">)</span>
<span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> /dev/sdb</span><span class="comment line number-sign shell">
</span><span class="meta function-call shell"><span class="variable function shell">194</span></span><span class="meta function-call arguments shell"> Temperature_Celsius     0x0002   141   141   000    Old_age   Always       -     46 (Min/Max 21/48</span><span class="meta function-call shell"></span><span class="meta post-cmd shell">)</span>
<span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> /dev/sdc</span><span class="comment line number-sign shell">
</span><span class="meta function-call shell"><span class="variable function shell">194</span></span><span class="meta function-call arguments shell"> Temperature_Celsius     0x0002   144   144   000    Old_age   Always       -     45 (Min/Max 19/61</span><span class="meta function-call shell"></span><span class="meta post-cmd shell">)</span>
<span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> /dev/sdd</span><span class="comment line number-sign shell">
</span><span class="meta function-call shell"><span class="variable function shell">194</span></span><span class="meta function-call arguments shell"> Temperature_Celsius     0x0002   171   171   000    Old_age   Always       -     38 (Min/Max 14/56</span><span class="meta function-call shell"></span><span class="meta post-cmd shell">)</span></span></code></pre>
<p>After looking to see if I could fit more fans into the case, I noticed that the 120mm fan used for intake from the front of the case was actually pushing air out of the case by mistake. This fan sits right in front of the hard drive bay.</p>
<p>Once I flipped the fan around to act as an intake fan, the temperatures dropped immediately! They are now idling at ~31-33 degrees Celsius. A single fan spinning the wrong way caused my drives to idle 10-15 degrees higher than they should have.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">ID#</span></span><span class="meta function-call arguments shell"> ATTRIBUTE_NAME          FLAG     VALUE WORST THRESH TYPE      UPDATED  WHEN_FAILED RAW_VALUE</span>
<span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> /dev/sda</span><span class="comment line number-sign shell">
</span><span class="meta function-call shell"><span class="variable function shell">194</span></span><span class="meta function-call arguments shell"> Temperature_Celsius     0x0002   209   209   000    Old_age   Always       -     31 (Min/Max 14/56</span><span class="meta function-call shell"></span><span class="meta post-cmd shell">)</span>
<span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> /dev/sdb</span><span class="comment line number-sign shell">
</span><span class="meta function-call shell"><span class="variable function shell">194</span></span><span class="meta function-call arguments shell"> Temperature_Celsius     0x0002   196   196   000    Old_age   Always       -     33 (Min/Max 19/61</span><span class="meta function-call shell"></span><span class="meta post-cmd shell">)</span>
<span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> /dev/sdc</span><span class="comment line number-sign shell">
</span><span class="meta function-call shell"><span class="variable function shell">194</span></span><span class="meta function-call arguments shell"> Temperature_Celsius     0x0002   203   203   000    Old_age   Always       -     32 (Min/Max 21/48</span><span class="meta function-call shell"></span><span class="meta post-cmd shell">)</span>
<span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> /dev/sdd</span><span class="comment line number-sign shell">
</span><span class="meta function-call shell"><span class="variable function shell">194</span></span><span class="meta function-call arguments shell"> Temperature_Celsius     0x0002   196   196   000    Old_age   Always       -     33 (Min/Max 22/46</span><span class="meta function-call shell"></span><span class="meta post-cmd shell">)</span></span></code></pre>
<p>This was a silly error to make, but I'm glad I found it today before I screwed the case into the rack and made things a lot more tedious to fix.</p>
]]></description>
    </item>
    <item>
      <title>Fixing Nginx Permission Denied Errors on /var/lib/nginx</title>
      <link>https://cleberg.net/blog/nginx-tmp-errors.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/nginx-tmp-errors.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Fri, 11 Nov 2022 00:00:00 +0000</pubDate>
      <category>web</category>
      <description><![CDATA[<p><em>This is a brief post so that I personally remember the solution as it has occurred multiple times for me.</em></p>
<h2 id="the-problem"><span class="section-number-2">1.</span> The Problem</h2>
<p>After migrating to a new server operating system (OS), I started receiving quite a few permission errors like the one below. These popped up for various different websites I'm serving via Nginx on this server, but did not prevent the website from loading.</p>
<p>I found the errors in the standard log file:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">cat</span></span><span class="meta function-call arguments shell"> /var/log/nginx/error.log</span></span></code></pre>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">2022/11/11</span></span><span class="meta function-call arguments shell"> 11:30:34 <span class="keyword control regexp set begin shell">[</span>crit<span class="keyword control regexp set end shell">]</span> 8970#8970: <span class="keyword operator regexp quantifier shell">*</span>10 open(</span><span class="meta function-call shell"></span><span class="meta post-cmd shell">)</span> <span class="meta function-call shell"><span class="variable function shell"><span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>/var/lib/nginx/tmp/proxy/3/00/0000000003<span class="punctuation definition string end shell">&quot;</span></span></span></span><span class="meta function-call arguments shell"> failed (13: Permission denied</span><span class="meta function-call shell"></span><span class="meta post-cmd shell">)</span> <span class="keyword control while shell">while</span> <span class="meta function-call shell"><span class="variable function shell">reading</span></span><span class="meta function-call arguments shell"> upstream, client: 169.150.203.10, server: cyberchef.example.com, request: <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>GET /assets/main.css HTTP/2.0<span class="punctuation definition string end shell">&quot;</span></span>, upstream: <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>http://127.0.0.1:8111/assets/main.css<span class="punctuation definition string end shell">&quot;</span></span>, host: <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>cyberchef.example.com<span class="punctuation definition string end shell">&quot;</span></span>, referrer: <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>https://cyberchef.example.com/<span class="punctuation definition string end shell">&quot;</span></span></span></span></code></pre>
<p>You can see that the error is <code class="verbatim">13: Permission denied</code> and it occurs in the <code class="verbatim">/var/lib/nginx/tmp/</code> directory. In my case, I had thousands of errors where Nginx was denied permission to read/write files in this directory.</p>
<p>So how do I fix it?</p>
<h2 id="the-solution"><span class="section-number-2">2.</span> The Solution</h2>
<p>In order to resolve the issue, I had to ensure the <code class="verbatim">/var/lib/nginx</code> directory is owned by Nginx. Mine was owned by the <code class="verbatim">www</code> user and Nginx was not able to read or write files within that directory. This prevented Nginx from caching temporary files.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> Alpine Linux</span><span class="comment line number-sign shell">
</span><span class="meta function-call shell"><span class="variable function shell">doas</span></span><span class="meta function-call arguments shell"> chown<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>R</span> nginx:nginx /var/lib/nginx</span>

<span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> Other Distros</span><span class="comment line number-sign shell">
</span><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> chown<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>R</span> nginx:nginx /var/lib/nginx</span></span></code></pre>
<p>You <em>may</em> also be able to change the <code class="verbatim">proxy_temp_path</code> in your Nginx config, but I did not try this. Here's a suggestion I found online that may work if the above solution does not:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">nano</span></span><span class="meta function-call arguments shell"> /etc/nginx/http.d/example.com.conf</span></span></code></pre>
<pre><code class="language-conf">server {
  ...

  # Set the proxy_temp_path to your preference, make sure it's owned by the
  # `nginx` user
  proxy_temp_path /tmp;

  ...
}</code></pre>
<p>Finally, restart Nginx and your server should be able to cache temporary files again.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> Alpine Linux (OpenRC)</span><span class="comment line number-sign shell">
</span><span class="meta function-call shell"><span class="variable function shell">doas</span></span><span class="meta function-call arguments shell"> rc-service nginx restart</span>

<span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> Other Distros (systemd)</span><span class="comment line number-sign shell">
</span><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> systemctl restart nginx</span></span></code></pre>
]]></description>
    </item>
    <item>
      <title>Self-Hosting Guide: Matrix Synapse</title>
      <link>https://cleberg.net/blog/self-hosting-matrix.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/self-hosting-matrix.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Mon, 07 Nov 2022 00:00:00 +0000</pubDate>
      <category>linux</category>
      <category>self-hosting</category>
      <description><![CDATA[<h2 id="synapse"><span class="section-number-2">1.</span> Synapse</h2>
<p>If you're reading this, you likely know that <a href="https://github.com/matrix-org/synapse/">Synapse</a> is a popular <a href="https://matrix.org/">Matrix</a> home server software that allows users to run their own Matrix home server.</p>
<p>This post is a short guide describing how I was able to get Synapse working in a minimally-usable state on Alpine Linux.</p>
<h2 id="installation-process"><span class="section-number-2">2.</span> Installation Process</h2>
<h3 id="dependencies"><span class="section-number-3">2.1.</span> Dependencies</h3>
<p>First, since there is no Alpine-specific package for Synapse, we need to ensure that Alpine has the required dependencies for the Python-based installation method.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">doas</span></span><span class="meta function-call arguments shell"> apk<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>U</span> update</span>
<span class="meta function-call shell"><span class="variable function shell">doas</span></span><span class="meta function-call arguments shell"> apk add python3 py3-virtualenv</span></span></code></pre>
<p>Next, we need to set up a Python virtual environment for Synapse:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">mkdir</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>p</span> <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/synapse</span> <span class="keyword operator logical and shell">&amp;&amp;</span> <span class="meta function-call shell"><span class="support function cd shell">cd</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/synapse</span>
<span class="meta function-call shell"><span class="variable function shell">virtualenv</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>p</span> python3 <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/synapse/env</span>
<span class="meta function-call shell"><span class="support function source shell">source</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/synapse/env/bin/activate</span>
<span class="meta function-call shell"><span class="variable function shell">pip</span></span><span class="meta function-call arguments shell"> install<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> --</span>upgrade</span> pip</span>
<span class="meta function-call shell"><span class="variable function shell">pip</span></span><span class="meta function-call arguments shell"> install<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> --</span>upgrade</span> setuptools</span>
<span class="meta function-call shell"><span class="variable function shell">pip</span></span><span class="meta function-call arguments shell"> install matrix-synapse</span></span></code></pre>
<h3 id="running-synapse"><span class="section-number-3">2.2.</span> Running Synapse</h3>
<p>Once installed, running Synapse is easy. Simply execute the following command, replacing <code class="verbatim">example.com</code> with the domain name that will be used with this home server. This will generate the configuration files needed to run the server.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">python</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>m</span> synapse.app.homeserver <span class="punctuation separator continuation line shell">\
</span><span class="variable parameter option shell"><span class="punctuation definition parameter shell">    --</span>server-name</span> example.com <span class="punctuation separator continuation line shell">\
</span><span class="variable parameter option shell"><span class="punctuation definition parameter shell">    --</span>config-path</span> homeserver.yaml <span class="punctuation separator continuation line shell">\
</span><span class="variable parameter option shell"><span class="punctuation definition parameter shell">    --</span>generate-config</span> <span class="punctuation separator continuation line shell">\
</span><span class="variable parameter option shell"><span class="punctuation definition parameter shell">    --</span>report-stats</span><span class="keyword operator assignment option shell">=</span>no</span></span></code></pre>
<p>Once the configuration is generated, we can start up the Synapse server:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">synctl</span></span><span class="meta function-call arguments shell"> start</span></span></code></pre>
<h3 id="configuring-synapse"><span class="section-number-3">2.3.</span> Configuring Synapse</h3>
<p>To make any change to Synapse, we need to edit the <code class="verbatim">YAML</code> configuration file:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">nano</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/synapse/homeserver.yaml</span></span></code></pre>
<p>For now, we just need to ensure the <code class="verbatim">server_name</code> is accurate. However, there are a lot of other configuration options found in the <a href="https://matrix-org.github.io/synapse/develop/usage/configuration/config_documentation.html">Configuring Synapse</a> documentation that can be enabled/disabled at any point.</p>
<pre><code class="language-yaml highlight"><span class="source yaml"><span class="string unquoted plain out yaml"><span class="entity name tag yaml">server_name</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string quoted double yaml"><span class="punctuation definition string begin yaml">&quot;</span>example.com<span class="punctuation definition string end yaml">&quot;</span></span></span></code></pre>
<p>Make sure to restart Synapse when you make changes to the configuration:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">synctl</span></span><span class="meta function-call arguments shell"> restart</span></span></code></pre>
<h3 id="nginx-reverse-proxy"><span class="section-number-3">2.4.</span> Nginx Reverse-Proxy</h3>
<p>To ensure that Synapse is reachable from the public, we need to connect our domain to the Synapse server. In my case, I use a Nginx reverse-proxy for this purpose.</p>
<p>To use Nginx, we need to create a reverse-proxy configuration file:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">doas</span></span><span class="meta function-call arguments shell"> nano /etc/nginx/http.d/example.com.conf</span></span></code></pre>
<p>If you already have TLS (Transport Layer Security) certificates for this domain (<code class="verbatim">example.com</code>), you can simply use the SSL (Secure Socket Layer) configuration and point toward your TLS certificates.</p>
<pre><code class="language-conf">server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;

    # For the federation port
    listen 8448 ssl http2;
    listen [::]:8448 ssl http2;

    server_name example.com;

    location ~ ^(/_matrix|/_synapse/client) {
        # note: do not add a path (even a single /) after the port in `proxy_pass`,
        # otherwise nginx will canonicalise the URI and cause signature verification
        # errors.
        proxy_pass http://localhost:8008;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header Host $host;

        # Nginx by default only allows file uploads up to 1M in size
        # Increase client_max_body_size to match max_upload_size defined in homeserver.yaml
        client_max_body_size 50M;
    }

    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
    access_log /var/log/nginx/matrix.access.log;
}

server {
    if ($host = example.com) {
        return 301 https://$host$request_uri;
    }

  server_name example.com;
  listen 80;
    return 404;
}</code></pre>
<p>If you need to generate TLS certificates (I recommend <a href="https://certbot.eff.org/">Certbot</a>), you'll need a more minimal Nginx conf file before you can use the TLS-enabled example above. Instead, use this configuration file during the Certbot certificate generation process:</p>
<pre><code class="language-conf">server {
  server_name example.com;
  location / {
      try_files $uri $uri/ =404;
  }
  listen 80;
}</code></pre>
<p>Once you're done editing the Nginx conf file, restart Nginx:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">doas</span></span><span class="meta function-call arguments shell"> rc-service nginx restart</span></span></code></pre>
<p>If you still need to generate TLS certificates, run <code class="verbatim">certbot</code> now and obtain the certificates. Certbot will ask if you want to use a webroot or spin up a temporary web server. I <strong>highly</strong> recommend using the temporary web server due to the many issues with using a webroot.</p>
<p>You will need to stop Nginx in order to user the temporary web server option with Certbot:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> Stop Nginx so certbot can spin up a temp webserver for cert generation</span><span class="comment line number-sign shell">
</span><span class="meta function-call shell"><span class="variable function shell">doas</span></span><span class="meta function-call arguments shell"> rc-service nginx stop</span>
<span class="meta function-call shell"><span class="variable function shell">doas</span></span><span class="meta function-call arguments shell"> certbot certonly<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>v</span></span>
<span class="meta function-call shell"><span class="variable function shell">doas</span></span><span class="meta function-call arguments shell"> rc-service nginx start</span></span></code></pre>
<h3 id="open-firewall-router-ports"><span class="section-number-3">2.5.</span> Open Firewall &amp; Router Ports</h3>
<p>If you use a firewall on the server, open the <code class="verbatim">8448</code> port for discovery and federation, as well as the normal web server ports if you're using a reverse proxy. If you want additional services, such as voice calls, you will need to read the Synapse documentation to see which ports need to be opened for those features.</p>
<p>Here's an example of the Universal Firewall (UFW) software:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> Matrix port</span><span class="comment line number-sign shell">
</span><span class="meta function-call shell"><span class="variable function shell">doas</span></span><span class="meta function-call arguments shell"> ufw allow 8448</span>
<span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> Standard web server ports</span><span class="comment line number-sign shell">
</span><span class="meta function-call shell"><span class="variable function shell">doas</span></span><span class="meta function-call arguments shell"> ufw allow <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>Nginx Full<span class="punctuation definition string end shell">&quot;</span></span></span></span></code></pre>
<p>Remember to forward any Synapse ports, such as <code class="verbatim">8448</code>, <code class="verbatim">80</code>, and <code class="verbatim">443</code>, in your Router from the internet to your server's internet protocol (IP) address.</p>
<h3 id="adding-matrix-users"><span class="section-number-3">2.6.</span> Adding Matrix Users</h3>
<p>Finally, if you didn't enable public registration in the <code class="verbatim">homeserver.yaml</code> file, you can manually create users via the command-line:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="support function cd shell">cd</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/synapse</span>
<span class="meta function-call shell"><span class="variable function shell">register_new_matrix_user</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>c</span> homeserver.yaml</span></span></code></pre>
<p>Remember that the format for federated Matrix usernames is <code class="verbatim">@username:example.com</code> when logging in to client applications.</p>
<p>Once Synapse is running, and you have a username, you are ready to log in to a Matrix client and start sending messages, joining rooms, and utilizing your very own Matrix server.</p>
]]></description>
    </item>
    <item>
      <title>Void Linux: Remove the Display Manager</title>
      <link>https://cleberg.net/blog/linux-display-manager.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/linux-display-manager.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Sun, 30 Oct 2022 00:00:00 +0000</pubDate>
      <category>linux</category>
      <description><![CDATA[<h2 id="display-manager-services"><span class="section-number-2">1.</span> Display Manager Services</h2>
<p>In order to change the <a href="https://en.wikipedia.org/wiki/Display_manager">display manager</a> on Void Linux - or any other Linux distribution - you need to identify the currently enabled display manager.</p>
<h3 id="disabling-the-current-display-manager"><span class="section-number-3">1.1.</span> Disabling the Current Display Manager</h3>
<p>Void Linux only has one optical disc image (ISO) available for download with a pre-built display manager at the time of this post: the XFCE ISO. If you've installed this version, the pre-assigned display manager is <code class="verbatim">lxdm</code>. If you installed another display manager, replace <code class="verbatim">lxdm</code> in the following command with the display manager you have installed.</p>
<p>To disable <code class="verbatim">lxdm</code>, simply remove the service symlink:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> rm /var/service/lxdm</span></span></code></pre>
<h3 id="enabling-a-new-display-manager"><span class="section-number-3">1.2.</span> Enabling a New Display Manager</h3>
<p>If you want to enable a new display manager, you can do so after <code class="verbatim">lxdm</code> is disabled. Make sure to replace <code class="verbatim">&lt;new_display_manager&gt;</code> with your new DM, such as <code class="verbatim">gdm</code>, <code class="verbatim">xdm</code>, etc.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> ln<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>s</span> /etc/sv/<span class="keyword operator assignment redirection shell">&lt;</span>new_display_manager<span class="keyword operator assignment redirection shell">&gt;</span> /var/service</span></span></code></pre>
<h2 id="set-up-xinitrc"><span class="section-number-2">2.</span> Set Up <code class="verbatim">.xinitrc</code></h2>
<p>Depending on your setup, you may need to create a few X files, such as <code class="verbatim">~/.xinitrc</code>. For my personal set-up, I created this file to launch the i3wm as my desktop.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">nano</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/.xinitrc</span></span></code></pre>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell">!/bin/sh</span><span class="comment line number-sign shell">
</span>
<span class="meta function-call shell"><span class="support function exec shell">exec</span></span><span class="meta function-call arguments shell"> i3</span></span></code></pre>
<p>If you run a desktop other than i3, simply replace <code class="verbatim">i3</code> with the shell command that launches that desktop.</p>
<h2 id="set-up-your-shell-profile"><span class="section-number-2">3.</span> Set Up Your Shell Profile</h2>
<p>Finally, in order to automatically launch an X session upon login, you will need to edit the <code class="verbatim">.bash_profile</code> (bash) or <code class="verbatim">.zprofile</code> (zsh) files for your shell:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">nano</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/.zprofile</span></span></code></pre>
<p>Add the following snippet to the end of the shell profile file. This will execute the <code class="verbatim">startx</code> command upon login.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="keyword control if begin shell">if</span> <span class="support function test begin shell">[</span><span class="meta function-call arguments shell"> <span class="variable parameter option shell"><span class="punctuation definition parameter shell">-</span>z</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section expansion parameter begin shell">{</span></span><span class="meta group expansion parameter shell"><span class="variable other readwrite shell">DISPLAY</span></span><span class="meta group expansion parameter shell"><span class="punctuation section expansion parameter end shell">}</span></span><span class="punctuation definition string end shell">&quot;</span></span> <span class="support function test end shell">]</span></span> <span class="keyword operator logical and shell">&amp;&amp;</span> <span class="support function test begin shell">[</span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section expansion parameter begin shell">{</span></span><span class="meta group expansion parameter shell"><span class="variable other readwrite shell">XDG_VTNR</span></span><span class="meta group expansion parameter shell"><span class="punctuation section expansion parameter end shell">}</span></span><span class="punctuation definition string end shell">&quot;</span></span> <span class="variable parameter option shell"><span class="punctuation definition parameter shell">-</span>eq</span> 1 <span class="support function test end shell">]</span></span><span class="keyword operator logical continue shell">;</span> <span class="keyword control if then shell">then</span>
    <span class="meta function-call shell"><span class="support function exec shell">exec</span></span><span class="meta function-call arguments shell"> startx</span>
<span class="meta function-call shell"><span class="variable function shell">fi</span></span></span></code></pre>
<p>Alternatively, you can ignore this step and simply choose to manually execute <code class="verbatim">startx</code> upon login. This can be useful if you have issues with your desktop or like to manually launch different desktops by choice.</p>
]]></description>
    </item>
    <item>
      <title>Alpine Linux: Minimal Install, Minimal Attack Surface</title>
      <link>https://cleberg.net/blog/alpine-linux.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/alpine-linux.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Sat, 22 Oct 2022 00:00:00 +0000</pubDate>
      <category>linux</category>
      <description><![CDATA[<h2 id="alpine-linux"><span class="section-number-2">1.</span> Alpine Linux</h2>
<p><a href="https://alpinelinux.org">Alpine Linux</a> is a very small distribution, built on musl libc and busybox. It uses ash as the default shell, OpenRC as the init system, and apk as the package manager. According to their website, an Alpine container "requires no more than 8 megabytes (MB) and a minimal installation to disk requires around 130 MB of storage." An actual bare metal machine is recommended to have 100 MB of RAM and 0-700 MB of storage space.</p>
<p>Historically, I've used Ubuntu's minimal installation image as my server OS for the last five years. Ubuntu worked well and helped as my original server contained an nVidia GPU (graphics processing unit) and no onboard graphics, so quite a few distributions won't boot or install without a lot of tinkering.</p>
<p>Alpine has given me a huge increase in performance across my Docker apps and Nginx websites. CPU (central processing unit) load for the new server I'm using to test Alpine hovers around 0-5% on average with an Intel(R) Core(TM) i3-6100 CPU @ 3.70 Gigahertz (GHz).</p>
<p>The only services I haven't moved over to Alpine are Plex Media Server and Syncthing, which may increase CPU load quite a bit depending on how many streams are running.</p>
<h3 id="installation"><span class="section-number-3">1.1.</span> Installation</h3>
<p>In terms of installation, Alpine has an incredibly useful <a href="https://wiki.alpinelinux.org/wiki/Installation">wiki</a> that will guide a user throughout the installation and post-installation processes, as well as various other articles and guides.</p>
<p>To install Alpine, find an appropriate <a href="https://alpinelinux.org/downloads/">image to download</a> and flash it to a USB (Universal Serial Bus) using software such as Rufus or Etcher. I opted to use the Standard image for my x86<sub>64</sub> architecture.</p>
<p>Once the USB is ready, plug it into the machine and reboot. Note that you may have to use a key such as <code class="verbatim">Esc</code> or <code class="verbatim">F1-12</code> to access the boot menu. The Alpine Linux terminal will load quickly and for a login.</p>
<p>To log in to the installation image, use the <code class="verbatim">root</code> account; there is no password. Once logged-in, execute the setup command:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">setup-alpine</span></span></span></code></pre>
<p>The setup script will ask a series of questions to configure the system. Be sure to answer carefully or else you may have to re-configure the system after boot.</p>
<ul>
<li><strong>Keyboard Layout</strong>: Local keyboard language and usage mode, e.g., us and variant of us-nodeadkeys.</li>
<li><strong>Hostname</strong>: The name for the computer.</li>
<li><strong>Network</strong>: For example, automatic internet protocol (IP) address discovery with the Dynamic Host Configuration Protocol (DHCP) protocol.</li>
<li><strong>DNS (Domain Name System)</strong>: DNS servers to query. For privacy reasons, it is NOT recommended to route every local request to servers like Google's 8.8.8.8.</li>
<li>*Timezone</li>
<li><strong>Proxy</strong>: Proxy server to use for accessing the web. Use <code class="verbatim">none</code> for direct connections to the internet.</li>
<li><strong>Mirror</strong>: From where to download packages. Choose the organization you trust giving your usage patterns to.</li>
<li><strong>SSH (Secure Shell Protocol)</strong>: Remote access server. <code class="verbatim">Openssh</code> is part of the default install image. Use <code class="verbatim">none</code> to disable remote login, e.g. on laptops.</li>
<li><strong>NTP (Network Time Protocol)</strong>: Client used for keeping the system clock in sync with a time-server. Package <code class="verbatim">chrony</code> is part of the default install image.</li>
<li><strong>Disk Mode</strong>: Select between diskless (<code class="verbatim">none</code>), <code class="verbatim">data</code> or <code class="verbatim">sys</code>, as described above.</li>
</ul>
<p>Once the setup script is finished, be sure to reboot the machine and remove the USB device.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">reboot</span></span></span></code></pre>
<h3 id="post-installation"><span class="section-number-3">1.2.</span> Post-Installation</h3>
<p>There are many things you can do once your Alpine Linux system is up and running, and it largely depends on what you'll use the machine for. I'm going to walk through my personal post-installation setup for my web server.</p>
<ol>
<li><p>Upgrade the System</p>
<p>First, login as <code class="verbatim">root</code> in order to update and upgrade the system:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">apk</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>U</span> upgrade</span></span></code></pre>
</li>
<li><p>Adding a User</p>
<p>I needed to add a user so that I don't need to log in as root. Note that if you're used to using the <code class="verbatim">sudo</code> command, you will now need to use the <code class="verbatim">doas</code> command on Alpine Linux.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">apk</span></span><span class="meta function-call arguments shell"> add doas</span>
<span class="meta function-call shell"><span class="variable function shell">adduser</span></span><span class="meta function-call arguments shell"> <span class="keyword operator assignment redirection shell">&lt;</span>username<span class="keyword operator assignment redirection shell">&gt;</span>
</span><span class="meta function-call shell"><span class="variable function shell">adduser</span></span><span class="meta function-call arguments shell"> <span class="keyword operator assignment redirection shell">&lt;</span>username<span class="keyword operator assignment redirection shell">&gt;</span> wheel</span></span></code></pre>
<p>You can now log out and log back in using the newly-created user:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="support function exit shell">exit</span></span></span></code></pre>
</li>
<li><p>Enable Community Packages</p>
<p>In order to install more common packages that aren't found in the <code class="verbatim">main</code> repository, you will need to enable the <code class="verbatim">community</code> repository:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">doas</span></span><span class="meta function-call arguments shell"> nano /etc/apk/repositories</span></span></code></pre>
<p>Uncomment the community line for whichever version of Alpine you're running:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">/media/usb/apks</span></span>
<span class="meta function-call shell"><span class="variable function shell">http://dl-cdn.alpinelinux.org/alpine/v3.16/main</span></span>
<span class="meta function-call shell"><span class="variable function shell">http://dl-cdn.alpinelinux.org/alpine/v3.16/community</span></span>
<span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell">http://dl-cdn.alpinelinux.org/alpine/edge/main</span><span class="comment line number-sign shell">
</span><span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell">http://dl-cdn.alpinelinux.org/alpine/edge/community</span><span class="comment line number-sign shell">
</span><span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell">http://dl-cdn.alpinelinux.org/alpine/edge/testing</span></span></code></pre>
</li>
<li><p>Install Required Packages</p>
<p>Now that the community packages are available, you can install any packages you need. In my case, I installed the web server packages I need for my services:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">doas</span></span><span class="meta function-call arguments shell"> apk add nano nginx docker docker-compose ufw</span></span></code></pre>
</li>
<li><p>SSH</p>
<p>If you didn't install OpenSSH as part of the installation, you can do so now:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">doas</span></span><span class="meta function-call arguments shell"> apk add openssh</span></span></code></pre>
<p>Next, either create a new key or copy your SSH key to the server from your current machines:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> Create a new key</span><span class="comment line number-sign shell">
</span><span class="meta function-call shell"><span class="variable function shell">ssh-keygen</span></span></span></code></pre>
<p>If you need to copy an existing SSH key from a current machine:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> Copy key from existing machines</span><span class="comment line number-sign shell">
</span><span class="meta function-call shell"><span class="variable function shell">ssh-copy-id</span></span><span class="meta function-call arguments shell"> <span class="keyword operator assignment redirection shell">&lt;</span>username<span class="keyword operator assignment redirection shell">&gt;</span>@<span class="keyword operator assignment redirection shell">&lt;</span>ip_address<span class="keyword operator assignment redirection shell">&gt;</span></span></span></code></pre>
</li>
<li><p>Firewall</p>
<p>Lastly, I installed <code class="verbatim">ufw</code> above as my firewall. To set up, default to deny incoming and allow outgoing connections. Then selectively allow other ports or apps as needed.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">doas</span></span><span class="meta function-call arguments shell"> ufw default deny incoming</span>
<span class="meta function-call shell"><span class="variable function shell">doas</span></span><span class="meta function-call arguments shell"> ufw default allow outgoing</span>
<span class="meta function-call shell"><span class="variable function shell">doas</span></span><span class="meta function-call arguments shell"> ufw allow SSH</span>
<span class="meta function-call shell"><span class="variable function shell">doas</span></span><span class="meta function-call arguments shell"> ufw allow <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>WWW Full<span class="punctuation definition string end shell">&quot;</span></span></span>
<span class="meta function-call shell"><span class="variable function shell">doas</span></span><span class="meta function-call arguments shell"> ufw allow 9418 <span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> Git server port</span></span></span></code></pre>
</li>
<li><p>Change Hostname</p>
<p>If you don't like the hostname set during installation, you just need to edit two files. First, edit the simple hostname file:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">doas</span></span><span class="meta function-call arguments shell"> nano /etc/hostname</span></span></code></pre>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"></span><span class="meta function-call arguments shell"><span class="keyword operator assignment redirection shell">&lt;</span>hostname<span class="keyword operator assignment redirection shell">&gt;</span></span></span></code></pre>
<p>Next, edit the <code class="verbatim">hosts</code> file:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">doas</span></span><span class="meta function-call arguments shell"> nano /etc/hosts</span></span></code></pre>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">127.0.0.1</span></span><span class="meta function-call arguments shell">   <span class="keyword operator assignment redirection shell">&lt;</span>hostname<span class="keyword operator assignment redirection shell">&gt;</span>.local <span class="keyword operator assignment redirection shell">&lt;</span>hostname<span class="keyword operator assignment redirection shell">&gt;</span> localhost.local localhost</span>
<span class="meta function-call shell"><span class="variable function shell">::1</span></span><span class="meta function-call arguments shell">         <span class="keyword operator assignment redirection shell">&lt;</span>hostname<span class="keyword operator assignment redirection shell">&gt;</span> <span class="keyword operator assignment redirection shell">&lt;</span>hostname<span class="keyword operator assignment redirection shell">&gt;</span>.local</span></span></code></pre>
</li>
</ol>
<h2 id="nginx-web-server"><span class="section-number-2">2.</span> Nginx Web Server</h2>
<p>To set up my web server, I simply created the <code class="verbatim">www</code> user and created the necessary files.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">doas</span></span><span class="meta function-call arguments shell"> adduser<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>D</span><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>g</span> <span class="string quoted single shell"><span class="punctuation definition string begin shell">&#39;</span>www<span class="punctuation definition string end shell">&#39;</span></span> www</span>
<span class="meta function-call shell"><span class="variable function shell">mkdir</span></span><span class="meta function-call arguments shell"> /www</span>
<span class="meta function-call shell"><span class="variable function shell">doas</span></span><span class="meta function-call arguments shell"> mkdir /www</span>
<span class="meta function-call shell"><span class="variable function shell">doas</span></span><span class="meta function-call arguments shell"> chown<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>R</span> www:www /var/lib/nginx/</span>
<span class="meta function-call shell"><span class="variable function shell">doas</span></span><span class="meta function-call arguments shell"> chown<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>R</span> www:www /www</span></span></code></pre>
<p>If you're running a simple webroot, you can alter the main <code class="verbatim">nginx.conf</code> file. Otherwise, you can drop configuration files in the following directory. You don't need to enable or symlink the configuration file like you do in other systems.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">doas</span></span><span class="meta function-call arguments shell"> nano /etc/nginx/http.d/example_website.conf</span></span></code></pre>
<p>Once the configuration is set and pointed at the <code class="verbatim">/www</code> directory to serve files, enable the Nginx service:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> Note that &#39;default&#39; must be included or Nginx will not start on boot</span><span class="comment line number-sign shell">
</span><span class="meta function-call shell"><span class="variable function shell">doas</span></span><span class="meta function-call arguments shell"> rc-update add nginx default</span></span></code></pre>
<h2 id="docker-containers"><span class="section-number-2">3.</span> Docker Containers</h2>
<p>Docker works exactly the same as other systems. Either execute a <code class="verbatim">docker run</code> command or create a <code class="verbatim">docker-compose.yml</code> file and do <code class="verbatim">docker-compose up -d</code>.</p>
<h2 id="git-server"><span class="section-number-2">4.</span> Git Server</h2>
<p>I went in-depth on how to self-host a git server in another post: <a href="https://cleberg.net/blog/git-server.html">Self-Hosting Guide: Git &amp; cGit</a>.</p>
<p>However, there are a few differences with Alpine. First note that in order to change the <code class="verbatim">git</code> user's shell, you must do a few things a little different:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">doas</span></span><span class="meta function-call arguments shell"> apk add libuser</span>
<span class="meta function-call shell"><span class="variable function shell">doas</span></span><span class="meta function-call arguments shell"> touch /etc/login.defs</span>
<span class="meta function-call shell"><span class="variable function shell">doas</span></span><span class="meta function-call arguments shell"> mkdir /etc/default</span>
<span class="meta function-call shell"><span class="variable function shell">doas</span></span><span class="meta function-call arguments shell"> touch /etc/default/useradd</span>
<span class="meta function-call shell"><span class="variable function shell">doas</span></span><span class="meta function-call arguments shell"> lchsh git</span></span></code></pre>
<h2 id="thoughts-on-alpine"><span class="section-number-2">5.</span> Thoughts on Alpine</h2>
<p>So far, I love Alpine Linux. I have no complaints about anything at this point, but I'm not completely finished with the migration yet. Once I'm able to upgrade my hardware to a rack-mounted server, I will migrate Plex and Syncthing over to Alpine as well - possibly putting Plex into a container or VM.</p>
<p>The performance is stellar, the <code class="verbatim">apk</code> package manager is seamless, and system administration tasks are effortless. My only regret is that I didn't install Alpine sooner.</p>
]]></description>
    </item>
    <item>
      <title>Self-Hosting Guide: Syncthing</title>
      <link>https://cleberg.net/blog/syncthing.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/syncthing.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Tue, 04 Oct 2022 00:00:00 +0000</pubDate>
      <category>linux</category>
      <category>self-hosting</category>
      <description><![CDATA[<h2 id="an-overview-of-syncthing"><span class="section-number-2">1.</span> An Overview of Syncthing</h2>
<p>If you've been looking around the self-hosted cloud storage space for a while, you've undoubtedly run into someone suggesting <a href="https://syncthing.net">Syncthing</a> as an option. However, it is an unusual alternative for those users out there who are used to having a centralized cloud server that serves as the "controller" of the data and interacts with clients on devices to fetch files.</p>
<p>This post is a walkthrough of the Syncthing software, how I set up my personal storage, and some pros and cons of using the software.</p>
<h2 id="installing-syncthing"><span class="section-number-2">2.</span> Installing Syncthing</h2>
<p>To install Syncthing, visit the <a href="https://syncthing.net/downloads/">Downloads</a> page or install via your device's package manager.</p>
<h3 id="server-desktop"><span class="section-number-3">2.1.</span> Server &amp; Desktop</h3>
<p>You can install Syncthing on servers and desktops via the Downloads page linked above or via the command-line.</p>
<p>For Debian-based distros:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> apt install syncthing</span></span></code></pre>
<p>For Fedora-based distros:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> dnf install syncthing</span></span></code></pre>
<h3 id="mobile"><span class="section-number-3">2.2.</span> Mobile</h3>
<p>Syncthing for Android is available on <a href="https://f-droid.org/packages/com.nutomic.syncthingandroid/">F-Droid</a> and <a href="https://play.google.com/store/apps/details?id=com.nutomic.syncthingandroid">Google Play</a>. Syncthing does not have an official iOS client, but there is a third-party client called <a href="https://apps.apple.com/us/app/m%C3%B6bius-sync/id1539203216">Möbius Sync</a>.</p>
<h2 id="how-does-syncthing-work"><span class="section-number-2">3.</span> How Does Syncthing Work?</h2>
<p>To start, I wanted to include the main marketing blurb from their website:</p>
<blockquote>
<p>Syncthing is a continuous file synchronization program. It synchronizes files between two or more computers in real time, safely protected from prying eyes. Your data is your data alone, and you deserve to choose where it is stored, whether it is shared with some third party, and how it's transmitted over the internet.</p>
</blockquote>
<p>Let's break this apart and add in some other details to help explain what exactly Syncthing does in order to sync files between devices.</p>
<h3 id="local-syncthing-server-s"><span class="section-number-3">3.1.</span> Local Syncthing Server(s)</h3>
<p>Syncthing syncs files between multiple devices by creating a local server on each device. These local servers handle a few different things, such as watching files and directories for changes, hosting an administrative GUI website, and authenticating with connected devices.</p>
<p>You can also start, stop, and restart the Syncthing server via the command-line or web dashboard. If you're running Syncthing on a device with <code class="verbatim">systemd</code>, you can use the following commands:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> systemctl start syncthing@username.service</span>
<span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> systemctl restart syncthing@username.service</span>
<span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> systemctl stop syncthing@username.service</span></span></code></pre>
<h3 id="syncthing-dashboard"><span class="section-number-3">3.2.</span> Syncthing Dashboard</h3>
<p>This biggest part of Syncthing is the admin GUI website that runs on each device (note that mobile devices will use the Syncthing app rather than the web GUI). The administrative graphical user interface (GUI) is available through the web browser on the local device that is running Syncthing - simply go to <code class="verbatim">http://localhost:8384</code> or <code class="verbatim">http://127.0.0.1:8384</code>. This web page is the place where you will change settings, add/modify synced files, and add/modify connected devices.</p>
<p>Here's an example web GUI dashboard:</p>
<figure><img src="https://img.cleberg.net/blog/20221020-syncthing/syncthing_gui.webp" alt="Syncthing web page on macOS, showing folders, device info, and remote devices."><figcaption><span class="figure-number">Figure 1: </span>Syncthing Dashboard</figcaption></figure>
<h3 id="remote-devices"><span class="section-number-3">3.3.</span> Remote Devices</h3>
<p>A cloud storage solution wouldn't be very useful if you aren't able to share data among various devices. Syncthing does this by sharing Device IDs to connect servers, and then by manually sharing Folders with devices that have been connected.</p>
<p>For instance, if you have a laptop running Syncthing and then install the Syncthing mobile app on a phone, you could scan the laptop's QR (quick-response) code for Device ID and then accept the authentication on the laptop's dashboard. Next, you can use either device to select a folder for sharing and dictating which device should send, receive, or both.</p>
<p>When you connect devices, you can set one device as an "Introducer," which can add devices from the introducer to the device list, for mutually shared folders. You can also configure Auto Accept, compression, rate limits, and more settings per device.</p>
<h2 id="my-personal-cloud-storage-set-up"><span class="section-number-2">4.</span> My Personal Cloud Storage Set-up</h2>
<p>Personally, I use a model similar to a traditional cloud storage service. I have a "centralized" server running 24/7 that acts as an Introducer for my Syncthing network. I think of this as my main storage and all other devices as tertiary client devices. I will likely add additional servers as backups as time goes on so that I don't have to rely on my laptop or phone as the only backups.</p>
<p>Currently, I have one desktop and one mobile device connected to the network, both running intermittently as they are not powered-on 24/7.</p>
<p>The initial set-up of the software was easy enough, but data transfer rates were incredibly slow for me due to the Wi-Fi. Instead, I plugged my laptop into the ethernet network that my server is on and manually copied my folders over to the server with <code class="verbatim">scp</code>. Once complete, Syncthing validated that all files were there and not missing, and it did not need to transfer any data through the WAN.</p>
<p>As slow as the transfer was going, this probably saved me a few days of waiting for my ~100 gigabytes to sync.</p>
<h2 id="pros-cons"><span class="section-number-2">5.</span> Pros &amp; Cons</h2>
<p>I've put together a short list of pros and cons for Syncthing. I thought about my experiences with Nextcloud, WebDAV, proprietary services (Google Drive, iCloud, etc.), and privacy-focused cloud solutions (pCloud, Tresorit, etc.).</p>
<p><strong>Pros:</strong></p>
<ul>
<li>I've faced no data loss at all through my two-month trial run.</li>
<li>No third-parties store your data on their servers.</li>
<li>You have full control over your data and can take your data and leave at any time.</li>
<li>It's possible to encrypt client-side easily with software like Cryptomator.</li>
<li>No proprietary clients or mounted volumes, just plain files and folders.</li>
</ul>
<p><strong>Cons:</strong></p>
<ul>
<li>The learning curve is steeper than traditional cloud services and is focused on a technical audience.</li>
<li>If a device needs to modify files in a Folder, the devices will need to sync ALL files from the folder, which may be large. To avoid size restraints, split large folders into smaller folders for syncing.</li>
<li>Syncing can be slow due to the clients/servers initially connecting or re-connecting after sleeping.</li>
<li>Multiple personal devices are required and require the user to own or rent them as no third-party servers are involved in the storage of data.</li>
</ul>
<p>Overall, I've had a great experience with Syncthing so far. I've had no data loss, syncing has been quick and easy when changes are made to files, device connections are reliable, and I love the freedom of controlling the clients and servers as I choose.</p>
<p>Not to mention that I appreciate that I - or someone else - could pull the Syncthing <a href="https://github.com/syncthing">source code</a> and continue development/support if the Syncthing Foundation decides to stop developing the software or sells the business.</p>
]]></description>
    </item>
    <item>
      <title>MTP on Linux: Mount Your Phone Without a File Manager</title>
      <link>https://cleberg.net/blog/mtp-linux.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/mtp-linux.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Tue, 04 Oct 2022 00:00:00 +0000</pubDate>
      <category>linux</category>
      <description><![CDATA[<p>I recently ran into trouble attempting to mount my GrapheneOS phone to my laptop running Fedora Linux via the <a href="https://en.wikipedia.org/wiki/Media_transfer_protocol">Media Transfer Protocol</a> (MTP) and discovered a simple and effective solution.</p>
<h2 id="use-a-universal-serial-bus-usb-3-0-port"><span class="section-number-2">1.</span> Use a Universal Serial Bus (USB) 3.0 Port</h2>
<p>First, ensure that the device was plugged in to the laptop through a USB 3.0 port, if possible. From a brief glance online, it seems that USB 2.0 ports may cause issues with dropped connections over MTP. This is purely anecdotal since I don't have any evidence to link showing that USB 2.0 causes issues, but I can confirm that switching to a USB 3.0 port seemed to cut out most of my issues.</p>
<h2 id="switch-usb-preferences-to-mtp"><span class="section-number-2">2.</span> Switch USB Preferences to MTP</h2>
<p>Secondly, you need to ensure that the phone's USB preferences/mode is changed to MTP or File Transfer once the phone is plugged in. Other modes will not allow you to access the phone's file system.</p>
<h2 id="install-jmtpfs"><span class="section-number-2">3.</span> Install <code class="verbatim">jmtpfs</code></h2>
<p>Next, I used the <code class="verbatim">jmtpfs</code> package to mount my phone to my laptop. There are other packages that exist, but this one worked perfectly for me. On Fedora Linux, you can install it like this:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> dnf install jmtpfs<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>y</span></span></span></code></pre>
<h2 id="create-a-mount-point"><span class="section-number-2">4.</span> Create a Mount Point</h2>
<p>Once you have the package installed, you just need to create a folder for the device to use as a mount point. In my case, I used <code class="verbatim">/mnt/pixel</code>:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> mkdir /mnt/pixel</span>
<span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> chown<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>R</span> <span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">USER</span></span>:<span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">USER</span></span> /mnt/pixel</span></span></code></pre>
<h2 id="mount-access-the-phone-s-file-system"><span class="section-number-2">5.</span> Mount &amp; Access the Phone's File System</h2>
<p>Finally, plug-in and mount the device, and you should be able to see all storage (internal and external) inside your new folder!</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">jmtpfs</span></span><span class="meta function-call arguments shell"> /mnt/pixel</span></span></code></pre>
<p>The output should look something like this:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">Device</span></span><span class="meta function-call arguments shell"> 0 (VID=18d1 and PID=4ee1</span><span class="meta function-call shell"></span><span class="meta post-cmd shell">)</span> <span class="meta function-call shell"><span class="variable function shell">is</span></span><span class="meta function-call arguments shell"> a Google Inc Nexus/Pixel (MTP</span><span class="meta function-call shell"></span><span class="meta post-cmd shell">)</span><span class="meta function-call shell"><span class="support function dot shell">.</span></span>
<span class="meta function-call shell"><span class="variable function shell">Android</span></span><span class="meta function-call arguments shell"> device detected, assigning default bug flags</span></span></code></pre>
<p>Now you are mounted and can do anything you'd like with the device's files:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="support function cd shell">cd</span></span><span class="meta function-call arguments shell"> /mnt/pixel</span>
<span class="meta function-call shell"><span class="variable function shell">ls</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>lha</span></span></span></code></pre>
<p>From here, you will be able to see any internal or external storage available on the device:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">total</span></span><span class="meta function-call arguments shell"> 0</span>
<span class="meta function-call shell"><span class="variable function shell">drwxr-xr-x.</span></span><span class="meta function-call arguments shell">  3 user user  0 Jan  1  1970  .</span>
<span class="meta function-call shell"><span class="variable function shell">drwxr-xr-x.</span></span><span class="meta function-call arguments shell">  1 root root 10 Oct  4 13:29  ..</span>
<span class="meta function-call shell"><span class="variable function shell">drwxr-xr-x.</span></span><span class="meta function-call arguments shell"> 16 user user  0 Apr 21  4426383 <span class="string quoted single shell"><span class="punctuation definition string begin shell">&#39;</span>Internal shared storage<span class="punctuation definition string end shell">&#39;</span></span></span></span></code></pre>
]]></description>
    </item>
    <item>
      <title>Installing GrapheneOS on Pixel 6 Pro</title>
      <link>https://cleberg.net/blog/graphene-os.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/graphene-os.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Wed, 21 Sep 2022 00:00:00 +0000</pubDate>
      <category>linux</category>
      <category>privacy</category>
      <description><![CDATA[<h2 id="introduction"><span class="section-number-2">1.</span> Introduction</h2>
<p>After using iOS for a couple of years, I finally took the plunge and purchased a Pixel 6 Pro in order to test and use <a href="https://grapheneos.org">GrapheneOS</a>.</p>
<p>The installation process was rather quick once you have the tools and files you need. Overall, it can be done in just a few minutes.</p>
<h2 id="gathering-tools-files"><span class="section-number-2">2.</span> Gathering Tools &amp; Files</h2>
<h3 id="android-tools"><span class="section-number-3">2.1.</span> Android Tools</h3>
<p>First, in order to interact with the device, we will need the <a href="https://developer.android.com/studio/releases/platform-tools.html">Android platform tools</a>. Find the Linux download and save the ZIP folder to your preferred location.</p>
<p>Once we've downloaded the files, we will need to unzip them, enter the directory, and move the necessary executables to a central location, such as <code class="verbatim">/usr/bin/</code>. For this installation, we only need the <code class="verbatim">fastboot</code> and <code class="verbatim">adb</code> executables.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="support function cd shell">cd</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/Downloads</span></span></code></pre>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">unzip</span></span><span class="meta function-call arguments shell"> platform-tools_r33.0.3-linux.zip</span>
<span class="meta function-call shell"><span class="support function cd shell">cd</span></span><span class="meta function-call arguments shell"> platform-tools</span>
<span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> mv fastboot /usr/bin/</span>
<span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> mv adb /usr/bin</span></span></code></pre>
<h3 id="grapheneos-files"><span class="section-number-3">2.2.</span> GrapheneOS Files</h3>
<p>Next, we need the <a href="https://grapheneos.org/releases">GrapheneOS files</a> for our device and model. For example, the Pixel 6 Pro is codenamed <code class="verbatim">raven</code> on the release page.</p>
<p>Once we have the links, let's download them to our working directory:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">curl</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>O</span> https://releases.grapheneos.org/factory.pub</span>
<span class="meta function-call shell"><span class="variable function shell">curl</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>0</span> https://releases.grapheneos.org/raven-factory-2022091400.zip</span>
<span class="meta function-call shell"><span class="variable function shell">curl</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>0</span> https://releases.grapheneos.org/raven-factory-2022091400.zip.sig</span></span></code></pre>
<ol>
<li><p>Validate Integrity</p>
<p>In order to validate the integrity of the downloaded files, we will need the <code class="verbatim">signify</code> package and Graphene's <code class="verbatim">factory.pub</code> file.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> dnf install signify</span></span></code></pre>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">curl</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>O</span> https://releases.grapheneos.org/factory.pub</span></span></code></pre>
<p>Then we can validate the files and ensure that no data was corrupted or modified before it was saved to our device.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">signify</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>Cqp</span> factory.pub<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>x</span> raven-factory-2022091400.zip.sig</span> <span class="keyword operator logical and shell">&amp;&amp;</span> <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> verified</span></span></code></pre>
</li>
<li><p>Unzip Files</p>
<p>Once the files are verified, we can unzip the Graphene image and enter the directory:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">unzip</span></span><span class="meta function-call arguments shell"> raven-factory-2022091400.zip</span> <span class="keyword operator logical and shell">&amp;&amp;</span> <span class="meta function-call shell"><span class="support function cd shell">cd</span></span><span class="meta function-call arguments shell"> raven-factory-2022091400</span></span></code></pre>
</li>
</ol>
<h2 id="installation-process"><span class="section-number-2">3.</span> Installation Process</h2>
<h3 id="enable-developer-debugging-oem-unlock"><span class="section-number-3">3.1.</span> Enable Developer Debugging &amp; OEM Unlock</h3>
<p>Before we can actually flash anything to the phone, we will need to enable OEM (Original Equipment Manufacturer) Unlocking, as well as either USB (Universal Serial Bus) Debugging or Wireless Debugging, depending on which method we will be using.</p>
<p>To start, enable developer mode by going to <code class="verbatim">Settings</code> &gt; <code class="verbatim">About</code> and tapping <code class="verbatim">Build Number</code> seven (7) times. You may need to enter your personal identified number (PIN) to enable this mode.</p>
<p>Once developer mode is enabled, go to <code class="verbatim">Settings</code> &gt; <code class="verbatim">System</code> &gt; <code class="verbatim">Devloper Options</code> and enable OEM Unlocking, as well as USB or Wireless Debugging. In my case, I chose USB Debugging and performed all actions via USB cable.</p>
<p>Once these options are enabled, plug the phone into the computer and execute the following command:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">adb</span></span><span class="meta function-call arguments shell"> devices</span></span></code></pre>
<p>If an unauthorized error occurs, make sure the USB mode on the phone is changed from charging to something like "File Transfer" or "PTP" (Picture Transfer Protocol). You can find the USB mode in the notification tray.</p>
<h3 id="reboot-device"><span class="section-number-3">3.2.</span> Reboot Device</h3>
<p>Once we have found the device via <code class="verbatim">adb</code>, we can either boot into the bootloader interface by holding the volume down button while the phone reboots or by executing the following command:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">adb</span></span><span class="meta function-call arguments shell"> reboot bootloader</span></span></code></pre>
<h3 id="unlock-the-bootloader"><span class="section-number-3">3.3.</span> Unlock the Bootloader</h3>
<p>The phone will reboot and load the bootloader screen upon startup. At this point, we are ready to start the actual flashing of GrapheneOS onto the device.</p>
<p><strong>NOTE</strong>: In my situation, I needed to use <code class="verbatim">sudo</code> with every <code class="verbatim">fastboot</code> command, but not with <code class="verbatim">adb</code> commands. I am not sure if this is standard or a Fedora quirk, but I'm documenting my commands verbatim in this post.</p>
<p>First, we start by unlocking the bootloader so that we can load other ROMs:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> fastboot flashing unlock</span></span></code></pre>
<h3 id="flashing-factory-images"><span class="section-number-3">3.4.</span> Flashing Factory Images</h3>
<p>Once the phone is unlocked, we can flash it with the <code class="verbatim">flash-all.sh</code> script found inside the <code class="verbatim">raven-factory-2022091400</code> folder we entered earlier:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> ./flash-all.sh</span></span></code></pre>
<p>This process should take a few minutes and will print informational messages as things progress. Avoid doing anything on the phone while this process is operating.</p>
<h3 id="lock-the-bootloader"><span class="section-number-3">3.5.</span> Lock the Bootloader</h3>
<p>If everything was successful, the phone should reboot a few times and finally land back on the bootloader screen. At this point, we can re-lock the bootloader to enable full verified boot and protect the device from unwanted flashing or erasure of data.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> fastboot flashing lock</span></span></code></pre>
<p>Once done, the device will be wiped and ready for a fresh set-up!</p>
]]></description>
    </item>
    <item>
      <title>Building and Exploring SerenityOS</title>
      <link>https://cleberg.net/blog/serenity-os.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/serenity-os.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Sat, 17 Sep 2022 00:00:00 +0000</pubDate>
      <category>linux</category>
      <description><![CDATA[<h2 id="overview"><span class="section-number-2">1.</span> Overview</h2>
<p><a href="https://serenityos.org">SerenityOS</a> is a unique operating system (OS) that I have seen pop up in my news feed a few times over the last few years, but I have never had time to test it out until now.</p>
<p>Testing out this system brought back fond memories of yellowed, modem-screeching, 100-pound computers that brought so many fond memories to my youth.</p>
<p>Per their website:</p>
<blockquote>
<p>A graphical Unix-like operating system for desktop computers!</p>
<p>SerenityOS is a love letter to '90s user interfaces with a custom Unix-like core. It flatters with sincerity by stealing beautiful ideas from various other systems.</p>
<p>Roughly speaking, the goal is a marriage between the aesthetic of late-1990s productivity software and the power-user accessibility of late-2000s *nix.</p>
<p>This is a system by us, for us, based on the things we like.</p>
</blockquote>
<h2 id="building"><span class="section-number-2">2.</span> Building</h2>
<p>Your first question may be "Where's the iso?" and the answer is… there are none. SerenityOS does not provide pre-built images for testing. You must build the images yourself. This seems intentionally to limit participation to only those who are truly interested enough to learn how to build the OS.</p>
<h3 id="clone"><span class="section-number-3">2.1.</span> Clone</h3>
<p>In order to get started, you'll need to clone the source repository:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">git</span></span><span class="meta function-call arguments shell"> clone https://github.com/SerenityOS/serenity</span> <span class="keyword operator logical and shell">&amp;&amp;</span> <span class="meta function-call shell"><span class="support function cd shell">cd</span></span><span class="meta function-call arguments shell"> serenity</span></span></code></pre>
<h3 id="build"><span class="section-number-3">2.2.</span> Build</h3>
<p>Note that I followed the <a href="https://github.com/SerenityOS/serenity/blob/master/Documentation/BuildInstructions.md">Build Instructions</a> in the SerenityOS repository as of commit <code class="verbatim">660d2b53b1206e868d5470eee80b5e62d7e30da7</code>. Things may have changed since my installation, and you should double-check the instructions first.</p>
<p>Regardless, I want to repeat my steps here to illustrate any errors or differing commands I needed to run in order to build and run SerenityOS.</p>
<p>Since I am running Fedora, I needed to install these packages in order to build the OS images:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> dnf install texinfo binutils-devel curl cmake mpfr-devel libmpc-devel gmp-devel e2fsprogs ninja-build patch ccache rsync @<span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>C Development Tools and Libraries<span class="punctuation definition string end shell">&quot;</span></span> @Virtualization</span></span></code></pre>
<p>Next, make sure you're inside the <code class="verbatim">serenity</code> directory created earlier during the git cloning process and process to build the toolchain:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">Meta/serenity.sh</span></span><span class="meta function-call arguments shell"> rebuild-toolchain</span></span></code></pre>
<p>Once the toolchain is built, you can Build and run the OS!</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">Meta/serenity.sh</span></span><span class="meta function-call arguments shell"> run</span></span></code></pre>
<p>After this process is completed, the image should run automatically and launch.</p>
<h2 id="issues"><span class="section-number-2">3.</span> Issues</h2>
<p>I played around in SerenityOS for an hour or two in order to see what I could do and had a lot of fun with it. The only issue I ran into was a lack of working internet. I didn't try very hard, but I could tell that the main network link wasn't connecting to my Fedora host properly.</p>
<h2 id="screenshots"><span class="section-number-2">4.</span> Screenshots</h2>
<p>The initial launch of the image displays the SerenityOS desktop, with a simple terminal already launched.</p>
<p>There is also a "Fire" application (literally just shows fire burning), a browser with the local Serenity Browser page loaded, and a text editor.</p>
<p>I also poked around the system utilities and found most tools you'd expect to find within a standard desktop, such as a system monitoring tool.</p>
<p>Lastly, I noted that the default desktop contains numerous pre-defined themes to choose from. This is a small piece, but it's actually wonderful to see desktop developers consider theming directly out of the box rather than using an addon-based mentality.</p>
<p>I didn't take a screenshot of the other pre-installed games, but I did spend nearly 30 minutes playing Solitaire before remembering that I was supposed to be writing a post about the OS.</p>
]]></description>
    </item>
    <item>
      <title>Privacy.com Changed the Product, Not the Name</title>
      <link>https://cleberg.net/blog/privacy-com-changes.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/privacy-com-changes.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Wed, 31 Aug 2022 00:00:00 +0000</pubDate>
      <category>privacy</category>
      <description><![CDATA[<h2 id="privacy-com-changes-their-terms"><span class="section-number-2">1.</span> Privacy.com Changes Their Terms</h2>
<p>Recently, Privacy.com reached out to their customers regarding a change in their terms of use. Further, all customers are required to agree to the changes in order to continue using their accounts.</p>
<p><a href="https://privacy.com/commercial-cardholder-agreement">You can view the new cardholder agreement here</a>.</p>
<p>When you log in, you'll be greeted with a pop-up window asking you to review and agree to the new terms of use. You will also not be able to open any new cards until the terms are agreed to.</p>
<h3 id="changing-from-a-prepaid-debit-model-to-a-charge-card-model"><span class="section-number-3">1.1.</span> Changing from a "Prepaid Debit" Model to a "Charge Card" Model</h3>
<p>The actual content of the changes is interesting. While the historical model of using Privacy.com was akin to prepaid debit cards, the new model is very similar to a credit card (they use the term "charge card").</p>
<p>I have used Privacy.com for 1-2 years, and the process was always that you would create a single-use or merchant-locked card. This card could be used for any dollar limit you set and would immediately draw the funds from whatever funding source you connected, e.g. PayPal account or a bank account.</p>
<p>The benefit this service provides with a premium account is masking the merchant names from your funding source. If you have a concern that your bank account uses merchant data from your account, you could direct all charges through Privacy.com and set the merchant as one of their pre-set options, such as "Smiley's Corner Store" or "NSA Gift Shop."</p>
<p>The new model still works with a bank account as a funding source, but the model is changed so that you get a "line of credit" set according to a 14-day billing cycle. It seems that Privacy.com will now allow charges to be incurred without being immediately paid.</p>
<h3 id="daily-payments-and-available-credit"><span class="section-number-3">1.2.</span> Daily Payments and Available Credit</h3>
<p>Instead of paying as charges are incurred, you must make a "Daily Payment" and your "Available Credit" will be locked until you make that payment. There are also "End of Billing Cycle Payments" that are assigned a due date.</p>
<p>Further, Privacy.com will decline charges that would cause you to exceed your Available Credit or Credit Limit.</p>
<p>One particular interesting section states the following:</p>
<blockquote>
<p>YOUR OBLIGATION TO PAY US BACK FOR ALL CARD TRANSACTIONS AND OTHER OBLIGATIONS YOU INCUR IS SECURED BY THE SECURED ACCOUNT. IF YOU DO NOT PAY US BACK FOR ANY AMOUNT YOU OWE US WHEN YOUR PAYMENTS ARE DUE, WE WILL EXERCISE OUR INTEREST AND DEBIT THE SECURED ACCOUNT, AND YOU WILL LOSE THE MONEY IN THE SECURED ACCOUNT. SEE SECTION 8: SECURITY AGREEMENT FOR MORE INFORMATION.</p>
</blockquote>
<h3 id="personal-information"><span class="section-number-3">1.3.</span> Personal Information</h3>
<p>Now that Privacy.com is more of a financial institution, they are obligated to comply with the <a href="https://en.wikipedia.org/wiki/Know_your_customer">know your customer</a> guidelines/laws.</p>
<p>I did not proceed with the change to my Privacy.com account, but I have heard from some peers that the changes require more personal information to be submitted, such as SSN (Social Security Number). I am not aware of all new personal information required or if the funding source is now required to only be a bank account.</p>
<h3 id="fees"><span class="section-number-3">1.4.</span> Fees</h3>
<p>Luckily, the fees section did not change much. The subscription fees for a premium account are still the only fees.</p>
<h2 id="my-thoughts"><span class="section-number-2">2.</span> My Thoughts</h2>
<p>Personally, I wiped my personal information from my account and then permanently deleted it when I heard about these changes. I have no interest in yet another method of credit lending offered by private companies. While I accepted that they would have access to my bank account information for the purposes of paying off my prepaid debit payments, I have no interest in incurring charges that will need to be paid back at a later date. I also have no interest in submitting personal information to Privacy.com.</p>
<p>This type of change toward a "buy it now, pay us later" model is concerning, and I will be watching Privacy.com to see if they further their interests in the credit model as time goes on.</p>
<p>Could we see them start charging interest, fees, etc.? I'm not sure, but this change does not inspire confidence in their mission as a privacy-focused company.</p>
]]></description>
    </item>
    <item>
      <title>Bash-It: Plugins and Autosuggestions</title>
      <link>https://cleberg.net/blog/bash-it.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/bash-it.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Sun, 31 Jul 2022 00:00:00 +0000</pubDate>
      <category>linux</category>
      <description><![CDATA[<h2 id="bash"><span class="section-number-2">1.</span> Bash</h2>
<p>For those who are not familiar, <a href="https://en.wikipedia.org/wiki/Bash_(Unix_shell)">Bash</a> is a Unix shell that is used as the default login shell for most Linux distributions. This shell and command processor should be familiar if you've used Linux (or older version of macOS) before.</p>
<p>However, bash is not the only option. There are numerous other shells that exist. Here are some popular examples:</p>
<ul>
<li><a href="https://en.wikipedia.org/wiki/Z_shell">zsh</a></li>
<li><a href="https://en.wikipedia.org/wiki/Fish_(Unix_shell)">fish</a></li>
<li><a href="https://github.com/ibara/oksh">oksh</a></li>
<li><a href="https://wiki.gentoo.org/wiki/Mksh">mksh</a></li>
<li><a href="https://en.wikipedia.org/wiki/Debian_Almquist_shell">dash</a></li>
</ul>
<p>While each shell has its differences, bash is POSIX compliant and the default for many Linux users. Because of this, I am going to explore a program called <code class="verbatim">bash-it</code> below that helps bash users increase the utility of their shell without installing a completely new shell.</p>
<h3 id="installation"><span class="section-number-3">1.1.</span> Installation</h3>
<p>First, if bash is not already installed on your system, you can <a href="https://www.gnu.org/software/bash/">download bash from GNU</a> or use your package manager to install it.</p>
<p>For example, this is how you can install bash on Fedora Linux:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> dnf install bash</span></span></code></pre>
<p>If you are not using bash as your default shell, use the <code class="verbatim">chsh</code> command to change your shell:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">chsh</span></span></span></code></pre>
<p>You should see a prompt like the one below. If the brackets (<code class="verbatim">[]</code>) contain <code class="verbatim">bash</code> already, you're done, and you can simply continue by hitting the Enter key.</p>
<p>If the brackets contain another shell path (e.g. <code class="verbatim">/usr/bin/zsh</code>), enter the path to the bash program on your system (it's most likely located at <code class="verbatim">/usr/bin/bash</code>).</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">Changing</span></span><span class="meta function-call arguments shell"> shell for <span class="keyword operator assignment redirection shell">&lt;</span>user<span class="keyword operator assignment redirection shell">&gt;</span>.</span>
<span class="meta function-call shell"><span class="variable function shell">New</span></span><span class="meta function-call arguments shell"> shell <span class="keyword control regexp set begin shell">[</span>/usr/bin/bash<span class="keyword control regexp set end shell">]</span>:</span></span></code></pre>
<p>You must log out or restart the machine in order for the login shell to be refreshed. You can do it now or wait until you're finished customizing the shell.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> reboot now</span></span></code></pre>
<h2 id="bash-it"><span class="section-number-2">2.</span> Bash-it</h2>
<p>As noted on the <a href="https://github.com/Bash-it/bash-it">Bash-it</a> repository:</p>
<blockquote>
<p>Bash-it is a collection of community Bash commands and scripts for Bash 3.2+. (And a shameless ripoff of oh-my-zsh 😃)</p>
</blockquote>
<p>Bash-it makes it easy to install plugins, set up aliases for common commands, and easily change the visual theme of your shell.</p>
<h3 id="installation"><span class="section-number-3">2.1.</span> Installation</h3>
<p>To install the framework, simply copy the repository files and use the <code class="verbatim">install.sh</code> script provided. If you want, you can (and should!) inspect the contents of the installation script before you run it.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">git</span></span><span class="meta function-call arguments shell"> clone<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> --</span>depth</span><span class="keyword operator assignment option shell">=</span>1 https://github.com/Bash-it/bash-it.git <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/.bash_it</span>
<span class="meta function-call shell"><span class="variable function shell"><span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/.bash_it/install.sh</span></span></span></code></pre>
<p>If you didn't restart your session after making bash the default, and are currently working within another shell, be sure to enter a bash session before using <code class="verbatim">bash-it</code>:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">bash</span></span></span></code></pre>
<h3 id="aliases"><span class="section-number-3">2.2.</span> Aliases</h3>
<p>Bash-it contains a number of aliases for common commands to help improve efficiency in the terminal. To list all available options, use the following command:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">bash-it</span></span><span class="meta function-call arguments shell"> show aliases</span></span></code></pre>
<p>This will provide you a list that looks like the following text block. Within this screen, you will be able to see all available options and which ones are currently enabled.</p>
<pre><code class="language-txt highlight"><span class="text plain">Alias                Enabled?   Description
ag                   [ ]        the silver searcher (ag) aliases
ansible              [ ]        ansible abbreviations
apt                  [ ]        Apt and dpkg aliases for Ubuntu and Debian distros.
atom                 [ ]        Atom.io editor abbreviations
bash-it              [ ]        Aliases for the bash-it command (these aliases are automatically included with the &quot;general&quot; aliases)
bolt                 [ ]        puppet bolt aliases
bundler              [ ]        ruby bundler
clipboard            [ ]        xclip shortcuts
composer             [ ]        common composer abbreviations
curl                 [x]        Curl aliases for convenience.
...</span></code></pre>
<p>To enable an alias, do:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">bash-it</span></span><span class="meta function-call arguments shell"> enable alias  <span class="keyword operator assignment redirection shell">&lt;</span>alias name<span class="keyword operator assignment redirection shell">&gt;</span> <span class="keyword control regexp set begin shell">[</span>alias name<span class="keyword control regexp set end shell">]</span>...<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>or-</span> $ bash-it enable alias all</span></span></code></pre>
<p>To disable an alias, do:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">bash-it</span></span><span class="meta function-call arguments shell"> disable alias <span class="keyword operator assignment redirection shell">&lt;</span>alias name<span class="keyword operator assignment redirection shell">&gt;</span> <span class="keyword control regexp set begin shell">[</span>alias name<span class="keyword control regexp set end shell">]</span>...<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>or-</span> $ bash-it disable alias all</span></span></code></pre>
<h3 id="plugins"><span class="section-number-3">2.3.</span> Plugins</h3>
<p>Similar to aliases, plugins are available with bash-it. You can find a complete list of plugins in the same way as aliases. Simply execute the following:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">bash-it</span></span><span class="meta function-call arguments shell"> show plugins</span></span></code></pre>
<p>You will see the following output showing enabled and disabled plugins:</p>
<pre><code class="language-txt highlight"><span class="text plain">Plugin               Enabled?   Description
alias-completion     [ ]
autojump             [ ]        Autojump configuration, see https://github.com/wting/autojump for more details
aws                  [ ]        AWS helper functions
base                 [x]        miscellaneous tools
basher               [ ]        initializes basher, the shell package manager
battery              [x]        display info about your battery charge level
blesh                [ ]        load ble.sh, the Bash line editor!
boot2docker          [ ]        Helpers to get Docker setup correctly for boot2docker
browser              [ ]        render commandline output in your browser</span></code></pre>
<p>To enable a plugin, do:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">bash-it</span></span><span class="meta function-call arguments shell"> enable plugin  <span class="keyword operator assignment redirection shell">&lt;</span>plugin name<span class="keyword operator assignment redirection shell">&gt;</span> <span class="keyword control regexp set begin shell">[</span>plugin name<span class="keyword control regexp set end shell">]</span>...<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>or-</span> $ bash-it enable plugin all</span></span></code></pre>
<p>To disable a plugin, do:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">bash-it</span></span><span class="meta function-call arguments shell"> disable plugin <span class="keyword operator assignment redirection shell">&lt;</span>plugin name<span class="keyword operator assignment redirection shell">&gt;</span> <span class="keyword control regexp set begin shell">[</span>plugin name<span class="keyword control regexp set end shell">]</span>...<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>or-</span> $ bash-it disable plugin all</span></span></code></pre>
<h3 id="themes"><span class="section-number-3">2.4.</span> Themes</h3>
<p>There are quite a few pre-defined <a href="https://bash-it.readthedocs.io/en/latest/themes-list/#list-of-themes">themes</a> available with bash-it.</p>
<p>To list all themes:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">ls</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/.bash_it/themes/</span></span></code></pre>
<p>To use a new theme, you'll need to edit <code class="verbatim">.bashrc</code> and alter the <code class="verbatim">BASH_IT_THEME</code> variable to your desired theme. For example, I am using the <code class="verbatim">zork</code> theme.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">nano</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/.bashrc</span></span></code></pre>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="storage modifier shell">export</span> <span class="variable other readwrite assignment shell">BASH_IT_THEME</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell"><span class="string quoted single shell"><span class="punctuation definition string begin shell">&#39;</span>zork<span class="punctuation definition string end shell">&#39;</span></span></span></span></span></code></pre>
<p>Once you save your changes, you just need to exit your terminal and create a new one in order to see your changes to the <code class="verbatim">.bashrc</code> file. You can also <code class="verbatim">source</code> the file to see changes, but I recommend starting a completely new shell instead.</p>
<h4 id="ble-sh"><span class="section-number-4">2.4.1.</span> ble.sh</h4>
<p>One big feature I was missing in Bash that both <code class="verbatim">zsh</code> and <code class="verbatim">fish</code> have is an autosuggestion feature. To explain: as you type, an autosuggestion feature in the shell will offer suggestions in a lighter font color beyond the characters already typed. Once you see the command you want, you can click the right arrow and have the shell auto-complete that line for you.</p>
<p>Luckily, the <a href="https://github.com/akinomyoga/ble.sh">Bash Line Editor</a> (ble.sh) exists! This program provides a wonderful autosuggestions feature perfectly, among other features that I haven't tested yet.</p>
<p>In order to install ble.sh, execute the following:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">git</span></span><span class="meta function-call arguments shell"> clone<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> --</span>recursive</span> https://github.com/akinomyoga/ble.sh.git</span>
<span class="meta function-call shell"><span class="variable function shell">make</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>C</span> ble.sh install PREFIX=<span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/.local</span>
<span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted single shell"><span class="punctuation definition string begin shell">&#39;</span>source ~/.local/share/blesh/ble.sh<span class="punctuation definition string end shell">&#39;</span></span> <span class="keyword operator assignment redirection shell">&gt;&gt;</span> <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/.bashrc</span></span></code></pre>
<p>Again, exit the terminal and open a new one in order to see the newly-configured shell.</p>
<h2 id="restart-the-session"><span class="section-number-2">3.</span> Restart the Session</h2>
<p>Finally, as mentioned above, you'll need to restart the session to ensure that your user is using bash by default.</p>
<p>You will also need to exit and re-open a shell (e.g., terminal or terminal tab) any time you make changes to the <code class="verbatim">.bashrc</code> file.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> reboot now</span></span></code></pre>
]]></description>
    </item>
    <item>
      <title>Recursive FLAC to Opus Conversion</title>
      <link>https://cleberg.net/blog/flac-to-opus.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/flac-to-opus.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Sat, 30 Jul 2022 00:00:00 +0000</pubDate>
      <category>linux</category>
      <description><![CDATA[<h2 id="converting-flac-to-opus"><span class="section-number-2">1.</span> Converting FLAC to OPUS</h2>
<p>I am currently rebuilding my music library from scratch so that I can effectively archive all the music I own in <a href="https://wikipedia.org/wiki/FLAC">FLAC</a> (Free Lossless Audio Codec) files.</p>
<p>However, streaming FLAC files outside the home can be difficult due to the size of the files, especially if you're using a weak connection.</p>
<p>So, in order to archive the music in a lossless format and still be able to stream it easily, I opted to create a copy of my FLAC files in the <a href="https://en.wikipedia.org/wiki/Opus_(audio_format)">Opus audio codec</a>. This allows me to archive a quality, lossless version of the music and then point my streaming service to the smaller, stream-ready version.</p>
<h3 id="dependencies"><span class="section-number-3">1.1.</span> Dependencies</h3>
<p>The process I follow utilizes the <code class="verbatim">opus-tools</code> package in Ubuntu. Before proceeding, install the package:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> apt install opus-tools</span></span></code></pre>
<p>If you want to use a different conversion method, such as <code class="verbatim">ffmpeg</code> or <code class="verbatim">avconv</code>, simply install that package instead.</p>
<h3 id="conversion-process"><span class="section-number-3">1.2.</span> Conversion Process</h3>
<p>The script I'm using is stored in my home directory, but feel free to create it wherever you want. It does not need to be in the same directory as your music files.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="support function cd shell">cd</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span></span> <span class="keyword operator logical and shell">&amp;&amp;</span> <span class="meta function-call shell"><span class="variable function shell">nano</span></span><span class="meta function-call arguments shell"> transform.sh</span></span></code></pre>
<p>Once you have your new bash script opened in an editor, go ahead and paste the following logic into the script.</p>
<p>You <strong>MUST</strong> edit the following variables in order for it to work:</p>
<ul>
<li><code class="verbatim">source</code>: The source directory where your FLAC files are stored.</li>
<li><code class="verbatim">dest</code>: The destination directory where you want the resulting Opus files to be stored.</li>
</ul>
<p>You <strong>MAY</strong> want to edit the following variables to suit your needs:</p>
<ul>
<li><code class="verbatim">filename</code>: If you are converting to a file format other than Opus, you'll need to edit this so that your resulting files have the correct filename extension.</li>
<li><code class="verbatim">reldir</code>: This variable can be edited to strip out more leading directories in the file path. As you'll see later, I ignore this for now and simply clean it up afterward.</li>
<li><code class="verbatim">opusenc</code>: This is the actual conversion process. You may want to edit the bitrate to suit your needs. I set mine at 128 but some prefer 160 or higher.</li>
</ul>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell">!/bin/bash</span><span class="comment line number-sign shell">
</span><span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"># - The IFS takes care of spaces in file and dirnames</span><span class="comment line number-sign shell">
</span><span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"># - your folders may vary</span><span class="comment line number-sign shell">
</span><span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"># - what you mount to the folders does not matter</span><span class="comment line number-sign shell">
</span><span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"># - in RELDIR, the f5 most likely MUST be edited,</span><span class="comment line number-sign shell">
</span><span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell">#    since its responsible, how many leading directories</span><span class="comment line number-sign shell">
</span><span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell">#    will be removed from the directory structure in order</span><span class="comment line number-sign shell">
</span><span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell">#    to append that exact path to the outfile</span><span class="comment line number-sign shell">
</span><span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"># - the commented echos are still in place in order to give</span><span class="comment line number-sign shell">
</span><span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell">#    you the variables for testing, before running.</span><span class="comment line number-sign shell">
</span>
<span class="variable other readwrite assignment shell">IFS</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell"><span class="string quoted single ansi-c shell"><span class="punctuation definition string begin shell">$&#39;</span><span class="constant character escape shell">\n</span><span class="punctuation definition string end shell">&#39;</span></span></span>

<span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"># the paths given here contain the directory structure that I want to keep</span><span class="comment line number-sign shell">
</span><span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"># source=/mnt/music/archives/ARTIST/ALBUM/FLACFILE.flac</span><span class="comment line number-sign shell">
</span><span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"># local=/mnt/music/library/ARTIST/ALBUM/OPUSFILE.opus</span><span class="comment line number-sign shell">
</span>
<span class="variable other readwrite assignment shell">source</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell">/mnt/music/archives</span>
<span class="variable other readwrite assignment shell">dest</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell">/mnt/music/library</span>

<span class="keyword control for shell">for</span><span class="meta group for shell"> i <span class="keyword control in shell">in</span> <span class="meta group expansion command parens shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section parens begin shell">(</span><span class="meta function-call shell"><span class="variable function shell">find</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">source</span></span><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>type</span> f<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>iname</span> <span class="string quoted single shell"><span class="punctuation definition string begin shell">&#39;</span>*.flac<span class="punctuation definition string end shell">&#39;</span></span> </span><span class="punctuation section parens end shell">)</span></span></span><span class="keyword operator logical continue shell">;</span>
<span class="keyword control do shell">do</span>
<span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"># SET VARIABLES for PATHS and FILENAMES</span><span class="comment line number-sign shell">
</span>        <span class="variable other readwrite assignment shell">fullfile</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell"><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">i</span></span></span>
        <span class="variable other readwrite assignment shell">filename</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell"><span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section expansion parameter begin shell">{</span></span><span class="meta group expansion parameter shell"><span class="variable other readwrite shell">i<span class="keyword operator expansion shell">##</span></span></span><span class="meta group expansion parameter shell"><span class="keyword operator regexp quantifier shell">*</span>/</span><span class="meta group expansion parameter shell"><span class="punctuation section expansion parameter end shell">}</span></span><span class="punctuation definition string end shell">&quot;</span></span></span>
        <span class="variable other readwrite assignment shell">filename</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell"><span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section expansion parameter begin shell">{</span></span><span class="meta group expansion parameter shell"><span class="variable other readwrite shell">filename<span class="keyword operator expansion shell">%</span></span></span><span class="meta group expansion parameter shell">.<span class="keyword operator regexp quantifier shell">*</span></span><span class="meta group expansion parameter shell"><span class="punctuation section expansion parameter end shell">}</span></span>.opus<span class="punctuation definition string end shell">&quot;</span></span></span>
        <span class="variable other readwrite assignment shell">fulldir</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell"><span class="meta group expansion command parens shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section parens begin shell">(</span><span class="meta function-call shell"><span class="variable function shell">dirname</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section expansion parameter begin shell">{</span></span><span class="meta group expansion parameter shell"><span class="variable other readwrite shell">i</span></span><span class="meta group expansion parameter shell"><span class="punctuation section expansion parameter end shell">}</span></span><span class="punctuation definition string end shell">&quot;</span></span></span><span class="punctuation section parens end shell">)</span></span></span>
        <span class="variable other readwrite assignment shell">reldir</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell"><span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion command parens shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section parens begin shell">(</span><span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">fulldir</span></span></span> <span class="keyword operator logical pipe shell">|</span> <span class="meta function-call shell"><span class="variable function shell">cut</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>d</span><span class="string quoted single shell"><span class="punctuation definition string begin shell">&#39;</span>/<span class="punctuation definition string end shell">&#39;</span></span><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>f5-</span></span><span class="punctuation section parens end shell">)</span></span><span class="punctuation definition string end shell">&quot;</span></span></span>
        <span class="variable other readwrite assignment shell">reldir</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell"><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section expansion parameter begin shell">{</span></span><span class="meta group expansion parameter shell"><span class="variable other readwrite shell">reldir</span></span><span class="meta group expansion parameter shell"><span class="keyword operator substitution shell">/</span></span><span class="meta group expansion parameter shell"><span class="variable parameter switch shell">/</span></span><span class="meta group expansion parameter shell">flac</span><span class="meta group expansion parameter shell"><span class="punctuation section expansion parameter end shell">}</span></span></span>
        <span class="variable other readwrite assignment shell">outdir</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell"><span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">dest</span></span>/<span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">reldir</span></span><span class="punctuation definition string end shell">&quot;</span></span></span>
        <span class="variable other readwrite assignment shell">outfile</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell"><span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">outdir</span></span>/<span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">filename</span></span><span class="punctuation definition string end shell">&quot;</span></span></span>

<span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> is that working?</span><span class="comment line number-sign shell">
</span><span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> outfile=&#39;$local/&quot;&quot;$(echo $(dirname &quot;${i}&quot;) | cut -d&#39;/&#39; -f5-)&quot;//flac&quot;/&quot;${i##*/}&quot;&#39;</span><span class="comment line number-sign shell">
</span><span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell">       echo &#39;output file: &#39; &quot;$outfile&quot;</span><span class="comment line number-sign shell">
</span>
<span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"># SHOW ME THE CONTENTS of the VARIABLES</span><span class="comment line number-sign shell">
</span><span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell">       echo &#39;File found:&#39; &quot;$i&quot;</span><span class="comment line number-sign shell">
</span><span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell">       echo &#39;Relative dir: &#39; &quot;$reldir&quot;</span><span class="comment line number-sign shell">
</span><span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell">       echo &#39;directory will be created: &#39; &quot;$outdir&quot;</span><span class="comment line number-sign shell">
</span><span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell">       echo &#39;Filename: &#39; &quot;$filename&quot;</span><span class="comment line number-sign shell">
</span><span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell">       echo &#39;FileExt: &#39; &quot;$extension&quot;</span><span class="comment line number-sign shell">
</span><span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell">       echo &#39;output file: &#39; &quot;$outfile&quot;</span><span class="comment line number-sign shell">
</span>
<span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>\n\n<span class="punctuation definition string end shell">&quot;</span></span></span>

<span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"># CREATE Output Folders</span><span class="comment line number-sign shell">
</span>        <span class="meta function-call shell"><span class="variable function shell">mkdir</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>p</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">outdir</span></span><span class="punctuation definition string end shell">&quot;</span></span></span>

<span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"># RUN</span><span class="comment line number-sign shell">
</span><span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> ffmpeg and avconv are alternative options if opusenc isn&#39;t adequate</span><span class="comment line number-sign shell">
</span><span class="meta function-call shell"><span class="variable function shell">opusenc</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> --</span>vbr</span><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> --</span>bitrate</span> 128<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> --</span>date</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">DATE</span></span><span class="punctuation definition string end shell">&quot;</span></span> <span class="punctuation separator continuation line shell">\
</span><span class="variable parameter option shell"><span class="punctuation definition parameter shell">--</span>title</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">TITLE</span></span><span class="punctuation definition string end shell">&quot;</span></span><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> --</span>artist</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">ARTIST</span></span><span class="punctuation definition string end shell">&quot;</span></span><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> --</span>album</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">ALBUM</span></span><span class="punctuation definition string end shell">&quot;</span></span><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> --</span>genre</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">GENRE</span></span><span class="punctuation definition string end shell">&quot;</span></span> <span class="punctuation separator continuation line shell">\
</span><span class="variable parameter option shell"><span class="punctuation definition parameter shell">--</span>comment</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>ALBUMARTIST=<span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">ALBUMARTIST</span></span><span class="punctuation definition string end shell">&quot;</span></span><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> --</span>comment</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>DISCNUMBER=<span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">DISCNUMBER</span></span><span class="punctuation definition string end shell">&quot;</span></span> <span class="punctuation separator continuation line shell">\
</span><span class="variable parameter option shell"><span class="punctuation definition parameter shell">--</span>comment</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>TRACKNUMBER=<span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">TRACKNUMBER</span></span><span class="punctuation definition string end shell">&quot;</span></span><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> --</span>comment</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>TRACKTOTAL=<span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">TRACKTOTAL</span></span><span class="punctuation definition string end shell">&quot;</span></span> <span class="punctuation separator continuation line shell">\
</span><span class="variable parameter option shell"><span class="punctuation definition parameter shell">--</span>comment</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>LYRICS=<span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">LYRICS</span></span><span class="punctuation definition string end shell">&quot;</span></span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">fullfile</span></span><span class="punctuation definition string end shell">&quot;</span></span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">outfile</span></span><span class="punctuation definition string end shell">&quot;</span></span></span>


<span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"># just for testing</span><span class="comment line number-sign shell">
</span><span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell">        sleep 1</span><span class="comment line number-sign shell">
</span><span class="meta function-call shell"><span class="variable function shell">done</span></span></span></code></pre>
<p>Once you're done, simply save the file and exit your editor. Don't forget to enable execution of the script:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">chmod</span></span><span class="meta function-call arguments shell"> +x transform.sh</span></span></code></pre>
<p>Finally, you may now run the script:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">./transform.sh</span></span></span></code></pre>
<p>If you used <code class="verbatim">opusenc</code>, you'll see the conversions happen within the terminal as it progresses. You will also see variables printed if you uncommented any of the bash script's comments.</p>
<h3 id="cleanup"><span class="section-number-3">1.3.</span> Cleanup</h3>
<p>As I noted above, I didn't customize my <code class="verbatim">reldir</code> variable in the script, which caused my output directory to be <code class="verbatim">/mnt/music/library/archives</code> instead of <code class="verbatim">/mnt/music/library</code>. So, I moved the output up one level and deleted the accidental directory.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="support function cd shell">cd</span></span><span class="meta function-call arguments shell"> /mnt/music/library</span>
<span class="meta function-call shell"><span class="variable function shell">mv</span></span><span class="meta function-call arguments shell"> archives/<span class="keyword operator regexp quantifier shell">*</span><span class="keyword operator regexp quantifier shell">*</span> .</span>
<span class="meta function-call shell"><span class="variable function shell">rm</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>rf</span> archives</span></span></code></pre>
<h3 id="check-the-resulting-size"><span class="section-number-3">1.4.</span> Check the Resulting Size</h3>
<p>If you want to see what kind of file size savings you've gained, you can always use the <code class="verbatim">du</code> command to check:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="support function cd shell">cd</span></span><span class="meta function-call arguments shell"> /mnt/music</span>
<span class="meta function-call shell"><span class="variable function shell">du</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>h</span><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> --</span>max-depth</span><span class="keyword operator assignment option shell">=</span>1 .</span></span></code></pre>
<p>In my case, my small library went from 78GB to 6.3GB!</p>
<pre><code class="language-txt highlight"><span class="text plain">78G    ./archives
6.3G   ./library</span></code></pre>
]]></description>
    </item>
    <item>
      <title>Curseradio: Internet Radio from the Terminal</title>
      <link>https://cleberg.net/blog/curseradio.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/curseradio.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Mon, 25 Jul 2022 00:00:00 +0000</pubDate>
      <category>linux</category>
      <description><![CDATA[<h2 id="overview"><span class="section-number-2">1.</span> Overview</h2>
<p>While exploring some interesting Linux applications, I stumbled across <a href="https://github.com/chronitis/curseradio">curseradio</a>, a command-line radio player based on Python.</p>
<p>This application is fantastic and incredibly easy to install, so I wanted to dedicate a post today to this app. Let's look at the features within the app and then walk through the installation process I took to get <code class="verbatim">curseradio</code> working.</p>
<h2 id="features"><span class="section-number-2">2.</span> Features</h2>
<p>The radio player itself is quite minimal. As you can see in the screenshot above, it contains a simple plaintext list of all available categories, which can be broken down further and further. In addition, radio shows are available for listening, alongside regular radio stations.</p>
<p>For example, the <code class="verbatim">Sports</code> &gt; <code class="verbatim">Pro Basketball</code> &gt; <code class="verbatim">Shows</code> category contains a number of specific shows related to Professional Basketball.</p>
<p>Aside from being able to play any of the listed stations/shows, you can make a channel your favorite by pressing <code class="verbatim">f</code>. It will now show up at the top of the radio player in the <code class="verbatim">Favourites</code> category.</p>
<h3 id="commands-shortcuts"><span class="section-number-3">2.1.</span> Commands/Shortcuts</h3>
<table>
<thead>
<tr><th>Key(s)</th><th>Command</th></tr>
</thead>
<tbody>
<tr><td>↑, ↓</td><td>navigate</td></tr>
<tr><td>PgUp, PgDn</td><td>navigate quickly</td></tr>
<tr><td>Home, End</td><td>to top/bottom</td></tr>
<tr><td>Enter</td><td>open/close folders, play stream</td></tr>
<tr><td>k</td><td>stop playing stream</td></tr>
<tr><td>q</td><td>quit</td></tr>
<tr><td>f</td><td>toggle favourite</td></tr>
</tbody>
</table>
<h2 id="installation"><span class="section-number-2">3.</span> Installation</h2>
<h3 id="dependencies"><span class="section-number-3">3.1.</span> Dependencies</h3>
<p>Before installing <code class="verbatim">curseradio</code>, a handful of system and Python packages are required. To get started, install <code class="verbatim">python3</code>, <code class="verbatim">pip3</code>, and <code class="verbatim">mpv</code> on your system. In this example, I'm using Fedora Linux, which uses the <code class="verbatim">dnf</code> package manager. You may need to adjust this if you're using a different system.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> dnf install python3 pip3 mpv</span></span></code></pre>
<p>Next, use <code class="verbatim">pip3</code> to install <code class="verbatim">requests</code>, <code class="verbatim">xdg</code>, and <code class="verbatim">lxml</code>:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">pip3</span></span><span class="meta function-call arguments shell"> install requests xdg lxml</span></span></code></pre>
<h3 id="repository-source-installation"><span class="section-number-3">3.2.</span> Repository Source Installation</h3>
<p>Once all the dependencies are installed, we can clone the source code and enter that directory:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">git</span></span><span class="meta function-call arguments shell"> clone https://github.com/chronitis/curseradio</span> <span class="keyword operator logical and shell">&amp;&amp;</span> <span class="meta function-call shell"><span class="support function cd shell">cd</span></span><span class="meta function-call arguments shell"> curseradio</span></span></code></pre>
<p>Once you're within the <code class="verbatim">curseradio</code> directory, you can install the application with the provided <code class="verbatim">setup.py</code> script.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> python3 setup.py install</span></span></code></pre>
<p>In my case, I ran into a few errors and needed to create the folders that curseradio wanted to use for its installation. If you don't get any errors, you can skip this and run the app.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> mkdir /usr/local/lib/python3.10/</span>
<span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> mkdir /usr/local/lib/python3.10/site-packages/</span></span></code></pre>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> chown<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>R</span> <span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">USER</span></span>:<span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">USER</span></span> /usr/local/lib/python3.10/</span></span></code></pre>
<h2 id="run-the-application"><span class="section-number-2">4.</span> Run the Application</h2>
<p>Once fully installed without errors, you can run the application!</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">python3</span></span><span class="meta function-call arguments shell"> /usr/local/bin/curseradio</span></span></code></pre>
]]></description>
    </item>
    <item>
      <title>GnuPG: Encryption, Signing, Web of Trust</title>
      <link>https://cleberg.net/blog/gnupg.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/gnupg.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Thu, 14 Jul 2022 00:00:00 +0000</pubDate>
      <category>linux</category>
      <category>security</category>
      <description><![CDATA[<h2 id="the-history-of-gpg"><span class="section-number-2">1.</span> The History of GPG</h2>
<p><a href="https://gnupg.org/">GNU Privacy Guard</a>, also known as GnuPG and GPG, is a free ("free" as in both speech and beer) software that fully implements the OpenPGP Message Format documented in <a href="https://www.rfc-editor.org/rfc/rfc4880">RFC 4880</a>.</p>
<p>I won't go in-depth on the full history of the software in this post, but it is important to understand that GPG is not the same as PGP (Pretty Good Privacy), which is a different implementation of RFC 4880. However, GPG was designed to interoperate with PGP.</p>
<p>GPG was originally developed in the late 1990s by <a href="https://en.wikipedia.org/wiki/Werner_Koch">Werner Koch</a> and has historically been funded generously by the German government.</p>
<p>Now that we have all the high-level info out of the way, let's dive into the different aspects of GPG and its uses.</p>
<h2 id="encryption-algorithms"><span class="section-number-2">2.</span> Encryption Algorithms</h2>
<p>GPG supports a wide range of different encryption algorithms, including public-key, cipher, hash, and compression algorithms. The support for these algorithms has grown since the adoption of the Libgcrypt library in the 2.x versions of GPG.</p>
<p>As you will be able to see below in an example of a full key generation with the GPG command line tool, GPG recommends the following algorithms to new users:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">Please</span></span><span class="meta function-call arguments shell"> select what kind of key you want:</span>
   <span class="punctuation definition compound begin shell">(</span><span class="meta function-call shell"><span class="variable function shell">1</span></span><span class="punctuation definition compound end shell">)</span><span class="meta function-call arguments shell"> RSA and RSA</span>
   <span class="punctuation definition compound begin shell">(</span><span class="meta function-call shell"><span class="variable function shell">2</span></span><span class="punctuation definition compound end shell">)</span><span class="meta function-call arguments shell"> DSA and Elgamal</span>
   <span class="punctuation definition compound begin shell">(</span><span class="meta function-call shell"><span class="variable function shell">3</span></span><span class="punctuation definition compound end shell">)</span><span class="meta function-call arguments shell"> DSA (sign only</span><span class="meta function-call shell"></span><span class="meta post-cmd shell">)</span>
   <span class="punctuation definition compound begin shell">(</span><span class="meta function-call shell"><span class="variable function shell">4</span></span><span class="punctuation definition compound end shell">)</span><span class="meta function-call arguments shell"> RSA (sign only</span><span class="meta function-call shell"></span><span class="meta post-cmd shell">)</span>
   <span class="punctuation definition compound begin shell">(</span><span class="meta function-call shell"><span class="variable function shell">9</span></span><span class="punctuation definition compound end shell">)</span><span class="meta function-call arguments shell"> ECC (sign and encrypt</span><span class="meta function-call shell"></span><span class="meta post-cmd shell">)</span> <span class="meta function-call shell"><span class="variable function shell">*default*</span></span>
  <span class="punctuation definition compound begin shell">(</span><span class="meta function-call shell"><span class="variable function shell">10</span></span><span class="punctuation definition compound end shell">)</span><span class="meta function-call arguments shell"> ECC (sign only</span><span class="meta function-call shell"></span><span class="meta post-cmd shell">)</span></span></code></pre>
<p>I am not doing an in-depth explanation here in order to keep the focus on GPG and not encryption algorithms. If you want a deep dive into cryptography or encryption algorithms, please read my other posts:</p>
<ul>
<li><a href="https://cleberg.net/blog/aes-encryption.html">How AES Encryption Works</a> (2018)</li>
<li><a href="https://cleberg.net/blog/cryptography.html">A Practical Guide to Encryption, Keys, and Secure Communication</a> (2020)</li>
</ul>
<h3 id="vulnerabilities"><span class="section-number-3">2.1.</span> Vulnerabilities</h3>
<p>As of 2022-07-14, there are a few different vulnerabilities associated with GPG or the libraries it uses:</p>
<ul>
<li>GPG versions 1.0.2–1.2.3 contains a bug where "as soon as one (GPG-generated) ElGamal signature of an arbitrary message is released, one can recover the signer's private key in less than a second on a PC." (<a href="https://www.di.ens.fr/~pnguyen/pub_Ng04.htm">Source</a>)</li>
<li>GPG versions prior to 1.4.2.1 contain a false positive signature verification bug. (<a href="https://lists.gnupg.org/pipermail/gnupg-announce/2006q1/000211.html">Source</a>)</li>
<li>GPG versions prior to 1.4.2.2 cannot detect injection of unsigned data. ( <a href="https://lists.gnupg.org/pipermail/gnupg-announce/2006q1/000218.html">Source</a>)</li>
<li>Libgcrypt, a library used by GPG, contained a bug which enabled full key recovery for RSA-1024 and some RSA-2048 keys. This was resolved in a GPG update in 2017. (<a href="https://lwn.net/Articles/727179/">Source</a>)</li>
<li>The <a href="https://en.wikipedia.org/wiki/ROCA_vulnerability">ROCA Vulnerability</a> affects RSA keys generated by YubiKey 4 tokens. (<a href="https://crocs.fi.muni.cz/_media/public/papers/nemec_roca_ccs17_preprint.pdf">Source</a>)</li>
<li>The <a href="https://en.wikipedia.org/wiki/SigSpoof">SigSpoof Attack</a> allows an attacker to spoof digital signatures. (<a href="https://arstechnica.com/information-technology/2018/06/decades-old-pgp-bug-allowed-hackers-to-spoof-just-about-anyones-signature/">Source</a>)</li>
<li>Libgcrypt 1.9.0 contains a severe flaw related to a heap buffer overflow, fixed in Libgcrypt 1.9.1 (<a href="https://web.archive.org/web/20210221012505/https://www.theregister.com/2021/01/29/severe_libgcrypt_bug/">Source</a>)</li>
</ul>
<h4 id="platforms"><span class="section-number-4">2.1.1.</span> Platforms</h4>
<p>Originally developed as a command-line program for *nix systems, GPG now has a wealth of front-end applications and libraries available for end-users. However, the most recommended programs remain the same:</p>
<ul>
<li><a href="https://gnupg.org">GnuPG</a> for Linux (depending on distro)</li>
<li><a href="https://gpg4win.org">Gpg4win</a> for Windows</li>
<li><a href="https://gpgtools.org">GPGTools</a> for macOS</li>
</ul>
<h2 id="creating-a-key-pair"><span class="section-number-2">3.</span> Creating a Key Pair</h2>
<p>In order to create a GPG key pair, a user would first need to install GPG on their system. If we're assuming that the user is on Fedora Linux, they would execute the following:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> dnf install gpg</span></span></code></pre>
<p>Once installed, a user can create a new key pair with the following command(s):</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">gpg</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> --</span>full-generate-key</span></span></span></code></pre>
<p>GPG will walk the user through an interactive setup that asks for an algorithm preference, expiration date, name, and email to associate with this key.</p>
<p>See the following example key set-up for a default key generation using the GnuPG command-line interface:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">gpg</span></span><span class="meta function-call arguments shell"> (GnuPG</span><span class="meta function-call shell"></span><span class="meta post-cmd shell">)</span> <span class="meta function-call shell"><span class="variable function shell">2.3.6</span></span><span class="keyword operator logical continue shell">;</span> <span class="meta function-call shell"><span class="variable function shell">Copyright</span></span><span class="meta function-call arguments shell"> (C</span><span class="meta function-call shell"></span><span class="meta post-cmd shell">)</span> <span class="meta function-call shell"><span class="variable function shell">2021</span></span><span class="meta function-call arguments shell"> Free Software Foundation, Inc.</span>
<span class="meta function-call shell"><span class="variable function shell">This</span></span><span class="meta function-call arguments shell"> is free software: you are free to change and redistribute it.</span>
<span class="meta function-call shell"><span class="variable function shell">There</span></span><span class="meta function-call arguments shell"> is NO WARRANTY, to the extent permitted by law.</span>

<span class="meta function-call shell"><span class="variable function shell">Please</span></span><span class="meta function-call arguments shell"> select what kind of key you want:</span>
   <span class="punctuation definition compound begin shell">(</span><span class="meta function-call shell"><span class="variable function shell">1</span></span><span class="punctuation definition compound end shell">)</span><span class="meta function-call arguments shell"> RSA and RSA</span>
   <span class="punctuation definition compound begin shell">(</span><span class="meta function-call shell"><span class="variable function shell">2</span></span><span class="punctuation definition compound end shell">)</span><span class="meta function-call arguments shell"> DSA and Elgamal</span>
   <span class="punctuation definition compound begin shell">(</span><span class="meta function-call shell"><span class="variable function shell">3</span></span><span class="punctuation definition compound end shell">)</span><span class="meta function-call arguments shell"> DSA (sign only</span><span class="meta function-call shell"></span><span class="meta post-cmd shell">)</span>
   <span class="punctuation definition compound begin shell">(</span><span class="meta function-call shell"><span class="variable function shell">4</span></span><span class="punctuation definition compound end shell">)</span><span class="meta function-call arguments shell"> RSA (sign only</span><span class="meta function-call shell"></span><span class="meta post-cmd shell">)</span>
   <span class="punctuation definition compound begin shell">(</span><span class="meta function-call shell"><span class="variable function shell">9</span></span><span class="punctuation definition compound end shell">)</span><span class="meta function-call arguments shell"> ECC (sign and encrypt</span><span class="meta function-call shell"></span><span class="meta post-cmd shell">)</span> <span class="meta function-call shell"><span class="variable function shell">*default*</span></span>
  <span class="punctuation definition compound begin shell">(</span><span class="meta function-call shell"><span class="variable function shell">10</span></span><span class="punctuation definition compound end shell">)</span><span class="meta function-call arguments shell"> ECC (sign only</span><span class="meta function-call shell"></span><span class="meta post-cmd shell">)</span>
  <span class="punctuation definition compound begin shell">(</span><span class="meta function-call shell"><span class="variable function shell">14</span></span><span class="punctuation definition compound end shell">)</span><span class="meta function-call arguments shell"> Existing key from card</span>
<span class="meta function-call shell"><span class="variable function shell">Your</span></span><span class="meta function-call arguments shell"> selection<span class="keyword operator regexp quantifier shell">?</span> 9</span>
<span class="meta function-call shell"><span class="variable function shell">Please</span></span><span class="meta function-call arguments shell"> select which elliptic curve you want:</span>
   <span class="punctuation definition compound begin shell">(</span><span class="meta function-call shell"><span class="variable function shell">1</span></span><span class="punctuation definition compound end shell">)</span><span class="meta function-call arguments shell"> Curve 25519 <span class="keyword operator regexp quantifier shell">*</span>default<span class="keyword operator regexp quantifier shell">*</span></span>
   <span class="punctuation definition compound begin shell">(</span><span class="meta function-call shell"><span class="variable function shell">4</span></span><span class="punctuation definition compound end shell">)</span><span class="meta function-call arguments shell"> NIST P-384</span>
<span class="meta function-call shell"><span class="variable function shell">Your</span></span><span class="meta function-call arguments shell"> selection<span class="keyword operator regexp quantifier shell">?</span> 1</span>
<span class="meta function-call shell"><span class="variable function shell">Please</span></span><span class="meta function-call arguments shell"> specify how long the key should be valid.</span>
         <span class="meta function-call shell"><span class="variable function shell">0</span></span><span class="meta function-call arguments shell"> = key does not expire</span>
      <span class="meta function-call shell"></span><span class="meta function-call arguments shell"><span class="keyword operator assignment redirection shell">&lt;</span>n<span class="keyword operator assignment redirection shell">&gt;</span>  = key expires in n days</span>
      <span class="meta function-call shell"></span><span class="meta function-call arguments shell"><span class="keyword operator assignment redirection shell">&lt;</span>n<span class="keyword operator assignment redirection shell">&gt;</span>w = key expires in n weeks</span>
      <span class="meta function-call shell"></span><span class="meta function-call arguments shell"><span class="keyword operator assignment redirection shell">&lt;</span>n<span class="keyword operator assignment redirection shell">&gt;</span>m = key expires in n months</span>
      <span class="meta function-call shell"></span><span class="meta function-call arguments shell"><span class="keyword operator assignment redirection shell">&lt;</span>n<span class="keyword operator assignment redirection shell">&gt;</span>y = key expires in n years</span>
<span class="meta function-call shell"><span class="variable function shell">Key</span></span><span class="meta function-call arguments shell"> is valid for<span class="keyword operator regexp quantifier shell">?</span> (0</span><span class="meta function-call shell"></span><span class="meta post-cmd shell">)</span> <span class="meta function-call shell"><span class="variable function shell">0</span></span>
<span class="meta function-call shell"><span class="variable function shell">Key</span></span><span class="meta function-call arguments shell"> does not expire at all</span>
<span class="meta function-call shell"><span class="variable function shell">Is</span></span><span class="meta function-call arguments shell"> this correct<span class="keyword operator regexp quantifier shell">?</span> (y/N</span><span class="meta function-call shell"></span><span class="meta post-cmd shell">)</span> <span class="meta function-call shell"><span class="variable function shell">y</span></span>

<span class="meta function-call shell"><span class="variable function shell">GnuPG</span></span><span class="meta function-call arguments shell"> needs to construct a user ID to identify your key.</span>

<span class="meta function-call shell"><span class="variable function shell">Real</span></span><span class="meta function-call arguments shell"> name: John Doe</span>
<span class="meta function-call shell"><span class="variable function shell">Email</span></span><span class="meta function-call arguments shell"> address: johndoe@example.com</span>
<span class="meta function-call shell"><span class="variable function shell">Comment:</span></span><span class="meta function-call arguments shell"> test key</span>
<span class="meta function-call shell"><span class="variable function shell">You</span></span><span class="meta function-call arguments shell"> selected this USER-ID:</span>
    <span class="meta function-call shell"><span class="variable function shell"><span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>John Doe (test key) &lt;johndoe@example.com&gt;<span class="punctuation definition string end shell">&quot;</span></span></span></span>

<span class="meta function-call shell"><span class="variable function shell">Change</span></span><span class="meta function-call arguments shell"> (N</span><span class="meta function-call shell"></span><span class="meta post-cmd shell">)</span><span class="meta function-call shell"><span class="variable function shell">ame,</span></span><span class="meta function-call arguments shell"> (C</span><span class="meta function-call shell"></span><span class="meta post-cmd shell">)</span><span class="meta function-call shell"><span class="variable function shell">omment,</span></span><span class="meta function-call arguments shell"> (E</span><span class="meta function-call shell"></span><span class="meta post-cmd shell">)</span><span class="meta function-call shell"><span class="variable function shell">mail</span></span><span class="meta function-call arguments shell"> or (O</span><span class="meta function-call shell"></span><span class="meta post-cmd shell">)</span><span class="meta function-call shell"><span class="variable function shell">kay/</span></span><span class="meta function-call arguments shell">(Q</span><span class="meta function-call shell"></span><span class="meta post-cmd shell">)</span><span class="meta function-call shell"><span class="variable function shell">uit?</span></span><span class="meta function-call arguments shell"> O</span>
<span class="meta function-call shell"><span class="variable function shell">We</span></span><span class="meta function-call arguments shell"> need to generate a lot of random bytes. It is a good idea to perform</span>
<span class="meta function-call shell"><span class="variable function shell">some</span></span><span class="meta function-call arguments shell"> other action (type on the keyboard, move the mouse, utilize the</span>
<span class="meta function-call shell"><span class="variable function shell">disks</span></span><span class="meta function-call shell"></span><span class="meta post-cmd shell">)</span> <span class="meta function-call shell"><span class="variable function shell">during</span></span><span class="meta function-call arguments shell"> the prime generation</span><span class="keyword operator logical continue shell">;</span> <span class="meta function-call shell"><span class="variable function shell">this</span></span><span class="meta function-call arguments shell"> gives the random number</span>
<span class="meta function-call shell"><span class="variable function shell">generator</span></span><span class="meta function-call arguments shell"> a better chance to gain enough entropy.</span>
<span class="meta function-call shell"><span class="variable function shell">We</span></span><span class="meta function-call arguments shell"> need to generate a lot of random bytes. It is a good idea to perform</span>
<span class="meta function-call shell"><span class="variable function shell">some</span></span><span class="meta function-call arguments shell"> other action (type on the keyboard, move the mouse, utilize the</span>
<span class="meta function-call shell"><span class="variable function shell">disks</span></span><span class="meta function-call shell"></span><span class="meta post-cmd shell">)</span> <span class="meta function-call shell"><span class="variable function shell">during</span></span><span class="meta function-call arguments shell"> the prime generation</span><span class="keyword operator logical continue shell">;</span> <span class="meta function-call shell"><span class="variable function shell">this</span></span><span class="meta function-call arguments shell"> gives the random number</span>
<span class="meta function-call shell"><span class="variable function shell">generator</span></span><span class="meta function-call arguments shell"> a better chance to gain enough entropy.</span>
<span class="meta function-call shell"><span class="variable function shell">gpg:</span></span><span class="meta function-call arguments shell"> revocation certificate stored as <span class="string quoted single shell"><span class="punctuation definition string begin shell">&#39;</span>example.rev<span class="punctuation definition string end shell">&#39;</span></span></span>
<span class="meta function-call shell"><span class="variable function shell">public</span></span><span class="meta function-call arguments shell"> and secret key created and signed.</span>

<span class="meta function-call shell"><span class="variable function shell">pub</span></span><span class="meta function-call arguments shell">   ed25519 2022-07-14 <span class="keyword control regexp set begin shell">[</span>SC<span class="keyword control regexp set end shell">]</span></span>
      <span class="meta function-call shell"><span class="variable function shell">E955B7700FFC11EF51C2BA1FE096AACDD4C32E9C</span></span>
<span class="meta function-call shell"><span class="variable function shell">uid</span></span><span class="meta function-call arguments shell">                      John Doe (test key</span><span class="meta function-call shell"></span><span class="meta post-cmd shell">)</span> <span class="meta function-call shell"></span><span class="meta function-call arguments shell"><span class="keyword operator assignment redirection shell">&lt;</span>johndoe@example.com<span class="keyword operator assignment redirection shell">&gt;</span>
</span><span class="meta function-call shell"><span class="variable function shell">sub</span></span><span class="meta function-call arguments shell">   cv25519 2022-07-14 <span class="keyword control regexp set begin shell">[</span>E<span class="keyword control regexp set end shell">]</span></span></span></code></pre>
<p>Please note that graphical apps may differ slightly from the GPG command-line interface.</p>
<h2 id="common-usage"><span class="section-number-2">4.</span> Common Usage</h2>
<p>As noted in RFC (Request for Comments) 4880, the general functions of OpenPGP are as follows:</p>
<ul>
<li>digital signatures</li>
<li>encryption</li>
<li>compression</li>
<li>Radix-64 conversion</li>
<li>key management and certificate services</li>
</ul>
<p>From this, you can probably gather that the main use of GPG is for encrypting data and/or signing the data with a key. The purpose of encrypting data with GPG is to ensure that no one except the intended recipient(s) can access the data.</p>
<p>Let's explore some specific GPG use-cases.</p>
<h3 id="email"><span class="section-number-3">4.1.</span> Email</h3>
<p>One of the more popular uses of GPG is to sign and/or encrypt emails. With the use of a GPG keypair, you can encrypt a message, its subject, and even the attachments within.</p>
<p>The first process, regarding the signing of a message without any encryption, is generally used to provide assurance that an email is truly coming from the sender that the message claims. When I send an email, and it's signed with my public key, the recipient(s) of the message can verify that the message was signed with my personal key.</p>
<p>The second process, regarding the actual encryption of the message and its contents, works by using a combination of the sender's keys and the recipient's keys. This process may vary slightly by implementation, but it most commonly uses asymmetric cryptography, also known as public-key cryptography. In this version of encryption, the sender's private key to sign the message and a combination of the sender's keys and the recipient's public key to encrypt the message.</p>
<p>If two people each have their own private keys and exchange their public keys, they can send encrypted messages back and forth with GPG. This is also possible with symmetric cryptography, but the process differs since there are no key pairs.</p>
<p>Implementation of email encryption varies greatly between email clients, so you will need to reference your email client's documentation to ensure you are setting it up correctly for that specific client.</p>
<h3 id="file-encryption"><span class="section-number-3">4.2.</span> File Encryption</h3>
<p>As noted in the section above regarding emails, GPG enables users to be able to send a message to each other if they are both set-up with GPG keys. In this example, I am going to show how a user could send a file called <code class="verbatim">example_file.txt</code> to another user via the recipient's email.</p>
<p>The sender would find the file they want to send and execute the following command:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">gpg</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> --</span>encrypt</span><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> --</span>output</span> example_file.txt.gpg<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> --</span>recipient</span> <span class="punctuation separator continuation line shell">\
</span>recipient@example.com example_file.txt</span></span></code></pre>
<p>Once received, the recipient can decrypt the file with the following command:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">gpg</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> --</span>decrypt</span><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> --</span>output</span> example_file.txt example_file.txt.gpg</span></span></code></pre>
<h3 id="ownership-signatures"><span class="section-number-3">4.3.</span> Ownership Signatures</h3>
<p>One important aspect of GPG, especially for developers, is the ability to sign data without encrypting it. For example, developers often sign code changes when they commit the changes back to a central repository, in order to display ownership of who made the changes. This allows other users to look at a code change and determine that the change was valid.</p>
<p>In order to do this using <a href="https://git-scm.com">Git</a>, the developer simply needs to alter the <code class="verbatim">git commit</code> command to include the <code class="verbatim">-S</code> flag. Here's an example:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">git</span></span><span class="meta function-call arguments shell"> commit<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>S</span><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>m</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>my commit message<span class="punctuation definition string end shell">&quot;</span></span></span></span></code></pre>
<p>As an expansion of the example above, Git users can configure their environment with a default key to use by adding their GPG signature:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">git</span></span><span class="meta function-call arguments shell"> config<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> --</span>global</span> user.signingkey XXXXXXXXXXXXXXXX</span></span></code></pre>
<p>If you're not sure what your signature is, you can find it titled <code class="verbatim">sig</code> in the output of this command:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">gpg</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> --</span>list-signatures</span></span></span></code></pre>
<h3 id="file-integrity"><span class="section-number-3">4.4.</span> File Integrity</h3>
<p>When a person generates a signature for data, they are allowing users the ability to verify the signature on that data in the future to ensure the data has not been corrupted. This is most common with software applications hosted on the internet - developers provide signatures so that users can verify a website was not hijacked and download links replaced with dangerous software.</p>
<p>In order to verify signed data, a user needs to have:</p>
<ol>
<li>The signed data</li>
<li>A signature file</li>
<li>The public GPG key of the signer</li>
</ol>
<p>Once the signer's public key is imported on the user's system, and they have the data and signature, they can verify the data with the following commands:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> If the signature is attached to the data</span><span class="comment line number-sign shell">
</span><span class="meta function-call shell"><span class="variable function shell">gpg</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> --</span>verify</span> <span class="keyword control regexp set begin shell">[</span>signature<span class="keyword operator word shell">-</span>file<span class="keyword control regexp set end shell">]</span></span>

<span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> If the signature is detached as a separate file from the data</span><span class="comment line number-sign shell">
</span><span class="meta function-call shell"><span class="variable function shell">gpg</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> --</span>verify</span> <span class="keyword control regexp set begin shell">[</span>signature<span class="keyword operator word shell">-</span>file<span class="keyword control regexp set end shell">]</span> <span class="keyword control regexp set begin shell">[</span>original<span class="keyword operator word shell">-</span>file<span class="keyword control regexp set end shell">]</span></span></span></code></pre>
<h4 id="finding-public-keys"><span class="section-number-4">4.4.1.</span> Finding Public Keys</h4>
<p>In order to use GPG with others, a user needs to know the other user(s) keys. This is easy to do if the user knows the other user(s) in person, but may be hard if the relationship is strictly digital. Luckily, there are a few options. The first option is to look at a user's web page or social pages if they have them.</p>
<p>Otherwise, the best option is to use a keyserver, such as:</p>
<ul>
<li><a href="https://pgp.mit.edu">pgp.mit.edu</a></li>
<li><a href="https://keys.openpgp.org">keys.openpgp.org</a></li>
</ul>
]]></description>
    </item>
    <item>
      <title>Self-Hosting Guide: Git and cgit</title>
      <link>https://cleberg.net/blog/git-server.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/git-server.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Fri, 01 Jul 2022 00:00:00 +0000</pubDate>
      <category>linux</category>
      <category>self-hosting</category>
      <description><![CDATA[<h2 id="my-approach-to-self-hosting-git"><span class="section-number-2">1.</span> My Approach to Self-Hosting Git</h2>
<p>I have often tried to self-host my Git repositories, but have always fallen short when I tried to find a suitable web interface to show on the front-end.</p>
<p>After a few years, I have finally found a combination of methods that allow me to easily self-host my projects, view them on the web, and access them from anywhere.</p>
<p>Before I dive into the details, I want to state a high-level summary of my self-hosted Git approach:</p>
<ul>
<li>This method uses the <code class="verbatim">ssh://</code> (read &amp; write) and <code class="verbatim">git://</code> (read-only) protocols for push and pull access.<ul>
<li>For the <code class="verbatim">git://</code> protocol, I create a <code class="verbatim">git-daemon-export-ok</code> file in any repository that I want to be cloneable by anyone.</li>
<li>The web interface I am using (<code class="verbatim">cgit</code>) allows simple HTTP cloning by default. I do not disable this setting as I want beginners to be able to clone one of my repositories even if they don't know the proper method.</li>
</ul>
</li>
<li>I am not enabling Smart HTTPS (Hypertext Transfer Protocol Secure) for any repositories. Updates to repositories must be pushed via SSH (Secure Shell Protocol).</li>
<li>Beyond the actual repository management, I am using <code class="verbatim">cgit</code> for the front-end web interface.<ul>
<li>If you use the <code class="verbatim">scan-path=&lt;path&gt;</code> configuration in the <code class="verbatim">cgitrc</code> configuration file to automatically find repositories, you can't exclude a repository from <code class="verbatim">cgit</code> if it's stored within the path that <code class="verbatim">cgit</code> reads. To host private repositories, you'd need to set up another directory that <code class="verbatim">cgit</code> can't read.</li>
</ul>
</li>
</ul>
<h2 id="assumptions"><span class="section-number-2">2.</span> Assumptions</h2>
<p>For the purposes of this walkthrough, I am assuming you have a URL (<code class="verbatim">git.example.com</code>) or internet protocol (IP) address (<code class="verbatim">207.84.26.991</code>) addressed to the server that you will be using to host your git repositories.</p>
<h2 id="adding-a-git-user"><span class="section-number-2">3.</span> Adding a Git User</h2>
<p>In order to use the SSH method associated with Git, we will need to add a user named <code class="verbatim">git</code>. If you have used the SSH method for other git hosting sites, you are probably used to the following syntax:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">git</span></span><span class="meta function-call arguments shell"> clone <span class="keyword control regexp set begin shell">[</span>user@<span class="keyword control regexp set end shell">]</span>server:project.git</span></span></code></pre>
<p>The syntax above is an <code class="verbatim">scp</code>-like syntax for using SSH on the <code class="verbatim">git</code> user on the server to access your repository.</p>
<p>Let's delete any remnants of an old <code class="verbatim">git</code> user, if any, and create the new user account:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> deluser<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> --</span>remove-home</span> git</span>
<span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> adduser git</span></span></code></pre>
<h3 id="import-your-ssh-keys-to-the-git-user"><span class="section-number-3">3.1.</span> Import Your SSH Keys to the Git User</h3>
<p>Once the <code class="verbatim">git</code> user is created, you will need to copy your public SSH key on your local development machine to the <code class="verbatim">git</code> user on the server.</p>
<p>If you don't have an SSH key yet, create one with this command:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">ssh-keygen</span></span></span></code></pre>
<p>Once you create the key pair, the public should be saved to <code class="verbatim">~/.ssh/id_rsa.pub</code>.</p>
<p>If your server still has password-based authentication available, you can copy it over to your user's home directory like this:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">ssh-copy-id</span></span><span class="meta function-call arguments shell"> git@server</span></span></code></pre>
<p>Otherwise, copy it over to any user that you can access.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">scp</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/.ssh/id_rsa.pub your_user@your_server:</span></span></code></pre>
<p>Once on the server, you will need to copy the contents into the <code class="verbatim">git</code> user's <code class="verbatim">authorized_keys</code> file:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">cat</span></span><span class="meta function-call arguments shell"> id_rsa.pub <span class="keyword operator assignment redirection shell">&gt;</span> /home/git/.ssh/authorized_keys</span></span></code></pre>
<h3 id="optional-disable-password-based-ssh"><span class="section-number-3">3.2.</span> (Optional) Disable Password-Based SSH</h3>
<p>If you want to lock down your server and ensure that no one can authenticate in via SSH with a password, you will need to edit your SSH configuration.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> nano /etc/ssh/sshd_config</span></span></code></pre>
<p>Within this file, find the following settings and set them to the values I am showing below:</p>
<pre><code class="language-conf">PermitRootLogin no
PasswordAuthentication no
AuthenticationMethods publickey</code></pre>
<p>You may have other Authentication Methods required in your personal set-up, so the key here is just to ensure that <code class="verbatim">AuthenticationMethods</code> does not allow passwords.</p>
<h4 id="setting-up-the-base-directory"><span class="section-number-4">3.2.1.</span> Setting up the Base Directory</h4>
<p>Now that we have set up a <code class="verbatim">git</code> user to handle all transport methods, we need to set up the directory that we will be using as our base of all repositories.</p>
<p>In my case, I am using <code class="verbatim">/git</code> as my source folder. To create this folder and assign it to the user we created, execute the following commands:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> mkdir /git</span>
<span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> chown<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>R</span> git:git /git</span></span></code></pre>
<h4 id="creating-a-test-repository"><span class="section-number-4">3.2.2.</span> Creating a Test Repository</h4>
<p>On your server, switch over to the <code class="verbatim">git</code> user in order to start managing git files.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">su</span></span><span class="meta function-call arguments shell"> git</span></span></code></pre>
<p>Once logged-in as the <code class="verbatim">git</code> user, go to your base directory and create a test repository.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="support function cd shell">cd</span></span><span class="meta function-call arguments shell"> /git</span>
<span class="meta function-call shell"><span class="variable function shell">mkdir</span></span><span class="meta function-call arguments shell"> test.git</span> <span class="keyword operator logical and shell">&amp;&amp;</span> <span class="meta function-call shell"><span class="support function cd shell">cd</span></span><span class="meta function-call arguments shell"> test.git</span>
<span class="meta function-call shell"><span class="variable function shell">git</span></span><span class="meta function-call arguments shell"> init<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> --</span>bare</span></span></span></code></pre>
<p>If you want to make this repo viewable/cloneable to the public via the <code class="verbatim">git://</code> protocol, you need to create a <code class="verbatim">git-daemon-export-ok</code> file inside the repository.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">touch</span></span><span class="meta function-call arguments shell"> git-daemon-export-ok</span></span></code></pre>
<h2 id="change-the-login-shell-for-git"><span class="section-number-2">4.</span> Change the Login Shell for <code class="verbatim">git</code></h2>
<p>To make sure that the <code class="verbatim">git</code> user is only used for git operations and nothing else, you need to change the user's login shell. To do this, simply use the <code class="verbatim">chsh</code> command:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> chsh git</span></span></code></pre>
<p>The interactive prompt will ask which shell you want the <code class="verbatim">git</code> user to use. You must use the following value:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">/usr/bin/git-shell</span></span></span></code></pre>
<p>Once done, no one will be able to SSH to the <code class="verbatim">git</code> user or execute commands other than the standard git commands.</p>
<h2 id="opening-the-firewall"><span class="section-number-2">5.</span> Opening the Firewall</h2>
<p>Don't forget to open up ports on the device firewall and network firewall if you want to access these repositories publicly. If you're using default ports, forward ports <code class="verbatim">22</code> (ssh) and <code class="verbatim">9418</code> (git) from your router to your server's IP address.</p>
<p>If your server also has a firewall, ensure that the firewall allows the same ports that are forwarded from the router. For example, if you use <code class="verbatim">ufw</code>:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> ufw allow 22</span>
<span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> ufw allow 9418</span></span></code></pre>
<h3 id="non-standard-ssh-ports"><span class="section-number-3">5.1.</span> Non-Standard SSH Ports</h3>
<p>If you use a non-standard port for SSH, such as <code class="verbatim">9876</code>, you will need to create an SSH configuration file on your local development machine in order to connect to your server's git repositories.</p>
<p>To do this, you'll need to define your custom port on your client machine in your <code class="verbatim">~/.ssh/config</code> file:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">nano</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/.ssh/config</span></span></code></pre>
<pre><code class="language-conf">Host git.example.com
  # HostName can be a URL or an IP address
  HostName git.example.com
  Port 9876
  User git</code></pre>
<h3 id="testing-ssh"><span class="section-number-3">5.2.</span> Testing SSH</h3>
<p>There are two main syntaxes you can use to manage git over SSH:</p>
<ul>
<li><code class="verbatim">git clone [user@]server:project.git</code></li>
<li><code class="verbatim">git clone ssh://[user@]server/project.git</code></li>
</ul>
<p>I prefer the first, which is an <code class="verbatim">scp</code>-like syntax. To test it, try to clone the test repository you set up on the server:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">git</span></span><span class="meta function-call arguments shell"> clone git@git.example.com:/git/test.git</span></span></code></pre>
<h2 id="enabling-read-only-access"><span class="section-number-2">6.</span> Enabling Read-Only Access</h2>
<p>If you want people to be able to clone any repository where you've placed a <code class="verbatim">git-daemon-export-ok</code> file, you will need to start the git daemon.</p>
<p>To do this on a system with <code class="verbatim">systemd</code>, create a service file:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> nano /etc/systemd/system/git-daemon.service</span></span></code></pre>
<p>Inside the <code class="verbatim">git-daemon.service</code> file, paste the following:</p>
<pre><code class="language-conf">[Unit]
Description=Start Git Daemon

[Service]
ExecStart=/usr/bin/git daemon --reuseaddr --base-path=/git/ /git/

Restart=always
RestartSec=500ms

StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=git-daemon

User=git
Group=git

[Install]
WantedBy=multi-user.target</code></pre>
<p>Once created, enable and start the service:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> systemctl enable git-daemon.service</span>
<span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> systemctl start git-daemon.service</span></span></code></pre>
<p>To clone read-only via the <code class="verbatim">git://</code> protocol, you can use the following syntax:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">git</span></span><span class="meta function-call arguments shell"> clone git://git.example.com/test.git</span></span></code></pre>
<h2 id="migrating-repositories"><span class="section-number-2">7.</span> Migrating Repositories</h2>
<p>At this point, we have a working git server that works with both SSH and read-only access.</p>
<p>For each of the repositories I had hosted a different provider, I executed the following commands in order to place a copy on my server as my new source of truth:</p>
<p>Server:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">su</span></span><span class="meta function-call arguments shell"> git</span>
<span class="meta function-call shell"><span class="variable function shell">mkdir</span></span><span class="meta function-call arguments shell"> /git/<span class="keyword operator assignment redirection shell">&lt;</span>REPOSITORY_NAME<span class="keyword operator assignment redirection shell">&gt;</span>.git</span> <span class="keyword operator logical and shell">&amp;&amp;</span> <span class="meta function-call shell"><span class="support function cd shell">cd</span></span><span class="meta function-call arguments shell"> /git/<span class="keyword operator assignment redirection shell">&lt;</span>REPOSITORY_NAME<span class="keyword operator assignment redirection shell">&gt;</span>.git</span>
<span class="meta function-call shell"><span class="variable function shell">git</span></span><span class="meta function-call arguments shell"> init<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> --</span>bare</span></span>

<span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> If you want to make this repo viewable/cloneable to the public</span><span class="comment line number-sign shell">
</span><span class="meta function-call shell"><span class="variable function shell">touch</span></span><span class="meta function-call arguments shell"> git-daemon-export-ok</span></span></code></pre>
<p>Client:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">git</span></span><span class="meta function-call arguments shell"> clone git@<span class="keyword operator assignment redirection shell">&lt;</span>PREVIOUS_HOST<span class="keyword operator assignment redirection shell">&gt;</span>:<span class="keyword operator assignment redirection shell">&lt;</span>REPOSITORY_NAME<span class="keyword operator assignment redirection shell">&gt;</span>
</span><span class="meta function-call shell"><span class="variable function shell">git</span></span><span class="meta function-call arguments shell"> remote set-url origin git@git.EXAMPLE.COM:/git/<span class="keyword operator assignment redirection shell">&lt;</span>REPOSITORY_NAME<span class="keyword operator assignment redirection shell">&gt;</span>.git</span>
<span class="meta function-call shell"><span class="variable function shell">git</span></span><span class="meta function-call arguments shell"> push</span></span></code></pre>
<h2 id="optional-web-view-cgit"><span class="section-number-2">8.</span> Optional Web View: <code class="verbatim">cgit</code></h2>
<p>If you want a web viewer for your repositories, you can use various tools, such as <code class="verbatim">gitweb</code>, <code class="verbatim">cgit</code>, or <code class="verbatim">klaus</code>. I chose <code class="verbatim">cgit</code> due to its simple interface and fairly easy set-up (compared to others). Not to mention that the <a href="https://git.kernel.org/">Linux kernel uses <code class="verbatim">cgit</code></a>.</p>
<h3 id="docker-compose"><span class="section-number-3">8.1.</span> Docker Compose</h3>
<p>Instead of using my previous method of using a <code class="verbatim">docker run</code> command, I've updated this section to use <code class="verbatim">docker-compose</code> instead for an easier installation and simpler management and configuration.</p>
<p>In order to use Docker Compose, you will set up a <code class="verbatim">docker-compose.yml</code> file to automatically connect resources like the repositories, <code class="verbatim">cgitrc</code>, and various files or folders to the <code class="verbatim">cgit</code> container you're creating:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">mkdir</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/cgit</span> <span class="keyword operator logical and shell">&amp;&amp;</span> <span class="meta function-call shell"><span class="support function cd shell">cd</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/cgit</span>
<span class="meta function-call shell"><span class="variable function shell">nano</span></span><span class="meta function-call arguments shell"> docker-compose.yml</span></span></code></pre>
<pre><code class="language-conf"># docker-compose.yml
version: '3'

services:
  cgit:
    image: invokr/cgit
    volumes:
      - /git:/git
      - ./cgitrc:/etc/cgitrc
      - ./logo.png:/var/www/htdocs/cgit/logo.png
      - ./favicon.png:/var/www/htdocs/cgit/favicon.png
      - ./filters:/var/www/htdocs/cgit/filters
    ports:
      - "8763:80"
    restart: always</code></pre>
<p>Then, just start the container:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> docker-compose up<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>d</span></span></span></code></pre>
<p>Once it's finished installing, you can access the site at <code class="verbatim">&lt;SERVER_IP&gt;:8763</code> or use a reverse-proxy service to forward <code class="verbatim">cgit</code> to a URL, such as <code class="verbatim">git.example.com</code>. See the next section for more details on reverse proxying a URL to a local port.</p>
<h3 id="nginx-reverse-proxy"><span class="section-number-3">8.2.</span> Nginx Reverse Proxy</h3>
<p>I am using Nginx as my reverse proxy so that the <code class="verbatim">cgit</code> Docker container can use <code class="verbatim">git.example.com</code> as its uniform resource locator (URL). To do so, I simply created the following configuration file:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> nano /etc/nginx/sites-available/git.example.com</span></span></code></pre>
<pre><code class="language-conf">server {
        listen 80;
          server_name git.example.com;

        if ($host = git.example.com) {
                return 301 https://$host$request_uri;
          }

          return 404;
}

server {
        server_name git.example.com;
        listen 443 ssl http2;

        location / {
                # The final `/` is important.
                    proxy_pass http://localhost:8763/;
                add_header X-Frame-Options SAMEORIGIN;
                add_header X-XSS-Protection "1; mode=block";
                proxy_redirect off;
                proxy_buffering off;
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header X-Forwarded-Proto $scheme;
                proxy_set_header X-Forwarded-Port $server_port;
        }

        # INCLUDE ANY SSL CERTS HERE
        include /etc/letsencrypt/options-ssl-nginx.conf;
        ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
}</code></pre>
<p>Once created, symlink it and restart the web server.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> ln<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>s</span> /etc/nginx/sites-available/git.example.com /etc/nginx/sites-enabled/</span>
<span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> systemctl restart nginx.service</span></span></code></pre>
<p>As we can see below, my site at <code class="verbatim">git.example.com</code> is available and running:</p>
<h3 id="settings-up-git-details"><span class="section-number-3">8.3.</span> Settings Up Git Details</h3>
<p>Once you have <code class="verbatim">cgit</code> running, you can add some small details, such as repository owners and descriptions by editing the following files within each repository.</p>
<p>Alternatively, you can use the <code class="verbatim">cgitrc</code> file to edit these details if you only care to edit them for the purpose of seeing them on your website.</p>
<p>The <code class="verbatim">description</code> file within the repository on your server will display the description online.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="support function cd shell">cd</span></span><span class="meta function-call arguments shell"> /git/example.git</span>
<span class="meta function-call shell"><span class="variable function shell">nano</span></span><span class="meta function-call arguments shell"> description</span></span></code></pre>
<p>You can add a <code class="verbatim">[gitweb]</code> block to the <code class="verbatim">config</code> file in order to display the owner of the repository.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="support function cd shell">cd</span></span><span class="meta function-call arguments shell"> /git/example.git</span>
<span class="meta function-call shell"><span class="variable function shell">nano</span></span><span class="meta function-call arguments shell"> config</span></span></code></pre>
<pre><code class="language-conf">[gitweb]
    owner = "YourName"</code></pre>
<p>Note that you can ignore the configuration within each repository and simply set up this information in the <code class="verbatim">cgitrc</code> file, if you want to do it that way.</p>
<h3 id="editing-cgit"><span class="section-number-3">8.4.</span> Editing <code class="verbatim">cgit</code></h3>
<p>In order to edit certain items within <code class="verbatim">cgit</code>, you need to edit the <code class="verbatim">cgitrc</code> file.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">nano</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/cgit/cgitrc</span></span></code></pre>
<p>Below is an example configuration for <code class="verbatim">cgitrc</code>. You can find all the configuration options within the <a href="https://git.zx2c4.com/cgit/plain/cgitrc.5.txt">configuration manual</a>.</p>
<pre><code class="language-conf">css=/cgit.css
logo=/logo.png
favicon=/favicon.png
robots=noindex, nofollow

enable-index-links=1
enable-commit-graph=1
enable-blame=1
enable-log-filecount=1
enable-log-linecount=1
enable-git-config=1

clone-url=git://git.example.com/$CGIT_REPO_URL ssh://git@git.example.com:/git/$CGIT_REPO_URL

root-title=My Git Website
root-desc=My personal git repositories.

# Allow download of tar.gz, tar.bz2 and zip-files
snapshots=tar.gz tar.bz2 zip

##
## List of common mimetypes
##
mimetype.gif=image/gif
mimetype.html=text/html
mimetype.jpg=image/jpeg
mimetype.jpeg=image/jpeg
mimetype.pdf=application/pdf
mimetype.png=image/png
mimetype.svg=image/svg+xml

# Highlight source code
# source-filter=/var/www/htdocs/cgit/filters/syntax-highlighting.sh
source-filter=/var/www/htdocs/cgit/filters/syntax-highlighting.py

# Format markdown, restructuredtext, manpages, text files, and html files
# through the right converters
about-filter=/var/www/htdocs/cgit/filters/about-formatting.sh

##
## Search for these files in the root of the default branch of repositories
## for coming up with the about page:
##
readme=:README.md
readme=:readme.md
readme=:README.mkd
readme=:readme.mkd
readme=:README.rst
readme=:readme.rst
readme=:README.html
readme=:readme.html
readme=:README.htm
readme=:readme.htm
readme=:README.txt
readme=:readme.txt
readme=:README
readme=:readme

# Repositories

# Uncomment the following line to scan a path instead of adding repositories manually
# scan-path=/git

## Test Section
section=git/test-section

repo.url=test.git
repo.path=/git/test.git
repo.readme=:README.md
repo.owner=John Doe
repo.desc=An example repository!</code></pre>
<h3 id="final-fixes-syntax-highlighting-readme-rendering"><span class="section-number-3">8.5.</span> Final Fixes: Syntax Highlighting &amp; README Rendering</h3>
<p>After completing my initial install and playing around with it for a few days, I noticed two issues:</p>
<ol>
<li>Syntax highlighting did not work when viewing the source code within a file.</li>
<li>The <code class="verbatim">about</code> tab within a repository was not rendered to HTML.</li>
</ol>
<p>The following process fixes these issues. To start, let's go to the <code class="verbatim">cgit</code> directory where we were editing our configuration file earlier.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="support function cd shell">cd</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/cgit</span></span></code></pre>
<p>In here, create two folders that will hold our syntax files:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">mkdir</span></span><span class="meta function-call arguments shell"> filters</span> <span class="keyword operator logical and shell">&amp;&amp;</span> <span class="meta function-call shell"><span class="variable function shell">mkdir</span></span><span class="meta function-call arguments shell"> filters/html-converters</span> <span class="keyword operator logical and shell">&amp;&amp;</span> <span class="meta function-call shell"><span class="support function cd shell">cd</span></span><span class="meta function-call arguments shell"> filters</span></span></code></pre>
<p>Next, download the default filters:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">curl</span></span><span class="meta function-call arguments shell"> https://git.zx2c4.com/cgit/plain/filters/about-formatting.sh <span class="keyword operator assignment redirection shell">&gt;</span> about-formatting.sh</span>
<span class="meta function-call shell"><span class="variable function shell">chmod</span></span><span class="meta function-call arguments shell"> 755 about-formatting.sh</span>
<span class="meta function-call shell"><span class="variable function shell">curl</span></span><span class="meta function-call arguments shell"> https://git.zx2c4.com/cgit/plain/filters/syntax-highlighting.py <span class="keyword operator assignment redirection shell">&gt;</span> syntax-highlighting.py</span>
<span class="meta function-call shell"><span class="variable function shell">chmod</span></span><span class="meta function-call arguments shell"> 755 syntax-highlighting.py</span></span></code></pre>
<p>Finally, download the HTML conversion files you need. The example below downloads the Markdown converter:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="support function cd shell">cd</span></span><span class="meta function-call arguments shell"> html-converters</span>
<span class="meta function-call shell"><span class="variable function shell">curl</span></span><span class="meta function-call arguments shell"> https://git.zx2c4.com/cgit/plain/filters/html-converters/md2html <span class="keyword operator assignment redirection shell">&gt;</span> md2html</span>
<span class="meta function-call shell"><span class="variable function shell">chmod</span></span><span class="meta function-call arguments shell"> 755 md2html</span></span></code></pre>
<p>If you need other filters or html-converters found within <a href="https://git.zx2c4.com/cgit/tree/filters">the cgit project files</a>, repeat the <code class="verbatim">curl</code> and <code class="verbatim">chmod</code> process above for whichever files you need.</p>
<p>However, formatting will not work quite yet since the Docker cgit container we're using doesn't have the formatting package installed. You can install this easily by install Python 3+ and the <code class="verbatim">pygments</code> package:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> Enter the container&#39;s command line</span><span class="comment line number-sign shell">
</span><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> docker exec<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>it</span> cgit bash</span></span></code></pre>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> Install the necessary packages and then exit</span><span class="comment line number-sign shell">
</span><span class="meta function-call shell"><span class="variable function shell">yum</span></span><span class="meta function-call arguments shell"> update<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>y</span></span> <span class="keyword operator logical and shell">&amp;&amp;</span>                      <span class="punctuation separator continuation line shell">\
</span><span class="meta function-call shell"><span class="variable function shell">yum</span></span><span class="meta function-call arguments shell"> upgrade<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>y</span></span> <span class="keyword operator logical and shell">&amp;&amp;</span>                     <span class="punctuation separator continuation line shell">\
</span><span class="meta function-call shell"><span class="variable function shell">yum</span></span><span class="meta function-call arguments shell"> install python3 python3-pip<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>y</span></span> <span class="keyword operator logical and shell">&amp;&amp;</span> <span class="punctuation separator continuation line shell">\
</span><span class="meta function-call shell"><span class="variable function shell">pip3</span></span><span class="meta function-call arguments shell"> install markdown pygments</span> <span class="keyword operator logical and shell">&amp;&amp;</span>     <span class="punctuation separator continuation line shell">\
</span><span class="meta function-call shell"><span class="support function exit shell">exit</span></span></span></code></pre>
<p><strong>You will need to enter the cgit docker container and re-run these <code class="verbatim">yum</code> commands every time you kill and restart the container!</strong></p>
<p>If not done already, we need to add the following variables to our <code class="verbatim">cgitrc</code> file in order for <code class="verbatim">cgit</code> to know where our filtering files are:</p>
<pre><code class="language-conf"># Highlight source code with python pygments-based highlighter
source-filter=/var/www/htdocs/cgit/filters/syntax-highlighting.py

# Format markdown, restructuredtext, manpages, text files, and html files
# through the right converters
about-filter=/var/www/htdocs/cgit/filters/about-formatting.sh</code></pre>
<p>Now you should see that syntax highlighting and README rendering to the <code class="verbatim">about</code> tab is fixed.</p>
<h3 id="theming"><span class="section-number-3">8.6.</span> Theming</h3>
<p>I won't go into much detail in this section, but you can fully theme your installation of <code class="verbatim">cgit</code> since you have access to the <code class="verbatim">cgit.css</code> file in your web root. This is another file you can add as a volume to the <code class="verbatim">docker-compose.yml</code> file if you want to edit this without entering the container's command line.</p>
<h4 id="remember-to-back-up-your-data"><span class="section-number-4">8.6.1.</span> Remember to Back Up Your Data!</h4>
<p>The last thing to note is that running services on your own equipment means that you're assuming a level of risk that exists regarding data loss, catastrophes, etc. In order to reduce the impact of any such occurrence, I suggest backing up your data regularly.</p>
<p>Backups can be automated via <code class="verbatim">cron</code>, by hooking your base directory up to a cloud provider, or even setting up hooks to push all repository info to git mirrors on other git hosts. Whatever the method, make sure that your data doesn't vanish in the event that your drives or servers fail.</p>
]]></description>
    </item>
    <item>
      <title>Fedora and i3: Back on Linux</title>
      <link>https://cleberg.net/blog/fedora-i3.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/fedora-i3.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Fri, 24 Jun 2022 00:00:00 +0000</pubDate>
      <category>linux</category>
      <description><![CDATA[<h2 id="leaving-macos"><span class="section-number-2">1.</span> Leaving macOS</h2>
<p>As I noted in a recent post, I have been planning on migrating from macOS back to a Linux-based operating system (OS). I am happy to say that I have finally completed my migration and am now stuck in the wonderful world of Linux again.</p>
<p>My decision to leave macOS really came down to just a few important things:</p>
<ul>
<li>Apple Security (Gatekeeper) restricting me from running any software I want. Even if you disable Gatekeeper and allow software to bypass the rest of the device installation security, you still have to repeat that process every time the allowed software is updated.</li>
<li>macOS sends out nearly constant connections, pings, telemetry, etc. to a myriad of mysterious Apple services. I'm not even going to dive into how many macOS apps have constant telemetry on, as well.</li>
<li>Lastly, I just <em>really</em> missed the customization and freedom that comes with Linux. Being able to switch to entirely new kernel, OS, or desktop within minutes is a freedom I took for granted when I switched to macOS.</li>
</ul>
<p>Now that I've covered macOS, I'm going to move on to more exciting topics: my personal choice of OS, desktop environment (DE), and various customizations I'm using.</p>
<h2 id="fedora"><span class="section-number-2">2.</span> Fedora</h2>
<p>After trying a ton of distributions (I think I booted and tested around 20-25 distributions), I finally landed on <a href="https://getfedora.org/">Fedora Linux</a>. I have quite a bit of experience with Fedora and enjoy the <code class="verbatim">dnf</code> package manager. Fedora allows me to keep up-to-date with recent software (I'm looking at you, Debian), but still provides a level of stability you don't find in every distribution.</p>
<p>In a very close second place was Arch Linux, as well as its spin-off: Garuda Linux (Garuda w/ sway is <em>beautiful</em>). Arch is great for compatibility and the massive community it has, but I have just never had the time to properly sit down and learn the methodology behind their packaging systems.</p>
<p>Basically, everything else I tested was unacceptable in at least one way or another. Void (<code class="verbatim">glibc</code>) was great, but doesn't support all the software I need. Slackware worked well as a text-based user interface (TUI), but I wasn't skilled enough to get a tiling window manager (WM) working on it.</p>
<h3 id="i3"><span class="section-number-3">2.1.</span> i3</h3>
<p>One of the reasons I settled on Fedora is that it comes with an official i3 spin. Being able to use a tiling WM, such as i3 or sway, is one of the biggest things I wanted to do as soon as I adopted Linux again.</p>
<p>I will probably set up a dotfile repository soon, so that I don't lose any of my configurations, but nothing big has been configured thus far.</p>
<p>The two main things I have updated in i3wm are natural scrolling and binding my brightness keys to the <code class="verbatim">brightnessctl</code> program.</p>
<ol>
<li><p>Natural Scrolling</p>
<p>You can enable natural scrolling by opening the following file:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> nano /usr/share/X11/xorg.conf.d/40-libinput.conf</span></span></code></pre>
<p>Within the <code class="verbatim">40-libinput.conf</code> file, find the following input sections and enable the natural scrolling option.</p>
<p>This is the <code class="verbatim">pointer</code> section:</p>
<pre><code class="language-conf">Section "InputClass"
        Identifier "libinput pointer catchall"
        MatchIsPointer "on"
        MatchDevicePath "/dev/input/event*"
        Driver "libinput"
        Option "NaturalScrolling" "True"
EndSection</code></pre>
<p>This is the <code class="verbatim">touchpad</code> section:</p>
<pre><code class="language-conf">Section "InputClass"
        Identifier "libinput touchpad catchall"
        MatchIsTouchpad "on"
        MatchDevicePath "/dev/input/event*"
        Driver "libinput"
        Option "NaturalScrolling" "True"
EndSection</code></pre>
</li>
<li><p>Enabling Brightness Keys</p>
<p>Likewise, enabling brightness key functionality is as simple as binding the keys to the <code class="verbatim">brightnessctl</code> program.</p>
<p>To do this, open up your i3 configuration file. Mine is located here:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">nano</span></span><span class="meta function-call arguments shell"> /home/<span class="keyword operator assignment redirection shell">&lt;</span>my-user<span class="keyword operator assignment redirection shell">&gt;</span>/.config/i3/config</span></span></code></pre>
<pre><code class="language-conf"># Use brightnessctl to adjust brightness.
bindsym XF86MonBrightnessDown exec --no-startup-id brightnessctl --min-val=2 -q set 3%-
bindsym XF86MonBrightnessUp exec --no-startup-id brightnessctl -q set 3%+</code></pre>
</li>
<li><p><code class="verbatim">polybar</code></p>
<p>Instead of using the default <code class="verbatim">i3status</code> bar, I have opted to use <code class="verbatim">polybar</code> instead (as you can also see in the screenshot above).</p>
<p>My configuration for this menu bar is basically just the default settings with modified colors and an added battery block to quickly show me the machine's battery info.</p>
</li>
<li><p><code class="verbatim">alacritty</code></p>
<p>Not much to say on this part yet, as I haven't configured it much, but I installed <code class="verbatim">alacritty</code> as my default terminal, and I am using <code class="verbatim">zsh</code> and the shell.</p>
</li>
</ol>
<h2 id="software-choices"><span class="section-number-2">3.</span> Software Choices</h2>
<p>Again, I'm not going to say much that I haven't said yet in other blog posts, so I'll just do a quick rundown of the apps I installed immediately after I set up the environment.</p>
<p>Flatpak Apps:</p>
<ul>
<li>Cryptomator</li>
<li>pCloud</li>
<li>Signal</li>
</ul>
<p>Fedora Packages:</p>
<ul>
<li>gomuks</li>
<li>neomutt</li>
<li>neofetch</li>
<li>Firefox<ul>
<li>uBlock Origin</li>
<li>Bitwarden</li>
<li>Stylus</li>
<li>Privacy Redirect</li>
</ul>
</li>
</ul>
<p>Other:</p>
<ul>
<li>exiftool</li>
</ul>
]]></description>
    </item>
    <item>
      <title>Daily Poetry via Cron</title>
      <link>https://cleberg.net/blog/daily-poetry.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/daily-poetry.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Wed, 22 Jun 2022 00:00:00 +0000</pubDate>
      <category>personal</category>
      <description><![CDATA[<h2 id="source-code"><span class="section-number-2">1.</span> Source Code</h2>
<p>I don't want to bury the lede here, so if you'd like to see the full source code I use to email myself plaintext poems daily, visit the repository: <a href="https://gitbay.org/krz/daily-poem">daily-poem.git</a>.</p>
<h2 id="my-daily-dose-of-poetry"><span class="section-number-2">2.</span> My Daily Dose of Poetry</h2>
<p>Most of my programming projects are small, random projects that are made strictly to fix some small problem I have or enhance my quality of life.</p>
<p>In this case, I was looking for a simply and easy way to get a daily dose of literature or poetry to read in the mornings.</p>
<p>However, I don't want to sign up for a random mailing list on just any website. I also don't want to have to work to find the reading content each morning, as I know I would simply give up and stop reading daily.</p>
<p>Thus, I found a way to deliver poetry to myself in plain-text format, on a daily basis, and scheduled to deliver automatically.</p>
<h2 id="prerequisites"><span class="section-number-2">3.</span> Prerequisites</h2>
<p>This solution uses Python and email, so the following process requires the following to be installed:</p>
<ol>
<li>A Simple Mail Transfer Protocol (SMTP) server, which can be as easy as installing <code class="verbatim">mailutils</code> if you're on a Debian-based distribution.</li>
<li>Python (&amp; pip!)</li>
<li>The following Python packages: <code class="verbatim">email</code>, <code class="verbatim">smtplib</code>, <code class="verbatim">json</code>, and <code class="verbatim">requests</code></li>
</ol>
<h2 id="breaking-down-the-logic"><span class="section-number-2">4.</span> Breaking Down the Logic</h2>
<p>I want to break down the logic for this program, as it's quite simple and informational.</p>
<h3 id="required-packages"><span class="section-number-3">4.1.</span> Required Packages</h3>
<p>This program starts with a simple import of the required packages, so I wanted to explain why each package is used:</p>
<pre><code class="language-python highlight"><span class="source python"><span class="meta statement import python"><span class="keyword control import from python">from</span></span><span class="meta statement import python"><span class="meta import-source python"> <span class="meta import-path python"><span class="meta import-name python">email</span><span class="punctuation accessor dot python">.</span><span class="meta import-name python">mime</span><span class="punctuation accessor dot python">.</span><span class="meta import-name python">text</span></span> <span class="meta statement import python"><span class="keyword control import python">import</span></span></span></span><span class="meta statement import python"></span><span class="meta statement import python"> <span class="meta generic-name python">MIMEText</span></span> <span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Required for translating MIMEText
</span><span class="meta statement import python"><span class="keyword control import python">import</span> <span class="meta qualified-name python"><span class="meta generic-name python">smtplib</span></span></span> <span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Required to process the SMTP mail delivery
</span><span class="meta statement import python"><span class="keyword control import python">import</span> <span class="meta qualified-name python"><span class="meta generic-name python">json</span></span></span> <span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Required to parse the poetry API results
</span><span class="meta statement import python"><span class="keyword control import python">import</span> <span class="meta qualified-name python"><span class="meta generic-name python">requests</span></span></span> <span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Required to send out a request to the API</span></span></code></pre>
<h3 id="sending-the-api-request"><span class="section-number-3">4.2.</span> Sending the API Request</h3>
<p>Next, we need to actually send the application programming interface (API) request. In my case, I'm calling a random poem from the entire API. If you want, you can call specific poems or authors from this API.</p>
<pre><code class="language-python highlight"><span class="source python"><span class="meta qualified-name python"><span class="meta generic-name python">json_data</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">requests</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">get</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">https://poetrydb.org/random<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="punctuation section arguments end python">)</span></span><span class="meta function-call python"><span class="meta qualified-name python"><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">json</span></span><span class="punctuation section arguments begin python">(</span><span class="punctuation section arguments end python">)</span></span></span></code></pre>
<p>This gives us the following result in JSON (JavaScript Object Notation):</p>
<pre><code class="language-json highlight"><span class="source json"><span class="meta structure array json"><span class="punctuation section array begin json">[</span>
    <span class="meta structure dictionary json"><span class="punctuation section dictionary begin json">{</span>
        <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>title<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>Sonnet XXII: With Fools and Children<span class="punctuation definition string end json">&quot;</span></span><span class="punctuation separator dictionary pair json">,</span></span>
        <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>author<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>Michael Drayton<span class="punctuation definition string end json">&quot;</span></span><span class="punctuation separator dictionary pair json">,</span></span>
        <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>lines<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="meta structure array json"><span class="punctuation section array begin json">[</span>
            <span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>To Folly<span class="punctuation definition string end json">&quot;</span></span><span class="punctuation separator array json">,</span>
            <span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span><span class="punctuation definition string end json">&quot;</span></span><span class="punctuation separator array json">,</span>
            <span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>With fools and children, good discretion bears;<span class="punctuation definition string end json">&quot;</span></span><span class="punctuation separator array json">,</span>
            <span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>Then, honest people, bear with Love and me,<span class="punctuation definition string end json">&quot;</span></span><span class="punctuation separator array json">,</span>
            <span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>Nor older yet, nor wiser made by years,<span class="punctuation definition string end json">&quot;</span></span><span class="punctuation separator array json">,</span>
            <span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>Amongst the rest of fools and children be;<span class="punctuation definition string end json">&quot;</span></span><span class="punctuation separator array json">,</span>
            <span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>Love, still a baby, plays with gauds and toys,<span class="punctuation definition string end json">&quot;</span></span><span class="punctuation separator array json">,</span>
            <span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>And, like a wanton, sports with every feather,<span class="punctuation definition string end json">&quot;</span></span><span class="punctuation separator array json">,</span>
            <span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>And idiots still are running after boys,<span class="punctuation definition string end json">&quot;</span></span><span class="punctuation separator array json">,</span>
            <span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>Then fools and children fitt&#39;st to go together.<span class="punctuation definition string end json">&quot;</span></span><span class="punctuation separator array json">,</span>
            <span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>He still as young as when he first was born,<span class="punctuation definition string end json">&quot;</span></span><span class="punctuation separator array json">,</span>
            <span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>No wiser I than when as young as he;<span class="punctuation definition string end json">&quot;</span></span><span class="punctuation separator array json">,</span>
            <span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>You that behold us, laugh us not to scorn;<span class="punctuation definition string end json">&quot;</span></span><span class="punctuation separator array json">,</span>
            <span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>Give Nature thanks you are not such as we.<span class="punctuation definition string end json">&quot;</span></span><span class="punctuation separator array json">,</span>
            <span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>Yet fools and children sometimes tell in play<span class="punctuation definition string end json">&quot;</span></span><span class="punctuation separator array json">,</span>
            <span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>Some, wise in show, more fools indeed than they.<span class="punctuation definition string end json">&quot;</span></span>
        <span class="punctuation section array end json">]</span></span><span class="punctuation separator dictionary pair json">,</span></span>
        <span class="meta structure dictionary key json"><span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>linecount<span class="punctuation definition string end json">&quot;</span></span></span><span class="meta structure dictionary value json"><span class="punctuation separator dictionary key-value json">:</span> <span class="string quoted double json"><span class="punctuation definition string begin json">&quot;</span>15<span class="punctuation definition string end json">&quot;</span></span>
    </span><span class="punctuation section dictionary end json">}</span></span>
<span class="punctuation section array end json">]</span></span></span></code></pre>
<h3 id="parsing-the-api-results"><span class="section-number-3">4.3.</span> Parsing the API Results</h3>
<p>In order to parse this into a readable format, we need to use the <code class="verbatim">json</code> package and extract the fields we want. In the example below, I am grabbing every field presented by the API.</p>
<p>For the actual poem content, we need to loop over each line in the <code class="verbatim">lines</code> variable since each line is a separate string by default.</p>
<blockquote>
<p>You <em>could</em> also extract the title or author and make another call out to the API to avoid having to build the plaintext poem with a loop, but it just doesn't make sense to me to send multiple requests when we can create a simple loop on our local machine to work with the data we already have.</p>
<p>For <a href="https://poetrydb.org/title/Sonnet%20XXII:%20With%20Fools%20and%20Children/lines.text">example</a>, look at the raw data response of this link to see the poem's lines returned in plaintext.</p>
</blockquote>
<pre><code class="language-python highlight"><span class="source python"><span class="meta qualified-name python"><span class="meta generic-name python">title</span></span> <span class="keyword operator assignment python">=</span> <span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">json_data</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="constant numeric integer decimal python">0</span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">title<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span>
<span class="meta qualified-name python"><span class="meta generic-name python">author</span></span> <span class="keyword operator assignment python">=</span> <span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">json_data</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="constant numeric integer decimal python">0</span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">author<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span>
<span class="meta qualified-name python"><span class="meta generic-name python">line_count</span></span> <span class="keyword operator assignment python">=</span> <span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">json_data</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="constant numeric integer decimal python">0</span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">linecount<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span>
<span class="meta qualified-name python"><span class="meta generic-name python">lines</span></span> <span class="keyword operator assignment python">=</span> <span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string end python">&#39;</span></span></span>
<span class="meta statement for python"><span class="keyword control flow for python">for</span> <span class="meta generic-name python">line</span> <span class="meta statement for python"><span class="keyword control flow for in python">in</span></span></span><span class="meta statement for python"> <span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">json_data</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="constant numeric integer decimal python">0</span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">lines<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span><span class="punctuation section block for python">:</span></span>
  <span class="meta qualified-name python"><span class="meta generic-name python">lines</span></span> <span class="keyword operator assignment python">=</span> <span class="meta qualified-name python"><span class="meta generic-name python">lines</span></span> <span class="keyword operator arithmetic python">+</span> <span class="meta qualified-name python"><span class="meta generic-name python">line</span></span> <span class="keyword operator arithmetic python">+</span> <span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python"><span class="constant character escape python">\n</span><span class="punctuation definition string end python">&quot;</span></span></span></span></code></pre>
<h3 id="composing-the-email"><span class="section-number-3">4.4.</span> Composing the Email</h3>
<p>Now that I have all the data I need, I just need to compose it into a message and prepare the message metadata.</p>
<p>For my daily email, I want to see the title of the poem first, followed by the author, then a blank line, and finally the full poem. This code snippet combines that data and packages it into a MIMEText container, ready to be emailed.</p>
<pre><code class="language-python highlight"><span class="source python"><span class="meta qualified-name python"><span class="meta generic-name python">msg_body</span></span> <span class="keyword operator assignment python">=</span> <span class="meta qualified-name python"><span class="meta generic-name python">title</span></span> <span class="keyword operator arithmetic python">+</span> <span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python"><span class="constant character escape python">\n</span><span class="punctuation definition string end python">&quot;</span></span></span> <span class="keyword operator arithmetic python">+</span> <span class="meta qualified-name python"><span class="meta generic-name python">author</span></span> <span class="keyword operator arithmetic python">+</span> <span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python"><span class="constant character escape python">\n</span><span class="constant character escape python">\n</span><span class="punctuation definition string end python">&quot;</span></span></span> <span class="keyword operator arithmetic python">+</span> <span class="meta qualified-name python"><span class="meta generic-name python">lines</span></span>
<span class="meta qualified-name python"><span class="meta generic-name python">msg</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="variable function python">MIMEText</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">msg_body</span></span></span><span class="punctuation section arguments end python">)</span></span></span></code></pre>
<p>Before we send the email, we need to prepare the metadata (subject, from, to, etc.):</p>
<pre><code class="language-python highlight"><span class="source python"><span class="meta qualified-name python"><span class="meta generic-name python">sender_email</span></span> <span class="keyword operator assignment python">=</span> <span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">example@server.local<span class="punctuation definition string end python">&#39;</span></span></span>
<span class="meta qualified-name python"><span class="meta generic-name python">recipient_emails</span></span> <span class="keyword operator assignment python">=</span> <span class="meta structure list python"><span class="punctuation section list begin python">[</span><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">user@example.com<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation section list end python">]</span></span>
<span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">msg</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">Subject<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span> <span class="keyword operator assignment python">=</span> <span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">Your Daily Poem (<span class="punctuation definition string end python">&#39;</span></span></span> <span class="keyword operator arithmetic python">+</span> <span class="meta qualified-name python"><span class="meta generic-name python">line_count</span></span> <span class="keyword operator arithmetic python">+</span> <span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python"> lines)<span class="punctuation definition string end python">&#39;</span></span></span>
<span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">msg</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">From<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span> <span class="keyword operator assignment python">=</span> <span class="meta qualified-name python"><span class="meta generic-name python">sender_email</span></span>
<span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">msg</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">To<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span> <span class="keyword operator assignment python">=</span> <span class="meta qualified-name python"><span class="meta generic-name python">recipient_email</span></span></span></code></pre>
<h3 id="sending-the-email"><span class="section-number-3">4.5.</span> Sending the Email</h3>
<p>Now that I have everything ready to be emailed, the last step is to simply connect to an SMTP server and send the email out to the recipients. In my case, I installed <code class="verbatim">mailutils</code> on Ubuntu and let my SMTP server be <code class="verbatim">localhost</code>.</p>
<pre><code class="language-python highlight"><span class="source python"><span class="meta qualified-name python"><span class="meta generic-name python">smtp_server</span></span> <span class="keyword operator assignment python">=</span> <span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">localhost<span class="punctuation definition string end python">&#39;</span></span></span>
<span class="meta qualified-name python"><span class="meta generic-name python">s</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">smtplib</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">SMTP</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">smtp_server</span></span></span><span class="punctuation section arguments end python">)</span></span>
<span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">s</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">sendmail</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">sender_email</span></span><span class="punctuation separator arguments python">,</span> <span class="meta qualified-name python"><span class="meta generic-name python">recipient_emails</span></span><span class="punctuation separator arguments python">,</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">msg</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">as_string</span></span><span class="punctuation section arguments begin python">(</span><span class="punctuation section arguments end python">)</span></span></span><span class="punctuation section arguments end python">)</span></span>
<span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">s</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">quit</span></span><span class="punctuation section arguments begin python">(</span><span class="punctuation section arguments end python">)</span></span></span></code></pre>
<h2 id="the-result"><span class="section-number-2">5.</span> The Result!</h2>
<p>Instead of including a screenshot, I've copied the contents of the email that was delivered to my inbox below since I set this process up in plaintext format.</p>
<pre><code class="language-txt highlight"><span class="text plain">Date: Wed, 22 Jun 2022 14:37:19 +0000 (UTC)
From: REDACTED
To: REDACTED
Subject: Your Daily Poem (36 lines)
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Content-Type: text/plain; charset=utf-8

Sonnet XXII: With Fools and Children
Michael Drayton

With fools and children, good discretion bears;
Then, honest people, bear with Love and me,
Nor older yet, nor wiser made by years,
Amongst the rest of fools and children be;
Love, still a baby, plays with gauds and toys,
And, like a wanton, sports with every feather,
And idiots still are running after boys,
Then fools and children fitt&#39;st to go together.
He still as young as when he first was born,
No wiser I than when as young as he;
You that behold us, laugh us not to scorn;
Give Nature thanks you are not such as we.
Yet fools and children sometimes tell in play
Some, wise in show, more fools indeed than they.</span></code></pre>
<h2 id="scheduling-the-daily-email"><span class="section-number-2">6.</span> Scheduling the Daily Email</h2>
<p>Last, but not least, is scheduling this Python script with <code class="verbatim">crontab</code>. To schedule a script to run daily, you can add it to the <code class="verbatim">crontab</code> file. To do this, open <code class="verbatim">crontab</code> in editing mode:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">crontab</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>e</span></span></span></code></pre>
<p>In the file, simply paste the following snippet at the bottom of the file and ensure that the file path is correctly pointing to wherever you saved your Python script:</p>
<pre><code class="language-config">0 8 ** ** ** python3 /home/&lt;your_user&gt;/dailypoem/main.py</code></pre>
<p>We have now set up the script and scheduled it to run daily at 08:00!</p>
]]></description>
    </item>
    <item>
      <title>Terminal First: Why the GUI Is Optional</title>
      <link>https://cleberg.net/blog/terminal-lifestyle.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/terminal-lifestyle.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Thu, 16 Jun 2022 00:00:00 +0000</pubDate>
      <category>linux</category>
      <description><![CDATA[<h2 id="text-based-simplicity"><span class="section-number-2">1.</span> Text-Based Simplicity</h2>
<p>I've detailed my views on web-based minimalism and related topics in other posts throughout the years; e.g., JavaScript/CSS (Cascading Style Sheets) bloat slowing down websites that are essentially a text document. However, I have never really expanded beyond talking about the web and describing how I focus on minimizing distractions in other digital environments.</p>
<p>This post is going to set the baseline for how I <em>try</em> to live my digital life. It does not necessarily get into my physical life, which is often harder to control and contain all the noise in our modern world.</p>
<p>While there are new things to do every day in our digital world, I find that keeping a core set of values and interests can ground you and keep you mindful of <em>why</em> you are participating in the digital world. For example, if - at your core - you have no interest in what strangers think about random topics, it would be unwise to start participating in social media. However, I am someone who has been dragged in by effective advertising to participate in communities that I realize I do not care for.</p>
<p>I won't dive much further into explaining the philosophy of all this, but I will link a few helpful articles that may pique your interest if you're in search of more meaningful experiences:</p>
<ul>
<li><a href="https://en.wikipedia.org/wiki/Mindfulness">Mindfulness</a></li>
<li><a href="https://en.wikipedia.org/wiki/Minimalism">Minimalism</a></li>
<li><a href="https://en.wikipedia.org/wiki/Stoicism">Stoicism</a></li>
</ul>
<h2 id="living-life-in-the-terminal"><span class="section-number-2">2.</span> Living Life in the Terminal</h2>
<p>My personal approach to reducing digital distractions and increasing my focus on the task at hand is to use a terminal for as much as I possibly can.</p>
<p>Most days, this means that I have a few tabs open constantly in my terminal:</p>
<ol>
<li>A web browser</li>
<li>A chat client</li>
<li>An email client</li>
<li>An RSS (Really Simple Syndication) feed reader</li>
<li>A local shell for navigating my computer's files</li>
<li>A remote shell for managing servers and other machines</li>
</ol>
<p>Beyond this, I rarely open other tabs or graphical applications, unless absolutely necessary. If you look, you may be surprised what can be accomplished in the terminal.</p>
<p>For example, I have moved my music and entertainment downloads to the terminal, along with my device virtual private network (VPN) connections. I am exploring options for moving my RSS subscriptions to something like <a href="https://newsboat.org/">Newsboat</a>, so that I can read my daily articles without all the fuss.</p>
<p>Now that we have some examples out of the way, let's dive into the specifics.</p>
<h3 id="browsing-the-web"><span class="section-number-3">2.1.</span> Browsing the Web</h3>
<p>I'm going to start off with a hard topic for those who prefer to live in the terminal: web browsing. This task is made hard mostly by websites and web apps that require JavaScript to run. The other difficult part is that if you're using a text-based browser, that means images won't load (hopefully that's obvious).</p>
<p>I am using <a href="https://lynx.invisible-island.net">Lynx</a>, a text-based browser that runs quickly and easily in the terminal. Lynx allows me to browser most websites by simply typing <code class="verbatim">g</code> and then typing in the URL I want.</p>
<p>If you need a search engine while in Lynx, I recommend <a href="https://lite.duckduckgo.com/lite/">DuckDuckGo (Lite)</a>, which allows you to search the web using their text-only interface.</p>
<p>Eventually, you will run into websites that don't work (or are just too ugly and messy) in a text-only mode, and you'll be forced to switch over to a GUI browser to look at that site. Personally, I don't mind this as it doesn't happen as often as I thought it would.</p>
<p>The only time I need to do this is when I want to browse an image/video-focused webpage or if I need to log in to a site, and it doesn't support a text-only login page. For example, I am able to easily log in to <a href="https://sr.ht">Sourcehut</a> in lynx.</p>
<h3 id="chatting-with-friends"><span class="section-number-3">2.2.</span> Chatting with Friends</h3>
<p>After web browsing activities, my main form of terminal communication is Matrix. I use the <a href="https://docs.mau.fi/gomuks/">gomuks</a> client currently.</p>
<p>This was incredibly easy to install on macOS (but I will need to see if it'll be just as easy on Linux when my new laptop arrives):</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">brew</span></span><span class="meta function-call arguments shell"> install gomuks</span></span></code></pre>
<p>Once you launch gomuks, it will sync and require your username and password to login. After doing so, the only problem I ran into was verifying my gomuks client so that I could participate in rooms with E2EE (end-to-end encryption).</p>
<p>Finally, I was able to verify the session by opening the Element desktop app (I assume you can do this in the browser and mobile app too, but I'm not sure) and manually verifying myself with this process:</p>
<ol>
<li>Open the Element desktop app</li>
<li>Open a room I was a member of</li>
<li>Open the <code class="verbatim">Room Info</code> pane</li>
<li>Open the <code class="verbatim">People</code> menu and search for myself</li>
<li>Click on my profile name</li>
<li>Click on the session link under the <code class="verbatim">Security</code> section and follow the prompts to manually verify the session</li>
</ol>
<p>Overall, I like gomuks and am able to enjoy all the features I was using in Element. The only hiccup I have occurred is manually downloading images to view them, which can be annoying.</p>
<h3 id="email"><span class="section-number-3">2.3.</span> Email</h3>
<p>Moving email to the terminal has been the hardest of the tasks for me. Unlike web browsing, where I can simply decide to not look at a website that does not work in the terminal, I cannot simply ignore emails sent to me.</p>
<p>Personally, I am experimenting with <a href="https://neomutt.org/">neomutt</a> as a potential email client.</p>
<p>However, this requires a <strong>TON</strong> of configuration and tweaking to get right. Even when I was able to set up neomutt, configure my email account, and customize a few personal preferences, a lot of emails still do not display correctly (mostly due to HTML (Hypertext Markup Language) and images).</p>
<p>I won't get into the details of configuring <code class="verbatim">neomutt</code>; I mostly followed this blog post: <a href="https://gideonwolfe.com/posts/workflow/neomutt/intro/">Email in the Terminal: Configuring Neomutt</a>.</p>
<p>Finally, I have yet to figure out how to connect my PGP (Pretty Good Privacy) keys to <code class="verbatim">neomutt</code>, but that's a problem for another day.</p>
<h3 id="rss-feed-reader"><span class="section-number-3">2.4.</span> RSS Feed Reader</h3>
<p>I have just started using <a href="https://newsboat.org/">Newsboat</a> to read articles in my terminal and have found quick success with it.</p>
<p>The configuration was super easy for this app; I simply installed the app, created a file for URLs, and imported my OPML (Outline Processor Markup Language) subscriptions that I had exported out of my old feed reader:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">brew</span></span><span class="meta function-call arguments shell"> install newsboat</span></span></code></pre>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">touch</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/.newsboat/urls</span></span></code></pre>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">newsboat</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>i</span><span class="keyword operator assignment option shell">=</span>my_subscriptions.opml</span></span></code></pre>
<h3 id="writing-programming"><span class="section-number-3">2.5.</span> Writing &amp; Programming</h3>
<p>Unfortunately, the weak link in my terminal-based environment right now is my grasp of the possibilities of editing files within a shell.</p>
<p>I am used to the easy extensions found in VSCodium and Kate, so I am slowly learning how to mold the default editing tools to my needs. Currently, this means I am using <code class="verbatim">nano</code> with the following configuration:</p>
<pre><code class="language-config">set breaklonglines
set autoindent
set linenumbers
set tabstospaces
set tabsize 2
set fill 80</code></pre>
<p>This configuration allows nano to automatically hard-wrap lines at 80 characters, autoindent the wrapped lines (if the previous line was indented), use 2 spaces per tab, and display line numbers within each file I open.</p>
<p>I am currently looking to see if <code class="verbatim">vim</code> or <code class="verbatim">emacs</code> would be more useful for my current needs, but I'm not in any rush, so I don't expect to find an answer anytime soon.</p>
<p>With my current life demands, I am not programming at the moment and have not explored the best terminal set-up for programming. However, I have seen many peers find success configuring <code class="verbatim">vim</code> and <code class="verbatim">emacs</code>, so that's where I will start when I pick my projects back up.</p>
]]></description>
    </item>
    <item>
      <title>Self-Hosting Guide: FreshRSS</title>
      <link>https://cleberg.net/blog/self-hosting-freshrss.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/self-hosting-freshrss.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Tue, 07 Jun 2022 00:00:00 +0000</pubDate>
      <category>linux</category>
      <category>self-hosting</category>
      <description><![CDATA[<h2 id="why-use-really-simple-syndication-rss"><span class="section-number-2">1.</span> Why Use Really Simple Syndication (RSS)?</h2>
<p>After noticing that I have collected 50+ blogs as bookmarks, I decided to migrate back to using RSS feeds to stay up-to-date with my favorite websites. Using RSS allows me to read all of these posts in a single app (on both mobile &amp; desktop) and allows me to be notified when new posts are available.</p>
<p>However, I ran into one issue: syncing subscriptions and read/unread posts across devices. Since I want to be able to easily read on both mobile and desktop, I decided to look for a self-hosted RSS solution.</p>
<p>Thus, I found <a href="https://www.freshrss.org/">FreshRSS</a> and was able to successfully install it on my server in about 30 minutes.</p>
<h2 id="documentation"><span class="section-number-2">2.</span> Documentation</h2>
<p>While it's certainly not robust, the <a href="https://freshrss.github.io/FreshRSS/">FreshRSS documentation</a> is helpful for figuring out basic information about the service.</p>
<p>However, I wanted to install this service as a Docker container and stumbled across the <a href="https://github.com/FreshRSS/FreshRSS/tree/edge/Docker">Docker README</a> within the GitHub repository.</p>
<p>This README was the documentation I actually needed. However, as you'll see below, I still had to manually edit one file (<code class="verbatim">config.php</code>) to access the API externally via my RSS apps.</p>
<h2 id="installation"><span class="section-number-2">3.</span> Installation</h2>
<h3 id="dns"><span class="section-number-3">3.1.</span> DNS</h3>
<p>The first step, as required by any external web service, was assigning a domain name to use. I chose to use a subdomain, like <code class="verbatim">rss.example.com</code>.</p>
<p>To assign this, I created an <code class="verbatim">A</code> record in my DNS settings with the IPv4 (Internet Protocol version 4) address of the server and an <code class="verbatim">AAAA</code> record with the IPv6 (Internet Protocol version 6) address of the server. Note: assigning an IPv6 (<code class="verbatim">AAAA</code>) record is optional, but I like to enable IPV6 for my services.</p>
<pre><code class="language-config">rss.example.com     A       xxx.xxx.xxx.xxx
rss.example.com     AAAA    xxxx:xxxx: ... :xxxx</code></pre>
<h3 id="docker"><span class="section-number-3">3.2.</span> Docker</h3>
<p>I initially tried to set up a <code class="verbatim">docker-compose.yml</code> file with a <code class="verbatim">.env</code> file because I prefer to have a file I can look back at later to see how I initially started the container, but it simply wouldn't work for me. I'm not sure why, but I assume I wasn't telling <code class="verbatim">docker-compose</code> where the <code class="verbatim">.env</code> file was.</p>
<p>Regardless, I chose to simply run the service with <code class="verbatim">docker run</code>. See the following command for my <code class="verbatim">docker run</code> configuration:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> docker run<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>d</span><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> --</span>restart</span> unless-stopped<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> --</span>log-opt</span> max-size=10m <span class="punctuation separator continuation line shell">\
</span><span class="variable parameter option shell"><span class="punctuation definition parameter shell">  -</span>p</span> 8080:80 <span class="punctuation separator continuation line shell">\
</span><span class="variable parameter option shell"><span class="punctuation definition parameter shell">  -</span>e</span> TZ=America/Chicago <span class="punctuation separator continuation line shell">\
</span><span class="variable parameter option shell"><span class="punctuation definition parameter shell">  -</span>e</span> <span class="string quoted single shell"><span class="punctuation definition string begin shell">&#39;</span>CRON_MIN=1,31<span class="punctuation definition string end shell">&#39;</span></span> <span class="punctuation separator continuation line shell">\
</span><span class="variable parameter option shell"><span class="punctuation definition parameter shell">  -</span>v</span> freshrss_data:/var/www/FreshRSS/data <span class="punctuation separator continuation line shell">\
</span><span class="variable parameter option shell"><span class="punctuation definition parameter shell">  -</span>v</span> freshrss_extensions:/var/www/FreshRSS/extensions <span class="punctuation separator continuation line shell">\
</span><span class="variable parameter option shell"><span class="punctuation definition parameter shell">  --</span>name</span> freshrss <span class="punctuation separator continuation line shell">\
</span>  freshrss/freshrss</span></span></code></pre>
<p>This started the container successfully and allowed me to visit the FreshRSS instance at <code class="verbatim">localhost:8080</code>.</p>
<h3 id="fresh-rss-set-up"><span class="section-number-3">3.3.</span> Fresh RSS Set-Up</h3>
<p>I <strong>HIGHLY</strong> suggest that you set up your user account prior to exposing this service to the public. It's unlikely that someone is trying to access the exact domain or IP/port you're assigning here, but as soon as you expose this service, the first person to open the URL will be able to create the administrative user.</p>
<p>In order to set up your FreshRSS service, open the <code class="verbatim">localhost:8080</code> URL in your browser (you may need to use a local internet protocol (IP) instead of <code class="verbatim">localhost</code> if you're accessing the page from a different machine on the network - e.g., <code class="verbatim">192.168.1.20:8080</code>).</p>
<p>Once the page loads, set up your default user with a strong username and password. You may also choose to configure other settings prior to exposing this service.</p>
<h3 id="nginx-reverse-proxy"><span class="section-number-3">3.4.</span> Nginx Reverse-Proxy</h3>
<p>In order to access this service outside my home, I needed to set up a reverse-proxy to connect <code class="verbatim">localhost:8080</code> to <code class="verbatim">rss.example.com</code>.</p>
<p>First, I created a new Nginx configuration file:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> nano /etc/nginx/sites-available/rss.example.com</span></span></code></pre>
<p>Within the configuration file, I pasted the following code:</p>
<pre><code class="language-config">upstream freshrss {
        server 127.0.0.1:8080;
        keepalive 64;
}

server {
        server_name rss.example.com;
        listen 80;

        location / {
                # The final `/` is important.
                proxy_pass http://localhost:8080/;
                add_header X-Frame-Options SAMEORIGIN;
                add_header X-XSS-Protection "1; mode=block";
                proxy_redirect off;
                proxy_buffering off;
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header X-Forwarded-Proto $scheme;
                proxy_set_header X-Forwarded-Port $server_port;
                proxy_read_timeout 90;

                # Forward the Authorization header for the Google Reader API.
                proxy_set_header Authorization $http_authorization;
                proxy_pass_header Authorization;
        }
}</code></pre>
<p>Finally, restart Nginx and you will be able to access your service via HTTP (Hypertext Transfer Protocol):</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> systemctl restart nginx.service</span></span></code></pre>
<h3 id="https"><span class="section-number-3">3.5.</span> HTTPS</h3>
<p>However, I don't want to access my RSS feeds via HTTP. I want it available only via HTTPS (Hypertext Transfer Protocol Secure). In order to do this, I ran the <a href="https://certbot.eff.org/">certbot</a> program to generate SSL (Secure Socket Layer) certificates for me:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> certbot<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> --</span>nginx</span></span></span></code></pre>
<p>This process will automatically generate an SSL certificate for you and modify the Nginx configuration file to include a redirect from HTTP to HTTPS.</p>
<h2 id="post-installation-fixes"><span class="section-number-2">4.</span> Post-Installation Fixes</h2>
<p>At this point, we have a functional FreshRSS website, available from anywhere and secured with HTTPS. However, attempting to connect this service to an RSS app resulted in many errors regarding unavailable URLs and incorrect credentials.</p>
<h3 id="api-set-up"><span class="section-number-3">4.1.</span> API Set-Up</h3>
<p>First, you need to open your user profile in FreshRSS (<code class="verbatim">Settings</code> &gt; <code class="verbatim">Profile</code>) and set an API password in the field at the bottom. This is the password you will need to provide to your RSS apps.</p>
<p>Once that is set and saved, click the link below the API password field to open the API (application programming interface) check tool. It should look something like <code class="verbatim">https://localhost:8080/api/</code> or <code class="verbatim">https://rss.example.com/api/</code>.</p>
<p>Within this page, you <em>should</em> see your correct external URL and "PASS" at the bottom of each API type. This would mean everything is set up correctly, and you can now move on and login to any RSS apps that support self-hosted options.</p>
<p>In my case, the URL showed an internal URL and I had a warning that the <code class="verbatim">base_url</code> variable may be misconfigured. If this is the case, see the next section for a fix.</p>
<h3 id="base-url-fix"><span class="section-number-3">4.2.</span> Base URL Fix</h3>
<p>In order to fix the <code class="verbatim">base_url</code> for the API, I opened up my docker container with the following command:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> docker exec<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>it</span> freshrss bash</span></span></code></pre>
<p>Within this container, update the packages and install an editor:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">apt-get</span></span><span class="meta function-call arguments shell"> update</span>
<span class="meta function-call shell"><span class="variable function shell">apt-get</span></span><span class="meta function-call arguments shell"> install nano</span></span></code></pre>
<p>Finally, open up <code class="verbatim">config.php</code> in the <code class="verbatim">data</code> directory:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">nano</span></span><span class="meta function-call arguments shell"> data/config.php</span></span></code></pre>
<p>Within <code class="verbatim">config.php</code>, you will need to update the <code class="verbatim">base_url</code> variable and update it to match your external URL (uniform resource locator). In my case, I simply commented-out the incorrect URL with <code class="verbatim">//</code> and added the correct one on a new line:</p>
<pre><code class="language-php highlight"><span class="embedding php"><span class="text html basic"><span class="meta embedded block php"><span class="punctuation section embedded begin php">&lt;?php</span></span><span class="meta embedded block php"><span class="source php">
    <span class="keyword control php">return</span> <span class="storage type php">array</span> <span class="meta group php"><span class="punctuation section group begin php">(</span>
        <span class="keyword operator string php">.</span><span class="keyword operator string php">.</span><span class="keyword operator string php">.</span>
        <span class="comment line double-slash php"><span class="punctuation definition comment php">//</span>  &#39;base_url&#39; =&gt; &#39;http://localhost:8080&#39;,
</span>        <span class="string quoted single php"><span class="punctuation definition string begin php">&#39;</span></span><span class="string quoted single php"><span class="meta string-contents quoted single php"></span></span><span class="string quoted single php"><span class="meta string-contents quoted single php">base_url</span><span class="punctuation definition string end php">&#39;</span></span> <span class="keyword operator key php">=&gt;</span> <span class="string quoted single php"><span class="punctuation definition string begin php">&#39;</span></span><span class="string quoted single php"><span class="meta string-contents quoted single php"></span></span><span class="string quoted single php"><span class="meta string-contents quoted single php">https://rss.example.com</span><span class="punctuation definition string end php">&#39;</span></span>,
        <span class="keyword operator string php">.</span><span class="keyword operator string php">.</span><span class="keyword operator string php">.</span>
    <span class="punctuation section group end php">)</span></span>
<span class="keyword operator comparison php">&gt;</span></span></span></span></span></code></pre>
<p>You can now exit the file with <code class="verbatim">Ctrl + x</code>, press <code class="verbatim">y</code> to save the file, and then click <code class="verbatim">Enter</code> to keep the same file name.</p>
<p>Finally, just exit out of the docker container:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="support function exit shell">exit</span></span></span></code></pre>
<p>Next, just restart the container:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> docker restart freshrss</span></span></code></pre>
<p>Voilà! Your API check should now "PASS" and you should be able to use one of the API URLs in your RSS apps.</p>
<p>In my case, I use <a href="https://netnewswire.com">NetNewsWire</a> on my desktop and phone.</p>
]]></description>
    </item>
    <item>
      <title>Ditching Cloudflare</title>
      <link>https://cleberg.net/blog/ditching-cloudflare.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/ditching-cloudflare.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Wed, 01 Jun 2022 00:00:00 +0000</pubDate>
      <category>privacy</category>
      <category>security</category>
      <description><![CDATA[<h2 id="registrar"><span class="section-number-2">1.</span> Registrar</h2>
<p>After spending a year or so using Cloudflare for DNS (Domain Name System) only - no proxying or applications - I spent the last few months using Cloudflare Tunnels and Cloudflare Access to protect my self-hosted websites and applications via their proxy traffic model.</p>
<p>However, I have never liked using Cloudflare due to their increasingly large share of control over web traffic, as well as their business model of being a MITM (man-in-the-middle) for all of your traffic.</p>
<p>So, as of today, I have switched over to <a href="https://njal.la">Njalla</a> as my registrar and DNS manager. I was able to easily transfer my domains over rapidly, with only one domain taking more than 15-30 minutes to propagate.</p>
<p><del>I do still have two domains sitting at Cloudflare for the moment while I decide if they're worth the higher rates (one domain is 30€ and the other is 45€).</del></p>
<blockquote>
<p><strong>Update (2022.06.03)</strong>: I ended up transferring my final two domains over to Njalla, clearing my Cloudflare account of personal data, and deleting the Cloudflare account entirely. <em>I actually feel relieved to have moved on to a provider I trust.</em></p>
</blockquote>
<h2 id="dns"><span class="section-number-2">2.</span> DNS</h2>
<p>As noted above, I'm using Njalla exclusively for DNS configurations on my domains.</p>
<p>However, the transfer process was not ideal. As soon as the domains transferred over, I switched the nameservers from Cloudflare to Njalla and lost most of the associated DNS records. So, the majority of the time spent during the migration was simply re-typing all the DNS records back in one-by-one.</p>
<p>This would be much simpler if I were able to edit the plain-text format of the DNS configuration. I was able to do that at a past registrar (perhaps it was <a href="https://gandi.net/">Gandi.net</a>?) and it made life a lot easier.</p>
<h3 id="dynamic-dns-updates"><span class="section-number-3">2.1.</span> Dynamic DNS Updates</h3>
<p>I have built an easy Python script to run (or set-up in <code class="verbatim">cron</code> to run automatically) that will check my server's IPv4 (Internet Protocol version 4)and IPv6 (Internet Protocol version 6), compare it to Njalla, and update the DNS records if they don't match. You can see the full script and process in my other post: <a href="https://cleberg.net/blog/njalla-dns-api.html">Automating Dynamic DNS Record Updates via Njalla API</a>.</p>
<p>I haven't used this other method, but I do know that you can create <code class="verbatim">Dynamic</code> DNS records with Njalla that <a href="https://njal.la/docs/ddns/">work for updating dynamic subdomains</a>.</p>
<h3 id="njalla-s-dns-tool"><span class="section-number-3">2.2.</span> Njalla's DNS Tool</h3>
<p>One neat upside to Njalla is that they have a <a href="https://check.njal.la/dns/">DNS lookup tool</a> that provides a lot of great information for those of you (AKA: me) who hate using the <code class="verbatim">dig</code> command.</p>
<p>This was very useful for monitoring a couple of my transferred domains to see when the changes in nameservers, records, and DNSSEC (Domain Name System Security Extensions) went into effect.</p>
<h2 id="tunnel"><span class="section-number-2">3.</span> Tunnel</h2>
<p>Cloudflare Tunnel is a service that acts as a reverse-proxy (hosted on Cloudflare's servers) and allowed me to mask the private internet protocol (IP) address of the server hosting my various websites and apps.</p>
<p>However, as I was moving away from Cloudflare, I was not able to find a suitable replacement that was both inexpensive and simple. So, I simply went back to hosting <a href="/blog/nginx-reverse-proxy.html">my own reverse proxy with Nginx</a>. With the recent additions of Unifi hardware in my server/network rack, I am much more protected against spam and malicious attacks at the network edge than I was before I switched to Cloudflare.</p>
<h2 id="access"><span class="section-number-2">4.</span> Access</h2>
<p>Cloudflare Access, another app I used in combination with Cloudflare Tunnel, provided an authentication screen that required you to enter valid credentials before Cloudflare would forward you to the actual website or app (if the website/app has their own authentication, you'd then have to authenticate a second time).</p>
<p>I did not replace this service with anything since I only host a handful of non-sensitive apps that don't require duplicate authentication.</p>
]]></description>
    </item>
    <item>
      <title>PineTime: Open Source Smartwatch Overview</title>
      <link>https://cleberg.net/blog/pinetime.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/pinetime.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Sat, 09 Apr 2022 00:00:00 +0000</pubDate>
      <category>linux</category>
      <description><![CDATA[<h2 id="pinetime-product-information"><span class="section-number-2">1.</span> PineTime Product Information</h2>
<h3 id="overview"><span class="section-number-3">1.1.</span> Overview</h3>
<p>The <a href="https://www.pine64.org/pinetime/">PineTime</a> is an open-source smartwatch, created by <a href="https://www.pine64.org">PINE64</a>. Originally announced in September 2019, this ARM-based watch is a fantastic option for users who want the benefits of a modern smartwatch with the backing of open-source components and software.</p>
<h3 id="product-specifications"><span class="section-number-3">1.2.</span> Product Specifications</h3>
<p>I won't dive into too many details that you can find on <a href="https://www.pine64.org/pinetime/">the product page</a>, but I wanted to point out the prices for each watch and the primary functions:</p>
<ol>
<li>Price:<ul>
<li>$26.99 (Sealed)</li>
<li>$24.99 (Dev Kit)</li>
<li>$51.98 (One Sealed + One Dev Kit)</li>
</ul>
</li>
<li>Primary Functionality:<ul>
<li>Clock (+ Smartphone Sync)</li>
<li>Pedometer</li>
<li>Heart Rate Monitor</li>
<li>Sleep Monitor</li>
<li>Calories burned</li>
<li>Messaging</li>
<li>Smartphone Notifications</li>
<li>Media Controls</li>
</ul>
</li>
</ol>
<h2 id="unboxing"><span class="section-number-2">2.</span> Unboxing</h2>
<p>Now, my PineTime was ordered on 2022-02-17, shipped on 2022-02-22, and was delivered on 2022-03-23. With the current delays on shipping times around the world (and the semiconductor shortage), a month for delivery from China seems reasonable to me.</p>
<p>The packaging is simple, and the watch comes with instructions, technical information, the watch, and a charger (it does not include a USB wall adapter).</p>
<p>The watch itself was able to turn on immediately when I pulled it out of the box, but the battery was depleted and required charging right away.</p>
<h2 id="software"><span class="section-number-2">3.</span> Software</h2>
<h3 id="watch-operating-system-os-infinitime"><span class="section-number-3">3.1.</span> Watch Operating System (OS): InfiniTime</h3>
<p>While turning on the watch for the first time, some of the main design choices you can see in the watch OS, <a href="https://wiki.pine64.org/wiki/InfiniTime">InfiniTime</a>, are:</p>
<ul>
<li>A square bezel, not too thin against the sides of the watch.</li>
<li>A simple, rubber band.</li>
<li>Basic font and screen pixel design.</li>
<li>Swipe gestures to access other screens.</li>
</ul>
<p>The OS itself is fantastic in terms of functionality for me. It does exactly what a smartwatch should do - track time, steps, heart rates, and connect to another smart device, without being overly burdensome to the user.</p>
<p>My only gripe so far is that it's <em>really</em> difficult to swipe to different screens, such as pulling down the notification tray. I'm not sure if this is an OS or hardware issue, but it makes it quite hard to quickly move around the screens.</p>
<p>However, my absolute favorite design choice is that the button the side turns the screen on and off and tilting/waving my wrist doesn't accidentally turn on the screen. With other watches, I absolutely hated not being able to turn off the raise-to-wake or wave features (i.e., blinding myself while wearing a watch at night because I moved my arm).</p>
<h3 id="ios-app-infinilink"><span class="section-number-3">3.2.</span> iOS App: InfiniLink</h3>
<p>Since I am using iOS as my primary mobile device OS, I am using the <a href="https://github.com/xan-m/InfiniLink">InfiniLink</a> app to connect my watch.</p>
<p>This app provides the following for PineTime owners:</p>
<ul>
<li>Firmware updates</li>
<li>Steps</li>
<li>Charts</li>
<li>Notifications</li>
</ul>
<p>Another big feature of InfiniLink is the ability to track pedometer steps in a collection of beautiful graphs, with the option to change your step goal and add in manual steps.</p>
<p>Finally, there are charts to display the battery percentage and heart rates over time. This area also comes with an option to clear data.</p>
<h2 id="final-thoughts"><span class="section-number-2">4.</span> Final Thoughts</h2>
<h3 id="pros"><span class="section-number-3">4.1.</span> Pros</h3>
<p>After wearing my watch for a few weeks, I have mostly positive thoughts about the watch so far. In the past, I have owned smartwatches by FitBit, Fossil, Apple, etc. - <strong>but I prefer the PineTime over all of those watches</strong>.</p>
<p>The PineTime strips out all the unnecessary features and performs the functions that it provides effectively and efficiently.</p>
<p>The battery life is amazing on this device. By default, the watch seems to last anywhere from a few days to a week before dying.</p>
<p>And of course, it's open source and backed by some of the most dedicated enthusiasts and developers I've seen. Watching the Matrix channel, forums, and website have been exciting to see.</p>
<h3 id="cons"><span class="section-number-3">4.2.</span> Cons</h3>
<p>If I had to complain about anything, it would simply be the small bugs in some features that can be contributed to the companion apps more than the watch itself.</p>
<p>A regular user would want native notification support out-of-the-box, which is the biggest item not working for me at the moment.</p>
<p>My only other complaint is that the battery indicator on the watch doesn't seem accurate when it's nearing depletion - it seems that there's a bit of battery life left and then my watch is dead very suddenly after. This could just be me misinterpreting the battery level icons, but it has fooled me a few times into thinking I had more battery left than I actually did.</p>
<p>Other than those small items, I really do love this watch and am glad I replaced my Apple Watch with the PineTime.</p>
]]></description>
    </item>
    <item>
      <title>Nginx Reverse Proxy Config</title>
      <link>https://cleberg.net/blog/nginx-reverse-proxy.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/nginx-reverse-proxy.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Sat, 02 Apr 2022 00:00:00 +0000</pubDate>
      <category>linux</category>
      <category>web</category>
      <description><![CDATA[<h2 id="what-is-a-reverse-proxy"><span class="section-number-2">1.</span> What is a Reverse Proxy?</h2>
<p>A reverse proxy is a server that is placed between local servers or services and clients/users (e.g., the internet). The reverse proxy intercepts all requests from clients at the network edge and uses its configuration files to determine where each request should be sent.</p>
<h3 id="a-brief-example"><span class="section-number-3">1.1.</span> A Brief Example</h3>
<p>For example, let's say that I run three servers in my home:</p>
<ul>
<li>Server01 (<code class="verbatim">example.com</code>)</li>
<li>Server02 (<code class="verbatim">service01.example.com</code>)</li>
<li>Server03 (<code class="verbatim">service02.example.com</code>)</li>
</ul>
<p>I also run a reverse proxy in my home that intercepts all public traffic:</p>
<ul>
<li>Reverse Proxy</li>
</ul>
<p>Assume that I have a domain name (<code class="verbatim">example.com</code>) that allows clients to request websites or services from my home servers.</p>
<p>In this case, the reverse proxy will intercept all traffic from <code class="verbatim">example.com</code> that enters my network and determine if the client is requesting valid data, based on my configuration.</p>
<p>If the user is requesting <code class="verbatim">example.com</code> and my configuration files say that Server<sub>01</sub> holds that data, Nginx will send the user to Server<sub>01</sub>. If I were to change the configuration so that <code class="verbatim">example.com</code> is routed to Server<sub>02</sub>, that same user would be sent to Server<sub>02</sub> instead.</p>
<pre><code class="language-txt highlight"><span class="text plain">┌──────┐                                              ┌───────────┐
│ User │─┐                                         ┌──► Server_01 │
└──────┘ │                                         │  └───────────┘
         │    ┌──────────┐   ┌───────────────┐     │  ┌───────────┐
         ├────► Internet ├───► Reverse Proxy ├─────├──► Server_02 │
         │    └──────────┘   └───────────────┘     │  └───────────┘
┌──────┐ │                                         │  ┌───────────┐
│ User │─┘                                         └──► Server_03 │
└──────┘                                              └───────────┘</span></code></pre>
<h2 id="reverse-proxy-options"><span class="section-number-2">2.</span> Reverse Proxy Options</h2>
<p>There are a lot of options when it comes to reverse proxy servers, so I'm just going to list a few of the options I've heard recommended over the last few years:</p>
<ul>
<li><a href="https://nginx.com">Nginx</a></li>
<li><a href="https://caddyserver.com">Caddy</a></li>
<li><a href="https://traefik.io/">Traefik</a></li>
<li><a href="https://www.haproxy.org/">HAProxy</a></li>
<li><a href="https://ubuntu.com/server/docs/proxy-servers-squid">Squid</a></li>
</ul>
<p>In this post, we will be using Nginx as our reverse proxy, running on Ubuntu Server 20.04.4 LTS.</p>
<h2 id="nginx-reverse-proxy-example"><span class="section-number-2">3.</span> Nginx Reverse Proxy Example</h2>
<h3 id="local-applications"><span class="section-number-3">3.1.</span> Local Applications</h3>
<p>You may be like me and have a lot of applications running on your local network that you'd like to expose publicly with a domain.</p>
<p>In my case, I have services running in multiple Docker containers within a single server and want a way to visit those services from anywhere with a URL. For example, on my local network, <a href="https://dashy.to">Dashy</a> runs through port 4000 (<code class="verbatim">localhost:4000</code>) and <a href="https://github.com/louislam/uptime-kuma">Uptime Kuma</a> runs through port 3001 (<code class="verbatim">localhost:3001</code>).</p>
<p>In order to expose these services to the public, I will need to do the following:</p>
<ol>
<li>Set up DNS (Domain Name System) records for a domain or subdomain (one per service) to point toward the internet protocol (IP) address of the server.</li>
<li>Open up the server network's HTTP (Hypertext Transfer Protocol) and HTTPS (Hypertext Transfer Protocol Secure) ports (80 &amp; 443) so that the reverse proxy can accept traffic and determine where to send it.</li>
<li>Install the reverse proxy software.</li>
<li>Configure the reverse proxy to recognize which service should get traffic from any of the domains or subdomains.</li>
</ol>
<h3 id="step-1-dns-configuration"><span class="section-number-3">3.2.</span> Step 1: DNS Configuration</h3>
<p>To start, update your DNS configuration so that you have an <code class="verbatim">A</code> record for each domain or subdomain.</p>
<p>The <code class="verbatim">A</code> records should point toward the public IP address of the server. If you don't know the public IP address, log in to the server and run the following command:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">curl</span></span><span class="meta function-call arguments shell"> ifconfig.co</span></span></code></pre>
<p>In the DNS example below, <code class="verbatim">xxx.xxx.xxx.xxx</code> is the public IP address of the server.</p>
<pre><code class="language-conf">example.com             A        xxx.xxx.xxx.xxx
uptime.example.com      A        xxx.xxx.xxx.xxx
dashy.example.com       A        xxx.xxx.xxx.xxx
www                     CNAME    example.com</code></pre>
<p>Finally, ensure the DNS has propagated correctly with <a href="https://dnschecker.org">DNS Checker</a> by entering your domains or subdomains in the search box and ensuring the results are showing the correct IP address.</p>
<h3 id="step-2-open-network-ports"><span class="section-number-3">3.3.</span> Step 2: Open Network Ports</h3>
<p>This step will be different depending on which router you have in your home. If you're not sure, try to visit <a href="http://192.168.1.1">192.168.1.1</a> in your browser. Login credentials are usually written on a sticker somewhere on your modem/router.</p>
<p>Once you're able to log in to your router, find the Port Forwarding settings. You will need to forward ports <code class="verbatim">80</code> and <code class="verbatim">443</code> to whichever machine is running the reverse proxy.</p>
<p>In my case, the table below shows the port-forwarding rules I've created. In this table, <code class="verbatim">xxx.xxx.xxx.xxx</code> is the local device IP of the reverse proxy server, it will probably be an IP between <code class="verbatim">192.168.1.1</code> and <code class="verbatim">192.168.1.255</code>.</p>
<table>
<thead>
<tr><th>NAME</th><th>FROM PORT</th><th>DEST PORT/IP</th><th>ENABLED</th></tr>
</thead>
<tbody>
<tr><td>HTTP</td><td>80</td><td>xxx.xxx.xxx.xxx</td><td>TRUE</td></tr>
<tr><td>HTTPS</td><td>443</td><td>xxx.xxx.xxx.xxx</td><td>TRUE</td></tr>
</tbody>
</table>
<p>Once configured, these rules will direct all web traffic to your reverse proxy.</p>
<h3 id="step-3-nginx-installation"><span class="section-number-3">3.4.</span> Step 3: Nginx Installation</h3>
<p>To install Nginx, simply run the following command:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> apt install nginx</span></span></code></pre>
<p>If you have a firewall enabled, open up ports <code class="verbatim">80</code> and <code class="verbatim">443</code> on your server so that Nginx can accept web traffic from the router.</p>
<p>For example, if you want to use <code class="verbatim">ufw</code> for web traffic and SSH, run the following commands:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> ufw allow <span class="string quoted single shell"><span class="punctuation definition string begin shell">&#39;</span>Nginx Full<span class="punctuation definition string end shell">&#39;</span></span></span>
<span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> ufw allow SSH</span>
<span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> ufw enable</span></span></code></pre>
<h3 id="step-4-nginx-configuration"><span class="section-number-3">3.5.</span> Step 4: Nginx Configuration</h3>
<p>Now that we have domains pointing toward the server, the only step left is to configure the reverse proxy to direct traffic from domains to local services.</p>
<p>To start, you'll need to create a configuration file for each domain in <code class="verbatim">/etc/nginx/sites-available/</code>. They will look identical except for the <code class="verbatim">server_name</code> variable and the <code class="verbatim">proxy_pass</code> port.</p>
<p>Dashy:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">nano</span></span><span class="meta function-call arguments shell"> /etc/nginx/sites-available/dashy.example.com</span></span></code></pre>
<pre><code class="language-config">server {
    listen 80;
    server_name dashy.example.com;

    location / {
        proxy_pass http://localhost:4000;
    }
}</code></pre>
<p>Uptime:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">nano</span></span><span class="meta function-call arguments shell"> /etc/nginx/sites-available/uptime.example.com</span></span></code></pre>
<pre><code class="language-config">server {
    listen 80;
    server_name uptime.example.com;

    location / {
        proxy_pass http://localhost:3001;
    }
}</code></pre>
<p>Once the configuration files are created, you will need to enable them with the <code class="verbatim">symlink</code> command:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> ln<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>s</span> /etc/nginx/sites-available/dashy.example.com /etc/nginx/sites-enabled/</span></span></code></pre>
<p>Voilà! Your local services should now be available through their URLs (uniform resource locators).</p>
<h2 id="https-with-certbot"><span class="section-number-2">4.</span> HTTPS with Certbot</h2>
<p>If you've followed along, you'll notice that your services are only available via HTTP (not HTTPS).</p>
<p>If you want to enable HTTPS for your new domains, you will need to generate TLS (Transport Layer Security) certificates for them. The easiest way to generate certificates on Nginx is <a href="https://certbot.eff.org">Certbot</a>:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> apt install snapd</span><span class="keyword operator logical continue shell">;</span> <span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> snap install core</span><span class="keyword operator logical continue shell">;</span> <span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> snap refresh core</span>
<span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> snap install<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> --</span>classic</span> certbot</span>
<span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> ln<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>s</span> /snap/bin/certbot /usr/bin/certbot</span>
<span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> certbot<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> --</span>nginx</span></span></span></code></pre>
]]></description>
    </item>
    <item>
      <title>SSH MFA: TOTP on Top of Keys</title>
      <link>https://cleberg.net/blog/ssh-mfa.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/ssh-mfa.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Sat, 26 Mar 2022 00:00:00 +0000</pubDate>
      <category>security</category>
      <description><![CDATA[<h2 id="why-do-i-need-multi-factor-authentication-mfa-for-ssh-secure-shell-protocol"><span class="section-number-2">1.</span> Why Do I Need Multi-Factor Authentication (MFA) for SSH (Secure Shell Protocol)?</h2>
<p>If you are a sysadmin of a server anywhere (that includes at home!), you may want an added layer of protection against intruders. This is not a replacement for other security measures, such as:</p>
<ul>
<li>Disable root SSH</li>
<li>Disable SSH password authentication</li>
<li>Allow only certain users to login via SSH</li>
<li>Allow SSH only from certain internet protocol (IP) addresses</li>
</ul>
<p>However, MFA can be added as an additional security measure to ensure that your server is protected. This is especially important if you need to allow password authentication for SSH.</p>
<p>For more guidance on server security measures, see my other post: <a href="https://cleberg.net/blog/server-hardening.html">Step-by-Step Guide to Securing Your Home Server with Firewalls, SSH, and VLANs</a>.</p>
<h2 id="install-mfa-pam-module"><span class="section-number-2">2.</span> Install MFA PAM Module</h2>
<p>PAM (Pluggable Authentication Module) is an authentication infrastructure used on Linux systems to authenticate a user. In order to use this technology, let's install the <code class="verbatim">libpam-google-authenticator</code> package:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> apt-get update</span></span></code></pre>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> apt-get install libpam-google-authenticator</span></span></code></pre>
<h2 id="initialize-the-pam-module"><span class="section-number-2">3.</span> Initialize the PAM Module</h2>
<h3 id="interactive-method"><span class="section-number-3">3.1.</span> Interactive Method</h3>
<p>Once the package is installed, initialize it and following the interactive prompts to generate your OTP (One-Time Password) or TOTP (Time-based One-Time Password):</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">google-authenticator</span></span></span></code></pre>
<p>If you are not sure how to answer, read the prompts carefully and think about having to how each situation would affect your normal login attempts. If you are still not sure, use my default responses below.</p>
<pre><code class="language-txt highlight"><span class="text plain">OUTPUT

Do you want authentication tokens to be time-based (y/n) y</span></code></pre>
<p>At this point, use an authenticator app somewhere one of your devices to scan the QR (quick-response) code. Any future login attempts after our upcoming configuration changes will require that TOTP.</p>
<pre><code class="language-txt highlight"><span class="text plain">OUTPUT

Do you want me to update your &quot;/home/user/.google_authenticator&quot; file? (y/n) y</span></code></pre>
<pre><code class="language-txt highlight"><span class="text plain">OUTPUT

Do you want to disallow multiple uses of the same authentication
token? This restricts you to one login about every 30s, but it increases
your chances to notice or even prevent man-in-the-middle attacks (y/n) y</span></code></pre>
<pre><code class="language-txt highlight"><span class="text plain">OUTPUT

By default, a new token is generated every 30 seconds by the mobile app.
In order to compensate for possible time-skew between the client and the server,
we allow an extra token before and after the current time. This allows for a
time skew of up to 30 seconds between authentication server and client. If you
experience problems with poor time synchronization, you can increase the window
from its default size of 3 permitted codes (one previous code, the current
code, the next code) to 17 permitted codes (the 8 previous codes, the current
code, and the 8 next codes). This will permit for a time skew of up to 4 minutes
between client and server.
Do you want to do so? (y/n) n</span></code></pre>
<pre><code class="language-txt highlight"><span class="text plain">OUTPUT

If the computer that you are logging into isn&#39;t hardened against brute-force
login attempts, you can enable rate-limiting for the authentication module.
By default, this limits attackers to no more than 3 login attempts every 30s.
Do you want to enable rate-limiting? (y/n) y</span></code></pre>
<h3 id="non-interactive-method"><span class="section-number-3">3.2.</span> Non-Interactive Method</h3>
<p>If you need to do this quickly, know your responses to the prompts, or are setting this up for numerous users, the non-interactive method can be much faster:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">google-authenticator</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>t</span><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>d</span><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>f</span><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>r</span> 3<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>R</span> 30<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>w</span> 3</span></span></code></pre>
<p>The options referenced above are as follows:</p>
<pre><code class="language-txt highlight"><span class="text plain">google-authenticator [&lt;options&gt;]
 -h, --help                     Print this message
 -c, --counter-based            Set up counter-based (HOTP) verification
 -t, --time-based               Set up time-based (TOTP) verification
 -d, --disallow-reuse           Disallow reuse of previously used TOTP tokens
 -D, --allow-reuse              Allow reuse of previously used TOTP tokens
 -f, --force                    Write file without first confirming with user
 -l, --label=&lt;label&gt;            Override the default label in &quot;otpauth://&quot; URL
 -i, --issuer=&lt;issuer&gt;          Override the default issuer in &quot;otpauth://&quot; URL
 -q, --quiet                    Quiet mode
 -Q, --qr-mode={NONE,ANSI,UTF8} QRCode output mode
 -r, --rate-limit=N             Limit logins to N per every M seconds
 -R, --rate-time=M              Limit logins to N per every M seconds
 -u, --no-rate-limit            Disable rate-limiting
 -s, --secret=&lt;file&gt;            Specify a non-standard file location
 -S, --step-size=S              Set interval between token refreshes
 -w, --window-size=W            Set window of concurrently valid codes
 -W, --minimal-window           Disable window of concurrently valid codes
 -e, --emergency-codes=N        Number of emergency codes to generate</span></code></pre>
<p>This fully configures the authenticator, saves it to a file, and then outputs the secret key, QR code, and recovery codes. (If you add the flag <code class="verbatim">-q</code>, then there won't be any output). If you use this command in an automated fashion, make sure your script captures the secret key and/or recovery codes and makes them available to the user.</p>
<h2 id="pam-configuration-settings"><span class="section-number-2">4.</span> PAM Configuration Settings</h2>
<p>Once you've enabled MFA and have it saved to an MFA app on your phone or other device, open the PAM <code class="verbatim">sshd</code> file:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> nano /etc/pam.d/sshd</span></span></code></pre>
<p>You need to do two things in this file. First, add the following lines to the bottom of the file:</p>
<pre><code class="language-config">auth required pam_google_authenticator.so nullok
auth required pam_permit.so</code></pre>
<p>Second, comment-out the following line near the top of the file.</p>
<p>If you leave this line uncommented, every SSH login attempt will ask for the following three authentication factors:</p>
<ol>
<li>Publickey</li>
<li>Password</li>
<li>T/OTP code</li>
</ol>
<pre><code class="language-config">#@include common-auth</code></pre>
<h2 id="ssh-configuration-settings"><span class="section-number-2">5.</span> SSH Configuration Settings</h2>
<p>Finally, edit the <code class="verbatim">sshd_config</code> file again:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> nano /etc/ssh/sshd_config</span></span></code></pre>
<p>You'll need to change <code class="verbatim">ChallengeResponseAuthentication</code> to yes and add the <code class="verbatim">AuthenticationMethods</code> line to the bottom of the file.</p>
<pre><code class="language-config">ChallengeResponseAuthentication yes
AuthenticationMethods publickey,password publickey,keyboard-interactive</code></pre>
<p>Finally, restart the <code class="verbatim">ssh</code> service:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> systemctl restart sshd.service</span></span></code></pre>
<p>The next time you log in, you should be greeted with a verification code request!</p>
]]></description>
    </item>
    <item>
      <title>Server Hardening: Firewalls, SSH, VLANs</title>
      <link>https://cleberg.net/blog/server-hardening.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/server-hardening.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Thu, 24 Mar 2022 00:00:00 +0000</pubDate>
      <category>linux</category>
      <category>security</category>
      <description><![CDATA[<h2 id="planning-data-flows-security"><span class="section-number-2">1.</span> Planning Data Flows &amp; Security</h2>
<h3 id="my-personal-data-flow"><span class="section-number-3">1.1.</span> My Personal Data Flow</h3>
<pre><code class="language-none">                                                          ┌───────┐   ┌─────────────────┐
                                                       ┌──► VLAN1 ├───► Private Devices │
                                                       │  └───────┘   └─────────────────┘
┌──────────┐   ┌────────┐   ┌──────────┐   ┌────────┐  │
│ Internet ├───► Router ├───► Firewall ├───► Switch ├──┤
└──────────┘   └────────┘   └──────────┘   └────────┘  │
                                                       │  ┌───────┐   ┌───────────────┐
                                                       └──► VLAN2 ├───► Public Server │
                                                          └───────┘   └───────────────┘</code></pre>
<h3 id="thought-process"><span class="section-number-3">1.2.</span> Thought Process</h3>
<p>To serve content from your home server and harden your security posture, you have to think about the transport of data from <code class="verbatim">server</code> to <code class="verbatim">client</code>.</p>
<p>Let's start with the actual server itself. Think about the following:</p>
<ul>
<li>Do I have a firewall enabled? Do I need to update this to allow new ports or internet protocol (IP) addresses?</li>
<li>Do I have an intrusion prevention system (IPS) or intrusion detection system (IDS) that may prevent outside traffic?</li>
<li>Do I have any other security software installed?</li>
<li>Are the services hosted inside Docker containers, behind a reverse proxy, or virtualized? If so, are they configured to allow outside traffic?</li>
</ul>
<p>Once the data leaves the server, where does it go? In my case, it goes to a managed switch. In this case, I asked the following:</p>
<ul>
<li>What configurations is the switch using?</li>
<li>Am I using VLANs (virtual local area networks)?<ul>
<li>Yes, I am using 802.1Q VLANs.</li>
</ul>
</li>
<li>Are the VLANs configured properly?<ul>
<li>Yes, as shown in the Switch section below, I have a separate VLAN to allow outside traffic to and from the server alone. No other devices, except for a service port, and in that VLAN.</li>
</ul>
</li>
</ul>
<p>At this point, the data has been processed through the switch. Where does it go next? In my case, it's pretty simple: it goes to the router/modem device.</p>
<ul>
<li>Does my internet service provider (ISP) block any ports that I need?<ul>
<li>This is an important step that a lot of people run into when self-hosting at home. Use an online port-checker tool for your IP or call your ISP if you think ports are blocked.</li>
</ul>
</li>
<li>Is there a router firewall?<ul>
<li>Yes, I checked that it's configured to allow the ports I need to run my services publicly. Common web servers and reverse proxies require ports 80 and 443, but other services like media servers or games can require unique ports, so be sure to check the documentation for your service(s).</li>
</ul>
</li>
<li>Are there any other settings affecting inbound/outbound traffic?<ul>
<li>Schedules or access blocks</li>
<li>Static Routing</li>
<li>QoS (Quality of Service)</li>
<li>Port Forwarding</li>
<li>DMZ (demilitarized zone) hosting</li>
<li>Remote Management (this can sometimes mess with services that also require the use of ports 80 and 443)</li>
</ul>
</li>
</ul>
<p>Once the data leaves my router, it goes to the upstream ISP and can be accessed publicly.</p>
<h4 id="server"><span class="section-number-4">1.2.1.</span> Server</h4>
<p>The services I run on my server are installed straight into the operating system (OS), without any use of Docker or virtual machines (VMs), so I don't need any extra application configuration to make them accessible to the outside world.</p>
<blockquote>
<p>As of 2022-10-04, the paragraph above is no longer true as I now run a reverse proxy with Nginx and host many services inside Docker. However, it doesn't change anything regarding this post as I still just need to open ports 80 &amp; 443 and create the necessary website configuration files.</p>
</blockquote>
<p>When creating new services - either installed directly on bare metal or within something like Docker - I ensure that I read through the documentation thoroughly to understand a few key things:</p>
<ul>
<li>What network activities should this app perform (if any)? Using which ports and protocols?</li>
<li>Does this app require any commands/services to be run as <code class="verbatim">root</code>?</li>
<li>Does this app log errors, authentication failures/successes, or anything else that would be useful for an investigation?</li>
</ul>
<p>For extra security, I use limit all incoming connections to SSH connections through my server firewall [=ufw= (Uncomplicated Firewall)] and disable common SSH (Secure Shell Protocol) settings. After all of that, I use <code class="verbatim">fail2ban</code> as a preventative measure against brute-force login attempts.</p>
<p>As another piece of security, you can randomize your SSH port to ensure that random scanners or attackers can't easily try to force their way into your network. For example, you can edit the port rules in your server to block all connection requests to port <code class="verbatim">22</code> but forward all remote connections from port <code class="verbatim">12345</code> to your server's port <code class="verbatim">22</code>. Then you just need to SSH to your network via your randomized port.</p>
<h3 id="ufw"><span class="section-number-3">1.3.</span> <code class="verbatim">ufw</code></h3>
<p>To see how to configure <code class="verbatim">ufw</code>, see my other post: <a href="https://cleberg.net/blog/ufw.html">Secure Your Network with the Uncomplicated Firewall</a>.</p>
<p>The general notion with an on-device firewall is that you want to deny all incoming connections by default and then selectively open certain ports for services or users that you know need access.</p>
<p>If you know that you will only be logging into this server from a certain set or list of IPs, you can always set the firewall to only allow connections to port 22 from those IPs.</p>
<p>For a quick start to only allow SSH connections to the server, use this:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> ufw default deny incoming</span>
<span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> ufw default allow outgoing</span>
<span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> ufw allow 22</span>
<span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> ufw enable</span></span></code></pre>
<h3 id="ssh"><span class="section-number-3">1.4.</span> <code class="verbatim">ssh</code></h3>
<ol>
<li><p>Using SSH Keys</p>
<p>First, make sure you have an SSH keypair generated on the device(s) that you'll be using to log in to the server. If you don't have an SSH key, run this command:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">ssh-keygen</span></span></span></code></pre>
<p>Now that we have an SSH key, copy it to the server with the following command, which will ask for the user's password before accepting the key:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">ssh-copy-id</span></span><span class="meta function-call arguments shell"> my_user@my_server</span></span></code></pre>
<p>If you have multiple keys, you'll need to specify which to use. After it's complete, <code class="verbatim">ssh</code> back into the server as that user and make sure it doesn't ask for a password.</p>
</li>
<li><p>Disable Password &amp; Root Authentication</p>
<p>Now that we can access the server without a password, we will disable password authentication and disable anyone from using <code class="verbatim">ssh</code> to login as <code class="verbatim">root</code>.</p>
<p>To do this, open the <code class="verbatim">sshd_config</code> file:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> nano /etc/ssh/sshd_config</span></span></code></pre>
<p>You'll need to update the parameters to the values below. If one of these rules is commented-out or doesn't exist, create the rule at the bottom of the file.</p>
<pre><code class="language-config">PermitRootLogin no
PasswordAuthentication no
PubkeyAuthentication yes</code></pre>
<p>Finally, restart the <code class="verbatim">ssh</code> service:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> systemctl restart sshd.service</span></span></code></pre>
<p>To test that everything's working so far, open ANOTHER terminal and try logging in as <code class="verbatim">root</code> over SSH. It is very important that you keep your current SSH session open and test with an additional session, or you will lock yourself out at some point and will need to use a recovery method (e.g., hooking monitor up to home server) to get yourself back in.</p>
</li>
<li><p>Enable Multi-Factor Authentication (MFA) for <code class="verbatim">ssh</code></p>
<p>This part is optional, but I highly recommend it. So far, we've ensured that no one can log into our user on the server without using our secret key, and we've ensured that no one can log in remotely as <code class="verbatim">root</code>. Next, you can enable MFA authentication for <code class="verbatim">ssh</code> connections.</p>
<p>This process involves editing a couple files and installing an MFA package, so I will not include all the details in this post. To see how to configure MFA for <code class="verbatim">ssh</code>, see my other post: <a href="https://cleberg.net/blog/ssh-mfa.html">Enabling MFA for SSH</a>.</p>
</li>
</ol>
<h3 id="fail2ban"><span class="section-number-3">1.5.</span> <code class="verbatim">fail2ban</code></h3>
<p>I haven't written a post on how I use <code class="verbatim">fail2ban</code>, but it's quite simple. I use the default <code class="verbatim">sshd</code> jail, but you can always create new jails for respective applications or ports. For example, if you use Nginx as your web server, you can use the <code class="verbatim">nginx-http-auth</code> jail.</p>
<p>In order to get it up and running, use the following commands:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> apt install fail2ban</span>
<span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> fail2ban-client start sshd</span>
<span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> fail2ban-client status sshd</span></span></code></pre>
<p>This should be used as a last-resort defense and shouldn't be a replacement for the security measures mentioned above.</p>
<h2 id="switch"><span class="section-number-2">2.</span> Switch</h2>
<p>Between the router and any local devices is my managed switch, which is used to create VLANs. The example below shows how I would isolate the VLANs if I were starting to host a single service at home.</p>
<h3 id="802-1q-vlan-configuration"><span class="section-number-3">2.1.</span> 802.1Q VLAN Configuration</h3>
<p>In this configuration, port 8 is the public server that needs to be accessed from the outside. Port 23 is my 'dedicated service port' for this server. In order to SSH to this server, I need to plug my laptop into port 23 or else I cannot SSH. Otherwise, I'd need to hook up a monitor and keyboard directly to the server to manage it.</p>
<table>
<thead>
<tr><th>VLAN ID</th><th>VLAN Name</th><th>Member Ports</th><th>Tagged Ports</th><th>Untagged Ports</th></tr>
</thead>
<tbody>
<tr><td>1</td><td>Default</td><td>1-24</td><td>1-24</td><td></td></tr>
<tr><td>2</td><td>Server</td><td>1,8,23</td><td>1,8,23</td><td></td></tr>
</tbody>
</table>
<h3 id="802-1q-vlan-pvid-setting"><span class="section-number-3">2.2.</span> 802.1Q VLAN PVID Setting</h3>
<p>Once the VLAN is created, I simply add the <code class="verbatim">VLAN ID</code> of <code class="verbatim">2</code> as the <code class="verbatim">PVID</code> for any related ports (in this case, see that ports <code class="verbatim">8</code> and <code class="verbatim">23</code> have a PVID of <code class="verbatim">2</code>).</p>
<table>
<thead>
<tr><th>Port</th><th>PVID</th></tr>
</thead>
<tbody>
<tr><td>1</td><td>1</td></tr>
<tr><td>2</td><td>1</td></tr>
<tr><td>3</td><td>1</td></tr>
<tr><td>4</td><td>1</td></tr>
<tr><td>5</td><td>1</td></tr>
<tr><td>6</td><td>1</td></tr>
<tr><td>7</td><td>1</td></tr>
<tr><td>8</td><td>2</td></tr>
<tr><td>9</td><td>1</td></tr>
<tr><td>10</td><td>1</td></tr>
<tr><td>11</td><td>1</td></tr>
<tr><td>12</td><td>1</td></tr>
<tr><td>13</td><td>1</td></tr>
<tr><td>14</td><td>1</td></tr>
<tr><td>15</td><td>1</td></tr>
<tr><td>16</td><td>1</td></tr>
<tr><td>17</td><td>1</td></tr>
<tr><td>18</td><td>1</td></tr>
<tr><td>19</td><td>1</td></tr>
<tr><td>20</td><td>1</td></tr>
<tr><td>21</td><td>1</td></tr>
<tr><td>22</td><td>1</td></tr>
<tr><td>23</td><td>2</td></tr>
<tr><td>24</td><td>1</td></tr>
</tbody>
</table>
<h2 id="router"><span class="section-number-2">3.</span> Router</h2>
<p>On my router, the configuration was as easy as opening the firewall settings and unblocking the ports I needed for my services (e.g., HTTP/S, Plex, SSH, MySQL, etc.).</p>
<p>Since I'm relying on an ISP-provided modem/router combo for now (not by choice), I do not use any other advanced settings on my router that would inhibit any valid traffic to these services.</p>
<p>The paragraph above regarding the ISP-owned router is no longer accurate as I now use the Ubiquiti Unifi Dream Machine Pro as my router. Within this router, I enabled port forwarding/firewall rules, segregate the network based on the device, and enable traffic restrictions (e.g., silently drop traffic from certain countries and threat categories).</p>
<p>If you have the option with your ISP, I recommend using a personal router with software that you are familiar with so that you can explore all the options available to you.</p>
<h2 id="physical-security"><span class="section-number-2">4.</span> Physical Security</h2>
<p>One large piece of self-hosting that people generally don't discuss online is physical security. However, physical security is very important for everyone who hosts a server like this. Exactly <em>how</em> important it is depends on the server use/purpose.</p>
<p>If you self-host customer applications that hold protected data, then physical security is extremely important and cannot be ignored. If you simply host a blog and some hobby sites, then it's a relatively minor consideration, but one you still need to think about.</p>
<h3 id="location"><span class="section-number-3">4.1.</span> Location</h3>
<p>The first consideration is quite simple: location.</p>
<ul>
<li>Is the server within a property you own or housed on someone else's property?</li>
<li>Is it nearby (in your house, in your work office, in your neighbor's garage, in a storage unit, etc.)?</li>
<li>Do you have 24/7 access to the server?</li>
<li>Are there climate considerations, such as humidity, fires, tornadoes, monsoons?</li>
<li>Do you have emergency equipment nearby in case of emergency?</li>
</ul>
<h3 id="hardware-ownership"><span class="section-number-3">4.2.</span> Hardware Ownership</h3>
<p>Secondly, consider the hardware itself:</p>
<ul>
<li>Do you own the server in its entirety?</li>
<li>Are any other users able to access the server, even if your data/space is segregated?</li>
<li>If you're utilizing a third party, do they have any documentation to show responsibility? This could be a Service Organization Controls (SOC) 1/2/3 report, International Organization for Standardization (ISO) compliance report, internal security/safety documentation.</li>
</ul>
<h3 id="physical-controls"><span class="section-number-3">4.3.</span> Physical Controls</h3>
<p>Regardless of who owns the hardware, ensure that there are adequate safeguards in place, if necessary. These usually don't apply to small home servers and are usually covered already if you're utilizing a third party.</p>
<p>These can include:</p>
<ul>
<li>Server bezel locks</li>
<li>Server room locks - physical, digital, or biometric authentication</li>
<li>Security cameras</li>
<li>Raised floors/lowered ceilings with proper guards/gates in-place within the floors or ceilings</li>
<li>Security personnel</li>
<li>Log sheets and/or guest badges</li>
</ul>
]]></description>
    </item>
    <item>
      <title>Self-Hosting Guide: Nextcloud</title>
      <link>https://cleberg.net/blog/nextcloud-on-ubuntu.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/nextcloud-on-ubuntu.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Wed, 23 Mar 2022 00:00:00 +0000</pubDate>
      <category>linux</category>
      <category>self-hosting</category>
      <description><![CDATA[<h2 id="what-is-nextcloud"><span class="section-number-2">1.</span> What is Nextcloud?</h2>
<p><a href="https://nextcloud.com/">Nextcloud</a> is a self-hosted solution for storage, communications, editing, calendar, contacts, and more.</p>
<p>This tutorial assumes that you have an Ubuntu server and a domain name configured to point toward the server.</p>
<h2 id="install-dependencies"><span class="section-number-2">2.</span> Install Dependencies</h2>
<p>To start, you will need to install the packages that Nextcloud requires:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> apt install apache2 mariadb-server libapache2-mod-php7.4</span>
<span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> apt install php7.4-gd php7.4-mysql php7.4-curl php7.4-mbstring php7.4-intl</span>
<span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> apt install php7.4-gmp php7.4-bcmath php-imagick php7.4-xml php7.4-zip</span></span></code></pre>
<h2 id="set-up-mysql"><span class="section-number-2">3.</span> Set Up MySQL</h2>
<p>Next, you will need to log in to MySQL as the <code class="verbatim">root</code> user of the machine.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> mysql<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>uroot</span><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>p</span></span></span></code></pre>
<p>Once you've logged in, you must create a new user so that Nextcloud can manage the database. You will also create a <code class="verbatim">nextcloud</code> database and assign privileges:</p>
<pre><code class="language-sql highlight"><span class="source sql"><span class="meta create sql"><span class="keyword other create sql">CREATE</span> <span class="keyword other sql">USER</span> &#39;<span class="entity name function sql">username</span>&#39;</span>@<span class="string quoted single sql"><span class="punctuation definition string begin sql">&#39;</span>localhost<span class="punctuation definition string end sql">&#39;</span></span> IDENTIFIED BY <span class="string quoted single sql"><span class="punctuation definition string begin sql">&#39;</span>password<span class="punctuation definition string end sql">&#39;</span></span>;
<span class="meta create sql"><span class="keyword other create sql">CREATE</span> <span class="keyword other sql">DATABASE</span> <span class="entity name function sql">IF</span></span> NOT EXISTS nextcloud CHARACTER <span class="keyword other DML sql">SET</span> utf8mb4 COLLATE utf8mb4_general_ci;
<span class="keyword other authorization sql">GRANT</span> ALL PRIVILEGES <span class="keyword other DDL create II sql">ON</span> nextcloud.<span class="keyword operator star sql">*</span><span class="keyword operator star sql">*</span> TO <span class="string quoted single sql"><span class="punctuation definition string begin sql">&#39;</span>username<span class="punctuation definition string end sql">&#39;</span></span>@<span class="string quoted single sql"><span class="punctuation definition string begin sql">&#39;</span>localhost<span class="punctuation definition string end sql">&#39;</span></span>;
FLUSH PRIVILEGES;
quit;</span></code></pre>
<h2 id="download-install-nextcloud"><span class="section-number-2">4.</span> Download &amp; Install Nextcloud</h2>
<p>To download Nextcloud, go the <a href="https://nextcloud.com/install/#instructions-server">Nextcloud downloads page</a>, click on <code class="verbatim">Archive File</code> and right-click the big blue button to copy the link.</p>
<p>Then, go to your server and enter the following commands to download, unzip, and move the files to your destination directory. This example uses <code class="verbatim">example.com</code> as the destination, but you can put it wherever you want to server your files from.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">wget</span></span><span class="meta function-call arguments shell"> https://download.nextcloud.com/server/releases/nextcloud-23.0.3.zip</span>
<span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> apt install unzip</span>
<span class="meta function-call shell"><span class="variable function shell">unzip</span></span><span class="meta function-call arguments shell"> nextcloud-23.0.3.zip</span>
<span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> cp<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>r</span> nextcloud /var/www/example.com</span></span></code></pre>
<h2 id="configure-the-apache-web-server"><span class="section-number-2">5.</span> Configure the Apache Web Server</h2>
<p>Now that the database is set up and Nextcloud is installed, you need to set up the Apache configuration files to tell the server how to handle requests for <code class="verbatim">example.com/nextcloud</code>.</p>
<p>First, open the following file in the editor:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> nano /etc/apache2/sites-available/nextcloud.conf</span></span></code></pre>
<p>Once the editor is open, paste the following information in. Then, save and close the file.</p>
<pre><code class="language-config">&lt;VirtualHost *:80&gt;
    DocumentRoot /var/www/example.com
    ServerName  example.com
    ServerAlias www.example.com
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    &lt;Directory /var/www/example.com/nextcloud/&gt;
        Require all granted
        AllowOverride All
        Options FollowSymLinks MultiViews
        Satisfy Any

        &lt;IfModule mod_dav.c&gt;
            Dav off
        &lt;/IfModule&gt;
    &lt;/Directory&gt;
&lt;/VirtualHost&gt;</code></pre>
<p>Once the file is saved, enable it with Apache:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> a2ensite nextcloud.conf</span></span></code></pre>
<p>Next, enable the Apache modules required by Nextcloud:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> a2enmod rewrite headers env dir mime</span></span></code></pre>
<p>Finally, restart Apache. If any errors arise, you must solve those before continuing.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> systemctl restart apache2</span></span></code></pre>
<p>For the app to work, you must have the correct file permissions on your <code class="verbatim">nextcloud</code> directory. Set the owner to be <code class="verbatim">www-data</code>:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> chown<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>R</span> www-data:www-data /var/www/example.com/nextcloud/</span></span></code></pre>
<h2 id="dns"><span class="section-number-2">6.</span> DNS</h2>
<p>If you do not have a static internet protocol (IP) address, you will need to update your DNS (Domain Name System) settings (at your DNS provider) whenever your dynamic IP address changes.</p>
<p>For an example on how I do that with Cloudflare, see my other post: <a href="https://cleberg.net/blog/cloudflare-dns-api.html">Dynamic DNS Record Updates via Cloudflare API</a>.</p>
<h2 id="certbot"><span class="section-number-2">7.</span> Certbot</h2>
<p>If you want to serve Nextcloud from HTTPS (Hypertext Transfer Protocol Secure) rather than plain HTTP (Hypertext Transfer Protocol), use the following commands to issue Let's Encrypt SSL (Secure Socket Layer) certificates:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> apt install snapd</span>
<span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> snap install core</span>
<span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> snap refresh core</span>
<span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> snap install<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> --</span>classic</span> certbot</span>
<span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> ln<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>s</span> /snap/bin/certbot /usr/bin/certbot</span>
<span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> certbot<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> --</span>apache</span></span></span></code></pre>
<h2 id="results"><span class="section-number-2">8.</span> Results</h2>
<p>Voilà! You're all done and should be able to access Nextcloud from your domain or IP address.</p>
]]></description>
    </item>
    <item>
      <title>Dynamic DNS Updates via the Cloudflare API</title>
      <link>https://cleberg.net/blog/cloudflare-dns-api.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/cloudflare-dns-api.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Wed, 23 Mar 2022 00:00:00 +0000</pubDate>
      <category>security</category>
      <description><![CDATA[<h2 id="ddns-dynamic-dns"><span class="section-number-2">1.</span> DDNS: Dynamic DNS</h2>
<p>If you're hosting a service from a location with DDNS (Dynamic Domain Name System), where your internet protocol (IP)address may change at any time, you must have a solution to update the DNS (Domain Name System) so that you can access your service even when the IP of the server changes.</p>
<p>The process below uses the <a href="https://api.cloudflare.com/">Cloudflare API</a> (application programming interface) to update DNS <code class="verbatim">A</code> and <code class="verbatim">AAAA</code> records with the server's current IP. If you use another DNS provider, you will have to find a way to update your DNS (or find a way to get a static IP).</p>
<p>First, install <code class="verbatim">jq</code> since we will use it in the next script:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> apt install jq</span></span></code></pre>
<p>Next, create a location for your DDNS update scripts and open the first script:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">mkdir</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/ddns</span>
<span class="meta function-call shell"><span class="variable function shell">nano</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/ddns/update.sh</span></span></code></pre>
<p>The following <code class="verbatim">update.sh</code> script will take all of your domains and subdomains and check Cloudflare to see if the current <code class="verbatim">A</code> and <code class="verbatim">AAAA</code> records match your server's IP address. If not, it will update the records.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> file: update.sh</span><span class="comment line number-sign shell">
</span><span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell">!/bin/bash</span><span class="comment line number-sign shell">
</span>
<span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> Update TLDs</span><span class="comment line number-sign shell">
</span><span class="variable other readwrite assignment shell">domains</span><span class="keyword operator assignment shell">=</span><span class="punctuation section parens begin shell">(</span>example.com example.net<span class="punctuation section parens end shell">)</span>

<span class="keyword control for shell">for</span><span class="meta group for shell"> domain <span class="keyword control in shell">in</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section expansion parameter begin shell">{</span></span><span class="meta group expansion parameter shell"><span class="variable other readwrite shell">domains<span class="punctuation section braces begin shell">[</span><span class="variable language array shell">@</span><span class="punctuation section braces end shell">]</span></span></span><span class="meta group expansion parameter shell"><span class="punctuation section expansion parameter end shell">}</span></span><span class="punctuation definition string end shell">&quot;</span></span></span>
<span class="keyword control do shell">do</span>
  <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="variable parameter option shell"><span class="punctuation definition parameter shell">-</span>e</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>\nUpdating <span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">domain</span></span>...<span class="punctuation definition string end shell">&quot;</span></span></span>
  <span class="variable other readwrite assignment shell">zone_name</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell"><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">domain</span></span></span> <span class="meta function-call shell"><span class="variable function shell">/home/</span></span><span class="meta function-call arguments shell"><span class="keyword operator assignment redirection shell">&lt;</span>your-username<span class="keyword operator assignment redirection shell">&gt;</span>/ddns/ddns.sh</span>
<span class="keyword control done shell">done</span>

<span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> Update subdomains for example.com</span><span class="comment line number-sign shell">
</span><span class="variable other readwrite assignment shell">domain</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell">example.com</span>
<span class="variable other readwrite assignment shell">subdomains</span><span class="keyword operator assignment shell">=</span><span class="punctuation section parens begin shell">(</span>photos.example.com<span class="punctuation section parens end shell">)</span>

<span class="keyword control for shell">for</span><span class="meta group for shell"> subdomain <span class="keyword control in shell">in</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section expansion parameter begin shell">{</span></span><span class="meta group expansion parameter shell"><span class="variable other readwrite shell">subdomains<span class="punctuation section braces begin shell">[</span><span class="variable language array shell">@</span><span class="punctuation section braces end shell">]</span></span></span><span class="meta group expansion parameter shell"><span class="punctuation section expansion parameter end shell">}</span></span><span class="punctuation definition string end shell">&quot;</span></span></span>
<span class="keyword control do shell">do</span>
  <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="variable parameter option shell"><span class="punctuation definition parameter shell">-</span>e</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>\nUpdating <span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">subdomain</span></span>...<span class="punctuation definition string end shell">&quot;</span></span></span>
  <span class="variable other readwrite assignment shell">zone_name</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell"><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">domain</span></span></span>  <span class="variable other readwrite assignment shell">dns_record</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell"><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">subdomain</span></span></span> <span class="meta function-call shell"><span class="variable function shell">/home/</span></span><span class="meta function-call arguments shell"><span class="keyword operator assignment redirection shell">&lt;</span>your-username<span class="keyword operator assignment redirection shell">&gt;</span>/ddns/ddns.sh</span>
<span class="meta function-call shell"><span class="variable function shell">done</span></span></span></code></pre>
<p>Next, open up the <code class="verbatim">ddns.sh</code> script. Paste the following into the script and update the <code class="verbatim">api_token</code> and <code class="verbatim">email</code> variables.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">nano</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/ddns/ddns.sh</span></span></code></pre>
<p><strong>Note</strong>: If you want your DNS records to be proxied through Cloudflare, find and update the following snippet: <code class="verbatim">"proxied":false}"</code> to say <code class="verbatim">true</code> instead of <code class="verbatim">false</code>.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> file: ddns.sh</span><span class="comment line number-sign shell">
</span><span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell">!/bin/bash</span><span class="comment line number-sign shell">
</span><span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> based on https://gist.github.com/Tras2/cba88201b17d765ec065ccbedfb16d9a</span><span class="comment line number-sign shell">
</span><span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> initial data; they need to be filled by the user</span><span class="comment line number-sign shell">
</span><span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"># API token</span><span class="comment line number-sign shell">
</span><span class="variable other readwrite assignment shell">api_token</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell">&lt;YOUR_API_TOKEN&gt;</span>
<span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"># email address associated with the Cloudflare account</span><span class="comment line number-sign shell">
</span><span class="variable other readwrite assignment shell">email</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell">&lt;YOUR_EMAIL&gt;</span>

<span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> get the basic data</span><span class="comment line number-sign shell">
</span><span class="variable other readwrite assignment shell">ipv4</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell"><span class="meta group expansion command parens shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section parens begin shell">(</span><span class="meta function-call shell"><span class="variable function shell">curl</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>s</span><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>X</span> GET<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>4</span> https://ifconfig.co</span><span class="punctuation section parens end shell">)</span></span></span>
<span class="variable other readwrite assignment shell">ipv6</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell"><span class="meta group expansion command parens shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section parens begin shell">(</span><span class="meta function-call shell"><span class="variable function shell">curl</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>s</span><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>X</span> GET<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>6</span> https://ifconfig.co</span><span class="punctuation section parens end shell">)</span></span></span>
<span class="variable other readwrite assignment shell">user_id</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell"><span class="meta group expansion command parens shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section parens begin shell">(</span><span class="meta function-call shell"><span class="variable function shell">curl</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>s</span><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>X</span> GET <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>https://api.cloudflare.com/client/v4/user/tokens/verify<span class="punctuation definition string end shell">&quot;</span></span> <span class="punctuation separator continuation line shell">\
</span><span class="variable parameter option shell"><span class="punctuation definition parameter shell">               -</span>H</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>Authorization: Bearer <span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">api_token</span></span><span class="punctuation definition string end shell">&quot;</span></span> <span class="punctuation separator continuation line shell">\
</span><span class="variable parameter option shell"><span class="punctuation definition parameter shell">               -</span>H</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>Content-Type:application/json<span class="punctuation definition string end shell">&quot;</span></span> <span class="punctuation separator continuation line shell">\
</span></span>          <span class="keyword operator logical pipe shell">|</span> <span class="meta function-call shell"><span class="variable function shell">jq</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>r</span> <span class="string quoted single shell"><span class="punctuation definition string begin shell">&#39;</span>{&quot;result&quot;}[] | .id<span class="punctuation definition string end shell">&#39;</span></span></span>
         <span class="punctuation section parens end shell">)</span></span></span>

<span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>Your IPv4 is: <span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">ipv4</span></span><span class="punctuation definition string end shell">&quot;</span></span></span>
<span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>Your IPv6 is: <span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">ipv6</span></span><span class="punctuation definition string end shell">&quot;</span></span></span>

<span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> check if the user API is valid and the email is correct</span><span class="comment line number-sign shell">
</span><span class="keyword control if begin shell">if</span> <span class="support function test begin shell">[</span><span class="meta function-call arguments shell"> <span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">user_id</span></span> <span class="support function test end shell">]</span></span>
<span class="keyword control if then shell">then</span>
    <span class="variable other readwrite assignment shell">zone_id</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell"><span class="meta group expansion command parens shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section parens begin shell">(</span><span class="meta function-call shell"><span class="variable function shell">curl</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>s</span><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>X</span> GET <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>https://api.cloudflare.com/client/v4/zones?name=<span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">zone_name</span></span>&amp;status=active<span class="punctuation definition string end shell">&quot;</span></span> <span class="punctuation separator continuation line shell">\
</span><span class="variable parameter option shell"><span class="punctuation definition parameter shell">                   -</span>H</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>Content-Type: application/json<span class="punctuation definition string end shell">&quot;</span></span> <span class="punctuation separator continuation line shell">\
</span><span class="variable parameter option shell"><span class="punctuation definition parameter shell">                   -</span>H</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>X-Auth-Email: <span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">email</span></span><span class="punctuation definition string end shell">&quot;</span></span> <span class="punctuation separator continuation line shell">\
</span><span class="variable parameter option shell"><span class="punctuation definition parameter shell">                   -</span>H</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>Authorization: Bearer <span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">api_token</span></span><span class="punctuation definition string end shell">&quot;</span></span> <span class="punctuation separator continuation line shell">\
</span></span>              <span class="keyword operator logical pipe shell">|</span> <span class="meta function-call shell"><span class="variable function shell">jq</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>r</span> <span class="string quoted single shell"><span class="punctuation definition string begin shell">&#39;</span>{&quot;result&quot;}[] | .[0] | .id<span class="punctuation definition string end shell">&#39;</span></span></span>
             <span class="punctuation section parens end shell">)</span></span></span>
    <span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> check if the zone ID is</span><span class="comment line number-sign shell">
</span>    <span class="keyword control if begin shell">if</span> <span class="support function test begin shell">[</span><span class="meta function-call arguments shell"> <span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">zone_id</span></span> <span class="support function test end shell">]</span></span>
    <span class="keyword control if then shell">then</span>
        <span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> check if there is any IP version 4</span><span class="comment line number-sign shell">
</span>        <span class="keyword control if begin shell">if</span> <span class="support function test begin shell">[</span><span class="meta function-call arguments shell"> <span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">ipv4</span></span> <span class="support function test end shell">]</span></span>
        <span class="keyword control if then shell">then</span>
            <span class="variable other readwrite assignment shell">dns_record_a_id</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell"><span class="meta group expansion command parens shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section parens begin shell">(</span><span class="meta function-call shell"><span class="variable function shell">curl</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>s</span><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>X</span> GET <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>https://api.cloudflare.com/client/v4/zones/<span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">zone_id</span></span>/dns_records?type=A&amp;name=<span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">dns_record</span></span><span class="punctuation definition string end shell">&quot;</span></span>  <span class="punctuation separator continuation line shell">\
</span><span class="variable parameter option shell"><span class="punctuation definition parameter shell">                                   -</span>H</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>Content-Type: application/json<span class="punctuation definition string end shell">&quot;</span></span> <span class="punctuation separator continuation line shell">\
</span><span class="variable parameter option shell"><span class="punctuation definition parameter shell">                                   -</span>H</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>X-Auth-Email: <span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">email</span></span><span class="punctuation definition string end shell">&quot;</span></span> <span class="punctuation separator continuation line shell">\
</span><span class="variable parameter option shell"><span class="punctuation definition parameter shell">                                   -</span>H</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>Authorization: Bearer <span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">api_token</span></span><span class="punctuation definition string end shell">&quot;</span></span></span>
                             <span class="punctuation section parens end shell">)</span></span></span>
            <span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> if the IPv6 exist</span><span class="comment line number-sign shell">
</span>            <span class="variable other readwrite assignment shell">dns_record_a_ip</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell"><span class="meta group expansion command parens shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section parens begin shell">(</span><span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">dns_record_a_id</span></span></span> <span class="keyword operator logical pipe shell">|</span>  <span class="meta function-call shell"><span class="variable function shell">jq</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>r</span> <span class="string quoted single shell"><span class="punctuation definition string begin shell">&#39;</span>{&quot;result&quot;}[] | .[0] | .content<span class="punctuation definition string end shell">&#39;</span></span></span><span class="punctuation section parens end shell">)</span></span></span>
            <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>The set IPv4 on Cloudflare (A Record) is:    <span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">dns_record_a_ip</span></span><span class="punctuation definition string end shell">&quot;</span></span></span>
            <span class="keyword control if begin shell">if</span> <span class="support function test begin shell">[</span><span class="meta function-call arguments shell"> <span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">dns_record_a_ip</span></span> <span class="keyword operator logical shell">!=</span> <span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">ipv4</span></span> <span class="support function test end shell">]</span></span>
            <span class="keyword control if then shell">then</span>
                <span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> change the A record</span><span class="comment line number-sign shell">
</span>                <span class="meta function-call shell"><span class="variable function shell">curl</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>s</span><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>X</span> PUT <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>https://api.cloudflare.com/client/v4/zones/<span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">zone_id</span></span>/dns_records/<span class="meta group expansion command parens shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section parens begin shell">(</span><span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">dns_record_a_id</span></span></span> <span class="keyword operator logical pipe shell">|</span> <span class="meta function-call shell"><span class="variable function shell">jq</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>r</span> <span class="string quoted single shell"><span class="punctuation definition string begin shell">&#39;</span>{&quot;result&quot;}[] | .[0] | .id<span class="punctuation definition string end shell">&#39;</span></span></span><span class="punctuation section parens end shell">)</span></span><span class="punctuation definition string end shell">&quot;</span></span> <span class="punctuation separator continuation line shell">\
</span><span class="variable parameter option shell"><span class="punctuation definition parameter shell">                     -</span>H</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>Content-Type: application/json<span class="punctuation definition string end shell">&quot;</span></span> <span class="punctuation separator continuation line shell">\
</span><span class="variable parameter option shell"><span class="punctuation definition parameter shell">                     -</span>H</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>X-Auth-Email: <span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">email</span></span><span class="punctuation definition string end shell">&quot;</span></span> <span class="punctuation separator continuation line shell">\
</span><span class="variable parameter option shell"><span class="punctuation definition parameter shell">                     -</span>H</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>Authorization: Bearer <span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">api_token</span></span><span class="punctuation definition string end shell">&quot;</span></span> <span class="punctuation separator continuation line shell">\
</span><span class="variable parameter option shell"><span class="punctuation definition parameter shell">                     --</span>data</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>{<span class="punctuation definition string end shell">&quot;</span></span>type<span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>:<span class="punctuation definition string end shell">&quot;</span></span>A<span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>,<span class="punctuation definition string end shell">&quot;</span></span>name<span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>:<span class="punctuation definition string end shell">&quot;</span></span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">dns_record</span></span><span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>,<span class="punctuation definition string end shell">&quot;</span></span>content<span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>:<span class="punctuation definition string end shell">&quot;</span></span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">ipv4</span></span><span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>,<span class="punctuation definition string end shell">&quot;</span></span>ttl<span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>:1,<span class="punctuation definition string end shell">&quot;</span></span>proxied<span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>:false}<span class="punctuation definition string end shell">&quot;</span></span> <span class="punctuation separator continuation line shell">\
</span></span>                <span class="keyword operator logical pipe shell">|</span> <span class="meta function-call shell"><span class="variable function shell">jq</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>r</span> <span class="string quoted single shell"><span class="punctuation definition string begin shell">&#39;</span>.errors<span class="punctuation definition string end shell">&#39;</span></span></span>
            <span class="keyword control if else shell">else</span>
                <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>The current IPv4 and DNS record IPv4 are the same.<span class="punctuation definition string end shell">&quot;</span></span></span>
            <span class="keyword control if end shell">fi</span>
        <span class="keyword control if else shell">else</span>
            <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>Could not get your IPv4. Check if you have it; e.g. on https://ifconfig.co<span class="punctuation definition string end shell">&quot;</span></span></span>
        <span class="keyword control if end shell">fi</span>

        <span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> check if there is any IP version 6</span><span class="comment line number-sign shell">
</span>        <span class="keyword control if begin shell">if</span> <span class="support function test begin shell">[</span><span class="meta function-call arguments shell"> <span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">ipv6</span></span> <span class="support function test end shell">]</span></span>
        <span class="keyword control if then shell">then</span>
            <span class="variable other readwrite assignment shell">dns_record_aaaa_id</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell"><span class="meta group expansion command parens shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section parens begin shell">(</span><span class="meta function-call shell"><span class="variable function shell">curl</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>s</span><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>X</span> GET <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>https://api.cloudflare.com/client/v4/zones/<span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">zone_id</span></span>/dns_records?type=AAAA&amp;name=<span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">dns_record</span></span><span class="punctuation definition string end shell">&quot;</span></span>  <span class="punctuation separator continuation line shell">\
</span><span class="variable parameter option shell"><span class="punctuation definition parameter shell">                                      -</span>H</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>Content-Type: application/json<span class="punctuation definition string end shell">&quot;</span></span> <span class="punctuation separator continuation line shell">\
</span><span class="variable parameter option shell"><span class="punctuation definition parameter shell">                                      -</span>H</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>X-Auth-Email: <span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">email</span></span><span class="punctuation definition string end shell">&quot;</span></span> <span class="punctuation separator continuation line shell">\
</span><span class="variable parameter option shell"><span class="punctuation definition parameter shell">                                      -</span>H</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>Authorization: Bearer <span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">api_token</span></span><span class="punctuation definition string end shell">&quot;</span></span></span>
                                <span class="punctuation section parens end shell">)</span></span></span>
            <span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> if the IPv6 exist</span><span class="comment line number-sign shell">
</span>            <span class="variable other readwrite assignment shell">dns_record_aaaa_ip</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell"><span class="meta group expansion command parens shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section parens begin shell">(</span><span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">dns_record_aaaa_id</span></span></span> <span class="keyword operator logical pipe shell">|</span> <span class="meta function-call shell"><span class="variable function shell">jq</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>r</span> <span class="string quoted single shell"><span class="punctuation definition string begin shell">&#39;</span>{&quot;result&quot;}[] | .[0] | .content<span class="punctuation definition string end shell">&#39;</span></span></span><span class="punctuation section parens end shell">)</span></span></span>
            <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>The set IPv6 on Cloudflare (AAAA Record) is: <span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">dns_record_aaaa_ip</span></span><span class="punctuation definition string end shell">&quot;</span></span></span>
            <span class="keyword control if begin shell">if</span> <span class="support function test begin shell">[</span><span class="meta function-call arguments shell"> <span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">dns_record_aaaa_ip</span></span> <span class="keyword operator logical shell">!=</span> <span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">ipv6</span></span> <span class="support function test end shell">]</span></span>
            <span class="keyword control if then shell">then</span>
                <span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> change the AAAA record</span><span class="comment line number-sign shell">
</span>                <span class="meta function-call shell"><span class="variable function shell">curl</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>s</span><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>X</span> PUT <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>https://api.cloudflare.com/client/v4/zones/<span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">zone_id</span></span>/dns_records/<span class="meta group expansion command parens shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section parens begin shell">(</span><span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">dns_record_aaaa_id</span></span></span> <span class="keyword operator logical pipe shell">|</span> <span class="meta function-call shell"><span class="variable function shell">jq</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>r</span> <span class="string quoted single shell"><span class="punctuation definition string begin shell">&#39;</span>{&quot;result&quot;}[] | .[0] | .id<span class="punctuation definition string end shell">&#39;</span></span></span><span class="punctuation section parens end shell">)</span></span><span class="punctuation definition string end shell">&quot;</span></span> <span class="punctuation separator continuation line shell">\
</span><span class="variable parameter option shell"><span class="punctuation definition parameter shell">                     -</span>H</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>Content-Type: application/json<span class="punctuation definition string end shell">&quot;</span></span> <span class="punctuation separator continuation line shell">\
</span><span class="variable parameter option shell"><span class="punctuation definition parameter shell">                     -</span>H</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>X-Auth-Email: <span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">email</span></span><span class="punctuation definition string end shell">&quot;</span></span> <span class="punctuation separator continuation line shell">\
</span><span class="variable parameter option shell"><span class="punctuation definition parameter shell">                     -</span>H</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>Authorization: Bearer <span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">api_token</span></span><span class="punctuation definition string end shell">&quot;</span></span> <span class="punctuation separator continuation line shell">\
</span><span class="variable parameter option shell"><span class="punctuation definition parameter shell">                     --</span>data</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>{<span class="punctuation definition string end shell">&quot;</span></span>type<span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>:<span class="punctuation definition string end shell">&quot;</span></span>AAAA<span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>,<span class="punctuation definition string end shell">&quot;</span></span>name<span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>:<span class="punctuation definition string end shell">&quot;</span></span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">dns_record</span></span><span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>,<span class="punctuation definition string end shell">&quot;</span></span>content<span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>:<span class="punctuation definition string end shell">&quot;</span></span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">ipv6</span></span><span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>,<span class="punctuation definition string end shell">&quot;</span></span>ttl<span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>:1,<span class="punctuation definition string end shell">&quot;</span></span>proxied<span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>:false}<span class="punctuation definition string end shell">&quot;</span></span> <span class="punctuation separator continuation line shell">\
</span></span>                <span class="keyword operator logical pipe shell">|</span> <span class="meta function-call shell"><span class="variable function shell">jq</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>r</span> <span class="string quoted single shell"><span class="punctuation definition string begin shell">&#39;</span>.errors<span class="punctuation definition string end shell">&#39;</span></span></span>
            <span class="keyword control if else shell">else</span>
                <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>The current IPv6 and DNS record IPv6 are the same.<span class="punctuation definition string end shell">&quot;</span></span></span>
            <span class="keyword control if end shell">fi</span>
        <span class="keyword control if else shell">else</span>
            <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>Could not get your IPv6. Check if you have it; e.g. on https://ifconfig.co<span class="punctuation definition string end shell">&quot;</span></span></span>
        <span class="keyword control if end shell">fi</span>
    <span class="keyword control if else shell">else</span>
        <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>There is a problem with getting the Zone ID. Check if the Zone Name is correct.<span class="punctuation definition string end shell">&quot;</span></span></span>
    <span class="keyword control if end shell">fi</span>
<span class="keyword control if else shell">else</span>
    <span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>There is a problem with either the email or the password<span class="punctuation definition string end shell">&quot;</span></span></span>
<span class="meta function-call shell"><span class="variable function shell">fi</span></span></span></code></pre>
<p>Once the script is saved and closed, make the scripts executable:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">chmod</span></span><span class="meta function-call arguments shell"> +x <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/ddns/ddns.sh</span>
<span class="meta function-call shell"><span class="variable function shell">chmod</span></span><span class="meta function-call arguments shell"> +x <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/ddns/update.sh</span></span></code></pre>
<p>You can test the script by running it manually:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">./update.sh</span></span></span></code></pre>
<p>To make sure the scripts run automatically, add it to the <code class="verbatim">cron</code> file so that it will run on a schedule. To do this, open the cron file:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">crontab</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>e</span></span></span></code></pre>
<p>In the <code class="verbatim">cron</code> file, paste the following at the bottom of the editor:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">*/5</span></span><span class="meta function-call arguments shell"> <span class="keyword operator regexp quantifier shell">*</span><span class="keyword operator regexp quantifier shell">*</span> <span class="keyword operator regexp quantifier shell">*</span><span class="keyword operator regexp quantifier shell">*</span> <span class="keyword operator regexp quantifier shell">*</span><span class="keyword operator regexp quantifier shell">*</span> <span class="keyword operator regexp quantifier shell">*</span><span class="keyword operator regexp quantifier shell">*</span> bash /home/<span class="keyword operator assignment redirection shell">&lt;</span>your_username<span class="keyword operator assignment redirection shell">&gt;</span>/ddns/update.sh</span></span></code></pre>
]]></description>
    </item>
    <item>
      <title>Migrating Plex to New Hardware with Nvidia GPU</title>
      <link>https://cleberg.net/blog/plex-migration.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/plex-migration.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Tue, 08 Mar 2022 00:00:00 +0000</pubDate>
      <category>self-hosting</category>
      <description><![CDATA[<h2 id="migration-phases"><span class="section-number-2">1.</span> Migration Phases</h2>
<p>I recently decided to migrate my server from an old OptiPlex desktop machine to a custom-built tower with better hardware in every category. In order to do this, I would need to properly migrate a full Plex installation.</p>
<p>The second part of this migration is that the new server uses an Nvidia GPU (graphics processing unit) and does not have any integrated graphics, which requires extra work for installation, but provides much better hardware transcoding options for Plex.</p>
<p>Therefore, I have broken this migration down into three phases:</p>
<ol>
<li>Configure the New Server</li>
<li>Migrate Plex Data &amp; Devices</li>
<li>Configure GPU Transcoding</li>
</ol>
<h2 id="phase-1-configure-the-new-server"><span class="section-number-2">2.</span> Phase 1: Configure the New Server</h2>
<h3 id="choosing-an-operating-system-os"><span class="section-number-3">2.1.</span> Choosing an Operating System (OS)</h3>
<p>In order to migrate Plex to my new server, I first needed to choose an appropriate OS and install it on the machine. Given that I have encountered numerous issues installing other Linux distributions properly with Nvidia graphics, I chose <a href="https://ubuntu.com/download/server">Ubuntu Server</a>.</p>
<p>The first step is to create a bootable USB (universal serial bus) with Ubuntu Server. This is easy with <a href="https://www.balena.io/etcher/">Etcher</a>, an app that runs on many different platforms. Just download the Ubuntu Server <code class="verbatim">.iso</code> image, launch Etcher, and install the <code class="verbatim">.iso</code> on the USB.</p>
<p>Once the USB is created, insert it into my server, reboot, and click <code class="verbatim">Esc</code> (or any of the <code class="verbatim">F1-12</code> keys) until the BIOS (Basic Input/Output System) menu appears. Finally, launch the USB boot drive.</p>
<h3 id="booting-with-nvidia"><span class="section-number-3">2.2.</span> Booting with Nvidia</h3>
<p>In order to install Ubuntu Server with an Nvidia Graphics card (and no integrated graphics on this device for some reason), you'll have to configure the boot menu to allow different graphics drivers to be loaded.</p>
<p>When booting from the USB, the machine will launch the initial installation menu. From this menu, type <code class="verbatim">e</code> to view the default command options that come with the device - it's a good idea to take a photo of this screen, so you can enter these commands on the next screen (along with adding support for Nvidia).</p>
<p>Finally, type <code class="verbatim">Ctrl + C</code> to enter the command line. From this command line, enter the commands found on the <code class="verbatim">e</code> screen. Remember to add <code class="verbatim">nomodeset</code> to the <code class="verbatim">linux ...</code> line so that your Nvidia device will display the installation screens properly!</p>
<p>Here's an example of the commands I pulled from the <code class="verbatim">e</code> screen and entered on the command line.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">setparams</span></span><span class="meta function-call arguments shell"> <span class="string quoted single shell"><span class="punctuation definition string begin shell">&#39;</span>Install Ubuntu Server<span class="punctuation definition string end shell">&#39;</span></span></span>
<span class="variable other readwrite assignment shell">setgfxpayload</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell">keep</span>
<span class="meta function-call shell"><span class="variable function shell">linux</span></span><span class="meta function-call arguments shell"> /casper/vmlinuz quiet nomodeset ---</span>
<span class="meta function-call shell"><span class="variable function shell">initrd</span></span><span class="meta function-call arguments shell"> /casper/initrd</span>
<span class="meta function-call shell"><span class="variable function shell">boot</span></span></span></code></pre>
<p>Once the machine is rebooted, enter the <code class="verbatim">e</code> screen again and add <code class="verbatim">nomodeset</code> to the <code class="verbatim">linux ...</code> line again and press <code class="verbatim">Ctrl + X</code> to save the boot options.</p>
<p>The machine is now fully installed and can properly display on an external display using the Nvidia GPU.</p>
<p>Always remember to update and upgrade on a new installation:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> apt update</span><span class="keyword operator logical continue shell">;</span> <span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> apt upgrade<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>y</span></span><span class="keyword operator logical continue shell">;</span> <span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> apt autoremove<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>y</span></span></span></code></pre>
<h2 id="phase-2-migrate-plex-data-devices"><span class="section-number-2">3.</span> Phase 2: Migrate Plex Data &amp; Devices</h2>
<p>This phase uses the great Plex article on migrations (<a href="https://support.plex.tv/articles/201370363-move-an-install-to-another-system/">Move an Installation to Another System</a>) and adds a bit more information to help with commands and context.</p>
<h3 id="terminology"><span class="section-number-3">3.1.</span> Terminology</h3>
<ul>
<li><strong>Source:</strong> The original server that is being replaced.</li>
<li><strong>Destination:</strong> The new server.</li>
<li><strong>Client:</strong> Any application that can be used to modify settings for both source/destination.</li>
</ul>
<h3 id="step-01-client-update-settings"><span class="section-number-3">3.2.</span> Step 01: [Client] Update Settings</h3>
<p>Open up a Plex app and <em>disable</em> the <code class="verbatim">Account</code> &gt; <code class="verbatim">Library</code> &gt; <code class="verbatim">Empty trash automatically after every scan</code> preference for the source server.</p>
<h3 id="step-02-destination-install-plex"><span class="section-number-3">3.3.</span> Step 02: [Destination] Install Plex</h3>
<p>Open up the <a href="https://www.plex.tv/media-server-downloads/">Plex Media Server download page</a> and copy the link for the appropriate platform.</p>
<p>Execute the following commands on the destination server to install Plex:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">wget</span></span><span class="meta function-call arguments shell"> <span class="keyword operator assignment redirection shell">&lt;</span>url<span class="keyword operator assignment redirection shell">&gt;</span>
</span><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> dpkg<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>i</span> <span class="keyword operator assignment redirection shell">&lt;</span>filename<span class="keyword operator assignment redirection shell">&gt;</span>
</span><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> systemctl stop plexmediaserver.service</span></span></code></pre>
<h3 id="step-03-source-stop-plex-migrate-data"><span class="section-number-3">3.4.</span> Step 03: [Source] Stop Plex &amp; Migrate Data</h3>
<p>First, stop the Plex service so that no data is created or modified during the migration.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> systemctl stop plexmediaserver.service</span></span></code></pre>
<p>Next, copy the data to the new server. To find where the Plex data directory is located, Plex has another excellent article available: <a href="https://support.plex.tv/articles/202915258-where-is-the-plex-media-server-data-directory-located/">Where is the Plex Media Server data directory located?</a>.</p>
<p>There are many ways to copy the data to the new server and will largely depend on the size of the folder being copied. Personally, my data folder was ~23GB and I opted to simply use the <code class="verbatim">scp</code> command to copy the files over SSH (Secure Shell Protocol).</p>
<p>This process was throttled by the old server's slow hard disk and ports and took approximately 90 minutes to complete. In comparison, moving the data from the new server's <code class="verbatim">home/user/</code> directory to the <code class="verbatim">/var/.../Plex Media Server</code> directory took 2-3 minutes.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">scp</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>r</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>/var/lib/plexmediaserver/Library/Application Support/Plex Media Server<span class="punctuation definition string end shell">&quot;</span></span> your_user@xxx.xxx.xxx.xxx:<span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>&#39;/path/to/destination/&#39;<span class="punctuation definition string end shell">&quot;</span></span></span></span></code></pre>
<h3 id="step-04-destination-update-file-permissions"><span class="section-number-3">3.5.</span> Step 04: [Destination] Update File Permissions</h3>
<p>In case you move the data directory to a common area on the new server, it will have to be moved to the proper location before Plex can function properly:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">mv</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>Plex Media Server<span class="punctuation definition string end shell">&quot;</span></span> /var/lib/plexmediaserver/Library/Application Support/</span></span></code></pre>
<p>To ensure permissions were retained properly, the server will need to show that all files and folders in the data directory are owned by <code class="verbatim">plex:plex</code> (or whichever user is running the Plex application).</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> chown<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>R</span> plex:plex <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>/var/lib/plexmediaserver/Library/Application Support/Plex Media Server<span class="punctuation definition string end shell">&quot;</span></span></span></span></code></pre>
<p>Finally, start the service and check the status.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> systemctl start plexmediaserver.service</span>
<span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> systemctl status plexmediaserver.service</span></span></code></pre>
<h3 id="step-05-client-update-libraries-metadata"><span class="section-number-3">3.6.</span> Step 05: [Client] Update Libraries &amp; Metadata</h3>
<p>The first step - now that the new server is up and running - is to sign out of the client and sign back in. Once this is done, update any library locations, if necessary. This was unnecessary in my case since I simply moved my storage drives from the source server to the destination server.</p>
<p>Next, perform the following actions in the client:</p>
<ol>
<li>On the left sidebar, click <code class="verbatim">More</code> &gt; Three-Dot Menu &gt; <code class="verbatim">Scan Library Files</code></li>
<li><em>Enable</em> the <code class="verbatim">Account</code> &gt; <code class="verbatim">Library</code> &gt; <code class="verbatim">Empty trash automatically after every scan</code> preference for the source server.</li>
<li>On the left sidebar, click <code class="verbatim">More</code> &gt; Three-Dot Menu &gt; <code class="verbatim">Manage Server</code> &gt; <code class="verbatim">Empty Trash</code></li>
<li>On the left sidebar, click <code class="verbatim">More</code> &gt; Three-Dot Menu &gt; <code class="verbatim">Manage Server</code> &gt; <code class="verbatim">Clean Bundles</code></li>
<li>On the left sidebar, click <code class="verbatim">More</code> &gt; Three-Dot Menu &gt; <code class="verbatim">Manage Server</code> &gt; <code class="verbatim">Optimize Database</code></li>
</ol>
<p>Finally, double-check the Remote Access settings to make sure no changes have caused issues with accessing the server from outside the network.</p>
<p>In my case, I use a single port forwarding rule in my router and needed to update the Local LAN (local area network) IP (internet protocol) Address to the new server IP address.</p>
<h2 id="phase-3-configure-gpu-transcoding"><span class="section-number-2">4.</span> Phase 3: Configure GPU Transcoding</h2>
<p>The final piece to the migration is enabling hardware transcoding so that Plex can fully utilize the new Nvidia GPU available in the server. The first step is to install Nvidia graphics drivers. This process may take a few minutes, but the commands are pretty simple:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> add-apt-repository ppa:graphics-drivers/ppa</span>
<span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> apt update</span>
<span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> apt-get install ubuntu-drivers-common</span>
<span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> ubuntu-drivers autoinstall</span></span></code></pre>
<p>Finally, reboot so that the changes are loaded:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> reboot now</span></span></code></pre>
<p>To ensure that the Nvidia graphics drivers are working properly, run the following command to view the available GPUs, statistics, and processes:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> nvidia-smi</span></span></code></pre>
<p>Finally, enable hardware transcoding settings in the Plex application to finish the process.</p>
]]></description>
    </item>
    <item>
      <title>Personal Finance Tracker with SQLite</title>
      <link>https://cleberg.net/blog/financial-database.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/financial-database.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Thu, 03 Mar 2022 00:00:00 +0000</pubDate>
      <category>self-hosting</category>
      <description><![CDATA[<h2 id="personal-financial-tracking"><span class="section-number-2">1.</span> Personal Financial Tracking</h2>
<p>For the last 6-ish years, I've tracked my finances in a spreadsheet. This is common practice in the business world, but any good dev will cringe at the thought of storing long-term data in a spreadsheet. A spreadsheet is not for long-term storage or as a source of data to pull data/reports.</p>
<p>As I wanted to expand the functionality of my financial data (e.g., adding more reports), I decided to migrate the data into a database. To run reports, I would query the database and use a language like Python or Javascript to process the data, perform calculations, and visualize the data.</p>
<h2 id="sqlite"><span class="section-number-2">2.</span> SQLite</h2>
<p>When choosing the type of database I wanted to use for this project, I was split between three options:</p>
<ol>
<li>MySQL: The database I have the most experience with and have used for years.</li>
<li>PostgreSQL: A database I'm new to, but want to learn.</li>
<li>SQLite: A database that I've used for a couple projects and have moderate experience.</li>
</ol>
<p>I ended up choosing SQLite since it can be maintained within a single <code class="verbatim">.sqlite</code> file, which allows me more flexibility for storage and backup. I keep this file in my cloud storage and pull it up whenever needed.</p>
<h3 id="visual-editing"><span class="section-number-3">2.1.</span> Visual Editing</h3>
<p>Since I didn't want to try and import 1000–1500 records into my new database via the command line, I opted to use <a href="https://sqlitebrowser.org/">DB Browser for SQLite (DB4S)</a> as a GUI (graphical user interface) tool. This application is excellent, and I don't see myself going back to the CLI (command line interface) when working in this database.</p>
<p>DB4S allows you to copy a range of cells from a spreadsheet and paste it straight into the SQL table. I used this process for all 36 accounts, 1290 account statements, and 126 pay statements. Overall, I'm guessing this took anywhere between 4–8 hours. In comparison, it probably took me 2-3 days to initially create the spreadsheet.</p>
<h3 id="schema"><span class="section-number-3">2.2.</span> Schema</h3>
<p>The schema for this database is actually extremely simple and involves only three tables (for now):</p>
<ol>
<li>Accounts</li>
<li>Statements</li>
<li>Payroll</li>
</ol>
<p><strong>Accounts</strong></p>
<p>The Accounts table contains summary information about an account, such as a car loan or a credit card. By viewing this table, you can find high-level data, such as interest rate, credit line, or owner.</p>
<pre><code class="language-sql highlight"><span class="source sql"><span class="meta create sql"><span class="keyword other create sql">CREATE</span> <span class="keyword other sql">TABLE</span> &quot;<span class="entity name function sql">Accounts</span>&quot;</span> (
    <span class="string quoted double sql"><span class="punctuation definition string begin sql">&quot;</span>AccountID<span class="punctuation definition string end sql">&quot;</span></span>     <span class="storage type sql">INTEGER</span> <span class="keyword other DDL create II sql">NOT NULL</span> UNIQUE,
    <span class="string quoted double sql"><span class="punctuation definition string begin sql">&quot;</span>AccountType<span class="punctuation definition string end sql">&quot;</span></span>   <span class="storage type sql">TEXT</span>,
    <span class="string quoted double sql"><span class="punctuation definition string begin sql">&quot;</span>AccountName<span class="punctuation definition string end sql">&quot;</span></span>   <span class="storage type sql">TEXT</span>,
    <span class="string quoted double sql"><span class="punctuation definition string begin sql">&quot;</span>InterestRate<span class="punctuation definition string end sql">&quot;</span></span>  <span class="storage type sql">NUMERIC</span>,
    <span class="string quoted double sql"><span class="punctuation definition string begin sql">&quot;</span>CreditLine<span class="punctuation definition string end sql">&quot;</span></span>    <span class="storage type sql">NUMERIC</span>,
    <span class="string quoted double sql"><span class="punctuation definition string begin sql">&quot;</span>State<span class="punctuation definition string end sql">&quot;</span></span>         <span class="storage type sql">TEXT</span>,
    <span class="string quoted double sql"><span class="punctuation definition string begin sql">&quot;</span>Owner<span class="punctuation definition string end sql">&quot;</span></span>         <span class="storage type sql">TEXT</span>,
    <span class="string quoted double sql"><span class="punctuation definition string begin sql">&quot;</span>Co-Owner<span class="punctuation definition string end sql">&quot;</span></span>      <span class="storage type sql">TEXT</span>,
    <span class="storage modifier sql">PRIMARY KEY</span>(<span class="string quoted double sql"><span class="punctuation definition string begin sql">&quot;</span>AccountID<span class="punctuation definition string end sql">&quot;</span></span> AUTOINCREMENT)
)</span></code></pre>
<p><strong>Statements</strong></p>
<p>The Statements table uses the same unique identifier as the Accounts table, meaning you can join the tables to find a monthly statement for any of the accounts listed in the Accounts table. Each statement has an account identified (ID), statement date, and total balance.</p>
<pre><code class="language-sql highlight"><span class="source sql"><span class="meta create sql"><span class="keyword other create sql">CREATE</span> <span class="keyword other sql">TABLE</span> &quot;<span class="entity name function sql">Statements</span>&quot;</span> (
    <span class="string quoted double sql"><span class="punctuation definition string begin sql">&quot;</span>StatementID<span class="punctuation definition string end sql">&quot;</span></span>   <span class="storage type sql">INTEGER</span> <span class="keyword other DDL create II sql">NOT NULL</span> UNIQUE,
    <span class="string quoted double sql"><span class="punctuation definition string begin sql">&quot;</span>AccountID<span class="punctuation definition string end sql">&quot;</span></span>     <span class="storage type sql">INTEGER</span>,
    <span class="string quoted double sql"><span class="punctuation definition string begin sql">&quot;</span>StatementDate<span class="punctuation definition string end sql">&quot;</span></span> <span class="storage type sql">INTEGER</span>,
    <span class="string quoted double sql"><span class="punctuation definition string begin sql">&quot;</span>Balance<span class="punctuation definition string end sql">&quot;</span></span>       <span class="storage type sql">NUMERIC</span>,
    <span class="storage modifier sql">PRIMARY KEY</span>(<span class="string quoted double sql"><span class="punctuation definition string begin sql">&quot;</span>StatementID<span class="punctuation definition string end sql">&quot;</span></span> AUTOINCREMENT),
    <span class="storage modifier sql">FOREIGN KEY</span>(<span class="string quoted double sql"><span class="punctuation definition string begin sql">&quot;</span>AccountID<span class="punctuation definition string end sql">&quot;</span></span>) <span class="storage modifier sql">REFERENCES</span> <span class="string quoted double sql"><span class="punctuation definition string begin sql">&quot;</span>Accounts<span class="punctuation definition string end sql">&quot;</span></span>(<span class="string quoted double sql"><span class="punctuation definition string begin sql">&quot;</span>AccountID<span class="punctuation definition string end sql">&quot;</span></span>)
)</span></code></pre>
<p><strong>Payroll</strong></p>
<p>The Payroll table is a separate entity, unrelated to the Accounts or Statements tables. This table contains all information you would find on a pay statement from an employer. As you change employers or obtain new perks/benefits, just add new columns to adapt to the new data.</p>
<pre><code class="language-sql highlight"><span class="source sql"><span class="meta create sql"><span class="keyword other create sql">CREATE</span> <span class="keyword other sql">TABLE</span> &quot;<span class="entity name function sql">Payroll</span>&quot;</span> (
    <span class="string quoted double sql"><span class="punctuation definition string begin sql">&quot;</span>PaycheckID<span class="punctuation definition string end sql">&quot;</span></span>            <span class="storage type sql">INTEGER</span> <span class="keyword other DDL create II sql">NOT NULL</span> UNIQUE,
    <span class="string quoted double sql"><span class="punctuation definition string begin sql">&quot;</span>PayDate<span class="punctuation definition string end sql">&quot;</span></span>               <span class="storage type sql">TEXT</span>,
    <span class="string quoted double sql"><span class="punctuation definition string begin sql">&quot;</span>Payee<span class="punctuation definition string end sql">&quot;</span></span>                 <span class="storage type sql">TEXT</span>,
    <span class="string quoted double sql"><span class="punctuation definition string begin sql">&quot;</span>Employer<span class="punctuation definition string end sql">&quot;</span></span>              <span class="storage type sql">TEXT</span>,
    <span class="string quoted double sql"><span class="punctuation definition string begin sql">&quot;</span>JobTitle<span class="punctuation definition string end sql">&quot;</span></span>              <span class="storage type sql">TEXT</span>,
    <span class="string quoted double sql"><span class="punctuation definition string begin sql">&quot;</span>IncomeRegular<span class="punctuation definition string end sql">&quot;</span></span>         <span class="storage type sql">NUMERIC</span>,
    <span class="string quoted double sql"><span class="punctuation definition string begin sql">&quot;</span>IncomePTO<span class="punctuation definition string end sql">&quot;</span></span>             <span class="storage type sql">NUMERIC</span>,
    <span class="string quoted double sql"><span class="punctuation definition string begin sql">&quot;</span>IncomeHoliday<span class="punctuation definition string end sql">&quot;</span></span>         <span class="storage type sql">NUMERIC</span>,
    <span class="string quoted double sql"><span class="punctuation definition string begin sql">&quot;</span>IncomeBonus<span class="punctuation definition string end sql">&quot;</span></span>           <span class="storage type sql">NUMERIC</span>,
    <span class="string quoted double sql"><span class="punctuation definition string begin sql">&quot;</span>IncomePTOPayout<span class="punctuation definition string end sql">&quot;</span></span>       <span class="storage type sql">NUMERIC</span>,
    <span class="string quoted double sql"><span class="punctuation definition string begin sql">&quot;</span>IncomeReimbursements<span class="punctuation definition string end sql">&quot;</span></span>  <span class="storage type sql">NUMERIC</span>,
    <span class="string quoted double sql"><span class="punctuation definition string begin sql">&quot;</span>FringeHSA<span class="punctuation definition string end sql">&quot;</span></span>             <span class="storage type sql">NUMERIC</span>,
    <span class="string quoted double sql"><span class="punctuation definition string begin sql">&quot;</span>FringeStudentLoan<span class="punctuation definition string end sql">&quot;</span></span>     <span class="storage type sql">NUMERIC</span>,
    <span class="string quoted double sql"><span class="punctuation definition string begin sql">&quot;</span>Fringe401k<span class="punctuation definition string end sql">&quot;</span></span>            <span class="storage type sql">NUMERIC</span>,
    <span class="string quoted double sql"><span class="punctuation definition string begin sql">&quot;</span>PreTaxMedical<span class="punctuation definition string end sql">&quot;</span></span>         <span class="storage type sql">NUMERIC</span>,
    <span class="string quoted double sql"><span class="punctuation definition string begin sql">&quot;</span>PreTaxDental<span class="punctuation definition string end sql">&quot;</span></span>          <span class="storage type sql">NUMERIC</span>,
    <span class="string quoted double sql"><span class="punctuation definition string begin sql">&quot;</span>PreTaxVision<span class="punctuation definition string end sql">&quot;</span></span>          <span class="storage type sql">NUMERIC</span>,
    <span class="string quoted double sql"><span class="punctuation definition string begin sql">&quot;</span>PreTaxLifeInsurance<span class="punctuation definition string end sql">&quot;</span></span>   <span class="storage type sql">NUMERIC</span>,
    <span class="string quoted double sql"><span class="punctuation definition string begin sql">&quot;</span>PreTax401k<span class="punctuation definition string end sql">&quot;</span></span>            <span class="storage type sql">NUMERIC</span>,
    <span class="string quoted double sql"><span class="punctuation definition string begin sql">&quot;</span>PreTaxParking<span class="punctuation definition string end sql">&quot;</span></span>         <span class="storage type sql">NUMERIC</span>,
    <span class="string quoted double sql"><span class="punctuation definition string begin sql">&quot;</span>PreTaxStudentLoan<span class="punctuation definition string end sql">&quot;</span></span>     <span class="storage type sql">NUMERIC</span>,
    <span class="string quoted double sql"><span class="punctuation definition string begin sql">&quot;</span>PreTaxOther<span class="punctuation definition string end sql">&quot;</span></span>           <span class="storage type sql">NUMERIC</span>,
    <span class="string quoted double sql"><span class="punctuation definition string begin sql">&quot;</span>TaxFederal<span class="punctuation definition string end sql">&quot;</span></span>            <span class="storage type sql">NUMERIC</span>,
    <span class="string quoted double sql"><span class="punctuation definition string begin sql">&quot;</span>TaxSocial<span class="punctuation definition string end sql">&quot;</span></span>             <span class="storage type sql">NUMERIC</span>,
    <span class="string quoted double sql"><span class="punctuation definition string begin sql">&quot;</span>TaxMedicare<span class="punctuation definition string end sql">&quot;</span></span>           <span class="storage type sql">NUMERIC</span>,
    <span class="string quoted double sql"><span class="punctuation definition string begin sql">&quot;</span>TaxState<span class="punctuation definition string end sql">&quot;</span></span>              <span class="storage type sql">NUMERIC</span>,
    <span class="storage modifier sql">PRIMARY KEY</span>(<span class="string quoted double sql"><span class="punctuation definition string begin sql">&quot;</span>PaycheckID<span class="punctuation definition string end sql">&quot;</span></span> AUTOINCREMENT)
)</span></code></pre>
<h3 id="python-reporting"><span class="section-number-3">2.3.</span> Python Reporting</h3>
<p>Once I created the database tables and imported all my data, the only step left was to create a process to report and visualize on various aspects of the data.</p>
<p>In order to explore and create the reports I'm interested in, I utilized a two-part process involving Jupyter Notebooks and Python scripts.</p>
<h4 id="step-1-jupyter-notebooks"><span class="section-number-4">2.3.1.</span> Step 1: Jupyter Notebooks</h4>
<p>When I need to explore data, try different things, and re-run my code cell-by-cell, I use Jupyter Notebooks. For example, I explored the <code class="verbatim">Accounts</code> table until I found the following useful information:</p>
<pre><code class="language-python highlight"><span class="source python"><span class="meta statement import python"><span class="keyword control import python">import</span> <span class="meta qualified-name python"><span class="meta generic-name python">sqlite3</span></span></span>
<span class="meta statement import python"><span class="keyword control import python">import</span> <span class="meta qualified-name python"><span class="meta generic-name python">pandas</span></span> <span class="keyword control import as python">as</span> <span class="meta qualified-name python"><span class="meta generic-name python">pd</span></span></span>
<span class="meta statement import python"><span class="keyword control import python">import</span> <span class="meta qualified-name python"><span class="meta generic-name python">matplotlib</span></span></span>

<span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Set up database filename and connect
</span><span class="meta qualified-name python"><span class="meta generic-name python">db</span></span> <span class="keyword operator assignment python">=</span> <span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">finances.sqlite<span class="punctuation definition string end python">&quot;</span></span></span>
<span class="meta qualified-name python"><span class="meta generic-name python">connection</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">sqlite3</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">connect</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">db</span></span></span><span class="punctuation section arguments end python">)</span></span>
<span class="meta qualified-name python"><span class="meta generic-name python">df</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">pd</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">read_sql_query</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python"><span class="source sql"><span class="keyword other DML sql">SELECT</span> <span class="keyword operator star sql">*</span><span class="keyword operator star sql">*</span> <span class="keyword other DML sql">FROM</span> Accounts</span><span class="punctuation definition string end python">&quot;</span></span></span><span class="punctuation separator arguments python">,</span> <span class="meta qualified-name python"><span class="meta generic-name python">connection</span></span></span><span class="punctuation section arguments end python">)</span></span>

<span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Set global matplotlib variables
</span><span class="keyword operator arithmetic python">%</span><span class="meta qualified-name python"><span class="meta generic-name python">matplotlib</span></span> <span class="meta qualified-name python"><span class="meta generic-name python">inline</span></span>
<span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">matplotlib</span><span class="punctuation accessor dot python">.</span><span class="meta generic-name python">rcParams</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">text.color<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span> <span class="keyword operator assignment python">=</span> <span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">white<span class="punctuation definition string end python">&#39;</span></span></span>
<span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">matplotlib</span><span class="punctuation accessor dot python">.</span><span class="meta generic-name python">rcParams</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">axes.labelcolor<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span> <span class="keyword operator assignment python">=</span> <span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">white<span class="punctuation definition string end python">&#39;</span></span></span>
<span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">matplotlib</span><span class="punctuation accessor dot python">.</span><span class="meta generic-name python">rcParams</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">xtick.color<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span> <span class="keyword operator assignment python">=</span> <span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">white<span class="punctuation definition string end python">&#39;</span></span></span>
<span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">matplotlib</span><span class="punctuation accessor dot python">.</span><span class="meta generic-name python">rcParams</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">ytick.color<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span> <span class="keyword operator assignment python">=</span> <span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">white<span class="punctuation definition string end python">&#39;</span></span></span>
<span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">matplotlib</span><span class="punctuation accessor dot python">.</span><span class="meta generic-name python">rcParams</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">legend.labelcolor<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span> <span class="keyword operator assignment python">=</span> <span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">black<span class="punctuation definition string end python">&#39;</span></span></span>

<span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Display graph
</span><span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">df</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">groupby</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta structure list python"><span class="punctuation section list begin python">[</span><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">AccountType<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation section list end python">]</span></span></span><span class="punctuation section arguments end python">)</span></span><span class="meta function-call python"><span class="meta qualified-name python"><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">sum</span></span><span class="punctuation section arguments begin python">(</span><span class="punctuation section arguments end python">)</span></span><span class="meta function-call python"><span class="meta qualified-name python"><span class="punctuation accessor dot python">.</span><span class="meta generic-name python">plot</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">pie</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="variable parameter python">title</span><span class="keyword operator assignment python">=</span><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">Credit Line by Account Type<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation separator arguments python">,</span> <span class="variable parameter python">y</span><span class="keyword operator assignment python">=</span><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">CreditLine<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation separator arguments python">,</span> <span class="variable parameter python">figsize</span><span class="keyword operator assignment python">=</span><span class="meta group python"><span class="punctuation section group begin python">(</span><span class="constant numeric integer decimal python">5</span><span class="punctuation separator tuple python">,</span><span class="constant numeric integer decimal python">5</span><span class="punctuation section group end python">)</span></span><span class="punctuation separator arguments python">,</span> <span class="variable parameter python">autopct</span><span class="keyword operator assignment python">=</span><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python"><span class="constant other placeholder python">%1.1f</span><span class="constant other placeholder python">%%</span><span class="punctuation definition string end python">&#39;</span></span></span></span><span class="punctuation section arguments end python">)</span></span></span></code></pre>
<h4 id="step-2-python-scripts"><span class="section-number-4">2.3.2.</span> Step 2: Python Scripts</h4>
<p>Once I explored enough through the notebooks and had a list of reports I wanted, I moved on to create a Python project with the following structure:</p>
<pre><code class="language-txt highlight"><span class="text plain">finance/
├── notebooks/
│   │   ├── account_summary.ipynb
│   │   ├── account_details.ipynb
│   │   └── payroll.ipynb
├── public/
│   │   ├── image-01.png
│   │   └── image-0X.png
├── src/
│   └── finance.sqlite
├── venv/
├── _init.py
├── database.py
├── process.py
├── requirements.txt
└── README.md</span></code></pre>
<p>This structure allows me to:</p>
<ol>
<li>Compile all required python packages into <code class="verbatim">requirements.txt</code> for easy installation if I move to a new machine.</li>
<li>Activate a virtual environment in <code class="verbatim">venv/</code> so I don't need to maintain a system-wide Python environment just for this project.</li>
<li>Keep my <code class="verbatim">notebooks/</code> folder to continuously explore the data as I see fit.</li>
<li>Maintain a local copy of the database in <code class="verbatim">src/</code> for easy access.</li>
<li>Export reports, images, HTML files, etc. to <code class="verbatim">public/</code>.</li>
</ol>
<p>Now, onto the differences between the code in a Jupyter Notebook and the actual Python files. To create the report in the Notebook snippet above, I created the following function inside <code class="verbatim">process.py</code>:</p>
<pre><code class="language-python highlight"><span class="source python"><span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Create summary pie chart
</span><span class="meta function python"><span class="storage type function python">def</span> <span class="entity name function python"><span class="meta generic-name python">summary_data</span></span></span><span class="meta function parameters python"><span class="punctuation section parameters begin python">(</span></span><span class="meta function parameters python"><span class="variable parameter python">accounts</span></span><span class="meta function parameters annotation python"><span class="punctuation separator annotation parameter python">:</span> <span class="meta qualified-name python"><span class="meta generic-name python">pandas</span><span class="punctuation accessor dot python">.</span><span class="meta generic-name python">DataFrame</span></span></span><span class="meta function parameters python"><span class="punctuation section parameters end python">)</span></span><span class="meta function python"> </span><span class="meta function annotation return python"><span class="punctuation separator annotation return python">-&gt;</span> <span class="constant language python">None</span></span><span class="meta function python"><span class="punctuation section function begin python">:</span></span>
    <span class="meta qualified-name python"><span class="meta generic-name python">accounts_01</span></span> <span class="keyword operator assignment python">=</span> <span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">accounts</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">accounts</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">Owner<span class="punctuation definition string end python">&quot;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span> <span class="keyword operator comparison python">==</span> <span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">Person01<span class="punctuation definition string end python">&quot;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span>
    <span class="meta qualified-name python"><span class="meta generic-name python">accounts_02</span></span> <span class="keyword operator assignment python">=</span> <span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">accounts</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">accounts</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">Owner<span class="punctuation definition string end python">&quot;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span> <span class="keyword operator comparison python">==</span> <span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">Person02<span class="punctuation definition string end python">&quot;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span>
    <span class="meta statement for python"><span class="keyword control flow for python">for</span> <span class="meta generic-name python">x</span> <span class="meta statement for python"><span class="keyword control flow for in python">in</span></span></span><span class="meta statement for python"> <span class="meta function-call python"><span class="meta qualified-name python"><span class="support function builtin python">range</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="constant numeric integer decimal python">1</span><span class="punctuation separator arguments python">,</span> <span class="constant numeric integer decimal python">4</span></span><span class="punctuation section arguments end python">)</span></span><span class="punctuation section block for python">:</span></span>
        <span class="meta statement if python"><span class="keyword control flow conditional python">if</span> <span class="meta qualified-name python"><span class="meta generic-name python">x</span></span> <span class="keyword operator comparison python">==</span> <span class="constant numeric integer decimal python">1</span><span class="punctuation section block conditional python">:</span></span>
            <span class="meta qualified-name python"><span class="meta generic-name python">df</span></span> <span class="keyword operator assignment python">=</span> <span class="meta qualified-name python"><span class="meta generic-name python">accounts</span></span>
            <span class="meta qualified-name python"><span class="meta generic-name python">account_string</span></span> <span class="keyword operator assignment python">=</span> <span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">All Accounts<span class="punctuation definition string end python">&quot;</span></span></span>
        <span class="meta statement conditional python"><span class="keyword control flow conditional python">elif</span></span> <span class="meta qualified-name python"><span class="meta generic-name python">x</span></span> <span class="keyword operator comparison python">==</span> <span class="constant numeric integer decimal python">2</span><span class="punctuation separator annotation variable python">:</span>
            <span class="meta qualified-name python"><span class="meta generic-name python">df</span></span> <span class="keyword operator assignment python">=</span> <span class="meta qualified-name python"><span class="meta generic-name python">accounts_01</span></span>
            <span class="meta qualified-name python"><span class="meta generic-name python">account_string</span></span> <span class="keyword operator assignment python">=</span> <span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">Person01&#39;s Accounts<span class="punctuation definition string end python">&quot;</span></span></span>
        <span class="meta statement conditional python"><span class="keyword control flow conditional python">elif</span></span> <span class="meta qualified-name python"><span class="meta generic-name python">x</span></span> <span class="keyword operator comparison python">==</span> <span class="constant numeric integer decimal python">3</span><span class="punctuation separator annotation variable python">:</span>
            <span class="meta qualified-name python"><span class="meta generic-name python">df</span></span> <span class="keyword operator assignment python">=</span> <span class="meta qualified-name python"><span class="meta generic-name python">accounts_02</span></span>
            <span class="meta qualified-name python"><span class="meta generic-name python">account_string</span></span> <span class="keyword operator assignment python">=</span> <span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">Person02&#39;s Accounts<span class="punctuation definition string end python">&quot;</span></span></span>
        <span class="meta function-call python"><span class="meta qualified-name python"><span class="support function builtin python">print</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="storage type string python">f</span><span class="meta string interpolated python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string interpolated python"><span class="string quoted double python">Generating pie chart summary image for </span><span class="meta interpolation python"><span class="punctuation section interpolation begin python">{</span><span class="source python embedded"><span class="meta qualified-name python"><span class="meta generic-name python">account_string</span></span></span></span><span class="meta interpolation python"><span class="punctuation section interpolation end python">}</span></span><span class="string quoted double python">...<span class="punctuation definition string end python">&quot;</span></span></span></span><span class="punctuation section arguments end python">)</span></span>
        <span class="meta qualified-name python"><span class="meta generic-name python">summary_chart</span></span> <span class="keyword operator assignment python">=</span> <span class="meta group python"><span class="punctuation section group begin python">(</span>
            <span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">df</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">groupby</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta structure list python"><span class="punctuation section list begin python">[</span><span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">AccountType<span class="punctuation definition string end python">&quot;</span></span></span><span class="punctuation section list end python">]</span></span></span><span class="punctuation section arguments end python">)</span></span>
            <span class="meta function-call python"><span class="meta qualified-name python"><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">sum</span></span><span class="punctuation section arguments begin python">(</span><span class="punctuation section arguments end python">)</span></span>
            <span class="meta function-call python"><span class="meta qualified-name python"><span class="punctuation accessor dot python">.</span><span class="meta generic-name python">plot</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">pie</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python">
                <span class="variable parameter python">title</span><span class="keyword operator assignment python">=</span><span class="storage type string python">f</span><span class="meta string interpolated python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string interpolated python"><span class="string quoted double python">Credit Line by Type for </span><span class="meta interpolation python"><span class="punctuation section interpolation begin python">{</span><span class="source python embedded"><span class="meta qualified-name python"><span class="meta generic-name python">account_string</span></span></span></span><span class="meta interpolation python"><span class="punctuation section interpolation end python">}</span></span><span class="string quoted double python"><span class="punctuation definition string end python">&quot;</span></span></span><span class="punctuation separator arguments python">,</span>
                <span class="variable parameter python">y</span><span class="keyword operator assignment python">=</span><span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">CreditLine<span class="punctuation definition string end python">&quot;</span></span></span><span class="punctuation separator arguments python">,</span>
                <span class="variable parameter python">autopct</span><span class="keyword operator assignment python">=</span><span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python"><span class="constant other placeholder python">%1.1f</span><span class="constant other placeholder python">%%</span><span class="punctuation definition string end python">&quot;</span></span></span><span class="punctuation separator arguments python">,</span>
            </span><span class="punctuation section arguments end python">)</span></span>
        <span class="punctuation section group end python">)</span></span>
        <span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">summary_chart</span><span class="punctuation accessor dot python">.</span><span class="meta generic-name python">figure</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">savefig</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="storage type string python">f</span><span class="meta string interpolated python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string interpolated python"><span class="string quoted double python">public/summary_chart_</span><span class="meta interpolation python"><span class="punctuation section interpolation begin python">{</span><span class="source python embedded"><span class="meta qualified-name python"><span class="meta generic-name python">x</span></span></span></span><span class="meta interpolation python"><span class="punctuation section interpolation end python">}</span></span><span class="string quoted double python">.png<span class="punctuation definition string end python">&quot;</span></span></span><span class="punctuation separator arguments python">,</span> <span class="variable parameter python">dpi</span><span class="keyword operator assignment python">=</span><span class="constant numeric integer decimal python">1200</span></span><span class="punctuation section arguments end python">)</span></span></span></code></pre>
<p>The result? A high-quality pie chart that is read directly by the <code class="verbatim">public/index.html</code> template I use.</p>
<p>Other charts generated by this project include:</p>
<ul>
<li>Charts of account balances over time.</li>
<li>Line chart of effective tax rate (taxes divided by taxable income).</li>
<li>Salary projections and error limits using past income and inflation rates.</li>
<li>Multi-line chart of gross income, taxable income, and net income.</li>
</ul>
<p>The best thing about this project? I can improve it at any given time, shaping it into whatever helps me the most for that time. I imagine that I will be introducing an asset tracking table soon to track the depreciating value of cars, houses, etc. Who knows what's next?</p>
]]></description>
    </item>
    <item>
      <title>Create Reliable Notes with Plaintext</title>
      <link>https://cleberg.net/blog/reliable-notes.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/reliable-notes.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Wed, 02 Mar 2022 00:00:00 +0000</pubDate>
      <category>personal</category>
      <description><![CDATA[<h2 id="choosing-durable-file-formats"><span class="section-number-2">1.</span> Choosing Durable File Formats</h2>
<blockquote>
<p>TL;DR (Too Long; Didn't Read): Write in a format that can be easily rendered and read in plain-text mode (e.g., <code class="verbatim">.txt</code>, <code class="verbatim">.md</code>, etc.).</p>
</blockquote>
<p>As I've written more and more over the years, I've found that my love of note-taking is always growing. Everything I learn or need to remember can be written down in a note and saved digitally, with no cost to myself. Unlike paper copies that need physical storage space, digital files simply need space on your local disk or cloud storage, which is fairly abundant these days.</p>
<p>However, I had a historical struggle with migration of notes between different apps that require different formats and applied proprietary styling. This meant that I had to go through each note during migration and edit the file to look presentable again.</p>
<p>For the last year or two, I have written everything exclusively in <a href="https://en.wikipedia.org/wiki/Markdown">Markdown</a> format. Small notes, long-form writings, and even these blog posts are all written in Markdown.</p>
<p>Why Markdown? While I do appreciate the simplicity of plain-text files without any formatting, I often need visual cues such as heading and code blocks to keep my thoughts straight. Markdown provides a minimal set of styling indicators for me to style my notes without adding any proprietary, embedded data into the files. If I want a top-level heading, I simply add a hash (<code class="verbatim">#</code>) before the line. An added bonus is that even if a system doesn't understand Markdown, it will render it as plain-text and I can read it just as easily.</p>
<p>For example, here's how TextEdit on macOS will open and display a Markdown file in plain-text, since it does contain any features to preview Markdown as HTML:</p>
<figure><img src="https://img.cleberg.net/blog/20220302-easy-reliable-note-taking/plain_markdown.webp" alt="A view of the README.md from the cleberg.net repository."><figcaption><span class="figure-number">Figure 1: </span>Plain Text Markdown</figcaption></figure>
<h3 id="saving-syncing-files"><span class="section-number-3">1.1.</span> Saving &amp; Syncing Files</h3>
<p>In order to read and edit my notes across platforms, I use my personal cloud storage through Tresorit due to its native integration with macOS and iOS file managers. In addition, Tresorit works well on Debian-based Linux distributions, which I used before macOS (and will likely switch back to in a few years).</p>
<p>You can use whatever sync software you want - syncing plain-text or markdown files is incredibly easy and fast, since the files are generally tiny.</p>
<p>Since the cloud storage syncs files automatically, there is no need for me to sync anything manually or kick-off a sync job to update my files. This means that I can edit on mobile, and it takes about 5-10 seconds to see the changes on desktop.</p>
<h4 id="version-control-with-git"><span class="section-number-4">1.1.1.</span> Version Control with Git</h4>
<p>A different approach I've contemplated is storing my notes and attachments is using a hosted Git repository to track changes to the files. However, I don't want to rely on an external service that could potentially see into my data, even if the repository is private.</p>
<p>I might just do <code class="verbatim">git init</code> locally and then commit my changes each time I write or update a note, but that seems to be a lot of work just for tracking changes - which I don't necessarily care to know.</p>
<h4 id="backups"><span class="section-number-4">1.1.2.</span> Backups!</h4>
<p>One small addition to the storage/sync conversation is the idea of backups. Personally, I manually create periodic backups of my entire cloud storage, compress it into an archive, and store it on my home server.</p>
<p>To improve my workflow, I am going to be exploring options to automatically compress the mounted cloud directory and send it over to my server on a set schedule.</p>
<h3 id="writing-on-desktop"><span class="section-number-3">1.2.</span> Writing on Desktop</h3>
<blockquote>
<p><strong>Update (06.14.22)</strong>: Since writing this post, I have reverted to simply keeping my <code class="verbatim">notes</code> folder open and opening notes individually in TextEdit for a more minimal and relaxing writing experience on the desktop.</p>
</blockquote>
<p>The bulk of my writing occurs in a desktop environment, with a full keyboard layout and wide screen. I don't illustrate with a smart pen, I rarely use embedded images, and I love being able to see all of my notes/directories in a sidebar.</p>
<p>With this simple set of requirements, I chose <a href="https://obsidian.md">Obsidian</a> as my desktop text editor. Obsidian has some in-depth tools like a graph view, command palette, mentions, etc., but I've found that using it as a simple Markdown editor is incredibly easy and straightforward.</p>
<p>Here's an example of how my Markdown notes look when opened in plain-text mode:</p>
<figure><img src="https://img.cleberg.net/blog/20220302-easy-reliable-note-taking/obsidian_source_mode.webp" alt="Markdown source mode, showing the symbols used by markdown to markup text."><figcaption><span class="figure-number">Figure 2: </span>Obsidian Markdown Source Mode</figcaption></figure>
<p>Here's the "live preview" version, where the Markdown is rendered into its HTML format:</p>
<figure><img src="https://img.cleberg.net/blog/20220302-easy-reliable-note-taking/obsidian_live_preview.webp" alt="Markdown preview mode, hiding all symbols used in Markdown syntax."><figcaption><span class="figure-number">Figure 3: </span>Obsidian Markdown Live Preview</figcaption></figure>
<h4 id="programming-on-desktop"><span class="section-number-4">1.2.1.</span> Programming on Desktop</h4>
<p>While I was writing this, I realized I should specify that I don't use the same editor for writing notes and for writing code. For programming purposes, I use <a href="https://vscodium.com">VSCodium</a> as my development IDE.</p>
<h3 id="writing-on-mobile"><span class="section-number-3">1.3.</span> Writing on Mobile</h3>
<p>Personally, I write very little on mobile, except when needing to take important notes on-the-go. Any long-form writing, journals, etc. are done at home, where I always have my laptop available.</p>
<p>I wanted a simple and foolproof editor for iOS, preferably open-source. After a long journey of testing the few (&amp; terrible) open-source iOS note-taking apps, I finally found a phenomenal one: <a href="https://github.com/simonbs/runestone">Runestone</a>. This app is fantastic for note-taking, has plenty of optional features, and integrates natively with the iOS file manager.</p>
<p>This app opens the iOS file manager and allows you to click any file you want, opens it up in an editor, and lets me save and close out of that note.</p>
<p>Quite simple but effective.</p>
]]></description>
    </item>
    <item>
      <title>Twosday: 2/22/22</title>
      <link>https://cleberg.net/blog/tuesday.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/tuesday.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Tue, 22 Feb 2022 00:00:00 +0000</pubDate>
      <category>personal</category>
      <description><![CDATA[<h2 id="tuesday-twosday"><span class="section-number-2">1.</span> Tuesday, Twosday</h2>
<p>I'm taking a break from my usual technology-related posts and writing about something a little more enjoyable today.</p>
<p>Today is Tuesday, February 22nd, 2022. Today is 02-22-2022. Today is Twosday.</p>
<p>Let's look at everything that fell in place today:</p>
<ol>
<li>Written in the <code class="verbatim">m-dd-yy</code> or <code class="verbatim">dd-m-yy</code> formats, today is 2-22-22 or 22-2-22, which is a neat little palindrome in either format. (The last ubiquitous six-digit palindrome was 1-11-11.)</li>
<li>Today is Tuesday, which is why everyone is using the nickname Twosday to call out these similarities.</li>
<li>Falling on Tuesday means today is the 2nd day of the week (for most cultures. For the US, it's the 3rd day of the week since we start on Sunday).</li>
<li>The only culture I could find with a connection to a <code class="verbatim">2</code> is that some Slavic languages derived their version of Tuesday from the Old Church Slavonic word <code class="verbatim">въторъ</code>, meaning "the second."</li>
<li>Written in the classic monospaced, digital font (think of digital clocks from the 80s/90s), there is nice symmetry to the numbers.</li>
<li>This one isn't naturally-occurring, but it seems people around the world are celebrating the day. For example, a group is putting together <a href="https://www.eventbrite.com/e/2-22-22-a-collective-wedding-ceremony-at-the-state-capitol-tickets-211434605597">a wedding of 222 couples at the California State Capitol in Sacramento</a>, concluding at exactly 2:22 PM. These couples will record their marriage dates as 2-22-22 2:22 PM. Tickets were on sale for $222.22.</li>
</ol>
]]></description>
    </item>
    <item>
      <title>Nginx Caching for Static Content</title>
      <link>https://cleberg.net/blog/nginx-caching.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/nginx-caching.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Sun, 20 Feb 2022 00:00:00 +0000</pubDate>
      <category>linux</category>
      <category>web</category>
      <description><![CDATA[<h2 id="update-your-nginx-config-to-cache-static-files"><span class="section-number-2">1.</span> Update Your Nginx Config to Cache Static Files</h2>
<p>If you run a website on Nginx that serves static content (i.e., content that is not dynamic and changing with interactions from the user), you would likely benefit from caching that content on the client-side. If you're used to Apache and looking for the Nginx equivalent, this post should help.</p>
<p>Luckily, setting up the cache is as easy as identifying the file types you want to cache and determining the expiration length. To include more file types, simply use the bar separator (<code class="verbatim">|</code>) and type the new file extension you want to include.</p>
<pre><code class="language-config">server {
    ...

    location ~** .(css|js|jpg|jpeg|gif|png|ico)$ {
        expires 30d;
    }

    ...
}</code></pre>
<p>I have seen some people who prefer to set <code class="verbatim">expires</code> as <code class="verbatim">365d</code> or even <code class="verbatim">max</code>, but that is only for stable, infrequently changing websites. As my site often changes (i.e., I'm never content with my website), I need to know that my readers are seeing the new content without waiting too long.</p>
<p>So, I went ahead and set the expiration date at <code class="verbatim">30d</code>, which is short enough to refresh for readers but long enough that clients/browsers won't be re-requesting the static files too often, hopefully resulting in faster loading times, as images should be the only thing slowing down my site.</p>
<h2 id="testing-results"><span class="section-number-2">2.</span> Testing Results</h2>
<p>To test my changes to the Nginx configuration, I used the <a href="https://addons.mozilla.org/en-US/firefox/addon/http-header-live/">HTTP Header Live</a> extension on my Gecko browser and used the sidebar to inspect the headers of a recent image from my blog.</p>
<p>In the image below, you can see that the <code class="verbatim">Cache-Control</code> header is now present and set to 2592000, which is 30 days represented in seconds (30 days _ 24 hours/day _ 60 minutes/hour ** 60 seconds/minute = 2,592,000 seconds).</p>
<p>The <code class="verbatim">Expires</code> field is now showing 22 March 2022, which is 30 days from the day of this post, 20 February 2022.</p>
<h2 id="caveats"><span class="section-number-2">3.</span> Caveats</h2>
<p>Remember that this caching system is <strong>client-side</strong>, which means that content is only cached for as long as a client allows it. For example, my browser purges all caches, data, etc. upon exit, so this caching policy will only work as long as my browser remains open and running.</p>
<p>If you need to test updates to your site, you'll need to clear the cache to see updates for any file extension you configured. This can often be done with the <code class="verbatim">Shift + F5</code> or <code class="verbatim">Ctrl + F5</code> key combinations in most browsers.</p>
]]></description>
    </item>
    <item>
      <title>ExifTool: Strip Metadata Before You Post</title>
      <link>https://cleberg.net/blog/exiftool.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/exiftool.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Thu, 17 Feb 2022 00:00:00 +0000</pubDate>
      <category>linux</category>
      <category>privacy</category>
      <description><![CDATA[<h2 id="why-strip-metadata"><span class="section-number-2">1.</span> Why Strip Metadata?</h2>
<p>Okay, so you want to strip metadata from your photos. Perhaps you take pictures of very rare birds, and the location metadata is a gold mine for poachers, or perhaps you're just privacy-oriented like me and prefer to strip metadata from publicly-available images.</p>
<p>There are various components of image metadata that you may want to delete before releasing a photo to the public. Here's an incomplete list of things I could easily see just by inspecting a photo on my laptop:</p>
<ul>
<li>Location (Latitude &amp; Longitude)</li>
<li>Dimensions</li>
<li>Device Make &amp; Model</li>
<li>Color Space</li>
<li>Color Profile</li>
<li>Focal Length</li>
<li>Alpha Channel</li>
<li>Red Eye</li>
<li>Metering Mode</li>
<li>F Number</li>
</ul>
<p>Regardless of your reasoning, I'm going to explain how I used the <code class="verbatim">exiftool</code> package in Linux to automatically strip metadata from all images in a directory (+ subdirectories).</p>
<h2 id="installing-exiftool"><span class="section-number-2">2.</span> Installing <code class="verbatim">exiftool</code></h2>
<p>First things first: we need to install the tool. I'm running Debian 11 on my server (Ubuntu will work the same), so the command is as simple as:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> apt install exiftool</span></span></code></pre>
<p>There are different tools that can accomplish the same thing across distributions, but I really only care to test out this one package.</p>
<h2 id="recursively-strip-data"><span class="section-number-2">3.</span> Recursively Strip Data</h2>
<p>I actually use this tool extensively to strip any photos uploaded to the website that serves all the images for my blog (<code class="verbatim">img.cleberg.net</code>).</p>
<p>The following command is incredibly useful and can be modified to include any image extensions that <code class="verbatim">exiftool</code> supports:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">exiftool</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>r</span><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>all</span><span class="keyword operator assignment option shell">=</span><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>ext</span> jpg<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>ext</span> png /path/to/directory/</span></span></code></pre>
<p>The output of the command will let you know how many directories were scanned, how many images were updated, and how many images were unchanged.</p>
]]></description>
    </item>
    <item>
      <title>Migrating from Ubuntu to Debian with Nginx</title>
      <link>https://cleberg.net/blog/debian-and-nginx.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/debian-and-nginx.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Wed, 16 Feb 2022 00:00:00 +0000</pubDate>
      <category>linux</category>
      <category>web</category>
      <description><![CDATA[<h2 id="server-operating-system-os-debian"><span class="section-number-2">1.</span> Server Operating System (OS): Debian</h2>
<p>I've used various Linux distributions throughout the years, but I've never used anything except Ubuntu for my servers. Why? I really have no idea, mostly just comfort around the commands and software availability.</p>
<p>However, I have always wanted to try Debian as a server OS after testing it out in a VM a few years ago (side-note: I'd love to try Alpine too, but I always struggle with compatibility). So, I decided to launch a new VPS and use <a href="https://www.debian.org">Debian</a> 11 as the operating system (OS). Spoiler alert: it feels identical to Ubuntu for my purposes.</p>
<p>I did the normal things when first launching the VPS (virtual private server), such as adding a new user, locking down SSH (secure shell protocol), etc. If you want to see that level of detail, read my other post about <a href="https://cleberg.net/blog/how-to-set-up-a-vps-web-server/">How to Set Up a VPS Web Server</a>.</p>
<p>All of this has been similar, apart from small things such as the location of users' home folders. No complaints at all from me - Debian seems great.</p>
<h2 id="web-server-nginx"><span class="section-number-2">2.</span> Web Server: Nginx</h2>
<p>Once I had the baseline server configuration set-up for Debian, I moved on to trying out <a href="https://nginx.org">Nginx</a> as my web server software. This required me to install the <code class="verbatim">nginx</code> and <code class="verbatim">ufw</code> packages, as well as setting up the initial UFW (Uncomplicated Firewall) config:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> apt install nginx ufw</span>
<span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> ufw allow <span class="string quoted single shell"><span class="punctuation definition string begin shell">&#39;</span>Nginx Full<span class="punctuation definition string end shell">&#39;</span></span></span>
<span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> ufw allow SSH</span>
<span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> ufw enable</span>
<span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> ufw status</span>
<span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> systemctl status nginx</span></span></code></pre>
<p>Once I had the firewall set, I moved on to creating the directories and files for my website. This is very easy and is basically the same as setting up an Apache server, so no struggles here.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> mkdir<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>p</span> /var/www/your_domain/html</span>
<span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> chown<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>R</span> <span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">USER</span></span>:<span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">USER</span></span> /var/www/your_domain/html</span>
<span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> chmod<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>R</span> 755 /var/www/your_domain</span>
<span class="meta function-call shell"><span class="variable function shell">nano</span></span><span class="meta function-call arguments shell"> /var/www/your_domain/html/index.html</span></span></code></pre>
<p>The next part, creating the Nginx configuration files, is quite a bit different from Apache. First, you need to create the files in the <code class="verbatim">sites-available</code> folder and symlink it the <code class="verbatim">sites-enabled</code> folder.</p>
<p>Creating the configuration file for your domain:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> nano /etc/nginx/sites-available/your_domain</span></span></code></pre>
<p>Default content for an Nginx configuration file:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">server</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion brace shell"><span class="punctuation section expansion brace begin shell">{</span>
        listen 80;
        listen <span class="keyword control regexp set begin shell">[</span>::<span class="keyword control regexp set end shell">]</span>:80;

        root /var/www/your_domain/html;
        index index.html index.htm index.nginx-debian.html;

        server_name your_domain www.your_domain;

        location / <span class="meta group expansion brace shell"><span class="punctuation section expansion brace begin shell">{</span>
                try_files <span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">uri</span></span> <span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">uri</span></span>/ =404;
        <span class="punctuation section expansion brace end shell">}</span></span>
<span class="punctuation section expansion brace end shell">}</span></span></span></span></code></pre>
<p>Finally, symlink it together:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> ln<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>s</span> /etc/nginx/sites-available/your_domain /etc/nginx/sites-enabled/</span></span></code></pre>
<p>This will make your site available to the public (as long as you have <code class="verbatim">your_domain</code> DNS (Domain Name System) records pointed at the server's IP address)!</p>
<p>Next, I used <a href="https://certbot.eff.org/">certbot</a> to issue an HTTPS (Hypertext Transfer Protocol Secure) certificate for my domains using the following commands:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> apt install snapd</span><span class="keyword operator logical continue shell">;</span> <span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> snap install core</span><span class="keyword operator logical continue shell">;</span> <span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> snap refresh core</span>
<span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> snap install<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> --</span>classic</span> certbot</span>
<span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> ln<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>s</span> /snap/bin/certbot /usr/bin/certbot</span>
<span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> certbot<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> --</span>nginx</span></span></span></code></pre>
<p>Now that <code class="verbatim">certbot</code> ran successfully and updated my Nginx configuration files to include a <code class="verbatim">443</code> server block of code, I went back in and edited the configuration file to include security HTTP headers. This part is optional, but is recommended for security purposes; you can even test a website's HTTP header security at <a href="https://securityheaders.com/">Security Headers</a>.</p>
<p>The configuration below shows a set-up where you only want your website to serve content from its own domain, except for images and scripts, which may come from <code class="verbatim">nullitics.com</code>. All other content would be blocked from loading in a browser.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> nano /etc/nginx/sites-available/your_domain</span></span></code></pre>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">server</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion brace shell"><span class="punctuation section expansion brace begin shell">{</span>
    ...
        add_header Content-Security-Policy <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>default-src &#39;none&#39;; img-src &#39;self&#39; https://nullitics.com; script-src &#39;self&#39; https://nullitics.com; style-src &#39;self&#39;; font-src &#39;self&#39;<span class="punctuation definition string end shell">&quot;</span></span>;
        add_header X-Content-Type-Options <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>nosniff<span class="punctuation definition string end shell">&quot;</span></span>;
        add_header X-XSS-Protection <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>1; mode=block<span class="punctuation definition string end shell">&quot;</span></span>;
        add_header X-Frame-Options <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>DENY<span class="punctuation definition string end shell">&quot;</span></span>;
        add_header Strict-Transport-Security <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>max-age=63072000; includeSubDomains<span class="punctuation definition string end shell">&quot;</span></span>;
        add_header Referrer-Policy <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>no-referrer<span class="punctuation definition string end shell">&quot;</span></span>;
    ...
<span class="punctuation section expansion brace end shell">}</span></span></span></span></code></pre>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> systemctl restart nginx</span></span></code></pre>
<h3 id="nginx-vs-apache"><span class="section-number-3">2.1.</span> Nginx vs. Apache</h3>
<p>As I stated at the beginning, my historical hesitation with trying Nginx was that the differences in configuration formats scared me away from leaving Apache. However, I prefer Nginx to Apache for a few reasons:</p>
<ol>
<li>Nginx uses only one configuration file (<code class="verbatim">your_domain</code>) vs. Apache's two-file approach for HTTP vs. HTTPS (<code class="verbatim">your_domain.conf</code> and <code class="verbatim">your_domain-le-ssl.conf</code>).</li>
<li>Symlinking new configurations files and reloading Nginx are way easier than Apache's process of having to enable headers with <code class="verbatim">a2enmod mod_headers</code>, enable PHP with <code class="verbatim">a2enmod php</code> (plus any other mods you need), and then enabling sites with <code class="verbatim">a2ensite</code>, and THEN reloading Apache.</li>
<li>The contents of the Nginx configuration files seem more organized and logical with the curly-bracket approach. This is a minor reason, but everything just felt cleaner while I was installing my sites and that had a big quality of life impact on the installation for me.</li>
</ol>
<p>They're both great software packages, but Nginx just seems more organized and easier to use these days. I will certainly be exploring the Nginx docs to see what other fun things I can do with all of this.</p>
<h2 id="gemini-server-agate"><span class="section-number-2">3.</span> Gemini Server: Agate</h2>
<p>Finally, I set up the Agate software on this server again to host my Gemini server content, using Rust as I have before. You can read my other post for more information on installing Agate: <a href="https://cleberg.net/blog/hosting-a-gemini-server/">Hosting a Gemini Server</a>.</p>
<p>All in all, Debian + Nginx is very slick and I prefer it over my old combination of Ubuntu + Apache (although it's really just Nginx &gt; Apache for me, since Debian seems mostly the same as Ubuntu is so far).</p>
]]></description>
    </item>
    <item>
      <title>Dynamic DNS Updates via the Njalla API</title>
      <link>https://cleberg.net/blog/njalla-dns-api.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/njalla-dns-api.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Thu, 10 Feb 2022 00:00:00 +0000</pubDate>
      <category>security</category>
      <description><![CDATA[<h2 id="njalla-s-api"><span class="section-number-2">1.</span> Njalla's API</h2>
<p>As noted in my recent post about <a href="https://cleberg.net/blog/ditching-cloudflare/">switching to Njalla from Cloudflare</a>, I was searching for a way to replace my <a href="https://cleberg.net/blog/cloudflare-dns-api.html">bash script</a> to update my domain's <code class="verbatim">A</code> record with my home's internet protocol (IP) address dynamically.</p>
<p>To reiterate what I said in those posts, this is a common necessity for those of us who have non-static IP addresses that can change at any moment due to internet service provider (ISP) policy.</p>
<p>In order to keep a home server running smoothly, the server admin needs to have a process to constantly monitor their public IP address and update their domain's DNS records if it changes.</p>
<p>This post explains how to use Python to update Njalla's DNS (domain name system) records whenever a machine's public IP address changes.</p>
<h3 id="creating-a-token"><span class="section-number-3">1.1.</span> Creating a Token</h3>
<p>To use Njalla's API, you will first need to create a token that will be used to authenticate you every time you call the API (application programming interface). Luckily, this is very easy to do if you have an account with Njalla.</p>
<p>Simply go the <a href="https://njal.la/settings/api/">API Settings</a> page and click the <code class="verbatim">Add Token</code> button. Next, enter a name for the token and click <code class="verbatim">Add</code>.</p>
<p>Finally, click the <code class="verbatim">Manage</code> button next to your newly created token and copy the <code class="verbatim">API Token</code> field.</p>
<h3 id="finding-the-correct-api-request"><span class="section-number-3">1.2.</span> Finding the Correct API Request</h3>
<p>Once you have a token, you're ready to call the Njalla API for any number of requests. For a full listing of available requests, see the <a href="https://njal.la/api/">Njalla API Documentation</a>.</p>
<p>For this demo, we are using the <code class="verbatim">list-records</code> and <code class="verbatim">edit-record</code> requests.</p>
<p>The <code class="verbatim">list-records</code> request requires the following payload to be sent when calling the API:</p>
<pre><code class="language-txt highlight"><span class="text plain">params: {
    domain: string
}</span></code></pre>
<p>The <code class="verbatim">edit-record</code> request requires the following payload to be sent when calling the API:</p>
<pre><code class="language-txt highlight"><span class="text plain">params: {
    domain: string
    id: int
    content: string
}</span></code></pre>
<h2 id="server-set-up"><span class="section-number-2">2.</span> Server Set-Up</h2>
<p>To create this script, we will be using Python. By default, I use Python 3 on my servers, so please note that I did not test this in Python 2, and I do not know if Python 2 will work for this.</p>
<h3 id="creating-the-script"><span class="section-number-3">2.1.</span> Creating the Script</h3>
<p>First, find a suitable place to create your script. Personally, I just create a directory called <code class="verbatim">ddns</code> in my home directory:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">mkdir</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/ddns</span></span></code></pre>
<p>Next, create a Python script file:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">nano</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/ddns/ddns.py</span></span></code></pre>
<p>The following code snippet is quite long, so I won't go into depth on each part. However, I suggest you read through the entire script before running it; it is quite simple and contains comments to help explain each code block.</p>
<p><strong>Note</strong>: You will need to update the following variables for this to work:</p>
<ul>
<li><code class="verbatim">token</code>: This is the Njalla API token you created earlier.</li>
<li><code class="verbatim">user_domain</code>: This is the top-level domain you want to modify.</li>
<li><code class="verbatim">include_subdomains</code>: Set this to <code class="verbatim">True</code> if you also want to modify subdomains found under the TLD (top-level domain).</li>
<li><code class="verbatim">subdomains</code>: If <code class="verbatim">include_subdomains</code> = <code class="verbatim">True</code>, you can include your list of subdomains to be modified here.</li>
</ul>
<pre><code class="language-python highlight"><span class="source python"><span class="comment line number-sign python"><span class="punctuation definition comment python">#</span>!/usr/bin/python
</span><span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> -*- coding: utf-8 -*-
</span><span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Import Python modules
</span>
<span class="meta statement import python"><span class="keyword control import from python">from</span></span><span class="meta statement import python"><span class="meta import-source python"> <span class="meta import-path python"><span class="meta import-name python">requests</span></span> <span class="meta statement import python"><span class="keyword control import python">import</span></span></span></span><span class="meta statement import python"></span><span class="meta statement import python"> <span class="meta generic-name python">get</span></span>
<span class="meta statement import python"><span class="keyword control import python">import</span> <span class="meta qualified-name python"><span class="meta generic-name python">requests</span></span></span>
<span class="meta statement import python"><span class="keyword control import python">import</span> <span class="meta qualified-name python"><span class="meta generic-name python">json</span></span></span>

<span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Set global variables
</span>
<span class="meta qualified-name python"><span class="meta generic-name python">url</span></span> <span class="keyword operator assignment python">=</span> <span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">https://njal.la/api/1/<span class="punctuation definition string end python">&#39;</span></span></span>
<span class="meta qualified-name python"><span class="meta generic-name python">token</span></span> <span class="keyword operator assignment python">=</span> <span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">&lt;your-api-token&gt;<span class="punctuation definition string end python">&#39;</span></span></span>
<span class="meta qualified-name python"><span class="meta generic-name python">user_domain</span></span> <span class="keyword operator assignment python">=</span> <span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">example.com<span class="punctuation definition string end python">&#39;</span></span></span>
<span class="meta qualified-name python"><span class="meta generic-name python">include_subdomains</span></span> <span class="keyword operator assignment python">=</span> <span class="constant language python">True</span>
<span class="meta qualified-name python"><span class="meta generic-name python">subdomains</span></span> <span class="keyword operator assignment python">=</span> <span class="meta structure list python"><span class="punctuation section list begin python">[</span><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">one<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation separator list python">,</span> <span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">two<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation section list end python">]</span></span>


<span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Main API call function
</span>
<span class="meta function python"><span class="storage type function python">def</span> <span class="entity name function python"><span class="meta generic-name python">njalla</span></span></span><span class="meta function parameters python"><span class="punctuation section parameters begin python">(</span></span><span class="meta function parameters python"><span class="variable parameter python">method</span><span class="punctuation separator parameters python">,</span> <span class="keyword operator unpacking mapping python">**</span><span class="variable parameter python">params</span><span class="punctuation section parameters end python">)</span></span><span class="meta function python"><span class="punctuation section function begin python">:</span></span>
    <span class="meta qualified-name python"><span class="meta generic-name python">headers</span></span> <span class="keyword operator assignment python">=</span> <span class="meta structure dictionary-or-set python"><span class="punctuation section dictionary-or-set begin python">{</span><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">Authorization<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation separator key-value python">:</span> <span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">Njalla <span class="punctuation definition string end python">&#39;</span></span></span> <span class="keyword operator arithmetic python">+</span> <span class="meta qualified-name python"><span class="meta generic-name python">token</span></span><span class="punctuation section dictionary-or-set end python">}</span></span>
    <span class="meta qualified-name python"><span class="meta generic-name python">response</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">requests</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">post</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">url</span></span><span class="punctuation separator arguments python">,</span> <span class="variable parameter python">json</span><span class="keyword operator assignment python">=</span><span class="meta structure dictionary-or-set python"><span class="punctuation section dictionary-or-set begin python">{</span><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">method<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation separator key-value python">:</span> <span class="meta qualified-name python"><span class="meta generic-name python">method</span></span><span class="punctuation separator dictionary-or-set python">,</span>
                             <span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">params<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation separator key-value python">:</span> <span class="meta qualified-name python"><span class="meta generic-name python">params</span></span><span class="punctuation section dictionary-or-set end python">}</span></span><span class="punctuation separator arguments python">,</span> <span class="variable parameter python">headers</span><span class="keyword operator assignment python">=</span><span class="meta qualified-name python"><span class="meta generic-name python">headers</span></span></span><span class="punctuation section arguments end python">)</span></span><span class="meta function-call python"><span class="meta qualified-name python"><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">json</span></span><span class="punctuation section arguments begin python">(</span><span class="punctuation section arguments end python">)</span></span>
    <span class="meta statement if python"><span class="keyword control flow conditional python">if</span> <span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">result<span class="punctuation definition string end python">&#39;</span></span></span> <span class="keyword operator logical python">not</span> <span class="keyword operator logical python">in</span> <span class="meta qualified-name python"><span class="meta generic-name python">response</span></span><span class="punctuation section block conditional python">:</span></span>
        <span class="meta statement raise python"><span class="keyword control flow raise python">raise</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="support type exception python">Exception</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">API Error<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation separator arguments python">,</span> <span class="meta qualified-name python"><span class="meta generic-name python">response</span></span></span><span class="punctuation section arguments end python">)</span></span></span>
    <span class="keyword control flow return python">return</span> <span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">response</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">result<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span>


<span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Gather all DNS records for a domain
</span>
<span class="meta function python"><span class="storage type function python">def</span> <span class="entity name function python"><span class="meta generic-name python">get_records</span></span></span><span class="meta function parameters python"><span class="punctuation section parameters begin python">(</span></span><span class="meta function parameters python"><span class="variable parameter python">domain</span><span class="punctuation section parameters end python">)</span></span><span class="meta function python"><span class="punctuation section function begin python">:</span></span>
    <span class="keyword control flow return python">return</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="variable function python">njalla</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">list-records<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation separator arguments python">,</span> <span class="variable parameter python">domain</span><span class="keyword operator assignment python">=</span><span class="meta qualified-name python"><span class="meta generic-name python">user_domain</span></span></span><span class="punctuation section arguments end python">)</span></span>


<span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Update a DNS record for a domain
</span>
<span class="meta function python"><span class="storage type function python">def</span> <span class="entity name function python"><span class="meta generic-name python">update_record</span></span></span><span class="meta function parameters python"><span class="punctuation section parameters begin python">(</span></span><span class="meta function parameters python"><span class="variable parameter python">domain</span><span class="punctuation separator parameters python">,</span> <span class="variable parameter python">record_id</span><span class="punctuation separator parameters python">,</span> <span class="variable parameter python">record_content</span><span class="punctuation section parameters end python">)</span></span><span class="meta function python"><span class="punctuation section function begin python">:</span></span>
    <span class="keyword control flow return python">return</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="variable function python">njalla</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">edit-record<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation separator arguments python">,</span> <span class="variable parameter python">domain</span><span class="keyword operator assignment python">=</span><span class="meta qualified-name python"><span class="meta generic-name python">domain</span></span><span class="punctuation separator arguments python">,</span> <span class="variable parameter python">id</span><span class="keyword operator assignment python">=</span><span class="meta qualified-name python"><span class="meta generic-name python">record_id</span></span><span class="punctuation separator arguments python">,</span>
                  <span class="variable parameter python">content</span><span class="keyword operator assignment python">=</span><span class="meta qualified-name python"><span class="meta generic-name python">record_content</span></span></span><span class="punctuation section arguments end python">)</span></span>


<span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Get public IP addresses
</span>
<span class="meta qualified-name python"><span class="meta generic-name python">ipv4</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="variable function python">get</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">https://api.ipify.org<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="punctuation section arguments end python">)</span></span><span class="punctuation accessor dot python">.</span><span class="meta generic-name python">text</span>
<span class="meta function-call python"><span class="meta qualified-name python"><span class="support function builtin python">print</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">IPv4: <span class="constant other placeholder python"><span class="punctuation definition placeholder begin python">{</span><span class="punctuation definition placeholder end python">}</span></span><span class="punctuation definition string end python">&#39;</span></span></span><span class="meta function-call python"><span class="meta qualified-name python"><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">format</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">ipv4</span></span></span><span class="punctuation section arguments end python">)</span></span></span><span class="punctuation section arguments end python">)</span></span>
<span class="meta qualified-name python"><span class="meta generic-name python">ipv6</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="variable function python">get</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">https://api64.ipify.org<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="punctuation section arguments end python">)</span></span><span class="punctuation accessor dot python">.</span><span class="meta generic-name python">text</span>
<span class="meta function-call python"><span class="meta qualified-name python"><span class="support function builtin python">print</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">IPv6: <span class="constant other placeholder python"><span class="punctuation definition placeholder begin python">{</span><span class="punctuation definition placeholder end python">}</span></span><span class="punctuation definition string end python">&#39;</span></span></span><span class="meta function-call python"><span class="meta qualified-name python"><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">format</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">ipv6</span></span></span><span class="punctuation section arguments end python">)</span></span></span><span class="punctuation section arguments end python">)</span></span>

<span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Call API to get all DNS records
</span>
<span class="meta qualified-name python"><span class="meta generic-name python">data</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="variable function python">get_records</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">user_domain</span></span></span><span class="punctuation section arguments end python">)</span></span>

<span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Loop through records and check if each one is IPv4 (A) or IPv6 (AAAA)
</span><span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Update only if DNS is different from server IP
</span>
<span class="meta statement for python"><span class="keyword control flow for python">for</span> <span class="meta generic-name python">record</span> <span class="meta statement for python"><span class="keyword control flow for in python">in</span></span></span><span class="meta statement for python"> <span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">data</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">records<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span><span class="punctuation section block for python">:</span></span>
    <span class="meta statement if python"><span class="keyword control flow conditional python">if</span> <span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">record</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">name<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span> <span class="keyword operator comparison python">==</span> <span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">@<span class="punctuation definition string end python">&#39;</span></span></span> <span class="keyword operator logical python">or</span> <span class="meta group python"><span class="punctuation section group begin python">(</span><span class="meta qualified-name python"><span class="meta generic-name python">include_subdomains</span></span> <span class="keyword operator logical python">and</span> <span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">record</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">name<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span> <span class="punctuation separator continuation line python">\</span>
        <span class="keyword operator logical python">in</span> <span class="meta qualified-name python"><span class="meta generic-name python">subdomains</span></span><span class="punctuation section group end python">)</span></span><span class="punctuation section block conditional python">:</span></span>
        <span class="meta statement if python"><span class="keyword control flow conditional python">if</span> <span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">record</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">type<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span> <span class="keyword operator comparison python">==</span> <span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">A<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation section block conditional python">:</span></span>
            <span class="meta statement if python"><span class="keyword control flow conditional python">if</span> <span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">record</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">content<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span> <span class="keyword operator comparison python">==</span> <span class="meta qualified-name python"><span class="meta generic-name python">ipv4</span></span><span class="punctuation section block conditional python">:</span></span>
                <span class="meta function-call python"><span class="meta qualified-name python"><span class="support function builtin python">print</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">record</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">type<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span><span class="punctuation separator arguments python">,</span> <span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">record for<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation separator arguments python">,</span> <span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">record</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">name<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span><span class="punctuation separator arguments python">,</span>
                      <span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">already matches public IPv4 address. Skipping...<span class="punctuation definition string end python">&#39;</span></span></span>
                      </span><span class="punctuation section arguments end python">)</span></span>
            <span class="meta statement conditional python"><span class="keyword control flow conditional python">else</span><span class="punctuation section block python">:</span></span>
                <span class="meta function-call python"><span class="meta qualified-name python"><span class="support function builtin python">print</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">IPv4 of<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation separator arguments python">,</span> <span class="meta qualified-name python"><span class="meta generic-name python">ipv4</span></span><span class="punctuation separator arguments python">,</span>
                      <span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">does not match Njalla<span class="punctuation definition string end python">&#39;</span></span></span><span class="meta qualified-name python"><span class="meta generic-name python">s</span></span> <span class="meta qualified-name python"><span class="meta generic-name python">value</span></span> <span class="meta qualified-name python"><span class="meta generic-name python">of</span></span><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">,<span class="invalid illegal unclosed-string python">
</span></span></span>                      <span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">record</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">content<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span><span class="punctuation separator arguments python">,</span> <span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">. Updating...<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="punctuation section arguments end python">)</span></span>
                <span class="meta function-call python"><span class="meta qualified-name python"><span class="variable function python">update_record</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">user_domain</span></span><span class="punctuation separator arguments python">,</span> <span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">record</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">id<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span><span class="punctuation separator arguments python">,</span> <span class="meta qualified-name python"><span class="meta generic-name python">ipv4</span></span></span><span class="punctuation section arguments end python">)</span></span>
        <span class="meta statement conditional python"><span class="keyword control flow conditional python">elif</span></span> <span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">record</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">type<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span> <span class="keyword operator comparison python">==</span> <span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">AAAA<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation separator annotation variable python">:</span>
            <span class="meta statement if python"><span class="keyword control flow conditional python">if</span> <span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">record</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">content<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span> <span class="keyword operator comparison python">==</span> <span class="meta qualified-name python"><span class="meta generic-name python">ipv6</span></span><span class="punctuation section block conditional python">:</span></span>
                <span class="meta function-call python"><span class="meta qualified-name python"><span class="support function builtin python">print</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">record</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">type<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span><span class="punctuation separator arguments python">,</span> <span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">record for<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation separator arguments python">,</span> <span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">record</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">name<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span><span class="punctuation separator arguments python">,</span>
                      <span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">already matches public IPv6 address. Skipping...<span class="punctuation definition string end python">&#39;</span></span></span>
                      </span><span class="punctuation section arguments end python">)</span></span>
            <span class="meta statement conditional python"><span class="keyword control flow conditional python">else</span><span class="punctuation section block python">:</span></span>
                <span class="meta function-call python"><span class="meta qualified-name python"><span class="support function builtin python">print</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">IPv6 of<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation separator arguments python">,</span> <span class="meta qualified-name python"><span class="meta generic-name python">ipv6</span></span><span class="punctuation separator arguments python">,</span>
                      <span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">does not match Njalla<span class="punctuation definition string end python">&#39;</span></span></span><span class="meta qualified-name python"><span class="meta generic-name python">s</span></span> <span class="meta qualified-name python"><span class="meta generic-name python">value</span></span> <span class="meta qualified-name python"><span class="meta generic-name python">of</span></span><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">,<span class="invalid illegal unclosed-string python">
</span></span></span>                      <span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">record</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">content<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span><span class="punctuation separator arguments python">,</span> <span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">. Updating...<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="punctuation section arguments end python">)</span></span>
                <span class="meta function-call python"><span class="meta qualified-name python"><span class="variable function python">update_record</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">user_domain</span></span><span class="punctuation separator arguments python">,</span> <span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">record</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">id<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span><span class="punctuation separator arguments python">,</span> <span class="meta qualified-name python"><span class="meta generic-name python">ipv6</span></span></span><span class="punctuation section arguments end python">)</span></span></span></code></pre>
<h3 id="running-the-script"><span class="section-number-3">2.2.</span> Running the Script</h3>
<p>Once you've created the script and are ready to test it, run the following command:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">python3</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/ddns/ddns.py</span></span></code></pre>
<h3 id="setting-the-script-to-run-automatically"><span class="section-number-3">2.3.</span> Setting the Script to Run Automatically</h3>
<p>To make sure the scripts run automatically, add it to the <code class="verbatim">cron</code> file so that it will run on a schedule. To do this, open the <code class="verbatim">cron</code> file:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">crontab</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>e</span></span></span></code></pre>
<p>In the cron file, paste the following at the bottom of the editor in order to check the IP every five minutes:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">*/5</span></span><span class="meta function-call arguments shell"> <span class="keyword operator regexp quantifier shell">*</span> <span class="keyword operator regexp quantifier shell">*</span> <span class="keyword operator regexp quantifier shell">*</span> <span class="keyword operator regexp quantifier shell">*</span> python3 /home/<span class="keyword operator assignment redirection shell">&lt;</span>your_username<span class="keyword operator assignment redirection shell">&gt;</span>/ddns/ddns.py</span></span></code></pre>
]]></description>
    </item>
    <item>
      <title>Leaving the Office</title>
      <link>https://cleberg.net/blog/leaving-the-office.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/leaving-the-office.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Thu, 10 Feb 2022 00:00:00 +0000</pubDate>
      <category>personal</category>
      <description><![CDATA[<h2 id="the-working-world-is-changing"><span class="section-number-2">1.</span> The Working World is Changing</h2>
<p>There has been a trend for the past few years of companies slowly realizing that the pandemic is not just a temporary state that will go away eventually and let everything return to the way it was before. In terms of business and employment, this means that more and more jobs are being offered as permanently remote roles.</p>
<p>I had always dreamt of working from home but thought of it as a fantasy, especially since I did not want to move over into the software development field. However, I have found that almost all roles being sent to me via recruiters are permanently remote (although most are limited to US citizens or even region-locked for companies who only operate in select states).</p>
<p>I decided to take a look back at my relatively short career so far and compare the positive and negative effects of the different work environments I've been in.</p>
<h2 id="in-person-offices"><span class="section-number-2">2.</span> In-Person Offices</h2>
<h3 id="retail-internship"><span class="section-number-3">2.1.</span> Retail Internship</h3>
<p>I started my first job as a management intern at a busy retail pharmacy, working my 40-hour weeks on my feet. As these retail stores don't believe in resting or sitting down, you can guarantee that you will spend entire shifts standing, walking, or running around the store. Unfortunately, I worked at a time when our store didn't have enough managers, so I spent the majority of my tenure at the store running and breaking a sweat.</p>
<p>Now, things aren't all bad in retail stores like this. It is definitely tiring and inefficient to force employees to work constantly, or pretend to work if there's nothing to do, and not allow anyone to sit down. However, if you are able to operate a retail store with a limited crew and provide enough comfort and support, I believe these jobs could be both comfortable and efficient.</p>
<h3 id="semi-private-cubicles"><span class="section-number-3">2.2.</span> Semi-Private Cubicles</h3>
<p>After about a year, I was able to find another internship - this time, it was in my field of interest: internal auditing. This was for a life insurance company that was well over 100 years old. The age of the company shows if you work there, as most people in management are well into their 40s-60s with little to no youthful leadership in the company. Likewise, they owned a large headquarters in a nice area of town with plenty of space, parking, etc.</p>
<p>One upside is that each person gets their own large L-shaped desk, formed into cubicles that house 4 desks/employees. These "pods" of 4-person cubicles are linked throughout each floor of the headquarters (except the sales people, who had that open-floor concept going on). The walls of the cubicle were tall and provided a lot of privacy and sound-proofing, except when I used the standing desk feature (I'm over 6 feet tall, so probably not an issue for most people).</p>
<p>I loved this environment, it allowed me to focus on my work with minimal distractions, but also allowed easy access, so I could spin around in my chair and chat with my friends without leaving my chair. This is the closest I've been to a home office environment (which is my personal favorite, as I'll get to later in this post).</p>
<h3 id="semi-open-floor-concept"><span class="section-number-3">2.3.</span> Semi-Open Floor Concept</h3>
<p>When I shifted to my first full-time internal audit job out of college, I was working at a company that was headquartered on a floor in a downtown high-rise building. The company was only about 20 years old when I worked there and were trying a lot of new things to attract young talent, one of which was a semi-open floor concept for the office. My department worked just around the hallway corner from the executive offices and used that "modern" layout young tech companies started using in the 2000s/2010s.</p>
<p>Each desk was brief, and you could look most coworkers in the face without moving from your chair, I hated this so much. Directly to my left was the Chief Audit Executive (our department's leading boss), and his desk was pointed so that his face would stare straight at my desk all day. I spent more time thinking about who was looking at me or checking on me than actually working.</p>
<p>The other annoying part of the open concept they used was that the kitchen area and pathways were too close to everyone's desks (since the desks were spread out, to provide space or something), so noise and conversation would be constant throughout the day while you try to work. For someone like me, who needs silence to get work done, that was a non-starter.</p>
<h3 id="hotel-office-concept"><span class="section-number-3">2.4.</span> Hotel Office Concept</h3>
<p>I currently work for a company remotely (for now) and travel to the office every once in a while for events and to help coach the staff underneath me. The office I visit uses the hotel desk concept, where you need to check in at a touch screen when you enter the office and "rent" a desk for the day. The same goes for offices and meeting rooms.</p>
<p>These desks are flat-top only and do not have any walls at all. In addition, they're stacked with one row of 4 desks facing another row of 4 desks. These pairs of desk rows are repeated through the office.</p>
<p>This means that when I go, I need to rent a random desk or try to remember the unique identification (ID) numbers on desks I like. Once I rent it, I have to make sure no one sat down in that desk without renting it. Then, I can sit down and work, but will probably need to adjust the monitors so that I'm not staring in the face of the person across from me all day. Finally, I need to wear headphones as this environment does nothing to provide you with peace or quiet.</p>
<p>Luckily, you can rent offices with doors that offer quiet and privacy, which can be very nice if you have a lot of meetings or webinars on a certain day.</p>
<h2 id="home-office"><span class="section-number-2">3.</span> Home Office</h2>
<p>Okay, now let's finally get to the home office concept. I have worked from home for a little over two years at this point, across three different jobs/employers. Over this time, I have experimented with a plethora of different organizational ideas, desks, and room layouts to find what works best for me.</p>
<p>These things might not apply to you, and that's fine. Everyone has a different situation, and I really don't think you'll know what works until you try.</p>
<h3 id="tip-1"><span class="section-number-3">3.1.</span> Tip #1</h3>
<p>Let's start with my top rule for a home office:</p>
<blockquote>
<p>If you live with others, working in a shared space is not effective.</p>
</blockquote>
<p>It just does not work. If you have another person sleeping in your bedroom, it is difficult to manage your work schedule with their sleeping/work/school schedule. If they wake up after you need to start work, you might wake them up or have to suffer the agony of staring at bright screens in a dark room.</p>
<p>In a similar vein, working from a location such as the living room likely won't work either. Distractions will come far more frequently: televisions, cooking, cleaning, deliveries, etc. If you're like me, you'll end up playing a game instead of actually doing any work.</p>
<h3 id="tip-2"><span class="section-number-3">3.2.</span> Tip #2</h3>
<p>Okay, the second thing I've discovered that works for me:</p>
<blockquote>
<p>Use the pomodoro method (or something similar) to balance work tasks with personal tasks.</p>
</blockquote>
<p>I use a very casual version of the pomodoro method where I will work for 1-2 hours (usually set in strict intervals like 1, 1.5, 2 hours) and then will allow myself 30-60 minutes for personal tasks. This schedule works for me, since my work schedule really only comes to 3-6 hours of work per day.</p>
<p>In this case, I'll work through my list of tasks for an hour or two and then give myself personal time to get drinks and food, wash dishes, put clothes in the washer, get the mail, etc. If you're in a convenient location, this usually gives time for things like getting groceries (as long as you're not a slow shopper).</p>
<h3 id="tip-3"><span class="section-number-3">3.3.</span> Tip #3</h3>
<p>While I listed this one as number three, I don't think I'd accomplish anything without it:</p>
<blockquote>
<p>Document everything: even things you didn't before - such as task lists and notes from casual calls or meetings.</p>
</blockquote>
<p>I've noticed that staying in an office gave me more constant reminders of outstanding tasks or facts I had learned in a conversation. Translating everything to a digital world has made me lose a bit of that focus (perhaps since I don't have visual reminders?).</p>
<p>Keeping a running task list of all things I have to do - even potential tasks! - has helped me keep up without missing anything small. Likewise, keeping notes for ALL meetings and calls, no matter how casual/quick, has improved my retention immensely. Beyond helping my mental recollection, it has saved me numerous times when I need to do a keyword search for some topic that was discussed 6+ months ago.</p>
<h3 id="tip-4"><span class="section-number-3">3.4.</span> Tip #4</h3>
<p>Okay, last one for now.</p>
<blockquote>
<p>Keep your work area clean.</p>
</blockquote>
<p>This one is straightforward, but I know some people struggle with cleanliness or may not believe it makes a difference. Trust me, keeping your desk area clean and organized makes a huge difference, both mentally and emotionally.</p>
<p>Just think about it, you walk into your home office and see a clean desk with a laptop, dock, monitors, keyboard, mouse, and a notepad with a pen on top.</p>
<p>Now imagine the opposite, there's an office with the same equipment, but there are clothes hanging on the chair, empty drink bottles, candy wrappers and dirty plates. This can take both a mental and emotional toll by bringing constant disarray and stress into your working environment.</p>
<p>Just keep things clean each day, and you won't need to do any big cleaning days to recover.</p>
<h2 id="my-preferences"><span class="section-number-2">4.</span> My Preferences</h2>
<p>I've talked about the different environments I've worked in and expressed some honest thoughts on pros or cons to each, but what do I prefer? Well, if you're reading along, you should be able to tell that I much prefer a home office above all else.</p>
<p>Being able to control my own day and allot my time as needed has brought a calmness to my life and has allowed me to maximize each day. I feel far more effective and efficient in a home office than any other office, especially open-office layouts.</p>
<p>If I do need to return to an office part-time in the future, I really hope the office will have privacy and quietness in order for me to get my work done.</p>
]]></description>
    </item>
    <item>
      <title>I Passed the CISA Exam</title>
      <link>https://cleberg.net/blog/cisa.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/cisa.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Sat, 04 Dec 2021 00:00:00 +0000</pubDate>
      <category>audit</category>
      <description><![CDATA[<h2 id="what-is-the-cisa"><span class="section-number-2">1.</span> What is the CISA?</h2>
<p>For those of you lucky enough not to be knee-deep in the world of information technology (IT) and information systems (IS) auditing, the <a href="https://www.isaca.org/credentialing/cisa">CISA</a> (Certified Information Systems Auditor) certification and exam are part of ISACA's suite of certifications. As I often explain it to people like my family, it basically means you're employed to use your knowledge of information systems, regulations, common threats, risks, etc. in order to assess an organization's current control of their risk. If a risk isn't controlled (and the company doesn't want to accept the risk), an IS auditor will suggest implementing a control to address that risk.</p>
<p>Now, the CISA certification itself is, in my opinion, the main certification for this career. While certifications such as the CPA (Certified Public Accountant) or CISSP (Certified Information Systems Security Professional) are beneficial, nothing matches the power of the CISA for an IS auditor when it comes to getting hired, getting a raise/bonus, or earning respect in the field.</p>
<p>However, to be honest, I am a skeptic of most certifications. I understand the value they hold in terms of how much you need to commit to studying or learning on the job, as well as the market value for certifications such as the CISA. But I also have known some very <del>incompetent</del> <em>less than stellar</em> auditors who have relevant certifications.</p>
<p>The same goes for most industries: if a person is good at studying, they can earn the certification. However, that knowledge means nothing unless you're actually able to use it in real life and perform as expected of a certification holder. The challenge comes when people are hired or connected strictly because of their certifications or resume; you need to see a person work before you can assume them having a CISA means they're better than someone without the CISA.</p>
<p>Okay, rant over. Certifications are generally accepted as a measuring stick of commitment and quality of an employee, so I am accepting it too.</p>
<h2 id="exam-content"><span class="section-number-2">2.</span> Exam Content</h2>
<p>The CISA is broken down into five sections, each weighted with a percentage of test questions that may appear.</p>
<p>Since the exam contains 150 questions, here's how those sections break down:</p>
<table>
<thead>
<tr><th>Exam Section</th><th>Percentage of Exam</th><th>Questions</th></tr>
</thead>
<tbody>
<tr><td>1</td><td>21%</td><td>32</td></tr>
<tr><td>2</td><td>17%</td><td>26</td></tr>
<tr><td>3</td><td>12%</td><td>18</td></tr>
<tr><td>4</td><td>23%</td><td>34</td></tr>
<tr><td>5</td><td>27%</td><td>40</td></tr>
<tr><td><strong>Grand Total</strong></td><td><strong>100%</strong></td><td><strong>150</strong></td></tr>
</tbody>
</table>
<h2 id="my-studying-habits"><span class="section-number-2">3.</span> My Studying Habits</h2>
<p>This part is a little hard for me to break down into specific detail due to the craziness of the last year. While I officially purchased my studying materials in December 2020 and opened them to "start studying" in January 2021, I really wasn't able to study much due to the demands of my job and personal life.</p>
<p>Let me approach this from a few different viewpoints.</p>
<h3 id="study-materials"><span class="section-number-3">3.1.</span> Study Materials</h3>
<p>Let's start by discussing the study materials I purchased. I'll be referring to #1 as the CRM (CISA Review Manual) and #2 as the QAE (Questions, Answers &amp; Explanations).</p>
<ol>
<li><a href="https://store.isaca.org/s/store#/store/browse/detail/a2S4w000004KoCbEAK">CISA Review Manual, 27th Edition | Print</a></li>
<li><a href="https://store.isaca.org/s/store#/store/browse/detail/a2S4w000004KoCcEAK">CISA Review Questions, Answers &amp; Explanations Manual, 12th Edition | Print</a></li>
</ol>
<p>The CRM is an excellent source of information and could honestly be used as a reference for most IS auditors as a learning reference during their daily audit responsibilities. However, it is <strong>full</strong> of information and can be overloading if you're not good at filtering out useless information while studying.</p>
<p>The QAE is the real star of the show here. This book contains 1000 questions, separated by exam section, and a practice exam. My only complaint about the QAE is that each question is immediately followed with the correct answer and explanations below it, which means I had to use something to constantly cover the answers while I was studying.</p>
<p>I didn't use the online database version of the QAE, but I've heard that it's easier to use than the printed book. However, it is more expensive ($299 database vs $129 book) which might be important if you're paying for materials yourself.</p>
<p>In terms of question difficulty, I felt that the QAE was a good representation of the actual exam. I've seen a lot of people online say it wasn't accurate to the exam or that it was much easier/harder, but I disagree with all of those. The exam was fairly similar to the QAE, just focusing on whichever topics they chose for my version of the exam.</p>
<p>If you understand the concepts, skim the CRM (and read in-depth on topics you struggle with), and use the QAE to continue practicing exam-like questions, you should be fine. I didn't use any online courses, videos, etc. - the ISACA materials are more than enough.</p>
<h3 id="studying-process"><span class="section-number-3">3.2.</span> Studying Process</h3>
<p>While I was able to briefly read through sections 1 and 2 in early 2021, I had to stop and take a break from February/March to September. I switched jobs in September, which allowed me a lot more free time to study.</p>
<p>In September, I studied sections 3-5, took notes, and did a quick review of the section topics. Once I felt comfortable with my notes, I took a practice exam from the QAE manual and scored 70% (105/150).</p>
<p>Here's a breakdown of my initial practice exam:</p>
<table>
<thead>
<tr><th>Exam Section</th><th>Incorrect</th><th>Correct</th><th>Grand Total</th><th>Percent</th></tr>
</thead>
<tbody>
<tr><td>1</td><td>8</td><td>25</td><td>33</td><td>76%</td></tr>
<tr><td>2</td><td>5</td><td>20</td><td>25</td><td>80%</td></tr>
<tr><td>3</td><td>6</td><td>12</td><td>18</td><td>67%</td></tr>
<tr><td>4</td><td>10</td><td>23</td><td>33</td><td>70%</td></tr>
<tr><td>5</td><td>16</td><td>25</td><td>41</td><td>61%</td></tr>
<tr><td><strong>Grand Total</strong></td><td><strong>45</strong></td><td><strong>105</strong></td><td><strong>150</strong></td><td><strong>70%</strong></td></tr>
</tbody>
</table>
<p>As I expected, my toughest sections were related to project management, development, implementation, and security.</p>
<p>This just leaves October and November. For these months, I tried to practice every few days, doing 10 questions for each section, until the exam. This came out to 13 practice sessions, ~140 questions per section, and ~700 questions total.</p>
<p>While some practice sessions were worse and some were better, the final results were similar to my practice exam results. As you can see below, my averages were slightly worse than my practice exam. However, I got in over 700 questions of practice and, most importantly, <em>I read through the explanations every time I answered incorrectly and learned from my mistakes</em>.</p>
<table>
<thead>
<tr><th>Exam Section</th><th>Incorrect</th><th>Correct</th><th>Grand Total</th><th>Percent</th></tr>
</thead>
<tbody>
<tr><td>1</td><td>33</td><td>108</td><td>141</td><td>77%</td></tr>
<tr><td>2</td><td>33</td><td>109</td><td>142</td><td>77%</td></tr>
<tr><td>3</td><td>55</td><td>89</td><td>144</td><td>62%</td></tr>
<tr><td>4</td><td>52</td><td>88</td><td>140</td><td>63%</td></tr>
<tr><td>5</td><td>55</td><td>85</td><td>140</td><td>61%</td></tr>
<tr><td><strong>Grand Total</strong></td><td><strong>228</strong></td><td><strong>479</strong></td><td><strong>707</strong></td><td><strong>68%</strong></td></tr>
</tbody>
</table>
<h2 id="results"><span class="section-number-2">4.</span> Results</h2>
<p>Now, how do the practice scores reflect my actual results? After all, it's hard to tell how good a practice regimen is unless you see how it turns out.</p>
<table>
<thead>
<tr><th>Exam Section</th><th>Section Name</th><th>Score</th></tr>
</thead>
<tbody>
<tr><td>1</td><td>Information Systems Auditing Process</td><td>678</td></tr>
<tr><td>2</td><td>Governance and Management of IT</td><td>590</td></tr>
<tr><td>3</td><td>Information Systems Acquisition, Development, and Implementation</td><td>721</td></tr>
<tr><td>4</td><td>Information Systems Operations and Business Resilience</td><td>643</td></tr>
<tr><td>5</td><td>Protection of Information Assets</td><td>511</td></tr>
</tbody>
</table>
<p>Now, in order to pass the CISA, you need at least 450 on a sliding scale of 200-800. Personally, I really have no clue what an average CISA score is. After a <em>very</em> brief look online, I can see that the high end is usually in the low 700s. In addition, only about 50-60% of people pass the exam.</p>
<p>Given this information, I feel great about my scores. 616 may not be phenomenal, and I wish I had done better on sections 2 &amp; 5, but my practicing seems to have worked very well overall.</p>
<p>However, the practice results do not conform to the actual results. Section 2 was one of my highest practice sections and was my second-lowest score in the exam. Conversely, section 3 was my second-lowest practice section and turned out to be my highest actual score!</p>
<p>After reflecting, it is obvious that if you have any background on the CISA topics at all, the most important part of studying is doing practice questions. You really need to understand how to read the questions critically and pick the best answer.</p>
<h2 id="looking-forward"><span class="section-number-2">5.</span> Looking Forward</h2>
<p>I am extremely happy that I was finally able to pass the CISA. Looking to the future, I'm not sure what's next in terms of professional learning. My current company offers internal learning courses, so I will most likely focus on that if I need to gain more knowledge in certain areas.</p>
<p>To be fair, even if you pass the CISA, it's hard to become an expert on any specific topic found within. My career may take me in a different direction, and I might need to focus more on security or networking certifications (or possibly building a better analysis/visualization portfolio if I want to go into data analysis/science).</p>
<p>All I know is that I am content at the moment and extremely proud of my accomplishment.</p>
]]></description>
    </item>
    <item>
      <title>Apache Rewrite Rules for Extensionless URLs</title>
      <link>https://cleberg.net/blog/apache-redirect.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/apache-redirect.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Sat, 09 Oct 2021 00:00:00 +0000</pubDate>
      <category>web</category>
      <description><![CDATA[<h2 id="the-problem"><span class="section-number-2">1.</span> The Problem</h2>
<p>After recently switching static site generators (SSG), my blog URLs (uniform resource locators) changed with no option to preserve the classic <code class="verbatim">.html</code> extension at the end of my blog post URLs.</p>
<p>I really disliked using my old SSG (<a href="https://jekyllrb.com">Jekyll</a>) and prefer my new tool (<a href="https://www.getzola.org">Zola</a>) much more, so I was determined to figure out a way to get the proper redirect set up so that people who find my posts online aren't constantly met by 404 errors.</p>
<h2 id="the-solution"><span class="section-number-2">2.</span> The Solution</h2>
<p>To solve this problem, I really needed to solve two pieces:</p>
<ol>
<li>Redirect all blog post URL requests from <code class="verbatim">/blog/some-post.html</code> to <code class="verbatim">/blog/some-post/</code>.</li>
<li>Ensure that no other <code class="verbatim">.html</code> files are redirected, such as <code class="verbatim">index.html</code>.</li>
</ol>
<p>After <em>a lot</em> of tweaking and testing, I believe I have finally found the solution. The solution is shown below.</p>
<pre><code class="language-conf">RewriteEngine On
RewriteCond %{REQUEST_URI} !\index.html$ [NC]
RewriteRule ^(.*).html$ https://example.com/$1 [R=301,L]</code></pre>
<p>This piece of code in the Apache <code class="verbatim">.conf</code> or <code class="verbatim">.htaccess</code> file will do the following:</p>
<ol>
<li>Turn on the RewriteEngine so that we can modify URLs.</li>
<li>Ignore any <code class="verbatim">index.html</code> files from the rule we are about to specify.</li>
<li>Find any <code class="verbatim">.html</code> files within the website directory and redirect it to exclude the file extension.</li>
<li>The final piece is adding the trailing slash (<code class="verbatim">/</code>) at the end of the URL - you'll notice that I don't have an Apache rule for that since Apache handles that automatically.</li>
</ol>
]]></description>
    </item>
    <item>
      <title>Audit Sampling with Pandas</title>
      <link>https://cleberg.net/blog/audit-sampling.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/audit-sampling.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Wed, 25 Aug 2021 00:00:00 +0000</pubDate>
      <category>audit</category>
      <description><![CDATA[<h2 id="introduction"><span class="section-number-2">1.</span> Introduction</h2>
<p>For anyone who is familiar with internal auditing, external auditing, or consulting, you will understand how tedious audit testing can become when you are required to test large swaths of data. When we cannot establish an automated means of testing an entire population, we generate samples to represent the population of data. This helps ensure we can have a small enough data pool to test and that our results still represent the population.</p>
<p>However, sampling data within the world of audit still seems to confuse quite a lot of people. While some audit-focused tools have introduced sampling functionality (e.g. Wdesk), many audit departments and firms cannot use software like this due to certain constraints, such as the team's budget or knowledge. Here is where this article comes in: we're going to use <a href="https://www.python.org">Python</a>, a free and open-source programming language, to generate random samples from a dataset in order to suffice numerous audit situations.</p>
<h2 id="audit-requirements-for-sampling"><span class="section-number-2">2.</span> Audit Requirements for Sampling</h2>
<p>Before we get into the details of how to sample with Python, I want to make sure I discuss the different requirements that auditors may have of samples used within their projects.</p>
<h3 id="randomness"><span class="section-number-3">2.1.</span> Randomness</h3>
<p>First, let's discuss randomness. When testing out new technology to help assist with audit sampling, you need to understand exactly how your samples are being generated. For example, if the underlying function is just picking every 57th element from a list, that's not truly random; it's a systematic form of sampling. Luckily, since Python is open-source, we have access to its codebase. Through this blog post, I will be using the <a href="https://pandas.pydata.org">pandas</a> module in order to generate the random samples. More specifically, I will be using the <a href="https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.sample.html">pandas.DataFrame.sample</a> function provided by Pandas.</p>
<p>Now that you know what you're using, you can always check out the code behind <code class="verbatim">pandas.DataFrame.sample</code>. This function does a lot of work, but we really only care about the following snippets of code:</p>
<pre><code class="language-python highlight"><span class="source python"><span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Process random_state argument
</span><span class="meta qualified-name python"><span class="meta generic-name python">rs</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">com</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">random_state</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">random_state</span></span></span><span class="punctuation section arguments end python">)</span></span>

<span class="constant language python">...</span>

<span class="meta qualified-name python"><span class="meta generic-name python">locs</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">rs</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">choice</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">axis_length</span></span><span class="punctuation separator arguments python">,</span> <span class="variable parameter python">size</span><span class="keyword operator assignment python">=</span><span class="meta qualified-name python"><span class="meta generic-name python">n</span></span><span class="punctuation separator arguments python">,</span> <span class="variable parameter python">replace</span><span class="keyword operator assignment python">=</span><span class="meta qualified-name python"><span class="meta generic-name python">replace</span></span><span class="punctuation separator arguments python">,</span> <span class="variable parameter python">p</span><span class="keyword operator assignment python">=</span><span class="meta qualified-name python"><span class="meta generic-name python">weights</span></span></span><span class="punctuation section arguments end python">)</span></span>
<span class="meta qualified-name python"><span class="meta generic-name python">result</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="variable language python">self</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">take</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">locs</span></span><span class="punctuation separator arguments python">,</span> <span class="variable parameter python">axis</span><span class="keyword operator assignment python">=</span><span class="meta qualified-name python"><span class="meta generic-name python">axis</span></span></span><span class="punctuation section arguments end python">)</span></span>
<span class="meta statement if python"><span class="keyword control flow conditional python">if</span> <span class="meta qualified-name python"><span class="meta generic-name python">ignore_index</span></span><span class="punctuation section block conditional python">:</span></span>
<span class="meta qualified-name python"><span class="meta generic-name python">result</span><span class="punctuation accessor dot python">.</span><span class="meta generic-name python">index</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">ibase</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">default_index</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta function-call python"><span class="meta qualified-name python"><span class="support function builtin python">len</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">result</span></span></span><span class="punctuation section arguments end python">)</span></span></span><span class="punctuation section arguments end python">)</span></span>

<span class="keyword control flow return python">return</span> <span class="meta qualified-name python"><span class="meta generic-name python">result</span></span></span></code></pre>
<p>The block of code above shows you that if you assign a <code class="verbatim">random_state</code> argument when you run the function, that will be used as a seed number in the random generation and will allow you to reproduce a sample, given that nothing else changes. This is critical to the posterity of audit work. After all, how can you say your audit process is adequately documented if the next person can't run the code and get the same sample? The final piece here on randomness is to look at the <a href="https://docs.python.org/3/library/random.html#random.choice">choice</a> function used above. This is the crux of the generation and can also be examined for more detailed analysis on its reliability. As far as auditing goes, we will trust that these functions are mathematically random.</p>
<h3 id="sample-sizes"><span class="section-number-3">2.2.</span> Sample Sizes</h3>
<p>As mentioned in the intro, sampling is only an effective method of auditing when it truly represents the entire population. While some audit departments or firms may consider certain judgmental sample sizes to be adequate, you may need to rely on statistically-significant confidence levels of sample testing at certain</p>
<p>points. I will demonstrate both here. For statistically-significant confidence levels, most people will assume a 90% - 99% confidence level. In order to actually calculate the correct sample size, it is best to use statistical tools due to the tedious math work required. For example, for a population of 1000, and a 90% confidence level that no more than 5% of the items are nonconforming, you would sample 45 items.</p>
<p>However, in my personal experience, many audit departments and firms do not use statistical sampling. Most people use a predetermined, often proprietary, table that will instruct auditors which sample sizes to choose. This allows for uniform testing and reduces overall workload. See the table below for a common implementation of sample sizes:</p>
<table>
<thead>
<tr><th>Control Frequency</th><th>Sample Size (High Risk)</th><th>Sample Size (Low Risk)</th></tr>
</thead>
<tbody>
<tr><td>More Than Daily</td><td>40</td><td>25</td></tr>
<tr><td>Daily</td><td>40</td><td>25</td></tr>
<tr><td>Weekly</td><td>12</td><td>5</td></tr>
<tr><td>Monthly</td><td>5</td><td>3</td></tr>
<tr><td>Quarterly</td><td>2</td><td>2</td></tr>
<tr><td>Semi-Annually</td><td>1</td><td>1</td></tr>
<tr><td>Annually</td><td>1</td><td>1</td></tr>
<tr><td>Ad-hoc</td><td>1</td><td>1</td></tr>
</tbody>
</table>
<h4 id="sampling-with-python-pandas"><span class="section-number-4">2.2.1.</span> Sampling with Python &amp; Pandas</h4>
<p>In this section, I am going to cover a few basic audit situations that require sampling. While some situations may require more effort, the syntax, organization, and intellect used remain largely the same. If you've never used Python before, note that lines starting with a '<code class="verbatim">#</code>' symbol are called comments, and they will be skipped by Python. I highly recommend taking a quick tutorial online to understand the basics of Python if any of the code below is confusing to you.</p>
<h3 id="simple-random-sample"><span class="section-number-3">2.3.</span> Simple Random Sample</h3>
<p>First, let's look at a simple, random sample. The code block below will import the <code class="verbatim">pandas</code> module, load a data file, sample the data, and export the sample to a file.</p>
<pre><code class="language-python highlight"><span class="source python"><span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Import the Pandas module
</span><span class="meta statement import python"><span class="keyword control import python">import</span> <span class="meta qualified-name python"><span class="meta generic-name python">pandas</span></span></span>

<span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Specify where to find the input file &amp; where to save the final sample
</span><span class="meta qualified-name python"><span class="meta generic-name python">file_input</span></span> <span class="keyword operator assignment python">=</span> <span class="storage type string python">r</span><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python"><span class="source regexp python">Population Data<span class="constant character character-class regexp">.</span>xlsx</span><span class="punctuation definition string end python">&#39;</span></span></span>
<span class="meta qualified-name python"><span class="meta generic-name python">file_output</span></span> <span class="keyword operator assignment python">=</span> <span class="storage type string python">r</span><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python"><span class="source regexp python">Sample<span class="constant character character-class regexp">.</span>xlsx</span><span class="punctuation definition string end python">&#39;</span></span></span>

<span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Load the data with pandas
</span><span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Remember to use the sheet_name parameter if your Excel file has multiple sheets
</span><span class="meta qualified-name python"><span class="meta generic-name python">df</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">pandas</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">read_excel</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">file_input</span></span></span><span class="punctuation section arguments end python">)</span></span>

<span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Sample the data for 25 selections
</span><span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Remember to always use the random_state parameter so the sample can be re-performed
</span><span class="meta qualified-name python"><span class="meta generic-name python">sample</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">df</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">sample</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="variable parameter python">n</span><span class="keyword operator assignment python">=</span><span class="constant numeric integer decimal python">25</span><span class="punctuation separator arguments python">,</span> <span class="variable parameter python">random_state</span><span class="keyword operator assignment python">=</span><span class="constant numeric integer decimal python">0</span></span><span class="punctuation section arguments end python">)</span></span>

<span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Save the sample to Excel
</span><span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">sample</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">to_excel</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">file_output</span></span></span><span class="punctuation section arguments end python">)</span></span></span></code></pre>
<h3 id="simple-random-sample-using-multiple-input-files"><span class="section-number-3">2.4.</span> Simple Random Sample: Using Multiple Input Files</h3>
<p>Now that we've created a simple sample, let's create a sample from multiple files.</p>
<pre><code class="language-python highlight"><span class="source python"><span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Import the Pandas module
</span><span class="meta statement import python"><span class="keyword control import python">import</span> <span class="meta qualified-name python"><span class="meta generic-name python">pandas</span></span></span>

<span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Specify where to find the input file &amp; where to save the final sample
</span><span class="meta qualified-name python"><span class="meta generic-name python">file_input_01</span></span> <span class="keyword operator assignment python">=</span> <span class="storage type string python">r</span><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python"><span class="source regexp python">Population Data Q1<span class="constant character character-class regexp">.</span>xlsx</span><span class="punctuation definition string end python">&#39;</span></span></span>
<span class="meta qualified-name python"><span class="meta generic-name python">file_input_02</span></span> <span class="keyword operator assignment python">=</span> <span class="storage type string python">r</span><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python"><span class="source regexp python">Population Data Q2<span class="constant character character-class regexp">.</span>xlsx</span><span class="punctuation definition string end python">&#39;</span></span></span>
<span class="meta qualified-name python"><span class="meta generic-name python">file_input_03</span></span> <span class="keyword operator assignment python">=</span> <span class="storage type string python">r</span><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python"><span class="source regexp python">Population Data Q3<span class="constant character character-class regexp">.</span>xlsx</span><span class="punctuation definition string end python">&#39;</span></span></span>
<span class="meta qualified-name python"><span class="meta generic-name python">file_output</span></span> <span class="keyword operator assignment python">=</span> <span class="storage type string python">r</span><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python"><span class="source regexp python">Sample<span class="constant character character-class regexp">.</span>xlsx</span><span class="punctuation definition string end python">&#39;</span></span></span>

<span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Load the data with pandas
</span><span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Remember to use the sheet_name parameter if your Excel file has multiple sheets
</span><span class="meta qualified-name python"><span class="meta generic-name python">df_01</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">pandas</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">read_excel</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">file_input_01</span></span></span><span class="punctuation section arguments end python">)</span></span>
<span class="meta qualified-name python"><span class="meta generic-name python">df_02</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">pandas</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">read_excel</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">file_input_02</span></span></span><span class="punctuation section arguments end python">)</span></span>
<span class="meta qualified-name python"><span class="meta generic-name python">df_03</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">pandas</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">read_excel</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">file_input_03</span></span></span><span class="punctuation section arguments end python">)</span></span>

<span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Sample the data for 5 selections from each quarter
</span><span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Remember to always use the random_state parameter so the sample can be re-performed
</span><span class="meta qualified-name python"><span class="meta generic-name python">sample_01</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">df_01</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">sample</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="variable parameter python">n</span><span class="keyword operator assignment python">=</span><span class="constant numeric integer decimal python">5</span><span class="punctuation separator arguments python">,</span> <span class="variable parameter python">random_state</span><span class="keyword operator assignment python">=</span><span class="constant numeric integer decimal python">0</span></span><span class="punctuation section arguments end python">)</span></span>
<span class="meta qualified-name python"><span class="meta generic-name python">sample_02</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">df_02</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">sample</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="variable parameter python">n</span><span class="keyword operator assignment python">=</span><span class="constant numeric integer decimal python">5</span><span class="punctuation separator arguments python">,</span> <span class="variable parameter python">random_state</span><span class="keyword operator assignment python">=</span><span class="constant numeric integer decimal python">0</span></span><span class="punctuation section arguments end python">)</span></span>
<span class="meta qualified-name python"><span class="meta generic-name python">sample_03</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">df_03</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">sample</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="variable parameter python">n</span><span class="keyword operator assignment python">=</span><span class="constant numeric integer decimal python">5</span><span class="punctuation separator arguments python">,</span> <span class="variable parameter python">random_state</span><span class="keyword operator assignment python">=</span><span class="constant numeric integer decimal python">0</span></span><span class="punctuation section arguments end python">)</span></span>

<span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> If required, combine the samples back together
</span><span class="meta qualified-name python"><span class="meta generic-name python">sample</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">pandas</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">concat</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta structure list python"><span class="punctuation section list begin python">[</span><span class="meta qualified-name python"><span class="meta generic-name python">sample_01</span></span><span class="punctuation separator list python">,</span> <span class="meta qualified-name python"><span class="meta generic-name python">sample_02</span></span><span class="punctuation separator list python">,</span> <span class="meta qualified-name python"><span class="meta generic-name python">sample_03</span></span><span class="punctuation section list end python">]</span></span><span class="punctuation separator arguments python">,</span> <span class="variable parameter python">ignore_index</span><span class="keyword operator assignment python">=</span><span class="constant language python">True</span></span><span class="punctuation section arguments end python">)</span></span>

<span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Save the sample to Excel
</span><span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">sample</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">to_excel</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">file_output</span></span></span><span class="punctuation section arguments end python">)</span></span></span></code></pre>
<h3 id="stratified-random-sample"><span class="section-number-3">2.5.</span> Stratified Random Sample</h3>
<p>Well, what if you need to sample distinct parts of a single file? For example, let's write some code to separate our data by "Region" and sample those regions independently.</p>
<pre><code class="language-python highlight"><span class="source python"><span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Import the Pandas module
</span><span class="meta statement import python"><span class="keyword control import python">import</span> <span class="meta qualified-name python"><span class="meta generic-name python">pandas</span></span></span>

<span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Specify where to find the input file &amp; where to save the final sample
</span><span class="meta qualified-name python"><span class="meta generic-name python">file_input</span></span> <span class="keyword operator assignment python">=</span> <span class="storage type string python">r</span><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python"><span class="source regexp python">Sales Data<span class="constant character character-class regexp">.</span>xlsx</span><span class="punctuation definition string end python">&#39;</span></span></span>
<span class="meta qualified-name python"><span class="meta generic-name python">file_output</span></span> <span class="keyword operator assignment python">=</span> <span class="storage type string python">r</span><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python"><span class="source regexp python">Sample<span class="constant character character-class regexp">.</span>xlsx</span><span class="punctuation definition string end python">&#39;</span></span></span>

<span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Load the data with pandas
</span><span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Remember to use the sheet_name parameter if your Excel file has multiple sheets
</span><span class="meta qualified-name python"><span class="meta generic-name python">df</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">pandas</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">read_excel</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">file_input</span></span></span><span class="punctuation section arguments end python">)</span></span>

<span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Stratify the data by &quot;Region&quot;
</span><span class="meta qualified-name python"><span class="meta generic-name python">df_east</span></span> <span class="keyword operator assignment python">=</span> <span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">df</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">df</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">Region<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span> <span class="keyword operator comparison python">==</span> <span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">East<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span>
<span class="meta qualified-name python"><span class="meta generic-name python">df_west</span></span> <span class="keyword operator assignment python">=</span> <span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">df</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">df</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">Region<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span> <span class="keyword operator comparison python">==</span> <span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">West<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span>

<span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Sample the data for 5 selections from each quarter
</span><span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Remember to always use the random_state parameter so the sample can be re-performed
</span><span class="meta qualified-name python"><span class="meta generic-name python">sample_east</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">df_east</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">sample</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="variable parameter python">n</span><span class="keyword operator assignment python">=</span><span class="constant numeric integer decimal python">5</span><span class="punctuation separator arguments python">,</span> <span class="variable parameter python">random_state</span><span class="keyword operator assignment python">=</span><span class="constant numeric integer decimal python">0</span></span><span class="punctuation section arguments end python">)</span></span>
<span class="meta qualified-name python"><span class="meta generic-name python">sample_west</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">df_west</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">sample</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="variable parameter python">n</span><span class="keyword operator assignment python">=</span><span class="constant numeric integer decimal python">5</span><span class="punctuation separator arguments python">,</span> <span class="variable parameter python">random_state</span><span class="keyword operator assignment python">=</span><span class="constant numeric integer decimal python">0</span></span><span class="punctuation section arguments end python">)</span></span>

<span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> If required, combine the samples back together
</span><span class="meta qualified-name python"><span class="meta generic-name python">sample</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">pandas</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">concat</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta structure list python"><span class="punctuation section list begin python">[</span><span class="meta qualified-name python"><span class="meta generic-name python">sample_east</span></span><span class="punctuation separator list python">,</span> <span class="meta qualified-name python"><span class="meta generic-name python">sample_west</span></span><span class="punctuation section list end python">]</span></span><span class="punctuation separator arguments python">,</span> <span class="variable parameter python">ignore_index</span><span class="keyword operator assignment python">=</span><span class="constant language python">True</span></span><span class="punctuation section arguments end python">)</span></span>

<span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Save the sample to Excel
</span><span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">sample</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">to_excel</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">file_output</span></span></span><span class="punctuation section arguments end python">)</span></span></span></code></pre>
<h3 id="stratified-systematic-sample"><span class="section-number-3">2.6.</span> Stratified Systematic Sample</h3>
<p>This next example is quite useful if you need audit coverage over a certain time period. This code will generate samples for each month in the data and combine them all together at the end. Obviously, this code can be modified to stratify by something other than months, if needed.</p>
<pre><code class="language-python highlight"><span class="source python"><span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Import the Pandas module
</span><span class="meta statement import python"><span class="keyword control import python">import</span> <span class="meta qualified-name python"><span class="meta generic-name python">pandas</span></span></span>

<span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Specify where to find the input file &amp; where to save the final sample
</span><span class="meta qualified-name python"><span class="meta generic-name python">file_input</span></span> <span class="keyword operator assignment python">=</span> <span class="storage type string python">r</span><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python"><span class="source regexp python">Sales Data<span class="constant character character-class regexp">.</span>xlsx</span><span class="punctuation definition string end python">&#39;</span></span></span>
<span class="meta qualified-name python"><span class="meta generic-name python">file_output</span></span> <span class="keyword operator assignment python">=</span> <span class="storage type string python">r</span><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python"><span class="source regexp python">Sample<span class="constant character character-class regexp">.</span>xlsx</span><span class="punctuation definition string end python">&#39;</span></span></span>

<span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Load the data with pandas
</span><span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Remember to use the sheet_name parameter if your Excel file has multiple sheets
</span><span class="meta qualified-name python"><span class="meta generic-name python">df</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">pandas</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">read_excel</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">file_input</span></span></span><span class="punctuation section arguments end python">)</span></span>

<span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Convert the date column to datetime so the function below will work
</span><span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">df</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">Date of Sale<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">pandas</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">to_datetime</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">df</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">Date of Sale<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span></span><span class="punctuation section arguments end python">)</span></span>

<span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Define a function to create a sample for each month
</span><span class="meta function python"><span class="storage type function python">def</span> <span class="entity name function python"><span class="meta generic-name python">monthly_stratified_sample</span></span></span><span class="meta function parameters python"><span class="punctuation section parameters begin python">(</span></span><span class="meta function parameters python"><span class="variable parameter python">df</span></span><span class="meta function parameters annotation python"><span class="punctuation separator annotation parameter python">:</span> <span class="meta qualified-name python"><span class="meta generic-name python">pandas</span><span class="punctuation accessor dot python">.</span><span class="meta generic-name python">DataFrame</span></span></span><span class="meta function parameters python"><span class="punctuation separator parameters python">,</span> <span class="variable parameter python">date_column</span></span><span class="meta function parameters annotation python"><span class="punctuation separator annotation parameter python">:</span> <span class="meta qualified-name python"><span class="support type python">str</span></span></span><span class="meta function parameters python"><span class="punctuation separator parameters python">,</span> <span class="variable parameter python">num_selections</span></span><span class="meta function parameters annotation python"><span class="punctuation separator annotation parameter python">:</span> <span class="meta qualified-name python"><span class="support type python">int</span></span></span><span class="meta function parameters python"><span class="punctuation section parameters end python">)</span></span><span class="meta function python"> </span><span class="meta function annotation return python"><span class="punctuation separator annotation return python">-&gt;</span> <span class="meta qualified-name python"><span class="meta generic-name python">pandas</span><span class="punctuation accessor dot python">.</span><span class="meta generic-name python">DataFrame</span></span></span><span class="meta function python"><span class="punctuation section function begin python">:</span></span>
    <span class="meta qualified-name python"><span class="meta generic-name python">static_num_selections</span></span> <span class="keyword operator assignment python">=</span> <span class="meta qualified-name python"><span class="meta generic-name python">num_selections</span></span> <span class="meta qualified-name python"><span class="meta generic-name python">final_sample</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">pandas</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">DataFrame</span></span><span class="punctuation section arguments begin python">(</span><span class="punctuation section arguments end python">)</span></span>
    <span class="meta statement for python"><span class="keyword control flow for python">for</span> <span class="meta generic-name python">month</span> <span class="meta statement for python"><span class="keyword control flow for in python">in</span></span></span><span class="meta statement for python"> <span class="meta function-call python"><span class="meta qualified-name python"><span class="support function builtin python">range</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="constant numeric integer decimal python">1</span><span class="punctuation separator arguments python">,</span> <span class="constant numeric integer decimal python">13</span></span><span class="punctuation section arguments end python">)</span></span><span class="punctuation section block for python">:</span></span>
        <span class="meta qualified-name python"><span class="meta generic-name python">num_selections</span></span> <span class="keyword operator assignment python">=</span> <span class="meta qualified-name python"><span class="meta generic-name python">static_num_selections</span></span>
        <span class="meta qualified-name python"><span class="meta generic-name python">rows_list</span></span> <span class="keyword operator assignment python">=</span> <span class="meta structure list python"><span class="punctuation section list begin python">[</span><span class="punctuation section list end python">]</span></span>
        <span class="meta statement for python"><span class="keyword control flow for python">for</span> <span class="meta generic-name python">index</span><span class="punctuation separator target-list python">,</span> <span class="meta generic-name python">row</span> <span class="meta statement for python"><span class="keyword control flow for in python">in</span></span></span><span class="meta statement for python"> <span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">df</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">iterrows</span></span><span class="punctuation section arguments begin python">(</span><span class="punctuation section arguments end python">)</span></span><span class="punctuation section block for python">:</span></span>
            <span class="meta qualified-name python"><span class="meta generic-name python">df_month</span></span> <span class="keyword operator assignment python">=</span> <span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">row</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">date_column</span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span><span class="punctuation accessor dot python">.</span><span class="meta generic-name python">month</span>
            <span class="meta statement if python"><span class="keyword control flow conditional python">if</span> <span class="meta qualified-name python"><span class="meta generic-name python">month</span></span> <span class="keyword operator comparison python">==</span> <span class="meta qualified-name python"><span class="meta generic-name python">df_month</span></span><span class="punctuation section block conditional python">:</span></span>
                <span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">rows_list</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">append</span></span><span class="punctuation section arguments begin python">(</span><span class="punctuation section arguments end python">)</span></span>
        <span class="meta qualified-name python"><span class="meta generic-name python">monthly_df</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">pd</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">DataFrame</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="variable parameter python">data</span><span class="keyword operator assignment python">=</span><span class="meta qualified-name python"><span class="meta generic-name python">rows_list</span></span></span><span class="punctuation section arguments end python">)</span></span>
        <span class="meta statement if python"><span class="keyword control flow conditional python">if</span> <span class="meta group python"><span class="punctuation section group begin python">(</span><span class="meta function-call python"><span class="meta qualified-name python"><span class="support function builtin python">len</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">monthly_df</span></span></span><span class="punctuation section arguments end python">)</span></span><span class="punctuation section group end python">)</span></span> <span class="keyword operator comparison python">==</span> <span class="constant numeric integer decimal python">0</span><span class="punctuation section block conditional python">:</span></span>
            <span class="keyword control flow python">continue</span>
        <span class="meta statement conditional python"><span class="keyword control flow conditional python">elif</span></span> <span class="keyword operator logical python">not</span> <span class="meta group python"><span class="punctuation section group begin python">(</span><span class="meta function-call python"><span class="meta qualified-name python"><span class="support function builtin python">len</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">monthly_df</span></span></span><span class="punctuation section arguments end python">)</span></span> <span class="keyword operator comparison python">&gt;</span> <span class="meta qualified-name python"><span class="meta generic-name python">sample_size</span></span><span class="punctuation section group end python">)</span></span><span class="punctuation separator annotation variable python">:</span>
            <span class="meta qualified-name python"><span class="meta generic-name python">num_selections</span></span> <span class="keyword operator assignment python">=</span> <span class="meta qualified-name python"><span class="meta generic-name python">sample_size</span></span>
        <span class="meta statement conditional python"><span class="keyword control flow conditional python">elif</span></span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="support function builtin python">len</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">monthly_df</span></span></span><span class="punctuation section arguments end python">)</span></span> <span class="keyword operator comparison python">&gt;=</span> <span class="meta qualified-name python"><span class="meta generic-name python">sample_size</span></span><span class="punctuation separator annotation variable python">:</span>
            <span class="meta qualified-name python"><span class="meta generic-name python">num_selections</span></span> <span class="keyword operator assignment python">=</span> <span class="meta qualified-name python"><span class="meta generic-name python">sample_size</span></span>
        <span class="meta qualified-name python"><span class="meta generic-name python">sample</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">monthly_df</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">sample</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="variable parameter python">n</span><span class="keyword operator assignment python">=</span><span class="meta qualified-name python"><span class="meta generic-name python">num_selections</span></span><span class="punctuation separator arguments python">,</span> <span class="variable parameter python">random_state</span><span class="keyword operator assignment python">=</span><span class="constant numeric integer decimal python">0</span></span><span class="punctuation section arguments end python">)</span></span>
        <span class="meta qualified-name python"><span class="meta generic-name python">final_sample</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">final_sample</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">append</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">sample</span></span></span><span class="punctuation section arguments end python">)</span></span>
    <span class="keyword control flow return python">return</span> <span class="meta qualified-name python"><span class="meta generic-name python">sample</span></span>

<span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Sample for 3 selections per month
</span><span class="meta qualified-name python"><span class="meta generic-name python">sample_size</span></span> <span class="keyword operator assignment python">=</span> <span class="constant numeric integer decimal python">3</span>
<span class="meta qualified-name python"><span class="meta generic-name python">sample</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="variable function python">monthly_stratified_sample</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">df</span></span><span class="punctuation separator arguments python">,</span> <span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">Date of Sale<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation separator arguments python">,</span> <span class="meta qualified-name python"><span class="meta generic-name python">sample_size</span></span></span><span class="punctuation section arguments end python">)</span></span>
<span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">sample</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">to_excel</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">file_output</span></span></span><span class="punctuation section arguments end python">)</span></span></span></code></pre>
<h4 id="documenting-the-results"><span class="section-number-4">2.6.1.</span> Documenting the Results</h4>
<p>Once you've generated a proper sample, there are a few things left to do in order to properly ensure your process is reproducible.</p>
<ol>
<li>Document the sample. Make sure the resulting file is readable and includes the documentation listed in the next bullet.</li>
<li>Include documentation around the data source, extraction techniques, any modifications made to the data, and be sure to include a copy of the script itself.</li>
<li>Whenever possible, perform a completeness and accuracy test to ensure your sample is coming from a complete and accurate population. To ensure completeness, compare the record count from the data source to the record count loaded into Python. To ensure accuracy, test a small sample against the source data (e.g., test 5 sales against the database to see if the details are accurate).</li>
</ol>
]]></description>
    </item>
    <item>
      <title>Deleting All GitLab Repositories with Python</title>
      <link>https://cleberg.net/blog/delete-gitlab-repos.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/delete-gitlab-repos.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Thu, 15 Jul 2021 00:00:00 +0000</pubDate>
      <category>personal</category>
      <description><![CDATA[<h2 id="background"><span class="section-number-2">1.</span> Background</h2>
<p>Have you ever used GitLab to host your source code, moved to a different host, and wanted to delete everything from your GitLab account? Well, this post covers any scenario where you would want to delete all repositories from your GitLab account.</p>
<p>For me, I currently maintain around 30 repositories and don't like to manually delete them whenever I switch host. GitHub has a few different tools online to delete all repositories for you, but I have not found anything similar for GitLab, so I needed an alternative solution.</p>
<h2 id="use-a-python-script"><span class="section-number-2">2.</span> Use a Python Script</h2>
<h3 id="requirements"><span class="section-number-3">2.1.</span> Requirements</h3>
<p>Before we look at the script, make sure you know your GitLab username. Next, <a href="https://gitlab.com/-/profile/personal_access_tokens">create an authorization token</a> so that the Python script can delete your repositories. Don't lose this token or else you'll need to create a new one.</p>
<h3 id="create-the-script"><span class="section-number-3">2.2.</span> Create the Script</h3>
<p>To run a Python script, you must first create it. Open a terminal and enter the following commands in whichever directory you prefer to store the script. You can do the same things in a file manager if you prefer.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">mkdir</span></span><span class="meta function-call arguments shell"> delete-gitlab</span></span></code></pre>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="support function cd shell">cd</span></span><span class="meta function-call arguments shell"> delete-gitlab</span></span></code></pre>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">nano</span></span><span class="meta function-call arguments shell"> main.py</span></span></code></pre>
<p>Enter the following code into your <code class="verbatim">main.py</code> script.</p>
<pre><code class="language-python highlight"><span class="source python"><span class="meta statement import python"><span class="keyword control import python">import</span> <span class="meta qualified-name python"><span class="meta generic-name python">request</span></span></span>
<span class="meta statement import python"><span class="keyword control import python">import</span> <span class="meta qualified-name python"><span class="meta generic-name python">json</span></span></span>


<span class="meta function python"><span class="storage type function python">def</span> <span class="entity name function python"><span class="meta generic-name python">get_project_ids</span></span></span><span class="meta function parameters python"><span class="punctuation section parameters begin python">(</span></span><span class="meta function parameters python"><span class="punctuation section parameters end python">)</span></span><span class="meta function python"><span class="punctuation section function begin python">:</span></span>
    <span class="meta qualified-name python"><span class="meta generic-name python">url</span></span> <span class="keyword operator assignment python">=</span> <span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">https://gitlab.com/api/v4/users/{user-id}/projects<span class="punctuation definition string end python">&quot;</span></span></span>

    <span class="meta qualified-name python"><span class="meta generic-name python">querystring</span></span> <span class="keyword operator assignment python">=</span> <span class="meta structure dictionary-or-set python"><span class="punctuation section dictionary-or-set begin python">{</span><span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">owned<span class="punctuation definition string end python">&quot;</span></span></span><span class="punctuation separator key-value python">:</span> <span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">true<span class="punctuation definition string end python">&quot;</span></span></span><span class="punctuation separator dictionary-or-set python">,</span> <span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">simple<span class="punctuation definition string end python">&quot;</span></span></span><span class="punctuation separator key-value python">:</span> <span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">true<span class="punctuation definition string end python">&quot;</span></span></span><span class="punctuation separator dictionary-or-set python">,</span> <span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">per_page<span class="punctuation definition string end python">&quot;</span></span></span><span class="punctuation separator key-value python">:</span> <span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">50<span class="punctuation definition string end python">&quot;</span></span></span><span class="punctuation section dictionary-or-set end python">}</span></span>

    <span class="meta qualified-name python"><span class="meta generic-name python">payload</span></span> <span class="keyword operator assignment python">=</span> <span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string end python">&quot;</span></span></span>
    <span class="meta qualified-name python"><span class="meta generic-name python">headers</span></span> <span class="keyword operator assignment python">=</span> <span class="meta structure dictionary-or-set python"><span class="punctuation section dictionary-or-set begin python">{</span><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">authorization<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation separator key-value python">:</span> <span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">Bearer {auth-token}<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation section dictionary-or-set end python">}</span></span>

    <span class="meta qualified-name python"><span class="meta generic-name python">response</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">requests</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">request</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">GET<span class="punctuation definition string end python">&quot;</span></span></span><span class="punctuation separator arguments python">,</span> <span class="meta qualified-name python"><span class="meta generic-name python">url</span></span><span class="punctuation separator arguments python">,</span> <span class="variable parameter python">data</span><span class="keyword operator assignment python">=</span><span class="meta qualified-name python"><span class="meta generic-name python">payload</span></span><span class="punctuation separator arguments python">,</span> <span class="variable parameter python">headers</span><span class="keyword operator assignment python">=</span><span class="meta qualified-name python"><span class="meta generic-name python">headers</span></span><span class="punctuation separator arguments python">,</span> <span class="variable parameter python">params</span><span class="keyword operator assignment python">=</span><span class="meta qualified-name python"><span class="meta generic-name python">querystring</span></span></span><span class="punctuation section arguments end python">)</span></span>

    <span class="meta qualified-name python"><span class="meta generic-name python">projects</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">json</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">loads</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">response</span><span class="punctuation accessor dot python">.</span><span class="meta generic-name python">text</span></span></span><span class="punctuation section arguments end python">)</span></span>
    <span class="meta qualified-name python"><span class="meta generic-name python">projects_ids</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="support type python">list</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta function-call python"><span class="meta qualified-name python"><span class="support function builtin python">map</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta function inline python"><span class="storage type function inline python">lambda</span></span><span class="meta function inline python"><span class="meta function inline parameters python"> <span class="variable parameter python">project</span></span><span class="punctuation section function begin python">:</span></span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">project</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">get</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">id<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="punctuation section arguments end python">)</span></span><span class="punctuation separator arguments python">,</span> <span class="meta qualified-name python"><span class="meta generic-name python">projects</span></span></span><span class="punctuation section arguments end python">)</span></span></span><span class="punctuation section arguments end python">)</span></span>

    <span class="keyword control flow return python">return</span> <span class="meta qualified-name python"><span class="meta generic-name python">projects_ids</span></span>


<span class="meta function python"><span class="storage type function python">def</span> <span class="entity name function python"><span class="meta generic-name python">remove_project</span></span></span><span class="meta function parameters python"><span class="punctuation section parameters begin python">(</span></span><span class="meta function parameters python"><span class="variable parameter python">project_id</span><span class="punctuation section parameters end python">)</span></span><span class="meta function python"><span class="punctuation section function begin python">:</span></span>
    <span class="meta qualified-name python"><span class="meta generic-name python">url_temp</span></span> <span class="keyword operator assignment python">=</span> <span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">https://gitlab.com/api/v4/projects/<span class="constant other placeholder python"><span class="punctuation definition placeholder begin python">{</span>project<span class="punctuation definition placeholder end python">}</span></span><span class="punctuation definition string end python">&quot;</span></span></span>
    <span class="meta qualified-name python"><span class="meta generic-name python">headers</span></span> <span class="keyword operator assignment python">=</span> <span class="meta structure dictionary-or-set python"><span class="punctuation section dictionary-or-set begin python">{</span><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">authorization<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation separator key-value python">:</span> <span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">Bearer {auth-token}<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation section dictionary-or-set end python">}</span></span>
    <span class="meta qualified-name python"><span class="meta generic-name python">querystring</span></span> <span class="keyword operator assignment python">=</span> <span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string end python">&quot;</span></span></span>
    <span class="meta qualified-name python"><span class="meta generic-name python">payload</span></span> <span class="keyword operator assignment python">=</span> <span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string end python">&quot;</span></span></span>

    <span class="meta qualified-name python"><span class="meta generic-name python">url</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">url_temp</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">format</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="variable parameter python">project</span><span class="keyword operator assignment python">=</span><span class="meta qualified-name python"><span class="meta generic-name python">project_id</span></span></span><span class="punctuation section arguments end python">)</span></span>

    <span class="meta qualified-name python"><span class="meta generic-name python">response</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">requests</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">request</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python"><span class="source sql"><span class="keyword other DML sql">DELETE</span></span><span class="punctuation definition string end python">&quot;</span></span></span><span class="punctuation separator arguments python">,</span> <span class="meta qualified-name python"><span class="meta generic-name python">url</span></span><span class="punctuation separator arguments python">,</span> <span class="variable parameter python">data</span><span class="keyword operator assignment python">=</span><span class="meta qualified-name python"><span class="meta generic-name python">payload</span></span><span class="punctuation separator arguments python">,</span> <span class="variable parameter python">headers</span><span class="keyword operator assignment python">=</span><span class="meta qualified-name python"><span class="meta generic-name python">headers</span></span><span class="punctuation separator arguments python">,</span> <span class="variable parameter python">params</span><span class="keyword operator assignment python">=</span><span class="meta qualified-name python"><span class="meta generic-name python">querystring</span></span></span><span class="punctuation section arguments end python">)</span></span>
    <span class="meta qualified-name python"><span class="meta generic-name python">project</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">json</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">loads</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">response</span><span class="punctuation accessor dot python">.</span><span class="meta generic-name python">text</span></span></span><span class="punctuation section arguments end python">)</span></span>
    <span class="meta function-call python"><span class="meta qualified-name python"><span class="support function builtin python">print</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">project</span></span></span><span class="punctuation section arguments end python">)</span></span>


<span class="meta function python"><span class="storage type function python">def</span> <span class="entity name function python"><span class="meta generic-name python">main</span></span></span><span class="meta function parameters python"><span class="punctuation section parameters begin python">(</span></span><span class="meta function parameters python"><span class="punctuation section parameters end python">)</span></span><span class="meta function python"><span class="punctuation section function begin python">:</span></span>
    <span class="meta qualified-name python"><span class="meta generic-name python">projects_ids</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="variable function python">get_project_ids</span></span><span class="punctuation section arguments begin python">(</span><span class="punctuation section arguments end python">)</span></span>

    <span class="meta qualified-name python"><span class="meta generic-name python">url_temp</span></span> <span class="keyword operator assignment python">=</span> <span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">https://gitlab.com/api/v4/projects/<span class="constant other placeholder python"><span class="punctuation definition placeholder begin python">{</span>project<span class="punctuation definition placeholder end python">}</span></span><span class="punctuation definition string end python">&quot;</span></span></span>
    <span class="meta qualified-name python"><span class="meta generic-name python">headers</span></span> <span class="keyword operator assignment python">=</span> <span class="meta structure dictionary-or-set python"><span class="punctuation section dictionary-or-set begin python">{</span><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">authorization<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation separator key-value python">:</span> <span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">Bearer {auth-token}<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation section dictionary-or-set end python">}</span></span>
    <span class="meta qualified-name python"><span class="meta generic-name python">querystring</span></span> <span class="keyword operator assignment python">=</span> <span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string end python">&quot;</span></span></span>
    <span class="meta qualified-name python"><span class="meta generic-name python">payload</span></span> <span class="keyword operator assignment python">=</span> <span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string end python">&quot;</span></span></span>

    <span class="meta statement for python"><span class="keyword control flow for python">for</span> <span class="meta generic-name python">project_id</span> <span class="meta statement for python"><span class="keyword control flow for in python">in</span></span></span><span class="meta statement for python"> <span class="meta qualified-name python"><span class="meta generic-name python">projects_ids</span></span><span class="punctuation section block for python">:</span></span>
        <span class="meta qualified-name python"><span class="meta generic-name python">url</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">url_temp</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">format</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="variable parameter python">project</span><span class="keyword operator assignment python">=</span><span class="meta qualified-name python"><span class="meta generic-name python">project_id</span></span></span><span class="punctuation section arguments end python">)</span></span>

        <span class="meta qualified-name python"><span class="meta generic-name python">response</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">requests</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">request</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">GET<span class="punctuation definition string end python">&quot;</span></span></span><span class="punctuation separator arguments python">,</span> <span class="meta qualified-name python"><span class="meta generic-name python">url</span></span><span class="punctuation separator arguments python">,</span> <span class="variable parameter python">data</span><span class="keyword operator assignment python">=</span><span class="meta qualified-name python"><span class="meta generic-name python">payload</span></span><span class="punctuation separator arguments python">,</span> <span class="variable parameter python">headers</span><span class="keyword operator assignment python">=</span><span class="meta qualified-name python"><span class="meta generic-name python">headers</span></span><span class="punctuation separator arguments python">,</span> <span class="variable parameter python">params</span><span class="keyword operator assignment python">=</span><span class="meta qualified-name python"><span class="meta generic-name python">querystring</span></span></span><span class="punctuation section arguments end python">)</span></span>
        <span class="meta qualified-name python"><span class="meta generic-name python">project</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">json</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">loads</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">response</span><span class="punctuation accessor dot python">.</span><span class="meta generic-name python">text</span></span></span><span class="punctuation section arguments end python">)</span></span>
        <span class="meta function-call python"><span class="meta qualified-name python"><span class="support function builtin python">print</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta function-call python"><span class="meta qualified-name python"><span class="support type python">str</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">project</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">get</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">id<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="punctuation section arguments end python">)</span></span></span><span class="punctuation section arguments end python">)</span></span> <span class="keyword operator arithmetic python">+</span> <span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python"> <span class="punctuation definition string end python">&quot;</span></span></span> <span class="keyword operator arithmetic python">+</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">project</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">get</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">name<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="punctuation section arguments end python">)</span></span></span><span class="punctuation section arguments end python">)</span></span>
        <span class="meta function-call python"><span class="meta qualified-name python"><span class="support function builtin python">print</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">Removing...<span class="punctuation definition string end python">&quot;</span></span></span></span><span class="punctuation section arguments end python">)</span></span>
        <span class="meta function-call python"><span class="meta qualified-name python"><span class="variable function python">remove_project</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">project_id</span></span></span><span class="punctuation section arguments end python">)</span></span>


<span class="meta statement if python"><span class="keyword control flow conditional python">if</span> <span class="meta qualified-name python"><span class="support variable magic python">__name__</span></span> <span class="keyword operator comparison python">==</span> <span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">__main__<span class="punctuation definition string end python">&quot;</span></span></span><span class="punctuation section block conditional python">:</span></span>
    <span class="meta function-call python"><span class="meta qualified-name python"><span class="variable function python">main</span></span><span class="punctuation section arguments begin python">(</span><span class="punctuation section arguments end python">)</span></span></span></code></pre>
<p>Now that you have the proper information, replace <code class="verbatim">{user-id}</code> with your GitLab username and <code class="verbatim">{auth-token}</code> with the authorization token you created earlier.</p>
<p>Finally, simply run the script and watch the output. You can also use PyCharm Community Edition to edit and run the Python script if you don't want to work in a terminal.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">python3</span></span><span class="meta function-call arguments shell"> main.py</span></span></code></pre>
]]></description>
    </item>
    <item>
      <title>Correcting Git Author Details Across Multiple Repos</title>
      <link>https://cleberg.net/blog/changing-git-authors.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/changing-git-authors.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Sun, 30 May 2021 00:00:00 +0000</pubDate>
      <category>personal</category>
      <description><![CDATA[<h2 id="changing-git-author-email-based-on-previously-committed-email"><span class="section-number-2">1.</span> Changing Git Author/Email Based on Previously Committed Email</h2>
<p>Here's the dilemma: You've been committing changes to your Git repository with an incorrect name or email (or multiple repositories), and now you want to fix it. Luckily, there's a semi-reliable way to fix that. While I have never experienced issues with this method, some people have warned that it can mess with historical hashes and integrity of commits, so use this method only if you're okay accepting that risk.</p>
<p>Okay, let's create the bash script:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">nano</span></span><span class="meta function-call arguments shell"> change_git_authors.sh</span></span></code></pre>
<p>The following information can be pasted directly into your bash script. The only changes you need to make are to the following variables:</p>
<ul>
<li><code class="verbatim">OLD_EMAIL</code></li>
<li><code class="verbatim">CORRECT_NAME</code></li>
<li><code class="verbatim">CORRECT_EMAIL</code></li>
</ul>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell">!/bin/sh</span><span class="comment line number-sign shell">
</span>
<span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> List all sub-directories in the current directory</span><span class="comment line number-sign shell">
</span><span class="keyword control for shell">for</span><span class="meta group for shell"> dir <span class="keyword control in shell">in</span> <span class="keyword operator regexp quantifier shell">*</span>/</span>
<span class="keyword control do shell">do</span>
    <span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> Remove the trailing &quot;/&quot;</span><span class="comment line number-sign shell">
</span>    <span class="variable other readwrite assignment shell">dir</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell"><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section expansion parameter begin shell">{</span></span><span class="meta group expansion parameter shell"><span class="variable other readwrite shell">dir<span class="keyword operator expansion shell">%</span></span></span><span class="meta group expansion parameter shell"><span class="keyword operator regexp quantifier shell">*</span>/</span><span class="meta group expansion parameter shell"><span class="punctuation section expansion parameter end shell">}</span></span></span>
    <span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> Enter sub-directory</span><span class="comment line number-sign shell">
</span>    <span class="meta function-call shell"><span class="support function cd shell">cd</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">dir</span></span></span>

    <span class="meta function-call shell"><span class="variable function shell">git</span></span><span class="meta function-call arguments shell"> filter-branch<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> --</span>env-filter</span> <span class="string quoted single shell"><span class="punctuation definition string begin shell">&#39;</span>

    OLD_EMAIL=&quot;old@example.com&quot;
    CORRECT_NAME=&quot;your-new-name&quot;
    CORRECT_EMAIL=&quot;new@example.com&quot;

    if [ &quot;$GIT_COMMITTER_EMAIL&quot; = &quot;$OLD_EMAIL&quot; ]
    then
        export GIT_COMMITTER_NAME=&quot;$CORRECT_NAME&quot;
        export GIT_COMMITTER_EMAIL=&quot;$CORRECT_EMAIL&quot;
    fi
    if [ &quot;$GIT_AUTHOR_EMAIL&quot; = &quot;$OLD_EMAIL&quot; ]
    then
        export GIT_AUTHOR_NAME=&quot;$CORRECT_NAME&quot;
        export GIT_AUTHOR_EMAIL=&quot;$CORRECT_EMAIL&quot;
    fi
    <span class="punctuation definition string end shell">&#39;</span></span><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> --</span>tag-name-filter</span> cat<span class="keyword operator end-of-options shell"> --</span></span><span class="meta function-call arguments shell"> --branches --tags</span>

    <span class="meta function-call shell"><span class="variable function shell">git</span></span><span class="meta function-call arguments shell"> push<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> --</span>force</span><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> --</span>tags</span> origin <span class="string quoted single shell"><span class="punctuation definition string begin shell">&#39;</span>refs/heads/*<span class="punctuation definition string end shell">&#39;</span></span></span>

    <span class="meta function-call shell"><span class="support function cd shell">cd</span></span><span class="meta function-call arguments shell"> ..</span>
<span class="meta function-call shell"><span class="variable function shell">done</span></span></span></code></pre>
<p>Finally, save the bash script and make it executable.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">chmod</span></span><span class="meta function-call arguments shell"> a+x change_git_authors.sh</span></span></code></pre>
<p>Now you can run the script and should see the process begin.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">./change_git_authors.sh</span></span></span></code></pre>
]]></description>
    </item>
    <item>
      <title>My Photography Gear</title>
      <link>https://cleberg.net/blog/photography.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/photography.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Wed, 28 Apr 2021 00:00:00 +0000</pubDate>
      <category>personal</category>
      <description><![CDATA[<h2 id="why-photography"><span class="section-number-2">1.</span> Why Photography?</h2>
<p>I've often wondered why photography is as enticing as it is. You can see billions of people around the world taking photographs every single moment of the day. New technology often boasts about their photographic capabilities, especially smartphones. I would even assume that we live in a world where there is never a moment in which a photograph is not being taken somewhere on Earth.</p>
<p>As for myself, I would simply say that I enjoy preserving a memory in physical (or digital) form. I've never had the best memory when it comes to recalling details of places and people gone by, so it helps to have a frame of reference lying around.</p>
<p>Regardless of the reason, I think most people would agree that you simply cannot have too many hobbies.</p>
<h2 id="older-cameras"><span class="section-number-2">2.</span> Older Cameras</h2>
<p>I started playing around with the idea of photography when my family purchased a Fujifilm camera for family-specific events. I don't recall the specific model, but I do recall it was a point-and-shoot camera without an interchangeable lens. However, it was of great value to someone, like myself, who couldn't afford any other camera. I took about 10,000 shots with that camera over a 3-5 year span. Most notably, all of my trips to California were documented through this camera.</p>
<p>When possible, I would borrow my sister's camera, which is a Sony SLT-A58. This camera was great and allowed for some of my best early shots, especially those taken in Utah's and Nevada's parks.</p>
<h2 id="my-current-kit"><span class="section-number-2">3.</span> My Current Kit</h2>
<p>I've finally come to a point in my life where I have the disposable income to invest in a solid photography kit. I played around with the idea of a lot of different cameras, different types, new vs used, etc. Finally, I settled on the <a href="https://en.wikipedia.org/wiki/Sony_%CE%B17_III">Sony α7 III</a>. This camera is mirror-less and uses a full-frame image sensor at 24 megapixels. I don't create large prints, and I am mostly focused on preserving memories in high quality for the next 5-10 years with this camera, so the specifications here are just perfect for me.</p>
<p>For lenses, I decided to buy two lenses that could carry me through most situations:</p>
<ul>
<li><a href="https://electronics.sony.com/imaging/lenses/full-frame-e-mount/p/sel2470z">Vario-Tessar T** FE 24-70 mm F4 ZA OSS</a></li>
<li><a href="https://www.tamron-usa.com/product/lenses/a047.html">Tamron 70-300mm f4.5-6.3 Di III RXD</a></li>
</ul>
<p>In addition, I grabbed a couple <a href="https://www.promaster.com/Product/6725">HGX Prime 67mm</a> protection filters for the lenses.</p>
<p>As I delve further into photography and pick up more skills, I will most likely go back and grab a lens with a higher f-stop value, such as f/1.8. I toyed with the idea of grabbing a 50 mm at <code class="verbatim">f/1.8</code>, but decided to keep things in a reasonable price range instead.</p>
<p>Finally, I made sure to buy a photography-specific backpack with a rain guard, and the zipper on the back panel, to protect the equipment while wearing the bag. If you've ever had to haul around a DSLR (digital single-lens reflex) camera in a bag that only has a shoulder strap, you'll know the pain it can cause. Putting all my equipment in a backpack was an easy decision.</p>
]]></description>
    </item>
    <item>
      <title>A Lightweight, Static PHP Comment System</title>
      <link>https://cleberg.net/blog/php-comment-system.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/php-comment-system.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Fri, 23 Apr 2021 00:00:00 +0000</pubDate>
      <category>linux</category>
      <category>web</category>
      <description><![CDATA[<h2 id="the-terrible-ness-of-commenting-systems"><span class="section-number-2">1.</span> The Terrible-ness of Commenting Systems</h2>
<p>The current state of affairs regarding interactive comment systems is, well, terrible. It is especially awful if you're a privacy conscious person who does not generally load third-party scripts or frames on the websites you visit.</p>
<p>Even further, many comment systems are charging exorbitant fees for something that should be standard.</p>
<p>Of course, there are some really terrible options:</p>
<ul>
<li>Facebook Comments</li>
<li>Discourse</li>
</ul>
<p>There are some options that are better but still use too many scripts, frames, or social integrations on your web page that could impact some users:</p>
<ul>
<li>Disqus</li>
<li>Isso</li>
<li>Remark42</li>
</ul>
<p>Lastly, I looked into a few unique ways of generating blog comments, such as using Twitter threads or GitHub issues to automatically post issues. However, these both rely on external third-party sites that I don't currently use.</p>
<h2 id="stay-static-with-server-side-comments"><span class="section-number-2">2.</span> Stay Static with Server-Side Comments</h2>
<p>The main issue for my personal use-case is that my blog is completely, 100% static. I use PHP on the back-end but website visitors only see HTML (Hypertext Markup Language) and a single CSS (Cascading Style Sheets) file. No external JavaScript and no embedded frames.</p>
<p>So, how do we keep a site static and still allow users to interact with blog posts? The key actually pretty simple - I'm already using PHP, so why not rely on the classic HTML <code class="verbatim">&lt;form&gt;</code> and a PHP script to save the comments somewhere? As it turns out, this was a perfect solution for me.</p>
<p>The second issue for my personal use-case is that I am trying to keep the contents of my website accessible over time, as described by Brandur, in his post entitled <a href="https://brandur.org/fragments/graceful-degradation-time">Blog with Markdown + Git, and degrade gracefully through time</a>.</p>
<p>This means I cannot rely on a database for comments, since I do not rely on a database for any other part of my websites.</p>
<p>I blog in plain Markdown files, commit all articles to Git, and ensure that future readers will be able to see the source data long after I'm gone, or the website has gone offline. However, I still haven't committed any images served on my blog to Git, as I'm not entirely sold on Git LFS (large file storage) yet - for now, images can be found at <a href="https://img.cleberg.net">img.cleberg.net</a>.</p>
<p>Saving my comments back to the Git repository ensures that another aspect of my site will degrade gracefully.</p>
<h2 id="create-a-comment-form"><span class="section-number-2">3.</span> Create a Comment Form</h2>
<p>Okay, let's get started. The first step is to create an HTML form that users can see and utilize to submit comments. This is fairly easy and can be changed depending on your personal preferences.</p>
<p>Take a look at the code block below for the form I currently use. Note that <code class="verbatim">&lt;current-url&gt;</code> is replaced automatically in PHP with the current post's URL (uniform resource locator), so that my PHP script used later will know which blog post the comment is related to.</p>
<p>The form contains the following structure:</p>
<ol>
<li><code class="verbatim">&lt;form&gt;</code> - This is the form and will determine which PHP script to send the comment to.</li>
<li><code class="verbatim">&lt;section hidden&gt;</code> - This section is hidden from the user and is used to ensure that we know which blog post sent the comment.</li>
<li><code class="verbatim">&lt;section&gt;</code> Display Name (Optional) - Used to accept a display name, if entered.</li>
<li><code class="verbatim">&lt;section&gt;</code> Comment (Required) - Used to accept the user's full comment. Markdown is allowed.</li>
<li><code class="verbatim">&lt;button&gt;</code> - A button to submit the form.</li>
</ol>
<pre><code class="language-html highlight"><span class="text html basic"><span class="meta tag block form html"><span class="punctuation definition tag begin html">&lt;</span><span class="entity name tag block form html">form</span> <span class="meta attribute-with-value html"><span class="entity other attribute-name html">action</span><span class="punctuation separator key-value html">=</span></span><span class="meta attribute-with-value html"><span class="string quoted double html"><span class="punctuation definition string begin html">&quot;</span>/comment.php<span class="punctuation definition string end html">&quot;</span></span></span> <span class="meta attribute-with-value html"><span class="entity other attribute-name html">method</span><span class="punctuation separator key-value html">=</span></span><span class="meta attribute-with-value html"><span class="string quoted double html"><span class="punctuation definition string begin html">&quot;</span>POST<span class="punctuation definition string end html">&quot;</span></span></span><span class="punctuation definition tag end html">&gt;</span></span>
    <span class="meta tag block any html"><span class="punctuation definition tag begin html">&lt;</span><span class="entity name tag block any html">h3</span><span class="punctuation definition tag end html">&gt;</span></span>Leave a Comment<span class="meta tag block any html"><span class="punctuation definition tag begin html">&lt;/</span><span class="entity name tag block any html">h3</span><span class="punctuation definition tag end html">&gt;</span></span>
    <span class="meta tag block any html"><span class="punctuation definition tag begin html">&lt;</span><span class="entity name tag block any html">section</span> <span class="entity other attribute-name html">hidden</span><span class="punctuation definition tag end html">&gt;</span></span>
        <span class="meta tag inline form html"><span class="punctuation definition tag begin html">&lt;</span><span class="entity name tag inline form html">label</span> <span class="meta attribute-with-value class html"><span class="entity other attribute-name class html">class</span><span class="punctuation separator key-value html">=</span></span><span class="meta attribute-with-value class html"><span class="string quoted double html"><span class="punctuation definition string begin html">&quot;</span></span></span><span class="meta attribute-with-value class html"><span class="string quoted double html"><span class="meta class-name html">form-label</span><span class="punctuation definition string end html">&quot;</span></span></span> <span class="meta attribute-with-value html"><span class="entity other attribute-name html">for</span><span class="punctuation separator key-value html">=</span></span><span class="meta attribute-with-value html"><span class="string quoted double html"><span class="punctuation definition string begin html">&quot;</span>postURL<span class="punctuation definition string end html">&quot;</span></span></span><span class="punctuation definition tag end html">&gt;</span></span>Post URL<span class="meta tag inline form html"><span class="punctuation definition tag begin html">&lt;/</span><span class="entity name tag inline form html">label</span><span class="punctuation definition tag end html">&gt;</span></span>
        <span class="meta tag inline form html"><span class="punctuation definition tag begin html">&lt;</span><span class="entity name tag inline form html">input</span>
            <span class="meta attribute-with-value class html"><span class="entity other attribute-name class html">class</span><span class="punctuation separator key-value html">=</span></span><span class="meta attribute-with-value class html"><span class="string quoted double html"><span class="punctuation definition string begin html">&quot;</span></span></span><span class="meta attribute-with-value class html"><span class="string quoted double html"><span class="meta class-name html">form-control</span><span class="punctuation definition string end html">&quot;</span></span></span>
            <span class="meta attribute-with-value id html"><span class="entity other attribute-name id html">id</span><span class="punctuation separator key-value html">=</span></span><span class="meta attribute-with-value id html"><span class="string quoted double html"><span class="punctuation definition string begin html">&quot;</span></span></span><span class="meta attribute-with-value id html"><span class="string quoted double html"><span class="meta toc-list id html">postURL</span><span class="punctuation definition string end html">&quot;</span></span></span>
            <span class="meta attribute-with-value html"><span class="entity other attribute-name html">name</span><span class="punctuation separator key-value html">=</span></span><span class="meta attribute-with-value html"><span class="string quoted double html"><span class="punctuation definition string begin html">&quot;</span>postURL<span class="punctuation definition string end html">&quot;</span></span></span>
            <span class="meta attribute-with-value html"><span class="entity other attribute-name html">type</span><span class="punctuation separator key-value html">=</span></span><span class="meta attribute-with-value html"><span class="string quoted double html"><span class="punctuation definition string begin html">&quot;</span>text<span class="punctuation definition string end html">&quot;</span></span></span>
            <span class="meta attribute-with-value html"><span class="entity other attribute-name html">value</span><span class="punctuation separator key-value html">=</span></span><span class="meta attribute-with-value html"><span class="string quoted double html"><span class="punctuation definition string begin html">&quot;</span>&lt;current-url&gt;<span class="punctuation definition string end html">&quot;</span></span></span>
       <span class="punctuation definition tag end html"> /&gt;</span></span>
    <span class="meta tag block any html"><span class="punctuation definition tag begin html">&lt;/</span><span class="entity name tag block any html">section</span><span class="punctuation definition tag end html">&gt;</span></span>
    <span class="meta tag block any html"><span class="punctuation definition tag begin html">&lt;</span><span class="entity name tag block any html">section</span><span class="punctuation definition tag end html">&gt;</span></span>
        <span class="meta tag inline form html"><span class="punctuation definition tag begin html">&lt;</span><span class="entity name tag inline form html">label</span> <span class="meta attribute-with-value class html"><span class="entity other attribute-name class html">class</span><span class="punctuation separator key-value html">=</span></span><span class="meta attribute-with-value class html"><span class="string quoted double html"><span class="punctuation definition string begin html">&quot;</span></span></span><span class="meta attribute-with-value class html"><span class="string quoted double html"><span class="meta class-name html">form-label</span><span class="punctuation definition string end html">&quot;</span></span></span> <span class="meta attribute-with-value html"><span class="entity other attribute-name html">for</span><span class="punctuation separator key-value html">=</span></span><span class="meta attribute-with-value html"><span class="string quoted double html"><span class="punctuation definition string begin html">&quot;</span>userName<span class="punctuation definition string end html">&quot;</span></span></span><span class="punctuation definition tag end html">&gt;</span></span>Display Name<span class="meta tag inline form html"><span class="punctuation definition tag begin html">&lt;/</span><span class="entity name tag inline form html">label</span><span class="punctuation definition tag end html">&gt;</span></span>
        <span class="meta tag inline form html"><span class="punctuation definition tag begin html">&lt;</span><span class="entity name tag inline form html">input</span>
            <span class="meta attribute-with-value class html"><span class="entity other attribute-name class html">class</span><span class="punctuation separator key-value html">=</span></span><span class="meta attribute-with-value class html"><span class="string quoted double html"><span class="punctuation definition string begin html">&quot;</span></span></span><span class="meta attribute-with-value class html"><span class="string quoted double html"><span class="meta class-name html">form-control</span><span class="punctuation definition string end html">&quot;</span></span></span>
            <span class="meta attribute-with-value id html"><span class="entity other attribute-name id html">id</span><span class="punctuation separator key-value html">=</span></span><span class="meta attribute-with-value id html"><span class="string quoted double html"><span class="punctuation definition string begin html">&quot;</span></span></span><span class="meta attribute-with-value id html"><span class="string quoted double html"><span class="meta toc-list id html">userName</span><span class="punctuation definition string end html">&quot;</span></span></span>
            <span class="meta attribute-with-value html"><span class="entity other attribute-name html">name</span><span class="punctuation separator key-value html">=</span></span><span class="meta attribute-with-value html"><span class="string quoted double html"><span class="punctuation definition string begin html">&quot;</span>userName<span class="punctuation definition string end html">&quot;</span></span></span>
            <span class="meta attribute-with-value html"><span class="entity other attribute-name html">placeholder</span><span class="punctuation separator key-value html">=</span></span><span class="meta attribute-with-value html"><span class="string quoted double html"><span class="punctuation definition string begin html">&quot;</span>John Doe<span class="punctuation definition string end html">&quot;</span></span></span>
            <span class="meta attribute-with-value html"><span class="entity other attribute-name html">type</span><span class="punctuation separator key-value html">=</span></span><span class="meta attribute-with-value html"><span class="string quoted double html"><span class="punctuation definition string begin html">&quot;</span>text<span class="punctuation definition string end html">&quot;</span></span></span>
       <span class="punctuation definition tag end html"> /&gt;</span></span>
    <span class="meta tag block any html"><span class="punctuation definition tag begin html">&lt;/</span><span class="entity name tag block any html">section</span><span class="punctuation definition tag end html">&gt;</span></span>
    <span class="meta tag block any html"><span class="punctuation definition tag begin html">&lt;</span><span class="entity name tag block any html">section</span><span class="punctuation definition tag end html">&gt;</span></span>
        <span class="meta tag inline form html"><span class="punctuation definition tag begin html">&lt;</span><span class="entity name tag inline form html">label</span> <span class="meta attribute-with-value class html"><span class="entity other attribute-name class html">class</span><span class="punctuation separator key-value html">=</span></span><span class="meta attribute-with-value class html"><span class="string quoted double html"><span class="punctuation definition string begin html">&quot;</span></span></span><span class="meta attribute-with-value class html"><span class="string quoted double html"><span class="meta class-name html">form-label</span><span class="punctuation definition string end html">&quot;</span></span></span> <span class="meta attribute-with-value html"><span class="entity other attribute-name html">for</span><span class="punctuation separator key-value html">=</span></span><span class="meta attribute-with-value html"><span class="string quoted double html"><span class="punctuation definition string begin html">&quot;</span>userContent<span class="punctuation definition string end html">&quot;</span></span></span><span class="punctuation definition tag end html">&gt;</span></span>Your Comment<span class="meta tag inline form html"><span class="punctuation definition tag begin html">&lt;/</span><span class="entity name tag inline form html">label</span><span class="punctuation definition tag end html">&gt;</span></span>
        <span class="meta tag inline form html"><span class="punctuation definition tag begin html">&lt;</span><span class="entity name tag inline form html">textarea</span>
            <span class="meta attribute-with-value class html"><span class="entity other attribute-name class html">class</span><span class="punctuation separator key-value html">=</span></span><span class="meta attribute-with-value class html"><span class="string quoted double html"><span class="punctuation definition string begin html">&quot;</span></span></span><span class="meta attribute-with-value class html"><span class="string quoted double html"><span class="meta class-name html">form-control</span><span class="punctuation definition string end html">&quot;</span></span></span>
            <span class="meta attribute-with-value id html"><span class="entity other attribute-name id html">id</span><span class="punctuation separator key-value html">=</span></span><span class="meta attribute-with-value id html"><span class="string quoted double html"><span class="punctuation definition string begin html">&quot;</span></span></span><span class="meta attribute-with-value id html"><span class="string quoted double html"><span class="meta toc-list id html">userContent</span><span class="punctuation definition string end html">&quot;</span></span></span>
            <span class="meta attribute-with-value html"><span class="entity other attribute-name html">name</span><span class="punctuation separator key-value html">=</span></span><span class="meta attribute-with-value html"><span class="string quoted double html"><span class="punctuation definition string begin html">&quot;</span>userContent<span class="punctuation definition string end html">&quot;</span></span></span>
            <span class="meta attribute-with-value html"><span class="entity other attribute-name html">rows</span><span class="punctuation separator key-value html">=</span></span><span class="meta attribute-with-value html"><span class="string quoted double html"><span class="punctuation definition string begin html">&quot;</span>3<span class="punctuation definition string end html">&quot;</span></span></span>
            <span class="meta attribute-with-value html"><span class="entity other attribute-name html">placeholder</span><span class="punctuation separator key-value html">=</span></span><span class="meta attribute-with-value html"><span class="string quoted double html"><span class="punctuation definition string begin html">&quot;</span># Feel free to use Markdown<span class="punctuation definition string end html">&quot;</span></span></span>
            <span class="meta attribute-with-value html"><span class="entity other attribute-name html">aria-describedby</span><span class="punctuation separator key-value html">=</span></span><span class="meta attribute-with-value html"><span class="string quoted double html"><span class="punctuation definition string begin html">&quot;</span>commentHelp<span class="punctuation definition string end html">&quot;</span></span></span>
            <span class="entity other attribute-name html">required</span>
        <span class="punctuation definition tag end html">&gt;</span></span><span class="meta tag inline form html"><span class="punctuation definition tag begin html">&lt;/</span><span class="entity name tag inline form html">textarea</span><span class="punctuation definition tag end html">&gt;</span></span>
        <span class="meta tag block any html"><span class="punctuation definition tag begin html">&lt;</span><span class="entity name tag block any html">div</span> <span class="meta attribute-with-value id html"><span class="entity other attribute-name id html">id</span><span class="punctuation separator key-value html">=</span></span><span class="meta attribute-with-value id html"><span class="string quoted double html"><span class="punctuation definition string begin html">&quot;</span></span></span><span class="meta attribute-with-value id html"><span class="string quoted double html"><span class="meta toc-list id html">commentHelp</span><span class="punctuation definition string end html">&quot;</span></span></span> <span class="meta attribute-with-value class html"><span class="entity other attribute-name class html">class</span><span class="punctuation separator key-value html">=</span></span><span class="meta attribute-with-value class html"><span class="string quoted double html"><span class="punctuation definition string begin html">&quot;</span></span></span><span class="meta attribute-with-value class html"><span class="string quoted double html"><span class="meta class-name html">form-text</span><span class="punctuation definition string end html">&quot;</span></span></span><span class="punctuation definition tag end html">&gt;</span></span>
            Comments are saved as Markdown and cannot be edited or deleted.
        <span class="meta tag block any html"><span class="punctuation definition tag begin html">&lt;/</span><span class="entity name tag block any html">div</span><span class="punctuation definition tag end html">&gt;</span></span>
    <span class="meta tag block any html"><span class="punctuation definition tag begin html">&lt;/</span><span class="entity name tag block any html">section</span><span class="punctuation definition tag end html">&gt;</span></span>
    <span class="meta tag inline form html"><span class="punctuation definition tag begin html">&lt;</span><span class="entity name tag inline form html">button</span> <span class="meta attribute-with-value html"><span class="entity other attribute-name html">type</span><span class="punctuation separator key-value html">=</span></span><span class="meta attribute-with-value html"><span class="string quoted double html"><span class="punctuation definition string begin html">&quot;</span>submit<span class="punctuation definition string end html">&quot;</span></span></span><span class="punctuation definition tag end html">&gt;</span></span>Submit<span class="meta tag inline form html"><span class="punctuation definition tag begin html">&lt;/</span><span class="entity name tag inline form html">button</span><span class="punctuation definition tag end html">&gt;</span></span>
<span class="meta tag block form html"><span class="punctuation definition tag begin html">&lt;/</span><span class="entity name tag block form html">form</span><span class="punctuation definition tag end html">&gt;</span></span></span></code></pre>
<h2 id="handle-comments-via-post"><span class="section-number-2">4.</span> Handle Comments via POST</h2>
<p>Now that we have a form and can submit comments, we need to create a PHP script so that the server can fetch the comment data and save it. Make sure your PHP script name matches the name you entered in the <code class="verbatim">action</code> field in your form.</p>
<p>See the code block below for the contents of my <code class="verbatim">comment.php</code> script. We perform the following tasks in this script:</p>
<ol>
<li>Grab the POST data from the HTML form.</li>
<li>Sanitize the comment data with <code class="verbatim">htmlentities</code>.</li>
<li>Set the display name to <code class="verbatim">Anonymous</code> if it was left blank.</li>
<li>Create a PHP object that combines all of this data.</li>
<li>Check if our destination file <code class="verbatim">comments.json</code> exists.</li>
<li>If so, convert the PHP object to JSON (JavaScript Object Notation) and save it to the file.</li>
<li>If the <code class="verbatim">comments.json</code> file does not exist, the script will exit with an error. You can alter this to ensure it creates the script, but my source code includes the file by default, so it will always exist.</li>
<li>Finally, send the user back to the <code class="verbatim">#comments</code> section of the blog post they just read.</li>
</ol>
<pre><code class="language-php highlight"><span class="embedding php"><span class="text html basic">// Get the content sent from the comment form
$comment = htmlentities($_POST[&#39;userContent&#39;]);
$post_url = $_POST[&#39;postURL&#39;];

// Set default values if blank
if (isset($_POST[&#39;userName&#39;]) <span class="invalid illegal bad-ampersand html">&amp;</span><span class="invalid illegal bad-ampersand html">&amp;</span> trim($_POST[&#39;userName&#39;]) !== &quot;&quot;) {
    $username = $_POST[&#39;userName&#39;];
} else {
    $username = &#39;Anonymous&#39;;
}

// Create an empty PHP object
$user_object = new stdClass();

// Add object content
$user_object-&gt;timestamp = date(&#39;Y-m-d H:i:s&#39;);
$user_object-&gt;username = $username;
$user_object-&gt;comment = $comment;
$user_object-&gt;post_url = $post_url;

// Append JSON to file
$file_name = &#39;comments.json&#39;;
if (file_exists($file_name)) {
    $source_data = file_get_contents($file_name);
    $temp_array = json_decode($source_data);
    array_push($temp_array, $user_object);
    $json_data = json_encode($temp_array, JSON_PRETTY_PRINT);
    file_put_contents($file_name, $json_data);
} else {
    die(&#39;Error: The &quot;comments.json&quot; file does not exist.&#39;);
}

// Send the user back
header(&#39;Location: &#39; . $post_url . &#39;#comments&#39;);</span></span></code></pre>
<p>If you're using Apache, make sure the <code class="verbatim">www-data</code> user on your server has the correct permissions to your website directory or else it will not be able to write to <code class="verbatim">comments.json</code>.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">chgrp</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>R</span> www-data /path/to/website/</span>
<span class="meta function-call shell"><span class="variable function shell">chmod</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>R</span> g+w comments.json</span></span></code></pre>
<h2 id="display-user-comments"><span class="section-number-2">5.</span> Display User Comments</h2>
<p>Now that we can submit comments, and they are saved to the <code class="verbatim">comments.json</code> file, let's make sure we can show those comments in each blog post.</p>
<p>The code block below shows the function I use to decode my <code class="verbatim">comments.json</code> file, check if the comments apply to the current post, and then display them.</p>
<p>This piece of code should <strong>really</strong> be inside a function (or at least in an organized PHP workflow). Don't just copy-and-paste and expect it to work. You need to at least supply a <code class="verbatim">$query</code> variable depending on the page visited.</p>
<pre><code class="language-php highlight"><span class="embedding php"><span class="text html basic">$query = &#39;your-blog-post.html&#39;;

// Load saved comments
$comments_file = &#39;comments.json&#39;;
$comments_raw = file_get_contents($comments_file);
$comments = json_decode($comments_raw);
$comment_section = &#39;<span class="meta tag block any html"><span class="punctuation definition tag begin html">&lt;</span><span class="entity name tag block any html">section</span> <span class="meta attribute-with-value id html"><span class="entity other attribute-name id html">id</span><span class="punctuation separator key-value html">=</span></span><span class="meta attribute-with-value id html"><span class="string quoted double html"><span class="punctuation definition string begin html">&quot;</span></span></span><span class="meta attribute-with-value id html"><span class="string quoted double html"><span class="meta toc-list id html">comments</span><span class="punctuation definition string end html">&quot;</span></span></span> <span class="meta attribute-with-value class html"><span class="entity other attribute-name class html">class</span><span class="punctuation separator key-value html">=</span></span><span class="meta attribute-with-value class html"><span class="string quoted double html"><span class="punctuation definition string begin html">&quot;</span></span></span><span class="meta attribute-with-value class html"><span class="string quoted double html"><span class="meta class-name html">comments</span><span class="punctuation definition string end html">&quot;</span></span></span><span class="punctuation definition tag end html">&gt;</span></span><span class="meta tag block any html"><span class="punctuation definition tag begin html">&lt;</span><span class="entity name tag block any html">h3</span><span class="punctuation definition tag end html">&gt;</span></span>Comments<span class="meta tag block any html"><span class="punctuation definition tag begin html">&lt;/</span><span class="entity name tag block any html">h3</span><span class="punctuation definition tag end html">&gt;</span></span>&#39;;
foreach ($comments as $comment) {
    if ($comment-&gt;post_url == &quot;https://example.com/post/&quot; . $query) {
        // Assign metadata to variables
        $comment_timestamp = $comment-&gt;timestamp;
        $comment_username = $comment-&gt;username;
        $comment_content = $comment-&gt;comment;

        // Parse the comment, in case it contains Markdown
        $comment_md = Parsedown::instance()-&gt;text($comment_content);
        $comment_html = new DOMDocument();
        $comment_html-&gt;loadHTML($comment_md);
        $comment_html_links = $comment_html-&gt;getElementsByTagName(&#39;a&#39;);
        foreach ($comment_html_links as $comment_html_link) {
            $comment_html_link-&gt;setAttribute(&#39;rel&#39;, &#39;noreferrer&#39;);
            $comment_html_link-&gt;setAttribute(&#39;target&#39;, &#39;_blank&#39;);
        }
        $comment_secured_html = $comment_html-&gt;saveHTML();

        // Apply metadata to comments section
        $comment_section .= &#39;<span class="meta tag block any html"><span class="punctuation definition tag begin html">&lt;</span><span class="entity name tag block any html">div</span> <span class="meta attribute-with-value class html"><span class="entity other attribute-name class html">class</span><span class="punctuation separator key-value html">=</span></span><span class="meta attribute-with-value class html"><span class="string quoted double html"><span class="punctuation definition string begin html">&quot;</span></span></span><span class="meta attribute-with-value class html"><span class="string quoted double html"><span class="meta class-name html">user-comment</span><span class="punctuation definition string end html">&quot;</span></span></span><span class="punctuation definition tag end html">&gt;</span></span><span class="meta tag block any html"><span class="punctuation definition tag begin html">&lt;</span><span class="entity name tag block any html">div</span> <span class="meta attribute-with-value class html"><span class="entity other attribute-name class html">class</span><span class="punctuation separator key-value html">=</span></span><span class="meta attribute-with-value class html"><span class="string quoted double html"><span class="punctuation definition string begin html">&quot;</span></span></span><span class="meta attribute-with-value class html"><span class="string quoted double html"><span class="meta class-name html">row</span><span class="punctuation definition string end html">&quot;</span></span></span><span class="punctuation definition tag end html">&gt;</span></span><span class="meta tag inline form html"><span class="punctuation definition tag begin html">&lt;</span><span class="entity name tag inline form html">label</span><span class="punctuation definition tag end html">&gt;</span></span>Timestamp:<span class="meta tag inline form html"><span class="punctuation definition tag begin html">&lt;/</span><span class="entity name tag inline form html">label</span><span class="punctuation definition tag end html">&gt;</span></span><span class="meta tag block any html"><span class="punctuation definition tag begin html">&lt;</span><span class="entity name tag block any html">p</span><span class="punctuation definition tag end html">&gt;</span></span>&#39; . $comment_timestamp . &#39;<span class="meta tag block any html"><span class="punctuation definition tag begin html">&lt;/</span><span class="entity name tag block any html">p</span><span class="punctuation definition tag end html">&gt;</span></span><span class="meta tag block any html"><span class="punctuation definition tag begin html">&lt;/</span><span class="entity name tag block any html">div</span><span class="punctuation definition tag end html">&gt;</span></span><span class="meta tag block any html"><span class="punctuation definition tag begin html">&lt;</span><span class="entity name tag block any html">div</span> <span class="meta attribute-with-value class html"><span class="entity other attribute-name class html">class</span><span class="punctuation separator key-value html">=</span></span><span class="meta attribute-with-value class html"><span class="string quoted double html"><span class="punctuation definition string begin html">&quot;</span></span></span><span class="meta attribute-with-value class html"><span class="string quoted double html"><span class="meta class-name html">row</span><span class="punctuation definition string end html">&quot;</span></span></span><span class="punctuation definition tag end html">&gt;</span></span><span class="meta tag inline form html"><span class="punctuation definition tag begin html">&lt;</span><span class="entity name tag inline form html">label</span><span class="punctuation definition tag end html">&gt;</span></span>Name:<span class="meta tag inline form html"><span class="punctuation definition tag begin html">&lt;/</span><span class="entity name tag inline form html">label</span><span class="punctuation definition tag end html">&gt;</span></span><span class="meta tag block any html"><span class="punctuation definition tag begin html">&lt;</span><span class="entity name tag block any html">p</span><span class="punctuation definition tag end html">&gt;</span></span>&#39; . $comment_username . &#39;<span class="meta tag block any html"><span class="punctuation definition tag begin html">&lt;/</span><span class="entity name tag block any html">p</span><span class="punctuation definition tag end html">&gt;</span></span><span class="meta tag block any html"><span class="punctuation definition tag begin html">&lt;/</span><span class="entity name tag block any html">div</span><span class="punctuation definition tag end html">&gt;</span></span><span class="meta tag block any html"><span class="punctuation definition tag begin html">&lt;</span><span class="entity name tag block any html">div</span> <span class="meta attribute-with-value class html"><span class="entity other attribute-name class html">class</span><span class="punctuation separator key-value html">=</span></span><span class="meta attribute-with-value class html"><span class="string quoted double html"><span class="punctuation definition string begin html">&quot;</span></span></span><span class="meta attribute-with-value class html"><span class="string quoted double html"><span class="meta class-name html">row markdown</span><span class="punctuation definition string end html">&quot;</span></span></span><span class="punctuation definition tag end html">&gt;</span></span><span class="meta tag inline form html"><span class="punctuation definition tag begin html">&lt;</span><span class="entity name tag inline form html">label</span><span class="punctuation definition tag end html">&gt;</span></span>Comment:<span class="meta tag inline form html"><span class="punctuation definition tag begin html">&lt;/</span><span class="entity name tag inline form html">label</span><span class="punctuation definition tag end html">&gt;</span></span><span class="meta tag block any html"><span class="punctuation definition tag begin html">&lt;</span><span class="entity name tag block any html">div</span> <span class="meta attribute-with-value class html"><span class="entity other attribute-name class html">class</span><span class="punctuation separator key-value html">=</span></span><span class="meta attribute-with-value class html"><span class="string quoted double html"><span class="punctuation definition string begin html">&quot;</span></span></span><span class="meta attribute-with-value class html"><span class="string quoted double html"><span class="meta class-name html">comment-markdown</span><span class="punctuation definition string end html">&quot;</span></span></span><span class="punctuation definition tag end html">&gt;</span></span>&#39; . $comment_secured_html . &#39;<span class="meta tag block any html"><span class="punctuation definition tag begin html">&lt;/</span><span class="entity name tag block any html">div</span><span class="punctuation definition tag end html">&gt;</span></span><span class="meta tag block any html"><span class="punctuation definition tag begin html">&lt;/</span><span class="entity name tag block any html">div</span><span class="punctuation definition tag end html">&gt;</span></span><span class="meta tag block any html"><span class="punctuation definition tag begin html">&lt;/</span><span class="entity name tag block any html">div</span><span class="punctuation definition tag end html">&gt;</span></span>&#39;;
    }
}

echo $comment_section;</span></span></code></pre>
<h2 id="bonus-create-a-recent-comments-page"><span class="section-number-2">6.</span> Bonus: Create a 'Recent Comments' Page</h2>
<p>Finally, the last part of my current system is to create a Recent Comments page so that I can easily check-in on my blog and moderate any spam. As an alternative, you could use PHP's <code class="verbatim">mail()</code> function to email you for each blog comment.</p>
<p>The code to do this is literally the same code as the previous section, I just make sure it is printed when someone visits <code class="verbatim">https://example.com/comments/</code>.</p>
<h2 id="possible-enhancements"><span class="section-number-2">7.</span> Possible Enhancements</h2>
<p>This comment system is by no means a fully-developed system. I have noted a few possible enhancements here that I may implement in the future:</p>
<ul>
<li>Create a secure moderator page with user authentication at <code class="verbatim">https://blog.example.com/mod/</code>. This page could have the option to edit or delete any comment found in <code class="verbatim">comments.json</code>.</li>
<li>Create a temporary file, such as <code class="verbatim">pending_comments.json</code>, that will store newly-submitted comments and won't display on blog posts until approved by a moderator.</li>
<li>Create a <code class="verbatim">/modlog/</code> page with a chronological log, showing which moderator approved which comments and why certain comments were rejected.</li>
</ul>
]]></description>
    </item>
    <item>
      <title>Agate Gemini Server Setup</title>
      <link>https://cleberg.net/blog/gemini-server.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/gemini-server.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Sat, 17 Apr 2021 00:00:00 +0000</pubDate>
      <category>linux</category>
      <category>web</category>
      <description><![CDATA[<h2 id="similar-article-available"><span class="section-number-2">1.</span> Similar Article Available</h2>
<p>To read more about Gemini and ways to test out this new protocol without your own server, see my previous post <a href="gemini-capsule.html">Launching a Gemini Capsule</a>.</p>
<h2 id="preparation"><span class="section-number-2">2.</span> Preparation</h2>
<p>This guide assumes you have access to a server accessible to the world through a public IP (internet protocol) address and that you own a domain name used for this Gemini capsule.</p>
<h2 id="getting-started-with-agate"><span class="section-number-2">3.</span> Getting Started with Agate</h2>
<p>We are going to use <a href="https://github.com/mbrubeck/agate">Agate</a> for this tutorial. This is a basic Gemini server written in Rust. It takes very little time and maintenance to get it running.</p>
<h2 id="install-dependencies"><span class="section-number-2">4.</span> Install Dependencies</h2>
<p>First, you will need to install the Rust package for your system. On Ubuntu, use the following commands (remember to use <code class="verbatim">sudo</code> if you are not the root user). The Rust installation will give you options to customize the installation; I used the default installation options.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> apt update</span> <span class="keyword operator logical and shell">&amp;&amp;</span> <span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> apt upgrade<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>y</span></span>
<span class="meta function-call shell"><span class="variable function shell">curl</span></span><span class="meta function-call arguments shell"> https://sh.rustup.rs<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>sSf</span></span> <span class="keyword operator logical pipe shell">|</span> <span class="meta function-call shell"><span class="variable function shell">sh</span></span></span></code></pre>
<p>Remember to configure your shell with the new configuration:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="support function source shell">source</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">HOME</span></span>/.cargo/env</span></span></code></pre>
<p>Before we install agate, make sure you have the <code class="verbatim">gcc</code> package installed:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> apt install gcc</span></span></code></pre>
<p>Next, you'll need to install the agate executable with Rust's Cargo package maintainer:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">cargo</span></span><span class="meta function-call arguments shell"> install agate</span></span></code></pre>
<h2 id="create-symlinks"><span class="section-number-2">5.</span> Create Symlinks</h2>
<p>Once Cargo has finished installing all the required packages, create a symbolic link to the executable to your $PATH.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> ln<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>s</span> <span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">HOME</span></span>/.cargo/bin/agate /usr/local/bin/agate</span></span></code></pre>
<h2 id="using-agate-s-built-in-installation-tool"><span class="section-number-2">6.</span> Using Agate's Built-In Installation Tool</h2>
<p>If you're running Ubuntu or Debian, use the Debian installation script found in Agate's GitHub repository, under the <code class="verbatim">tools/debian</code> folder.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">git</span></span><span class="meta function-call arguments shell"> clone https://github.com/mbrubeck/agate</span>
<span class="meta function-call shell"><span class="support function cd shell">cd</span></span><span class="meta function-call arguments shell"> agate/tools/debian</span>
<span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> ./install.sh</span></span></code></pre>
<h2 id="configure-the-gemini-service"><span class="section-number-2">7.</span> Configure the Gemini Service</h2>
<p>We have a little more to do, but since this script tries to immediately run the service, it will likely fail with an exit code. Let's add our finishing touches. Edit the following file and replace the hostname with your desired URL (uniform resource locator). You can also change the directory where content will be served.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> nano /etc/systemd/system/gemini.service</span></span></code></pre>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> Edit these lines to whatever you want - see the next code block for my personal configuration.</span><span class="comment line number-sign shell">
</span><span class="variable other readwrite assignment shell">WorkingDirectory</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell">/srv/gemini</span>
<span class="variable other readwrite assignment shell">ExecStart</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell">agate</span> <span class="meta function-call shell"><span class="variable function shell">--hostname</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion command parens shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section parens begin shell">(</span><span class="meta function-call shell"><span class="variable function shell">uname</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>n</span></span><span class="punctuation section parens end shell">)</span></span><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> --</span>lang</span> en</span></span></code></pre>
<p>This is my personal config:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="variable other readwrite assignment shell">WorkingDirectory</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell">/var/gemini/</span>
<span class="variable other readwrite assignment shell">ExecStart</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell">agate</span> <span class="meta function-call shell"><span class="variable function shell">--hostname</span></span><span class="meta function-call arguments shell"> gemini.example.com<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> --</span>lang</span> en</span></span></code></pre>
<p>Since we've altered the systemd configuration files, we have to reload the daemon. Let's do that, restart our service, and check its status.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> systemctl daemon-reload</span>
<span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> systemctl restart gemini.service</span>
<span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> systemctl status gemini.service</span></span></code></pre>
<h2 id="fixing-systemd-errors"><span class="section-number-2">8.</span> Fixing Systemd Errors</h2>
<p>If you're still getting errors, the installation process may not have properly enabled the gemini service. Fix it with the following commands.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> systemctl enable gemini.service</span>
<span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> systemctl restart gemini.service</span>
<span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> systemctl status gemini.service</span></span></code></pre>
<h2 id="firewall-rules"><span class="section-number-2">9.</span> Firewall Rules</h2>
<p>Great! Our server is now functional and running. The first consideration now is that you need to be able to access port 1965 on the server. If you have a firewall enabled, you'll need to open that port up.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> ufw allow 1965</span>
<span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> ufw reload</span></span></code></pre>
<h2 id="creating-content"><span class="section-number-2">10.</span> Creating Content</h2>
<p>Let's create the Gemini capsule. Note that wherever you set the <code class="verbatim">WorkingDirectory</code> variable to earlier, Agate will expect you to put your Gemini capsule contents in a sub-folder called <code class="verbatim">content</code>. So, I place my files in <code class="verbatim">/var/gmi/content</code>. I'm going to create that folder now and put a file in there.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> mkdir /var/gemini/content</span>
<span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> nano /var/gemini/content/index.gmi</span></span></code></pre>
<p>You can put whatever you want in the <code class="verbatim">index.gmi</code> file, just make sure it's valid Gemtext.</p>
<h2 id="the-results"><span class="section-number-2">11.</span> The Results</h2>
<p>To view the results, you can use a Gemini browser, such as <a href="https://gmi.skyjake.fi/lagrange/">Lagrange</a> or <a href="https://github.com/makeworld-the-better-one/amfora">amfora</a>.</p>
]]></description>
    </item>
    <item>
      <title>VPS Web Server: Get Off Shared Hosting</title>
      <link>https://cleberg.net/blog/vps-web-server.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/vps-web-server.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Tue, 30 Mar 2021 00:00:00 +0000</pubDate>
      <category>linux</category>
      <category>self-hosting</category>
      <description><![CDATA[<h2 id="shared-hosting-vs-vps-virtual-private-server"><span class="section-number-2">1.</span> Shared Hosting vs. VPS (Virtual Private Server)</h2>
<p>Choosing a place to host a website is one of the most confusing decisions for beginner web developers. Even for experienced web devs, choosing between different forms of web hosting can be a daunting choice.</p>
<p>First, let's take a look at <a href="https://en.wikipedia.org/wiki/Shared_web_hosting_service">shared web hosting</a>. Shared web hosting is a product where you are purchasing a small piece of a web server that is being shared between many websites. As a result, the cost of shared hosting is extremely low. You won't have access to the server itself, which means you can't install your own software on the server, such as Docker. Usually, you are simply allowed to connect your domains to the server, set up domain security, and other small utilities.</p>
<p>In contrast, a <a href="https://en.wikipedia.org/wiki/Virtual_private_server">virtual private server</a> (VPS) is a virtual machine that replicates the environment of having a dedicated server to yourself. You are able to control the virtual server's host names, base file system, package manager, etc. Another great upside of a VPS is that since it's virtual, the company providing the VPS can dynamically increase the disk size, RAM size, or number of CPUs at any time. However, the virtual server is still physically located on a server that is shared between multiple virtual servers.</p>
<p>The choice between shared hosting and VPS mostly depends on your skill level with system administration. If you're comforting working on a server that is mostly left up to you (or you're willing to learn), then a VPS is usually a better option. However, shared hosting is a fantastic option for people who don't want to have to learn how to manage their server.</p>
<h2 id="my-situation"><span class="section-number-2">2.</span> My Situation</h2>
<p>I had used shared hosting for approximately 5 years before trying my first VPS. I manage a homelab and have had success running a server and performing typical sysadmin duties, but I was still hesitant to get a VPS. One fear was that I always struggled to properly set up the networking part of a server - DNS and hostname configurations were not my friend.</p>
<p>As a little bit of background, I originally used <a href="https://www.siteground.com">Siteground</a> for my initially shared hosting and stayed on that platform for at least a year. However, the user interface (UI) was clunky, and I didn't like how they handled certain technical aspects, so I switched to <a href="https://www.namecheap.com">Namecheap</a>. Namecheap was great because it is the service I primarily use for purchasing domain names, which made it incredibly easy to link them to my hosting service. However, it was still mediocre shared hosting, and Namecheap is notorious for not letting you use <a href="https://letsencrypt.org">Let's Encrypt</a> to obtain free SSL (Secure Socket Layer)/TLS (Transport Layer Security) certificates; Namecheap wants to make you purchase certificates through their store.</p>
<p>Finally, I settled down with <a href="https://www.iwebfusion.net">iWebFusion</a> for about the last year of my shared hosting. This service was pretty great, came with free SSL/TLS, and I never had any complaints.</p>
<p>However, I finally grew tired of not being able to install software on my own web server. I wanted to be able to try out things like <a href="https://postmill.xyz">Postmill</a> or <a href="https://matrix.org">Matrix</a>. This is possible with a VPS, so I decided to grab a new domain name to try it out.</p>
<h2 id="getting-started-buying-a-vps"><span class="section-number-2">3.</span> Getting Started: Buying a VPS</h2>
<p>The first step to moving over to a VPS is (you guessed it): finding a VPS provider. For my VPSs, I use <a href="https://1984hosting.com">1984</a> and prefer their services much more than any alternative, due to their location (Iceland), their <a href="https://1984hosting.com/GDPR/">privacy policy</a>, their respect for GDPR, and the ability to remain anonymous if you pay in Bitcoin or Monero.</p>
<p><a href="https://njal.la">Njalla</a> is another good, privacy-oriented option for VPS services.</p>
<p>You'll have to decide what specifications you want on your VPS. For me, I only build and deploy low-resource HTML, PHP, and Python websites. This means I can survive on the smallest VPS: 1 CPU, 1GB of RAM, and 25GB SSD for $5.00 per month.</p>
<p>As noted above, the great thing about a VPS is you can request your provider to increase the resources at any time.</p>
<h2 id="configuring-dns-settings"><span class="section-number-2">4.</span> Configuring DNS Settings</h2>
<p>Okay, so now let's get into some actual work that has to be done to get content moved from a shared host to a VPS. At this point, I'm assuming you have a shared host with website content that you can still access, and you've purchased a new VPS and can SSH into that server.</p>
<p>The first change is minor, but it should be done immediately in order to get things moving: DNS settings. Go to wherever your DNS settings are handled. If your shared host also managed your DNS settings, you'll need to first move that DNS over to your new VPS provider. For me, I route my DNS through <a href="https://www.gandi.net">Gandi</a>.</p>
<p>Once you know where your DNS settings are, go ahead and update the <code class="verbatim">A</code> records to match the public IP address of your VPS. For example:</p>
<pre><code class="language-txt highlight"><span class="text plain">A         example.com     xxx.xxx.xxx.xxx
A         subdomain       xxx.xxx.xxx.xxx
CNAME     www             example.com.</span></code></pre>
<p>If you have any other records that require updates, such as MX or TXT records for a mail server, be sure to update those accordingly. Personally, I don't host my own mail server. I route all mail on my custom domains to <a href="https://www.migadu.com">Migadu</a>. Hosting your own email server can become complex quickly and is not for beginners.</p>
<p>DNS changes can take up to 48 hours to propagate, so be sure to give it some time before assuming you've made an error.</p>
<h2 id="server-updates-and-packages"><span class="section-number-2">5.</span> Server Updates and Packages</h2>
<p>Now that the DNS settings have been changed, let's set up our server while we wait for the DNS to propagate. First up is to ssh into your server. If you've signed up with a service like DigitalOcean, you can add your SSH key to your account and to your VPS droplet so that you don't need a password in order to SSH.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">ssh</span></span><span class="meta function-call arguments shell"> root@xxx.xxx.xxx.xxx</span></span></code></pre>
<p>The VPS that is used in this blog post runs Ubuntu 20.04 with an Apache web server. If you're working on a different operating system (OS) or want a different web server, such as Nginx, you'll have to use different commands to set it up.</p>
<p>First, let's update and upgrade our server.</p>
<p><strong>NOTE:</strong> Since we have logged in to the server as <code class="verbatim">root</code> for now, we don't need to use the <code class="verbatim">sudo</code> modifier before our commands.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">apt</span></span><span class="meta function-call arguments shell"> update</span> <span class="keyword operator logical and shell">&amp;&amp;</span> <span class="meta function-call shell"><span class="variable function shell">apt</span></span><span class="meta function-call arguments shell"> upgrade<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>y</span></span></span></code></pre>
<h2 id="create-a-user-account"><span class="section-number-2">6.</span> Create A User Account</h2>
<p>While being able to use <code class="verbatim">root</code> can be beneficial at times, you shouldn't use <code class="verbatim">root</code> unless you have to.</p>
<p>So let's set up a new user in our system. The <code class="verbatim">-m</code> option below tells the OS to create a home directory for the new user.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">adduser</span></span><span class="meta function-call arguments shell"> USERNAME</span></span></code></pre>
<p>Now, create a password for that user.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">passwd</span></span><span class="meta function-call arguments shell"> USERNAME</span></span></code></pre>
<p>Finally, add the user to the sudoers file, so they can perform privileged commands.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">usermod</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>a</span><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>G</span> sudo USERNAME</span></span></code></pre>
<p>If you are using SSH (secure shell protocol) keys and not passwords, you'll need to copy your SSH key from your local machine to the VPS. If you haven't disabled password-based SSH yet, the easiest way to do this is <code class="verbatim">ssh-copy-id</code> from your local computer (not from the VPS):</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">ssh-copy-id</span></span><span class="meta function-call arguments shell"> testuser@xxx.xxx.xxx.xxx</span></span></code></pre>
<p>If you've disabled password-based SSH, you'll need to manually copy your SSH key into the <code class="verbatim">~/.ssh/authorized_keys</code> file.</p>
<h2 id="install-software"><span class="section-number-2">7.</span> Install Software</h2>
<p>Our goal here is to host a web server, so the next step is to install the Apache web server and any other packages we need.</p>
<p>From this point on, I will be logged in as a user (not <code class="verbatim">root</code>) and will need to use the <code class="verbatim">sudo</code> modifier for most commands.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> apt update</span><span class="keyword operator logical continue shell">;</span> <span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> apt upgrade<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>y</span></span><span class="keyword operator logical continue shell">;</span> <span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> apt autoremove<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>y</span></span>
<span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> apt install apache2</span></span></code></pre>
<p>If you need other language support, such as PHP, you'll need to install that too.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> apt install libapache2-mod-php php-dom</span>
<span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> a2enmod php</span>
<span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> systemctl restart apache2</span></span></code></pre>
<h2 id="website-files-folders"><span class="section-number-2">8.</span> Website Files &amp; Folders</h2>
<p>Next up is to create the directories for the domain(s) we want to be hosted on this web server.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="support function cd shell">cd</span></span><span class="meta function-call arguments shell"> /var/www</span>
<span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> mkdir example.com</span></span></code></pre>
<p>We have a folder for <code class="verbatim">example.com</code> now, so let's add an <code class="verbatim">index.html</code> file and put it within a specific <code class="verbatim">public_html</code> folder. You don't need this <code class="verbatim">public_html</code> if you don't want it, but it helps with organizing items related to <code class="verbatim">example.com</code> that you don't want to publish to the internet.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="support function cd shell">cd</span></span><span class="meta function-call arguments shell"> example.com</span>
<span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> mkdir public_html</span> <span class="keyword operator logical and shell">&amp;&amp;</span> <span class="meta function-call shell"><span class="support function cd shell">cd</span></span><span class="meta function-call arguments shell"> public_html</span>
<span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> nano index.html</span></span></code></pre>
<p>You can put anything you want in this <code class="verbatim">index.html</code> file. If you can't think of anything, paste this in there:</p>
<pre><code class="language-html highlight"><span class="text html basic"><span class="meta tag sgml html"><span class="punctuation definition tag html">&lt;!</span><span class="meta tag sgml doctype html"><span class="entity name tag doctype html">DOCTYPE</span> html</span><span class="punctuation definition tag html">&gt;</span></span>
<span class="meta tag structure any html"><span class="punctuation definition tag begin html">&lt;</span><span class="entity name tag structure any html">html</span> <span class="meta attribute-with-value html"><span class="entity other attribute-name html">lang</span><span class="punctuation separator key-value html">=</span></span><span class="meta attribute-with-value html"><span class="string quoted double html"><span class="punctuation definition string begin html">&quot;</span>en<span class="punctuation definition string end html">&quot;</span></span></span><span class="punctuation definition tag end html">&gt;</span></span>
    <span class="meta tag structure any html"><span class="punctuation definition tag begin html">&lt;</span><span class="entity name tag structure any html">head</span><span class="punctuation definition tag end html">&gt;</span></span>
        <span class="meta tag inline any html"><span class="punctuation definition tag begin html">&lt;</span><span class="entity name tag inline any html">meta</span> <span class="meta attribute-with-value html"><span class="entity other attribute-name html">charset</span><span class="punctuation separator key-value html">=</span></span><span class="meta attribute-with-value html"><span class="string quoted double html"><span class="punctuation definition string begin html">&quot;</span>utf-8<span class="punctuation definition string end html">&quot;</span></span></span><span class="punctuation definition tag end html"> /&gt;</span></span>
        <span class="meta tag inline any html"><span class="punctuation definition tag begin html">&lt;</span><span class="entity name tag inline any html">meta</span> <span class="meta attribute-with-value html"><span class="entity other attribute-name html">name</span><span class="punctuation separator key-value html">=</span></span><span class="meta attribute-with-value html"><span class="string quoted double html"><span class="punctuation definition string begin html">&quot;</span>viewport<span class="punctuation definition string end html">&quot;</span></span></span> <span class="meta attribute-with-value html"><span class="entity other attribute-name html">content</span><span class="punctuation separator key-value html">=</span></span><span class="meta attribute-with-value html"><span class="string quoted double html"><span class="punctuation definition string begin html">&quot;</span>width=device-width, initial-scale=1<span class="punctuation definition string end html">&quot;</span></span></span><span class="punctuation definition tag end html"> /&gt;</span></span>
        <span class="meta tag inline any html"><span class="punctuation definition tag begin html">&lt;</span><span class="entity name tag inline any html">title</span><span class="punctuation definition tag end html">&gt;</span></span>Hello, world!<span class="meta tag inline any html"><span class="punctuation definition tag begin html">&lt;/</span><span class="entity name tag inline any html">title</span><span class="punctuation definition tag end html">&gt;</span></span>
    <span class="meta tag structure any html"><span class="punctuation definition tag begin html">&lt;/</span><span class="entity name tag structure any html">head</span><span class="punctuation definition tag end html">&gt;</span></span>
    <span class="meta tag structure any html"><span class="punctuation definition tag begin html">&lt;</span><span class="entity name tag structure any html">body</span><span class="punctuation definition tag end html">&gt;</span></span>
        <span class="meta tag block any html"><span class="punctuation definition tag begin html">&lt;</span><span class="entity name tag block any html">h1</span><span class="punctuation definition tag end html">&gt;</span></span>Hello, world!<span class="meta tag block any html"><span class="punctuation definition tag begin html">&lt;/</span><span class="entity name tag block any html">h1</span><span class="punctuation definition tag end html">&gt;</span></span>
    <span class="meta tag structure any html"><span class="punctuation definition tag begin html">&lt;/</span><span class="entity name tag structure any html">body</span><span class="punctuation definition tag end html">&gt;</span></span>
<span class="meta tag structure any html"><span class="punctuation definition tag begin html">&lt;/</span><span class="entity name tag structure any html">html</span><span class="punctuation definition tag end html">&gt;</span></span></span></code></pre>
<p>If you want something to be served at <code class="verbatim">example.com/page01/file.txt</code>, you'll have to create the <code class="verbatim">page01</code> directory under the <code class="verbatim">example.com</code> directory. For example:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="support function cd shell">cd</span></span><span class="meta function-call arguments shell"> /var/www/example.com/public_html</span>
<span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> mkdir page01</span>
<span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> nano file.txt</span></span></code></pre>
<h2 id="apache-configuration"><span class="section-number-2">9.</span> Apache Configuration</h2>
<p>Now, let's set up the files that will tell the server where to find the files for <code class="verbatim">example.com</code>. We will copy the default configuration file and create our own.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="support function cd shell">cd</span></span><span class="meta function-call arguments shell"> /etc/apache2/sites-available</span>
<span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> cp 000-default.conf example.com.conf</span>
<span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> nano example.com.conf</span></span></code></pre>
<p>This configuration file will have a few default lines, but you'll need to edit it to look similar to this (settings may change based on your personal needs):</p>
<pre><code class="language-config">&lt;VirtualHost *:80&gt;
    ServerAdmin your-email@email-provider.com
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot /var/www/example.com/public_html
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
&lt;/VirtualHost&gt;</code></pre>
<p>Now, enable the configuration for your new site, disable the default configuration, and reload the web server.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> a2ensite example.com.conf</span>
<span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> a2dissite 000-default.conf</span>
<span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> systemctl reload apache2</span></span></code></pre>
<p>You can always run a test to make sure no errors or warnings are found in your configuration files.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> apache2ctl configtest</span></span></code></pre>
<p>Now, restart the web server entirely. After this, you should be able to browse to <code class="verbatim">http://example.com</code> and see the HTML (hypertext markup language) content you provided earlier. Note that SSL/TLS has not been enabled yet, so you won't be able to use the secure version yet (<code class="verbatim">https://example.com</code>).</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> systemctl restart apache2</span></span></code></pre>
<p>You can repeat this for as many websites as you need. Just create the domain folders in <code class="verbatim">/var/www/</code>, add the configuration file, enable the configuration, and restart <code class="verbatim">apache2</code>.</p>
<h2 id="ssl-tls-certificates-serve-websites-over-https"><span class="section-number-2">10.</span> SSL/TLS Certificates: Serve Websites Over HTTPS</h2>
<p>In order to serve secure content, you'll need to obtain SSL/TLS certificates. Luckily, there's a free tool called <a href="https://certbot.eff.org">Certbot</a> that helps us with the process.</p>
<p>The first step is to install <code class="verbatim">snapd</code> and <code class="verbatim">core</code> for Ubuntu.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> apt install snapd</span>
<span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> snap install core</span>
<span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> snap refresh core</span></span></code></pre>
<p>Next, install the <code class="verbatim">certbot</code> snap package.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> snap install<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> --</span>classic</span> certbot</span></span></code></pre>
<p>Execute the following command to ensure that the <code class="verbatim">certbot</code> command can be run.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> ln<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>s</span> /snap/bin/certbot /usr/bin/certbot</span></span></code></pre>
<p>Finally, you can run <code class="verbatim">certbot</code> one of two ways:</p>
<ol>
<li>run it and let it alter your Apache configuration files automatically to enable HTTPS (Hypertext Transport Protocol) redirects.</li>
<li>run it and only allow it to create certificates. You'll need to manually alter the config files to enable HTTPS redirects.</li>
</ol>
<p>Run certbot and allow automatic config changes:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> certbot<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> --</span>apache</span></span></span></code></pre>
<p>Run certbot for certificates only and don't allow it to alter config files:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> certbot certonly<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> --</span>apache</span></span></span></code></pre>
<p>The Certbot packages on your system come with a <code class="verbatim">cron</code> job or <code class="verbatim">systemd</code> timer that will renew your certificates automatically before they expire. You will not need to run Certbot again unless you change your configuration. You can test automatic renewal for your certificates by running this command:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> certbot renew<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> --</span>dry-run</span></span></span></code></pre>
<p>Now, test your domains by going to <code class="verbatim">https://example.com</code>.</p>
<h2 id="firewall-security"><span class="section-number-2">11.</span> Firewall Security</h2>
<p>To enable better security on your server, you'll need to enable a basic firewall. For Ubuntu, we'll use <a href="https://cleberg.net/blog/ufw.html">the uncomplicated firewall</a>.</p>
<p>Now, add the following rules to the firewall allow SSH, Apache, and HTTP(S) connections. If you need to, you can enable different ports for specific applications.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> ufw default deny incoming</span>
<span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> ufw default allow outgoing</span>
<span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> ufw allow OpenSSH</span>
<span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> ufw allow Apache</span>
<span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> ufw allow proto tcp from any to any port 80,443</span></span></code></pre>
<p>Once you've added all the rules you need, enable the firewall.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> ufw enable</span></span></code></pre>
<h2 id="troubleshooting"><span class="section-number-2">12.</span> Troubleshooting</h2>
<p>If you run into any issues during your VPS set-up, be sure to walk back through your actions and make sure you didn't miss any steps.</p>
<p>Many websites have fantastic guides to setting up various web servers. This is one of the areas <a href="https://www.digitalocean.com/community/tutorials">where DigitalOcean shines</a>. For simpler or more Linux-oriented questions, I suggest using [Linuxize] (<a href="https://linuxize.com">https://linuxize.com</a>).</p>
<p>If you're getting certain errors (e.g. <code class="verbatim">500 Internal Server Error</code>) and need to debug locally, you can view the <code class="verbatim">access.log</code> and <code class="verbatim">error.log</code> files in the <code class="verbatim">/var/log/apache/</code> directory.</p>
]]></description>
    </item>
    <item>
      <title>Vaporwave vs. Outrun</title>
      <link>https://cleberg.net/blog/vaporwave-vs-outrun.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/vaporwave-vs-outrun.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Sun, 28 Mar 2021 00:00:00 +0000</pubDate>
      <category>personal</category>
      <description><![CDATA[<h2 id="overview"><span class="section-number-2">1.</span> Overview</h2>
<p>When it comes to an aesthetic that originated primarily online, there tends to be a lot of confusion around what falls into each specific genre. This post discusses Vaporwave and Outrun, which have become almost synonymous in the minds of those online who aren't hardcore into these genres of media. More specifically, Outrun is largely an unknown term while all aesthetics in these two genres are usually attributed to Vaporwave. For example, take a look at the image search results for Vaporwave: the results include <strong>a lot</strong> of Outrun-themed images. You'll find a similar trend almost everywhere.</p>
<figure><img src="https://img.cleberg.net/blog/20210328-vaporwave-vs-outrun/vaporwave-search-results.webp" alt="Search engine results for vaporwave, showing many outrun-related images."><figcaption><span class="figure-number">Figure 1: </span>Vaporwave Search Results</figcaption></figure>
<h2 id="vaporwave"><span class="section-number-2">2.</span> Vaporwave</h2>
<figure><img src="https://img.cleberg.net/blog/20210328-vaporwave-vs-outrun/macintosh-plus.webp" alt="Album cover of the Macintosh Plus album."><figcaption><span class="figure-number">Figure 2: </span>Macintosh Plus Album Cover</figcaption></figure>
<p>Okay, so what is Vaporwave? I'm going to just copy-and-paste some general info from the Wikipedia article on <a href="https://en.wikipedia.org/wiki/Vaporwave">Vaporwave</a>, so that I'm not repeating everything you can already search for online:</p>
<blockquote>
<p>Vaporwave is a microgenre of electronic music, a visual art style, and an Internet meme that emerged in the early 2010s. It is defined partly by its slowed-down, chopped and screwed samples of smooth jazz, elevator, R&amp;B, and lounge music from the 1980s and 1990s. The surrounding subculture is sometimes associated with an ambiguous or satirical take on consumer capitalism and pop culture, and tends to be characterized by a nostalgic or surrealist engagement with the popular entertainment, technology and advertising of previous decades. Visually, it incorporates early Internet imagery, late 1990s web design, glitch art, anime, 3D-rendered objects, and cyberpunk tropes in its cover artwork and music videos.</p>
</blockquote>
<p>This is an excellent summary, and it helps address my point here: there are specific aspects that make Vaporwave unique:</p>
<h3 id="time-frame"><span class="section-number-3">2.1.</span> Time Frame</h3>
<p>The time frame for references, logos, etc. focuses mostly on the 1990s in Vaporwave. You'll see old school Pepsi logos, Microsoft 95 screens, tropical plants, classic marble sculptures, and many references from Japan's influence in the 90s.</p>
<h3 id="art"><span class="section-number-3">2.2.</span> Art</h3>
<p>The color scheme is generally a soft, light palette that uses pastel colors. The backdrop will often be in a light-pink or teal blue.</p>
<h3 id="music"><span class="section-number-3">2.3.</span> Music</h3>
<p>The musical genre of Vaporwave incorporates soft tunes, lounge music, and sound effects that will make the listener reminisce of the 90s. The sounds of the genre are generally slower-paced and calming. The major breakthrough artist for Vaporwave was <a href="https://en.wikipedia.org/wiki/Vektroid">Macintosh Plus</a>, who released the album <a href="https://archive.org/details/MACINTOSHPLUS-FLORALSHOPPE_complete">Floral Shoppe</a> in 2011. Another more recent example is the artist <a href="https://sadbert.bandcamp.com/">sadbert</a>, whose latest album incorporates the upbeat tones of the 1999 Dilbert television series.</p>
<p>Notice that Vaporwave doesn't include things like racing cars, futuristic technology, chrome, or the deep orange/purple color scheme. Vaporwave is a focus on the idyllic state of the world when technology was becoming common in households, a reality that we have already experienced. Focus on the most aesthetically-pleasing parts of that past is a large part of Vaporwave.</p>
<h2 id="outrun"><span class="section-number-2">3.</span> Outrun</h2>
<figure><img src="https://img.cleberg.net/blog/20210328-vaporwave-vs-outrun/outrun.jpg" alt="The classic outrun picture with digital hills and a grid leading to a far-away sunset."><figcaption><span class="figure-number">Figure 3: </span>Outrun</figcaption></figure>
<p>Now, let's get to Outrun. This one is a little trickier since the genre has largely been lumped under the Vaporwave title for so long. However, it stems from the <a href="https://en.wikipedia.org/wiki/Synthwave">Synthwave</a> music genre and is likely named after the 1986 racer game, <a href="https://en.wikipedia.org/wiki/Out_Run">Out Run</a>.</p>
<h3 id="time-frame"><span class="section-number-3">3.1.</span> Time Frame</h3>
<p>Outrun can be thought of as a retro-futuristic aesthetic born from the 1980s.</p>
<h3 id="art"><span class="section-number-3">3.2.</span> Art</h3>
<p>The color scheme uses a very dark color palette with the main colors being deep oranges, blues, and purples. Red edges are common around objects in Outrun art. The background of the Outrun aesthetic is almost always a neon grid like you'd expect to see in Tron or a 1980s arcade machine.</p>
<p>Classic sports cars, chrome robots, computer generated graphics and fonts, and the occasional use of rain or palm trees can be found in Outrun art.</p>
<h3 id="music"><span class="section-number-3">3.3.</span> Music</h3>
<p>This aesthetic has a more aggressive and fast-paced style of music, which tends to match the subject of the art in this aesthetic.</p>
<p>Outrun enthusiasts love what people in the 1980s thought the future would look like. Take a look at a common video game discussed in Outrun circles, Far Cry 3: Blood Dragon:</p>
<figure><img src="https://img.cleberg.net/blog/20210328-vaporwave-vs-outrun/far-cry.jpg" alt="The game cover for Far Cary 3: Blood Dragon, showing ninjas, lasers, dinosaurs, and cyborgs."><figcaption><span class="figure-number">Figure 4: </span>Fry Cry 3: Blood Dragon</figcaption></figure>
<p>Another example that doesn't force the color scheme as hard as some online art does is Kung Fury:</p>
<figure><img src="https://img.cleberg.net/blog/20210328-vaporwave-vs-outrun/kung-fury.jpg" alt="The movie cover for Kung Fury, showing the proteagonist in a city at night with a moon."><figcaption><span class="figure-number">Figure 5: </span>Kung Fury</figcaption></figure>
<figure><img src="https://img.cleberg.net/blog/20210328-vaporwave-vs-outrun/kung-fury-hacker.jpg" alt="The HACKERMAN scene from Kung Fury, showing a classic 1980's hacker in a computer room."><figcaption><span class="figure-number">Figure 6: </span>Kung Fury Hacker Scene</figcaption></figure>
<h2 id="conclusion"><span class="section-number-2">4.</span> Conclusion</h2>
<p>While Vaporwave and Outrun share similarities, they are two distinct aesthetics with many important distinctions. Someone who enjoys one may not necessarily enjoy the other, so it's important to make sure we properly describe the aesthetic we're looking for.</p>
]]></description>
    </item>
    <item>
      <title>Gemini Capsule: Deploy and Own Your Content</title>
      <link>https://cleberg.net/blog/gemini-capsule.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/gemini-capsule.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Sun, 28 Mar 2021 00:00:00 +0000</pubDate>
      <category>linux</category>
      <category>web</category>
      <description><![CDATA[<h2 id="what-is-gemini"><span class="section-number-2">1.</span> What is Gemini?</h2>
<p><a href="https://gemini.circumlunar.space/">Gemini</a> is an internet protocol introduced in June 2019 as an alternative to the Hypertext Transfer Protocol (HTTP) or Gopher. In layman's terms, it's an alternative way to browse sites (called capsules) that requires a special browser. Since Gemini is not standardized as an internet standard, normal web browsers won't be able to load a Gemini capsule. Instead, you'll need to use <a href="https://gemini.circumlunar.space/clients.html">a Gemini-specific browser</a>.</p>
<p>The content found within a Gemini page is called <a href="https://gemini.circumlunar.space/docs/cheatsheet.gmi">Gemtext</a> and is <em>extremely</em> basic (on purpose). Gemini only processes the text, no media content like images. However, you're able to style 3 levels of headings, regular text, links (which will display on their own line), quotes, and an unordered list.</p>
<p>Here's a complete listing of valid Gemtext:</p>
<pre><code class="language-txt highlight"><span class="text plain"># Heading 1
## Heading 2
### Heading 3

Regular text! Lorem ipsum dolor sit amet.

=&gt; https://example.com My Website
=&gt; gemini://example.com My Gemini Capsule

&gt; &quot;If life were predictable it would cease to be life, and be without flavor.&quot; - Eleanor Roosevelt

My List:
** Item
** Item

```Anything between three backticks will be rendered as code.```</span></code></pre>
<h4 id="free-option"><span class="section-number-4">1.0.1.</span> Free Option</h4>
<p>There are probably numerous websites that allow you to create your personal Gemini capsule, but I'm going to focus on the two sites that I have personally tested. The first option below, Midnight Pub, allows you to create/edit any Gemini files you want in your account. This is essentially a graphical option with a built-in text box for editing. The second option below, Sourcehut, allows you to use a Git repository and automatic build process to deploy your personal Gemini capsule every time you push a commit.</p>
<h3 id="midnight-pub-beginner-friendly"><span class="section-number-3">1.1.</span> Midnight Pub - Beginner Friendly</h3>
<p><a href="https://midnight.pub/">Midnight Pub</a> is a small, virtual community meant to reflect the atmosphere of wandering into a small alley pub. The site is built in Gemtext and has a server-side process to convert Gemtext to HTML if someone loads the site in an HTTP(S) browser.</p>
<p>To create an account, you'll need to email the owner of the website to obtain a key. You can find their email on the Midnight Pub homepage. Once registered, head to <a href="https://midnight.pub/account">your account</a> and select <a href="https://midnight.pub/site">manage site</a>. This is the screen where you can upload or create any files to be displayed on the internet.</p>
<p>For example, I've created both a Hypertext Markup Language (HTML) file and a Gemini file. Remember that Gemini is automatically converted to HTML on the Pub, so you don't need an HTML version. For example, I created an HTML version to add in some extra styling.</p>
<p>All you need to do is create a page like <code class="verbatim">index.gmi</code> and use your Gemini browser to head over to your-username.midnight.pub to see the result.</p>
<p>That's all there is to it! Easy enough, right? Let's check out a more advanced version in the next section.</p>
<h2 id="paid-option"><span class="section-number-2">2.</span> Paid Option</h2>
<p>As of 2021, Sourcehut has decided to require users to have a paid account in order to utilize their automated build system. For now, paid accounts can be as low as $2/month.</p>
<h3 id="sourcehut"><span class="section-number-3">2.1.</span> Sourcehut</h3>
<p><a href="https://sourcehut.org/">Sourcehut</a> is a collection of software development tools, but mostly surrounds their hosted Git repository service. Simply put, it's a minimal and more private alternative to services like GitHub.</p>
<p>This walkthrough is more advanced and involves things like Git, SSH, the command line. If you don't think you know enough to do this, check out my walkthrough on creating a Gemini capsule for the Midnight Pub instead.</p>
<p>The first thing you'll need to do is create an SSH key pair, if you don't already have one on your system. Once created, grab the contents of <code class="verbatim">id_rsa.pub</code> and add it to your Sourcehut account settings - this will allow you to push and pull code changes without using a username/password.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">ssh</span></span><span class="meta function-call arguments shell"> keygen</span></span></code></pre>
<p>Next up, let's create a repository with the proper name so that the Sourcehut build system will know we want them to host a website for us. Use the following format exactly:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">mkdir</span></span><span class="meta function-call arguments shell"> your-username.srht.site</span> <span class="keyword operator logical and shell">&amp;&amp;</span> <span class="meta function-call shell"><span class="support function cd shell">cd</span></span><span class="meta function-call arguments shell"> your-username.srht.site</span></span></code></pre>
<p>Now that we've created the repo, let's initialize Git and add the proper remote URL.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">git</span></span><span class="meta function-call arguments shell"> init</span></span></code></pre>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">git</span></span><span class="meta function-call arguments shell"> remote add origin git@git.sr.ht:<span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>your-username/your-username.srht.site</span></span></code></pre>
<p>Now that our repository is set up and configured, we will need to create at least two files:</p>
<ul>
<li><code class="verbatim">index.gmi</code></li>
<li><code class="verbatim">.build.yml</code></li>
</ul>
<p>For your <code class="verbatim">.build.yml</code> file, use the following content and be sure to update the <code class="verbatim">site</code> line with your username!</p>
<pre><code class="language-yaml highlight"><span class="source yaml"><span class="string unquoted plain out yaml"><span class="entity name tag yaml">image</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string unquoted plain out yaml">alpine/latest</span>
<span class="string unquoted plain out yaml"><span class="entity name tag yaml">oauth</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string unquoted plain out yaml">pages.sr.ht/PAGES:RW</span>
<span class="string unquoted plain out yaml"><span class="entity name tag yaml">environment</span></span><span class="punctuation separator key-value mapping yaml">:</span>
    <span class="string unquoted plain out yaml"><span class="entity name tag yaml">site</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="string unquoted plain out yaml">your-username.srht.site</span>
<span class="string unquoted plain out yaml"><span class="entity name tag yaml">tasks</span></span><span class="punctuation separator key-value mapping yaml">:</span>
    <span class="punctuation definition block sequence item yaml">-</span> <span class="string unquoted plain out yaml"><span class="entity name tag yaml">package</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="keyword control flow block-scalar literal yaml">|</span>
<span class="string unquoted block yaml">          cd $site
          tar -cvz . &gt; ../site.tar.gz
</span>    <span class="punctuation definition block sequence item yaml">-</span> <span class="string unquoted plain out yaml"><span class="entity name tag yaml">upload</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="keyword control flow block-scalar literal yaml">|</span>
<span class="string unquoted block yaml">          acurl -f https://pages.sr.ht/publish/$site -Fcontent=@site.tar.gz -Fprotocol=GEMINI</span></span></code></pre>
<p>For the <code class="verbatim">index.gmi</code> file, put whatever you want in there and save it. You could even just copy and paste the Gemtext cheatsheet.</p>
<p>If you want to serve both HTML and Gemini files from this repository, just add a second command to the <code class="verbatim">upload</code> section:</p>
<pre><code class="language-yaml highlight"><span class="source yaml"><span class="punctuation definition block sequence item yaml">-</span> <span class="string unquoted plain out yaml"><span class="entity name tag yaml">upload</span></span><span class="punctuation separator key-value mapping yaml">:</span> <span class="keyword control flow block-scalar literal yaml">|</span>
<span class="string unquoted block yaml">      acurl -f https://pages.sr.ht/publish/$site -Fcontent=@site.tar.gz -Fprotocol=GEMINI
      acurl -f https://pages.sr.ht/publish/$site -Fcontent=@site.tar.gz</span></span></code></pre>
<p>Lastly, commit your changes and push them to the remote repo.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">git</span></span><span class="meta function-call arguments shell"> add .</span><span class="keyword operator logical continue shell">;</span> <span class="meta function-call shell"><span class="variable function shell">git</span></span><span class="meta function-call arguments shell"> commit<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>m</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>initial commit<span class="punctuation definition string end shell">&quot;</span></span></span><span class="keyword operator logical continue shell">;</span> <span class="meta function-call shell"><span class="variable function shell">git</span></span><span class="meta function-call arguments shell"> push<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> --</span>set-upstream</span> origin HEAD</span></span></code></pre>
<p>If you've successfully created the files with the proper format, you'll see the terminal print a message that lets you know where the automatic build is taking place. For example, here's what the terminal tells me:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">remote:</span></span><span class="meta function-call arguments shell"> Build started:</span>
<span class="meta function-call shell"><span class="variable function shell">remote:</span></span><span class="meta function-call arguments shell"> https://builds.sr.ht/<span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>user/job/689803 <span class="keyword control regexp set begin shell">[</span>.build.yml<span class="keyword control regexp set end shell">]</span></span></span></code></pre>
<p>Now that you've properly built your Sourcehut page, you can browse to your-username.srht.site in a Gemini browser and view the final results.</p>
]]></description>
    </item>
    <item>
      <title>Scripting Mass Clones from GitHub and Sourcehut</title>
      <link>https://cleberg.net/blog/clone-github-repos.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/clone-github-repos.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Fri, 19 Mar 2021 00:00:00 +0000</pubDate>
      <category>personal</category>
      <description><![CDATA[<h2 id="cloning-from-github"><span class="section-number-2">1.</span> Cloning from GitHub</h2>
<p>If you're like me and use a lot of different devices [and sometimes decide to just wipe your device and start with a new operating system (OS)], you probably know the pain of cloning all your old code repositories down to your local file system.</p>
<p>If you're using GitHub, you can easily clone all of your code back down in just seconds. First, create a bash script. I do so by opening a new file in <code class="verbatim">nano</code>, but you can use <code class="verbatim">gedit</code>, <code class="verbatim">vim</code>, or something else:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">nano</span></span><span class="meta function-call arguments shell"> clone_github_repos.sh</span></span></code></pre>
<p>Next, paste in the following information. Note that you can replace the word <code class="verbatim">users</code> in the first line with <code class="verbatim">orgs</code> and type an organization's name instead of a user's name.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="variable other readwrite assignment shell">CNTX</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell">users</span><span class="meta function-call shell"></span><span class="keyword operator logical continue shell">;</span> <span class="variable other readwrite assignment shell">NAME</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell">YOUR-USERNAME</span><span class="meta function-call shell"></span><span class="keyword operator logical continue shell">;</span> <span class="variable other readwrite assignment shell">PAGE</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell">1</span>
<span class="meta function-call shell"><span class="variable function shell">curl</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>https://api.github.com/<span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">CNTX</span></span>/<span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">NAME</span></span>/repos?page=<span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">PAGE</span></span>&amp;per_page=100<span class="punctuation definition string end shell">&quot;</span></span></span> <span class="keyword operator logical pipe shell">|</span>
  <span class="meta function-call shell"><span class="variable function shell">grep</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>e</span> <span class="string quoted single shell"><span class="punctuation definition string begin shell">&#39;</span>git_url*<span class="punctuation definition string end shell">&#39;</span></span></span> <span class="keyword operator logical pipe shell">|</span>
  <span class="meta function-call shell"><span class="variable function shell">cut</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>d</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span> -f 4 |
  xargs -L1 git clone</span></span></span></code></pre>
<p>Finally, save the bash script and make it executable.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">chmod</span></span><span class="meta function-call arguments shell"> a+x clone_github_repos.sh</span></span></code></pre>
<p>Now you can run the script and should see the cloning process begin.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">./clone_github_repos.sh</span></span></span></code></pre>
<h2 id="cloning-from-sourcehut"><span class="section-number-2">2.</span> Cloning from Sourcehut</h2>
<p>I haven't fully figured out how to directly incorporate Sourcehut's GraphQL application programming interface (API) into a bash script yet, so this one will take two steps.</p>
<p>First, log-in to Sourcehut and go to their <a href="https://git.sr.ht/graphql">GraphQL playground for Git</a>. Next, paste the following query into the left box:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">query</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion brace shell"><span class="punctuation section expansion brace begin shell">{</span>
  me <span class="meta group expansion brace shell"><span class="punctuation section expansion brace begin shell">{</span>
    canonicalName
    repositories() <span class="meta group expansion brace shell"><span class="punctuation section expansion brace begin shell">{</span>
      cursor
      results <span class="meta group expansion brace shell"><span class="punctuation section expansion brace begin shell">{</span>
        name
      <span class="punctuation section expansion brace end shell">}</span></span>
    <span class="punctuation section expansion brace end shell">}</span></span>
  <span class="punctuation section expansion brace end shell">}</span></span>
<span class="punctuation section expansion brace end shell">}</span></span></span></span></code></pre>
<p>The output on the right side will give you an object of all your repositories. Just grab that text and remove all the characters such as quotation marks and curly brackets. You will need a single-line list of space-separated values for the next step.</p>
<p>Now let's create the bash script:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">nano</span></span><span class="meta function-call arguments shell"> clone_sourcehut_repos.sh</span></span></code></pre>
<p>Next, paste the following bash script in with the list of repositories you obtained above and replace <code class="verbatim">your-username</code> with your username.</p>
<p>Note that this uses the secure shell protocol (SSH)-based Git cloning method (e.g. <code class="verbatim">git@git...</code>), so you'll need to ensure you have set up Sourcehut with your SSH key.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="variable other readwrite assignment shell">repos</span><span class="keyword operator assignment shell">=</span><span class="punctuation section parens begin shell">(</span>repo1 repo2 repo3<span class="punctuation section parens end shell">)</span>

<span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> List all sub-directories in the current directory</span><span class="comment line number-sign shell">
</span><span class="keyword control for shell">for</span><span class="meta group for shell"> repo <span class="keyword control in shell">in</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section expansion parameter begin shell">{</span></span><span class="meta group expansion parameter shell"><span class="variable other readwrite shell">repos<span class="punctuation section braces begin shell">[</span><span class="variable language array shell">@</span><span class="punctuation section braces end shell">]</span></span></span><span class="meta group expansion parameter shell"><span class="punctuation section expansion parameter end shell">}</span></span><span class="punctuation definition string end shell">&quot;</span></span></span>
<span class="keyword control do shell">do</span>
    <span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> Clone</span><span class="comment line number-sign shell">
</span>    <span class="meta function-call shell"><span class="variable function shell">git</span></span><span class="meta function-call arguments shell"> clone git@git.sr.ht:<span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>your-username/<span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">repo</span></span></span>
<span class="meta function-call shell"><span class="variable function shell">done</span></span></span></code></pre>
<p>Finally, save the bash script and make it executable.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">chmod</span></span><span class="meta function-call arguments shell"> a+x clone_sourcehut_repos.sh</span></span></code></pre>
<p>Now you can run the script and should see the cloning process begin.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">./clone_sourcehut_repos.sh</span></span></span></code></pre>
<h2 id="moving-repositories-to-a-new-host"><span class="section-number-2">3.</span> Moving Repositories to a New Host</h2>
<p>Now that you have all of your code repositories cloned to your local computer, you may want to change the remote host (e.g., moving from GitHub to GitLab). To do this, let's create another bash script:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">nano</span></span><span class="meta function-call arguments shell"> change_remote_urls.sh</span></span></code></pre>
<p>Paste the following information and be sure to change the URL (uniform resource locator) information to whichever host you are moving to. For this example, I am looping through all of my cloned GitHub directories and changing them to Sourcehut (e.g. <code class="verbatim">&lt;YOUR_NEW_REMOTE_URL&gt;</code> -&gt; <code class="verbatim">git@git.sr.ht:~myusername</code>).</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> List all sub-directories in the current directory</span><span class="comment line number-sign shell">
</span><span class="keyword control for shell">for</span><span class="meta group for shell"> dir <span class="keyword control in shell">in</span> <span class="keyword operator regexp quantifier shell">*</span>/</span>
<span class="keyword control do shell">do</span>
    <span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> Remove the trailing &quot;/&quot;</span><span class="comment line number-sign shell">
</span>    <span class="variable other readwrite assignment shell">dir</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell"><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section expansion parameter begin shell">{</span></span><span class="meta group expansion parameter shell"><span class="variable other readwrite shell">dir<span class="keyword operator expansion shell">%</span></span></span><span class="meta group expansion parameter shell"><span class="keyword operator regexp quantifier shell">*</span>/</span><span class="meta group expansion parameter shell"><span class="punctuation section expansion parameter end shell">}</span></span></span>
    <span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> Enter sub-directory</span><span class="comment line number-sign shell">
</span>    <span class="meta function-call shell"><span class="support function cd shell">cd</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="variable other readwrite shell">dir</span></span></span>
    <span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> Change remote Git URL</span><span class="comment line number-sign shell">
</span>    <span class="meta function-call shell"><span class="variable function shell">git</span></span><span class="meta function-call arguments shell"> remote set-url origin <span class="keyword operator assignment redirection shell">&lt;</span>YOUR_NEW_REMOTE_URL<span class="keyword operator assignment redirection shell">&gt;</span>/<span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section expansion parameter begin shell">{</span></span><span class="meta group expansion parameter shell"><span class="variable other readwrite shell">dir<span class="keyword operator expansion shell">##</span></span></span><span class="meta group expansion parameter shell"><span class="keyword operator regexp quantifier shell">*</span>/</span><span class="meta group expansion parameter shell"><span class="punctuation section expansion parameter end shell">}</span></span><span class="punctuation definition string end shell">&quot;</span></span></span>
    <span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> Push code to new remote</span><span class="comment line number-sign shell">
</span>    <span class="meta function-call shell"><span class="variable function shell">git</span></span><span class="meta function-call arguments shell"> push</span>
    <span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> Go back to main directory</span><span class="comment line number-sign shell">
</span>    <span class="meta function-call shell"><span class="support function cd shell">cd</span></span><span class="meta function-call arguments shell"> ..</span>
<span class="meta function-call shell"><span class="variable function shell">done</span></span></span></code></pre>
<p>Finally, save the bash script and make it executable.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">chmod</span></span><span class="meta function-call arguments shell"> a+x change_remote_urls.sh</span></span></code></pre>
<p>Now you can run the script and should see the cloning process begin.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">./change_remote_urls.sh</span></span></span></code></pre>
]]></description>
    </item>
    <item>
      <title>macOS for Linux Users</title>
      <link>https://cleberg.net/blog/macos.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/macos.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Fri, 19 Feb 2021 00:00:00 +0000</pubDate>
      <category>linux</category>
      <description><![CDATA[<h2 id="diving-into-macos"><span class="section-number-2">1.</span> Diving into macOS</h2>
<p>After spending nearly 15 years working with Windows and 8 years on Linux, I have experienced macOS for the first time. By chance, my spouse happened to buy a new MacBook and gifted me their 2013 model. Of course, I still consider my Linux desktop to be my daily driver and keep Windows around for gaming needs, but over the past week I've found myself using the MacBook more and more for things that don't require gaming specs or advanced developer tools.</p>
<h2 id="initial-thoughts"><span class="section-number-2">2.</span> Initial Thoughts</h2>
<p>Before I move on to the technical aspects of my set-up, I want to take some time and express my thoughts on the overall operating system (OS).</p>
<p>As expected, the initial computer setup is a breeze with Mac's guided graphical user interface (GUI) installer.</p>
<p>The desktop itself reminds me of GNOME more than anything else I've seen: even Pantheon from <a href="https://elementary.io/">ElementaryOS</a>, which people commonly refer to as the closest Linux distro to macOS. The desktop toolbar is great and far surpasses the utility of the GNOME toolbar due to the fact that the extensions and icons <em>actually work</em>. I launch macOS and immediately see my shortcuts for Tresorit, Bitwarden, and Mullvad pop up as the computer loads.</p>
<p>Even further, the app dock is very useful and will be yet another familiarity for GNOME users. I know many people like panels instead of docks, but I've always found docks to have a more pleasing UI. However, I had to disable the "Show recent applications in Dock" preference; I can't stand items taking up precious screen space if I'm not currently using them. On that same note, it's taking me some time to get use to the fact that I have to manually quit an app or else it will still stay open/active in the dock, even if I've closed out all windows for that app (e.g. Firefox).</p>
<p>Overall, I'm having a lot of fun and for users who spend a large majority of their time performing basic tasks like web browsing, writing, watching media, etc., macOS is a fantastic option.</p>
<p>The rest of this post explains the technicalities of how I set up my command line interface (CLI) environment to make me feel more at-home, similar to the environments I set up on Fedora, Ubuntu, etc.</p>
<h2 id="making-it-feel-like-home"><span class="section-number-2">3.</span> Making it Feel Like Home</h2>
<p>If you're someone who uses Linux primarily, no doubt your first thought when booting macOS will be the same as mine was: "Where is the terminal and how do I set up my favorite utilities?"</p>
<p>Luckily, macOS hasn't completely hidden away the development tools from the average user. You can easily find the Terminal app in the Launchpad area, but it's probably not what you're used to. I was surprised (and happy) to see that the default shell is <code class="verbatim">zsh</code>, the shell I use on all of my Linux distros. However, the commands are not the same - even the ones you may think are native to the shell. Commands like <code class="verbatim">dir</code> do not exist, so other native commands like <code class="verbatim">ls -la</code> or <code class="verbatim">pwd</code> are more useful here.</p>
<p>With only a few minutes of installing and tweaking a few packages, I was able to recreate a terminal environment that I feel very comfortable using. See the image below for a preview of the iTerm2 app with a split view between my macOS desktop shell and an SSH (secure shell protocol) session into my server.</p>
<h2 id="xcode"><span class="section-number-2">4.</span> Xcode</h2>
<p>My first step was to search the web for any hints on how to get <code class="verbatim">zsh</code> back up to the state I like, with extensions, themes, etc. My first step was to install the CLI tools for <a href="https://developer.apple.com/xcode/">Xcode</a>, Apple's suite of development tools.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> xcode-select<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>r</span></span></span></code></pre>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> xcode-select<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> --</span>install</span></span></span></code></pre>
<h2 id="homebrew"><span class="section-number-2">5.</span> Homebrew</h2>
<p>Next up is to install <a href="https://brew.sh">Homebrew</a>, a nifty package manager for macOS.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">/bin/bash</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>c</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion command parens shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section parens begin shell">(</span><span class="meta function-call shell"><span class="variable function shell">curl</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>fsSL</span></span>
<span class="meta function-call shell"><span class="variable function shell">https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh</span></span><span class="punctuation section parens end shell">)</span></span><span class="punctuation definition string end shell">&quot;</span></span></span></span></code></pre>
<p>I ran into a permission error when installing Homebrew:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">Error:</span></span><span class="meta function-call arguments shell"> Failed to link all completions, docs and manpages: Permission denied @</span>
    <span class="meta function-call shell"><span class="variable function shell">rb_file_s_symlink</span></span><span class="meta function-call arguments shell"> - (../../../Homebrew/completions/zsh/_brew,</span>
    <span class="meta function-call shell"><span class="variable function shell">/usr/local/share/zsh/site-functions/_brew</span></span><span class="meta function-call shell"></span><span class="meta post-cmd shell">)</span> <span class="meta function-call shell"><span class="variable function shell">Failed</span></span><span class="meta function-call arguments shell"> during:</span>
    <span class="meta function-call shell"><span class="variable function shell">/usr/local/bin/brew</span></span><span class="meta function-call arguments shell"> update<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> --</span>force</span><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> --</span>quiet</span></span></span></code></pre>
<p>I found that the following permission modification worked like a charm. However, I noted that some users online discussed the fact that this solution may not work if your system has multiple users who use Homebrew.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> chown<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>R</span> <span class="meta group expansion command parens shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section parens begin shell">(</span><span class="meta function-call shell"><span class="variable function shell">whoami</span></span><span class="punctuation section parens end shell">)</span></span> <span class="meta group expansion command parens shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section parens begin shell">(</span><span class="meta function-call shell"><span class="variable function shell">brew</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> --</span>prefix</span></span><span class="punctuation section parens end shell">)</span></span>/<span class="keyword operator regexp quantifier shell">*</span></span></span></code></pre>
<p>Next up is to ensure Homebrew is updated and cleaned.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">brew</span></span><span class="meta function-call arguments shell"> update</span></span></code></pre>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">brew</span></span><span class="meta function-call arguments shell"> cleanup</span></span></code></pre>
<h2 id="iterm2"><span class="section-number-2">6.</span> iTerm2</h2>
<p>Now that I've installed the basic utilities for development, I moved onto installing iTerm2, a much better terminal than the default.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">brew</span></span><span class="meta function-call arguments shell"> install<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> --</span>cask</span> iterm2</span></span></code></pre>
<p>I also used the <code class="verbatim">Make iTerm2 Default Term</code> and <code class="verbatim">Install Shell Integration</code> options in the iTerm2 application menu to make sure I don't run into any issues later on with different terminals.</p>
<p>We will also install <code class="verbatim">zsh</code> so we can use it in iTerm2.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">brew</span></span><span class="meta function-call arguments shell"> install zsh</span></span></code></pre>
<h2 id="oh-my-zsh"><span class="section-number-2">7.</span> Oh-My-Zsh</h2>
<p>I've shown the great aspects of <a href="https://ohmyz.sh">Oh My Zsh</a> in other blog posts, so I'll skip over that speech for now. Simply install it and run an update.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sh</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>c</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion command parens shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section parens begin shell">(</span><span class="meta function-call shell"><span class="variable function shell">curl</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>fsSL</span></span>
<span class="meta function-call shell"><span class="variable function shell">https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh</span></span><span class="punctuation section parens end shell">)</span></span><span class="punctuation definition string end shell">&quot;</span></span></span></span></code></pre>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">omz</span></span><span class="meta function-call arguments shell"> update</span></span></code></pre>
<p>Finally, restart the iTerm2 application to ensure all changes go into effect.</p>
<h2 id="oh-my-zsh-themes"><span class="section-number-2">8.</span> Oh-My-Zsh Themes</h2>
<p>Let's change the theme of the terminal to make it a little more friendly.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">open</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/.zshrc</span></span></code></pre>
<p>The third section of this file should contain a line like the code below. Change that theme to <a href="https://github.com/ohmyzsh/ohmyzsh/wiki/Themes">any theme you want</a>, save the file, and exit.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="variable other readwrite assignment shell">ZSH_THEME</span><span class="keyword operator assignment shell">=</span><span class="string unquoted shell"><span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>af-magic<span class="punctuation definition string end shell">&quot;</span></span></span></span></code></pre>
<p>After changing the <code class="verbatim">.zshrc</code> file, you'll need to close your terminal and re-open it to see the changes. Optionally, just open a new tab if you're using iTerm2, and you'll see the new shell config.</p>
<h2 id="oh-my-zsh-plugins"><span class="section-number-2">9.</span> Oh-My-Zsh Plugins</h2>
<p>Of course, my customization of <code class="verbatim">zsh</code> would not be complete without <a href="https://github.com/zsh-users/zsh-autosuggestions">zsh-autosuggestions</a>. This will bring up commands you've run in the past as you type them. For example, if you've run <code class="verbatim">ssh user@192.168.1.99</code> before, the terminal will show this command as soon as you start typing it (e.g. <code class="verbatim">zsh u</code>), and you can hit the right arrow to autocomplete the command.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">git</span></span><span class="meta function-call arguments shell"> clone https://github.com/zsh-users/zsh-autosuggestions</span>
<span class="meta function-call shell"><span class="variable function shell"><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section expansion parameter begin shell">{</span></span><span class="meta group expansion parameter shell"><span class="variable other readwrite shell">ZSH_CUSTOM</span></span><span class="meta group expansion parameter shell"><span class="keyword operator assignment shell">:-</span></span><span class="meta group expansion parameter shell"><span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/.oh-my-zsh/custom</span><span class="meta group expansion parameter shell"><span class="punctuation section expansion parameter end shell">}</span></span>/plugins/zsh-autosuggestions</span></span></span></code></pre>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">open</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/.zshrc</span></span></code></pre>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="comment line number-sign shell"><span class="punctuation definition comment begin shell">#</span></span><span class="comment line number-sign shell"> Scroll down the script and edit this line to add zsh-autosuggestions</span><span class="comment line number-sign shell">
</span><span class="variable other readwrite assignment shell">plugins</span><span class="keyword operator assignment shell">=</span><span class="punctuation section parens begin shell">(</span>git zsh-autosuggestions<span class="punctuation section parens end shell">)</span></span></code></pre>
<p>Remember: After changing the <code class="verbatim">.zshrc</code> file, you'll need to close your terminal and re-open it to see the changes. Optionally, just open a new tab if you're using iTerm2, and you'll see the new shell config.</p>
]]></description>
    </item>
    <item>
      <title>UFW: Firewall Setup on Ubuntu</title>
      <link>https://cleberg.net/blog/ufw.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/ufw.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Thu, 07 Jan 2021 00:00:00 +0000</pubDate>
      <category>linux</category>
      <category>security</category>
      <description><![CDATA[<h2 id="uncomplicated-firewall"><span class="section-number-2">1.</span> Uncomplicated Firewall</h2>
<p>Uncomplicated Firewall (UFW) is a convenient and beginner-friendly way to enforce operating system (OS)-level firewall rules. For those who are hosting servers or any device that is accessible to the world (i.e., by public IP or domain name), it's critical that a firewall is properly implemented and active.</p>
<p>UFW is available by default in all Ubuntu installations after 8.04 LTS (long-term support). For other distributions, you can look to install UFW or check if there are alternative firewalls installed already. There are usually alternatives available, such as Fedora's <code class="verbatim">firewall</code> and the package available on most distributions: <code class="verbatim">iptables</code>. UFW is considered a beginner-friendly front-end to iptables.</p>
<p><a href="https://gufw.org">Gufw</a> is available as a graphical user interface (GUI) application for users who are uncomfortable setting up a firewall through a terminal.</p>
<h2 id="getting-help"><span class="section-number-2">2.</span> Getting Help</h2>
<p>If you need help figuring out commands, remember that you can run the <code class="verbatim">--help</code> flag to get a list of options.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> ufw<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> --</span>help</span></span></span></code></pre>
<h2 id="set-default-state"><span class="section-number-2">3.</span> Set Default State</h2>
<p>The proper way to run a firewall is to set a strict default state and slowly open up ports that you want to allow. This helps prevent anything malicious from slipping through the cracks. The following command prevents all incoming traffic (other than the rules we specify later), but you can also set this for outgoing connections, if necessary.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> ufw default deny incoming</span></span></code></pre>
<p>You should also allow outgoing traffic if you want to allow the device to communicate back to you or other parties. For example, media servers like Plex need to be able to send out data related to streaming the media.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> ufw default allow outgoing</span></span></code></pre>
<h2 id="adding-port-rules"><span class="section-number-2">4.</span> Adding Port Rules</h2>
<p>Now that we've disabled all incoming traffic by default, we need to open up some ports (or else no traffic would be able to come in). If you need to be able to <code class="verbatim">ssh</code> into the machine, you'll need to open up port 22.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> ufw allow 22</span></span></code></pre>
<p>You can also issue more restrictive rules. The following rule will allow <code class="verbatim">ssh</code> (secure shell protocol) connections only from machines on the local subnet.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> ufw allow proto tcp from 192.168.0.0/24 to any port 22</span></span></code></pre>
<p>If you need to set a rule that isn't TCP (Transmission Control Protocol) just append your connection type to the end of the rule.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> ufw allow 1900/udp</span></span></code></pre>
<h2 id="enable-ufw"><span class="section-number-2">5.</span> Enable ufw</h2>
<p>Now that the firewall is configured and ready to go, you can enable the firewall.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> ufw enable</span></span></code></pre>
<p>A restart may be required for the firewall to begin operating.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> reboot now</span></span></code></pre>
<h2 id="checking-status"><span class="section-number-2">6.</span> Checking Status</h2>
<p>Now that the firewall is enabled, let's check and see what the rules look like.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> ufw status numbered</span></span></code></pre>
<pre><code class="language-txt highlight"><span class="text plain">Status: active

     To                    Action      From
     --                    ------      ----
[ 1] 22                    ALLOW IN    Anywhere
[ 2] 22 (v6)               ALLOW IN    Anywhere (v6)</span></code></pre>
<h2 id="deleting-rules"><span class="section-number-2">7.</span> Deleting Rules</h2>
<p>If you need to delete a rule, you need to know the number associated with that rule. Let's delete the first rule in the table above. You'll be asked to confirm the deletion as part of this process.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> ufw delete 1</span></span></code></pre>
<h2 id="managing-app-rules"><span class="section-number-2">8.</span> Managing App Rules</h2>
<p>Luckily, there's a convenient way for installed applications to create files that ufw can easily implement so that you don't have to search and find which ports your application requires. To see if your device has any applications with pre-installed UFW rules, execute the following command:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> ufw app list</span></span></code></pre>
<p>The results should look something like this:</p>
<pre><code class="language-txt highlight"><span class="text plain">Available applications:
    OpenSSH
    Samba
    plexmediaserver
    plexmediaserver-all
    plexmediaserver-dlna</span></code></pre>
<p>If you want to get more information on a specific app rule, use the <code class="verbatim">info</code> command.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> ufw app info plexmediaserver-dlna</span></span></code></pre>
<p>You'll get a blurb of info back like this:</p>
<pre><code class="language-txt highlight"><span class="text plain">Profile: plexmediaserver-dlna
Title: Plex Media Server (DLNA)
Description: The Plex Media Server (additional DLNA capability only)

Ports:
    1900/udp
    32469/tcp</span></code></pre>
<p>You can add or delete app rules the same way that you'd add or delete specific port rules.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> ufw allow plexmediaserver-dlna</span></span></code></pre>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> ufw delete RULE</span><span class="keyword operator logical pipe shell">|</span><span class="meta function-call shell"><span class="variable function shell">NUM</span></span></span></code></pre>
<h2 id="creating-app-rules"><span class="section-number-2">9.</span> Creating App Rules</h2>
<p>If you'd like to create you own app rule, you'll need to create a file in the <code class="verbatim">/etc/ufw/applications.d</code> directory. Within the file you create, you need to make sure the content is properly formatted.</p>
<p>For example, here are the contents my <code class="verbatim">plexmediaserver</code> file, which creates three distinct app rules for ufw:</p>
<pre><code class="language-config">[plexmediaserver]
title=Plex Media Server (Standard)
description=The Plex Media Server
ports=32400/tcp|3005/tcp|5353/udp|8324/tcp|32410:32414/udp

[plexmediaserver-dlna]
title=Plex Media Server (DLNA)
description=The Plex Media Server (additional DLNA capability only)
ports=1900/udp|32469/tcp

[plexmediaserver-all]
title=Plex Media Server (Standard + DLNA)
description=The Plex Media Server (with additional DLNA capability)
ports=32400/tcp|3005/tcp|5353/udp|8324/tcp|32410:32414/udp|1900/udp|32469/tcp</code></pre>
<p>So, if I wanted to create a custom app rule called "mycustomrule," I'd create a file and add my content like this:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> nano /etc/ufw/applications.d/mycustomrule</span></span></code></pre>
<pre><code class="language-config">[mycustomrule]
title=My Custom Rule
description=This is a temporary ufw app rule.
ports=88/tcp|9100/udp</code></pre>
<p>Then, I would just enable this rule in ufw.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> ufw allow mycustomrule</span></span></code></pre>
]]></description>
    </item>
    <item>
      <title>Fediverse: Decentralized Social</title>
      <link>https://cleberg.net/blog/fediverse.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/fediverse.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Mon, 04 Jan 2021 00:00:00 +0000</pubDate>
      <category>privacy</category>
      <description><![CDATA[<h2 id="what-is-the-fediverse"><span class="section-number-2">1.</span> What is the Fediverse?</h2>
<p>The fediverse is a federated universe of servers commonly used for sharing content, like social media. So, instead of having to rely on a single organization to run the server (e.g. Facebook), the fediverse is a giant collection of servers across the world, owned by many people and organizations.</p>
<p>Take a look at this depiction of a federated network. Each server in this photo is owned and run by different administrators/owners. Federated networks are best explained as email servers: you have an email account that exists on a server (e.g. Outlook), your friend has an account on a different server (e.g. GMail), and another friend has an account on a third server (e.g. ProtonMail). All three of you can talk and communicate back and forth without having to be on the same server. However, responsible email admins are there to set rules and control the traffic going in/out of the server.</p>
<p>The main objective of this architecture is to decentralize the control within the internet connections. For example, if you run your own Mastodon instance, you and your users can't be censored or impacted in any way by authorities of another Mastodon instance. Some users have praised these features due to recent criticism of popular social media websites that may be over-censoring their users.</p>
<p>This strategy is great for making sure control of the social web isn't controlled by a single organization, but it also has some downsides. If I create a Mastodon instance and get a ton of users to sign up, I can shut the server down at any time. That means you're at risk of losing the content you've created unless you back it up, or the server backs it up for you. Also, depending on the software used (e.g. Mastodon, Pixelfed, etc.), censorship may still be an issue if the server admins decide they want to censor their users. Now, censorship isn't always a bad thing and can even benefit the community as a whole, but you'll want to determine which servers align with your idea of proper censorship.</p>
<p>However, these are risks that we take when we sign up for any online platform. Whatever your reason is for trying out federated social networks, they are part of the future of the internet. However, the popularity of these services is still yet to be determined, especially with the increased difficulty understanding and signing up for these platforms. Perhaps increased regulation and litigation against current social media sites will push more users into the fediverse.</p>
<h2 id="federated-alternatives-to-popular-sites"><span class="section-number-2">2.</span> Federated Alternatives to Popular Sites</h2>
<p>The list below is a small guide that will show you federated alternatives to current popular websites. There are many more out there, so go and explore: you might just find the perfect home.</p>
<h3 id="reddit"><span class="section-number-3">2.1.</span> Reddit</h3>
<ul>
<li><a href="https://lemmy.ml/instances">Lemmy</a></li>
</ul>
<h3 id="twitter-facebook-tumblr"><span class="section-number-3">2.2.</span> Twitter/Facebook/Tumblr</h3>
<ul>
<li><a href="https://joinmastodon.org">Mastodon</a></li>
<li><a href="https://diasporafoundation.org">Diaspora</a></li>
<li><a href="https://friendi.ca">Friendica</a></li>
<li><a href="https://gnusocial.network">GNU Social</a></li>
<li><a href="https://pleroma.social">Pleroma</a></li>
</ul>
<h3 id="instagram"><span class="section-number-3">2.3.</span> Instagram</h3>
<ul>
<li><a href="https://pixelfed.org">Pixelfed</a></li>
</ul>
<h3 id="slack-discord"><span class="section-number-3">2.4.</span> Slack/Discord</h3>
<ul>
<li><a href="https://element.io">Matrix</a></li>
</ul>
<h3 id="youtube-vimeo"><span class="section-number-3">2.5.</span> Youtube/Vimeo</h3>
<ul>
<li><a href="https://joinpeertube.org">Peertube</a></li>
</ul>
<h3 id="spotify-soundcloud"><span class="section-number-3">2.6.</span> Spotify/Soundcloud</h3>
<ul>
<li><a href="https://funkwhale.audio">Funkwhale</a></li>
</ul>
<h3 id="podcasting"><span class="section-number-3">2.7.</span> Podcasting</h3>
<ul>
<li><a href="https://pubcast.pub">Pubcast</a></li>
</ul>
<h3 id="medium-blogger"><span class="section-number-3">2.8.</span> Medium/Blogger</h3>
<ul>
<li><a href="https://writefreely.org">WriteFreely</a></li>
</ul>
<h2 id="get-started"><span class="section-number-2">3.</span> Get Started</h2>
<p>The best way to get started is to simply sign up and learn as you go. If you're comfortable signing up through a Mastodon, Pleroma, or Friendica server, here is <a href="https://fediverse.party/en/portal/servers">a list of themed servers</a> to choose from. If you're looking for something else, try a web search for a federated alternative to your favorite sites.</p>
<p>Find a server that focuses on your passions and start there!</p>
]]></description>
    </item>
    <item>
      <title>SEUM: Speedrunners from Hell</title>
      <link>https://cleberg.net/blog/seum.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/seum.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Fri, 01 Jan 2021 00:00:00 +0000</pubDate>
      <category>personal</category>
      <description><![CDATA[<h2 id="game-description"><span class="section-number-2">1.</span> Game Description</h2>
<p><a href="https://store.steampowered.com/app/457210/SEUM_Speedrunners_from_Hell/">SEUM: Speedrunners from Hell</a> is an incredibly fast-paced mashup of a puzzle game and a free-running game. Created by <a href="https://pinestudio.co">Pine Studio</a> in early 2016 and first released as a <a href="https://gamejolt.com/games/seum-speedrunners-from-hell-demo/154868">demo on GameJolt</a>, this game was successfully green-lit on Steam and has amassed a cult following on multiple consoles.</p>
<p>Here's the game description straight from the developers:</p>
<blockquote>
<p>Like a bastard child of Quake 3 and Super Meat Boy, SEUM: Speedrunners from Hell is truly hardcore and focuses on speed and fast reaction.</p>
</blockquote>
<h2 id="story"><span class="section-number-2">2.</span> Story</h2>
<p>SEUM does a great job setting the stage when you open the game for the first time, playing an animated video in the form of comic book images. You see Marty, the protagonist, sitting around drinking his beer as Satan busts down the door, cuts his hand off, and steals all his beer and bacon. As Satan is leaving, Marty whips a vinyl record across the room and cuts off one of Satan's hands. This hand is what allows you to use all the powers in the game.</p>
<h2 id="gameplay"><span class="section-number-2">3.</span> Gameplay</h2>
<p>To accomplish each level, you will need to get to the final blue portal under a certain time limit. You can beat a level by getting to the portal before the time meter runs out or "Dominate" a level by beating it within a shorter time limit (noted by a bright red/orange color in the time meter).</p>
<p>The portal is usually set behind locked gates, protected by dangerous defenses, or in hard-to-reach places. To reach the portal, you'll need to go through any existing orange portals, light all yellow beacons, avoid things like fireballs and blades, or use any satanic power orbs lying around. These special abilities include:</p>
<ul>
<li>Gravity</li>
<li>Teleport</li>
<li>Rewind</li>
<li>Spawn platform</li>
<li>Roar (DLC)</li>
<li>Rocket (DLC)</li>
<li>Shadow world (DLC)</li>
</ul>
<p>For the main storyline, there are nine floors to beat. Each floor contains nine regular levels, one boss level, and one bonus level; although you don't technically need to beat all levels to advance to the next floor. # In-Game Screenshots</p>
<p>The main menu gives you plenty of options for tuning your system, playing main levels, playing the downloadable content (DLC), or exploring the other game modes.</p>
<p>Once you enter a level, you can look around and strategize before starting. Clicking any button will start the menu, and you'll have to restart if you die. One of the great things about SEUM is that it has great keyboard shortcuts. You can quickly smash <code class="verbatim">R</code> to restart the level or <code class="verbatim">M</code> to return to the level menu.</p>
<p>Once you're able to win a level, you'll see the high scores and can watch replays of the best scores.</p>
<p>Each regular level also contains a beer in a disguised location that may take some out-of-the-box thinking.</p>
]]></description>
    </item>
    <item>
      <title>The Zork Anthology</title>
      <link>https://cleberg.net/blog/zork.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/zork.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Tue, 29 Dec 2020 00:00:00 +0000</pubDate>
      <category>personal</category>
      <description><![CDATA[<h2 id="download-free"><span class="section-number-2">1.</span> Download (Free)</h2>
<p>Before we get into the game itself, you should know that you can download Zork for free from Infocom's <a href="http://infocom-if.org/downloads/downloads.html">download page</a>. So feel free to boot it up and take a ride back to the 1980s with this masterpiece.</p>
<h2 id="game-description"><span class="section-number-2">2.</span> Game Description</h2>
<p>Zork is an interactive, text-based computer game originally released in 1980. This series, split into three separate games, introduced a robust and sophisticated text parser to gamers. People were largely used to the simple commands used in the popular game <a href="https://en.wikipedia.org/wiki/Colossal_Cave_Adventure">Colossal Cave Adventure</a>, but Zork allowed users to send more complex commands that included prepositions and conjunctions.</p>
<p>Zork tracks your score as you explore the map, find tools, and collect trophy items (e.g., a jewel-encrusted egg). When you place your trophy items in the trophy case found in the Living Room area, you gain score points. Collecting the Twenty Treasures of Zork and placing them within the trophy case wins the game. However, you must explore the map, solve puzzles, and avoid being eaten by a grue to collect these treasures.</p>
<h2 id="the-map"><span class="section-number-2">3.</span> The Map</h2>
<p>Since Zork is a vast and complex game, it helps to have a map as you explore and collect your trophies. However, if you want to play the game as it was truly intended, you should try to play it without using the map.</p>
<figure><img src="https://img.cleberg.net/blog/20201229-zork/zork_map.jpg" alt="A map for Zork, showing passageways, restrictions, and all locations."><figcaption><span class="figure-number">Figure 1: </span>Zork Map</figcaption></figure>
<p><em><a href="https://www.filfre.net/2012/01/exploring-zork-part-1/">Map Source</a></em></p>
<h2 id="in-game-screenshots"><span class="section-number-2">4.</span> In-Game Screenshots</h2>
<p>After playing the game (for the first time ever) for several weeks around 2014, I was finally able to beat the game with some online help to find the last couple items. As I was writing this post, I installed the game again to grab some screenshots to show off the true glory of this game. As noted in <a href="https://www.filfre.net/2012/01/exploring-zork-part-1/">Jimmy Maher's Playthrough</a>, the original Zork games looked quite a bit different due to the older hardware of computers like the Apple II and multiple bug fixes that Infocom pushed out after the game's initial release. My play-through uses the <a href="https://store.steampowered.com/app/570580/Zork_Anthology/">Zork Anthology</a> version, which utilizes DOSBox on Windows.</p>
<p>The first screenshot here shows the introductory information, which doesn't include instructions of any kind for the player. If you haven't played text adventures before, try to use simple commands like "go west," "look around," or "hit troll with elvish sword."</p>
<p>In this second screenshot, we see the player has entered the house and found the trophy case in the living room. The lantern and sword in this room allow the player to explore dark areas and attack enemies. If you don't use the lantern, you won't be able to see anything in dark areas, and you may be eaten by a grue.</p>
<p>Finally, we see that the player has found the first treasure: a jewel-encrusted egg. These treasures can be taken back to the house and placed in the trophy case or carried until you feel like you want to put things away.</p>
<h2 id="conclusion"><span class="section-number-2">5.</span> Conclusion</h2>
<p>It's been quite a few years since I first played Zork, but I clearly remember the late nights and bloodshot eyes that helped me find all the treasures. This game is well worth the time and effort, even though the text-based aspect may be off-putting to gamers who didn't have to grow up playing games without graphics. However, I believe that the strategy and skills learned in early video games like Zork can actually help you, even when playing newer games.</p>
<p>If you do decide to play Zork, you can download Zork I, II, and III from Infocom's <a href="http://infocom-if.org/downloads/downloads.html">download page</a> for free or search the internet for an online version.</p>
]]></description>
    </item>
    <item>
      <title>Neon Drive</title>
      <link>https://cleberg.net/blog/neon-drive.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/neon-drive.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Mon, 28 Dec 2020 00:00:00 +0000</pubDate>
      <category>personal</category>
      <description><![CDATA[<h2 id="game-description"><span class="section-number-2">1.</span> Game Description</h2>
<p><a href="https://store.steampowered.com/app/433910/Neon_Drive/">Neon Drive</a> presents itself as a simple arcade-style game inspired by the arcade race games of the 1980s, yet it has managed to take up hours of my life without much effort. The game description, directly from the Steam page, is intriguing enough to entice anyone who's been looking for a good arcade racing game:</p>
<blockquote>
<p>Neon Drive is a slick retro-futuristic arcade game that will make your brain melt. You've been warned. From beautiful cityscapes and ocean roads to exploding enemy spaceships, Neon Drive has it all.</p>
</blockquote>
<h2 id="gameplay"><span class="section-number-2">2.</span> Gameplay</h2>
<p>The game holds true to the <a href="https://en.wikipedia.org/wiki/Retrofuturism">retro-futurism</a> style, including chrome female robots, pixelated arcade machines, and <a href="https://teddit.net/r/outrun/">outrun</a> aesthetics.</p>
<p>Each level of the game is shown as a separate arcade machine. Each arcade machine lets you play on Normal, Hard, Insane, Practice, and Free Run. To beat each arcade, you must reach the end of the level without crashing your car into the various obstacles on the course. Basic levels let you move left or right to avoid blocks in the road. Later levels put you through other tests, such as dodging traffic or blasting asteroids.</p>
<p>The game uses synthwave music to keep you on track to make the correct moves by timing the beats of the songs to the correct moves on the screen. It reminds me of the early Guitar Hero games, as well as mobile apps like VOEZ - repetition and staying on-beat is the only way to win.</p>
<h2 id="in-game-screenshots"><span class="section-number-2">3.</span> In-Game Screenshots</h2>
<p>Taking a look at the main menu, you can see that Neon Drive plays into every stereotype you can think of around retro-futuristic, synthwave arcades (in a good way).</p>
<p>Once you get into the first level, we see that the choice of car fits right in with the stereotypical cars of the 80s, like the <a href="https://en.wikipedia.org/wiki/DMC_DeLorean">DeLorean</a> or the <a href="https://en.wikipedia.org/wiki/Ferrari_F40">Ferrari F40</a>. Each new level comes with new color schemes and cars, so you should never get tired of the aesthetic.</p>
<p>Personally, I love the orange and blue colors used in level 2:</p>
<p>If you're the competitive type and getting 100% on all arcade machines isn't enough, there are leaderboards for the regular part of the game, and the endurance game mode.</p>
<h2 id="other-suggestions"><span class="section-number-2">4.</span> Other Suggestions</h2>
<p>Neon Drive sits nicely within the well-founded cult genre of Outrun. Other games that I've enjoyed in this same spectrum are:</p>
<ul>
<li><a href="https://store.steampowered.com/app/233270/Far_Cry_3__Blood_Dragon/">Far Cry 3: Blood Dragon</a></li>
<li><a href="https://store.steampowered.com/app/1239690/Retrowave/">Retrowave</a></li>
<li><a href="https://store.steampowered.com/app/732810/Slipstream/">Slipstream</a></li>
</ul>
<p>Although these games aren't necessarily in the same genre, they do have aspects that place them close enough to interest gamers that enjoyed Neon Drive:</p>
<ul>
<li><a href="https://store.steampowered.com/app/311800/Black_Ice/">Black Ice</a></li>
<li><a href="https://store.steampowered.com/app/746850/Cloudpunk/">Cloudpunk</a></li>
<li><a href="https://store.steampowered.com/app/1222680/Need_for_Speed_Heat/">Need for Speed: Heat</a></li>
<li><a href="https://store.steampowered.com/app/1019310/VirtuaVerse/">VirtuaVerse</a></li>
</ul>
<p>Of course, if all you really care about is the arcade aspect of these games, you can check out the <a href="https://store.steampowered.com/app/400020/Atari_Vault/">Atari Vault</a> or any of the other classic games sold on Steam by companies like Namco, Atari. For something like Nintendo, you'd have to settle for buying used classic consoles or delve into the world of emulation.</p>
]]></description>
    </item>
    <item>
      <title>Minimalist Website Redesign (5kb)</title>
      <link>https://cleberg.net/blog/website-redesign.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/website-redesign.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Sun, 27 Dec 2020 00:00:00 +0000</pubDate>
      <category>web</category>
      <description><![CDATA[<h2 id="a-brief-history"><span class="section-number-2">1.</span> A Brief History</h2>
<p>As a form of continuous learning and entertainment, I've been running a handful of websites since 2016 when I took my first programming courses in college. I maintain one main website, the place I consider the official website to represent me. Under this site, I have a handful of subdirectories and subdomains.</p>
<p>One of the parts I've enjoyed the most about web development is the aspect of designing an identity for a web page and working to find exciting ways to display the site's content. Inevitably, this means I've changed the designs for my websites more times than I could possibly count. Since I don't really host anything on my main webpage that's vital, it allows me the freedom to change things as inspiration strikes.</p>
<p>Historically, I've relied on core utilities for spacing, components, and layouts from <a href="https://getbootstrap.com">Bootstrap</a> and added custom cascading style sheets (CSS) for fonts, accents, colors, and other items. I also tend to create sites with no border radius on items, visible borders, and content that takes up the entire screen (using whitespace inside components instead of whitespace around my components).</p>
<h2 id="the-redesign-process"><span class="section-number-2">2.</span> The Redesign Process</h2>
<p>About a week ago, I found myself wishing for a new design yet again. The prior design was largely inspired by IBM's <a href="https://www.carbondesignsystem.com">Carbon Design System</a> and relied on jQuery, Bootstrap, along with some compressed <a href="https://en.wikipedia.org/wiki/WebP">.webp</a> images.</p>
<p>To anyone who knows my preferences toward web design - and even in my personal life - it should be no surprise that I immediately started looking for inspiration on minimalism. While there are some decent minimalistic designs on sites like <a href="https://dribbble.com/search/shots/popular/web-design?q=minimalism">Dribbble</a>, people seem to mostly discuss <a href="https://brutalist-web.design">brutalist web design</a> when you ask about minimalism. While brutalist web design doesn't have to be minimal, it often is.</p>
<p>I suppose, in a way, I did create a brutalist website since my HTML is semantic and accessible, hyperlinks are colored and underlined, and all native browser functions like scrolling and the back button work as expected. However, I didn't think about brutalism while designing these sites.</p>
<p>The new design followed a simple design process. I walked through the screens on my blog and asked myself: "Is this element necessary for a user?" This allowed me to first start by removing all javascript, which had the sole purpose of allowing users to open a collapsed navbar on mobile. Replacing the collapsible navbar allowed me to remove both jQuery and Bootstrap's javascript.</p>
<p>Next, I removed things like author names (since I'm literally the only person who will ever write on this site), multiple ways to click on a blog post card, blog post descriptions, and the scroll-to-top button. It also helped to move all categories to a single page, rather than have each category on its own page.</p>
<p>The final big piece to finish the "<a href="https://en.wikipedia.org/wiki/Marie_Kondo#KonMari_method">KonMari</a>"-like part of my process was to remove Bootstrap CSS in its entirety. However, this meant pulling out a few very useful classes, such as <code class="verbatim">.img-fluid</code> and the default font stacks to keep in my custom CSS.</p>
<p>After removing all the unnecessary pieces, I was finally able to reorganize my content and add a very small amount of custom CSS to make everything pretty. This took a brief amount of time, effectively just consisting of me converting <code class="verbatim">&lt;div&gt;</code> tags into things like <code class="verbatim">&lt;ul&gt;</code> lists and choosing accent colors.</p>
<h2 id="the-results"><span class="section-number-2">3.</span> The Results</h2>
<h3 id="reflection"><span class="section-number-3">3.1.</span> Reflection</h3>
<p>So, what did all of this reorganizing do to my webpages? Well, first, my websites are now <strong>ridiculously fast</strong>. Since the prior designs were also minimal and didn't have many images, they measured up in Firefox's Network Monitor around 300 KB - 600KB. After making the changes, my main site is at 5 KB transferred (22 KB total), and my blog is at 6.5 KB transferred (13 KB total). <strong>That means the redesigned pages are less than 2% the size of the old designs.</strong></p>
<p>Google Lighthouse ranks the new webpage as 100 in performance, accessibility, and best practices, with search engine optimization (SEO) at 92 since they think tap targets are not sized appropriately for mobile users. First contextual paints of the pages are under 0.8 seconds with 0 ms (millisecond) of blocking time. However, the blog subdomain ranks at 100 for all four categories! First contextual paints of the blog homepage are under 1.0 seconds with 0 ms of blocking time, due to the fact that the CSS for my blog is within a separate CSS file, and the CSS for my main website is simply embedded in the HTML file.</p>
<p>Now that everything is complete, I can confidently say I'm happy with the result and proud to look at the fastest set of websites I've created so far.</p>
]]></description>
    </item>
    <item>
      <title>On Mediocrity</title>
      <link>https://cleberg.net/blog/mediocrity.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/mediocrity.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Mon, 12 Oct 2020 00:00:00 +0000</pubDate>
      <category>personal</category>
      <description><![CDATA[<h2 id="perfect-is-the-enemy-of-good"><span class="section-number-2">1.</span> Perfect is the Enemy of Good</h2>
<p>As the saying goes, "the best is the enemy of the good." As we strive for perfection, we often fail to realize the implications of such an undertaking. Attempting to reach perfection is often unrealistic. Even worse, it can get in the way of achieving a good outcome. In certain situations, we try so hard to achieve the ideal solution that we have burned the bridges that would have allowed us to reach a lesser yet still superb solution.</p>
<p>Philosophers throughout history have inspected this plight from many viewpoints. Greek mythology speaks of the <a href="https://en.wikipedia.org/wiki/Golden_mean_(philosophy)">golden mean</a>, which uses the story of Icarus to illustrate that sometimes "the middle course" is the best solution. In this story, Daedalus, a famous artist of his time, built feathered wings for himself and his son so that they might escape the clutches of King Minos. Daedalus warns his beloved son whom he loved so much to "fly the middle course", between the sea spray and the sun's heat. Icarus did not heed his father; he flew up and up until the sun melted the wax off his wings. For not heeding the middle course, he fell into the sea and drowned.</p>
<p>More recently, management scholars have explored the <a href="https://en.wikipedia.org/wiki/Pareto_principle">Pareto principle</a> and found that as we increase the frequency of something, or strive to perform actions to achieve some form of perfection, we run into <a href="https://en.wikipedia.org/wiki/Diminishing_returns">diminishing returns</a>.</p>
<p>Even further, Harold Demsetz is noted as coining the term <a href="https://en.wikipedia.org/wiki/Nirvana_fallacy">the Nirvana fallacy</a> in 1969, which shows the fallacy of comparing actual things with unrealistic, idealized alternatives. This is another trap that we may fall into, where we are constantly thinking of the ultimate solutions to problems, when something more realistic needs to be considered.</p>
<p>Over and over throughout history, we've found that perfection is often unrealistic and unachievable. However, we push ourselves and our peers to "give 100%" or "go the extra mile," while it may be that the better course is to give a valuable level of effort while considering the effects of further effort on the outcome. Working harder does not always help us achieve loftier goals.</p>
<p>This has presented itself to me most recently during my time studying at my university. I was anxious and feeling the stresses of my courses, career, and personal life for quite a while, which was greatly affecting how well I was doing at school and my level of effort at work. One day, I happened to be talking to my father when he said something simple that hit home:</p>
<blockquote>
<p>All you can do is show up and do your best. Worrying about the outcomes won't affect the outcome itself.</p>
</blockquote>
<p>The thought was extremely straightforward and uncomplicated, yet it was something that I had lost sight of during my stress-filled years at school. Ever since then, I've found myself pausing and remembering that quote every time I get anxious or stressed. It helps to stop and think "Can I do anything to affect the outcome, or am I simply worrying over something I can't change?"</p>
<h2 id="when-mediocrity-isn-t-enough"><span class="section-number-2">2.</span> When Mediocrity Isn't Enough</h2>
<p>One problem with the philosophies presented in this post is that they are implemented far too often in situations where mediocrity simply isn't adequate. For example, let's take a look at digital user data, specifically personally-identifiable information (PII). As a cybersecurity auditor in the United States, I have found that most companies are concerned more with compliance than any actual safeguards over the privacy or protection of user data. Other than companies who have built their reputation on privacy and security, most companies will use <a href="https://en.wikipedia.org/wiki/Satisficing">satisficing</a> as their primary decision-making strategy around user data.</p>
<blockquote>
<p>Satisficing is a decision-making strategy or cognitive heuristic that entails searching through the available alternatives until an acceptability threshold is met.</p>
</blockquote>
<p>This means that each decision will be met with certain possible solutions until one of the solutions meets their minimum acceptable standards. For companies that deal with user data, the minimum-acceptable standards come from three areas:</p>
<ol>
<li>Laws and regulations</li>
<li>Competitive pressure</li>
<li>Risk of monetary or reputation loss</li>
</ol>
<p>Working with project management or auditing, the primary concern here is the risk of legal ramifications. Since the primary risk comes from laws and regulations, companies will require that any project that involves user data must follow all the rules of those laws so that the company can protect itself from fines or other penalties.</p>
<p>Following this, companies will consider best practices in order to place itself in a competitive position (e.g. Google vs. Apple) and review any recent or ongoing litigation against companies regarding user data. In a perfect company, management would then consider the ethical responsibilities of their organization and discuss their responsibilities over things like personally-identifiable information.</p>
<p>However, as we mentioned above, most companies follow the idea of satisficing, which states that they have met the minimum acceptable standards and can now move on to other decisions. Modern business culture in the United States dictates that profits are the golden measure of how well a company or manager is performing, so we often don't think about our responsibilities beyond these basic standards.</p>
<p>Not all situations demand excellence, but I believe that applying any philosophy as a broad stroke across one's life can be a mistake. We must be able to think critically about what we are doing as we do it and ask ourselves a few questions. Have I done everything I can in this situation? Is mediocrity an acceptable outcome, or should we strive for perfection, even if we can't attain it?</p>
<p>Taking a few moments to think critically throughout our day, as we make decisions, can have a tremendous effect on the outcomes we create.</p>
]]></description>
    </item>
    <item>
      <title>Data Analysis: World Happiness Choropleth Map</title>
      <link>https://cleberg.net/blog/happiness-map.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/happiness-map.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Fri, 25 Sep 2020 00:00:00 +0000</pubDate>
      <category>personal</category>
      <description><![CDATA[<h2 id="background-information"><span class="section-number-2">1.</span> Background Information</h2>
<p>The dataset (obtained from <a href="https://www.kaggle.com/unsdsn/world-happiness">Kaggle</a>) used in this article contains a list of countries around the world, their happiness rankings and scores, as well as other national scoring measures.</p>
<p>Fields include:</p>
<ul>
<li>Overall rank</li>
<li>Country or region</li>
<li>GDP per capita</li>
<li>Social support</li>
<li>Healthy life expectancy</li>
<li>Freedom to make life choices</li>
<li>Generosity</li>
<li>Perceptions of corruption</li>
</ul>
<p>There are 156 records. Since there are ~195 countries in the world, we can see that around 40 countries will be missing from this dataset.</p>
<h2 id="install-packages"><span class="section-number-2">2.</span> Install Packages</h2>
<p>As always, run the <code class="verbatim">install</code> command for all packages needed to perform analysis.</p>
<pre><code class="language-python highlight"><span class="source python">!<span class="meta qualified-name python"><span class="meta generic-name python">pip</span></span> <span class="meta qualified-name python"><span class="meta generic-name python">install</span></span> <span class="meta qualified-name python"><span class="meta generic-name python">folium</span></span> <span class="meta qualified-name python"><span class="meta generic-name python">geopandas</span></span> <span class="meta qualified-name python"><span class="meta generic-name python">matplotlib</span></span> <span class="meta qualified-name python"><span class="meta generic-name python">numpy</span></span> <span class="meta qualified-name python"><span class="meta generic-name python">pandas</span></span></span></code></pre>
<h2 id="import-the-data"><span class="section-number-2">3.</span> Import the Data</h2>
<p>We only need a couple packages to create a choropleth map. We will use <a href="https://python-visualization.github.io/folium/">Folium</a>, which provides map visualizations in Python. We will also use geopandas and pandas to wrangle our data before we put it on a map.</p>
<pre><code class="language-python highlight"><span class="source python"><span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Import the necessary Python packages
</span><span class="meta statement import python"><span class="keyword control import python">import</span> <span class="meta qualified-name python"><span class="meta generic-name python">folium</span></span></span>
<span class="meta statement import python"><span class="keyword control import python">import</span> <span class="meta qualified-name python"><span class="meta generic-name python">geopandas</span></span> <span class="keyword control import as python">as</span> <span class="meta qualified-name python"><span class="meta generic-name python">gpd</span></span></span>
<span class="meta statement import python"><span class="keyword control import python">import</span> <span class="meta qualified-name python"><span class="meta generic-name python">pandas</span></span> <span class="keyword control import as python">as</span> <span class="meta qualified-name python"><span class="meta generic-name python">pd</span></span></span></span></code></pre>
<p>To get anything to show up on a map, we need a file that will specify the boundaries of each country. Luckily, GeoJSON files exist (for free!) on the internet. To get the boundaries of every country in the world, we will use the GeoJSON link shown below.</p>
<p>GeoPandas will take this data and load it into a dataframe so that we can easily match it to the data we're trying to analyze. Let's look at the GeoJSON dataframe:</p>
<pre><code class="language-python highlight"><span class="source python"><span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Load the GeoJSON data with geopandas
</span><span class="meta qualified-name python"><span class="meta generic-name python">geo_data</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">gpd</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">read_file</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">https://raw.githubusercontent.com/datasets/geo-countries/master/data/countries.geojson<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="punctuation section arguments end python">)</span></span>
<span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">geo_data</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">head</span></span><span class="punctuation section arguments begin python">(</span><span class="punctuation section arguments end python">)</span></span></span></code></pre>
<p>Next, let's load the data from the Kaggle dataset. I've downloaded this file, so update the file path if you have it somewhere else. After loading, let's take a look at this dataframe:</p>
<pre><code class="language-python highlight"><span class="source python"><span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Load the world happiness data with pandas
</span><span class="meta qualified-name python"><span class="meta generic-name python">happy_data</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">pd</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">read_csv</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="storage type string python">r</span><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python"><span class="source regexp python">~/Downloads/world_happiness_data_2019<span class="constant character character-class regexp">.</span>csv</span><span class="punctuation definition string end python">&#39;</span></span></span></span><span class="punctuation section arguments end python">)</span></span>
<span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">happy_data</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">head</span></span><span class="punctuation section arguments begin python">(</span><span class="punctuation section arguments end python">)</span></span></span></code></pre>
<h2 id="clean-the-data"><span class="section-number-2">4.</span> Clean the Data</h2>
<p>Some countries need to be renamed, or they will be lost when you merge the happiness and GeoJSON dataframes. This is something I discovered when the map below showed empty countries. I searched both data frames for the missing countries to see the naming differences. Any countries that do not have records in the <code class="verbatim">happy_data</code> data frame will not show up on the map.</p>
<pre><code class="language-python highlight"><span class="source python"><span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Rename some countries to match our GeoJSON data
</span>
<span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Rename USA
</span><span class="meta qualified-name python"><span class="meta generic-name python">usa_index</span></span> <span class="keyword operator assignment python">=</span> <span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">happy_data</span><span class="punctuation accessor dot python">.</span><span class="meta generic-name python">index</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">happy_data</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">Country or region<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span> <span class="keyword operator comparison python">==</span> <span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">United States<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span>
<span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">happy_data</span><span class="punctuation accessor dot python">.</span><span class="meta generic-name python">at</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">usa_index</span></span>, <span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">Country or region<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span> <span class="keyword operator assignment python">=</span> <span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">United States of America<span class="punctuation definition string end python">&#39;</span></span></span>

<span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Rename Tanzania
</span><span class="meta qualified-name python"><span class="meta generic-name python">tanzania_index</span></span> <span class="keyword operator assignment python">=</span> <span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">happy_data</span><span class="punctuation accessor dot python">.</span><span class="meta generic-name python">index</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">happy_data</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">Country or region<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span> <span class="keyword operator comparison python">==</span> <span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">Tanzania<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span>
<span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">happy_data</span><span class="punctuation accessor dot python">.</span><span class="meta generic-name python">at</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">tanzania_index</span></span>, <span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">Country or region<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span> <span class="keyword operator assignment python">=</span> <span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">United Republic of Tanzania<span class="punctuation definition string end python">&#39;</span></span></span>

<span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Rename the Congo
</span><span class="meta qualified-name python"><span class="meta generic-name python">republic_congo_index</span></span> <span class="keyword operator assignment python">=</span> <span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">happy_data</span><span class="punctuation accessor dot python">.</span><span class="meta generic-name python">index</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">happy_data</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">Country or region<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span> <span class="keyword operator comparison python">==</span> <span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">Congo (Brazzaville)<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span>
<span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">happy_data</span><span class="punctuation accessor dot python">.</span><span class="meta generic-name python">at</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">republic_congo_index</span></span>, <span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">Country or region<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span> <span class="keyword operator assignment python">=</span> <span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">Republic of Congo<span class="punctuation definition string end python">&#39;</span></span></span>

<span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Rename the DRC
</span><span class="meta qualified-name python"><span class="meta generic-name python">democratic_congo_index</span></span> <span class="keyword operator assignment python">=</span> <span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">happy_data</span><span class="punctuation accessor dot python">.</span><span class="meta generic-name python">index</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">happy_data</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">Country or region<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span> <span class="keyword operator comparison python">==</span> <span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">Congo (Kinshasa)<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span>
<span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">happy_data</span><span class="punctuation accessor dot python">.</span><span class="meta generic-name python">at</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">democratic_congo_index</span></span>, <span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">Country or region<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span> <span class="keyword operator assignment python">=</span> <span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">Democratic Republic of the Congo<span class="punctuation definition string end python">&#39;</span></span></span></span></code></pre>
<h2 id="merge-the-data"><span class="section-number-2">5.</span> Merge the Data</h2>
<p>Now that we have clean data, we need to merge the GeoJSON data with the happiness data. Since we've stored them both in dataframes, we just need to call the <code class="verbatim">.merge()</code> function.</p>
<p>We will also rename a couple columns, just so that they're a little easier to use when we create the map.</p>
<pre><code class="language-python highlight"><span class="source python"><span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Merge the two previous dataframes into a single geopandas dataframe
</span><span class="meta qualified-name python"><span class="meta generic-name python">merged_df</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">geo_data</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">merge</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">happy_data</span></span><span class="punctuation separator arguments python">,</span><span class="variable parameter python">left_on</span><span class="keyword operator assignment python">=</span><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">ADMIN<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation separator arguments python">,</span> <span class="variable parameter python">right_on</span><span class="keyword operator assignment python">=</span><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">Country or region<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="punctuation section arguments end python">)</span></span>

<span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Rename columns for ease of use
</span><span class="meta qualified-name python"><span class="meta generic-name python">merged_df</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">merged_df</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">rename</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="variable parameter python">columns</span> <span class="keyword operator assignment python">=</span> <span class="meta structure dictionary-or-set python"><span class="punctuation section dictionary-or-set begin python">{</span><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">ADMIN<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation separator key-value python">:</span><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">GeoJSON_Country<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation section dictionary-or-set end python">}</span></span></span><span class="punctuation section arguments end python">)</span></span>
<span class="meta qualified-name python"><span class="meta generic-name python">merged_df</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">merged_df</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">rename</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="variable parameter python">columns</span> <span class="keyword operator assignment python">=</span> <span class="meta structure dictionary-or-set python"><span class="punctuation section dictionary-or-set begin python">{</span><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">Country or region<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation separator key-value python">:</span><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">Country<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation section dictionary-or-set end python">}</span></span></span><span class="punctuation section arguments end python">)</span></span></span></code></pre>
<h2 id="create-the-map"><span class="section-number-2">6.</span> Create the Map</h2>
<p>The data is finally ready to be added to a map. The code below shows the simplest way to find the center of the map and create a Folium map object. The important part is to remember to reference the merged dataframe for our GeoJSON data and value data. The columns specify which geo data and value data to use.</p>
<pre><code class="language-python highlight"><span class="source python"><span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Assign centroids to map
</span><span class="meta qualified-name python"><span class="meta generic-name python">x_map</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">merged_df</span><span class="punctuation accessor dot python">.</span><span class="meta generic-name python">centroid</span><span class="punctuation accessor dot python">.</span><span class="meta generic-name python">x</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">mean</span></span><span class="punctuation section arguments begin python">(</span><span class="punctuation section arguments end python">)</span></span>
<span class="meta qualified-name python"><span class="meta generic-name python">y_map</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">merged_df</span><span class="punctuation accessor dot python">.</span><span class="meta generic-name python">centroid</span><span class="punctuation accessor dot python">.</span><span class="meta generic-name python">y</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">mean</span></span><span class="punctuation section arguments begin python">(</span><span class="punctuation section arguments end python">)</span></span>
<span class="meta function-call python"><span class="meta qualified-name python"><span class="support function builtin python">print</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">x_map</span></span><span class="punctuation separator arguments python">,</span><span class="meta qualified-name python"><span class="meta generic-name python">y_map</span></span></span><span class="punctuation section arguments end python">)</span></span>

<span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Creating a map object
</span><span class="meta qualified-name python"><span class="meta generic-name python">world_map</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">folium</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">Map</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="variable parameter python">location</span><span class="keyword operator assignment python">=</span><span class="meta structure list python"><span class="punctuation section list begin python">[</span><span class="meta qualified-name python"><span class="meta generic-name python">y_map</span></span><span class="punctuation separator list python">,</span> <span class="meta qualified-name python"><span class="meta generic-name python">x_map</span></span><span class="punctuation section list end python">]</span></span><span class="punctuation separator arguments python">,</span> <span class="variable parameter python">zoom_start</span><span class="keyword operator assignment python">=</span><span class="constant numeric integer decimal python">2</span><span class="punctuation separator arguments python">,</span><span class="variable parameter python">tiles</span><span class="keyword operator assignment python">=</span><span class="constant language python">None</span></span><span class="punctuation section arguments end python">)</span></span>
<span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">folium</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">TileLayer</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">CartoDB positron<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation separator arguments python">,</span><span class="variable parameter python">name</span><span class="keyword operator assignment python">=</span><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">Dark Map<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation separator arguments python">,</span><span class="variable parameter python">control</span><span class="keyword operator assignment python">=</span><span class="constant language python">False</span></span><span class="punctuation section arguments end python">)</span></span><span class="meta function-call python"><span class="meta qualified-name python"><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">add_to</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">world_map</span></span></span><span class="punctuation section arguments end python">)</span></span>

<span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Creating choropleth map
</span><span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">folium</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">Choropleth</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python">
    <span class="variable parameter python">geo_data</span><span class="keyword operator assignment python">=</span><span class="meta qualified-name python"><span class="meta generic-name python">merged_df</span></span><span class="punctuation separator arguments python">,</span>
    <span class="variable parameter python">name</span><span class="keyword operator assignment python">=</span><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">Choropleth<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation separator arguments python">,</span>
    <span class="variable parameter python">data</span><span class="keyword operator assignment python">=</span><span class="meta qualified-name python"><span class="meta generic-name python">merged_df</span></span><span class="punctuation separator arguments python">,</span>
    <span class="variable parameter python">columns</span><span class="keyword operator assignment python">=</span><span class="meta structure list python"><span class="punctuation section list begin python">[</span><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">Country<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation separator list python">,</span><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">Overall rank<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation section list end python">]</span></span><span class="punctuation separator arguments python">,</span>
    <span class="variable parameter python">key_on</span><span class="keyword operator assignment python">=</span><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">feature.properties.Country<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation separator arguments python">,</span>
    <span class="variable parameter python">fill_color</span><span class="keyword operator assignment python">=</span><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">YlOrRd<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation separator arguments python">,</span>
    <span class="variable parameter python">fill_opacity</span><span class="keyword operator assignment python">=</span><span class="constant numeric float python">0<span class="punctuation separator decimal python">.</span>6</span><span class="punctuation separator arguments python">,</span>
    <span class="variable parameter python">line_opacity</span><span class="keyword operator assignment python">=</span><span class="constant numeric float python">0<span class="punctuation separator decimal python">.</span>8</span><span class="punctuation separator arguments python">,</span>
    <span class="variable parameter python">legend_name</span><span class="keyword operator assignment python">=</span><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">Overall happiness rank<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation separator arguments python">,</span>
    <span class="variable parameter python">smooth_factor</span><span class="keyword operator assignment python">=</span><span class="constant numeric integer decimal python">0</span><span class="punctuation separator arguments python">,</span>
    <span class="variable parameter python">highlight</span><span class="keyword operator assignment python">=</span><span class="constant language python">True</span>
</span><span class="punctuation section arguments end python">)</span></span><span class="meta function-call python"><span class="meta qualified-name python"><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">add_to</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">world_map</span></span></span><span class="punctuation section arguments end python">)</span></span></span></code></pre>
<p>Let's look at the resulting map.</p>
<h2 id="create-a-tooltip-on-hover"><span class="section-number-2">7.</span> Create a Tooltip on Hover</h2>
<p>Now that we have a map set up, we could stop. However, I want to add a tooltip so that I can see more information about each country. The <code class="verbatim">tooltip_data</code> code below will show a popup on hover with all the data fields shown.</p>
<pre><code class="language-python highlight"><span class="source python">    <span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Adding labels to map
</span>    <span class="meta qualified-name python"><span class="meta generic-name python">style_function</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function inline python"><span class="storage type function inline python">lambda</span></span><span class="meta function inline python"><span class="meta function inline parameters python"> <span class="variable parameter python">x</span></span><span class="punctuation section function begin python">:</span></span> <span class="meta structure dictionary-or-set python"><span class="punctuation section dictionary-or-set begin python">{</span><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">fillColor<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation separator key-value python">:</span> <span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">#ffffff<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation separator dictionary-or-set python">,</span>
                                <span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">color<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation separator key-value python">:</span><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">#000000<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation separator dictionary-or-set python">,</span>
                                <span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">fillOpacity<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation separator key-value python">:</span> <span class="constant numeric float python">0<span class="punctuation separator decimal python">.</span>1</span><span class="punctuation separator dictionary-or-set python">,</span>
                            <span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">weight<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation separator key-value python">:</span> <span class="constant numeric float python">0<span class="punctuation separator decimal python">.</span>1</span><span class="punctuation section dictionary-or-set end python">}</span></span>

<span class="meta qualified-name python"><span class="meta generic-name python">tooltip_data</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">folium</span><span class="punctuation accessor dot python">.</span><span class="meta generic-name python">features</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">GeoJson</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python">
    <span class="meta qualified-name python"><span class="meta generic-name python">merged_df</span></span><span class="punctuation separator arguments python">,</span>
    <span class="variable parameter python">style_function</span><span class="keyword operator assignment python">=</span><span class="meta qualified-name python"><span class="meta generic-name python">style_function</span></span><span class="punctuation separator arguments python">,</span>
    <span class="variable parameter python">control</span><span class="keyword operator assignment python">=</span><span class="constant language python">False</span><span class="punctuation separator arguments python">,</span>
    <span class="variable parameter python">tooltip</span><span class="keyword operator assignment python">=</span><span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">folium</span><span class="punctuation accessor dot python">.</span><span class="meta generic-name python">features</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">GeoJsonTooltip</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python">
        <span class="variable parameter python">fields</span><span class="keyword operator assignment python">=</span><span class="meta structure list python"><span class="punctuation section list begin python">[</span><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">Country<span class="punctuation definition string end python">&#39;</span></span></span>
                <span class="punctuation separator list python">,</span><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">Overall rank<span class="punctuation definition string end python">&#39;</span></span></span>
                <span class="punctuation separator list python">,</span><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">Score<span class="punctuation definition string end python">&#39;</span></span></span>
                <span class="punctuation separator list python">,</span><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">GDP per capita<span class="punctuation definition string end python">&#39;</span></span></span>
                <span class="punctuation separator list python">,</span><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">Social support<span class="punctuation definition string end python">&#39;</span></span></span>
                <span class="punctuation separator list python">,</span><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">Healthy life expectancy<span class="punctuation definition string end python">&#39;</span></span></span>
                <span class="punctuation separator list python">,</span><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">Freedom to make life choices<span class="punctuation definition string end python">&#39;</span></span></span>
                <span class="punctuation separator list python">,</span><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">Generosity<span class="punctuation definition string end python">&#39;</span></span></span>
                <span class="punctuation separator list python">,</span><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">Perceptions of corruption<span class="punctuation definition string end python">&#39;</span></span></span>
               <span class="punctuation section list end python">]</span></span><span class="punctuation separator arguments python">,</span>
        <span class="variable parameter python">aliases</span><span class="keyword operator assignment python">=</span><span class="meta structure list python"><span class="punctuation section list begin python">[</span><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">Country: <span class="punctuation definition string end python">&#39;</span></span></span>
                <span class="punctuation separator list python">,</span><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">Happiness rank: <span class="punctuation definition string end python">&#39;</span></span></span>
                <span class="punctuation separator list python">,</span><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">Happiness score: <span class="punctuation definition string end python">&#39;</span></span></span>
                <span class="punctuation separator list python">,</span><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">GDP per capita: <span class="punctuation definition string end python">&#39;</span></span></span>
                <span class="punctuation separator list python">,</span><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">Social support: <span class="punctuation definition string end python">&#39;</span></span></span>
                <span class="punctuation separator list python">,</span><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">Healthy life expectancy: <span class="punctuation definition string end python">&#39;</span></span></span>
                <span class="punctuation separator list python">,</span><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">Freedom to make life choices: <span class="punctuation definition string end python">&#39;</span></span></span>
                <span class="punctuation separator list python">,</span><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">Generosity: <span class="punctuation definition string end python">&#39;</span></span></span>
                <span class="punctuation separator list python">,</span><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">Perceptions of corruption: <span class="punctuation definition string end python">&#39;</span></span></span>
                 <span class="punctuation section list end python">]</span></span><span class="punctuation separator arguments python">,</span>
        <span class="variable parameter python">style</span><span class="keyword operator assignment python">=</span><span class="meta group python"><span class="punctuation section group begin python">(</span><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">background-color: white; color: #333333; font-family: arial; font-size: 12px; padding: 10px;<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation section group end python">)</span></span>
    </span><span class="punctuation section arguments end python">)</span></span>
</span><span class="punctuation section arguments end python">)</span></span>
<span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">world_map</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">add_child</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">tooltip_data</span></span></span><span class="punctuation section arguments end python">)</span></span>
<span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">world_map</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">keep_in_front</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">tooltip_data</span></span></span><span class="punctuation section arguments end python">)</span></span>
<span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">folium</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">LayerControl</span></span><span class="punctuation section arguments begin python">(</span><span class="punctuation section arguments end python">)</span></span><span class="meta function-call python"><span class="meta qualified-name python"><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">add_to</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">world_map</span></span></span><span class="punctuation section arguments end python">)</span></span>

<span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Display the map
</span><span class="meta qualified-name python"><span class="meta generic-name python">world_map</span></span></span></code></pre>
<p>The tooltip will now appear whenever you hover over a country.</p>
]]></description>
    </item>
    <item>
      <title>Internal Audit: Who Are They?</title>
      <link>https://cleberg.net/blog/internal-audit.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/internal-audit.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Tue, 22 Sep 2020 00:00:00 +0000</pubDate>
      <category>audit</category>
      <description><![CDATA[<h2 id="definitions"><span class="section-number-2">1.</span> Definitions</h2>
<p>One of the many reasons that Internal Audit needs such thorough explaining to non-auditors is that Internal Audit can serve many purposes, depending on the organization's size and needs. However, the Institute of Internal Auditors (IIA) defines Internal Auditing as:</p>
<blockquote>
<p>Internal auditing is an independent, objective assurance and consulting activity designed to add value and improve an organization's operations. It helps an organization accomplish its objectives by bringing a systematic, disciplined approach to evaluate and improve the effectiveness of risk management, control, and governance processes.</p>
</blockquote>
<p>However, this definition uses quite a few terms that aren't clear unless the reader already has a solid understanding of the auditing profession. To further explain, the following is a list of definitions that can help supplement understanding of internal auditing.</p>
<h3 id="independent"><span class="section-number-3">1.1.</span> Independent</h3>
<p>Independence is the freedom from conditions that threaten the ability of the internal audit activity to carry out internal audit responsibilities in an unbiased manner. To achieve the degree of independence necessary to effectively carry out the responsibilities of the internal audit activity, the chief audit executive has direct and unrestricted access to senior management and the board. This can be achieved through a dual-reporting relationship. Threats to independence must be managed at the individual auditor, engagement, functional, and organizational levels.</p>
<h3 id="objective"><span class="section-number-3">1.2.</span> Objective</h3>
<p>Objectivity is an unbiased mental attitude that allows internal auditors to perform engagements in such a manner that they believe in their work product and that no quality compromises are made. Objectivity requires that internal auditors do not subordinate their judgment on audit matters to others. Threats to objectivity must be managed at the individual auditor, engagement, functional, and organizational levels.</p>
<h3 id="assurance"><span class="section-number-3">1.3.</span> Assurance</h3>
<p>Assurance services involve the internal auditor's objective assessment of evidence to provide opinions or conclusions regarding an entity, operation, function, process, system, or other subject matters. The internal auditor determines the nature and scope of an assurance engagement. Generally, three parties are participants in assurance services: (1) the person or group directly involved with the entity, operation, function, process, system, or other subject - (the process owner), (2) the person or group making the assessment - (the internal auditor), and (3) the person or group using the assessment - (the user).</p>
<h3 id="consulting"><span class="section-number-3">1.4.</span> Consulting</h3>
<p>Consulting services are advisory in nature and are generally performed at the specific request of an engagement client. The nature and scope of the consulting engagement are subject to agreement with the engagement client. Consulting services generally involve two parties: (1) the person or group offering the advice (the internal auditor), and (2) the person or group seeking and receiving the advice (the engagement client). When performing consulting services, the internal auditor should maintain objectivity and not assume management responsibility.</p>
<h3 id="governance-risk-management-compliance-grc"><span class="section-number-3">1.5.</span> Governance, Risk Management, &amp; Compliance (GRC)</h3>
<p>The integrated collection of capabilities that enable an organization to reliably achieve objectives, address uncertainty and act with integrity.</p>
<h2 id="audit-charter-standards"><span class="section-number-2">2.</span> Audit Charter &amp; Standards</h2>
<p>First, it's important to note that not every organization needs internal auditors. In fact, it's unwise for an organization to hire internal auditors unless they have regulatory requirements for auditing and have the capital to support the department. Internal audit is a cost center that can only affect revenue indirectly.</p>
<p>Once an organization determines the need for internal assurance services, they will hire a Chief Audit Executive and create the audit charter. This charter is a document, approved by the company's governing body, that will define internal audit's purpose, authority, responsibility, and position within the organization. Fortunately, the IIA has model charters available to IIA members for those developing or improving their charter.</p>
<p>Beyond the charter and organizational documents, internal auditors follow a few different standards in order to perform their job. First is the International Professional Practices Framework (IPPF) by the IIA, which is the model of standards for internal auditing. In addition, ISACA's Information Technology Assurance Framework (ITAF) helps guide auditors in reference to information technology (IT) compliance and assurance. Finally, additional standards such as FASB, GAAP, and industry-specific standards are used when performing internal audit work.</p>
<h2 id="three-lines-of-defense"><span class="section-number-2">3.</span> Three Lines of Defense</h2>
<p><a href="https://theiia.org">The IIA</a> released the original Three Lines of Defense model in 2013, but have released an updated version in 2020.</p>
<p>I won't go into depth about the changes made to the model in this article. Instead, let's take a look at the most current model.</p>
<p>The updated model forgets the strict idea of areas performing their own functions or line of defense. Instead of talking about management, risk, and internal audit as 1-2-3, the new model creates a more fluid and cooperative model.</p>
<p>Looking at this model from an auditing perspective shows us that auditors will need to align, communicate, and collaborate with management, including business area managers and chief officers, as well as reporting to the governing body. The governing body will instruct internal audit <em>functionally</em> on their goals and track their progress periodically.</p>
<p>However, the internal audit department will report <em>administratively</em> to a chief officer in the company for the purposes of collaboration, direction, and assistance with the business. Note that in most situations, the governing body is the audit committee on the company's board of directors.</p>
<p>The result of this structure is that internal audit is an independent and objective function that can provide assurance over the topics they audit.</p>
<h2 id="audit-process"><span class="section-number-2">4.</span> Audit Process</h2>
<p>A normal audit will generally follow the same process, regardless of the topic. However, certain special projects or abnormal business areas may call for changes to the audit process. The audit process is not set in stone, it's simply a set of best practices so that audits can be performed consistently.</p>
<p>While different organizations may tweak the process, it will generally follow this flow:</p>
<h3 id="1-risk-assessment"><span class="section-number-3">4.1.</span> 1. Risk Assessment</h3>
<p>The risk assessment part of the process has historically been performed annually, but many organizations have moved to performing this process much more frequently. In fact, some organizations are moving to an agile approach that can take new risks into the risk assessment and re-prioritize risk areas on-the-go. To perform a risk assessment, leaders in internal audit will research industry risks, consult with business leaders around the company, and perform analyses on company data.</p>
<p>Once a risk assessment has been documented, the audit department has a prioritized list of risks that can be audited. This is usually in the form of auditable entities, such as business areas or departments.</p>
<h3 id="2-planning"><span class="section-number-3">4.2.</span> 2. Planning</h3>
<p>During the planning phase of an audit, auditors will meet with the business area to discuss the various processes, controls, and risks applicable to the business. This helps the auditors determine the scope limits for the audit, as well as timing and subject-matter experts. Certain documents will be created in this phase that will be used to keep the audit on-track an in-scope as it goes forward.</p>
<h3 id="3-testing"><span class="section-number-3">4.3.</span> 3. Testing</h3>
<p>The testing phase, also known as fieldwork or execution, is where internal auditors will take the information they've discovered and test it against regulations, industry standards, company rules, best practices, as well as validating that any processes are complete and accurate. For example, an audit of HR would most likely examine processes such as employee on-boarding, employee termination, security of personally identifiable information (PII), or the IT systems involved in these processes. Company standards would be examined and compared against how the processes are actually being performed day-to-day, as well as compared against regulations such as the Equal Employment Opportunity (EEO), American with Disabilities Act, and National Labor Relations Act.</p>
<h3 id="4-reporting"><span class="section-number-3">4.4.</span> 4. Reporting</h3>
<p>Once all the tests have been completed, the audit will enter the reporting phase. This is when the audit team will conclude on the evidence they've collected, interviews they've held, and any opinions they've formed on the controls in place. A summary of the audit findings, conclusions, and specific recommendations are officially communicated to the client through a draft report. Clients have the opportunity to respond to the report and submit an action plan and time frame. These responses become part of the final report which is distributed to the appropriate level of administration.</p>
<h3 id="5-follow-up"><span class="section-number-3">4.5.</span> 5. Follow-Up</h3>
<p>After audits have been completed and management has formed action plans and time frames for audit issues, internal audit will follow up once that due date has arrived. In most cases, the follow-up will simply consist of a meeting to discuss how the action plan has been completed and to request documentation to prove it.</p>
<h2 id="audit-department-structure"><span class="section-number-2">5.</span> Audit Department Structure</h2>
<p>While an internal audit department is most often thought of as a team of full-time employees, there are actually many different ways in which a department can be structured. As the world becomes more digital and fast-paced, outsourcing has become a more attractive option for some organizations. Internal audit can be fully outsourced or partially outsourced, allowing for flexibility in cases where turnover is high.</p>
<p>In addition, departments can implement a rotational model. This allows for interested employees around the organization to rotate into the internal audit department for a period of time, allowing them to obtain knowledge of risks and controls and allowing the internal audit team to obtain more business area knowledge. This program is popular in very large organizations, but organizations tend to rotate lower-level audit staff instead of managers. This helps prevent any significant knowledge loss as auditors rotate out to business areas.</p>
<h2 id="consulting"><span class="section-number-2">6.</span> Consulting</h2>
<p>Consulting is not an easy task at any organization, especially for a department that can have negative perceptions within the organization as the "compliance police." However, once an internal audit department has delivered value to organization, adding consulting to their suite of services is a smart move. In most cases, Internal Audit can insert themselves into a consulting role without affecting the process of project management at the company. This means that internal audit can add objective assurance and opinions to business areas as they develop new processes, instead of coming in periodically to audit an area and file issues that could have been fixed at the beginning.</p>
<h2 id="data-science-data-analytics"><span class="section-number-2">7.</span> Data Science &amp; Data Analytics</h2>
<p>One major piece of the internal audit function in the modern world is data science. While the process is data science, most auditors will refer to anything in this realm as data analytics. Hot topics such as robotic process automation (RPA), machine learning (ML), and data mining have taken over the auditing world in recent years. These technologies have been immensely helpful with increasing the effectiveness and efficiency of auditors.</p>
<p>For example, mundane and repetitive tasks can be automated in order for auditors to make more room in their schedules for labor-intensive work. Further, auditors will need to adapt technologies like machine learning in order to extract more value from the data they're using to form conclusions.</p>
]]></description>
    </item>
    <item>
      <title>IBM Watson Vision API</title>
      <link>https://cleberg.net/blog/visual-recognition.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/visual-recognition.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Tue, 01 Sep 2020 00:00:00 +0000</pubDate>
      <category>linux</category>
      <description><![CDATA[<h2 id="what-is-ibm-watson"><span class="section-number-2">1.</span> What is IBM Watson?</h2>
<p>If you've never heard of <a href="https://www.ibm.com/watson">Watson</a>, this service is a suite of enterprise-ready artificial intelligence (AI) services, applications, and tooling provided by IBM. Watson contains quite a few useful tools for data scientists and students, including the subject of this post today: visual recognition.</p>
<p>If you'd like to view the official documentation for the Visual Recognition application programming interface (API), visit the <a href="https://cloud.ibm.com/apidocs/visual-recognition/visual-recognition-v3?code=python">API Docs</a>.</p>
<h2 id="prerequisites"><span class="section-number-2">2.</span> Prerequisites</h2>
<p>To be able to use Watson Visual Recognition, you'll need the following:</p>
<ol>
<li>Create a free account on <a href="https://www.ibm.com/cloud/watson-studio">IBM Watson Studio</a>.</li>
<li>Add the <a href="https://www.ibm.com/cloud/watson-visual-recognition">Watson Visual Recognition</a> service to your IBM Watson account.</li>
<li>Get your API key and URL (uniform resource locator). To do this, first go to the <a href="https://dataplatform.cloud.ibm.com/home2?context=cpdaas">profile dashboard</a> for your IBM account and click on the Watson Visual Recognition service you created. This will be listed in the section titled <strong>Your services</strong>. Then click the <strong>Credentials</strong> tab and open the <strong>Auto-generated credentials</strong> dropdown. Copy your API key and URL so that you can use them in the Python script later.</li>
<li><strong>[Optional]</strong> While not required, you can also create the Jupyter Notebook for this project right inside <a href="https://www.ibm.com/cloud/watson-studio">Watson Studio</a>. Watson Studio will save your notebooks inside an organized project and allow you to use their other integrated products, such as storage containers, AI models, documentation, external sharing, etc.</li>
</ol>
<h2 id="calling-the-ibm-watson-visual-recognition-api"><span class="section-number-2">3.</span> Calling the IBM Watson Visual Recognition API</h2>
<p>Okay, now let's get started.</p>
<p>To begin, we need to install the proper Python package for IBM Watson.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">pip</span></span><span class="meta function-call arguments shell"> install<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> --</span>upgrade</span><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> --</span>user</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>ibm-watson&gt;=4.5.0<span class="punctuation definition string end shell">&quot;</span></span></span></span></code></pre>
<p>Next, we need to specify the API key, version, and URL given to us when we created the Watson Visual Recognition service.</p>
<pre><code class="language-python highlight"><span class="source python"><span class="meta qualified-name python"><span class="meta generic-name python">apikey</span></span> <span class="keyword operator assignment python">=</span> <span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">&lt;your-apikey&gt;<span class="punctuation definition string end python">&quot;</span></span></span>
<span class="meta qualified-name python"><span class="meta generic-name python">version</span></span> <span class="keyword operator assignment python">=</span> <span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">2018-03-19<span class="punctuation definition string end python">&quot;</span></span></span>
<span class="meta qualified-name python"><span class="meta generic-name python">url</span></span> <span class="keyword operator assignment python">=</span> <span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">&lt;your-url&gt;<span class="punctuation definition string end python">&quot;</span></span></span></span></code></pre>
<p>Now, let's import the necessary libraries and authenticate our service.</p>
<pre><code class="language-python highlight"><span class="source python"><span class="meta statement import python"><span class="keyword control import python">import</span> <span class="meta qualified-name python"><span class="meta generic-name python">json</span></span></span>
<span class="meta statement import python"><span class="keyword control import from python">from</span></span><span class="meta statement import python"><span class="meta import-source python"> <span class="meta import-path python"><span class="meta import-name python">ibm_watson</span></span> <span class="meta statement import python"><span class="keyword control import python">import</span></span></span></span><span class="meta statement import python"></span><span class="meta statement import python"> <span class="meta generic-name python">VisualRecognitionV3</span></span>
<span class="meta statement import python"><span class="keyword control import from python">from</span></span><span class="meta statement import python"><span class="meta import-source python"> <span class="meta import-path python"><span class="meta import-name python">ibm_cloud_sdk_core</span><span class="punctuation accessor dot python">.</span><span class="meta import-name python">authenticators</span></span> <span class="meta statement import python"><span class="keyword control import python">import</span></span></span></span><span class="meta statement import python"></span><span class="meta statement import python"> <span class="meta generic-name python">IAMAuthenticator</span></span>

<span class="meta qualified-name python"><span class="meta generic-name python">authenticator</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="variable function python">IAMAuthenticator</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">apikey</span></span></span><span class="punctuation section arguments end python">)</span></span>
<span class="meta qualified-name python"><span class="meta generic-name python">visual_recognition</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="variable function python">VisualRecognitionV3</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python">
  <span class="variable parameter python">version</span><span class="keyword operator assignment python">=</span><span class="meta qualified-name python"><span class="meta generic-name python">version</span></span><span class="punctuation separator arguments python">,</span>
  <span class="variable parameter python">authenticator</span><span class="keyword operator assignment python">=</span><span class="meta qualified-name python"><span class="meta generic-name python">authenticator</span></span>
</span><span class="punctuation section arguments end python">)</span></span>

<span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">visual_recognition</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">set_service_url</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">url</span></span></span><span class="punctuation section arguments end python">)</span></span></span></code></pre>
<p><strong>[Optional]</strong> If you'd like to tell the API not to use any data to improve their products, set the following header.</p>
<pre><code class="language-python highlight"><span class="source python"><span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">visual_recognition</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">set_default_headers</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta structure dictionary-or-set python"><span class="punctuation section dictionary-or-set begin python">{</span><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">x-watson-learning-opt-out<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation separator key-value python">:</span> <span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">true<span class="punctuation definition string end python">&quot;</span></span></span><span class="punctuation section dictionary-or-set end python">}</span></span></span><span class="punctuation section arguments end python">)</span></span></span></code></pre>
<p>Now we have our API all set and ready to go. For this example, I'm going to include a <code class="verbatim">dict</code> of photos to load as we test out the API.</p>
<pre><code class="language-python highlight"><span class="source python"><span class="meta qualified-name python"><span class="meta generic-name python">data</span></span> <span class="keyword operator assignment python">=</span> <span class="meta structure list python"><span class="punctuation section list begin python">[</span>
  <span class="meta structure dictionary-or-set python"><span class="punctuation section dictionary-or-set begin python">{</span>
    <span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">title<span class="punctuation definition string end python">&quot;</span></span></span><span class="punctuation separator key-value python">:</span> <span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">Grizzly Bear<span class="punctuation definition string end python">&quot;</span></span></span><span class="punctuation separator dictionary-or-set python">,</span>
    <span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">url<span class="punctuation definition string end python">&quot;</span></span></span><span class="punctuation separator key-value python">:</span> <span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">https://example.com/photos/image1.jpg<span class="punctuation definition string end python">&quot;</span></span></span>
  <span class="punctuation section dictionary-or-set end python">}</span></span><span class="punctuation separator list python">,</span>
  <span class="meta structure dictionary-or-set python"><span class="punctuation section dictionary-or-set begin python">{</span>
    <span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">title<span class="punctuation definition string end python">&quot;</span></span></span><span class="punctuation separator key-value python">:</span> <span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">Nature Lake<span class="punctuation definition string end python">&quot;</span></span></span><span class="punctuation separator dictionary-or-set python">,</span>
    <span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">url<span class="punctuation definition string end python">&quot;</span></span></span><span class="punctuation separator key-value python">:</span> <span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">https://example.com/photos/image2.jpg<span class="punctuation definition string end python">&quot;</span></span></span>
  <span class="punctuation section dictionary-or-set end python">}</span></span><span class="punctuation separator list python">,</span>
  <span class="meta structure dictionary-or-set python"><span class="punctuation section dictionary-or-set begin python">{</span>
    <span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">title<span class="punctuation definition string end python">&quot;</span></span></span><span class="punctuation separator key-value python">:</span> <span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">Welcome Sign<span class="punctuation definition string end python">&quot;</span></span></span><span class="punctuation separator dictionary-or-set python">,</span>
    <span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">url<span class="punctuation definition string end python">&quot;</span></span></span><span class="punctuation separator key-value python">:</span> <span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">https://example.com/photos/image3.jpg<span class="punctuation definition string end python">&quot;</span></span></span>
  <span class="punctuation section dictionary-or-set end python">}</span></span><span class="punctuation separator list python">,</span>
  <span class="meta structure dictionary-or-set python"><span class="punctuation section dictionary-or-set begin python">{</span>
    <span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">title<span class="punctuation definition string end python">&quot;</span></span></span><span class="punctuation separator key-value python">:</span> <span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">Honey Badger<span class="punctuation definition string end python">&quot;</span></span></span><span class="punctuation separator dictionary-or-set python">,</span>
    <span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">url<span class="punctuation definition string end python">&quot;</span></span></span><span class="punctuation separator key-value python">:</span> <span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">https://example.com/photos/image4.jpg<span class="punctuation definition string end python">&quot;</span></span></span>
  <span class="punctuation section dictionary-or-set end python">}</span></span><span class="punctuation separator list python">,</span>
  <span class="meta structure dictionary-or-set python"><span class="punctuation section dictionary-or-set begin python">{</span>
    <span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">title<span class="punctuation definition string end python">&quot;</span></span></span><span class="punctuation separator key-value python">:</span> <span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">Grand Canyon Lizard<span class="punctuation definition string end python">&quot;</span></span></span><span class="punctuation separator dictionary-or-set python">,</span>
    <span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">url<span class="punctuation definition string end python">&quot;</span></span></span><span class="punctuation separator key-value python">:</span> <span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">https://example.com/photos/image5.jpg<span class="punctuation definition string end python">&quot;</span></span></span>
  <span class="punctuation section dictionary-or-set end python">}</span></span><span class="punctuation separator list python">,</span>
  <span class="meta structure dictionary-or-set python"><span class="punctuation section dictionary-or-set begin python">{</span>
    <span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">title<span class="punctuation definition string end python">&quot;</span></span></span><span class="punctuation separator key-value python">:</span> <span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">Castle<span class="punctuation definition string end python">&quot;</span></span></span><span class="punctuation separator dictionary-or-set python">,</span>
    <span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">url<span class="punctuation definition string end python">&quot;</span></span></span><span class="punctuation separator key-value python">:</span> <span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">https://example.com/photos/image6.jpg<span class="punctuation definition string end python">&quot;</span></span></span>
  <span class="punctuation section dictionary-or-set end python">}</span></span>
<span class="punctuation section list end python">]</span></span></span></code></pre>
<p>Now that we've set up our libraries and have the photos ready, let's create a loop to call the API for each image. The code below shows a loop that calls the URL of each image and sends it to the API, requesting results with at least 60% confidence. The results are output to the console with dotted lines separating each section.</p>
<p>In the case of an API error, the codes and explanations are output to the console.</p>
<pre><code class="language-python highlight"><span class="source python"><span class="meta statement import python"><span class="keyword control import from python">from</span></span><span class="meta statement import python"><span class="meta import-source python"> <span class="meta import-path python"><span class="meta import-name python">ibm_watson</span></span> <span class="meta statement import python"><span class="keyword control import python">import</span></span></span></span><span class="meta statement import python"></span><span class="meta statement import python"> <span class="meta generic-name python">ApiException</span></span>

<span class="meta statement for python"><span class="keyword control flow for python">for</span> <span class="meta generic-name python">x</span> <span class="meta statement for python"><span class="keyword control flow for in python">in</span></span></span><span class="meta statement for python"> <span class="meta function-call python"><span class="meta qualified-name python"><span class="support function builtin python">range</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta function-call python"><span class="meta qualified-name python"><span class="support function builtin python">len</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">data</span></span></span><span class="punctuation section arguments end python">)</span></span></span><span class="punctuation section arguments end python">)</span></span><span class="punctuation section block for python">:</span></span>
<span class="meta statement try python"><span class="keyword control flow try python">try</span><span class="punctuation section block try python">:</span></span>
   <span class="meta qualified-name python"><span class="meta generic-name python">url</span></span> <span class="keyword operator assignment python">=</span> <span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">data</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">x</span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">url<span class="punctuation definition string end python">&quot;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span>
   <span class="meta qualified-name python"><span class="meta generic-name python">images_filename</span></span> <span class="keyword operator assignment python">=</span> <span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">data</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">x</span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">title<span class="punctuation definition string end python">&quot;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span>
   <span class="meta qualified-name python"><span class="meta generic-name python">classes</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">visual_recognition</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">classify</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python">
       <span class="variable parameter python">url</span><span class="keyword operator assignment python">=</span><span class="meta qualified-name python"><span class="meta generic-name python">url</span></span><span class="punctuation separator arguments python">,</span>
       <span class="variable parameter python">images_filename</span><span class="keyword operator assignment python">=</span><span class="meta qualified-name python"><span class="meta generic-name python">images_filename</span></span><span class="punctuation separator arguments python">,</span>
       <span class="variable parameter python">threshold</span><span class="keyword operator assignment python">=</span><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">0.6<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation separator arguments python">,</span>
       <span class="variable parameter python">owners</span><span class="keyword operator assignment python">=</span><span class="meta structure list python"><span class="punctuation section list begin python">[</span><span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">IBM<span class="punctuation definition string end python">&quot;</span></span></span><span class="punctuation section list end python">]</span></span></span><span class="punctuation section arguments end python">)</span></span><span class="meta function-call python"><span class="meta qualified-name python"><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">get_result</span></span><span class="punctuation section arguments begin python">(</span><span class="punctuation section arguments end python">)</span></span>
   <span class="meta function-call python"><span class="meta qualified-name python"><span class="support function builtin python">print</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">-----------------------------------------------<span class="punctuation definition string end python">&quot;</span></span></span></span><span class="punctuation section arguments end python">)</span></span>
   <span class="meta function-call python"><span class="meta qualified-name python"><span class="support function builtin python">print</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">Image Title: <span class="punctuation definition string end python">&quot;</span></span></span><span class="punctuation separator arguments python">,</span> <span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">data</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">x</span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">title<span class="punctuation definition string end python">&quot;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span><span class="punctuation separator arguments python">,</span> <span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python"><span class="constant character escape python">\n</span><span class="punctuation definition string end python">&quot;</span></span></span></span><span class="punctuation section arguments end python">)</span></span>
   <span class="meta function-call python"><span class="meta qualified-name python"><span class="support function builtin python">print</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">Image URL: <span class="punctuation definition string end python">&quot;</span></span></span><span class="punctuation separator arguments python">,</span> <span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">data</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">x</span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">url<span class="punctuation definition string end python">&quot;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span><span class="punctuation separator arguments python">,</span> <span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python"><span class="constant character escape python">\n</span><span class="punctuation definition string end python">&quot;</span></span></span></span><span class="punctuation section arguments end python">)</span></span>
   <span class="meta qualified-name python"><span class="meta generic-name python">classification_results</span></span> <span class="keyword operator assignment python">=</span> <span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">classes</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">images<span class="punctuation definition string end python">&quot;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="constant numeric integer decimal python">0</span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">classifiers<span class="punctuation definition string end python">&quot;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="constant numeric integer decimal python">0</span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">classes<span class="punctuation definition string end python">&quot;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span>
   <span class="meta statement for python"><span class="keyword control flow for python">for</span> <span class="meta generic-name python">result</span> <span class="meta statement for python"><span class="keyword control flow for in python">in</span></span></span><span class="meta statement for python"> <span class="meta qualified-name python"><span class="meta generic-name python">classification_results</span></span><span class="punctuation section block for python">:</span></span>
       <span class="meta function-call python"><span class="meta qualified-name python"><span class="support function builtin python">print</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">result</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">class<span class="punctuation definition string end python">&quot;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span><span class="punctuation separator arguments python">,</span> <span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">(<span class="punctuation definition string end python">&quot;</span></span></span><span class="punctuation separator arguments python">,</span> <span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">result</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">score<span class="punctuation definition string end python">&quot;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span><span class="punctuation separator arguments python">,</span> <span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">)<span class="punctuation definition string end python">&quot;</span></span></span></span><span class="punctuation section arguments end python">)</span></span>
   <span class="meta function-call python"><span class="meta qualified-name python"><span class="support function builtin python">print</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">-----------------------------------------------<span class="punctuation definition string end python">&quot;</span></span></span></span><span class="punctuation section arguments end python">)</span></span>
<span class="meta statement except python"><span class="keyword control flow except python">except</span> <span class="meta generic-name python">ApiException</span> <span class="keyword control flow as python">as</span></span><span class="meta statement except python"> <span class="meta generic-name python">ex</span></span><span class="meta statement except python"><span class="punctuation section block except python">:</span></span>
   <span class="meta function-call python"><span class="meta qualified-name python"><span class="support function builtin python">print</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">Method failed with status code <span class="punctuation definition string end python">&quot;</span></span></span> <span class="keyword operator arithmetic python">+</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="support type python">str</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">ex</span><span class="punctuation accessor dot python">.</span><span class="meta generic-name python">code</span></span></span><span class="punctuation section arguments end python">)</span></span> <span class="keyword operator arithmetic python">+</span> <span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">: <span class="punctuation definition string end python">&quot;</span></span></span> <span class="keyword operator arithmetic python">+</span> <span class="meta qualified-name python"><span class="meta generic-name python">ex</span><span class="punctuation accessor dot python">.</span><span class="meta generic-name python">message</span></span></span><span class="punctuation section arguments end python">)</span></span></span></code></pre>
<h2 id="the-results"><span class="section-number-2">4.</span> The Results</h2>
<p>Here we can see the full result set of our function above. If you view each of the URLs that we sent to the API, you'll be able to see that it was remarkably accurate. To be fair, these are clear high-resolution, clear photos shot with a professional camera. In reality, you will most likely be processing images that are lower quality and may have a lot of noise in the photo.</p>
<p>However, we can clearly see the benefit of being able to call this API instead of attempting to write our own image recognition function. Each of the classifications returned was a fair description of the image.</p>
<p>If you wanted to restrict the results to those that are at least 90% confident or greater, you would simply adjust the <code class="verbatim">threshold</code> in the <code class="verbatim">visual_recognition.classify()</code> function.</p>
<p>When your program runs, it should show the output below for each photo you provide.</p>
<pre><code class="language-txt highlight"><span class="text plain">----------------------------------------------------------------
Image Title:  Grizzly Bear
Image URL: https://example.com/photos/image1.jpg

brown bear ( 0.944 )
bear ( 1 )
carnivore ( 1 )
mammal ( 1 )
animal ( 1 )
Alaskan brown bear ( 0.759 )
greenishness color ( 0.975 )
----------------------------------------------------------------</span></code></pre>
<h2 id="discussion"><span class="section-number-2">5.</span> Discussion</h2>
<p>Now, this was a very minimal implementation of the API. We simply supplied some images and looked to see how accurate the results were. However, you could implement this type of API into many machine learning (ML) models.</p>
<p>For example, you could be working for a company that scans their warehouses or inventory using drones. Would you want to pay employees to sit there and watch drone footage all day in order to identify or count things in the video? Probably not. Instead, you could use a classification system similar to this one in order to train your machine learning model to correctly identify items that the drones show through video. More specifically, you could have your machine learning model watch a drone fly over a field of sheep in order to count how many sheep are living in that field.</p>
<p>There are many ways to implement machine learning functionality, but hopefully this post helped inspire some deeper thought about the tools that can help propel us further into the future of machine learning and AI.</p>
]]></description>
    </item>
    <item>
      <title>Learning PHP Auth</title>
      <link>https://cleberg.net/blog/php-auth-flow.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/php-auth-flow.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Sat, 29 Aug 2020 00:00:00 +0000</pubDate>
      <category>web</category>
      <description><![CDATA[<h2 id="introduction"><span class="section-number-2">1.</span> Introduction</h2>
<p>When creating websites that will allow users to create accounts, the developer always needs to consider the proper authentication flow for their app. For example, some developers will utilize an application programming interface (API) for authentication, some will use OAuth, and some may just use their own simple database.</p>
<p>For those using pre-built libraries, authentication may simply be a problem of copying and pasting the code from their library's documentation. For example, here's the code I use to authenticate users with the Tumblr OAuth API for my Tumblr client, Vox Populi:</p>
<pre><code class="language-php highlight"><span class="embedding php"><span class="text html basic">// Start the session
session_start();

// Use my key/secret pair to create a new client connection
$consumer_key = getenv(&#39;CONSUMER_KEY&#39;);
$consumer_secret = getenv(&#39;CONSUMER_SECRET&#39;);
$client = new Tumblr\API\Client($consumer_key, $consumer_secret);
$requestHandler = $client-&gt;getRequestHandler();
$requestHandler-&gt;setBaseUrl(&#39;https://www.tumblr.com/&#39;);

// Check the session and cookies to see if the user is authenticated
// Otherwise, send user to Tumblr authentication page and set tokens from Tumblr&#39;s response

// Authenticate client
$client = new Tumblr\API\Client(
    $consumer_key,
    $consumer_secret,
    $token,
    $token_secret
);</span></span></code></pre>
<p>However, developers creating authentication flows from scratch will need to think carefully about when to make sure a web page will check the user's authenticity.</p>
<p>In this article, we're going to look at a simple authentication flow using a MySQL database and PHP.</p>
<h2 id="creating-user-accounts"><span class="section-number-2">2.</span> Creating User Accounts</h2>
<p>The beginning to any type of user authentication is to create a user account. This process can take many formats, but the simplest is to accept user input from a form (e.g., username and password) and send it over to your database. For example, here's a snippet that shows how to get username and password parameters that would come when a user submits a form to your PHP script.</p>
<p><strong>Note</strong>: Ensure that your password column is large enough to hold the hashed value (at least 60 characters or longer).</p>
<pre><code class="language-php highlight"><span class="embedding php"><span class="text html basic">// Get the values from the URL
$username = $_POST[&#39;username&#39;];
$raw_password = $_POST[&#39;password&#39;];

// Hash password
// password_hash() will create a random salt if one isn&#39;t provided, and this is generally the easiest and most secure approach.
$password = password_hash($raw_password, PASSWORD_DEFAULT);

// Save database details as variables
$servername = &quot;localhost&quot;;
$username = &quot;username&quot;;
$password = &quot;password&quot;;
$dbname = &quot;myDB&quot;;

// Create connection to the database
$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn-&gt;connect_error) {
  die(&quot;Connection failed: &quot; . $conn-&gt;connect_error);
}

$sql = &quot;INSERT INTO users (username, password)
VALUES (&#39;$username&#39;, &#39;$password&#39;)&quot;;

if ($conn-&gt;query($sql) === TRUE) {
  echo &quot;New record created successfully&quot;;
} else {
  echo &quot;Error: &quot; . $sql . &quot;<span class="meta tag inline any html"><span class="punctuation definition tag begin html">&lt;</span><span class="entity name tag inline any html">br</span><span class="punctuation definition tag end html">&gt;</span></span>&quot; . $conn-&gt;error;
}

$conn-&gt;close();</span></span></code></pre>
<h3 id="validate-returning-users"><span class="section-number-3">2.1.</span> Validate Returning Users</h3>
<p>To be able to verify that a returning user has a valid username and password in your database is as simple as having users fill out a form and comparing their inputs to your database.</p>
<pre><code class="language-php highlight"><span class="embedding php"><span class="text html basic">// Query the database for username and password
// ...

if(password_verify($password_input, $hashed_password)) {
    // If the input password matched the hashed password in the database
    // Do something, log the user in.
}

// Else, Redirect them back to the login page.
...</span></span></code></pre>
<h2 id="storing-authentication-state"><span class="section-number-2">3.</span> Storing Authentication State</h2>
<p>Once you've created the user's account, now you're ready to initialize the user's session. <strong>You will need to do this on every page you load while the user is logged in.</strong> To do so, simply enter the following code snippet:</p>
<pre><code class="language-php highlight"><span class="embedding php"><span class="text html basic">session_start();</span></span></code></pre>
<p>Once you've initialized the session, the next step is to store the session in a cookie so that you can access it later.</p>
<pre><code class="language-php highlight"><span class="embedding php"><span class="text html basic">setcookie(session_name());</span></span></code></pre>
<p>Now that the session name has been stored, you'll be able to check if there's an active session whenever you load a page.</p>
<pre><code class="language-php highlight"><span class="embedding php"><span class="text html basic">if(isset(session_name())) {
    // The session is active
}</span></span></code></pre>
<h3 id="removing-user-authentication"><span class="section-number-3">3.1.</span> Removing User Authentication</h3>
<p>The next logical step is to give your users the option to log out once they are done using your application. This can be tricky in PHP since a few of the standard ways do not always work.</p>
<pre><code class="language-php highlight"><span class="embedding php"><span class="text html basic">// Initialize the session.
// If you are using session_name(&quot;something&quot;), don&#39;t forget it now!
session_start();

// Delete authentication cookies
unset($_COOKIE[session_name()]);
setcookie(session_name(), &quot;&quot;, time() - 3600, &quot;/logged-in/&quot;);
unset($_COOKIE[&quot;PHPSESSID&quot;]);
setcookie(&quot;PHPSESSID&quot;, &quot;&quot;, time() - 3600, &quot;/logged-in/&quot;);

// Unset all of the session variables.
$_SESSION = array();
session_unset();

// If it&#39;s desired to kill the session, also delete the session cookie.
// Note: This will destroy the session, and not just the session data!
if (ini_get(&quot;session.use_cookies&quot;)) {
    $params = session_get_cookie_params();
    setcookie(session_name(), &#39;&#39;, time() - 42000,
        $params[&quot;path&quot;], $params[&quot;domain&quot;],
        $params[&quot;secure&quot;], $params[&quot;httponly&quot;]
    );
}

// Finally, destroy the session.
session_destroy();
session_write_close();

// Go back to sign-in page
header(&#39;Location: https://example.com/logged-out/&#39;);
die();</span></span></code></pre>
<h2 id="wrapping-up"><span class="section-number-2">4.</span> Wrapping Up</h2>
<p>Now you should be ready to begin your authentication programming with PHP. You can create user accounts, create sessions for users across different pages of your site, and then destroy the user data when they're ready to leave.</p>
<p>For more information on this subject, I recommend reading the <a href="https://www.php.net/">PHP Documentation</a>. Specifically, you may want to look at <a href="https://www.php.net/manual/en/features.http-auth.php">HTTP Authentication with PHP</a>, <a href="https://www.php.net/manual/en/book.session.php">session handling</a>, and <a href="https://www.php.net/manual/en/function.hash.php">hash</a>.</p>
]]></description>
    </item>
    <item>
      <title>GitHub Pages Redirect Subdomain to TLD</title>
      <link>https://cleberg.net/blog/redirect-github-pages.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/redirect-github-pages.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Sat, 22 Aug 2020 00:00:00 +0000</pubDate>
      <category>web</category>
      <description><![CDATA[<h2 id="short-answer"><span class="section-number-2">1.</span> Short answer</h2>
<h3 id="step-1"><span class="section-number-3">1.1.</span> Step 1</h3>
<p>Add a new file called <code class="verbatim">CNAME</code> (canonical name) to your GitHub Pages repository containing only one line: your top-level domain name. E.g.: <code class="verbatim">example.com</code></p>
<h3 id="step-2"><span class="section-number-3">1.2.</span> Step 2</h3>
<p>[Optional] but highly recommended</p>
<p>2.1: Remove all other top-level records (prefixed with @) of type A from your DNS configuration.</p>
<p>2.2: Remove a CNAME record for the second-level domain <code class="verbatim">www</code>, if it is present.</p>
<h3 id="step-3"><span class="section-number-3">1.3.</span> Step 3</h3>
<p>Add these 5 entries to the very top of your domain name system (DNS) configuration:</p>
<pre><code class="language-txt highlight"><span class="text plain">@        A        185.199.108.153
@        A        185.199.109.153
@        A        185.199.110.153
@        A        185.199.111.153
www      CNAME    your_github_username.github.io.</span></code></pre>
<p>Replace <code class="verbatim">your_github_username</code> with your actual GitHub username.</p>
<h3 id="step-4"><span class="section-number-3">1.4.</span> Step 4</h3>
<p>Wait for your DNS changes to propagate. DNS changes aren't effective immediately. They can take up to a full day to propagate.</p>
<h2 id="long-answer"><span class="section-number-2">2.</span> Long answer</h2>
<p>This issue has two sides. One is the DNS configuration itself. Another one is the way GitHub Pages will forward hypertext transfer protocol (HTTP) requests.</p>
<p>We need to know a few things to understand what GitHub is trying to say in their documentation.</p>
<h3 id="dns-entry-types"><span class="section-number-3">2.1.</span> DNS Entry Types</h3>
<p>There are two types of DNS records which interest us: CNAME and A.</p>
<p><code class="verbatim">A</code> is also known as <code class="verbatim">Apex</code> or sometimes as <code class="verbatim">root entry</code>. It forwards requests to a specified fixed IP address. <code class="verbatim">CNAME</code> entry forwards requests to a specified URL (actual valid plain text URL, not an internet protocol (IP) address).</p>
<h3 id="dns-load-balancing"><span class="section-number-3">2.2.</span> DNS Load balancing</h3>
<p>GitHub has one central URL address which accepts all DNS requests for GitHub Pages: <code class="verbatim">http://username.github.io</code>. That URL is resolved to different IP addresses based on your geographical location. Website hosted on GitHub Pages is a simple collection of <code class="verbatim">HTML</code>, <code class="verbatim">CSS</code> and <code class="verbatim">JS</code> files. GitHub distributes these files to different servers across the globe. So that when your browser sends a request from Europe, it receives data from a server in Europe. The same is valid for the requests from Asia and the USA.</p>
<h3 id="what-github-is-trying-to-say"><span class="section-number-3">2.3.</span> What GitHub is trying to say</h3>
<p>Since <code class="verbatim">A</code> records in DNS must contain IP addresses, and they must be either <code class="verbatim">185.199.108.153</code> or <code class="verbatim">185.199.109.153</code> or <code class="verbatim">185.199.110.153</code> or <code class="verbatim">185.199.111.153</code>, there is no way to forward requests to a server located somewhere in Europe or Asia. Your website hosted at GitHub Pages will be downloaded from a central GitHub Pages server. There is a minor risk that if GitHub Pages DNS servers (<code class="verbatim">x.x.x.153</code>) are down for some reason, all custom domains which use fixed GitHub Pages IP addresses will not be accessible (their DNS requests will not be resolvable).</p>
<p>That is why GitHub strongly suggests to either use a second-level domain for your GitHub Pages (e.g. <code class="verbatim">blog.example.com</code>) or use a DNS service provider that supports a record type <code class="verbatim">ALIAS</code> that acts as <code class="verbatim">A</code> record but forwards request to a URL address (e.g. <code class="verbatim">username.github.io</code>) instead of a fixed IP address.</p>
<h3 id="how-github-pages-treats-http-requests"><span class="section-number-3">2.4.</span> How GitHub Pages treats HTTP requests</h3>
<p>After a DNS request for <code class="verbatim">your_github_username.github.io</code> is resolved into an IP address, e.g. <code class="verbatim">185.199.108.153</code> your browser sends an HTTP request to that server with an HTTP header <code class="verbatim">Host</code>. Below are <code class="verbatim">curl</code> examples that load the same website (these examples might not work if you are behind a proxy server):</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">curl</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> --</span>header</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>Host: your_github_username.github.io<span class="punctuation definition string end shell">&quot;</span></span> http://185.199.108.153/</span>
<span class="meta function-call shell"><span class="variable function shell">curl</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> --</span>header</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>Host: www.example.com<span class="punctuation definition string end shell">&quot;</span></span> http://185.199.108.153/</span>
<span class="meta function-call shell"><span class="variable function shell">curl</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> --</span>header</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>Host: example.com<span class="punctuation definition string end shell">&quot;</span></span> http://185.199.108.153/</span></span></code></pre>
<p>This way GitHub Pages servers know which user website to serve.</p>
<blockquote>
<p>GitHub Pages server will automatically redirect HTTP requests to the top-level domain if your <code class="verbatim">CNAME</code> file contains <code class="verbatim">example.com</code> but <code class="verbatim">www.example.com</code> is requested.</p>
<p>The same is valid if your <code class="verbatim">CNAME</code> file contains <code class="verbatim">www.example.com</code> but the header <code class="verbatim">Host</code> in the <code class="verbatim">HTTP</code> request contains <code class="verbatim">example.com</code>.</p>
</blockquote>
<h3 id="why-can-t-i-add-a-cname-record-entry-that-accepts-a-top-level-request-to-my-dns-configuration"><span class="section-number-3">2.5.</span> Why can't I add a <code class="verbatim">CNAME</code> record entry that accepts a top-level request (<code class="verbatim">@</code>) to my DNS configuration?</h3>
<p>Quote from the GitHub Pages documentation:</p>
<blockquote>
<p>Warning: Do not create a CNAME record for your custom apex domain! Doing so may cause issues with other services, such as email, on that domain.</p>
</blockquote>
<h3 id="references"><span class="section-number-3">2.6.</span> References:</h3>
<ol>
<li><a href="https://docs.github.com/en/github/working-with-github-pages/configuring-a-custom-domain-for-your-github-pages-site">Setting up a custom domain with GitHub Pages</a></li>
<li><a href="https://docs.github.com/en/github/working-with-github-pages/troubleshooting-custom-domains-and-github-pages">My custom domain isn't working</a></li>
<li><a href="https://serverfault.com/questions/589370/cannot-access-my-github-pages-website-by-ip-address">Cannot access my GitHub Pages website by IP Address</a></li>
<li><a href="https://stackoverflow.com/questions/23375422/how-do-i-set-up-github-pages-to-redirect-dns-requests-from-a-subdomain-e-g-www">How do I set up GitHub Pages to redirect DNS requests from a subdomain (e.g. www) to the top-level domain (TLD, Apex record)?</a></li>
</ol>
]]></description>
    </item>
    <item>
      <title>Data Analysis: Finding the Best Location for a Business</title>
      <link>https://cleberg.net/blog/business-analysis.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/business-analysis.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Sun, 26 Jul 2020 00:00:00 +0000</pubDate>
      <category>audit</category>
      <description><![CDATA[<h2 id="background-information"><span class="section-number-2">1.</span> Background Information</h2>
<p>This project aims to help investors learn more about a random city in order to determine optimal locations for business investments. The data used in this project was obtained using Foursquare's developer API.</p>
<p>Fields include:</p>
<ul>
<li>Venue Name</li>
<li>Venue Category</li>
<li>Venue Latitude</li>
<li>Venue Longitude</li>
</ul>
<p>There are 232 records found using the center of Lincoln as the area of interest with a radius of 10,000.</p>
<h2 id="import-the-data"><span class="section-number-2">2.</span> Import the Data</h2>
<p>The first step is the simplest: import the applicable libraries. We will be using the libraries below for this project.</p>
<pre><code class="language-python highlight"><span class="source python"><span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Import the Python libraries we will be using
</span><span class="meta statement import python"><span class="keyword control import python">import</span> <span class="meta qualified-name python"><span class="meta generic-name python">pandas</span></span> <span class="keyword control import as python">as</span> <span class="meta qualified-name python"><span class="meta generic-name python">pd</span></span></span>
<span class="meta statement import python"><span class="keyword control import python">import</span> <span class="meta qualified-name python"><span class="meta generic-name python">requests</span></span></span>
<span class="meta statement import python"><span class="keyword control import python">import</span> <span class="meta qualified-name python"><span class="meta generic-name python">folium</span></span></span>
<span class="meta statement import python"><span class="keyword control import python">import</span> <span class="meta qualified-name python"><span class="meta generic-name python">math</span></span></span>
<span class="meta statement import python"><span class="keyword control import python">import</span> <span class="meta qualified-name python"><span class="meta generic-name python">json</span></span></span>
<span class="meta statement import python"><span class="keyword control import from python">from</span></span><span class="meta statement import python"><span class="meta import-source python"> <span class="meta import-path python"><span class="meta import-name python">pandas</span><span class="punctuation accessor dot python">.</span><span class="meta import-name python">io</span><span class="punctuation accessor dot python">.</span><span class="meta import-name python">json</span></span> <span class="meta statement import python"><span class="keyword control import python">import</span></span></span></span><span class="meta statement import python"></span><span class="meta statement import python"> <span class="meta generic-name python">json_normalize</span></span>
<span class="meta statement import python"><span class="keyword control import from python">from</span></span><span class="meta statement import python"><span class="meta import-source python"> <span class="meta import-path python"><span class="meta import-name python">sklearn</span><span class="punctuation accessor dot python">.</span><span class="meta import-name python">cluster</span></span> <span class="meta statement import python"><span class="keyword control import python">import</span></span></span></span><span class="meta statement import python"></span><span class="meta statement import python"> <span class="meta generic-name python">KMeans</span></span></span></code></pre>
<p>To begin our analysis, we need to import the data for this project. The data we are using in this project comes directly from the Foursquare application programming interface (API). The first step is to get the latitude and longitude of the city being studied (Lincoln, NE) and setting up the folium map.</p>
<pre><code class="language-python highlight"><span class="source python"><span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Define the latitude and longitude, then map the results
</span><span class="meta qualified-name python"><span class="meta generic-name python">latitude</span></span> <span class="keyword operator assignment python">=</span> <span class="constant numeric float python">40<span class="punctuation separator decimal python">.</span>806862</span>
<span class="meta qualified-name python"><span class="meta generic-name python">longitude</span></span> <span class="keyword operator assignment python">=</span> <span class="keyword operator arithmetic python">-</span><span class="constant numeric float python">96<span class="punctuation separator decimal python">.</span>681679</span>
<span class="meta qualified-name python"><span class="meta generic-name python">map_LNK</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">folium</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">Map</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="variable parameter python">location</span><span class="keyword operator assignment python">=</span><span class="meta structure list python"><span class="punctuation section list begin python">[</span><span class="meta qualified-name python"><span class="meta generic-name python">latitude</span></span><span class="punctuation separator list python">,</span> <span class="meta qualified-name python"><span class="meta generic-name python">longitude</span></span><span class="punctuation section list end python">]</span></span><span class="punctuation separator arguments python">,</span> <span class="variable parameter python">zoom_start</span><span class="keyword operator assignment python">=</span><span class="constant numeric integer decimal python">12</span></span><span class="punctuation section arguments end python">)</span></span>

<span class="meta qualified-name python"><span class="meta generic-name python">map_LNK</span></span></span></code></pre>
<p>Now that we have defined our city and created the map, we need to go get the business data. The Foursquare API will limit the results to 100 per API call, so we use our first API call below to determine the total results that Foursquare has found. Since the total results are 232, we perform the API fetching process three times (100 + 100 + 32 = 232).</p>
<pre><code class="language-python highlight"><span class="source python"><span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Foursquare API credentials
</span><span class="meta qualified-name python"><span class="variable other constant python">CLIENT_ID</span></span> <span class="keyword operator assignment python">=</span> <span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">your-client-id<span class="punctuation definition string end python">&#39;</span></span></span>
<span class="meta qualified-name python"><span class="variable other constant python">CLIENT_SECRET</span></span> <span class="keyword operator assignment python">=</span> <span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">your-client-secret<span class="punctuation definition string end python">&#39;</span></span></span>
<span class="meta qualified-name python"><span class="variable other constant python">VERSION</span></span> <span class="keyword operator assignment python">=</span> <span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">20180604<span class="punctuation definition string end python">&#39;</span></span></span>

<span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Set up the URL to fetch the first 100 results
</span><span class="meta qualified-name python"><span class="variable other constant python">LIMIT</span></span> <span class="keyword operator assignment python">=</span> <span class="constant numeric integer decimal python">100</span>
<span class="meta qualified-name python"><span class="meta generic-name python">radius</span></span> <span class="keyword operator assignment python">=</span> <span class="constant numeric integer decimal python">10000</span>
<span class="meta qualified-name python"><span class="meta generic-name python">url</span></span> <span class="keyword operator assignment python">=</span> <span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">https://api.foursquare.com/v2/venues/explore?&amp;client_id=<span class="constant other placeholder python"><span class="punctuation definition placeholder begin python">{</span><span class="punctuation definition placeholder end python">}</span></span>&amp;client_secret=<span class="constant other placeholder python"><span class="punctuation definition placeholder begin python">{</span><span class="punctuation definition placeholder end python">}</span></span>&amp;v=<span class="constant other placeholder python"><span class="punctuation definition placeholder begin python">{</span><span class="punctuation definition placeholder end python">}</span></span>&amp;ll=<span class="constant other placeholder python"><span class="punctuation definition placeholder begin python">{</span><span class="punctuation definition placeholder end python">}</span></span>,<span class="constant other placeholder python"><span class="punctuation definition placeholder begin python">{</span><span class="punctuation definition placeholder end python">}</span></span>&amp;radius=<span class="constant other placeholder python"><span class="punctuation definition placeholder begin python">{</span><span class="punctuation definition placeholder end python">}</span></span>&amp;limit=<span class="constant other placeholder python"><span class="punctuation definition placeholder begin python">{</span><span class="punctuation definition placeholder end python">}</span></span><span class="punctuation definition string end python">&#39;</span></span></span><span class="meta function-call python"><span class="meta qualified-name python"><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">format</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python">
    <span class="meta qualified-name python"><span class="variable other constant python">CLIENT_ID</span></span><span class="punctuation separator arguments python">,</span>
    <span class="meta qualified-name python"><span class="variable other constant python">CLIENT_SECRET</span></span><span class="punctuation separator arguments python">,</span>
    <span class="meta qualified-name python"><span class="variable other constant python">VERSION</span></span><span class="punctuation separator arguments python">,</span>
    <span class="meta qualified-name python"><span class="meta generic-name python">latitude</span></span><span class="punctuation separator arguments python">,</span>
    <span class="meta qualified-name python"><span class="meta generic-name python">longitude</span></span><span class="punctuation separator arguments python">,</span>
    <span class="meta qualified-name python"><span class="meta generic-name python">radius</span></span><span class="punctuation separator arguments python">,</span>
    <span class="meta qualified-name python"><span class="variable other constant python">LIMIT</span></span></span><span class="punctuation section arguments end python">)</span></span>

<span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Fetch the first 100 results
</span><span class="meta qualified-name python"><span class="meta generic-name python">results</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">requests</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">get</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">url</span></span></span><span class="punctuation section arguments end python">)</span></span><span class="meta function-call python"><span class="meta qualified-name python"><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">json</span></span><span class="punctuation section arguments begin python">(</span><span class="punctuation section arguments end python">)</span></span>

<span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Determine the total number of results needed to fetch
</span><span class="meta qualified-name python"><span class="meta generic-name python">totalResults</span></span> <span class="keyword operator assignment python">=</span> <span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">results</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">response<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">totalResults<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span>
<span class="meta qualified-name python"><span class="meta generic-name python">totalResults</span></span>

<span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Set up the URL to fetch the second 100 results (101-200)
</span><span class="meta qualified-name python"><span class="variable other constant python">LIMIT</span></span> <span class="keyword operator assignment python">=</span> <span class="constant numeric integer decimal python">100</span>
<span class="meta qualified-name python"><span class="meta generic-name python">offset</span></span> <span class="keyword operator assignment python">=</span> <span class="constant numeric integer decimal python">100</span>
<span class="meta qualified-name python"><span class="meta generic-name python">radius</span></span> <span class="keyword operator assignment python">=</span> <span class="constant numeric integer decimal python">10000</span>
<span class="meta qualified-name python"><span class="meta generic-name python">url2</span></span> <span class="keyword operator assignment python">=</span> <span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">https://api.foursquare.com/v2/venues/explore?&amp;client_id=<span class="constant other placeholder python"><span class="punctuation definition placeholder begin python">{</span><span class="punctuation definition placeholder end python">}</span></span>&amp;client_secret=<span class="constant other placeholder python"><span class="punctuation definition placeholder begin python">{</span><span class="punctuation definition placeholder end python">}</span></span>&amp;v=<span class="constant other placeholder python"><span class="punctuation definition placeholder begin python">{</span><span class="punctuation definition placeholder end python">}</span></span>&amp;ll=<span class="constant other placeholder python"><span class="punctuation definition placeholder begin python">{</span><span class="punctuation definition placeholder end python">}</span></span>,<span class="constant other placeholder python"><span class="punctuation definition placeholder begin python">{</span><span class="punctuation definition placeholder end python">}</span></span>&amp;radius=<span class="constant other placeholder python"><span class="punctuation definition placeholder begin python">{</span><span class="punctuation definition placeholder end python">}</span></span>&amp;limit=<span class="constant other placeholder python"><span class="punctuation definition placeholder begin python">{</span><span class="punctuation definition placeholder end python">}</span></span>&amp;offset=<span class="constant other placeholder python"><span class="punctuation definition placeholder begin python">{</span><span class="punctuation definition placeholder end python">}</span></span><span class="punctuation definition string end python">&#39;</span></span></span><span class="meta function-call python"><span class="meta qualified-name python"><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">format</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python">
    <span class="meta qualified-name python"><span class="variable other constant python">CLIENT_ID</span></span><span class="punctuation separator arguments python">,</span>
    <span class="meta qualified-name python"><span class="variable other constant python">CLIENT_SECRET</span></span><span class="punctuation separator arguments python">,</span>
    <span class="meta qualified-name python"><span class="variable other constant python">VERSION</span></span><span class="punctuation separator arguments python">,</span>
    <span class="meta qualified-name python"><span class="meta generic-name python">latitude</span></span><span class="punctuation separator arguments python">,</span>
    <span class="meta qualified-name python"><span class="meta generic-name python">longitude</span></span><span class="punctuation separator arguments python">,</span>
    <span class="meta qualified-name python"><span class="meta generic-name python">radius</span></span><span class="punctuation separator arguments python">,</span>
    <span class="meta qualified-name python"><span class="variable other constant python">LIMIT</span></span><span class="punctuation separator arguments python">,</span>
    <span class="meta qualified-name python"><span class="meta generic-name python">offset</span></span></span><span class="punctuation section arguments end python">)</span></span>

<span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Fetch the second 100 results (101-200)
</span><span class="meta qualified-name python"><span class="meta generic-name python">results2</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">requests</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">get</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">url2</span></span></span><span class="punctuation section arguments end python">)</span></span><span class="meta function-call python"><span class="meta qualified-name python"><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">json</span></span><span class="punctuation section arguments begin python">(</span><span class="punctuation section arguments end python">)</span></span>

<span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Set up the URL to fetch the final results (201 - 232)
</span><span class="meta qualified-name python"><span class="variable other constant python">LIMIT</span></span> <span class="keyword operator assignment python">=</span> <span class="constant numeric integer decimal python">100</span>
<span class="meta qualified-name python"><span class="meta generic-name python">offset</span></span> <span class="keyword operator assignment python">=</span> <span class="constant numeric integer decimal python">200</span>
<span class="meta qualified-name python"><span class="meta generic-name python">radius</span></span> <span class="keyword operator assignment python">=</span> <span class="constant numeric integer decimal python">10000</span>
<span class="meta qualified-name python"><span class="meta generic-name python">url3</span></span> <span class="keyword operator assignment python">=</span> <span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">https://api.foursquare.com/v2/venues/explore?&amp;client_id=<span class="constant other placeholder python"><span class="punctuation definition placeholder begin python">{</span><span class="punctuation definition placeholder end python">}</span></span>&amp;client_secret=<span class="constant other placeholder python"><span class="punctuation definition placeholder begin python">{</span><span class="punctuation definition placeholder end python">}</span></span>&amp;v=<span class="constant other placeholder python"><span class="punctuation definition placeholder begin python">{</span><span class="punctuation definition placeholder end python">}</span></span>&amp;ll=<span class="constant other placeholder python"><span class="punctuation definition placeholder begin python">{</span><span class="punctuation definition placeholder end python">}</span></span>,<span class="constant other placeholder python"><span class="punctuation definition placeholder begin python">{</span><span class="punctuation definition placeholder end python">}</span></span>&amp;radius=<span class="constant other placeholder python"><span class="punctuation definition placeholder begin python">{</span><span class="punctuation definition placeholder end python">}</span></span>&amp;limit=<span class="constant other placeholder python"><span class="punctuation definition placeholder begin python">{</span><span class="punctuation definition placeholder end python">}</span></span>&amp;offset=<span class="constant other placeholder python"><span class="punctuation definition placeholder begin python">{</span><span class="punctuation definition placeholder end python">}</span></span><span class="punctuation definition string end python">&#39;</span></span></span><span class="meta function-call python"><span class="meta qualified-name python"><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">format</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python">
    <span class="meta qualified-name python"><span class="variable other constant python">CLIENT_ID</span></span><span class="punctuation separator arguments python">,</span>
    <span class="meta qualified-name python"><span class="variable other constant python">CLIENT_SECRET</span></span><span class="punctuation separator arguments python">,</span>
    <span class="meta qualified-name python"><span class="variable other constant python">VERSION</span></span><span class="punctuation separator arguments python">,</span>
    <span class="meta qualified-name python"><span class="meta generic-name python">latitude</span></span><span class="punctuation separator arguments python">,</span>
    <span class="meta qualified-name python"><span class="meta generic-name python">longitude</span></span><span class="punctuation separator arguments python">,</span>
    <span class="meta qualified-name python"><span class="meta generic-name python">radius</span></span><span class="punctuation separator arguments python">,</span>
    <span class="meta qualified-name python"><span class="variable other constant python">LIMIT</span></span><span class="punctuation separator arguments python">,</span>
    <span class="meta qualified-name python"><span class="meta generic-name python">offset</span></span></span><span class="punctuation section arguments end python">)</span></span>

<span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Fetch the final results (201 - 232)
</span><span class="meta qualified-name python"><span class="meta generic-name python">results3</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">requests</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">get</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">url3</span></span></span><span class="punctuation section arguments end python">)</span></span><span class="meta function-call python"><span class="meta qualified-name python"><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">json</span></span><span class="punctuation section arguments begin python">(</span><span class="punctuation section arguments end python">)</span></span></span></code></pre>
<h2 id="clean-the-data"><span class="section-number-2">3.</span> Clean the Data</h2>
<p>Now that we have our data in three separate dataframes, we need to combine them into a single dataframe and make sure to reset the index so that we have a unique ID for each business. The <code class="verbatim">get_category_type</code> function below will pull the categories and name from each business's entry in the Foursquare data automatically. Once all the data has been labeled and combined, the results are stored in the <code class="verbatim">nearby_venues</code> dataframe.</p>
<pre><code class="language-python highlight"><span class="source python"><span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> This function will extract the category of the venue from the API dictionary
</span><span class="meta function python"><span class="storage type function python">def</span> <span class="entity name function python"><span class="meta generic-name python">get_category_type</span></span></span><span class="meta function parameters python"><span class="punctuation section parameters begin python">(</span></span><span class="meta function parameters python"><span class="variable parameter python">row</span><span class="punctuation section parameters end python">)</span></span><span class="meta function python"><span class="punctuation section function begin python">:</span></span>
    <span class="meta statement try python"><span class="keyword control flow try python">try</span><span class="punctuation section block try python">:</span></span>
        <span class="meta qualified-name python"><span class="meta generic-name python">categories_list</span></span> <span class="keyword operator assignment python">=</span> <span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">row</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">categories<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span>
    <span class="meta statement except python"><span class="keyword control flow except python">except</span><span class="punctuation section block except python">:</span></span>
        <span class="meta qualified-name python"><span class="meta generic-name python">categories_list</span></span> <span class="keyword operator assignment python">=</span> <span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">row</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">venue.categories<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span>

    <span class="meta statement if python"><span class="keyword control flow conditional python">if</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="support function builtin python">len</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">categories_list</span></span></span><span class="punctuation section arguments end python">)</span></span> <span class="keyword operator comparison python">==</span> <span class="constant numeric integer decimal python">0</span><span class="punctuation section block conditional python">:</span></span>
        <span class="keyword control flow return python">return</span> <span class="constant language python">None</span>
    <span class="meta statement conditional python"><span class="keyword control flow conditional python">else</span><span class="punctuation section block python">:</span></span>
        <span class="keyword control flow return python">return</span> <span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">categories_list</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="constant numeric integer decimal python">0</span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">name<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span>

<span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Get the first 100 venues
</span><span class="meta qualified-name python"><span class="meta generic-name python">venues</span></span> <span class="keyword operator assignment python">=</span> <span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">results</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">response<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">groups<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="constant numeric integer decimal python">0</span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">items<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span>
<span class="meta qualified-name python"><span class="meta generic-name python">nearby_venues</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="variable function python">json_normalize</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">venues</span></span></span><span class="punctuation section arguments end python">)</span></span>

<span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> filter columns
</span><span class="meta qualified-name python"><span class="meta generic-name python">filtered_columns</span></span> <span class="keyword operator assignment python">=</span> <span class="meta structure list python"><span class="punctuation section list begin python">[</span><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">venue.name<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation separator list python">,</span> <span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">venue.categories<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation separator list python">,</span> <span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">venue.location.lat<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation separator list python">,</span> <span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">venue.location.lng<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation section list end python">]</span></span>
<span class="meta qualified-name python"><span class="meta generic-name python">nearby_venues</span></span> <span class="keyword operator assignment python">=</span> <span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">nearby_venues</span><span class="punctuation accessor dot python">.</span><span class="meta generic-name python">loc</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="punctuation separator slice python">:</span>, <span class="meta qualified-name python"><span class="meta generic-name python">filtered_columns</span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span>

<span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> filter the category for each row
</span><span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">nearby_venues</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">venue.categories<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">nearby_venues</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">apply</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">get_category_type</span></span><span class="punctuation separator arguments python">,</span> <span class="variable parameter python">axis</span><span class="keyword operator assignment python">=</span><span class="constant numeric integer decimal python">1</span></span><span class="punctuation section arguments end python">)</span></span>

<span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> clean columns
</span><span class="meta qualified-name python"><span class="meta generic-name python">nearby_venues</span><span class="punctuation accessor dot python">.</span><span class="meta generic-name python">columns</span></span> <span class="keyword operator assignment python">=</span> <span class="meta structure list python"><span class="punctuation section list begin python">[</span><span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">col</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">split</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">.<span class="punctuation definition string end python">&quot;</span></span></span></span><span class="punctuation section arguments end python">)</span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="keyword operator arithmetic python">-</span><span class="constant numeric integer decimal python">1</span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span> <span class="meta expression generator python"><span class="keyword control flow for generator python">for</span> <span class="meta generic-name python">col</span> <span class="keyword control flow for in python">in</span></span> <span class="meta qualified-name python"><span class="meta generic-name python">nearby_venues</span><span class="punctuation accessor dot python">.</span><span class="meta generic-name python">columns</span></span><span class="punctuation section list end python">]</span></span>

<span class="keyword operator arithmetic python">-</span><span class="keyword operator arithmetic python">-</span><span class="keyword operator arithmetic python">-</span>

<span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Get the second 100 venues
</span><span class="meta qualified-name python"><span class="meta generic-name python">venues2</span></span> <span class="keyword operator assignment python">=</span> <span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">results2</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">response<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">groups<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="constant numeric integer decimal python">0</span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">items<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span>
<span class="meta qualified-name python"><span class="meta generic-name python">nearby_venues2</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="variable function python">json_normalize</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">venues2</span></span></span><span class="punctuation section arguments end python">)</span></span> <span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> flatten JSON
</span>
<span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> filter columns
</span><span class="meta qualified-name python"><span class="meta generic-name python">filtered_columns2</span></span> <span class="keyword operator assignment python">=</span> <span class="meta structure list python"><span class="punctuation section list begin python">[</span><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">venue.name<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation separator list python">,</span> <span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">venue.categories<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation separator list python">,</span> <span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">venue.location.lat<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation separator list python">,</span> <span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">venue.location.lng<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation section list end python">]</span></span>
<span class="meta qualified-name python"><span class="meta generic-name python">nearby_venues2</span></span> <span class="keyword operator assignment python">=</span> <span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">nearby_venues2</span><span class="punctuation accessor dot python">.</span><span class="meta generic-name python">loc</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="punctuation separator slice python">:</span>, <span class="meta qualified-name python"><span class="meta generic-name python">filtered_columns</span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span>

<span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> filter the category for each row
</span><span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">nearby_venues2</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">venue.categories<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">nearby_venues2</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">apply</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">get_category_type</span></span><span class="punctuation separator arguments python">,</span> <span class="variable parameter python">axis</span><span class="keyword operator assignment python">=</span><span class="constant numeric integer decimal python">1</span></span><span class="punctuation section arguments end python">)</span></span>

<span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> clean columns
</span><span class="meta qualified-name python"><span class="meta generic-name python">nearby_venues2</span><span class="punctuation accessor dot python">.</span><span class="meta generic-name python">columns</span></span> <span class="keyword operator assignment python">=</span> <span class="meta structure list python"><span class="punctuation section list begin python">[</span><span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">col</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">split</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">.<span class="punctuation definition string end python">&quot;</span></span></span></span><span class="punctuation section arguments end python">)</span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="keyword operator arithmetic python">-</span><span class="constant numeric integer decimal python">1</span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span> <span class="meta expression generator python"><span class="keyword control flow for generator python">for</span> <span class="meta generic-name python">col</span> <span class="keyword control flow for in python">in</span></span> <span class="meta qualified-name python"><span class="meta generic-name python">nearby_venues</span><span class="punctuation accessor dot python">.</span><span class="meta generic-name python">columns</span></span><span class="punctuation section list end python">]</span></span>
<span class="meta qualified-name python"><span class="meta generic-name python">nearby_venues</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">nearby_venues</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">append</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">nearby_venues2</span></span></span><span class="punctuation section arguments end python">)</span></span>

<span class="keyword operator arithmetic python">-</span><span class="keyword operator arithmetic python">-</span><span class="keyword operator arithmetic python">-</span>

<span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Get the rest of the venues
</span><span class="meta qualified-name python"><span class="meta generic-name python">venues3</span></span> <span class="keyword operator assignment python">=</span> <span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">results3</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">response<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">groups<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="constant numeric integer decimal python">0</span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">items<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span>
<span class="meta qualified-name python"><span class="meta generic-name python">nearby_venues3</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="variable function python">json_normalize</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">venues3</span></span></span><span class="punctuation section arguments end python">)</span></span> <span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> flatten JSON
</span>
<span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> filter columns
</span><span class="meta qualified-name python"><span class="meta generic-name python">filtered_columns3</span></span> <span class="keyword operator assignment python">=</span> <span class="meta structure list python"><span class="punctuation section list begin python">[</span><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">venue.name<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation separator list python">,</span> <span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">venue.categories<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation separator list python">,</span> <span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">venue.location.lat<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation separator list python">,</span> <span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">venue.location.lng<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation section list end python">]</span></span>
<span class="meta qualified-name python"><span class="meta generic-name python">nearby_venues3</span></span> <span class="keyword operator assignment python">=</span> <span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">nearby_venues3</span><span class="punctuation accessor dot python">.</span><span class="meta generic-name python">loc</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="punctuation separator slice python">:</span>, <span class="meta qualified-name python"><span class="meta generic-name python">filtered_columns</span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span>

<span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> filter the category for each row
</span><span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">nearby_venues3</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">venue.categories<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">nearby_venues3</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">apply</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">get_category_type</span></span><span class="punctuation separator arguments python">,</span> <span class="variable parameter python">axis</span><span class="keyword operator assignment python">=</span><span class="constant numeric integer decimal python">1</span></span><span class="punctuation section arguments end python">)</span></span>

<span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> clean columns
</span><span class="meta qualified-name python"><span class="meta generic-name python">nearby_venues3</span><span class="punctuation accessor dot python">.</span><span class="meta generic-name python">columns</span></span> <span class="keyword operator assignment python">=</span> <span class="meta structure list python"><span class="punctuation section list begin python">[</span><span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">col</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">split</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">.<span class="punctuation definition string end python">&quot;</span></span></span></span><span class="punctuation section arguments end python">)</span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="keyword operator arithmetic python">-</span><span class="constant numeric integer decimal python">1</span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span> <span class="meta expression generator python"><span class="keyword control flow for generator python">for</span> <span class="meta generic-name python">col</span> <span class="keyword control flow for in python">in</span></span> <span class="meta qualified-name python"><span class="meta generic-name python">nearby_venues3</span><span class="punctuation accessor dot python">.</span><span class="meta generic-name python">columns</span></span><span class="punctuation section list end python">]</span></span>

<span class="meta qualified-name python"><span class="meta generic-name python">nearby_venues</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">nearby_venues</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">append</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">nearby_venues3</span></span></span><span class="punctuation section arguments end python">)</span></span>
<span class="meta qualified-name python"><span class="meta generic-name python">nearby_venues</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">nearby_venues</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">reset_index</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="variable parameter python">drop</span><span class="keyword operator assignment python">=</span><span class="constant language python">True</span></span><span class="punctuation section arguments end python">)</span></span>
<span class="meta qualified-name python"><span class="meta generic-name python">nearby_venues</span></span></span></code></pre>
<h2 id="visualize-the-data"><span class="section-number-2">4.</span> Visualize the Data</h2>
<p>We now have a complete, clean data set. The next step is to visualize this data onto the map we created earlier. We will be using folium's <code class="verbatim">CircleMarker()</code> function to do this.</p>
<pre><code class="language-python highlight"><span class="source python"><span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> add markers to map
</span><span class="meta statement for python"><span class="keyword control flow for python">for</span> <span class="meta generic-name python">lat</span><span class="punctuation separator target-list python">,</span> <span class="meta generic-name python">lng</span><span class="punctuation separator target-list python">,</span> <span class="meta generic-name python">name</span><span class="punctuation separator target-list python">,</span> <span class="meta generic-name python">categories</span> <span class="meta statement for python"><span class="keyword control flow for in python">in</span></span></span><span class="meta statement for python"> <span class="meta function-call python"><span class="meta qualified-name python"><span class="support function builtin python">zip</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">nearby_venues</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">lat<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span><span class="punctuation separator arguments python">,</span> <span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">nearby_venues</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">lng<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span><span class="punctuation separator arguments python">,</span> <span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">nearby_venues</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">name<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span><span class="punctuation separator arguments python">,</span> <span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">nearby_venues</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">categories<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span></span><span class="punctuation section arguments end python">)</span></span><span class="punctuation section block for python">:</span></span>
    <span class="meta qualified-name python"><span class="meta generic-name python">label</span></span> <span class="keyword operator assignment python">=</span> <span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python"><span class="constant other placeholder python"><span class="punctuation definition placeholder begin python">{</span><span class="punctuation definition placeholder end python">}</span></span> (<span class="constant other placeholder python"><span class="punctuation definition placeholder begin python">{</span><span class="punctuation definition placeholder end python">}</span></span>)<span class="punctuation definition string end python">&#39;</span></span></span><span class="meta function-call python"><span class="meta qualified-name python"><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">format</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">name</span></span><span class="punctuation separator arguments python">,</span> <span class="meta qualified-name python"><span class="meta generic-name python">categories</span></span></span><span class="punctuation section arguments end python">)</span></span>
    <span class="meta qualified-name python"><span class="meta generic-name python">label</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">folium</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">Popup</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">label</span></span><span class="punctuation separator arguments python">,</span> <span class="variable parameter python">parse_html</span><span class="keyword operator assignment python">=</span><span class="constant language python">True</span></span><span class="punctuation section arguments end python">)</span></span>
    <span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">folium</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">CircleMarker</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python">
        <span class="meta structure list python"><span class="punctuation section list begin python">[</span><span class="meta qualified-name python"><span class="meta generic-name python">lat</span></span><span class="punctuation separator list python">,</span> <span class="meta qualified-name python"><span class="meta generic-name python">lng</span></span><span class="punctuation section list end python">]</span></span><span class="punctuation separator arguments python">,</span>
        <span class="variable parameter python">radius</span><span class="keyword operator assignment python">=</span><span class="constant numeric integer decimal python">5</span><span class="punctuation separator arguments python">,</span>
        <span class="variable parameter python">popup</span><span class="keyword operator assignment python">=</span><span class="meta qualified-name python"><span class="meta generic-name python">label</span></span><span class="punctuation separator arguments python">,</span>
        <span class="variable parameter python">color</span><span class="keyword operator assignment python">=</span><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">blue<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation separator arguments python">,</span>
        <span class="variable parameter python">fill</span><span class="keyword operator assignment python">=</span><span class="constant language python">True</span><span class="punctuation separator arguments python">,</span>
        <span class="variable parameter python">fill_color</span><span class="keyword operator assignment python">=</span><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">#3186cc<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation separator arguments python">,</span>
        <span class="variable parameter python">fill_opacity</span><span class="keyword operator assignment python">=</span><span class="constant numeric float python">0<span class="punctuation separator decimal python">.</span>7</span><span class="punctuation separator arguments python">,</span>
        </span><span class="punctuation section arguments end python">)</span></span><span class="meta function-call python"><span class="meta qualified-name python"><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">add_to</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">map_LNK</span></span></span><span class="punctuation section arguments end python">)</span></span>

<span class="meta qualified-name python"><span class="meta generic-name python">map_LNK</span></span></span></code></pre>
<h2 id="clustering-k-means"><span class="section-number-2">5.</span> Clustering: <em>k-means</em></h2>
<p>To cluster the data, we will be using the <em>k-means</em> algorithm. This algorithm is iterative and will automatically make sure that data points in each cluster are as close as possible to each other, while being as far as possible away from other clusters.</p>
<p>However, we first have to figure out how many clusters to use (defined as the variable 'k'). To do so, we will use the next two functions to calculate the sum of squares within clusters and then return the optimal number of clusters.</p>
<pre><code class="language-python highlight"><span class="source python"><span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> This function will return the sum of squares found in the data
</span><span class="meta function python"><span class="storage type function python">def</span> <span class="entity name function python"><span class="meta generic-name python">calculate_wcss</span></span></span><span class="meta function parameters python"><span class="punctuation section parameters begin python">(</span></span><span class="meta function parameters python"><span class="variable parameter python">data</span><span class="punctuation section parameters end python">)</span></span><span class="meta function python"><span class="punctuation section function begin python">:</span></span>
    <span class="meta qualified-name python"><span class="meta generic-name python">wcss</span></span> <span class="keyword operator assignment python">=</span> <span class="meta structure list python"><span class="punctuation section list begin python">[</span><span class="punctuation section list end python">]</span></span>
    <span class="meta statement for python"><span class="keyword control flow for python">for</span> <span class="meta generic-name python">n</span> <span class="meta statement for python"><span class="keyword control flow for in python">in</span></span></span><span class="meta statement for python"> <span class="meta function-call python"><span class="meta qualified-name python"><span class="support function builtin python">range</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="constant numeric integer decimal python">2</span><span class="punctuation separator arguments python">,</span> <span class="constant numeric integer decimal python">21</span></span><span class="punctuation section arguments end python">)</span></span><span class="punctuation section block for python">:</span></span>
        <span class="meta qualified-name python"><span class="meta generic-name python">kmeans</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="variable function python">KMeans</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="variable parameter python">n_clusters</span><span class="keyword operator assignment python">=</span><span class="meta qualified-name python"><span class="meta generic-name python">n</span></span></span><span class="punctuation section arguments end python">)</span></span>
        <span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">kmeans</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">fit</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="variable parameter python">X</span><span class="keyword operator assignment python">=</span><span class="meta qualified-name python"><span class="meta generic-name python">data</span></span></span><span class="punctuation section arguments end python">)</span></span>
        <span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">wcss</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">append</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">kmeans</span><span class="punctuation accessor dot python">.</span><span class="meta generic-name python">inertia_</span></span></span><span class="punctuation section arguments end python">)</span></span>

    <span class="keyword control flow return python">return</span> <span class="meta qualified-name python"><span class="meta generic-name python">wcss</span></span>

<span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Drop &#39;str&#39; cols so we can use k-means clustering
</span><span class="meta qualified-name python"><span class="meta generic-name python">cluster_df</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">nearby_venues</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">drop</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="variable parameter python">columns</span><span class="keyword operator assignment python">=</span><span class="meta structure list python"><span class="punctuation section list begin python">[</span><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">name<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation separator list python">,</span> <span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">categories<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation section list end python">]</span></span></span><span class="punctuation section arguments end python">)</span></span>

<span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> calculating the within clusters sum-of-squares for 19 cluster amounts
</span><span class="meta qualified-name python"><span class="meta generic-name python">sum_of_squares</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="variable function python">calculate_wcss</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">cluster_df</span></span></span><span class="punctuation section arguments end python">)</span></span>

<span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> This function will return the optimal number of clusters
</span><span class="meta function python"><span class="storage type function python">def</span> <span class="entity name function python"><span class="meta generic-name python">optimal_number_of_clusters</span></span></span><span class="meta function parameters python"><span class="punctuation section parameters begin python">(</span></span><span class="meta function parameters python"><span class="variable parameter python">wcss</span><span class="punctuation section parameters end python">)</span></span><span class="meta function python"><span class="punctuation section function begin python">:</span></span>
    <span class="meta qualified-name python"><span class="meta generic-name python">x1</span></span>, <span class="meta qualified-name python"><span class="meta generic-name python">y1</span></span> <span class="keyword operator assignment python">=</span> <span class="constant numeric integer decimal python">2</span>, <span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">wcss</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="constant numeric integer decimal python">0</span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span>
    <span class="meta qualified-name python"><span class="meta generic-name python">x2</span></span>, <span class="meta qualified-name python"><span class="meta generic-name python">y2</span></span> <span class="keyword operator assignment python">=</span> <span class="constant numeric integer decimal python">20</span>, <span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">wcss</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta function-call python"><span class="meta qualified-name python"><span class="support function builtin python">len</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">wcss</span></span></span><span class="punctuation section arguments end python">)</span></span><span class="keyword operator arithmetic python">-</span><span class="constant numeric integer decimal python">1</span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span>

    <span class="meta qualified-name python"><span class="meta generic-name python">distances</span></span> <span class="keyword operator assignment python">=</span> <span class="meta structure list python"><span class="punctuation section list begin python">[</span><span class="punctuation section list end python">]</span></span>
    <span class="meta statement for python"><span class="keyword control flow for python">for</span> <span class="meta generic-name python">i</span> <span class="meta statement for python"><span class="keyword control flow for in python">in</span></span></span><span class="meta statement for python"> <span class="meta function-call python"><span class="meta qualified-name python"><span class="support function builtin python">range</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta function-call python"><span class="meta qualified-name python"><span class="support function builtin python">len</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">wcss</span></span></span><span class="punctuation section arguments end python">)</span></span></span><span class="punctuation section arguments end python">)</span></span><span class="punctuation section block for python">:</span></span>
        <span class="meta qualified-name python"><span class="meta generic-name python">x0</span></span> <span class="keyword operator assignment python">=</span> <span class="meta qualified-name python"><span class="meta generic-name python">i</span></span><span class="keyword operator arithmetic python">+</span><span class="constant numeric integer decimal python">2</span>
        <span class="meta qualified-name python"><span class="meta generic-name python">y0</span></span> <span class="keyword operator assignment python">=</span> <span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">wcss</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">i</span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span>
        <span class="meta qualified-name python"><span class="meta generic-name python">numerator</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="support function builtin python">abs</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta group python"><span class="punctuation section group begin python">(</span><span class="meta qualified-name python"><span class="meta generic-name python">y2</span></span><span class="keyword operator arithmetic python">-</span><span class="meta qualified-name python"><span class="meta generic-name python">y1</span></span><span class="punctuation section group end python">)</span></span><span class="keyword operator arithmetic python">*</span><span class="meta qualified-name python"><span class="meta generic-name python">x0</span></span> <span class="keyword operator arithmetic python">-</span> <span class="meta group python"><span class="punctuation section group begin python">(</span><span class="meta qualified-name python"><span class="meta generic-name python">x2</span></span><span class="keyword operator arithmetic python">-</span><span class="meta qualified-name python"><span class="meta generic-name python">x1</span></span><span class="punctuation section group end python">)</span></span><span class="keyword operator arithmetic python">*</span><span class="meta qualified-name python"><span class="meta generic-name python">y0</span></span> <span class="keyword operator arithmetic python">+</span> <span class="meta qualified-name python"><span class="meta generic-name python">x2</span></span><span class="keyword operator arithmetic python">*</span><span class="meta qualified-name python"><span class="meta generic-name python">y1</span></span> <span class="keyword operator arithmetic python">-</span> <span class="meta qualified-name python"><span class="meta generic-name python">y2</span></span><span class="keyword operator arithmetic python">*</span><span class="meta qualified-name python"><span class="meta generic-name python">x1</span></span></span><span class="punctuation section arguments end python">)</span></span>
        <span class="meta qualified-name python"><span class="meta generic-name python">denominator</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">math</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">sqrt</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta group python"><span class="punctuation section group begin python">(</span><span class="meta qualified-name python"><span class="meta generic-name python">y2</span></span> <span class="keyword operator arithmetic python">-</span> <span class="meta qualified-name python"><span class="meta generic-name python">y1</span></span><span class="punctuation section group end python">)</span></span><span class="keyword operator arithmetic python">*</span><span class="keyword operator arithmetic python">*</span><span class="constant numeric integer decimal python">2</span> <span class="keyword operator arithmetic python">+</span> <span class="meta group python"><span class="punctuation section group begin python">(</span><span class="meta qualified-name python"><span class="meta generic-name python">x2</span></span> <span class="keyword operator arithmetic python">-</span> <span class="meta qualified-name python"><span class="meta generic-name python">x1</span></span><span class="punctuation section group end python">)</span></span><span class="keyword operator arithmetic python">*</span><span class="keyword operator arithmetic python">*</span><span class="constant numeric integer decimal python">2</span></span><span class="punctuation section arguments end python">)</span></span>
        <span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">distances</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">append</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">numerator</span></span><span class="keyword operator arithmetic python">/</span><span class="meta qualified-name python"><span class="meta generic-name python">denominator</span></span></span><span class="punctuation section arguments end python">)</span></span>

    <span class="keyword control flow return python">return</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">distances</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">index</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta function-call python"><span class="meta qualified-name python"><span class="support function builtin python">max</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">distances</span></span></span><span class="punctuation section arguments end python">)</span></span></span><span class="punctuation section arguments end python">)</span></span> <span class="keyword operator arithmetic python">+</span> <span class="constant numeric integer decimal python">2</span>

<span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> calculating the optimal number of clusters
</span><span class="meta qualified-name python"><span class="meta generic-name python">n</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="variable function python">optimal_number_of_clusters</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">sum_of_squares</span></span></span><span class="punctuation section arguments end python">)</span></span></span></code></pre>
<p>Now that we have found that our optimal number of clusters is six, we need to perform k-means clustering. When this clustering occurs, each business is assigned a cluster number from 0 to 5 in the dataframe.</p>
<pre><code class="language-python highlight"><span class="source python"><span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> set number of clusters equal to the optimal number
</span><span class="meta qualified-name python"><span class="meta generic-name python">kclusters</span></span> <span class="keyword operator assignment python">=</span> <span class="meta qualified-name python"><span class="meta generic-name python">n</span></span>

<span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> run k-means clustering
</span><span class="meta qualified-name python"><span class="meta generic-name python">kmeans</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="variable function python">KMeans</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="variable parameter python">n_clusters</span><span class="keyword operator assignment python">=</span><span class="meta qualified-name python"><span class="meta generic-name python">kclusters</span></span><span class="punctuation separator arguments python">,</span> <span class="variable parameter python">random_state</span><span class="keyword operator assignment python">=</span><span class="constant numeric integer decimal python">0</span></span><span class="punctuation section arguments end python">)</span></span><span class="meta function-call python"><span class="meta qualified-name python"><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">fit</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">cluster_df</span></span></span><span class="punctuation section arguments end python">)</span></span>

<span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> add clustering labels to dataframe
</span><span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">nearby_venues</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">insert</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="constant numeric integer decimal python">0</span><span class="punctuation separator arguments python">,</span> <span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">Cluster Labels<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation separator arguments python">,</span> <span class="meta qualified-name python"><span class="meta generic-name python">kmeans</span><span class="punctuation accessor dot python">.</span><span class="meta generic-name python">labels_</span></span></span><span class="punctuation section arguments end python">)</span></span></span></code></pre>
<p>Success! We now have a dataframe with clean business data, along with a cluster number for each business. Now let's map the data using six different colors.</p>
<pre><code class="language-python highlight"><span class="source python"><span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> create map with clusters
</span><span class="meta qualified-name python"><span class="meta generic-name python">map_clusters</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">folium</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">Map</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="variable parameter python">location</span><span class="keyword operator assignment python">=</span><span class="meta structure list python"><span class="punctuation section list begin python">[</span><span class="meta qualified-name python"><span class="meta generic-name python">latitude</span></span><span class="punctuation separator list python">,</span> <span class="meta qualified-name python"><span class="meta generic-name python">longitude</span></span><span class="punctuation section list end python">]</span></span><span class="punctuation separator arguments python">,</span> <span class="variable parameter python">zoom_start</span><span class="keyword operator assignment python">=</span><span class="constant numeric integer decimal python">12</span></span><span class="punctuation section arguments end python">)</span></span>
<span class="meta qualified-name python"><span class="meta generic-name python">colors</span></span> <span class="keyword operator assignment python">=</span> <span class="meta structure list python"><span class="punctuation section list begin python">[</span><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">#0F9D58<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation separator list python">,</span> <span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">#DB4437<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation separator list python">,</span> <span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">#4285F4<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation separator list python">,</span> <span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">#800080<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation separator list python">,</span> <span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">#ce12c0<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation separator list python">,</span> <span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">#171717<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation section list end python">]</span></span>

<span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> add markers to the map
</span><span class="meta statement for python"><span class="keyword control flow for python">for</span> <span class="meta generic-name python">lat</span><span class="punctuation separator target-list python">,</span> <span class="meta generic-name python">lng</span><span class="punctuation separator target-list python">,</span> <span class="meta generic-name python">name</span><span class="punctuation separator target-list python">,</span> <span class="meta generic-name python">categories</span><span class="punctuation separator target-list python">,</span> <span class="meta generic-name python">cluster</span> <span class="meta statement for python"><span class="keyword control flow for in python">in</span></span></span><span class="meta statement for python"> <span class="meta function-call python"><span class="meta qualified-name python"><span class="support function builtin python">zip</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">nearby_venues</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">lat<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span><span class="punctuation separator arguments python">,</span> <span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">nearby_venues</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">lng<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span><span class="punctuation separator arguments python">,</span> <span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">nearby_venues</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">name<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span><span class="punctuation separator arguments python">,</span> <span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">nearby_venues</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">categories<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span><span class="punctuation separator arguments python">,</span> <span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">nearby_venues</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">Cluster Labels<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span></span><span class="punctuation section arguments end python">)</span></span><span class="punctuation section block for python">:</span></span>
    <span class="meta qualified-name python"><span class="meta generic-name python">label</span></span> <span class="keyword operator assignment python">=</span> <span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">[<span class="constant other placeholder python"><span class="punctuation definition placeholder begin python">{</span><span class="punctuation definition placeholder end python">}</span></span>] <span class="constant other placeholder python"><span class="punctuation definition placeholder begin python">{</span><span class="punctuation definition placeholder end python">}</span></span> (<span class="constant other placeholder python"><span class="punctuation definition placeholder begin python">{</span><span class="punctuation definition placeholder end python">}</span></span>)<span class="punctuation definition string end python">&#39;</span></span></span><span class="meta function-call python"><span class="meta qualified-name python"><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">format</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">cluster</span></span><span class="punctuation separator arguments python">,</span> <span class="meta qualified-name python"><span class="meta generic-name python">name</span></span><span class="punctuation separator arguments python">,</span> <span class="meta qualified-name python"><span class="meta generic-name python">categories</span></span></span><span class="punctuation section arguments end python">)</span></span>
    <span class="meta qualified-name python"><span class="meta generic-name python">label</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">folium</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">Popup</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">label</span></span><span class="punctuation separator arguments python">,</span> <span class="variable parameter python">parse_html</span><span class="keyword operator assignment python">=</span><span class="constant language python">True</span></span><span class="punctuation section arguments end python">)</span></span>
    <span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">folium</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">CircleMarker</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python">
        <span class="meta structure list python"><span class="punctuation section list begin python">[</span><span class="meta qualified-name python"><span class="meta generic-name python">lat</span></span><span class="punctuation separator list python">,</span> <span class="meta qualified-name python"><span class="meta generic-name python">lng</span></span><span class="punctuation section list end python">]</span></span><span class="punctuation separator arguments python">,</span>
        <span class="variable parameter python">radius</span><span class="keyword operator assignment python">=</span><span class="constant numeric integer decimal python">5</span><span class="punctuation separator arguments python">,</span>
        <span class="variable parameter python">popup</span><span class="keyword operator assignment python">=</span><span class="meta qualified-name python"><span class="meta generic-name python">label</span></span><span class="punctuation separator arguments python">,</span>
        <span class="variable parameter python">color</span><span class="keyword operator assignment python">=</span><span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">colors</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta function-call python"><span class="meta qualified-name python"><span class="support type python">int</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">cluster</span></span></span><span class="punctuation section arguments end python">)</span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span><span class="punctuation separator arguments python">,</span>
        <span class="variable parameter python">fill</span><span class="keyword operator assignment python">=</span><span class="constant language python">True</span><span class="punctuation separator arguments python">,</span>
        <span class="variable parameter python">fill_color</span><span class="keyword operator assignment python">=</span><span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">colors</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta function-call python"><span class="meta qualified-name python"><span class="support type python">int</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">cluster</span></span></span><span class="punctuation section arguments end python">)</span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span><span class="punctuation separator arguments python">,</span>
        <span class="variable parameter python">fill_opacity</span><span class="keyword operator assignment python">=</span><span class="constant numeric float python">0<span class="punctuation separator decimal python">.</span>7</span></span><span class="punctuation section arguments end python">)</span></span><span class="meta function-call python"><span class="meta qualified-name python"><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">add_to</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">map_clusters</span></span></span><span class="punctuation section arguments end python">)</span></span>

<span class="meta qualified-name python"><span class="meta generic-name python">map_clusters</span></span></span></code></pre>
<h2 id="investigate-clusters"><span class="section-number-2">6.</span> Investigate Clusters</h2>
<p>Now that we have figured out our clusters, let's do a little more analysis to provide more insight into the clusters. With the information below, we can see which clusters are more popular for businesses and which are less popular. The results below show us that clusters 0 through 3 are popular, while clusters 4 and 5 are not very popular at all.</p>
<pre><code class="language-python highlight"><span class="source python"><span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Show how many venues are in each cluster
</span><span class="meta qualified-name python"><span class="meta generic-name python">color_names</span></span> <span class="keyword operator assignment python">=</span> <span class="meta structure list python"><span class="punctuation section list begin python">[</span><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">Dark Green<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation separator list python">,</span> <span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">Red<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation separator list python">,</span> <span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">Blue<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation separator list python">,</span> <span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">Purple<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation separator list python">,</span> <span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">Pink<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation separator list python">,</span> <span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">Black<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation section list end python">]</span></span>
<span class="meta statement for python"><span class="keyword control flow for python">for</span> <span class="meta generic-name python">x</span> <span class="meta statement for python"><span class="keyword control flow for in python">in</span></span></span><span class="meta statement for python"> <span class="meta function-call python"><span class="meta qualified-name python"><span class="support function builtin python">range</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="constant numeric integer decimal python">0</span><span class="punctuation separator arguments python">,</span><span class="constant numeric integer decimal python">6</span></span><span class="punctuation section arguments end python">)</span></span><span class="punctuation section block for python">:</span></span>
    <span class="meta function-call python"><span class="meta qualified-name python"><span class="support function builtin python">print</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">Color of Cluster<span class="punctuation definition string end python">&quot;</span></span></span><span class="punctuation separator arguments python">,</span> <span class="meta qualified-name python"><span class="meta generic-name python">x</span></span><span class="punctuation separator arguments python">,</span> <span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">:<span class="punctuation definition string end python">&quot;</span></span></span><span class="punctuation separator arguments python">,</span> <span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">color_names</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">x</span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span></span><span class="punctuation section arguments end python">)</span></span>
    <span class="meta function-call python"><span class="meta qualified-name python"><span class="support function builtin python">print</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">Venues found in Cluster<span class="punctuation definition string end python">&quot;</span></span></span><span class="punctuation separator arguments python">,</span> <span class="meta qualified-name python"><span class="meta generic-name python">x</span></span><span class="punctuation separator arguments python">,</span> <span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">:<span class="punctuation definition string end python">&quot;</span></span></span><span class="punctuation separator arguments python">,</span> <span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">nearby_venues</span><span class="punctuation accessor dot python">.</span><span class="meta generic-name python">loc</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">nearby_venues</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">Cluster Labels<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span> <span class="keyword operator comparison python">==</span> <span class="meta qualified-name python"><span class="meta generic-name python">x</span></span>, <span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">nearby_venues</span><span class="punctuation accessor dot python">.</span><span class="meta generic-name python">columns</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="punctuation separator slice python">:</span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span><span class="punctuation accessor dot python">.</span><span class="meta generic-name python">shape</span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="constant numeric integer decimal python">0</span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span></span><span class="punctuation section arguments end python">)</span></span>
    <span class="meta function-call python"><span class="meta qualified-name python"><span class="support function builtin python">print</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">---<span class="punctuation definition string end python">&quot;</span></span></span></span><span class="punctuation section arguments end python">)</span></span></span></code></pre>
<p>Our last piece of analysis is to summarize the categories of businesses within each cluster. With these results, we can clearly see that restaurants, coffee shops, and grocery stores are the most popular.</p>
<pre><code class="language-python highlight"><span class="source python"><span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Calculate how many venues there are in each category
</span><span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Sort from largest to smallest
</span><span class="meta qualified-name python"><span class="meta generic-name python">temp_df</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">nearby_venues</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">drop</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="variable parameter python">columns</span><span class="keyword operator assignment python">=</span><span class="meta structure list python"><span class="punctuation section list begin python">[</span><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">name<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation separator list python">,</span> <span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">lat<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation separator list python">,</span> <span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">lng<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation section list end python">]</span></span></span><span class="punctuation section arguments end python">)</span></span>

<span class="meta qualified-name python"><span class="meta generic-name python">cluster0_grouped</span></span> <span class="keyword operator assignment python">=</span> <span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">temp_df</span><span class="punctuation accessor dot python">.</span><span class="meta generic-name python">loc</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">temp_df</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">Cluster Labels<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span> <span class="keyword operator comparison python">==</span> <span class="constant numeric integer decimal python">0</span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span><span class="meta function-call python"><span class="meta qualified-name python"><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">groupby</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta structure list python"><span class="punctuation section list begin python">[</span><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">categories<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation section list end python">]</span></span></span><span class="punctuation section arguments end python">)</span></span><span class="meta function-call python"><span class="meta qualified-name python"><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">count</span></span><span class="punctuation section arguments begin python">(</span><span class="punctuation section arguments end python">)</span></span><span class="meta function-call python"><span class="meta qualified-name python"><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">sort_values</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="variable parameter python">by</span><span class="keyword operator assignment python">=</span><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">Cluster Labels<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation separator arguments python">,</span> <span class="variable parameter python">ascending</span><span class="keyword operator assignment python">=</span><span class="constant language python">False</span></span><span class="punctuation section arguments end python">)</span></span>
<span class="meta qualified-name python"><span class="meta generic-name python">cluster1_grouped</span></span> <span class="keyword operator assignment python">=</span> <span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">temp_df</span><span class="punctuation accessor dot python">.</span><span class="meta generic-name python">loc</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">temp_df</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">Cluster Labels<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span> <span class="keyword operator comparison python">==</span> <span class="constant numeric integer decimal python">1</span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span><span class="meta function-call python"><span class="meta qualified-name python"><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">groupby</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta structure list python"><span class="punctuation section list begin python">[</span><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">categories<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation section list end python">]</span></span></span><span class="punctuation section arguments end python">)</span></span><span class="meta function-call python"><span class="meta qualified-name python"><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">count</span></span><span class="punctuation section arguments begin python">(</span><span class="punctuation section arguments end python">)</span></span><span class="meta function-call python"><span class="meta qualified-name python"><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">sort_values</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="variable parameter python">by</span><span class="keyword operator assignment python">=</span><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">Cluster Labels<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation separator arguments python">,</span> <span class="variable parameter python">ascending</span><span class="keyword operator assignment python">=</span><span class="constant language python">False</span></span><span class="punctuation section arguments end python">)</span></span>
<span class="meta qualified-name python"><span class="meta generic-name python">cluster2_grouped</span></span> <span class="keyword operator assignment python">=</span> <span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">temp_df</span><span class="punctuation accessor dot python">.</span><span class="meta generic-name python">loc</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">temp_df</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">Cluster Labels<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span> <span class="keyword operator comparison python">==</span> <span class="constant numeric integer decimal python">2</span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span><span class="meta function-call python"><span class="meta qualified-name python"><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">groupby</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta structure list python"><span class="punctuation section list begin python">[</span><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">categories<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation section list end python">]</span></span></span><span class="punctuation section arguments end python">)</span></span><span class="meta function-call python"><span class="meta qualified-name python"><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">count</span></span><span class="punctuation section arguments begin python">(</span><span class="punctuation section arguments end python">)</span></span><span class="meta function-call python"><span class="meta qualified-name python"><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">sort_values</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="variable parameter python">by</span><span class="keyword operator assignment python">=</span><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">Cluster Labels<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation separator arguments python">,</span> <span class="variable parameter python">ascending</span><span class="keyword operator assignment python">=</span><span class="constant language python">False</span></span><span class="punctuation section arguments end python">)</span></span>
<span class="meta qualified-name python"><span class="meta generic-name python">cluster3_grouped</span></span> <span class="keyword operator assignment python">=</span> <span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">temp_df</span><span class="punctuation accessor dot python">.</span><span class="meta generic-name python">loc</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">temp_df</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">Cluster Labels<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span> <span class="keyword operator comparison python">==</span> <span class="constant numeric integer decimal python">3</span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span><span class="meta function-call python"><span class="meta qualified-name python"><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">groupby</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta structure list python"><span class="punctuation section list begin python">[</span><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">categories<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation section list end python">]</span></span></span><span class="punctuation section arguments end python">)</span></span><span class="meta function-call python"><span class="meta qualified-name python"><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">count</span></span><span class="punctuation section arguments begin python">(</span><span class="punctuation section arguments end python">)</span></span><span class="meta function-call python"><span class="meta qualified-name python"><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">sort_values</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="variable parameter python">by</span><span class="keyword operator assignment python">=</span><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">Cluster Labels<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation separator arguments python">,</span> <span class="variable parameter python">ascending</span><span class="keyword operator assignment python">=</span><span class="constant language python">False</span></span><span class="punctuation section arguments end python">)</span></span>
<span class="meta qualified-name python"><span class="meta generic-name python">cluster4_grouped</span></span> <span class="keyword operator assignment python">=</span> <span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">temp_df</span><span class="punctuation accessor dot python">.</span><span class="meta generic-name python">loc</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">temp_df</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">Cluster Labels<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span> <span class="keyword operator comparison python">==</span> <span class="constant numeric integer decimal python">4</span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span><span class="meta function-call python"><span class="meta qualified-name python"><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">groupby</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta structure list python"><span class="punctuation section list begin python">[</span><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">categories<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation section list end python">]</span></span></span><span class="punctuation section arguments end python">)</span></span><span class="meta function-call python"><span class="meta qualified-name python"><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">count</span></span><span class="punctuation section arguments begin python">(</span><span class="punctuation section arguments end python">)</span></span><span class="meta function-call python"><span class="meta qualified-name python"><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">sort_values</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="variable parameter python">by</span><span class="keyword operator assignment python">=</span><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">Cluster Labels<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation separator arguments python">,</span> <span class="variable parameter python">ascending</span><span class="keyword operator assignment python">=</span><span class="constant language python">False</span></span><span class="punctuation section arguments end python">)</span></span>
<span class="meta qualified-name python"><span class="meta generic-name python">cluster5_grouped</span></span> <span class="keyword operator assignment python">=</span> <span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">temp_df</span><span class="punctuation accessor dot python">.</span><span class="meta generic-name python">loc</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">temp_df</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">Cluster Labels<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span> <span class="keyword operator comparison python">==</span> <span class="constant numeric integer decimal python">5</span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span><span class="meta function-call python"><span class="meta qualified-name python"><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">groupby</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta structure list python"><span class="punctuation section list begin python">[</span><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">categories<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation section list end python">]</span></span></span><span class="punctuation section arguments end python">)</span></span><span class="meta function-call python"><span class="meta qualified-name python"><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">count</span></span><span class="punctuation section arguments begin python">(</span><span class="punctuation section arguments end python">)</span></span><span class="meta function-call python"><span class="meta qualified-name python"><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">sort_values</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="variable parameter python">by</span><span class="keyword operator assignment python">=</span><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">Cluster Labels<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation separator arguments python">,</span> <span class="variable parameter python">ascending</span><span class="keyword operator assignment python">=</span><span class="constant language python">False</span></span><span class="punctuation section arguments end python">)</span></span>

<span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> show how many venues there are in each cluster (&gt; 1)
</span><span class="meta statement with python"><span class="keyword control flow with python">with</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">pd</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">option_context</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">display.max_rows<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation separator arguments python">,</span> <span class="constant language python">None</span><span class="punctuation separator arguments python">,</span> <span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">display.max_columns<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation separator arguments python">,</span> <span class="constant language python">None</span></span><span class="punctuation section arguments end python">)</span></span><span class="punctuation section block with python">:</span></span>
    <span class="meta function-call python"><span class="meta qualified-name python"><span class="support function builtin python">print</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python"><span class="constant character escape python">\n</span><span class="constant character escape python">\n</span><span class="punctuation definition string end python">&quot;</span></span></span><span class="punctuation separator arguments python">,</span> <span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">Cluster 0:<span class="punctuation definition string end python">&quot;</span></span></span><span class="punctuation separator arguments python">,</span> <span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python"><span class="constant character escape python">\n</span><span class="punctuation definition string end python">&quot;</span></span></span><span class="punctuation separator arguments python">,</span> <span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">cluster0_grouped</span><span class="punctuation accessor dot python">.</span><span class="meta generic-name python">loc</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">cluster0_grouped</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">Cluster Labels<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span> <span class="keyword operator comparison python">&gt;</span> <span class="constant numeric integer decimal python">1</span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span></span><span class="punctuation section arguments end python">)</span></span>
    <span class="meta function-call python"><span class="meta qualified-name python"><span class="support function builtin python">print</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python"><span class="constant character escape python">\n</span><span class="constant character escape python">\n</span><span class="punctuation definition string end python">&quot;</span></span></span><span class="punctuation separator arguments python">,</span> <span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">Cluster 1:<span class="punctuation definition string end python">&quot;</span></span></span><span class="punctuation separator arguments python">,</span> <span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python"><span class="constant character escape python">\n</span><span class="punctuation definition string end python">&quot;</span></span></span><span class="punctuation separator arguments python">,</span> <span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">cluster1_grouped</span><span class="punctuation accessor dot python">.</span><span class="meta generic-name python">loc</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">cluster1_grouped</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">Cluster Labels<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span> <span class="keyword operator comparison python">&gt;</span> <span class="constant numeric integer decimal python">1</span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span></span><span class="punctuation section arguments end python">)</span></span>
    <span class="meta function-call python"><span class="meta qualified-name python"><span class="support function builtin python">print</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python"><span class="constant character escape python">\n</span><span class="constant character escape python">\n</span><span class="punctuation definition string end python">&quot;</span></span></span><span class="punctuation separator arguments python">,</span> <span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">Cluster 2:<span class="punctuation definition string end python">&quot;</span></span></span><span class="punctuation separator arguments python">,</span> <span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python"><span class="constant character escape python">\n</span><span class="punctuation definition string end python">&quot;</span></span></span><span class="punctuation separator arguments python">,</span> <span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">cluster2_grouped</span><span class="punctuation accessor dot python">.</span><span class="meta generic-name python">loc</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">cluster2_grouped</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">Cluster Labels<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span> <span class="keyword operator comparison python">&gt;</span> <span class="constant numeric integer decimal python">1</span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span></span><span class="punctuation section arguments end python">)</span></span>
    <span class="meta function-call python"><span class="meta qualified-name python"><span class="support function builtin python">print</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python"><span class="constant character escape python">\n</span><span class="constant character escape python">\n</span><span class="punctuation definition string end python">&quot;</span></span></span><span class="punctuation separator arguments python">,</span> <span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">Cluster 3:<span class="punctuation definition string end python">&quot;</span></span></span><span class="punctuation separator arguments python">,</span> <span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python"><span class="constant character escape python">\n</span><span class="punctuation definition string end python">&quot;</span></span></span><span class="punctuation separator arguments python">,</span> <span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">cluster3_grouped</span><span class="punctuation accessor dot python">.</span><span class="meta generic-name python">loc</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">cluster3_grouped</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">Cluster Labels<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span> <span class="keyword operator comparison python">&gt;</span> <span class="constant numeric integer decimal python">1</span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span></span><span class="punctuation section arguments end python">)</span></span>
    <span class="meta function-call python"><span class="meta qualified-name python"><span class="support function builtin python">print</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python"><span class="constant character escape python">\n</span><span class="constant character escape python">\n</span><span class="punctuation definition string end python">&quot;</span></span></span><span class="punctuation separator arguments python">,</span> <span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">Cluster 4:<span class="punctuation definition string end python">&quot;</span></span></span><span class="punctuation separator arguments python">,</span> <span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python"><span class="constant character escape python">\n</span><span class="punctuation definition string end python">&quot;</span></span></span><span class="punctuation separator arguments python">,</span> <span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">cluster4_grouped</span><span class="punctuation accessor dot python">.</span><span class="meta generic-name python">loc</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">cluster4_grouped</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">Cluster Labels<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span> <span class="keyword operator comparison python">&gt;</span> <span class="constant numeric integer decimal python">1</span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span></span><span class="punctuation section arguments end python">)</span></span>
    <span class="meta function-call python"><span class="meta qualified-name python"><span class="support function builtin python">print</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python"><span class="constant character escape python">\n</span><span class="constant character escape python">\n</span><span class="punctuation definition string end python">&quot;</span></span></span><span class="punctuation separator arguments python">,</span> <span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">Cluster 5:<span class="punctuation definition string end python">&quot;</span></span></span><span class="punctuation separator arguments python">,</span> <span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python"><span class="constant character escape python">\n</span><span class="punctuation definition string end python">&quot;</span></span></span><span class="punctuation separator arguments python">,</span> <span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">cluster5_grouped</span><span class="punctuation accessor dot python">.</span><span class="meta generic-name python">loc</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">cluster5_grouped</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">Cluster Labels<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span> <span class="keyword operator comparison python">&gt;</span> <span class="constant numeric integer decimal python">1</span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span></span><span class="punctuation section arguments end python">)</span></span></span></code></pre>
<h2 id="discussion"><span class="section-number-2">7.</span> Discussion</h2>
<p>In this project, we gathered location data for Lincoln, Nebraska, USA and clustered the data using the k-means algorithm in order to identify the unique clusters of businesses in Lincoln. Through these actions, we found that there are six unique business clusters in Lincoln and that two of the clusters are likely unsuitable for investors. The remaining four clusters have a variety of businesses, but are largely dominated by restaurants and grocery stores.</p>
<p>Using this project, investors can now make more informed decisions when deciding the location and category of business in which to invest.</p>
<p>Further studies may involve other attributes for business locations, such as population density, average wealth across the city, or crime rates. In addition, further studies may include additional location data and businesses by utilizing multiple sources, such as Google Maps and OpenStreetMap.</p>
]]></description>
    </item>
    <item>
      <title>Data Analysis: Video Games Sales Data</title>
      <link>https://cleberg.net/blog/video-game-sales.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/video-game-sales.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Mon, 20 Jul 2020 00:00:00 +0000</pubDate>
      <category>personal</category>
      <description><![CDATA[<h2 id="background-information"><span class="section-number-2">1.</span> Background Information</h2>
<p>This dataset (obtained from <a href="https://www.kaggle.com/gregorut/videogamesales/data">Kaggle</a>) contains a list of video games with sales greater than 100,000 copies. It was generated by a scrape of vgchartz.com.</p>
<p>Fields include:</p>
<ul>
<li>Rank: Ranking of overall sales</li>
<li>Name: The game name</li>
<li>Platform: Platform of the game release (i.e. PC,PS4, etc.)</li>
<li>Year: Year of the game's release</li>
<li>Genre: Genre of the game</li>
<li>Publisher: Publisher of the game</li>
<li>NA<sub>Sales</sub>: Sales in North America (in millions)</li>
<li>EU<sub>Sales</sub>: Sales in Europe (in millions)</li>
<li>JP<sub>Sales</sub>: Sales in Japan (in millions)</li>
<li>Other<sub>Sales</sub>: Sales in the rest of the world (in millions)</li>
<li>Global<sub>Sales</sub>: Total worldwide sales.</li>
</ul>
<p>There are 16,598 records. 2 records were dropped due to incomplete information.</p>
<h2 id="import-the-data"><span class="section-number-2">2.</span> Import the Data</h2>
<pre><code class="language-python highlight"><span class="source python"><span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Import the Python libraries we will be using
</span><span class="meta statement import python"><span class="keyword control import python">import</span> <span class="meta qualified-name python"><span class="meta generic-name python">pandas</span></span> <span class="keyword control import as python">as</span> <span class="meta qualified-name python"><span class="meta generic-name python">pd</span></span></span>
<span class="meta statement import python"><span class="keyword control import python">import</span> <span class="meta qualified-name python"><span class="meta generic-name python">numpy</span></span> <span class="keyword control import as python">as</span> <span class="meta qualified-name python"><span class="meta generic-name python">np</span></span></span>
<span class="meta statement import python"><span class="keyword control import python">import</span> <span class="meta qualified-name python"><span class="meta generic-name python">seaborn</span></span> <span class="keyword control import as python">as</span> <span class="meta qualified-name python"><span class="meta generic-name python">sns</span></span></span><span class="punctuation terminator statement python">;</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">sns</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">set</span></span><span class="punctuation section arguments begin python">(</span><span class="punctuation section arguments end python">)</span></span>
<span class="meta statement import python"><span class="keyword control import python">import</span> <span class="meta qualified-name python"><span class="meta generic-name python">matplotlib</span><span class="punctuation accessor dot python">.</span><span class="meta generic-name python">pyplot</span></span> <span class="keyword control import as python">as</span> <span class="meta qualified-name python"><span class="meta generic-name python">plt</span></span></span>

<span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Load the file using the path to the downloaded file
</span><span class="meta qualified-name python"><span class="meta generic-name python">file</span></span> <span class="keyword operator assignment python">=</span> <span class="storage type string python">r</span><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python"><span class="source regexp python">video_game_sales<span class="constant character character-class regexp">.</span>csv</span><span class="punctuation definition string end python">&#39;</span></span></span>
<span class="meta qualified-name python"><span class="meta generic-name python">df</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">pd</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">read_csv</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">file</span></span></span><span class="punctuation section arguments end python">)</span></span>
<span class="meta qualified-name python"><span class="meta generic-name python">df</span></span></span></code></pre>
<h2 id="explore-the-data"><span class="section-number-2">3.</span> Explore the Data</h2>
<pre><code class="language-python highlight"><span class="source python"><span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> With the description function, we can see the basic stats. For example, we can
</span><span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> also see that the &#39;Year&#39; column has some incomplete values.
</span><span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">df</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">describe</span></span><span class="punctuation section arguments begin python">(</span><span class="punctuation section arguments end python">)</span></span></span></code></pre>
<pre><code class="language-python highlight"><span class="source python"><span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> This function shows the rows and columns of NaN values. For example, df[179,3] = nan
</span><span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">np</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">where</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">pd</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">isnull</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">df</span></span></span><span class="punctuation section arguments end python">)</span></span></span><span class="punctuation section arguments end python">)</span></span>

<span class="meta group python"><span class="punctuation section group begin python">(</span><span class="meta function-call python"><span class="meta qualified-name python"><span class="variable function python">array</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta structure list python"><span class="punctuation section list begin python">[</span><span class="constant numeric integer decimal python">179</span><span class="punctuation separator list python">,</span> <span class="constant language python">...</span><span class="punctuation separator list python">,</span> <span class="constant numeric integer decimal python">16553</span><span class="punctuation section list end python">]</span></span><span class="punctuation separator arguments python">,</span> <span class="variable parameter python">dtype</span><span class="keyword operator assignment python">=</span><span class="meta qualified-name python"><span class="meta generic-name python">int64</span></span></span><span class="punctuation section arguments end python">)</span></span><span class="punctuation separator tuple python">,</span>
 <span class="meta function-call python"><span class="meta qualified-name python"><span class="variable function python">array</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta structure list python"><span class="punctuation section list begin python">[</span><span class="constant numeric integer decimal python">3</span><span class="punctuation separator list python">,</span> <span class="constant language python">...</span><span class="punctuation separator list python">,</span> <span class="constant numeric integer decimal python">5</span><span class="punctuation section list end python">]</span></span><span class="punctuation separator arguments python">,</span> <span class="variable parameter python">dtype</span><span class="keyword operator assignment python">=</span><span class="meta qualified-name python"><span class="meta generic-name python">int64</span></span></span><span class="punctuation section arguments end python">)</span></span><span class="punctuation section group end python">)</span></span></span></code></pre>
<h2 id="visualize-the-data"><span class="section-number-2">4.</span> Visualize the Data</h2>
<pre><code class="language-python highlight"><span class="source python"><span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> This function plots the global sales by platform
</span><span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">sns</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">catplot</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="variable parameter python">x</span><span class="keyword operator assignment python">=</span><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">Platform<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation separator arguments python">,</span> <span class="variable parameter python">y</span><span class="keyword operator assignment python">=</span><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">Global_Sales<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation separator arguments python">,</span> <span class="variable parameter python">data</span><span class="keyword operator assignment python">=</span><span class="meta qualified-name python"><span class="meta generic-name python">df</span></span><span class="punctuation separator arguments python">,</span> <span class="variable parameter python">jitter</span><span class="keyword operator assignment python">=</span><span class="constant language python">False</span></span><span class="punctuation section arguments end python">)</span></span><span class="meta function-call python"><span class="meta qualified-name python"><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">set_xticklabels</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="variable parameter python">rotation</span><span class="keyword operator assignment python">=</span><span class="constant numeric integer decimal python">90</span></span><span class="punctuation section arguments end python">)</span></span></span></code></pre>
<pre><code class="language-python highlight"><span class="source python"><span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> This function plots the global sales by genre
</span><span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">sns</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">catplot</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="variable parameter python">x</span><span class="keyword operator assignment python">=</span><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">Genre<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation separator arguments python">,</span> <span class="variable parameter python">y</span><span class="keyword operator assignment python">=</span><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">Global_Sales<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation separator arguments python">,</span> <span class="variable parameter python">data</span><span class="keyword operator assignment python">=</span><span class="meta qualified-name python"><span class="meta generic-name python">df</span></span><span class="punctuation separator arguments python">,</span> <span class="variable parameter python">jitter</span><span class="keyword operator assignment python">=</span><span class="constant language python">False</span></span><span class="punctuation section arguments end python">)</span></span><span class="meta function-call python"><span class="meta qualified-name python"><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">set_xticklabels</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="variable parameter python">rotation</span><span class="keyword operator assignment python">=</span><span class="constant numeric integer decimal python">45</span></span><span class="punctuation section arguments end python">)</span></span></span></code></pre>
<pre><code class="language-python highlight"><span class="source python"><span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> This function plots the global sales by year
</span><span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">sns</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">lmplot</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="variable parameter python">x</span><span class="keyword operator assignment python">=</span><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">Year<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation separator arguments python">,</span> <span class="variable parameter python">y</span><span class="keyword operator assignment python">=</span><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">Global_Sales<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation separator arguments python">,</span> <span class="variable parameter python">data</span><span class="keyword operator assignment python">=</span><span class="meta qualified-name python"><span class="meta generic-name python">df</span></span></span><span class="punctuation section arguments end python">)</span></span><span class="meta function-call python"><span class="meta qualified-name python"><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">set_xticklabels</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="variable parameter python">rotation</span><span class="keyword operator assignment python">=</span><span class="constant numeric integer decimal python">45</span></span><span class="punctuation section arguments end python">)</span></span></span></code></pre>
<pre><code class="language-python highlight"><span class="source python"><span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> This function plots four different lines to show sales from different regions.
</span><span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> The global sales plot line is commented-out, but can be included for comparison
</span><span class="meta qualified-name python"><span class="meta generic-name python">df2</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">df</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">groupby</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">Year<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="punctuation section arguments end python">)</span></span><span class="meta function-call python"><span class="meta qualified-name python"><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">sum</span></span><span class="punctuation section arguments begin python">(</span><span class="punctuation section arguments end python">)</span></span>
<span class="meta qualified-name python"><span class="meta generic-name python">years</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="support function builtin python">range</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="constant numeric integer decimal python">1980</span><span class="punctuation separator arguments python">,</span><span class="constant numeric integer decimal python">2019</span></span><span class="punctuation section arguments end python">)</span></span>

<span class="meta qualified-name python"><span class="meta generic-name python">a</span></span> <span class="keyword operator assignment python">=</span> <span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">df2</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">NA_Sales<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span>
<span class="meta qualified-name python"><span class="meta generic-name python">b</span></span> <span class="keyword operator assignment python">=</span> <span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">df2</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">EU_Sales<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span>
<span class="meta qualified-name python"><span class="meta generic-name python">c</span></span> <span class="keyword operator assignment python">=</span> <span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">df2</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">JP_Sales<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span>
<span class="meta qualified-name python"><span class="meta generic-name python">d</span></span> <span class="keyword operator assignment python">=</span> <span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">df2</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">Other_Sales<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span>
<span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> e = df2[&#39;Global_Sales&#39;]
</span>
<span class="meta qualified-name python"><span class="meta generic-name python">fig</span></span>, <span class="meta qualified-name python"><span class="meta generic-name python">ax</span></span> <span class="keyword operator assignment python">=</span> <span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">plt</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">subplots</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="variable parameter python">figsize</span><span class="keyword operator assignment python">=</span><span class="meta group python"><span class="punctuation section group begin python">(</span><span class="constant numeric integer decimal python">12</span><span class="punctuation separator tuple python">,</span><span class="constant numeric integer decimal python">12</span><span class="punctuation section group end python">)</span></span></span><span class="punctuation section arguments end python">)</span></span>
<span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">ax</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">set_ylabel</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">Region Sales (in Millions)<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="punctuation section arguments end python">)</span></span>
<span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">ax</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">set_xlabel</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">Year<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="punctuation section arguments end python">)</span></span>

<span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">ax</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">plot</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">years</span></span><span class="punctuation separator arguments python">,</span> <span class="meta qualified-name python"><span class="meta generic-name python">a</span></span><span class="punctuation separator arguments python">,</span> <span class="variable parameter python">label</span><span class="keyword operator assignment python">=</span><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">NA_Sales<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="punctuation section arguments end python">)</span></span>
<span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">ax</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">plot</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">years</span></span><span class="punctuation separator arguments python">,</span> <span class="meta qualified-name python"><span class="meta generic-name python">b</span></span><span class="punctuation separator arguments python">,</span> <span class="variable parameter python">label</span><span class="keyword operator assignment python">=</span><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">EU_Sales<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="punctuation section arguments end python">)</span></span>
<span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">ax</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">plot</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">years</span></span><span class="punctuation separator arguments python">,</span> <span class="meta qualified-name python"><span class="meta generic-name python">c</span></span><span class="punctuation separator arguments python">,</span> <span class="variable parameter python">label</span><span class="keyword operator assignment python">=</span><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">JP_Sales<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="punctuation section arguments end python">)</span></span>
<span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">ax</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">plot</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="meta qualified-name python"><span class="meta generic-name python">years</span></span><span class="punctuation separator arguments python">,</span> <span class="meta qualified-name python"><span class="meta generic-name python">d</span></span><span class="punctuation separator arguments python">,</span> <span class="variable parameter python">label</span><span class="keyword operator assignment python">=</span><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">Other_Sales<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="punctuation section arguments end python">)</span></span>
<span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> ax.plot(years, e, label=&#39;Global_Sales&#39;)
</span>
<span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">ax</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">legend</span></span><span class="punctuation section arguments begin python">(</span><span class="punctuation section arguments end python">)</span></span>
<span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">plt</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">show</span></span><span class="punctuation section arguments begin python">(</span><span class="punctuation section arguments end python">)</span></span></span></code></pre>
<h3 id="investigate-outliers"><span class="section-number-3">4.1.</span> Investigate Outliers</h3>
<pre><code class="language-python highlight"><span class="source python"><span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Find the game with the highest sales in North America
</span><span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">df</span><span class="punctuation accessor dot python">.</span><span class="meta generic-name python">loc</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">df</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">NA_Sales<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span><span class="meta function-call python"><span class="meta qualified-name python"><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">idxmax</span></span><span class="punctuation section arguments begin python">(</span><span class="punctuation section arguments end python">)</span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span>

<span class="meta qualified-name python"><span class="meta generic-name python">Rank</span></span>                     <span class="constant numeric integer decimal python">1</span>
<span class="meta qualified-name python"><span class="meta generic-name python">Name</span></span>            <span class="meta qualified-name python"><span class="meta generic-name python">Wii</span></span> <span class="meta qualified-name python"><span class="meta generic-name python">Sports</span></span>
<span class="meta qualified-name python"><span class="meta generic-name python">Platform</span></span>               <span class="meta qualified-name python"><span class="meta generic-name python">Wii</span></span>
<span class="meta qualified-name python"><span class="meta generic-name python">Year</span></span>                  <span class="constant numeric integer decimal python">2006</span>
<span class="meta qualified-name python"><span class="meta generic-name python">Genre</span></span>               <span class="meta qualified-name python"><span class="meta generic-name python">Sports</span></span>
<span class="meta qualified-name python"><span class="meta generic-name python">Publisher</span></span>         <span class="meta qualified-name python"><span class="meta generic-name python">Nintendo</span></span>
<span class="meta qualified-name python"><span class="meta generic-name python">NA_Sales</span></span>             <span class="constant numeric float python">41<span class="punctuation separator decimal python">.</span>49</span>
<span class="meta qualified-name python"><span class="meta generic-name python">EU_Sales</span></span>             <span class="constant numeric float python">29<span class="punctuation separator decimal python">.</span>02</span>
<span class="meta qualified-name python"><span class="meta generic-name python">JP_Sales</span></span>              <span class="constant numeric float python">3<span class="punctuation separator decimal python">.</span>77</span>
<span class="meta qualified-name python"><span class="meta generic-name python">Other_Sales</span></span>           <span class="constant numeric float python">8<span class="punctuation separator decimal python">.</span>46</span>
<span class="meta qualified-name python"><span class="meta generic-name python">Global_Sales</span></span>         <span class="constant numeric float python">82<span class="punctuation separator decimal python">.</span>74</span>
<span class="meta qualified-name python"><span class="meta generic-name python">Name</span></span><span class="punctuation separator annotation variable python">:</span> <span class="constant numeric integer decimal python">0</span>, <span class="meta qualified-name python"><span class="meta generic-name python">dtype</span></span><span class="punctuation separator annotation variable python">:</span> <span class="meta qualified-name python"><span class="support type python">object</span></span>

<span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Explore statistics in the year 2006 (highest selling year)
</span><span class="meta qualified-name python"><span class="meta generic-name python">df3</span></span> <span class="keyword operator assignment python">=</span> <span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">df</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta group python"><span class="punctuation section group begin python">(</span><span class="meta item-access python"><span class="meta qualified-name python"><span class="meta generic-name python">df</span></span></span><span class="meta item-access python"><span class="punctuation section brackets begin python">[</span></span><span class="meta item-access arguments python"><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">Year<span class="punctuation definition string end python">&#39;</span></span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span> <span class="keyword operator comparison python">==</span> <span class="constant numeric integer decimal python">2006</span><span class="punctuation section group end python">)</span></span></span><span class="meta item-access python"><span class="punctuation section brackets end python">]</span></span>
<span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">df3</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">describe</span></span><span class="punctuation section arguments begin python">(</span><span class="punctuation section arguments end python">)</span></span></span></code></pre>
<pre><code class="language-python highlight"><span class="source python"><span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> Plot the results of the previous dataframe (games from 2006) - we can see the year&#39;s results were largely carried by Wii Sports
</span><span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">sns</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">catplot</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="variable parameter python">x</span><span class="keyword operator assignment python">=</span><span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">Genre<span class="punctuation definition string end python">&quot;</span></span></span><span class="punctuation separator arguments python">,</span> <span class="variable parameter python">y</span><span class="keyword operator assignment python">=</span><span class="meta string python"><span class="string quoted double python"><span class="punctuation definition string begin python">&quot;</span></span></span><span class="meta string python"><span class="string quoted double python">Global_Sales<span class="punctuation definition string end python">&quot;</span></span></span><span class="punctuation separator arguments python">,</span> <span class="variable parameter python">data</span><span class="keyword operator assignment python">=</span><span class="meta qualified-name python"><span class="meta generic-name python">df3</span></span><span class="punctuation separator arguments python">,</span> <span class="variable parameter python">jitter</span><span class="keyword operator assignment python">=</span><span class="constant language python">False</span></span><span class="punctuation section arguments end python">)</span></span><span class="meta function-call python"><span class="meta qualified-name python"><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">set_xticklabels</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="variable parameter python">rotation</span><span class="keyword operator assignment python">=</span><span class="constant numeric integer decimal python">45</span></span><span class="punctuation section arguments end python">)</span></span></span></code></pre>
<pre><code class="language-python highlight"><span class="source python"><span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> We can see 4 outliers in the graph above, so let&#39;s get the top 5 games from that dataframe
</span><span class="comment line number-sign python"><span class="punctuation definition comment python">#</span> The results below show that Nintendo had all top 5 games (3 on the Wii and 2 on the DS)
</span><span class="meta function-call python"><span class="meta qualified-name python"><span class="meta generic-name python">df3</span><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">sort_values</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="variable parameter python">by</span><span class="keyword operator assignment python">=</span><span class="meta structure list python"><span class="punctuation section list begin python">[</span><span class="meta string python"><span class="string quoted single python"><span class="punctuation definition string begin python">&#39;</span></span></span><span class="meta string python"><span class="string quoted single python">Global_Sales<span class="punctuation definition string end python">&#39;</span></span></span><span class="punctuation section list end python">]</span></span><span class="punctuation separator arguments python">,</span> <span class="variable parameter python">ascending</span><span class="keyword operator assignment python">=</span><span class="constant language python">False</span></span><span class="punctuation section arguments end python">)</span></span><span class="meta function-call python"><span class="meta qualified-name python"><span class="punctuation accessor dot python">.</span></span><span class="meta qualified-name python"><span class="variable function python">head</span></span><span class="punctuation section arguments begin python">(</span><span class="meta function-call arguments python"><span class="constant numeric integer decimal python">5</span></span><span class="punctuation section arguments end python">)</span></span></span></code></pre>
<h2 id="discussion"><span class="section-number-2">5.</span> Discussion</h2>
<p>The purpose of exploring datasets is to ask questions, answer questions, and discover intelligence that can be used to inform decision-making. So, what have we found in this dataset?</p>
<p>Today we simply explored a publicly-available dataset to see what kind of information it contained. During that exploration, we found that video game sales peaked in 2006. That peak was largely due to Nintendo, who sold the top 5 games in 2006 and has a number of games in the top-10 list for the years 1980-2020. Additionally, the top four platforms by global sales (Wii, NES, GB, DS) are owned by Nintendo.</p>
<p>We didn't explore everything this dataset has to offer, but we can tell from a brief analysis that Nintendo seems to rule sales in the video gaming world. Further analysis could provide insight into which genres, regions, publishers, or world events are correlated with sales.</p>
]]></description>
    </item>
    <item>
      <title>Ubuntu GNOME Customization</title>
      <link>https://cleberg.net/blog/customizing-ubuntu.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/customizing-ubuntu.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Tue, 19 May 2020 00:00:00 +0000</pubDate>
      <category>linux</category>
      <description><![CDATA[<h2 id="more-information"><span class="section-number-2">1.</span> More Information</h2>
<p>For inspiration on designing your *nix computer, check out the <a href="https://libredd.it/r/unixporn">r/unixporn</a> subreddit!</p>
<h2 id="customizing-ubuntu"><span class="section-number-2">2.</span> Customizing Ubuntu</h2>
<p>New to Linux and want to add a personal touch to your machine? One of the best perks of Linux is that it is <strong>extremely</strong> customizable. You can change the styles of the windows, shell (status bars/docks), icons, fonts, terminals, and more.</p>
<p>In this post, I'm going to go through customization on Ubuntu 20.04 (GNOME) since most new users tend to choose Ubuntu-based distros. If you've found a way to install Arch with i3-gaps, I'm assuming you know how to find more advanced tutorials out there on customizations.</p>
<h3 id="required-tools"><span class="section-number-3">2.1.</span> Required Tools</h3>
<p>Ubuntu 20.04 ships with the default desktop environment <a href="https://www.gnome.org/">Gnome</a>, which includes the handy <code class="verbatim">gnome-tweaks</code> tool to quickly change designs. To install this, just open your terminal and enter the following command:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> apt install gnome-tweaks</span></span></code></pre>
<p>After you've finished installing the tool, simply launch the Tweaks application, and you'll be able to access the various customization options available by default on Ubuntu. You might even like some of the pre-installed options.</p>
<h3 id="gnome-application-themes"><span class="section-number-3">2.2.</span> GNOME Application Themes</h3>
<p>To change the themes applied to applications in GNOME, you will need to change the Applications drop-down in the Appearance section of Tweaks. To add more themes, you will have to find your preferred theme online and follow the steps below to have it show up in the Tweaks tool. While you may find themes anywhere, one of the most popular sites for GNOME themes is <a href="https://www.gnome-look.org/">gnome-look.org</a>. This website contains themes for applications, shells, icons, and cursors.</p>
<p>Steps to import themes into Tweaks:</p>
<ol>
<li>Download the theme.</li>
<li>These files are usually compressed (.zip, .tar.gz, .tar.xz), so you will need to extract the contents. This is easiest when opening the file explorer, right-clicking the compressed file, and choosing "Extract here."</li>
<li>Move the theme folder to <code class="verbatim">/usr/share/themes/</code>. You can do so with the following command: <code class="verbatim">sudo mv theme-folder/ /usr/share/themes/</code>.<ul>
<li>Icons and cursors will be moved to the <code class="verbatim">/usr/share/icons/</code> folder.</li>
<li>Fonts will be moved to the <code class="verbatim">/usr/share/fonts/</code> folder Alternatively, you can move them to the <code class="verbatim">/usr/share/fonts/opentype/</code> or <code class="verbatim">/usr/share/fonts/opentype/</code> folders, if you have a specific font type.</li>
</ul>
</li>
<li>Close tweaks if it is open. Re-open Tweaks and your new theme will be available in the Applications drop-down in the Appearance section of Tweaks.</li>
</ol>
<p>If the theme is not showing up after you've moved it into the themes folder, you may have uncompressed the folder into a sub-folder. You can check this by entering the theme folder and listing the contents:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="support function cd shell">cd</span></span><span class="meta function-call arguments shell"> /usr/share/themes/Mojave-Dark</span> <span class="keyword operator logical and shell">&amp;&amp;</span> <span class="meta function-call shell"><span class="variable function shell">ls</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>la</span></span></span></code></pre>
<p>This is an example of what the contents of your theme folder should look like. If you just see another folder there, you should move that folder up into the <code class="verbatim">/usr/share/themes/</code> folder.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">cinnamon</span></span><span class="meta function-call arguments shell"> COPYING gnome-shell gtk-2.0 gtk-3.0 index.theme metacity-1 plank xfwm4</span></span></code></pre>
<h3 id="gnome-shell-themes"><span class="section-number-3">2.3.</span> GNOME Shell Themes</h3>
<p>To change the appearance of the title bar, default dock, app menu, and other parts of the GNOME shell, you'll need to install the <a href="https://extensions.gnome.org/extension/19/user-themes/">user themes</a> extension on <a href="https://extensions.gnome.org/">Gnome Extensions</a>. To be able to install extensions, you will first need to install the browser extension that the website instructs you to. See this screenshot for the blue box with a link to the extension.</p>
<p>After the browser extension is installed, you will need to install the native host connector:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> apt install chrome-gnome-shell</span></span></code></pre>
<p>Finally, you can go the <a href="https://extensions.gnome.org/extension/19/user-themes/">user themes</a> extension page and click the installation button. This will enable the Shell option in Tweaks. Now you can move shell themes to the <code class="verbatim">/usr/share/themes</code> directory, using the same steps mentioned in the previous section, and enable the new theme in Tweaks.</p>
<h3 id="icons-cursors"><span class="section-number-3">2.4.</span> Icons &amp; Cursors</h3>
<p>Icons and cursors are installed exactly the same way, so I'm grouping these together in this post. Both of these items will need to follow the same process as installing themes, except you will want to move your font folders to the <code class="verbatim">/usr/share/icons/</code> directory instead.</p>
<h3 id="fonts"><span class="section-number-3">2.5.</span> Fonts</h3>
<p>Fonts are one of the overlooked parts of customization, but a good font can make the whole screen look different. For example, I have installed the <a href="https://github.com/IBM/plex/releases">IBM Plex</a> fonts on my system. This follows the same process as installing themes, except you will want to move your font folders to the <code class="verbatim">/usr/share/fonts/</code> directory instead.</p>
<h3 id="terminal"><span class="section-number-3">2.6.</span> Terminal</h3>
<p>If you spend a lot of time typing commands, you know how important the style and functionality of the terminal is. After spending a lot of time using the default GNOME terminal with <a href="https://en.wikipedia.org/wiki/Bash_(Unix_shell)">unix shell</a>, I decided to try some different options. I ended up choosing <a href="https://terminator-gtk3.readthedocs.io/en/latest/">Terminator</a> with <a href="https://en.wikipedia.org/wiki/Z_shell">zsh</a> (Z Shell).</p>
<p>Terminator is great if you need to open multiple terminals at one time by simply right-clicking and splitting the screen into as many terminals as you want. While this project hasn't been updated in a while, <a href="https://github.com/gnome-terminator/terminator/issues/1">it is coming under new development</a>. However, this terminal is great and I haven't experienced any errors yet.</p>
<p>For the shell choice, I decided to choose zsh after trying it out on a fresh Manjaro installation. Zsh is great if you like to change the themes of your terminal, include icons, or add plugins.</p>
<p>The desktop uses the <a href="https://github.com/zsh-users/zsh-autosuggestions">zsh-autosuggestions</a> to suggest past commands as you type. In addition, it suggests corrections if you misspell a command. Lastly, it uses the <code class="verbatim">af-magic</code> theme, which adds dashed lines between commands, moving the user@host tag to the right side of the terminal, and changes the colors. There are plenty of plugins and themes to choose from. Just figure out what you like and add it to your <code class="verbatim">~/.zshrc</code> file!</p>
<h4 id="steps-to-replicate-my-terminal"><span class="section-number-4">2.6.1.</span> Steps to Replicate My Terminal</h4>
<p>To install zsh on Ubuntu, enter the following command into a terminal:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> apt install zsh</span></span></code></pre>
<p>Then, enter the next command to activate zsh:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> chsh<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>s</span> <span class="meta group expansion command parens shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section parens begin shell">(</span><span class="meta function-call shell"><span class="variable function shell">which</span></span><span class="meta function-call arguments shell"> zsh</span><span class="punctuation section parens end shell">)</span></span> <span class="meta group expansion command parens shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section parens begin shell">(</span><span class="meta function-call shell"><span class="variable function shell">whoami</span></span><span class="punctuation section parens end shell">)</span></span></span></span></code></pre>
<p>To install Terminator on Ubuntu:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> apt install terminator</span></span></code></pre>
<p>To install Oh My Zsh on Ubuntu:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sh</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>c</span> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span><span class="meta group expansion command parens shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section parens begin shell">(</span><span class="meta function-call shell"><span class="variable function shell">curl</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>fsSL</span></span>
<span class="meta function-call shell"><span class="variable function shell">https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh</span></span><span class="punctuation section parens end shell">)</span></span><span class="punctuation definition string end shell">&quot;</span></span></span></span></code></pre>
<p>To install zsh-autosuggestions via Oh My Zsh:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">git</span></span><span class="meta function-call arguments shell"> clone https://github.com/zsh-users/zsh-autosuggestions</span>
<span class="meta function-call shell"><span class="variable function shell"><span class="meta group expansion parameter shell"><span class="punctuation definition variable shell">$</span><span class="punctuation section expansion parameter begin shell">{</span></span><span class="meta group expansion parameter shell"><span class="variable other readwrite shell">ZSH_CUSTOM</span></span><span class="meta group expansion parameter shell"><span class="keyword operator assignment shell">:-</span></span><span class="meta group expansion parameter shell"><span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/.oh-my-zsh/custom</span><span class="meta group expansion parameter shell"><span class="punctuation section expansion parameter end shell">}</span></span>/plugins/zsh-autosuggestions</span></span></span></code></pre>
<p>Then, add the following plugin wording to your <code class="verbatim">~/.zshrc</code> file (the default config usually has the <code class="verbatim">git</code> plugin activated, so just add any other plugins to the parentheses separated by a space):</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">nano</span></span><span class="meta function-call arguments shell"> <span class="meta group expansion tilde"><span class="variable language tilde shell">~</span></span>/.zshrc</span></span></code></pre>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="variable other readwrite assignment shell">plugins</span><span class="keyword operator assignment shell">=</span><span class="punctuation section parens begin shell">(</span>git zsh-autosuggestions<span class="punctuation section parens end shell">)</span></span></code></pre>
<p>Finally, you need to log out of your computer and log back in so your user shell can refresh.</p>
]]></description>
    </item>
    <item>
      <title>A Look Inside My Homelab</title>
      <link>https://cleberg.net/blog/homelab.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/homelab.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Sun, 03 May 2020 00:00:00 +0000</pubDate>
      <category>self-hosting</category>
      <description><![CDATA[<h2 id="what-is-a-homelab"><span class="section-number-2">1.</span> What is a Homelab?</h2>
<p>Starting as a developer, I have stayed away from hardware-based hobbies (other than building a gaming desktop). However, as the quarantine for COVID-19 stretches out further and further, I found myself bored and in search of new hobbies. After spending the last few months browsing the <a href="https://www.reddit.com/r/homelab/">r/homelab</a> subreddit, I decided it was time to jump in and try things out for myself.</p>
<p>Since I am a beginner and just recently graduated from college, everything I've done so far in my homelab is low-budget.</p>
<h2 id="hardware"><span class="section-number-2">2.</span> Hardware</h2>
<h3 id="raspberry-pi-4"><span class="section-number-3">2.1.</span> Raspberry Pi 4</h3>
<p>Luckily, I had actually purchased a <a href="https://www.raspberrypi.org/products/raspberry-pi-4-model-b/">Raspberry Pi 4</a> before the quarantine started so that I could try to keep Plex Media Center running, even while my desktop computer was turned off. I started here, using the Pi to hold Plex and Pi-hole until I grew tired with the slow performance.</p>
<p>Here are the specifications for the Pi 4:</p>
<ul>
<li>Broadcom BCM2711, Quad core Cortex-A72 (ARM v8) 64-bit SoC @ 1.5GHz</li>
<li>4GB LPDDR4-3200 SDRAM</li>
<li>Gigabit Ethernet</li>
<li>H.265 (4kp60 decode), H264 (1080p60 decode, 1080p30 encode)</li>
<li>64 GB MicroSD Card</li>
</ul>
<h3 id="dell-optiplex-5040"><span class="section-number-3">2.2.</span> Dell Optiplex 5040</h3>
<p>Since I wasn't happy with the Pi as my main server, I turned to Craigslist. I know a lot of other homelabbers use Ebay, but I can't seem to ever trust it enough to purchase items on there. So I used Craigslist and found a Dell Optiplex 5040 desktop computer on sale for $90. While this computer might be underpowered, it was one of the few computers under $100 that was available during quarantine.</p>
<p>Here are the specifications for the Dell Optiplex 5040:</p>
<ul>
<li>Intel Core i3 6100</li>
<li>8GB RAM DDR3</li>
<li>Intel HD Graphics</li>
<li>Gigabit Ethernet</li>
<li>500GB Hard Drive</li>
</ul>
<p>While this hardware would be awful for a work computer or a gaming rig, it turned out to be wonderful for my server purposes. The only limitation I have found so far is the central processing unit (CPU). The i3-6100 only has enough power for a single 4k video transcode at a time. I haven't tested more than three 1080p streams at a time, but the maximum amount of streams I've ever actually used is two.</p>
<h3 id="wd-easystore-10tb-8tb"><span class="section-number-3">2.3.</span> WD easystore 10TB &amp; 8TB</h3>
<p>Application storage and temporary files are stored on the internal hard drive of the server, but all media files (movies, television, games, books, etc) are stored externally on my WD easystore hard drive. Creating auto-boot configurations in the <code class="verbatim">/etc/fstab</code> file on my server allows the hard drives to automatically mount whenever I need to restart my server.</p>
<blockquote>
<p>Update: In March 2022, I shucked the hard drives out of their external cases, put some Kapton tape on the third power pin to prevent power shutdowns, and stuck them inside my server tower using internal Serial AT Attachment (SATA) cables.</p>
</blockquote>
<h3 id="netgear-unmanaged-switch"><span class="section-number-3">2.4.</span> Netgear Unmanaged Switch</h3>
<p>To manage all the ethernet cords used by my homelab, my desktop, and my living room media center, I purchased an 8-port gigabit ethernet switch for $50 at my local computer store. This is probably much more than I should have spent on an unmanaged switch, but I am comfortable with the choice.</p>
<h3 id="tp-link-managed-switch"><span class="section-number-3">2.5.</span> TP-Link Managed Switch</h3>
<p>Since I use the unmanaged switch to group all living room devices together, I use the managed switch to configure virtual local area networks (VLANs) and secure my network.</p>
<h3 id="arris-tm1602a-modem-sagecom-fast-5280-router"><span class="section-number-3">2.6.</span> Arris TM1602A Modem &amp; Sagecom Fast 5280 Router</h3>
<p>My default modem and router, provided by my ISP, are fairly standard. The Arris modem supports DOCSIS 3.0, which is something that I definitely wanted as a minimum. The Sagecom router is also standard, no fancy bells or whistles. However, it does support the dynamic host configuration protocol (DHCP) for internet protocol version 4 (IPv4) and internet protocol version 6 (IPv6), which is something you can use to route all household traffic through a pi-hole or firewall.</p>
<h3 id="tp-link-eap"><span class="section-number-3">2.7.</span> TP-Link EAP</h3>
<p>In order to gain better control over the network, I use my own wireless access point instead of the one included in the Sagecom router above. Now I can control and organize all of my ethernet connections through the VLANs on the managed switch and wireless connections through the VLANS on the EAP.</p>
<h3 id="generic-printer"><span class="section-number-3">2.8.</span> Generic Printer</h3>
<p>The last piece to my homelab is a standard wireless printer. Nothing special here.</p>
<h2 id="software"><span class="section-number-2">3.</span> Software</h2>
<h3 id="ubuntu-server-20-04"><span class="section-number-3">3.1.</span> Ubuntu Server 20.04</h3>
<p>While the 20.04 version of Ubuntu was just released, I always like to experiment with new features (and I don't mind breaking my system - it just gives me more experience learning how to fix things). So, I have Ubuntu Server 20.04 installed on the Dell Optiplex server and Ubuntu Server 19.10 installed on the Raspberry Pi. Once I find an acceptable use for the Pi, I will most likely switch the operating system.</p>
<h3 id="docker"><span class="section-number-3">3.2.</span> Docker</h3>
<p>I am <em>very</em> new to Docker, but I have had a lot of fun playing with it so far. Docker is used to create containers that can hold all the contents of a system without interfering with other software on the same system. So far, I have successfully installed pi-hole, GitLab, Gogs, and Nextcloud in containers. However, I opted to delete all of those so that I can reconfigure them more professionally at a later time.</p>
<h3 id="plex-media-server"><span class="section-number-3">3.3.</span> Plex Media Server</h3>
<p>Plex is a media center software that allows you to organize your movies, TV shows, music, photos, and videos automatically. It will even download metadata for you so that you can easily browse these collections.</p>
<h3 id="pi-hole"><span class="section-number-3">3.4.</span> Pi-hole</h3>
<p>Pi-hole is an alternative ad-blocker that runs at the DNS level, allowing you to block traffic when it hits your network, so that you can reject any traffic you deem to be bad. Pi-hole uses blacklists and whitelists to decide which traffic block and, luckily, there are a lot of pre-made lists out there on Reddit, GitHub, etc.</p>
<h3 id="nextcloud"><span class="section-number-3">3.5.</span> Nextcloud</h3>
<p>While I had trouble with the Docker version of Nextcloud, I was very successful when setting up the snap version. Using this, I was able to map Nextcloud to a subdomain of a domain I own in Namecheap. Additionally, Nextcloud has an integration with Let's Encrypt that allows me to issue certificates automatically to any new domain I authorize.</p>
<h3 id="webmin"><span class="section-number-3">3.6.</span> Webmin</h3>
<p>To monitor my servers, and the processes running on them, I use the Webmin dashboard. This was fairly painless to set up, and I currently access it straight through the server's IP address. In the future, I will be looking to configure Webmin to use a custom domain just like Nextcloud.</p>
]]></description>
    </item>
    <item>
      <title>Review: Session Messenger</title>
      <link>https://cleberg.net/blog/session-messenger.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/session-messenger.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Wed, 25 Mar 2020 00:00:00 +0000</pubDate>
      <category>privacy</category>
      <description><![CDATA[<h2 id="privacy-warning"><span class="section-number-2">1.</span> Privacy Warning</h2>
<p>The company behind Session (Loki Foundation) is from Australia. If you didn't know, Australia has introduced <a href="https://parlinfo.aph.gov.au/parlInfo/download/legislation/bills/r6195_aspassed/toc_pdf/18204b01.pdf">legislation</a> mandating companies comply with government requests to build back door access into applications. For more information, read my article on <a href="aes-encryption.html">AES Encryption</a>.</p>
<h2 id="about-session"><span class="section-number-2">2.</span> About Session</h2>
<p><a href="https://getsession.org">Session</a> is a private, cross-platform messaging app from the <a href="https://loki.foundation">Loki Foundation</a>. As someone who has spent years looking for quality alternatives to major messaging apps, I was excited when I first heard about Session. Reading through <a href="https://arxiv.org/pdf/2002.04609.pdf">Session's white paper</a>, you can learn the technologies behind the Session app. Part of the security of Session comes from the Signal protocol, which was forked as the origin of Session.</p>
<blockquote>
<p>Session is an end-to-end encrypted messenger that removes sensitive metadata collection, and is designed for people who want privacy and freedom from any forms of surveillance.</p>
</blockquote>
<p>In general, this app promises security through end-to-end encryption, decentralized onion routing, and private identities. The biggest change that the Loki Foundation has made to the Signal protocol is removing the need for a phone number. Instead, a random identification string is generated for any session you create. This means you can create a new session for each device if you want to, or link new devices with your ID.</p>
<p>Since Session's website and white paper describe the details of Session's security, I'm going to focus on using the app in this post.</p>
<h2 id="features"><span class="section-number-2">3.</span> Features</h2>
<p>Since most people are looking for an alternative to a popular chat app, I am going to list out the features that Session has so that you are able to determine if the app would suit your needs:</p>
<ul>
<li>Multiple device linking [via a quick-response (QR) code or identifier (ID)]</li>
<li>App locking via device screen lock, password, or fingerprint</li>
<li>Screenshot blocking</li>
<li>Incognito keyboard</li>
<li>Read receipts and typing indicators</li>
<li>Mobile notification customization</li>
<li>Old message deletion and conversation limit</li>
<li>Backups</li>
<li>Recovery phrase</li>
<li>Account deletion, including ID, messages, sessions, and contacts</li>
</ul>
<h2 id="downloads"><span class="section-number-2">4.</span> Downloads</h2>
<p>I have tested this app on Ubuntu 19.10, Android 10, macOS Monterey, and iOS 15. All apps have worked well without issue.</p>
<p>Below is a brief overview of the Session app on Linux. To get this app, you'll need to go to the <a href="https://getsession.org/download/">Downloads</a> page and click to link to the operating system you're using.</p>
<p>For Linux, it will download an AppImage that you'll need to enable with the following command:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> chmod u+x session-messenger-desktop-linux-x86_64-1.0.5.AppImage</span></span></code></pre>
<h2 id="creating-an-account"><span class="section-number-2">5.</span> Creating an Account</h2>
<p>Once you've installed the app, simply run the app and create your unique Session ID. It will look something like this: <code class="verbatim">05af1835afdd63c947b47705867501d6373f486aa1ae05b1f2f3fcd24570eba608</code>.</p>
<p>You'll need to set a display name and, optionally, a password. If you set a password, you will need to enter it every time you open the app.</p>
<h2 id="start-messaging"><span class="section-number-2">6.</span> Start Messaging</h2>
<p>Once you've created your account and set up your profile details, the next step is to start messaging other people. To do so, you'll need to share your Session ID with other people. From this point, it's straightforward and acts like any other messaging app, so I won't dive into much detail here.</p>
<h3 id="macos"><span class="section-number-3">6.1.</span> macOS</h3>
<p>One key feature to note is that the desktop application now provides a helpful pop-up box explaining the process that Session uses to hide your IP address:</p>
<h3 id="ios"><span class="section-number-3">6.2.</span> iOS</h3>
<p>The mobile app is simple and effective, giving you all the standard mobile messaging options you'd expect.</p>
<h2 id="potential-issues"><span class="section-number-2">7.</span> Potential Issues</h2>
<p>I've discovered one annoying issue that would prevent from using this app regularly. On a mobile device, there have been issues with receiving messages on time. Even with battery optimization disabled and no network restrictions, Session notifications sometimes do not display until I open the app or the conversation itself and wait. This is actually one of the reasons I stopped using Signal (this seems fixed as of my updates in 2021/2022, so I wouldn't worry about this issue anymore).</p>
<p>Looking for another messenger instead of Session? I recommend Signal, Matrix, and internet relay chat (IRC).</p>
]]></description>
    </item>
    <item>
      <title>Cryptography Basics</title>
      <link>https://cleberg.net/blog/cryptography.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/cryptography.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Sun, 09 Feb 2020 00:00:00 +0000</pubDate>
      <category>security</category>
      <description><![CDATA[<h2 id="similar-article-available"><span class="section-number-2">1.</span> Similar Article Available</h2>
<p>If you haven't already, feel free to read my post on <a href="aes-encryption.html">AES Encryption</a>.</p>
<h2 id="what-is-cryptography"><span class="section-number-2">2.</span> What is Cryptography?</h2>
<p>In layman's terms, cryptography is a process that can change data from a readable format into an unreadable format (and vice-versa) through a series of processes and secrets. More technically, this is the Internet Security Glossary's definition:</p>
<blockquote>
<p>[Cryptography is] the mathematical science that deals with transforming data to render its meaning unintelligible (i.e., to hide its semantic content), prevent its undetected alteration, or prevent its unauthorized use. If the transformation is reversible, cryptography also deals with restoring encrypted data to an intelligible form.</p>
<ul>
<li><a href="https://tools.ietf.org/html/rfc2828">Internet Security Glossary (2000)</a></li>
</ul>
</blockquote>
<p>Cryptography cannot offer protection against the loss of data; it simply offers encryption methods to protect data at-rest and data in-traffic. At a high-level, encrypted is when plain text data is encrypted to cipher text (a secure form of text that cannot be understood unless decrypted back to plain text). The encryption process is completed through the use of a mathematical function that utilizes one or more values called keys to encrypt or decrypt the data.</p>
<h2 id="key-elements-of-cryptographic-systems"><span class="section-number-2">3.</span> Key Elements of Cryptographic Systems</h2>
<p>To create or evaluate a cryptographic system, you need to know the essential pieces to the system:</p>
<ul>
<li><strong>Encryption Algorithm (Primitive):</strong> A mathematical process that encrypts and decrypts data.</li>
<li><strong>Encryption Key:</strong> A string of bits used within the encryption algorithm as the secret that allows successful encryption or decryption of data.</li>
<li><strong>Key Length (Size):</strong> The maximum number of bits within the encryption key. It's important to remember that key size is regulated in certain countries.</li>
<li><strong>Message Digest:</strong> A smaller, fixed-size bit string version of the original message. This is practically infeasible to reverse, which is why it's commonly used to verify integrity.</li>
</ul>
<h2 id="symmetric-systems-secret-key-cryptography"><span class="section-number-2">4.</span> Symmetric Systems (Secret Key Cryptography)</h2>
<p>Symmetric cryptography utilizes a secret, bidirectional key to perform both encryption and decryption of the data. The most common implementation of symmetric cryptography is the Advanced Encryption Standard, which uses keys that are 128 bits to 256 bits in size. This standard came after the National Institute of Standards and Technology (NIST) decided to retire the Data Encryption Standard (DES) in 2001.</p>
<p>Since brute force attacks strongly correlate with key length, the 56-bit key length of DES was considered insecure after it was publicly broken in under 24 hours. However, there is a modern implementation of DES called Triple DES where the DES method is applied three times to each data block.</p>
<p>The main advantages to symmetric systems are the ease of use, since only one key is required for both encryption and decryption, and the simplicity of the algorithms. This helps with bulk data encryption that may unnecessarily waste time and power using asymmetric systems.</p>
<p>However, symmetric systems have disadvantages to keep in mind. Since the key is private, it can be difficult to safely distribute keys to communication partners. Additionally, the key cannot be used to sign messages since it's necessary to keep the key private.</p>
<h2 id="asymmetric-systems-public-key-cryptography"><span class="section-number-2">5.</span> Asymmetric Systems (Public Key Cryptography)</h2>
<p>Asymmetric cryptography utilizes two keys within the system: a secret key that is privately-held and a public key that can be distributed freely. The interesting aspect of asymmetric cryptography is that either key can be used to encrypt the data, there's no rule that dictates which key must be used for encryption. Once one key is used to encrypt the data, only the other key can be used to decrypt the data. This means that if the private key encrypts the data, only the public key can decrypt the data.</p>
<p>An advantage of this system is that if you successfully decrypt data using one of the keys, you can be sure of the sender since only the other key could have encrypted the data.</p>
<p>One of the major implementations of an asymmetric system is a digital signature. A digital signature can be generated using the sender's private key, or a one-way hash function and is used to provide assurance for the integrity and authenticity of the message. A couple common message digest algorithms are SHA-256 and SHA-512, which securely compress data and produce a 128-bit message digest.</p>
<p>It should be noted that man-in-the-middle attacks are one of the risks with digital signatures and public keys. To combat this, applications often use a public key infrastructure (PKI) to independently authenticate the validity of signatures and keys.</p>
<p>Due to the large key size and <a href="https://crypto.stackexchange.com/a/591">inefficient mathematical functions</a> of asymmetric encryption, elliptical curve cryptography (ECC) is often used to increase security while using fewer resources.</p>
<h2 id="applications-of-cryptographic-systems"><span class="section-number-2">6.</span> Applications of Cryptographic Systems</h2>
<p>There are numerous implementations of cryptographic systems around the world. Here are six popular examples:</p>
<p><strong>Transport Layer Security (TLS):</strong> One of the most famous cryptographic solutions created is TLS, a session-layered or connection-layered internet protocol that allows for secure communications between browsers and servers. Using handshakes, peer negotiation, and authentication allows TLS to prevent eavesdropping and malicious transformation of data. The major reason for TLS popularity is that a major vulnerability was found in the SSL protocol in 2014. Instead of SSL, TLS can be used with HTTP to form HTTPS and is the preferred method for modern web development due to its increased security.</p>
<p><strong>Secure Hypertext Transfer Protocol (HTTPS):</strong> An application layer protocol that allows for secure transport of data between servers and web clients. One of the unique parts of HTTPS is that it uses a secured port number instead of the default web port address.</p>
<p><strong>Virtual Private Network (VPN):</strong> VPNs are made to securely extend a private network across public networks by utilizing an encrypted layered tunneling protocol paired with an authentication method, such as usernames and passwords. This technology originally allowed remote employees to access their company's data but have evolved into one of the top choices for anyone who wishes to mask their sensitive personal data.</p>
<p><strong>Internet Protocol Security (IPSec):</strong> This protocol suite facilitates communication between two or more hosts or subnets by authenticating and encrypting the data packets. IPSec is used in a lot of VPNs to establish the VPN connection through the transport and tunnel mode encryption methods. IPSec encrypts just the data portion of packets in the transport methods, but it encrypts both the data and headers in the tunnel method (introducing an additional header for authentication).</p>
<p><strong>Secure Shell (SSH):</strong> SSH is another network protocol used to protect network services by authenticating users through a secure channel. This protocol is often used for command-line (shell) functions such as remote shell commands, logins, and file transfers.</p>
<p><strong>Kerberos:</strong> Developed by MIT, Kerberos is a computer-network authentication protocol that works on the basis of tickets to allow nodes communicating over a non-secure network to prove their identity to one another securely. This is most commonly used in business environments when used as the authentication and encryption method for Windows Active Directory (AD).</p>
<h2 id="cybersecurity-controls"><span class="section-number-2">7.</span> Cybersecurity Controls</h2>
<p>If you're someone who needs solutions on how to control risks associated with utilizing a cryptographic system, start with these basic controls:</p>
<ul>
<li><strong>Policies:</strong> A policy on the use of cryptographic controls for protection of information is implemented and is in accordance with organizational objectives.</li>
<li><strong>Key management:</strong> A policy on the use, protection and lifetime of cryptographic keys is implemented through the entire application lifecycle.</li>
<li><strong>Key size:</strong> The organization has researched the optimal key size for their purposes, considering national laws, required processing power, and longevity of the solution.</li>
<li><strong>Algorithm selection:</strong> Implemented algorithms are sufficiently appropriate for the business of the organization, robust, and align with recommended guidelines.</li>
<li><strong>Protocol configuration:</strong> Protocols have been reviewed and configured suitable to the purpose of the business.</li>
</ul>
]]></description>
    </item>
    <item>
      <title>Steam NTFS Fix on Linux</title>
      <link>https://cleberg.net/blog/steam-on-ntfs.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/steam-on-ntfs.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Sun, 26 Jan 2020 00:00:00 +0000</pubDate>
      <category>linux</category>
      <description><![CDATA[<h2 id="auto-mount-steam-drives"><span class="section-number-2">1.</span> Auto-Mount Steam Drives</h2>
<p>If you want to see how to install Steam on Linux, see my other post: <a href="linux-software.html">Linux Software</a>.</p>
<p>Are you having trouble launching games, even though they've installed correctly? This may happen if you're storing your games on an NT File System (NTFS)-formatted drive. This shouldn't be an issue if you're storing your games on the same drive that Steam is on, but some gamers prefer to put Steam on their main drive and game files on another solid state drive (SSD) or hard disk drive (HDD).</p>
<p>To fix this problem, you'll need to try two things. First, you'll need to install the <code class="verbatim">ntfs-3g</code> package, which allows for better interoperability with Linux.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> apt install ntfs-3g</span></span></code></pre>
<p>Next, you should set up the <code class="verbatim">/etc/fstab</code> file to automatically mount your drives on boot. To automatically mount your drives when the computer boots up, you'll have to create the folders you want to mount your drive to first. I store mine in the <code class="verbatim">/mnt</code> folder using names that I'll recognize, but you can create your folders wherever you want.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">mkdir</span></span><span class="meta function-call arguments shell"> /path/to/folder</span></span></code></pre>
<p>For example:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">mkdir</span></span><span class="meta function-call arguments shell"> /mnt/steam_library</span></span></code></pre>
<p>To automatically mount drives upon system boot, you will need to collect five items. The universally unique identifier (UUID) is the identification number connected to whichever drive you're using to store Steam games.</p>
<p>Drives are usually labeled similar to <code class="verbatim">/dev/nvme0n1p1</code> or <code class="verbatim">/dev/sda1</code>, so you'll need to find the line in the output of the command below that correlates to your drive and copy the UUID over to the <code class="verbatim">/etc/fstab</code> file.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> blkid</span> <span class="keyword operator logical pipe shell">|</span> <span class="meta function-call shell"><span class="variable function shell">grep</span></span><span class="meta function-call arguments shell"> UUID=</span></span></code></pre>
<p>Next, you'll need your user identified (<code class="verbatim">uid</code>) and group identifier (<code class="verbatim">gid</code>). To find these, run the following command:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">id</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>u</span></span> <span class="keyword operator logical and shell">&amp;&amp;</span> <span class="meta function-call shell"><span class="variable function shell">id</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>g</span></span></span></code></pre>
<p>Now that you have collected the necessary information, open the <code class="verbatim">/etc/fstab</code> file:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> nano /etc/fstab</span></span></code></pre>
<p>Each drive you want to mount on boot should have its own line in the <code class="verbatim">/etc/fstab</code> file that looks similar to this:</p>
<pre><code class="language-config">UUID=B64E53824E5339F7 /mnt/steam_library ntfs-3g uid=1000,gid=1000 0 0</code></pre>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> umount /dev/sdxX</span></span></code></pre>
<p>Now all you need to do is unmount your drive and re-mount it. You can unmount the drive by doing this (be sure to use the correct drive name here):</p>
<p>You can re-mount all your drives by executing the following:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> mount<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>a</span></span></span></code></pre>
<p>If you don't know what your drive name is, or you're nervous about unmounting and re-mounting, simply reboot your computer, and the system will mount the drive for you automatically.</p>
]]></description>
    </item>
    <item>
      <title>My Favorite Linux Software</title>
      <link>https://cleberg.net/blog/linux-software.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/linux-software.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Sat, 25 Jan 2020 00:00:00 +0000</pubDate>
      <category>linux</category>
      <description><![CDATA[<h2 id="graphical-applications"><span class="section-number-2">1.</span> Graphical Applications</h2>
<h3 id="etcher"><span class="section-number-3">1.1.</span> Etcher</h3>
<p><a href="https://www.balena.io/etcher/">Etcher</a> is a quick and easy way to burn an optical disc image (ISO) to a compact disc (CD) or universal serial bus (USB) device. There are two different ways you can install this program. First, you can navigate to the <a href="https://www.balena.io/etcher/">official website</a> and download the AppImage file, which can run without installation.</p>
<p>However, AppImage files are not executable by default, so you'll either need to right-click to open the properties of the file and click the "Allow executing file as program" box in the Permissions tab or use the following command:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">chmod</span></span><span class="meta function-call arguments shell"> u+x FILE_NAME</span></span></code></pre>
<p>If you don't like AppImage files or just prefer repositories, you can use the following commands to add the author's repository and install it through the command-line only.</p>
<p>First, you'll have to write the repository to a list file:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="support function echo shell">echo</span></span><span class="meta function-call arguments shell"> <span class="string quoted double shell"><span class="punctuation definition string begin shell">&quot;</span>deb https://deb.etcher.iostable etcher<span class="punctuation definition string end shell">&quot;</span></span></span> <span class="keyword operator logical pipe shell">|</span> <span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> tee /etc/apt/sources.list.d/balena-etcher.list</span></span></code></pre>
<p>Next, add the application keys to Ubuntu's key ring:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> apt-key adv<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> --</span>keyserver</span> keyserver.ubuntu.com<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> --</span>recv-keys</span> 379CE192D401AB61</span></span></code></pre>
<p>Finally, update the repositories and install the app.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> apt update</span> <span class="keyword operator logical and shell">&amp;&amp;</span> <span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> apt install balena-etcher-electron</span></span></code></pre>
<p>Using Arch, Manjaro, or another distribution using the Arch User Repository (AUR)? Use this command instead:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> pacman<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>S</span> etcher</span></span></code></pre>
<h3 id="atom"><span class="section-number-3">1.2.</span> Atom</h3>
<p><a href="https://atom.io">Atom</a> is the self-proclaimed "hackable text editor for the 21st century". GitHub develops this editor, <a href="https://news.microsoft.com/2018/06/04/microsoft-to-acquire-github-for-7-5-billion/">now owned by Microsoft</a>, and has some of the best add-ons available to customize the layout and abilities of the app.</p>
<p>First, add the Atom repository to your sources.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> add-apt-repository ppa:webupd8team/atom</span></span></code></pre>
<p>Next, update your package listings and install atom.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> apt update</span> <span class="keyword operator logical and shell">&amp;&amp;</span> <span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> apt install atom</span></span></code></pre>
<p>If you have issues updating your packages with the Atom repository, you'll need to use the snap package described below instead of the repository. To remove the repository we just added, use this command:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> add-apt-repository<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>r</span> ppa:webupd8team/atom</span></span></code></pre>
<p>You can also install Atom as a snap package, but you must install it with the <code class="verbatim">--classic</code> flag. A <a href="https://language-bash.com/blog/how-to-snap-introducing-classic-confinement">full explanation is available</a> if you'd like to read more about why you need the classic flag.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">snap</span></span><span class="meta function-call arguments shell"> install atom<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> --</span>classic</span></span></span></code></pre>
<p>Using Arch, Manjaro, or another distro using the AUR? Use this command instead:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> pacman<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>S</span> atom</span></span></code></pre>
<h3 id="visual-studio-code"><span class="section-number-3">1.3.</span> Visual Studio Code</h3>
<p><a href="https://code.visualstudio.com">Visual Studio Code</a> (VS Code) is yet another fantastic choice for programming on Linux, especially if you need those extra add-ons to spice up your late-night coding sessions. The theme used in the screenshot is <a href="https://marketplace.visualstudio.com/items?itemName=EliverLara.mars">Mars</a> by theme creator <a href="https://github.com/EliverLara">Eliver Lara</a>, who makes a ton of great themes for VS Code, Atom, and Linux desktop environments.</p>
<p>To install VS Code, you'll need to download the <code class="verbatim">.deb</code> file from the official website. Once you've downloaded the file, either double-click it to install through the Software Center or run the following command:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> dpkg<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>i</span> FILE_NAME.deb</span></span></code></pre>
<p>You can also install VS Code as a snap package, but you must install it with the <code class="verbatim">--classic</code> flag. A <a href="https://language-bash.com/blog/how-to-snap-introducing-classic-confinement">full explanation is available</a> if you'd like to read more about why you need the classic flag.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">snap</span></span><span class="meta function-call arguments shell"> install code<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> --</span>classic</span></span></span></code></pre>
<p>Using Arch, Manjaro, or another distro using the AUR? Use these commands instead:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> pacman<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>S</span> yay binutils make gcc pkg-config fakeroot yay<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>S</span> visual-studio-code-bin</span></span></code></pre>
<h3 id="gnome-tweaks"><span class="section-number-3">1.4.</span> GNOME Tweaks</h3>
<p><a href="https://gitlab.gnome.org/GNOME/gnome-tweaks">Gnome Tweaks</a> is the ultimate tool to use if you want to customize your GNOME desktop environment. This is how you can switch application themes (GTK), shell themes, icons, fonts, and more. To install GNOME Tweaks on Ubuntu, you just need to install the official package.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> apt install gnome-tweaks</span></span></code></pre>
<p>If you've installed Manjaro or Arch with Gnome, you should have the tweak tool pre-installed. If you're on Fedora, this tool is available as an official package:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> dnf install gnome-tweaks</span></span></code></pre>
<h3 id="steam"><span class="section-number-3">1.5.</span> Steam</h3>
<p><a href="https://steampowered.com">Steam</a> is one of the most popular gaming libraries for computers and is one of the main reasons that people have been able to switch to Linux in recent years, thanks to Steam Proton, which makes it easier to play games not officially created for Linux platforms.</p>
<p>To install Steam on Ubuntu, you just need to install the official package.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> apt install steam-installer</span></span></code></pre>
<p>For Arch-based systems, you'll simply need to install the <code class="verbatim">steam</code> package. However, this requires that you enable the <code class="verbatim">multilib</code> source. To do so, use the following command:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> nano /etc/pacman.conf</span></span></code></pre>
<p>Now, scroll down and uncomment the <code class="verbatim">multilib</code> section.</p>
<pre><code class="language-config"># Before:
#[multilib]
#Include = /etc/pacman.d/mirrorlist

# After:
[multilib]
Include = /etc/pacman.d/mirrorlist</code></pre>
<p>Finally, install the program:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> pacman<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>S</span> steam</span></span></code></pre>
<p><a href="steam-on-ntfs.html">Problem Launching Steam Games? Click Here.</a></p>
<h2 id="command-line-packages"><span class="section-number-2">2.</span> Command-Line Packages</h2>
<h3 id="neofetch"><span class="section-number-3">2.1.</span> neofetch</h3>
<p><a href="https://github.com/dylanaraps/neofetch">Neofetch</a> is a customizable tool used in the command-line to show system information. This is exceptionally useful if you want to see your system's information quickly without the clutter of some resource-heavy GUI apps.</p>
<p>This is an official package if you're running Ubuntu 17.04 or later, so simply use the following command:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> apt install neofetch</span></span></code></pre>
<p>If you're running Ubuntu 16.10 or earlier, you'll have to use a series of commands:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> add-apt-repository ppa:dawidd0811/neofetch</span><span class="keyword operator logical continue shell">;</span> <span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> apt update</span><span class="keyword operator logical continue shell">;</span> <span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> apt</span>
<span class="meta function-call shell"><span class="variable function shell">install</span></span><span class="meta function-call arguments shell"> neofetch</span></span></code></pre>
<p>Using Arch, Manjaro, or another distro using the AUR? Use this command instead:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> pacman<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>S</span> neofetch</span></span></code></pre>
<h3 id="yt-dlp"><span class="section-number-3">2.2.</span> yt-dlp</h3>
<p><a href="https://github.com/yt-dlp/yt-dlp">yt-dlp</a> is a handy command-line tool that allows you to download video or audio files from websites, such as YouTube. There are a ton of different options when running this package, so be sure to run <code class="verbatim">yt-dlp --help</code> first to look through everything you can do (or give up and search for the best configuration online).</p>
<p>While this shouldn't be a problem for most users, yt-dlp requires Python 2.6, 2.7, or 3.2+ to work correctly, so install Python if you don't have it already. You can check to see if you have Python installed by running:</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">python</span></span><span class="meta function-call arguments shell"><span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>V</span></span></span></code></pre>
<p>To get the youtube-dl package, simply curl the URL and output the results.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> curl<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>L</span> https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp<span class="variable parameter option shell"><span class="punctuation definition parameter shell"> -</span>o</span></span>
<span class="meta function-call shell"><span class="variable function shell">/usr/local/bin/yt-dlp</span></span></span></code></pre>
<p>Finally, make the file executable so that you can run it from the command-line.</p>
<pre><code class="language-sh highlight"><span class="source shell bash"><span class="meta function-call shell"><span class="variable function shell">sudo</span></span><span class="meta function-call arguments shell"> chmod a+rx /usr/local/bin/yt-dlp</span></span></code></pre>
]]></description>
    </item>
    <item>
      <title>NIST Password Security</title>
      <link>https://cleberg.net/blog/password-security.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/password-security.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Mon, 16 Dec 2019 00:00:00 +0000</pubDate>
      <category>security</category>
      <description><![CDATA[<h2 id="users"><span class="section-number-2">1.</span> Users</h2>
<h3 id="why-does-it-matter"><span class="section-number-3">1.1.</span> Why Does It Matter?</h3>
<p>Information security, including passwords and identities, has become one of the most important digital highlights of the last decade. With <a href="https://www.usatoday.com/story/money/2018/12/28/data-breaches-2018-billions-hit-growing-number-cyberattacks/2413411002/">billions of people affected by data breaches each year</a>, there's a greater need to introduce strong information security systems. If you think you've been part of a breach, or you want to check and see, you can use <a href="https://haveibeenpwned.com/">Have I Been Pwned</a> to see if any public breaches have exposed your email(s). Remember that there's a possibility that a company experienced a breach and did not report it to anyone.</p>
<h3 id="how-do-i-protect-myself"><span class="section-number-3">1.2.</span> How Do I Protect Myself?</h3>
<p>The first place to start with any personal security check-up is to gather a list of all the different websites, apps, or programs that require you to have login credentials. Optionally, once you know where you are storing your information, you can sort the list from the most-important items such as banks or government logins to less important items such as your favorite meme site. You will want to ensure that your critical logins are secure before getting to the others.</p>
<p>Once you think you have a good idea of all your different authentication methods, I recommend using a password manager such as <a href="https://bitwarden.com/">Bitwarden</a>. Using a password manager allows you to automatically save your logins, create randomized passwords, and transfer passwords across devices. However, you'll need to memorize your "vault password" that allows you to open the password manager. It's important to make this something hard to guess since it would allow anyone who has it to access every password you've stored in there.</p>
<p>Personally, I recommend using a <a href="https://en.wikipedia.org/wiki/Passphrase">passphrase</a> instead of a <a href="https://en.wikipedia.org/wiki/Password">password</a> for your vault password. Instead of using a string of characters (whether random or simple), use a phrase and add in symbols and a number. For example, your vault password could be <code class="verbatim">Racing-Alphabet-Gourd-Parrot3</code>. Swap the symbols out for whichever symbol you want, move the number around, and fine-tune the pass phrase until you are confident that you can remember it whenever necessary.</p>
<p>Once you've stored your passwords, make sure you continually check up on your account and make sure you aren't following bad password practices. Krebs on Security has a great <a href="https://krebsonsecurity.com/password-dos-and-donts/">blog post on password recommendations</a>. Any time that a data breach happens, make sure you check to see if the breach exposed your email, and if you need to reset any account passwords.</p>
<h2 id="developers"><span class="section-number-2">2.</span> Developers</h2>
<h3 id="what-are-the-basic-requirements"><span class="section-number-3">2.1.</span> What Are the Basic Requirements?</h3>
<p>When developing any password-protected application, there are basic rules that anyone should follow even if they do not follow any official guidelines such as NIST. The foremost practice is to require users to use passwords that are at least 8 characters and bad actors cannot easily guess them. This sounds simple, but it requires different strategies. First, the application should check the potential passwords against a dictionary of insecure passwords such <code class="verbatim">password</code>, <code class="verbatim">1234abc</code>, or <code class="verbatim">application_name</code>.</p>
<p>Next, the application should offer guidance on the strength of passwords you enter during enrollment. Further, NIST officially recommends <strong>not</strong> implementing any composition rules that make passwords hard to remember (e.g. passwords with letters, numbers, and special characters) and instead encouraging the use of long pass phrases which can include spaces. Note that to be able to keep spaces within passwords, you should support all unicode characters, and you should not truncate spaces.</p>
<h3 id="what-does-nist-recommend"><span class="section-number-3">2.2.</span> What Does NIST Recommend?</h3>
<p>The National Institute of Standards and Technology (<a href="https://www.nist.gov">NIST</a>) in the US Department of Commerce regularly publishes information around information security and digital identity guidelines. Recently, NIST published <a href="https://pages.nist.gov/800-63-3/sp800-63b.html">Special Publication 800-63b</a>: Digital Identity Guidelines and Authentication and Lifecycle Management.</p>
<blockquote>
<p>A Memorized Secret authenticator - commonly referred to as a password or, if numeric, a PIN - is a secret value intended to be chosen and memorized by the user. Memorized secrets need to be of sufficient complexity and secrecy that it would be impractical for an attacker to guess or otherwise discover the correct secret value. A memorized secret is something you know.</p>
<ul>
<li>NIST Special Publication 800-63B</li>
</ul>
</blockquote>
<p>NIST offers a lot of guidance on passwords, but I'm going to highlight just a few of the important factors:</p>
<ul>
<li>Require passwords to be a minimum of 8 characters (6 characters if randomly generated and generate using an approved random bit generator).</li>
<li>Compare potential passwords against a list that contains values known to be commonly-used, expected, or compromised.</li>
<li>Offer guidance on password strength, such as a strength meter.</li>
<li>Implement a rate-limiting mechanism to limit the number of failed authentication attempts for each user account.</li>
<li>Do not require composition rules for passwords and do not require users to change their passwords periodically (unless compromised).</li>
<li>Allow pasting of user identification and passwords to facilitate the use of password managers.</li>
<li>Allow users to view the password as they type.</li>
<li>Use secure forms of communication and storage, including salting and hashing passwords using a one-way key derivation function.</li>
</ul>
<p>NIST offers further guidance on other devices that require specific security policies, querying for passwords, and more. All the information discussed so far comes from <a href="https://pages.nist.gov/800-63-3/sp800-63b.html">NIST SP800-63b</a> but NIST offers a lot of information on digital identities, enrollment, identity proofing, authentication, lifecycle management, federation, and assertions in the total <a href="https://pages.nist.gov/800-63-3/">NIST SP800-63 Digital Identity Guidelines</a>.</p>
]]></description>
    </item>
    <item>
      <title>The Ansoff Matrix</title>
      <link>https://cleberg.net/blog/the-ansoff-matrix.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/the-ansoff-matrix.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Tue, 03 Dec 2019 00:00:00 +0000</pubDate>
      <category>audit</category>
      <description><![CDATA[<h2 id="overview"><span class="section-number-2">1.</span> Overview</h2>
<p>As the world of business evolves, managers must approach business planning and strategy with a contemporary mindset. According to Dess, McNamara, Eisner, and Lee, managers must be willing to adapt to the modern business environment by going beyond "'incremental management', whereby they view their job as making a series of small, minor changes to improve the efficiency of the firm's operations"(2019).</p>
<p>One reason that strategic management is crucial is because most businesses that fail in the United States each year fail due to a lack of strategic focus or direction(2019). The rate of failure for businesses with poor strategies shows that strategic planning and management are crucial to a business's strength and longevity, injecting the critical factors of growth and direction into a company's business plan.</p>
<p>One of the most significant strategic planning and management frameworks that companies can use is the <a href="https://en.wikipedia.org/wiki/Ansoff_matrix">Ansoff Matrix</a>. While this framework has unique purposes and use-cases, it can effectively help an organization grow and compete. Specifically, the Ansoff matrix is one of the most effective frameworks for companies who want to focus on increasing sales revenue or profitability(2019).</p>
<p>This framework uses a two-by-two figure to show the four strategic options for companies to use in this framework: market penetration, market development, product development, and diversification (see <strong>Figure 1</strong>). The x-axis of the matrix focuses on the firm's markets and also determines if the firm is looking to enter new markets or innovate in its current markets. The y-axis of the matrix focuses on the firm's products and determines if the firm wants to pursue strategies around their existing products or explore new products.</p>
<h2 id="strategic-options"><span class="section-number-2">2.</span> Strategic Options</h2>
<h3 id="market-penetration"><span class="section-number-3">2.1.</span> Market Penetration</h3>
<p>The most straightforward strategy in the Ansoff matrix is to focus on existing products in existing markets, also known as market penetration(2019). Companies such as Coca-Cola have used market penetration successfully by investing a lot of money to get further value out of their current markets. Coca-Cola does this by introducing new features such as Christmas-themed bottles, personal names on the bottles, and other marketing schemes.</p>
<h3 id="market-development"><span class="section-number-3">2.2.</span> Market Development</h3>
<p>Market development extends existing products into new markets in an attempt to increase the number of buyers. One interesting way that Coca-Cola used this strategy comes from the stigma that Diet Coke is a woman's drink(2019). Coca-Cola introduced Coca-Cola Zero, which contained the same nutritional content as Diet Coke, but the company packaged it in a dark black can to appear more "manly" (2019).</p>
<h3 id="product-development"><span class="section-number-3">2.3.</span> Product Development</h3>
<p>Product development uses existing markets to introduce new products so that the firm can better meet customer needs(2019). The extreme end of diversification is home to companies such as Johnson &amp; Johnson, a healthcare company that has developed a business portfolio of more than 60,000 different products(2019). Johnson &amp; Johnson's dedication to continuous diversification has led them to a balance sheet rating of "AAA", industry recognition for diversification, and increases in their investor dividends for 57 consecutive years(2019).</p>
<h3 id="related-diversification"><span class="section-number-3">2.4.</span> Related Diversification</h3>
<p>Diversification, the final strategy of the Ansoff Matrix, is more difficult than the others since it involves exploring both new markets and new products. Related diversification is a diversification strategy that closely relates to the firm's core business. Coca-Cola's best example of related diversification is its acquisition of Glaceau and Vitamin Water, which expanded their drinking lines of business(2019).</p>
<h3 id="unrelated-diversification"><span class="section-number-3">2.5.</span> Unrelated Diversification</h3>
<p>Unrelated diversification is a diversification strategy that does not really relate to the firm's core business but still diversifies their business portfolio. A good example of this would be a coffee company who has decided to enter the market for bicycle sales. The main purpose of this strategy is to a diverse company that will not go bankrupt if one market goes through difficult times. However, this requires a lot of independent skills and heavy investments since the company most likely cannot easily transfer knowledge between the markets they compete in.</p>
<h2 id="requirements-for-success"><span class="section-number-2">3.</span> Requirements for Success</h2>
<p>To use the Ansoff Matrix framework, managers need to formulate corporate goals and objectives. Without goals and direction, management frameworks do not present much practical utility. Further, the Ansoff Matrix requires the managers involved to make tactical decisions and create a path for the company to take toward their goals. Lastly, both the Ansoff Matrix needs to consider both internal and external perspectives throughout the strategy formulation process.</p>
<p>One interesting probability is that companies will be using multiple strategic planning and management frameworks at the same time. While this may sound like it could crowd the management process, there are numerous reasons to do so. For example, the Ansoff Matrix and the Balanced Scorecard are popular, and they cover entirely different parts of a company's strategy. Using the results from the Balanced Scorecard could inform a company of the potential product and market demands, such as from customer or supplier survey results, to help the company determine which Ansoff Matrix strategy to pursue. However, a combined approach at this level would require mature frameworks and focused managers who are able to strategize at a high level.</p>
<p>Lastly, please note that the author of the Ansoff matrix, Igor Ansoff, often used the term <a href="https://en.wikipedia.org/wiki/Analysis_paralysis">paralysis by analysis</a> to explain the mistake of companies who overuse analysis and spend too much time planning. Companies need to understand the utility of a strategic management framework while ensuring that the company is poised to execute as efficiently as they have planned.</p>
]]></description>
    </item>
    <item>
      <title>Internal Audit Analytics</title>
      <link>https://cleberg.net/blog/audit-analytics.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/audit-analytics.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Mon, 09 Sep 2019 00:00:00 +0000</pubDate>
      <category>audit</category>
      <description><![CDATA[<h2 id="what-are-data-analytics"><span class="section-number-2">1.</span> What Are Data Analytics?</h2>
<p>A quick aside before I dive into this post: <code class="verbatim">data analytics</code> is a vague term that has become popular in recent years. Think of a <code class="verbatim">data analytic</code> as the output of any data analysis you perform. For example, a pivot table or a pie chart could be a data analytic.</p>
<p><a href="https://en.wikipedia.org/wiki/Data_analysis">Data analysis</a> is a process that utilizes statistics and other mathematical methods to discover useful information within datasets. This involves examining, cleaning, transforming, and modeling data so that you can use the data to support an opinion, create more useful viewpoints, and gain knowledge to implement into audit planning or risk assessments.</p>
<p>One of the common mistakes that managers (and anyone new to the process) make is assuming that everything involved with this process is "data analytics". In fact, data analytics are only a small part of the process.</p>
<p>See <strong>Figure 1</strong> for a more accurate representation of where data analysis sits within the full process. This means that data analysis does not include querying or extracting data, selecting samples, or performing audit tests. These steps can be necessary for an audit (and the same associates may perform these steps), but they are not data analytics.</p>
<h2 id="current-use-of-analytics-in-auditing"><span class="section-number-2">2.</span> Current Use of Analytics in Auditing</h2>
<p>While data analysis has been an integral part of most businesses and departments for the better part of the last century, only recently have internal audit functions been adopting this practice. The internal audit function works exclusively to provide assurance and consulting services to the business areas within the firm (except for internal auditing firms hired by different companies to perform their roles).</p>
<blockquote>
<p>Internal Auditing helps an organization accomplish its objectives by bringing a systematic, disciplined approach to evaluate and improve the effectiveness of risk management, control and governance processes.</p>
<ul>
<li>The IIA's Definition of Internal Audit</li>
</ul>
</blockquote>
<p>Part of the blame for the slow adoption of data analysis can be attributed to the fact that internal auditing is strongly based on tradition and following the precedents set by previous auditors. However, there can be no progress without auditors who are willing to break the mold and test new audit techniques. In fact, as of 2018, <a href="https://www.cpapracticeadvisor.com/accounting-audit/news/12404086/internal-audit-groups-are-lagging-in-data-analytics">only 63% of internal audit departments currently utilize data analytics</a> in North America. This number should be as close as possible to 100%. I have never been part of an audit that would not have benefited from data analytics.</p>
<p>So, how do internal audit functions remedy this situation? It's definitely not as easy as walking into work on Monday and telling your Chief Audit Executive that you're going to start implementing analytics in the next audit. You need a plan and a system to make the analysis process as effective as possible.</p>
<h2 id="the-delta-model"><span class="section-number-2">3.</span> The DELTA Model</h2>
<p>One of the easiest ways to experiment with data analytics and gain an understanding of the processes is to implement them within your own department. But how do we do this if we've never worked with analysis before? One of the most common places to start is to research some data analysis models currently available. For this post, we'll take a look at the DELTA model. You can take a look at <strong>Figure 2</strong> for a quick overview of the model.</p>
<p>The DELTA model sets guidelines for areas wanting to implement data analytics so that the results can be as comprehensive as possible:</p>
<ul>
<li><strong>Data</strong>: Must be clean, accessible, and (usually) unique.</li>
<li><strong>Enterprise-Wide Focus</strong>: Key data systems and analytical resources must be available for use (by the Internal Audit Function).</li>
<li><strong>Leaders</strong>: Must promote a data analytics approach and show the value of analytical results.</li>
<li><strong>Targets</strong>: Must be defined for key areas and risks that the analytics can be compared against (KPIs).</li>
<li><strong>Analysts</strong>: There must be auditors willing and able to perform data analytics or else the system cannot be sustained.</li>
</ul>
<h2 id="finding-the-proper-kpis"><span class="section-number-2">4.</span> Finding the Proper KPIs</h2>
<p>Once the Internal Audit Function has decided that they want to start using data analytics internally and have ensured they're properly set up to do so, they need to figure out what they will be testing against. Key Performance Indicators (KPIs) are qualitative or quantitative factors that can be evaluated and assessed to determine if the department is performing well, usually compared to historical or industry benchmarks. Once KPIs have been agreed upon and set, auditors can use data analytics to assess and report on these KPIs. This allows the person performing the analytics the freedom to express opinions on the results, whereas the results are ambiguous if no KPIs exist.</p>
<p>Note that tracking KPIs in the department can help ensure you have a rigorous Quality Assurance and Improvement Program (QAIP) in accordance with some applicable standards, such as IPPF Standard 1300.</p>
<blockquote>
<p>The chief audit executive must develop and maintain a quality assurance and improvement program that covers all aspects of the internal audit activity.</p>
<ul>
<li>IPPF Standard 1300</li>
</ul>
</blockquote>
<p>Additionally, IPPF Standard 2060 discusses reporting:</p>
<blockquote>
<p>The chief audit executive must report periodically to senior management and the board on the internal audit activity's purpose, authority, responsibility, and performance relative to its plan and on its conformance with the Code of Ethics and the Standards. Reporting must also include significant risk and control issues, including fraud risks, governance issues, and other matters that require the attention of senior management and/or the board.</p>
<ul>
<li>IPPF Standard 2060</li>
</ul>
</blockquote>
<p>The hardest part of finding KPIs is to determine which KPIs are appropriate for your department. Since every department is different and has different goals, KPIs will vary drastically between companies. To give you an idea of where to look, here are some ideas I came up with when discussing the topic with a few colleagues.</p>
<ul>
<li>Efficiency/Budgeting:<ul>
<li>Audit hours to staff utilization ratio (annual hours divided by total annual work hours).</li>
<li>Audit hours compared to the number of audits completed.</li>
<li>Time between audit steps or to complete the whole audit. E.g., time from fieldwork completion to audit report issuance.</li>
</ul>
</li>
<li>Reputation:<ul>
<li>The frequency that management has requested the services of the IAF.</li>
<li>Management, audit committee, or external audit satisfaction survey results.</li>
<li>Education, experience, certifications, tenure, and training of the auditors on staff.</li>
</ul>
</li>
<li>Quality:<ul>
<li>Number and frequency of audit findings. Assign monetary or numerical values, if possible.</li>
<li>Percentage of recommendations issued and implemented.</li>
</ul>
</li>
<li>Planning:<ul>
<li>Percentage or number of key risks audited per year or per audit.</li>
<li>Proportion of audit universe audited per year.</li>
</ul>
</li>
</ul>
<h2 id="data-analysis-tools"><span class="section-number-2">5.</span> Data Analysis Tools</h2>
<p>Finally, to be able to analyze and report on the data analysis, auditors need to evaluate the tools at their disposal. There are options available, but the most common ones can easily get the job done. For example, almost every auditor already has access to Microsoft Excel. Excel is more powerful than most people give it credit for and can accomplish a lot of basic statistics without much work. If you don't know a lot about statistics but still want to see some of the more basic results, Excel is a great option.</p>
<p>To perform more in-depth statistical analysis or to explore large datasets that Excel cannot handle, auditors will need to explore other options. The big three that have had a lot of success in recent years are Python, R, and ACL Analytics (ACL). You can use ACL as either a graphical tool (point and click) or as a scripting tool, where the auditor must write the scripts manually. Python and the R-language are solely scripting languages.</p>
<p>The general trend in the data analytics environment is that if the tool allows you to do everything by clicking buttons or dragging elements, you won't be able to fully utilize the analytics you need. To create the most robust solutions, you should write the scripts manually. Note that as the utility of a tool increases, it usually means that the learning curve for that tool will also be higher. It will take auditors longer to learn how to utilize Python, R, or ACL versus learning how to utilize Excel.</p>
<h2 id="visualization"><span class="section-number-2">6.</span> Visualization</h2>
<p>Once an auditor has finally found the right data, KPIs, and tools, they must report these results so that readers of their results can take action. Performing in-depth data analysis is only useful if the audience can understand the results. The best way to create this understanding is to visualize the results of the data. Let's take a look at some of the best options to visualize and report the results you've found.</p>
<p>Some of the most popular commercial tools for visualization are Microsoft PowerBI and Tableau Desktop. However, other tools exist such as JMP, Plotly, Qlikview, Alteryx, or D3. Some require commercial licenses while others are simply free to use. For corporate data, you may want to make sure that the tool does not communicate any of the data outside the company (such as cloud storage). I won't be going into depth on any of these tools since visualization is a subjective and creative experience, but remember to constantly explore new options as you repeat the process.</p>
<p>Lastly, let's take a look at an example of data visualization. This example comes from a <a href="https://talent.works/2018/03/28/the-science-of-the-job-search-part-iii-61-of-entry-level-jobs-require-3-years-of-experience/">blog post written by Kushal Chakrabarti</a> in 2018 about the percent of entry-level US jobs that require experience. <strong>Figure 3</strong> shows us an easy-to-digest picture of the data. We can quickly tell that only about 12.5% of entry-level jobs don't require experience.</p>
<p>This is the kind of result that easily describes the data for you. However, make sure to include an explanation of what the results mean. Don't let the reader assume what the data means, especially if it relates to a complex subject. <em>Tell a story</em> about the data and why the results matter.</p>
<h2 id="wrap-up"><span class="section-number-2">7.</span> Wrap-Up</h2>
<p>While this is not an all-encompassing program that you can just adopt into your department, it should be enough to get anyone started on the process of understanding and implementing data analytics. Always remember to continue learning and exploring new options as your processes grow and evolve.</p>
]]></description>
    </item>
    <item>
      <title>CSS Tips: Flexbox, Shadows, Variables</title>
      <link>https://cleberg.net/blog/useful-css.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/useful-css.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Mon, 07 Jan 2019 00:00:00 +0000</pubDate>
      <category>web</category>
      <description><![CDATA[<h2 id="introduction-to-css"><span class="section-number-2">1.</span> Introduction to CSS</h2>
<p>Cascading Style Sheets (<a href="https://en.wikipedia.org/wiki/CSS">CSS</a>), the language used to mark up HTML code and give it a visual style, is one of the most effective ways to increase the attractiveness of a website. It can also lead to increased user engagement, retention, and satisfaction. In fact, there are whole career fields dedicated to the improvement of user experiences, known as User Interface (UI) design and User Experience (UX) design.</p>
<p>Some web developers are familiar with the common CSS properties, such as element sizing, fonts, and colors, but are not as well versed in less-used properties and values such as <code class="verbatim">flexbox</code>, <code class="verbatim">clip-path</code>, and <code class="verbatim">transform</code>. This article will provide some insight into the less-used and unique CSS properties.</p>
<h2 id="css-variables"><span class="section-number-2">2.</span> CSS Variables</h2>
<p>The first topic today is CSS variables. Variables are not often used by smaller developers. CSS variables allow you to give your website a well-defined structure, where you can easily reuse CSS properties throughout the project.</p>
<p>You can use variables to define things, such as color palettes. Then, you can use these colors for backgrounds anywhere else in the HTML. You can expand this and define variables for <code class="verbatim">primary-text</code>, <code class="verbatim">quoted-text</code>, etc. You can also use variables to define spacing (e.g. <code class="verbatim">32px</code> or <code class="verbatim">2rem</code>), which you can then apply to margins, padding, font sizes, and more.</p>
<p>For example, here are some variables defined at the root of the website, which allows for any subsequent CSS rules to use those variables:</p>
<pre><code class="language-css highlight"><span class="source css"><span class="meta selector css"><span class="entity other pseudo-class css"><span class="punctuation definition entity css">:</span>root</span> </span><span class="meta property-list css"><span class="punctuation section property-list css">{</span>
    <span class="meta property-name css"><span class="support type custom-property css"><span class="punctuation definition custom-property css">--</span><span class="support type custom-property name css">primary-color</span></span></span><span class="punctuation separator key-value css">:</span><span class="meta property-value css"> </span><span class="meta property-value css"><span class="support constant color w3c-standard-color-name css">black</span></span><span class="punctuation terminator rule css">;</span>
    <span class="meta property-name css"><span class="support type custom-property css"><span class="punctuation definition custom-property css">--</span><span class="support type custom-property name css">secondary-color</span></span></span><span class="punctuation separator key-value css">:</span><span class="meta property-value css"> </span><span class="meta property-value css"><span class="support constant color w3c-standard-color-name css">white</span></span><span class="punctuation terminator rule css">;</span>
</span><span class="punctuation section property-list css">}</span>

<span class="meta selector css"><span class="entity name tag css">body</span> </span><span class="meta property-list css"><span class="punctuation section property-list css">{</span>
    <span class="meta property-name css"><span class="support type property-name css">background-color</span></span><span class="punctuation separator key-value css">:</span><span class="meta property-value css"> </span><span class="meta property-value css"><span class="meta function-call css"><span class="support function var css">var</span><span class="meta group css"><span class="punctuation definition group begin css">(</span><span class="support type custom-property css"><span class="punctuation definition custom-property css">--</span><span class="support type custom-property name css">primary-color</span></span></span><span class="meta group css"><span class="punctuation definition group end css">)</span></span></span></span><span class="punctuation terminator rule css">;</span>
    <span class="meta property-name css"><span class="support type property-name css">color</span></span><span class="punctuation separator key-value css">:</span><span class="meta property-value css"> </span><span class="meta property-value css"><span class="meta function-call css"><span class="support function var css">var</span><span class="meta group css"><span class="punctuation definition group begin css">(</span><span class="support type custom-property css"><span class="punctuation definition custom-property css">--</span><span class="support type custom-property name css">secondary-color</span></span></span><span class="meta group css"><span class="punctuation definition group end css">)</span></span></span></span><span class="punctuation terminator rule css">;</span>
</span><span class="punctuation section property-list css">}</span></span></code></pre>
<h2 id="css-box-shadows"><span class="section-number-2">3.</span> CSS Box Shadows</h2>
<p>Box shadows were once my mortal enemy. No matter how hard I tried, I just couldn't get them to work how I wanted. Because of this, my favorite discovery has been CSSMatic's <a href="https://www.cssmatic.com/box-shadow">box shadow generator</a>. It provides a tool to generate box shadows using their simple sliders. Surprisingly, this is the reason I learned how box shadows work! You can use the sliders and watch how the CSS code changes in the image that the tool displays. Through this, you should understand that the basic structure for box shadows is:</p>
<pre><code class="language-css highlight"><span class="source css"><span class="meta selector css"><span class="entity name tag custom css">box-shadow</span>: inset horizontal vertical blur spread color;</span></span></code></pre>
<p>Now, let's look at some basic examples! You can copy and paste the following code into a site like CodePen or your own HTML files. Feel free to play around with the code, experiment, and learn.</p>
<p><strong>Box Shadow #1</strong></p>
<pre><code class="language-html highlight"><span class="text html basic"><span class="meta tag block any html"><span class="punctuation definition tag begin html">&lt;</span><span class="entity name tag block any html">div</span> <span class="meta attribute-with-value class html"><span class="entity other attribute-name class html">class</span><span class="punctuation separator key-value html">=</span></span><span class="meta attribute-with-value class html"><span class="string quoted double html"><span class="punctuation definition string begin html">&quot;</span></span></span><span class="meta attribute-with-value class html"><span class="string quoted double html"><span class="meta class-name html">shadow-examples</span><span class="punctuation definition string end html">&quot;</span></span></span><span class="punctuation definition tag end html">&gt;</span></span>
    <span class="meta tag block any html"><span class="punctuation definition tag begin html">&lt;</span><span class="entity name tag block any html">div</span> <span class="meta attribute-with-value class html"><span class="entity other attribute-name class html">class</span><span class="punctuation separator key-value html">=</span></span><span class="meta attribute-with-value class html"><span class="string quoted double html"><span class="punctuation definition string begin html">&quot;</span></span></span><span class="meta attribute-with-value class html"><span class="string quoted double html"><span class="meta class-name html">box effect1</span><span class="punctuation definition string end html">&quot;</span></span></span><span class="punctuation definition tag end html">&gt;</span></span>
        <span class="meta tag block any html"><span class="punctuation definition tag begin html">&lt;</span><span class="entity name tag block any html">h3</span><span class="punctuation definition tag end html">&gt;</span></span>Effect 1<span class="meta tag block any html"><span class="punctuation definition tag begin html">&lt;/</span><span class="entity name tag block any html">h3</span><span class="punctuation definition tag end html">&gt;</span></span>
    <span class="meta tag block any html"><span class="punctuation definition tag begin html">&lt;/</span><span class="entity name tag block any html">div</span><span class="punctuation definition tag end html">&gt;</span></span>
<span class="meta tag block any html"><span class="punctuation definition tag begin html">&lt;/</span><span class="entity name tag block any html">div</span><span class="punctuation definition tag end html">&gt;</span></span></span></code></pre>
<pre><code class="language-css highlight"><span class="source css"><span class="meta selector css"><span class="entity other attribute-name class css"><span class="punctuation definition entity css">.</span>box</span> <span class="entity name tag css">h3</span> </span><span class="meta property-list css"><span class="punctuation section property-list css">{</span>
    <span class="meta property-name css"><span class="support type property-name css">text-align</span></span><span class="punctuation separator key-value css">:</span><span class="meta property-value css"> </span><span class="meta property-value css"><span class="support constant property-value css">center</span></span><span class="punctuation terminator rule css">;</span>
    <span class="meta property-name css"><span class="support type property-name css">position</span></span><span class="punctuation separator key-value css">:</span><span class="meta property-value css"> </span><span class="meta property-value css"><span class="support constant property-value css">relative</span></span><span class="punctuation terminator rule css">;</span>
    <span class="meta property-name css"><span class="support type property-name css">top</span></span><span class="punctuation separator key-value css">:</span><span class="meta property-value css"> </span><span class="meta property-value css"><span class="constant numeric css">80<span class="keyword other unit css">px</span></span></span><span class="punctuation terminator rule css">;</span>
</span><span class="punctuation section property-list css">}</span>
<span class="meta selector css"><span class="entity other attribute-name class css"><span class="punctuation definition entity css">.</span>box</span> </span><span class="meta property-list css"><span class="punctuation section property-list css">{</span>
    <span class="meta property-name css"><span class="support type property-name css">width</span></span><span class="punctuation separator key-value css">:</span><span class="meta property-value css"> </span><span class="meta property-value css"><span class="constant numeric css">70<span class="keyword other unit css">%</span></span></span><span class="punctuation terminator rule css">;</span>
    <span class="meta property-name css"><span class="support type property-name css">height</span></span><span class="punctuation separator key-value css">:</span><span class="meta property-value css"> </span><span class="meta property-value css"><span class="constant numeric css">200<span class="keyword other unit css">px</span></span></span><span class="punctuation terminator rule css">;</span>
    <span class="meta property-name css"><span class="support type property-name css">background</span></span><span class="punctuation separator key-value css">:</span><span class="meta property-value css"> </span><span class="meta property-value css"><span class="constant other color rgb-value css"><span class="punctuation definition constant css">#</span>fff</span></span><span class="punctuation terminator rule css">;</span>
    <span class="meta property-name css"><span class="support type property-name css">margin</span></span><span class="punctuation separator key-value css">:</span><span class="meta property-value css"> </span><span class="meta property-value css"><span class="constant numeric css">40<span class="keyword other unit css">px</span></span> <span class="support constant property-value css">auto</span></span><span class="punctuation terminator rule css">;</span>
</span><span class="punctuation section property-list css">}</span>
<span class="meta selector css"><span class="entity other attribute-name class css"><span class="punctuation definition entity css">.</span>effect1</span> </span><span class="meta property-list css"><span class="punctuation section property-list css">{</span>
    <span class="meta property-name css"><span class="support type property-name css">box-shadow</span></span><span class="punctuation separator key-value css">:</span><span class="meta property-value css"> </span><span class="meta property-value css"><span class="constant numeric css">0</span> <span class="constant numeric css">10<span class="keyword other unit css">px</span></span> <span class="constant numeric css">6<span class="keyword other unit css">px</span></span> <span class="constant numeric css">-6<span class="keyword other unit css">px</span></span> <span class="constant other color rgb-value css"><span class="punctuation definition constant css">#</span>777</span></span><span class="punctuation terminator rule css">;</span>
</span><span class="punctuation section property-list css">}</span></span></code></pre>
<p><strong>Box Shadow #2</strong></p>
<pre><code class="language-html highlight"><span class="text html basic"><span class="meta tag block any html"><span class="punctuation definition tag begin html">&lt;</span><span class="entity name tag block any html">div</span> <span class="meta attribute-with-value class html"><span class="entity other attribute-name class html">class</span><span class="punctuation separator key-value html">=</span></span><span class="meta attribute-with-value class html"><span class="string quoted double html"><span class="punctuation definition string begin html">&quot;</span></span></span><span class="meta attribute-with-value class html"><span class="string quoted double html"><span class="meta class-name html">shadow-examples</span><span class="punctuation definition string end html">&quot;</span></span></span><span class="punctuation definition tag end html">&gt;</span></span>
    <span class="meta tag block any html"><span class="punctuation definition tag begin html">&lt;</span><span class="entity name tag block any html">div</span> <span class="meta attribute-with-value class html"><span class="entity other attribute-name class html">class</span><span class="punctuation separator key-value html">=</span></span><span class="meta attribute-with-value class html"><span class="string quoted double html"><span class="punctuation definition string begin html">&quot;</span></span></span><span class="meta attribute-with-value class html"><span class="string quoted double html"><span class="meta class-name html">box effect2</span><span class="punctuation definition string end html">&quot;</span></span></span><span class="punctuation definition tag end html">&gt;</span></span>
        <span class="meta tag block any html"><span class="punctuation definition tag begin html">&lt;</span><span class="entity name tag block any html">h3</span><span class="punctuation definition tag end html">&gt;</span></span>Effect 2<span class="meta tag block any html"><span class="punctuation definition tag begin html">&lt;/</span><span class="entity name tag block any html">h3</span><span class="punctuation definition tag end html">&gt;</span></span>
    <span class="meta tag block any html"><span class="punctuation definition tag begin html">&lt;/</span><span class="entity name tag block any html">div</span><span class="punctuation definition tag end html">&gt;</span></span>
<span class="meta tag block any html"><span class="punctuation definition tag begin html">&lt;/</span><span class="entity name tag block any html">div</span><span class="punctuation definition tag end html">&gt;</span></span></span></code></pre>
<pre><code class="language-css highlight"><span class="source css"><span class="meta selector css"><span class="entity other attribute-name class css"><span class="punctuation definition entity css">.</span>box</span> <span class="entity name tag css">h3</span> </span><span class="meta property-list css"><span class="punctuation section property-list css">{</span>
    <span class="meta property-name css"><span class="support type property-name css">text-align</span></span><span class="punctuation separator key-value css">:</span><span class="meta property-value css"> </span><span class="meta property-value css"><span class="support constant property-value css">center</span></span><span class="punctuation terminator rule css">;</span>
    <span class="meta property-name css"><span class="support type property-name css">position</span></span><span class="punctuation separator key-value css">:</span><span class="meta property-value css"> </span><span class="meta property-value css"><span class="support constant property-value css">relative</span></span><span class="punctuation terminator rule css">;</span>
    <span class="meta property-name css"><span class="support type property-name css">top</span></span><span class="punctuation separator key-value css">:</span><span class="meta property-value css"> </span><span class="meta property-value css"><span class="constant numeric css">80<span class="keyword other unit css">px</span></span></span><span class="punctuation terminator rule css">;</span>
</span><span class="punctuation section property-list css">}</span>
<span class="meta selector css"><span class="entity other attribute-name class css"><span class="punctuation definition entity css">.</span>box</span> </span><span class="meta property-list css"><span class="punctuation section property-list css">{</span>
    <span class="meta property-name css"><span class="support type property-name css">width</span></span><span class="punctuation separator key-value css">:</span><span class="meta property-value css"> </span><span class="meta property-value css"><span class="constant numeric css">70<span class="keyword other unit css">%</span></span></span><span class="punctuation terminator rule css">;</span>
    <span class="meta property-name css"><span class="support type property-name css">height</span></span><span class="punctuation separator key-value css">:</span><span class="meta property-value css"> </span><span class="meta property-value css"><span class="constant numeric css">200<span class="keyword other unit css">px</span></span></span><span class="punctuation terminator rule css">;</span>
    <span class="meta property-name css"><span class="support type property-name css">background</span></span><span class="punctuation separator key-value css">:</span><span class="meta property-value css"> </span><span class="meta property-value css"><span class="constant other color rgb-value css"><span class="punctuation definition constant css">#</span>fff</span></span><span class="punctuation terminator rule css">;</span>
    <span class="meta property-name css"><span class="support type property-name css">margin</span></span><span class="punctuation separator key-value css">:</span><span class="meta property-value css"> </span><span class="meta property-value css"><span class="constant numeric css">40<span class="keyword other unit css">px</span></span> <span class="support constant property-value css">auto</span></span><span class="punctuation terminator rule css">;</span>
</span><span class="punctuation section property-list css">}</span>
<span class="meta selector css"><span class="entity other attribute-name class css"><span class="punctuation definition entity css">.</span>effect2</span> </span><span class="meta property-list css"><span class="punctuation section property-list css">{</span>
    <span class="meta property-name css"><span class="support type property-name css">box-shadow</span></span><span class="punctuation separator key-value css">:</span><span class="meta property-value css"> </span><span class="meta property-value css"><span class="constant numeric css">10<span class="keyword other unit css">px</span></span> <span class="constant numeric css">10<span class="keyword other unit css">px</span></span> <span class="constant numeric css">5<span class="keyword other unit css">px</span></span> <span class="constant numeric css">-5<span class="keyword other unit css">px</span></span> <span class="meta function-call css"><span class="support function color css">rgba</span><span class="meta group css"><span class="punctuation definition group begin css">(</span><span class="constant numeric css">0</span><span class="punctuation separator css">,</span> <span class="constant numeric css">0</span><span class="punctuation separator css">,</span> <span class="constant numeric css">0</span><span class="punctuation separator css">,</span> <span class="constant numeric css">0.75</span></span><span class="meta group css"><span class="punctuation definition group end css">)</span></span></span></span><span class="punctuation terminator rule css">;</span>
</span><span class="punctuation section property-list css">}</span></span></code></pre>
<p>Try these box shadows out on your own and see how changing each shadow value works.</p>
<h2 id="css-flex-box"><span class="section-number-2">4.</span> CSS Flex Box</h2>
<p>Now, let's move on to the best part of this article: flex box. The flex box is by far my favorite new toy. I originally stumbled across this solution after looking for more efficient ways of centering content horizontally AND vertically. I had used other methods before, but flex box throws those out the window. The best part of it all is that flex box is <em>dead simple</em>.</p>
<p>Flex Box pertains to the parent div of any element. You want the parent to be the flex box and the children's behavior modified by the parent's attributes. It's easier to see this in action that explained, so let's see an example.</p>
<p><strong>Flex Box</strong></p>
<pre><code class="language-html highlight"><span class="text html basic"><span class="meta tag block any html"><span class="punctuation definition tag begin html">&lt;</span><span class="entity name tag block any html">div</span> <span class="meta attribute-with-value class html"><span class="entity other attribute-name class html">class</span><span class="punctuation separator key-value html">=</span></span><span class="meta attribute-with-value class html"><span class="string quoted double html"><span class="punctuation definition string begin html">&quot;</span></span></span><span class="meta attribute-with-value class html"><span class="string quoted double html"><span class="meta class-name html">flex-examples</span><span class="punctuation definition string end html">&quot;</span></span></span><span class="punctuation definition tag end html">&gt;</span></span>
    <span class="meta tag block any html"><span class="punctuation definition tag begin html">&lt;</span><span class="entity name tag block any html">div</span> <span class="meta attribute-with-value class html"><span class="entity other attribute-name class html">class</span><span class="punctuation separator key-value html">=</span></span><span class="meta attribute-with-value class html"><span class="string quoted double html"><span class="punctuation definition string begin html">&quot;</span></span></span><span class="meta attribute-with-value class html"><span class="string quoted double html"><span class="meta class-name html">sm-box</span><span class="punctuation definition string end html">&quot;</span></span></span><span class="punctuation definition tag end html">&gt;</span></span>
        <span class="meta tag block any html"><span class="punctuation definition tag begin html">&lt;</span><span class="entity name tag block any html">h3</span><span class="punctuation definition tag end html">&gt;</span></span>1<span class="meta tag block any html"><span class="punctuation definition tag begin html">&lt;/</span><span class="entity name tag block any html">h3</span><span class="punctuation definition tag end html">&gt;</span></span>
    <span class="meta tag block any html"><span class="punctuation definition tag begin html">&lt;/</span><span class="entity name tag block any html">div</span><span class="punctuation definition tag end html">&gt;</span></span>
    <span class="meta tag block any html"><span class="punctuation definition tag begin html">&lt;</span><span class="entity name tag block any html">div</span> <span class="meta attribute-with-value class html"><span class="entity other attribute-name class html">class</span><span class="punctuation separator key-value html">=</span></span><span class="meta attribute-with-value class html"><span class="string quoted double html"><span class="punctuation definition string begin html">&quot;</span></span></span><span class="meta attribute-with-value class html"><span class="string quoted double html"><span class="meta class-name html">sm-box</span><span class="punctuation definition string end html">&quot;</span></span></span><span class="punctuation definition tag end html">&gt;</span></span>
        <span class="meta tag block any html"><span class="punctuation definition tag begin html">&lt;</span><span class="entity name tag block any html">h3</span><span class="punctuation definition tag end html">&gt;</span></span>2<span class="meta tag block any html"><span class="punctuation definition tag begin html">&lt;/</span><span class="entity name tag block any html">h3</span><span class="punctuation definition tag end html">&gt;</span></span>
    <span class="meta tag block any html"><span class="punctuation definition tag begin html">&lt;/</span><span class="entity name tag block any html">div</span><span class="punctuation definition tag end html">&gt;</span></span>
<span class="meta tag block any html"><span class="punctuation definition tag begin html">&lt;/</span><span class="entity name tag block any html">div</span><span class="punctuation definition tag end html">&gt;</span></span></span></code></pre>
<pre><code class="language-css highlight"><span class="source css"><span class="meta selector css"><span class="entity other attribute-name class css"><span class="punctuation definition entity css">.</span>flex-examples</span> </span><span class="meta property-list css"><span class="punctuation section property-list css">{</span>
    <span class="meta property-name css"><span class="support type property-name css">display</span></span><span class="punctuation separator key-value css">:</span><span class="meta property-value css"> </span><span class="meta property-value css"><span class="support constant property-value css">flex</span></span><span class="punctuation terminator rule css">;</span>
    <span class="meta property-name css"><span class="support type property-name css">flex-wrap</span></span><span class="punctuation separator key-value css">:</span><span class="meta property-value css"> </span><span class="meta property-value css"><span class="support constant property-value css">wrap</span></span><span class="punctuation terminator rule css">;</span>
    <span class="meta property-name css"><span class="support type property-name css">justify-content</span></span><span class="punctuation separator key-value css">:</span><span class="meta property-value css"> </span><span class="meta property-value css"><span class="support constant property-value css">flex-start</span></span><span class="punctuation terminator rule css">;</span>
    <span class="meta property-name css"><span class="support type property-name css">align-items</span></span><span class="punctuation separator key-value css">:</span><span class="meta property-value css"> </span><span class="meta property-value css"><span class="support constant property-value css">center</span></span><span class="punctuation terminator rule css">;</span>
    <span class="meta property-name css"><span class="support type property-name css">padding</span></span><span class="punctuation separator key-value css">:</span><span class="meta property-value css"> </span><span class="meta property-value css"><span class="constant numeric css">10<span class="keyword other unit css">px</span></span></span><span class="punctuation terminator rule css">;</span>
    <span class="meta property-name css"><span class="support type property-name css">background-color</span></span><span class="punctuation separator key-value css">:</span><span class="meta property-value css"> </span><span class="meta property-value css"><span class="constant other color rgb-value css"><span class="punctuation definition constant css">#</span>f2f2f2</span></span><span class="punctuation terminator rule css">;</span>
</span><span class="punctuation section property-list css">}</span>
<span class="meta selector css"><span class="entity other attribute-name class css"><span class="punctuation definition entity css">.</span>sm-box</span> </span><span class="meta property-list css"><span class="punctuation section property-list css">{</span>
    <span class="meta property-name css"><span class="support type property-name css">display</span></span><span class="punctuation separator key-value css">:</span><span class="meta property-value css"> </span><span class="meta property-value css"><span class="support constant property-value css">flex</span></span><span class="punctuation terminator rule css">;</span>
    <span class="meta property-name css"><span class="support type property-name css">justify-content</span></span><span class="punctuation separator key-value css">:</span><span class="meta property-value css"> </span><span class="meta property-value css"><span class="support constant property-value css">center</span></span><span class="punctuation terminator rule css">;</span>
    <span class="meta property-name css"><span class="support type property-name css">align-items</span></span><span class="punctuation separator key-value css">:</span><span class="meta property-value css"> </span><span class="meta property-value css"><span class="support constant property-value css">center</span></span><span class="punctuation terminator rule css">;</span>
    <span class="meta property-name css"><span class="support type property-name css">width</span></span><span class="punctuation separator key-value css">:</span><span class="meta property-value css"> </span><span class="meta property-value css"><span class="constant numeric css">20<span class="keyword other unit css">%</span></span></span><span class="punctuation terminator rule css">;</span>
    <span class="meta property-name css"><span class="support type property-name css">height</span></span><span class="punctuation separator key-value css">:</span><span class="meta property-value css"> </span><span class="meta property-value css"><span class="constant numeric css">100<span class="keyword other unit css">px</span></span></span><span class="punctuation terminator rule css">;</span>
    <span class="meta property-name css"><span class="support type property-name css">background</span></span><span class="punctuation separator key-value css">:</span><span class="meta property-value css"> </span><span class="meta property-value css"><span class="constant other color rgb-value css"><span class="punctuation definition constant css">#</span>fff</span></span><span class="punctuation terminator rule css">;</span>
    <span class="meta property-name css"><span class="support type property-name css">margin</span></span><span class="punctuation separator key-value css">:</span><span class="meta property-value css"> </span><span class="meta property-value css"><span class="constant numeric css">40<span class="keyword other unit css">px</span></span> <span class="constant numeric css">10<span class="keyword other unit css">px</span></span></span><span class="punctuation terminator rule css">;</span>
</span><span class="punctuation section property-list css">}</span></span></code></pre>
<p>You may notice that we no longer need to use the <code class="verbatim">top</code> property for the <code class="verbatim">h3</code> elements in our code. This is because we set the display box to be a flex container for the small boxes, AND we made the small boxes flex containers for their elements (the h3 tags). You can nest flex boxes to center content that is inside centered content.</p>
<p>For the example above, we designated the <code class="verbatim">justify-content</code> property to be <code class="verbatim">flex-start</code> so that the boxes stack from the left side of the screen. You can change this property to <code class="verbatim">center</code> to make the boxes appear in the center of the screen.</p>
<p>For an interactive example, <a href="https://codepen.io/LandonSchropp/pen/KpzzGo">check out this CodePen</a> from <a href="https://codepen.io/LandonSchropp/">LandonScropp</a>. Resize the window with dice to see how they collapse and re-align.</p>
<h2 id="even-more-css"><span class="section-number-2">5.</span> Even More CSS</h2>
<p>For more inspiration, you can visit <a href="https://www.codepen.io">CodePen</a>, <a href="https://dribbble.com">Dribbble</a>, or <a href="https://uimovement.com">UI Movement</a> to browse the collections of amazing web designers.</p>
]]></description>
    </item>
    <item>
      <title>The C++ Compiler</title>
      <link>https://cleberg.net/blog/cpp-compiler.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/cpp-compiler.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Wed, 28 Nov 2018 00:00:00 +0000</pubDate>
      <category>linux</category>
      <description><![CDATA[<h2 id="a-brief-introduction"><span class="section-number-2">1.</span> A Brief Introduction</h2>
<p><a href="https://en.wikipedia.org/wiki/C%2B%2B">C++</a> is a general-purpose programming language with object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.</p>
<p>A developer must compile source code, such as the example shown in the snippet below, before they can execute the compiled program. There are numerous steps and intricacies to the compilation process, and this post was a personal exercise to learn and remember as much information as I can.</p>
<pre><code class="language-cpp highlight"><span class="source c++"><span class="meta preprocessor include c++"><span class="keyword control import include c++">#include</span> <span class="string quoted other lt-gt include c++"><span class="punctuation definition string begin c++">&lt;</span>iostream<span class="punctuation definition string end c++">&gt;</span></span>
</span>
<span class="storage type c">int</span> <span class="meta function c++"><span class="entity name function c++">main</span></span><span class="meta function parameters c++"><span class="meta group c++"><span class="punctuation section group begin c++">(</span></span></span><span class="meta function parameters c++"><span class="meta group c++"><span class="punctuation section group end c++">)</span></span></span><span class="meta function c++">
</span><span class="meta function c++"><span class="meta block c++"><span class="punctuation section block begin c++">{</span></span></span><span class="meta function c++"><span class="meta block c++">
    std<span class="punctuation accessor c++">::</span>cout <span class="keyword operator arithmetic c">&lt;&lt;</span> <span class="string quoted double c"><span class="punctuation definition string begin c">&quot;</span>Hello, world!<span class="constant character escape c">\n</span><span class="punctuation definition string end c">&quot;</span></span><span class="punctuation terminator c++">;</span>
</span></span><span class="meta function c++"><span class="meta block c++"><span class="punctuation section block end c++">}</span></span></span></span></code></pre>
<h3 id="compilation-process"><span class="section-number-3">1.1.</span> Compilation Process</h3>
<h4 id="an-overview"><span class="section-number-4">1.1.1.</span> An Overview</h4>
<p>Compiling C++ projects is a frustrating task most days. Seemingly nonexistent errors keeping your program from successfully compiling can be annoying (especially since you know you wrote it perfectly the first time, right?).</p>
<p>I'm learning more and more about C++ these days and decided to write this concept down so that I can cement it even further in my own head. However, C++ is not the only compiled language. Check out <a href="https://en.wikipedia.org/wiki/Compiled_language">the Wikipedia entry for compiled languages</a> for more examples of compiled languages.</p>
<p>I'll start with a wonderful, graphical way to conceptualize the C++ compiler. View <a href="https://web.archive.org/web/20190419035048/http://faculty.cs.niu.edu/~mcmahon/CS241/Notes/compile.html">The C++ Compilation Process</a> by Kurt MacMahon, a Northern Illinois University (NIU) professor, to see the graphic and an explanation. The goal of the compilation process is to take the C++ code and produce a shared library, dynamic library, or an executable file.</p>
<h3 id="compilation-phases"><span class="section-number-3">1.2.</span> Compilation Phases</h3>
<p>Let's break down the compilation process. There are four major steps to compiling C++ code.</p>
<h4 id="step-1"><span class="section-number-4">1.2.1.</span> Step 1</h4>
<p>The first step is to expand the source code file to meet all dependencies. The C++ preprocessor includes the code from all the header files, such as <code class="verbatim">#include &lt;iostream&gt;</code>. Now, what does that mean? The previous example includes the <code class="verbatim">iostream</code> header. This tells the computer that you want to use the <code class="verbatim">iostream</code> standard library, which contains classes and functions written in the core language. This specific header allows you to manipulate input/output streams. After all this, you'll end up with a temporary file that contains the expanded source code.</p>
<p>In the example of the C++ code above, the <code class="verbatim">iostream</code> class would be included in the expanded code.</p>
<h4 id="step-2"><span class="section-number-4">1.2.2.</span> Step 2</h4>
<p>After the compiler expands the code, the compiler comes into play. The compiler takes the C++ code and converts this code into the assembly language, understood by the platform. You can see this in action if you head over to the <a href="https://godbolt.org">GodBolt Compiler Explorer</a>, which shows the compiler converting C++ into assembly dynamically.</p>
<p>For example, the <code class="verbatim">Hello, world!</code> code snippet above compiles into the following assembly code:</p>
<pre><code class="language-asm">.LC0:
        .string "Hello, world!\n"
main:
        push    rbp
        mov     rbp, rsp
        mov     esi, OFFSET FLAT:.LC0
        mov     edi, OFFSET FLAT:_ZSt4cout
        call    std::basic_ostream&lt;char, std::char_traits&lt;char&gt; &gt;&amp; std::operator&lt;&lt; &lt;std::char_traits&lt;char&gt; &gt;(std::basic_ostream&lt;char, std::char_traits&lt;char&gt; &gt;&amp;, char const*)
        mov     eax, 0
        pop     rbp
        ret
__static_initialization_and_destruction_0(int, int):
        push    rbp
        mov     rbp, rsp
        sub     rsp, 16
        mov     DWORD PTR [rbp-4], edi
        mov     DWORD PTR [rbp-8], esi
        cmp     DWORD PTR [rbp-4], 1
        jne     .L5
        cmp     DWORD PTR [rbp-8], 65535
        jne     .L5
        mov     edi, OFFSET FLAT:_ZStL8__ioinit
        call    std::ios_base::Init::Init() [complete object constructor]
        mov     edx, OFFSET FLAT:__dso_handle
        mov     esi, OFFSET FLAT:_ZStL8__ioinit
        mov     edi, OFFSET FLAT:_ZNSt8ios_base4InitD1Ev
        call    __cxa_atexit
.L5:
        nop
        leave
        ret
_GLOBAL__sub_I_main:
        push    rbp
        mov     rbp, rsp
        mov     esi, 65535
        mov     edi, 1
        call    __static_initialization_and_destruction_0(int, int)
        pop     rbp
        ret</code></pre>
<h4 id="step-3"><span class="section-number-4">1.2.3.</span> Step 3</h4>
<p>Third, the compiler assembles the assembly code into the object code for the platform. Essentially, this is when the compiler takes the assembly code and assembles it into machine code in a binary format. After researching this online, I figured out that a lot of compilers will allow you to stop compilation at this step. This would be useful for compiling each source code file separately. This saves time later if a single file changes, since the developer will only need to re-compile a single file.</p>
<h4 id="step-4"><span class="section-number-4">1.2.4.</span> Step 4</h4>
<p>Finally, the compiler links the object code file generated by the assembler together with the object code files for any library functions used to produce a shared library, dynamic library, or an executable file. It replaces all references to undefined symbols with the correct addresses.</p>
]]></description>
    </item>
    <item>
      <title>AES Encryption</title>
      <link>https://cleberg.net/blog/aes-encryption.html</link>
      <guid isPermaLink="true">https://cleberg.net/blog/aes-encryption.html</guid>
      <author>hello@cleberg.net (Christian Cleberg)</author>
      <pubDate>Wed, 28 Nov 2018 00:00:00 +0000</pubDate>
      <category>security</category>
      <description><![CDATA[<h2 id="basic-aes"><span class="section-number-2">1.</span> Basic AES</h2>
<p>If you're not familiar with encryption techniques, the Advanced Encryption Standard (<a href="https://en.wikipedia.org/wiki/Advanced_Encryption_Standard">AES</a>) is a specification for encryption of electronic data. The National Institute of Standards and Technology established this specification, sub-selected from the Rijndael family of ciphers (128, 192, and 256 bits) in 2001. Furthering its popularity and status, the US government chose AES as their default encryption method for top-secret data, removing the previous standard which had been in place since 1977.</p>
<p>AES has proven to be a safe encryption method, with 7-round and 8-round attacks making no material improvements since the release of this encryption standard almost two decades ago.</p>
<blockquote>
<p>Though many papers have been published on the cryptanalysis of AES, the fastest single-key attacks on round-reduced AES variants [20, 33] so far are only slightly more powerful than those proposed 10 years ago [23,24].</p>
<ul>
<li><a href="http://research.microsoft.com/en-us/projects/cryptanalysis/aesbc.pdf">Bogdanov, et al.</a></li>
</ul>
</blockquote>
<h2 id="how-secure-is-aes"><span class="section-number-2">2.</span> How Secure is AES?</h2>
<p>In theory, AES-256 (AES using a 256-bit key) is non-crackable due to the massive number of combinations that can the encryption process can produce. However, AES-128 is no longer recommended as a viable implementation to protect important data due the 128-bit key's short length.</p>
<p>A semi-short <a href="http://www.moserware.com/2009/09/stick-figure-guide-to-advanced.html">comic strip</a> from Moserware quickly explains AES for the public to understand. Basically, AES encrypts the data by obscuring the relationship between the data and the encrypted data. Additionally, this method spreads the message out. Lastly, the key produced by AES is the secret to decrypting it. Someone may know the method of AES, but without the key, they are powerless.</p>
<p>To obscure and spread the data out, AES creates a substitution-permutation network. Wikipedia has a wonderful <a href="https://upload.wikimedia.org/wikipedia/commons/thumb/c/cd/SubstitutionPermutationNetwork2.png/468px-SubstitutionPermutationNetwork2.png">example of an SP network</a> available. This network sends the data through a set of S boxes (using the unique key) to substitute the bits with another block of bits. Then, a P box will permute, or rearrange, the bits. This is performed numerous times, with the last round deriving the key. For AES, the key size specifies the number of transformation rounds: 10, 12, and 14 rounds for 128-bit, 192-bit, and 256-bit keys, respectively.</p>
<h2 id="the-process"><span class="section-number-2">3.</span> The Process</h2>
<ol>
<li><strong>KeyExpansion</strong>: Using <a href="https://en.m.wikipedia.org/wiki/Advanced_Encryption_Standard">Rijndael's key schedule</a>, the keys are dynamically generated.</li>
<li><strong>AddRoundKey</strong>: The process combines each byte of the data with the generated key(s) using bitwise xor.</li>
<li><strong>SubBytes</strong>: Next, the process substitutes each byte of data.</li>
<li><strong>ShiftRows</strong>: Then, the process shifts the final three rows a specific number of steps, dictated by the cipher.</li>
<li><strong>MixColumns</strong>: Finally, the process mixes and combines the columns into the final data for this round of processing.</li>
</ol>
<p>This process does not necessarily stop after one full round. Steps 2 through 5 will repeat for the number of rounds specified by the key. However, the final round excludes the MixColumns step. As you can see, this is a fairly complex process. One must have a solid understanding of general mathematical principles to fully understand how the sequence works (and to even attempt to find a weakness).</p>
<p>According to research done by Bogdanov et al., it would take billions of years to brute force a 126-bit key with current hardware. Additionally, this brute force attack would require storing 2<sup>88</sup> bits of data! However, people have shown different attacks displaying vulnerabilities with the use of this technology. Side-channel attacks use inadvertent leaks of data from the hardware or software, which can allow attackers to obtain the key or run programs on a user's hardware.</p>
<p>Please note that this is not something you should run out and try to implement in your <code class="verbatim">Hello, World!</code> application after only hours of research. While AES (basically all encryption methods) is efficient in what it does, it takes a lot of time and patience to understand. If you're looking for something which currently implements AES, check out the <a href="https://www.bouncycastle.org/documentation.html">Legion of the Bouncy Castle</a> for Java implementations of cryptographic algorithms.</p>
<h2 id="why-does-encryption-matter"><span class="section-number-2">4.</span> Why Does Encryption Matter?</h2>
<p>There are limitless reasons to enable encryption at-rest or in-transit for aspects of your digital life. You can research specific examples, such as <a href="https://arstechnica.com/tech-policy/2018/12/australia-passes-new-law-to-thwart-strong-encryption/">Australia passes new law to thwart strong encryption</a>. However, I will simply list basic reasons to always enable encryption, where feasible:</p>
<ol>
<li>Privacy is a human right and some countries recognize it as a national right (e.g., <a href="https://www.law.cornell.edu/wex/fourth_amendment">US Fourth Amendment</a>).</li>
<li>"Why not?" Encryption rarely affects performance or speed, so there's usually not a reason to avoid it in the first place.</li>
<li>Your digital identity and activity (texts, emails, phone calls, online accounts, etc.) are valuable and can result in consequences, such as identity theft, if leaked to other parties. Encrypting this data prevents such leaks from ruining lives.</li>
<li>Wiping or factory-resetting does not actually wipe all data from the storage device. There are methods to read data from the physical disks/boards inside devices.</li>
<li>Corporations, governments, and other groups or individuals are actively looking for ways to collect personal information about anyone they can. If someone's data is not encrypted, that person may become a target due to the ease of data collection.</li>
</ol>
<h2 id="read-more"><span class="section-number-2">5.</span> Read More</h2>
<ul>
<li><a href="http://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.197.pdf">Federal Information Processing Standards Publication 197</a></li>
</ul>
]]></description>
    </item>
  </channel>
</rss>