🍓 Raspberry Pi Lab - sudo apt update and sudo apt upgrade

This week I used ChatGPT to build a small maintenance utility for Raspberry Pi OS.

🍓 Raspberry Pi Lab - sudo apt update and sudo apt upgrade

#RaspberryPi Bash #Linux


Podcast 🎧 • Video 📽 • Short 📽


Overview

This week I used ChatGPT to build a small maintenance utility for Raspberry Pi OS.

The project's purpose was straightforward: create a Bash script that refreshes package information, upgrades installed software, presents a clean terminal interface, and records everything to a log file.


Not a Tutorial

This article is not a tutorial.

Instead, it's a build report documenting exactly what I built, how I prompted the AI, how I reviewed the generated code, what I changed, and what I learned during the process.

If you decide to build or run something similar, review the generated code carefully and make sure you understand every command before executing it. My goal here is to document my engineering process—not to suggest that anyone should blindly run AI-generated code.


Objective

The project had four simple goals.

  • Build a clean Bash utility.
  • Display a friendly terminal interface.
  • Record execution in a log file.
  • Review the generated code before running it.

The Bash itself wasn't the interesting part.
The engineering workflow was.


Design Goals

The script should:

  • Refresh the package database.
  • Upgrade installed software.
  • Display clear progress messages.
  • Stop if a command fails.
  • Produce a timestamped log file.
  • Remain small enough to understand in one screen of code.

Simple software tends to be easier to review, easier to trust, and easier to maintain.


Prompt #1 - Build the Script

The first prompt was intentionally simple.

Create a Bash script for Raspberry Pi OS that refreshes package information
using sudo apt update, upgrades installed packages using sudo apt upgrade,
displays a clean terminal interface with progress messages, exits on errors,
and writes execution details to a timestamped log file.

Within seconds the AI produced a complete first draft.
That became Version 1.


Generated Script

#!/bin/bash

set -e

LOGFILE="$HOME/pi-maintenance-$(date +%Y-%m-%d_%H-%M-%S).log"

exec > >(tee -a "$LOGFILE") 2>&1

echo "========================================"
echo " Raspberry Pi Maintenance Utility"
echo "========================================"
echo
echo "Hostname : $(hostname)"
echo "Date     : $(date)"
echo

echo "Refreshing package information..."
sudo apt update

echo
echo "Installing available updates..."
sudo apt upgrade -y

echo
echo "Maintenance completed successfully."

echo
echo "Log file saved to:"
echo "$LOGFILE"

Even before running the script, there was plenty to evaluate.


Prompt #2 - Review the Script

Rather than immediately executing the code, I asked the AI to perform a second job.

Review this Bash script as though you are performing a professional Linux
code review. Identify safety concerns, security issues, edge cases,
error handling, logging improvements, portability concerns,
maintainability issues, and opportunities to simplify the design.
Do not rewrite the script unless absolutely necessary.
Explain your reasoning.

I find this second prompt at least as valuable as the first. 
Generating software is becoming routine.
Evaluating software remains an engineering discipline.


Review Findings

The review identified several discussion points.

Area Observation
Overall design Clean and readable
Safety Suitable for manual execution
Logging Good foundation; could include more system details
Error handling set -e prevents continuing after failures
User interaction Could ask for confirmation before upgrading
Maintainability Short, understandable, easy to extend
Future enhancements Disk checks, reboot detection, colored output, dry-run mode

None of these observations prevented the script from running.

Several, however, made a future Version 2 an obvious improvement over Version 1.


Human Review

After reading the AI's assessment, I performed my own review.

Questions I asked included:

  • Do I understand every command?
  • Is anything happening automatically that shouldn't?
  • Would I be comfortable scheduling this script with cron later?
  • Does the log contain enough information for troubleshooting?
  • Could another Raspberry Pi owner understand what this script is doing?

Only after answering those questions did I decide to execute it.


Running the Script

The script was saved locally, made executable, and launched manually.

$ chmod +x pi-maintenance.sh

$ ./pi-maintenance.sh

========================================
 Raspberry Pi Maintenance Utility
========================================

Hostname : raspberrypi
Date     : Sat Jul 25 09:14:37 CDT 2026

Refreshing package information...

Hit:1 http://archive.raspberrypi.com/debian bookworm InRelease
Hit:2 http://deb.debian.org/debian bookworm InRelease

Reading package lists...
Building dependency tree...
Reading state information...

Installing available updates...

12 packages upgraded.

Maintenance completed successfully.

Log file saved to:
/home/pi/pi-maintenance-2026-07-25_09-14-37.log

The important point is that I chose to execute the script. 
The AI generated the code. 
The AI reviewed the code. 
The human accepted responsibility for running the code. 
That feels like a healthy engineering workflow.  


Sample Log File

One of my favorite additions was automatic logging.

========================================
Pi Maintenance Utility
========================================

Run Started:
2026-07-25 09:14:37

Hostname:
raspberrypi

User:
pi

Updating package information...
SUCCESS

Installing available updates...
SUCCESS

Packages upgraded:
12

Run completed successfully.

Elapsed time:
1 minute 43 seconds

========================================

A log file transforms a simple utility into something much easier to troubleshoot and improve over time.


Testing Environment

Hardware:

  • Raspberry Pi 5
  • 8 GB RAM

Operating System:

  • Raspberry Pi OS Bookworm

Execution:

  • Manual terminal launch

Status:

  • Successful

Lessons Learned

The biggest surprise wasn't that AI could write Bash.
That part is becoming expected.
The more interesting discovery was how valuable AI became as a reviewer.

One prompt generated the code.
A second prompt critiqued the code.
Finally, a human reviewed both before anything was executed.

That sequence resembles a traditional software workflow more than the popular image of "vibe coding."

The result wasn't simply a script.
It was a documented engineering process.


Ideas for Version 2

Possible improvements include:

  • Colored terminal output
  • Internet connectivity test
  • Available disk space check
  • Reboot-required detection
  • Optional confirmation before upgrading
  • JSON log output
  • Email notification after completion
  • Dry-run mode
  • Automatic log rotation

Each enhancement is small on its own.

Together, they turn a basic maintenance script into a more polished system utility.


Final Thoughts

There's no shortage of AI-generated code on the Internet.
What's still relatively uncommon is documenting everything that happens after the code appears.

That's the purpose of these Build Reports.

The prompts matter.
The review matters.
The testing matters.
The log files matter.

Most of all, the engineering judgment matters.

The AI wrote a useful first draft.
The review improved it.

The human made the final decision.
That's a workflow I expect to use again.


Build Information

Project:
Pi Maintenance Utility

Category:
System Administration

Language:
Bash

Platform:
Raspberry Pi OS

AI Assistant:
ChatGPT

Development Approach:
Prompt → Generate → Review → Refine → Execute → Document

Estimated Development Time:
Approximately 20 minutes

Status:
Working

Difficulty:
Beginner

Tech Reader Labs:
Build Report #001





Aaron Rose is a software engineer and technology writer at tech-reader.blog

Catch up on the latest explainer videos, podcasts, and industry discussions below.


Popular posts from this blog

Insight: The Great Minimal OS Showdown—DietPi vs Raspberry Pi OS Lite

Running AI Models on Raspberry Pi 5 (8GB RAM): What Works and What Doesn't