reorganize image-extras

This commit is contained in:
Attila Lendvai
2015-07-11 02:01:26 +02:00
parent e4bc40f366
commit 303454c221
10 changed files with 7 additions and 16 deletions

View File

@@ -0,0 +1,27 @@
config global
option anon_swap '0'
option anon_mount '0'
option auto_swap '0'
option auto_mount '0'
option delay_root '3'
option check_fs '0'
config swap
option uuid '05d615b3-bef8-460c-9a23-52db8d09e002'
option enabled '1'
config mount
option target '/overlay'
option uuid '05d615b3-bef8-460c-9a23-52db8d09e000'
option fstype 'ext4'
option options 'rw,noatime'
option enabled '1'
option enabled_fsck '0'
config mount
option target '/mnt/data'
option uuid '05d615b3-bef8-460c-9a23-52db8d09e001'
option fstype 'ext4'
option options 'rw,noatime'
option enabled '1'
option enabled_fsck '0'

View File

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

View File

@@ -0,0 +1,10 @@
/var/log/syslog
{
olddir archive
rotate 30
daily
dateext
notifempty
missingok
copytruncate
}

View File

@@ -0,0 +1,6 @@
# Put your custom commands here that should be executed once
# the system init finished. By default this file does nothing.
/root/autoprovision-stage1.sh
exit 0

View File

@@ -0,0 +1,99 @@
#!/bin/sh
# utility functions for the various stages of autoprovisioning
# make sure that installed packages take precedence over busybox. see https://dev.openwrt.org/ticket/18523
PATH="/usr/bin:/usr/sbin:/bin:/sbin"
# these are also copy-pasted into other scripts and config files!
rootUUID=05d615b3-bef8-460c-9a23-52db8d09e000
dataUUID=05d615b3-bef8-460c-9a23-52db8d09e001
swapUUID=05d615b3-bef8-460c-9a23-52db8d09e002
. /lib/ar71xx.sh
# let's try some defaults...
autoprovisionUSBLed="tp-link:green:usb"
autoprovisionStatusLed="tp-link:green:qss"
# 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"
;;
esac
log()
{
/usr/bin/logger -t autoprov -s $*
}
setLedAttribute()
{
[ -f "/sys/class/leds/$1/$2" ] && echo "$3" > "/sys/class/leds/$1/$2"
}
signalAutoprovisionWorking()
{
setLedAttribute ${autoprovisionStatusLed} trigger none
setLedAttribute ${autoprovisionStatusLed} trigger timer
setLedAttribute ${autoprovisionStatusLed} delay_on 2000
setLedAttribute ${autoprovisionStatusLed} delay_off 2000
}
signalAutoprovisionWaitingForUser()
{
setLedAttribute ${autoprovisionStatusLed} trigger none
setLedAttribute ${autoprovisionStatusLed} trigger timer
setLedAttribute ${autoprovisionStatusLed} delay_on 200
setLedAttribute ${autoprovisionStatusLed} delay_off 300
}
signalWaitingForPendrive()
{
setLedAttribute ${autoprovisionUSBLed} trigger none
setLedAttribute ${autoprovisionUSBLed} trigger timer
setLedAttribute ${autoprovisionUSBLed} delay_on 200
setLedAttribute ${autoprovisionUSBLed} delay_off 300
}
signalFormatting()
{
setLedAttribute ${autoprovisionUSBLed} trigger none
setLedAttribute ${autoprovisionUSBLed} trigger timer
setLedAttribute ${autoprovisionUSBLed} delay_on 1000
setLedAttribute ${autoprovisionUSBLed} delay_off 1000
}
stopSignallingAnything()
{
# TODO this is wrong, they should be restored to their original state.
# but then leds are only touched in the setup stage, which is ephemeral when things work as expected...
setLedAttribute ${autoprovisionStatusLed} trigger none
setLedAttribute ${autoprovisionUSBLed} trigger usbdev
}
setRootPassword()
{
local password=$1
if [ "$password" == "" ]; then
# set and forget a random password merely to disable telnet. login will go through ssh keys.
password=$(</dev/urandom sed 's/[^A-Za-z0-9+_]//g' | head -c 22)
fi
#echo "Setting root password to '"$password"'"
log "Setting root password"
echo -e "$password\n$password\n" | passwd root
}

