Skip to content

Instantly share code, notes, and snippets.

@tsjk
Last active April 13, 2022 20:05
Show Gist options
  • Save tsjk/7f61370cb243ce04957993c9dc8f5b52 to your computer and use it in GitHub Desktop.
Save tsjk/7f61370cb243ce04957993c9dc8f5b52 to your computer and use it in GitHub Desktop.
OpenWRT v19.07.9 extroot image for the TP-Link TL-MR3420 V2 - the easy way
#!/bin/bash
BASENAME=$(basename "${0}"); DIRNAME=$(dirname "${0}"); DIRNAME=$(realpath "${DIRNAME}");
VERSION=$(grep -oP '(?<=imgbuilder-)[0-9\.]+(?=-)' <<< "${BASENAME}")
ARCH=$(sed -E 's@^imgbuilder-[0-9\.]+-@@' <<< "${BASENAME}" | grep -oP '^[^-]+')
TYPE=$(sed -E 's@^imgbuilder-[0-9\.]+-@@; s@'"${ARCH}"'-@@' <<< "${BASENAME}" | grep -oP '^[^\.]+')
[[ -n "${VERSION}" && -n "${ARCH}" && -n "${TYPE}" ]] || exit 255
[[ ! -x "${DIRNAME}/imgbuilder-get-base-path.sh" ]] || source "${DIRNAME}/imgbuilder-get-base-path.sh"
[[ -n "${OPENWRT_IMG_BUILDER_BASE_PATH}" ]] || OPENWRT_IMG_BUILDER_BASE_PATH="${DIRNAME}/openwrt-imagebuilder-${ARCH}-${TYPE}"
OPENWRT_IMG_BUILDER_PATH="${OPENWRT_IMG_BUILDER_BASE_PATH}/openwrt-imagebuilder-${VERSION}-${ARCH}-${TYPE}.Linux-x86_64"
if [[ "${ARCH}" == "ar71xx" ]]; then
_PROFILE="tl-mr3420-v2"
elif [[ "${ARCH}" == "ath79" ]]; then
_PROFILE="tplink_tl-mr3420-v2"
else exit 254; fi
# Unfortunately doesn't work for v21.x due to bloat one cannot opt out.
# v21.x extroot images can still be built using the build system, though.
if [[ "${VERSION}" =~ ^19\.07\..*$ ]]; then
_CONFIG_IPV6="y"; _PACKAGES="-kmod-ipt-offload -odhcpd-ipv6only -ppp -ppp-mod-pppoe block-mount f2fsck kmod-usb-storage kmod-fs-f2fs usb-modeswitch"
elif [[ "${VERSION}" =~ ^18\.06\..*$ ]]; then
_CONFIG_IPV6="y"; _PACKAGES="-kmod-ipt-offload -odhcpd-ipv6only -ppp -ppp-mod-pppoe block-mount f2fsck kmod-usb-storage kmod-fs-f2fs usb-modeswitch"
else exit 253; fi
[[ -n "${OPENWRT_IMG_BUILDER_BASE_PATH}" ]] && \
{ [[ -d "${OPENWRT_IMG_BUILDER_BASE_PATH}" ]] || mkdir "${OPENWRT_IMG_BUILDER_BASE_PATH}"; } && \
( cd "${OPENWRT_IMG_BUILDER_BASE_PATH}" && { \
[[ -d "openwrt-imagebuilder-${VERSION}-${ARCH}-${TYPE}.Linux-x86_64" ]] && \
( cd "openwrt-imagebuilder-${VERSION}-${ARCH}-${TYPE}.Linux-x86_64" && make clean ); \
} || { \
{ [[ -s "openwrt-imagebuilder-${VERSION}-${ARCH}-${TYPE}.Linux-x86_64.tar.xz" ]] || \
wget "https://downloads.openwrt.org/releases/${VERSION}/targets/${ARCH}/${TYPE}/openwrt-imagebuilder-${VERSION}-${ARCH}-${TYPE}.Linux-x86_64.tar.xz"; } && \
tar xJpf "openwrt-imagebuilder-${VERSION}-${ARCH}-${TYPE}.Linux-x86_64.tar.xz"; } ) && \
( cd "${OPENWRT_IMG_BUILDER_PATH}" && \
{ [[ ! -d "${DIRNAME}/${ARCH}/files" ]] || { rm -rf "${OPENWRT_IMG_BUILDER_PATH}/files" && cp -av "${DIRNAME}/${ARCH}/files" "${OPENWRT_IMG_BUILDER_PATH}"/; }; } && \
{ [[ "${VERSION}" != "19.07.9" ]] || export SOURCE_DATE_EPOCH=1; } && \
make image PROFILE="${_PROFILE}" CONFIG_IPV6="${_CONFIG_IPV6}" PACKAGES="${_PACKAGES}" FILES="files/" ) && \
set -x && \
[[ -s "${OPENWRT_IMG_BUILDER_PATH}/bin/targets/${ARCH}/${TYPE}/openwrt-${VERSION}-${ARCH}-${TYPE}-${_PROFILE}-squashfs-sysupgrade.bin" && \
-s "${OPENWRT_IMG_BUILDER_PATH}/bin/targets/${ARCH}/${TYPE}/openwrt-${VERSION}-${ARCH}-${TYPE}-${_PROFILE}-squashfs-factory.bin" && \
-s "${OPENWRT_IMG_BUILDER_PATH}/bin/targets/${ARCH}/${TYPE}/openwrt-${VERSION}-${ARCH}-${TYPE}-device-${_PROFILE//_/-}.manifest" ]] && \
cp -av "${OPENWRT_IMG_BUILDER_PATH}/bin/targets/${ARCH}/${TYPE}/openwrt-${VERSION}-${ARCH}-${TYPE}-${_PROFILE}-squashfs-sysupgrade.bin" \
"${OPENWRT_IMG_BUILDER_PATH}/bin/targets/${ARCH}/${TYPE}/openwrt-${VERSION}-${ARCH}-${TYPE}-${_PROFILE}-squashfs-factory.bin" \
"${OPENWRT_IMG_BUILDER_PATH}/bin/targets/${ARCH}/${TYPE}/openwrt-${VERSION}-${ARCH}-${TYPE}-device-${_PROFILE//_/-}.manifest" \
"${DIRNAME}"/
@tsjk
Copy link
Author

tsjk commented Apr 13, 2022

I have only tested ar71xx.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment