#!/bin/sh

# build_custom_openwrt_image.sh
# 2024-07-21
# by Gernot WALZL

# https://openwrt.org/docs/guide-user/additional-software/imagebuilder
# "make info" shows a list of available profiles.
# Unfortunately, luci (the web interface) is not part of the default packages.

VERSION=${VERSION:-"23.05.4"}
PROFILE=${PROFILE:-"linksys_wrt3200acm"}
PACKAGES=${PACKAGES:-"luci-ssl ddns-scripts luci-app-ddns etherwake luci-app-wol kmod-usb-storage block-mount kmod-fs-ext4 samba4-server luci-app-samba4 openssh-sftp-server"}

set -e

IMAGEBUILDER="openwrt-imagebuilder-${VERSION}-mvebu-cortexa9.Linux-x86_64.tar.xz"
DOWNLOAD="https://downloads.openwrt.org/releases/${VERSION}/targets/mvebu/cortexa9/${IMAGEBUILDER}"

if [ ! -f "$IMAGEBUILDER" ]; then
  wget -O "$IMAGEBUILDER" "$DOWNLOAD"
fi
tar xvf "$IMAGEBUILDER"
cd "openwrt-imagebuilder-${VERSION}-mvebu-cortexa9.Linux-x86_64"
make image PROFILE="$PROFILE" PACKAGES="$PACKAGES"
cat bin/targets/mvebu/cortexa9/sha256sums
find bin/targets/mvebu/cortexa9/ -type f