View File

@@ -0,0 +1,137 @@
#!/bin/sh
# autoprovision stage 1: this script will be executed upon boot without a valid extroot (i.e. when rc.local is found and run from the internal overlay)
. /root/autoprovision-functions.sh
getPendriveSize()
{
# this is needed for the mmc card in some (all?) Huawei 3G dongle.
# 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
fi
if (grep -q sda /proc/partitions) then
cat /sys/block/sda/size
else
echo 0
fi
}
hasBigEnoughPendrive()
{
local size=$(getPendriveSize)
if [ $size -ge 600000 ]; then
log "Found a pendrive of size: $(($size / 2 / 1024)) MB"
return 0
else
return 1
fi
}
setupPendrivePartitions()
{
# erase partition table
dd if=/dev/zero of=/dev/sda bs=1M count=1
# sda1 is 'swap'
# sda2 is 'root'
# sda3 is 'data'
fdisk /dev/sda <<EOF
o
n
p
1
+64M
n
p
2
+512M
n
p
3
t
1
82
w
q
EOF
log "Finished partitioning /dev/sda using fdisk"
sleep 2
until [ -e /dev/sda1 ]
do
echo "Waiting for partitions to show up in /dev"
sleep 1
done
mkswap -L swap -U $swapUUID /dev/sda1
mkfs.ext4 -L root -U $rootUUID /dev/sda2
mkfs.ext4 -L data -U $dataUUID /dev/sda3
log "Finished setting up filesystems"
}
setupExtroot()
{
mkdir -p /mnt/extroot/
mount -U $rootUUID /mnt/extroot
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
# TODO FIXME when this is enabled then Chaos Calmer doesn't turn on the network and thus the device remains unreachable
# make sure that we shadow the /var -> /tmp symlink with the extroot, so that /var is permanent
# 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"
}
autoprovisionStage1()
{
signalAutoprovisionWorking
signalAutoprovisionWaitingForUser
signalWaitingForPendrive
until hasBigEnoughPendrive
do
echo "Waiting for a pendrive to be inserted"
sleep 3
done
signalAutoprovisionWorking # to make it flash in sync with the USB led
signalFormatting
sleep 1
setupPendrivePartitions
sleep 1
setupExtroot
sync
stopSignallingAnything
reboot
}
autoprovisionStage1

View File

@@ -0,0 +1,81 @@
#!/bin/sh
# autoprovision stage 2: this script will be executed upon boot if the extroot was successfully mounted (i.e. rc.local is run from the extroot overlay)
. /root/autoprovision-functions.sh
installPackages()
{
signalAutoprovisionWaitingForUser
until (opkg update)
do
log "opkg update failed. No internet connection? Retrying in 15 seconds..."
sleep 15
done
signalAutoprovisionWorking
log "Autoprovisioning stage2 is about to install packages"
# switch ssh from dropbear to openssh (needed to install sshtunnel)
#opkg remove dropbear
#opkg install openssh-server openssh-sftp-server sshtunnel
#/etc/init.d/sshd enable
#mkdir /root/.ssh
#chmod 0700 /root/.ssh
#mv /etc/dropbear/authorized_keys /root/.ssh/
#rm -rf /etc/dropbear
# CUSTOMIZE
# install some more packages that don't need any extra steps
opkg install lua luci ppp-mod-pppoe screen mc zip 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
/etc/init.d/uhttpd enable
}
autoprovisionStage2()
{
log "Autoprovisioning stage2 speaking"
# TODO this is a rather sloppy way to test whether stage2 has been done already, but this is a shell script...
if [ $(uci get system.@system[0].log_type) == "file" ]; then
log "Seems like autoprovisioning stage2 has been done already. Running stage3."
#/root/autoprovision-stage3.py
else
signalAutoprovisionWorking
# 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 ""
installPackages
crontab - <<EOF
# */10 * * * * /root/autoprovision-stage3.py
0 0 * * * /usr/sbin/logrotate /etc/logrotate.conf
EOF
mkdir -p /var/log/archive
# logrotate is complaining without this directory
mkdir -p /var/lib
uci set system.@system[0].log_type=file
uci set system.@system[0].log_file=/var/log/syslog
uci set system.@system[0].log_size=0
uci commit
sync
reboot
fi
}
autoprovisionStage2