Information Technology Grimoire

Version .0.0.1

IT Notes from various projects because I forget, and hopefully they help you too.

Hugo Github Reinstall

Computer Crashed, Now what?

My daily work computer crashed, and because of the computer requiring windows environment to fix the corrupt bios (or going through tremendous hassle), I was not able to easily repair it and it required a reinstall of the OS. As I’ve fought with the bios corruption a few times, I just decided to convert this particular computer to windows. A live boot USB allowed me to recover important files, which I then restored after I had installed windows and fixed the BIOS.

But now what?

Install Tools Needed

https://gohugo.io/installation/windows/ and followed install for Windows

Recreate SSH Keys, Then Overwrite Keys

I recreated ssh keys to make sure they would exist with permissions I expected, then copied my backups on top of them.

ssh-keygen -t ed25519 -C "your_email@example.com"

This created the files I expected in .ssh, which I then overwrote with my backup keys.

I could of also recreated keys in github, but I didn’t (settings > ssh keys)

Basic git Config and Test

$ ssh -T git@github.com
Enter passphrase for key '/c/Users/User/.ssh/id_ed25519':
Hi James! You've successfully authenticated, but GitHub does not provide shell access.

git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"

Github is connected, and I’m ready.

On my D:\ partition, I created a folder called “sites”, where I store all of my sites. My Repos on github all start with site.something so I can easily sort my sites from other projects. Your “site” can be named something different of course.

Overview of Restoring Sites

  • init so we can work with github
  • fetch from github
  • reset so fetch is not confused
  • remove files that cause clone errors
  • reinstall theme
  • check git status if you desire
  • start local server and edit files

The Script

I wrote a little bash script that works in git-scm bash to do this for each of the sites I manage:

#!/bin/bash

# Check if a directory name is provided
if [ -z "$1" ]; then
  echo "Usage: $0 <directory-name>"
  exit 1
fi

REPO_NAME=$1
THEME_URL="https://github.com/thingsym/hugo-theme-techdoc.git"
THEME_NAME="hugo-theme-techdoc"
GIT_REPO="git@github.com:rubysash/$REPO_NAME.git"

# Remove the existing directory if it exists (if needed)
#rm -Rf $REPO_NAME/

# Create a new Hugo site
hugo new site $REPO_NAME

# Navigate into the directory
cd $REPO_NAME/

# Initialize Git and set up remote
git init
git remote add origin $GIT_REPO

# Fetch and reset
git fetch origin
git reset --hard

# Remove default markdown to avoid conflicts
rm archetypes/default.md

# Pull from main branch
git pull origin main

# Remove Hugo configuration to avoid conflicts
rm hugo.toml

# Remove the existing theme directory if it exists in Git index
git rm -r --cached themes/$THEME_NAME
rm -rf .git/modules/themes/$THEME_NAME

# Clean up .gitmodules if it exists
if [ -f .gitmodules ]; then
  git config -f .gitmodules --remove-section submodule.themes/$THEME_NAME
fi
rm -rf themes/$THEME_NAME

# Add the theme as a submodule
git submodule add $THEME_URL themes/$THEME_NAME

# Initialize and update submodules
git submodule update --init --recursive

Script Output:

$ ./addsites.sh site.grimoire.jamesfraze
Congratulations! Your new Hugo site was created in D:\sites\site.grimoire.jamesfraze.

Just a few more steps...

1. Change the current directory to D:\sites\site.grimoire.jamesfraze.
2. Create or install a theme:
   - Create a new theme with the command "hugo new theme <THEMENAME>"
   - Or, install a theme from https://themes.gohugo.io/
3. Edit hugo.toml, setting the "theme" property to the theme name.
4. Create new content with the command "hugo new content <SECTIONNAME>\<FILENAME>.<FORMAT>".
5. Start the embedded web server with the command "hugo server --buildDrafts".

See documentation at https://gohugo.io/.
Initialized empty Git repository in D:/sites/site.grimoire.jamesfraze/.git/
Enter passphrase for key '/c/Users/User/.ssh/id_ed25519':
remote: Enumerating objects: 4216, done.
remote: Total 4216 (delta 0), reused 0 (delta 0), pack-reused 4216
Receiving objects: 100% (4216/4216), 38.03 MiB | 27.35 MiB/s, done.
Resolving deltas: 100% (2100/2100), done.
From github.com:rubysash/site.grimoire.jamesfraze
 * [new branch]      main       -> origin/main
Enter passphrase for key '/c/Users/User/.ssh/id_ed25519':
From github.com:rubysash/site.grimoire.jamesfraze
 * branch            main       -> FETCH_HEAD
Updating files: 100% (1378/1378), done.
rm 'themes/hugo-theme-techdoc'
Cloning into 'D:/sites/site.grimoire.jamesfraze/themes/hugo-theme-techdoc'...
remote: Enumerating objects: 2085, done.
remote: Counting objects: 100% (819/819), done.
remote: Compressing objects: 100% (230/230), done.
remote: Total 2085 (delta 543), reused 743 (delta 503), pack-reused 1266
Receiving objects: 100% (2085/2085), 5.40 MiB | 10.51 MiB/s, done.
Resolving deltas: 100% (1188/1188), done.
warning: in the working copy of '.gitmodules', LF will be replaced by CRLF the next time Git touches it

Normal Workflow

Your github repo is now cloned and synced on your local machine. You can now run the server and see your edits on http://localhost:1313

Start Hugo Local Server

hugo server --buildDrafts

or

hugo server --noHTTPCache --disableFastRender --port=1313

Make whatever edits you desire and watch as they appear on your local copy. Commit to git when you’re ready to publish to netlify CDN.

Git Workflow

git add .
git commit -m "describe your work"

Commit often, push sometimes. I use “main” instead of “master” so I push like this this the first time:

git push --set-upstream origin main

Every time afterwards I can push like this:

git push

Verify your branches with:

User@victus MINGW64 /d/sites/site.grimoire.jamesfraze (main)
$ git branch -r
  origin/main

Remaining Workflow

Netlify will grab from github and push to it’s CDN.

Presto, all done.