68 Commits

Author SHA1 Message Date
Attila Lendvai
0378f9ac40 housekeeping 2023-10-22 21:49:41 +02:00
Attila Lendvai
912ab6c5ea decrease memory need of dd while erasing the partition table
this was leading to the OOM killer killing dd.
2023-10-22 19:22:24 +02:00
Attila Lendvai
5eac25a701 readme 2023-09-24 15:47:05 +02:00
Attila Lendvai
f99d5f5f99 let ntpd fork and work in the background, and also retry regularly
i have witnessed a situation where opkg update didn't work due to
"Connection error: Invalid SSL certificate", which was in turn due
to wrong time on the router.

hopefully this will fix this situation for good.
2023-08-18 01:15:02 +02:00
Attila Lendvai
66a736508d update to use OpenWrt 22.03.5 2023-08-18 00:32:28 +02:00
Attila Lendvai
309e6dd80c use blockdev --rereadpt instead of sleep
FTR, this may not be needed. i have realized after this change that
the pendrive i was using was too small and fdisk errored out in a
way that was not visible in the log, only its symptoms.

but this is a nicer way than arbitrary sleeps for not much extra space.
2023-08-18 00:32:27 +02:00
Attila Lendvai
a21e995567 lower minimum pendrive size to ~100 Mb 2023-08-17 23:10:42 +02:00
Attila Lendvai
95201a77b3 fix archer-c7-v1 support, add missing ;; 2023-08-17 22:16:54 +02:00
Attila Lendvai
0c9ff42c17 use ln -sf to avoid a potentially confusing error message 2023-03-22 10:01:17 +01:00
Attila Lendvai
f23ce0d6bd build.sh adjust some syntax, make it more robust 2023-03-22 09:55:12 +01:00
Luiz Antonio Lazoti
b5ccc504d4 include archer-c7-v1 led settings
Signed-off-by: Attila Lendvai <attila@lendvai.name>
2023-03-22 09:45:45 +01:00
Attila Lendvai
ae7badd573 support removing packages using a SAVE_SPACE_PACKAGES variable
adapted from the patch by @luizoti in PR #21.
2023-03-22 09:41:20 +01:00
Attila Lendvai
1e35dda6bf change OpenWrt version to 22.03.3 2023-03-22 09:36:37 +01:00
Attila Lendvai
54ca610025 build.sh: use #!/usr/bin/env bash
this is a guix/nix compatible way to run it using bash.
2023-03-22 09:32:36 +01:00
Attila Lendvai
48794f78ab readme 2023-03-10 14:16:58 +01:00
Attila Lendvai
a14b56bd6e leds: use the same shell case entry for two very similar routers 2022-09-25 09:40:03 +02:00
ShapeShifter499
b313b20227 Add TP-Link TL-WDR3600 v1 LEDs
This solves https://github.com/attila-lendvai/openwrt-auto-extroot/issues/24
2022-09-25 09:37:36 +02:00
Lance
9060718dda Add WD My Net n750 LEDs
This solves https://github.com/attila-lendvai/openwrt-auto-extroot/issues/22
2022-09-22 17:12:39 +02:00
Attila Lendvai
a6ff005322 readme: add section about sysupgrade 2022-09-19 10:39:44 +02:00
Attila Lendvai
1d8ced0acb readme: OpenWRT -> OpenWrt 2022-09-19 10:39:19 +02:00
Attila Lendvai
b63b613949 updated to use the OpenWRT 22.03.0 release 2022-09-14 21:27:44 +02:00
Attila Lendvai
5efa008e3b small changes to make it work with openwrt 22.03.0-rc3 2022-06-03 21:54:21 +02:00
Attila Lendvai
41a0a93fde readme (one more example for a bit of variety) 2022-02-28 13:53:55 +01:00
Attila Lendvai
3d02057bb6 Updated to work on 21.02.0 2021-10-19 14:56:31 +02:00
Attila Lendvai
725caf2919 update to 19.07.6 2021-02-14 16:02:41 +01:00
Attila Lendvai
63806ccfe5 add shell.nix and make it work on nixos 2021-02-14 10:05:02 +01:00
Attila Lendvai
527bbf214c Update README.md 2021-01-12 14:21:18 +01:00
Attila Lendvai
74b2a4d989 readme: update openwrt wiki links, add some extra words 2020-12-03 21:16:01 +01:00
Attila Lendvai
7a39ab9adc readme 2020-11-29 23:43:14 +01:00
Attila Lendvai
f9cdbd39ef update for 19.07.4
no changes were needed, all seems to still work
2020-11-29 23:07:02 +01:00
Attila Lendvai
75b8e35aa7 fix the gitignore mess: git refuses to ignore already tracked files 2020-11-29 23:07:02 +01:00
Attila Lendvai
85e367523a update to openwrt 18.06.1
tested with ./build.sh ar71xx generic tl-wr1043nd-v1
2019-01-06 18:40:27 +01:00
Attila Lendvai
38a96e37e0 small note into the usage about the imagebuilder URL 2018-07-18 10:17:01 +02:00
Attila Lendvai
0381c6f40b small adjustments after the lede -> openwrt re-rename. 2018-06-26 23:26:25 +02:00
Martin Friedrich
a761fb7630 Changed to openwrt imagebuilder, back to release instead of snapshots 2018-06-26 22:40:35 +02:00
Martin Friedrich
e96f2d38cc Changed to openwrt imagebuilder, back to release instead of snapshots 2018-06-26 22:40:35 +02:00
Martin Friedrich
4a1e765a85 Changed README to openwrt imagebuilder (snapshot) 2018-06-26 22:40:35 +02:00
Martin Friedrich
31d0688c7c change to openwrt imagebuilder (snapshot) 2018-06-26 22:40:35 +02:00
Attila Lendvai
68a222edc6 small fix: creating the symping to packages dir at the end of the build. 2017-05-14 20:17:58 +02:00
Attila Lendvai
8e64a64186 Update README.md 2017-04-21 03:09:09 +02:00
Attila Lendvai
a02567b2fd Update readme for LEDE 2017-04-21 02:28:41 +02:00
Attila Lendvai
6d0547b26b update for LEDE release 17.01.1 2017-04-21 00:42:39 +02:00
Attila Lendvai
b8627f3eb3 build.sh now uses the lede-project.org imagebuilder 2016-12-12 18:39:04 +01:00
Attila Lendvai
027da763aa Update README.md
add note that it's linux x86_64 only
2016-08-25 15:00:49 +02:00
Sindhu S
37fd973cce Fix directory creation flags (#6)
--parents doesn't work and stalls the program. 
-pv is more correct.
2016-08-25 13:52:16 +02:00
Attila Lendvai
840c8298c8 Update README.md
note the changes to build.sh
2016-07-25 14:34:32 +02:00
Attila Lendvai
8faf47e902 extend build.sh to be able to build any architecture supported by openwrt 2016-07-25 14:17:08 +02:00
Attila Lendvai
6a8fae808e fix filename in build.sh 2016-03-17 17:35:39 +01:00
Attila Lendvai
1a6d86bb24 small factoring in build.sh 2016-03-17 15:22:22 +01:00
Attila Lendvai
e14ac06e8c make it one bit less ar71xx dependent 2016-03-17 15:19:47 +01:00
Attila Lendvai
798860d56d housekeeping 2016-03-17 14:59:39 +01:00
Attila Lendvai
0c5b94a0a0 change head -c to 1024 bytes, just in case. 2016-03-17 14:59:16 +01:00
Attila Lendvai
64c1557046 Merge pull request #3 from zetxx/master
read only first 10 bytes only
2016-03-17 14:56:20 +01:00
Elin Angelov
40ee59671c read only first 10 bytes only
read only first 10 bytes only because if we put MC with 16Gb e should wait a lot head to finish
2016-03-17 15:46:30 +02:00
Attila Lendvai
50f483c001 Update README.md 2016-01-01 14:55:53 +01:00
Attila Lendvai
515f96c3bb Update README.md
extended troubleshooting
2015-11-30 12:38:52 +01:00
Attila Lendvai
56ed68a95e separated the absolute needed packages in build.sh, added comments 2015-11-16 18:02:26 +01:00
Attila Lendvai
6c2be54cda Update README.md 2015-11-15 16:51:42 +01:00
Attila Lendvai
61c95f104b separated the crucial and optional package in build.sh 2015-11-15 16:42:06 +01:00
Attila Lendvai
d48956ff95 build.sh updated for final 15.05 chaos calmer release 2015-11-15 16:07:03 +01:00
Attila Lendvai
4efc9cb53a don't set a password, and delete my ssh public key 2015-11-14 08:18:09 +01:00
Attila Lendvai
cbf234800e Update README.md 2015-11-13 12:26:05 +01:00
Attila Lendvai
ca36ecdaaf Merge pull request #1 from lcafaro/master
added support for 15.05-rc3
2015-07-18 12:23:10 +02:00
Lorenzo Cafaro
38e15cbf3c added support for 15.05-rc3 2015-07-18 10:52:18 +02:00
Attila Lendvai
0c5f3f22b4 Update README.md
Added troubleshooting section with one note.
2015-07-11 04:17:18 +02:00
Attila Lendvai
303454c221 reorganize image-extras 2015-07-11 02:01:26 +02:00
Attila Lendvai
e4bc40f366 add a clear warning to the readme 2015-05-28 01:34:10 +02:00
Attila Lendvai
ba653bdaeb initial work towards chaos calmer rc1.
it works, but /var is left transient.
2015-05-28 00:55:04 +02:00
15 changed files with 296 additions and 133 deletions

1
.gitignore vendored
View File

@@ -1 +1,2 @@
notes.txt
build/

160
README.md
View File

@@ -1,56 +1,152 @@
# What
It's a script to build a customized OpenWRT firmware that will
automatically set up
[extroot](http://wiki.openwrt.org/doc/howto/extroot) on any (!)
storage device plugged into the USB port (`/dev/sda`).
It's a script to build a customized
[OpenWrt](https://openwrt.org/docs/guide-user/start)
firmware image using
[ImageBuilder](https://openwrt.org/docs/guide-user/additional-software/imagebuilder).
If the generated image is flashed on a router, then during its boot
process it will try to automatically set up
[extroot](https://openwrt.org/docs/guide-user/additional-software/extroot_configuration)
on **any (!)** storage device plugged into the USB port (`/dev/sda`),
including your already working extroot pendrive if you plug it in too
late in the boot process.
# Why
So that e.g. customers can buy a router on their own, flash our
So that e.g. customers can buy a router on their own, download and flash our custom
firmware, plug in a pendrive, and manage their SIP (telephony) node
from our webapp.
# Status
I've extracted the generic parts from the above mentioned auto-provision
project because I thought it's useful enough for making it public.
This is more of a template than something standalone. You most
probably want to customize this script here and there; search for
`CUSTOMIZE` for places of interest.
It also serves me well on my own routers ever since then.
I've extracted this from a project where OpenWRT nodes auto-provision
themselves in 3 stages, but I thought it's useful enough for making it
public (stage 1: extroot setup; stage 2: install packages; stage 3: a
Python script for app-level sync).
# How
At the time of writing it only supports a few `ar71xx` routers but
it's easy to extend it.
You can read more about the underlying technology on the OpenWrt wiki: see e.g. the
[ImageBuilder](https://openwrt.org/docs/guide-user/additional-software/imagebuilder)
page, or the page that lists some other
[ImageBuilder frontends](https://openwrt.org/docs/guide-developer/imagebuilder_frontends).
## Tested with
As for the actual mechanism: custom scripts are baked into the boot
process of the flashed firmware. If the extroot overlay is properly
set up, then these scripts get hidden by it; i.e. they will only be run
when the extroot has failed to mount early in the boot process.
[OpenWRT Barrier Breaker 14.07](http://downloads.openwrt.org/barrier_breaker/14.07/)
on a TP-Link WDR4300.
Keep in mind that **this will automatically erase/format any inserted
storage device while the router is in the initial setup phase**!
Unfortunately there's little that can be done at that point to ask the
user for confirmation.
# Building
### Building
e.g. `./build.sh TLWDR4300`
OpenWrt's ImageBuilder only works on Linux x86_64. To build a firmware, issue the following command:
`./build.sh architecture variant device-profile`, e.g.:
Results will be under `build/OpenWrt-ImageBuilder-ar71xx_generic-for-linux-x86_64`.
* `./build.sh ath79 generic tplink_tl-wr1043nd-v1`
* `./build.sh ath79 generic tplink_archer-c6-v2`
* `./build.sh ath79 generic tplink_tl-wdr4300-v1`
* `./build.sh bcm53xx generic dlink_dir-885l`
To see a list of available targets, run this in the ImageBuilder dir: ```make info```.
Results will be under `build/openwrt-imagebuilder-${release}-${architecture}-${variant}.Linux-x86_64/bin/`.
# Usage
To see a list of available targets, run `make info` in the ImageBuilder dir.
If you want to change which OpenWrt version is used, then try editing
the relevant variable(s) in `build.sh`. It's not guaranteed to work
across OpenWrt releases, therefore we keep git branches for the past
releases.
### Setup stages
Blinking leds show which phase the extroot setup scripts are in. Consult the
sources for details: [autoprovision-functions.sh](image-extras/common/root/autoprovision-functions.sh#L49).
#### Stage 1: setup extroot
When the custom firmware first boots, the autoprovision script will
wait for anything (!) in `/dev/sda` to show up (that is >= 512M), then erase
it and set up a `swap`, an `extroot`, and a `data`filesystem (for the remaining
space), and then reboot.
#### Stage 2: download and install some packages from the internet
Once it rebooted into the new extroot, it will continuously keep trying to install
some OpenWrt packages until an internet connection is set up on the router. You
need to do that manually either by using ssh or the web UI (LuCI).
#### Stage 3, optional
We also have a 3rd stage, written in Python, but it's commented out here.
Search for `autoprovision-stage3.py` to see how it's done.
### Login
After flashing the firmware the router will have the standard
`192.168.1.1` IP address, and SSH will listen there using the keys
specified in `image-extras/etc/dropbear/authorized_keys`.
`192.168.1.1` IP address.
By default the root passwd is not set, so the router will start telnet with
no password. If you want to set up a password, then edit the stage 2 script:
[autoprovision-stage2.sh](image-extras/common/root/autoprovision-stage2.sh#L53).
If a password is set, then telnet is disabled by OpenWrt and SSH will listen
using the keys specified in [authorized_keys](image-extras/common/etc/dropbear/authorized_keys).
Once connected, you can read the log with `logread -f`.
The autoprovision script will wait for any `/dev/sda` to show up, then
erase it and set up a `swap`, an `extroot`, and a `data` filesystem,
and then reboots.
# Status
In stage 2 it will need an internet connection, so you should connect
to its [LuCI interface](http://192.168.1.1) to set up an Internet
upstream, and then it will automatically continue installing packages,
finishing the whole process, and then do a final reboot.
This is more of a template than something standalone, but I use it for
my home routers as is. For more specific applications you most
probably want to customize this script here and there; search for
`CUSTOMIZE` for places of interest.
Most importantly, **set up a password and maybe add your ssh key** by
adding it to `image-extras/common/etc/dropbear/authorized_keys`.
None of this script is hardware specific except `setLedAttribute`,
which is used to provide feedback about the progress of the initial
setup phase. At the time of writing it only works on a few routers
(mostly `ath79` ones), but without this everything should work fine,
if only a bit less convenient.
# Troubleshooting
## Which file should I flash?
You should consult the [OpenWrt documentation](https://openwrt.org/docs/guide-user/start).
The produced firmware files should be somewhere around
```./build/openwrt-imagebuilder-21.02.0-ath79-generic.Linux-x86_64/bin/targets/ath79/generic/```.
In short:
* You need a file with the name ```-factory.bin``` or ```-sysupgrade.bin```. The former is to
be used when you first install OpenWrt, the latter is when you upgrade an already installed
OpenWrt.
* You must carefully pick the proper firmware file for your **hardware version**! I advise you
to look up the wiki page for your hardware on the [OpenWrt wiki](https://openwrt.org),
because most of them have a table of the released hardware versions with comments on their
status (sometimes new hardware revisions are only supported by the latest OpenWrt, which is
not released yet).
## Help! The build has finished but there's no firmware file!
If the build doesn't yield a firmware file (```*-factory.bin``` and/or ```*-sysupgrade.bin```):
when there's not enough space in the flash memory of the target device to install everything
then the OpenWrt ImageBuilder prints a hardly visible error into its flow of output and
silently continues. Look into [build.sh](build.sh#L31) and try to remove some packages
that you can live without.
## Extroot is not mounted after a `sysupgrade`
In short, this is an OpenWrt issue, and the solution is to mount the extroot
somewhere, and delete `/etc/.extroot-uuid`. More details are available in
[this issue](https://github.com/attila-lendvai/openwrt-auto-extroot/issues/12),
and a way to deal with it can be found in
[this blog post](https://blog.mbirth.de/archives/2014/05/26/openwrt-sysupgrade-with-extroot.html).
You may also want to check out the
[official OpenWrt wiki](https://openwrt.org/docs/guide-user/additional-software/extroot_configuration#system_upgrade)
on this topic.

103
build.sh
View File

@@ -1,59 +1,92 @@
#!/bin/bash
#!/usr/bin/env bash
# Note: this runs as-is, pretty much without external
# dependencies. The OpenWrt ImageBuilder contains the toolchain and
# everything that is needed to build the firmware images.
set -e
absolutize ()
{
if [ ! -d "$1" ]; then
echo
echo "ERROR: '$1' doesn't exist or not a directory!"
kill -INT $$
fi
TARGET_ARCHITECTURE=$1
TARGET_VARIANT=$2
TARGET_DEVICE=$3
pushd "$1" >/dev/null
echo `pwd`
popd >/dev/null
}
BUILD="$(dirname "${0}")/build/"
BUILD="$(readlink -f "${BUILD}")"
TARGET_PLATFORM=$1
###
### chose a release
###
RELEASE="22.03.5"
if [ -z ${TARGET_PLATFORM} ]; then
echo "Usage: $0 target-platform (e.g. 'TLWDR4300')"
IMGBUILDER_NAME="openwrt-imagebuilder-${RELEASE}-${TARGET_ARCHITECTURE}-${TARGET_VARIANT}.Linux-x86_64"
IMGBUILDER_DIR="${BUILD}/${IMGBUILDER_NAME}"
IMGBUILDER_ARCHIVE="${IMGBUILDER_NAME}.tar.xz"
IMGTEMPDIR="${BUILD}/image-extras"
# see this feature request:
# FS#1670 - consistent naming convention for the imagebuilder.tar.xz URL
# https://bugs.openwrt.org/index.php?do=details&task_id=1670
IMGBUILDERURL="https://downloads.openwrt.org/releases/${RELEASE}/targets/${TARGET_ARCHITECTURE}/${TARGET_VARIANT}/${IMGBUILDER_ARCHIVE}"
if [ -z ${TARGET_DEVICE} ]; then
echo "Usage: $0 architecture variant device-profile"
echo " e.g.: $0 ath79 generic tplink_tl-wr1043nd-v1"
echo " $0 ath79 generic tplink_archer-c6-v2"
echo " $0 ath79 generic tplink_tl-wdr4300-v1"
echo " $0 bcm53xx generic dlink_dir-885l"
echo " to get a list of supported devices issue a 'make info' in the OpenWRT image builder directory:"
echo " '${IMGBUILDER_DIR}'"
echo " the build results will be under '${IMGBUILDER_DIR}/bin/targets/'"
kill -INT $$
fi
BUILD=`dirname "$0"`"/build/"
BUILD=`absolutize $BUILD`
IMGTEMPDIR="${BUILD}/openwrt-build-image-extras"
IMGBUILDERDIR="${BUILD}/OpenWrt-ImageBuilder-ar71xx_generic-for-linux-x86_64"
IMGBUILDERURL="https://downloads.openwrt.org/barrier_breaker/14.07/ar71xx/generic/OpenWrt-ImageBuilder-ar71xx_generic-for-linux-x86_64.tar.bz2"
# the absolute minimum for extroot to work at all (i.e. when the disk is already set up, for example by hand).
# this list may be smaller and/or different for your router, but it works with my ath79.
# blockdev is needed to re-read the partition table using `blockdev --rereadpt /dev/sdX`
PREINSTALLED_PACKAGES="block-mount kmod-fs-ext4 kmod-usb-storage blockdev"
PREINSTALLED_PACKAGES="wireless-tools firewall iptables"
# some kernel modules may also be needed for your hardware
#PREINSTALLED_PACKAGES+=" kmod-usb-uhci kmod-usb-ohci"
# these are needed for the proper functioning of the auto extroot scripts
PREINSTALLED_PACKAGES+=" blkid mount-utils swap-utils e2fsprogs fdisk"
# the following packages are optional, feel free to (un)comment them
PREINSTALLED_PACKAGES+=" wireless-tools firewall4"
PREINSTALLED_PACKAGES+=" kmod-usb-storage-extras kmod-mmc"
PREINSTALLED_PACKAGES+=" ppp ppp-mod-pppoe ppp-mod-pppol2tp ppp-mod-pptp kmod-ppp kmod-pppoe"
PREINSTALLED_PACKAGES+=" fdisk blkid swap-utils mount-utils block-mount e2fsprogs kmod-fs-ext4 kmod-usb2 kmod-usb-uhci kmod-usb-ohci kmod-usb-storage kmod-usb-storage-extras kmod-mmc"
PREINSTALLED_PACKAGES+=" luci"
mkdir --parents ${BUILD}
# you exclude packages with this to shrink the image for
# routers with smaller flash storage.
# SAVE_SPACE_PACKAGES=" -ppp -ppp-mod-pppoe -ip6tables -odhcp6c -kmod-ipv6 -kmod-ip6tables -ath10k"
SAVE_SPACE_PACKAGES=""
rm -rf $IMGTEMPDIR
cp -r image-extras $IMGTEMPDIR
if [ -e image-extras.$TARGET_PLATFORM/ ]; then
rsync -pr image-extras.$TARGET_PLATFORM/ $IMGTEMPDIR/
PREINSTALLED_PACKAGES+=${SAVE_SPACE_PACKAGES}
mkdir -pv "${BUILD}"
rm -rf "${IMGTEMPDIR}"
cp -r image-extras/common/ "${IMGTEMPDIR}"
PER_PLATFORM_IMAGE_EXTRAS="image-extras/${TARGET_DEVICE}/"
if [ -e "${PER_PLATFORM_IMAGE_EXTRAS}" ]; then
rsync -pr "${PER_PLATFORM_IMAGE_EXTRAS}" "${IMGTEMPDIR}/"
fi
if [ ! -e ${IMGBUILDERDIR} ]; then
pushd ${BUILD}
wget --continue ${IMGBUILDERURL}
tar jvxf OpenWrt-ImageBuilder*.tar.bz2
if [ ! -e "${IMGBUILDER_DIR}" ]; then
pushd "${BUILD}"
# --no-check-certificate if needed
wget --continue "${IMGBUILDERURL}"
xz -d <"${IMGBUILDER_ARCHIVE}" | tar vx
popd
fi
pushd ${IMGBUILDERDIR}
pushd "${IMGBUILDER_DIR}"
make image PROFILE=${TARGET_PLATFORM} PACKAGES="${PREINSTALLED_PACKAGES}" FILES=${IMGTEMPDIR}
make image PROFILE=${TARGET_DEVICE} PACKAGES="${PREINSTALLED_PACKAGES}" FILES=${IMGTEMPDIR}
pushd bin/ar71xx/
ln -s ../../packages .
pushd "bin/targets/${TARGET_ARCHITECTURE}/"
ln -sf ../../../packages .
popd
popd

4
build/.gitignore vendored
View File

@@ -1,4 +0,0 @@
# Ignore everything in this directory
*
# Except this file
!.gitignore

19
default.nix Normal file
View File

@@ -0,0 +1,19 @@
{ pkgs ? import <nixpkgs> {} }:
pkgs.mkShell {
buildInputs = with pkgs; [
coreutils posix_man_pages bash-completion less
gitFull diffutils
gnumake which
ncurses perl python2 python3
# keep this line if you use bash
bashInteractive
];
shellHook =
''
alias ..='cd ..'
alias ...='cd ../..'
'';
}

View File

@@ -1,11 +0,0 @@
config interface 'loopback'
option ifname 'lo'
option proto 'static'
option ipaddr '127.0.0.1'
option netmask '255.0.0.0'
config interface 'lan'
option ifname 'eth0'
option type 'bridge'
option proto 'dhcp'

View File

@@ -0,0 +1 @@
# this is just a file to show how platform specific image extras can be specified

View File

@@ -0,0 +1,3 @@
# you can put your ssh public key into authorized_keys,
# but we don't ever want it to be committed to the repo
authorized_keys

View File

@@ -10,32 +10,43 @@ rootUUID=05d615b3-bef8-460c-9a23-52db8d09e000
dataUUID=05d615b3-bef8-460c-9a23-52db8d09e001
swapUUID=05d615b3-bef8-460c-9a23-52db8d09e002
. /lib/ar71xx.sh
. /lib/functions.sh
# let's try some defaults...
autoprovisionUSBLed="tp-link:green:usb"
autoprovisionStatusLed="tp-link:green:qss"
# let's attempt to define some defaults...
autoprovisionUSBLed="green:usb"
autoprovisionStatusLed="green:qss"
echo Board name is [$(board_name)]
# CUSTOMIZE
case $(ar71xx_board_name) in
"tl-wr1043nd")
autoprovisionUSBLed="tp-link:green:usb"
autoprovisionStatusLed="tp-link:green:qss"
;;
"tl-mr3020")
autoprovisionUSBLed="tp-link:green:wps"
autoprovisionStatusLed="tp-link:green:wlan"
;;
"tl-wr2543n")
autoprovisionUSBLed="tp-link:green:wps"
autoprovisionStatusLed="tp-link:green:wlan5g"
;;
"tl-wdr4300")
autoprovisionUSBLed="tp-link:blue:wan"
autoprovisionStatusLed="tp-link:blue:qss"
;;
case $(board_name) in
*tl-wr1043nd*)
autoprovisionUSBLed="green:usb"
autoprovisionStatusLed="green:qss"
;;
*tl-mr3020*)
autoprovisionUSBLed="green:wps"
autoprovisionStatusLed="green:wlan"
;;
*tl-wr2543n*)
autoprovisionUSBLed="green:wps"
autoprovisionStatusLed="green:wlan5g"
;;
*tl-wdr3600* | *tl-wdr4300*)
autoprovisionUSBLed="green:wlan2g"
autoprovisionStatusLed="green:wlan5g"
;;
*mynet-n750*)
autoprovisionUSBLed="blue:wps"
autoprovisionStatusLed="blue:wireless"
;;
*archer-c7-v1*)
autoprovisionUSBLed="green:wlan2g"
autoprovisionStatusLed="green:wlan5g"
;;
esac
log()
{
/usr/bin/logger -t autoprov -s $*

View File

@@ -10,7 +10,7 @@ getPendriveSize()
# details: https://dev.openwrt.org/ticket/10716#comment:4
if [ -e /dev/sda ]; then
# force re-read of the partition table
head /dev/sda >/dev/null
head -c 1024 /dev/sda >/dev/null
fi
if (grep -q sda /proc/partitions) then
@@ -23,7 +23,7 @@ getPendriveSize()
hasBigEnoughPendrive()
{
local size=$(getPendriveSize)
if [ $size -ge 600000 ]; then
if [ $size -ge 100000 ]; then
log "Found a pendrive of size: $(($size / 2 / 1024)) MB"
return 0
else
@@ -31,14 +31,24 @@ hasBigEnoughPendrive()
fi
}
rereadPartitionTable()
{
log "Rereading partition table"
blockdev --rereadpt /dev/sda
}
setupPendrivePartitions()
{
log "Erasing partition table"
# erase partition table
dd if=/dev/zero of=/dev/sda bs=1M count=1
dd if=/dev/zero of=/dev/sda bs=1k count=256
rereadPartitionTable
log "Creating partitions"
# sda1 is 'swap'
# sda2 is 'root'
# sda3 is 'data'
# sda3 is 'data', if there's any space left
fdisk /dev/sda <<EOF
o
n
@@ -64,7 +74,7 @@ q
EOF
log "Finished partitioning /dev/sda using fdisk"
sleep 2
rereadPartitionTable
until [ -e /dev/sda1 ]
do
@@ -73,38 +83,37 @@ EOF
done
mkswap -L swap -U $swapUUID /dev/sda1
mkfs.ext4 -L root -U $rootUUID /dev/sda2
mkfs.ext4 -L data -U $dataUUID /dev/sda3
mkfs.ext4 -F -L root -U $rootUUID /dev/sda2
mkfs.ext4 -F -L data -U $dataUUID /dev/sda3
log "Finished setting up filesystems"
}
setupExtroot()
{
mkdir -p /mnt/extroot
# TODO they said on the wiki that it's optional, an empty overlay also works...
# we need to make the internal overlay read-only, otherwise the two md5's may be different
# due to writing to the internal overlay from this point until the reboot.
# files: /.extroot.md5sum (extroot) and /etc/extroot.md5sum (internal)
#mount -o remount,ro /
#log "Remounted / as read-only"
mkdir -p /mnt/extroot/
mount -U $rootUUID /mnt/extroot
#tar -C /overlay -cvf - . | tar -C /mnt/extroot -xf -
# let's write a new rc.local on extroot which will shadow the one which is in the rom and runs stage1
mkdir -p /mnt/extroot/etc/
cat >/mnt/extroot/etc/rc.local <<EOF
overlay_root=/mnt/extroot/upper
# at this point we could copy the entire root (a previous version of this script did that), or just the overlay from the flash,
# but it seems to work fine if we just create an empty overlay that is only replacing the rc.local from the firmware.
# let's write a new rc.local on the extroot that will shadow the one which is in the rom (to run stage2 instead of stage1)
mkdir -p ${overlay_root}/etc/
cat >${overlay_root}/etc/rc.local <<EOF
/root/autoprovision-stage2.sh
exit 0
EOF
# make sure that we shadow the /var -> /tmp symlink with the extroot, so that /var is permanent
mkdir -p /mnt/extroot/var
# KLUDGE: but /var/state is assumed to be transient, see https://dev.openwrt.org/ticket/12228
cd /mnt/extroot/var
ln -s /tmp state
cd -
# TODO FIXME when this below is enabled then Chaos Calmer doesn't turn on the network and the device remains unreachable
# make sure that we shadow the /var -> /tmp symlink in the new extroot, so that /var becomes persistent across reboots.
# mkdir -p ${overlay_root}/var
# KLUDGE: /var/state is assumed to be transient, so link it to tmp, see https://dev.openwrt.org/ticket/12228
# cd ${overlay_root}/var
# ln -s /tmp state
# cd -
log "Finished setting up extroot"
}

View File

@@ -9,9 +9,11 @@ installPackages()
signalAutoprovisionWaitingForUser
until (opkg update)
do
do
log "opkg update failed. No internet connection? Retrying in 15 seconds..."
sleep 15
# Initiate a synchronous time update.
ntpd -d -q -n -p openwrt.pool.ntp.org
done
signalAutoprovisionWorking
@@ -30,12 +32,12 @@ installPackages()
# CUSTOMIZE
# install some more packages that don't need any extra steps
opkg install lua luci ppp-mod-pppoe screen mc zip unzip logrotate
opkg install lua luci ppp-mod-pppoe screen mc unzip logrotate
# this is needed for the vlans on tp-link 3020 with only a single hw ethernet port
opkg install kmod-macvlan ip
# just in case if we were run in a firmware that didn't already had luci
# just in case if we were run in a firmware that didn't already have luci
/etc/init.d/uhttpd enable
}
@@ -50,11 +52,15 @@ autoprovisionStage2()
else
signalAutoprovisionWorking
log "Starting ntpd to update system time; otherwise the openwrt.org certificates are rejected as not yet valid."
# Added -l hoping that it may help against ntpd quitting.
ntpd -l -N -p openwrt.pool.ntp.org
# CUSTOMIZE: with an empty argument it will set a random password and only ssh key based login will work.
# please note that stage2 requires internet connection to install packages and you most probably want to log in
# on the GUI to set up a WAN connection. but on the other hand you don't want to end up using a publically
# available default password anywhere, therefore the random here...
setRootPassword ""
#setRootPassword ""
installPackages

View File

@@ -1 +0,0 @@
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAu9Nwb8tr91hvChHSjEbyS3P0c1+jKtKAdaFCRkyUjVwgCpuzDxiq0auuNulYIfD2oc+THJ6zymJUjWNrVipeUo8BmKkDSMgN0Qf5PlwcSiIj9vDbLqxmVnnvB6xGEROO215Y8XzMOgq8r3Z3WqRUZIeFDHC2sSwJKO3INgsLZd6IoDiM7Dza8pKzYPfY7jJ19JmK4S8lHG3YsoxTy2zkcwCI20sBekJU0iDGvOOJq5UbIumKsAm2uJkMKsKlxkDQr0Y+2J1l0iWBrUHonja6CieO5yNBWluA3DCqxa0pQW3dcOju3mGCQl0j8+3Iblu8lCGoQVSLQ3rUhekmz+cB2Q== alendvai laptop ssh key