Skip to content

Commit fce31f0

Browse files
committed
Add update command
1 parent fe6ecf8 commit fce31f0

2 files changed

Lines changed: 34 additions & 1 deletion

File tree

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ That's it!
1818
- **pandoc** - for the actual heavy lifting
1919
- **python3** (optional) - for the dev server (`start` command)
2020
- **fswatch** (optional) - for instant rebuilds during development
21+
- **curl** or **wget** (optional) - for self-updating
2122

2223
## Usage
2324

@@ -33,6 +34,9 @@ That's it!
3334

3435
# Watch, rebuild, and serve at http://localhost:8000
3536
./blurt start
37+
38+
# Update to the latest version
39+
./blurt update
3640
```
3741

3842
## Structure

blurt

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,31 @@ FEED_HEADER
153153
echo "Built site in $DIST ($(($(now_ms) - build_start))ms)"
154154
}
155155
156+
cmd_update() {
157+
remote_url="https://raw.githubusercontent.com/shkm/blurt/main/blurt"
158+
tmp_file=$(mktemp)
159+
trap "rm -f '$tmp_file'" EXIT
160+
161+
echo "Fetching latest version..."
162+
if command -v curl >/dev/null 2>&1; then
163+
curl -fsSL "$remote_url" -o "$tmp_file"
164+
elif command -v wget >/dev/null 2>&1; then
165+
wget -qO "$tmp_file" "$remote_url"
166+
else
167+
echo "curl or wget is required for update"
168+
exit 1
169+
fi
170+
171+
if [ ! -s "$tmp_file" ] || ! head -1 "$tmp_file" | grep -q '^#!/bin/sh'; then
172+
echo "Failed to download valid script"
173+
exit 1
174+
fi
175+
176+
cp "$tmp_file" "$0"
177+
chmod +x "$0"
178+
echo "Updated blurt to latest version"
179+
}
180+
156181
cmd_start() {
157182
if ! command -v python3 >/dev/null 2>&1; then
158183
echo "python3 is required for the dev server"
@@ -195,11 +220,15 @@ case "$1" in
195220
start)
196221
cmd_start "$2"
197222
;;
223+
update)
224+
cmd_update
225+
;;
198226
*)
199-
echo "Usage: blurt <new|build|start>"
227+
echo "Usage: blurt <new|build|start|update>"
200228
echo " new [-e] \"Title\" - Create a new post"
201229
echo " build - Build the site"
202230
echo " start [port] - Watch, rebuild, and serve (default: 8000)"
231+
echo " update - Update blurt to latest version"
203232
exit 1
204233
;;
205234
esac

0 commit comments

Comments
 (0)