a simple script to prevent bricking for openwrt

八 12th, 2011
root@OpenWrt:~# cat /etc/init.d/unbrick 
#!/bin/sh /etc/rc.common
 
START=20
 
bakcat() {
	for i in $* ; do
		echo "################file seperator for $i##################"
		cat $i
		echo
	done
}
 
revert() {
	echo revert config...
	bakcat /etc/config/* >/root/cfgbak.all 2>&1
	cp -R /root/cfgbak/* /etc/config/
}
 
start() {
	count=$(cat /root/count_file)
	if [ $count -eq 0 ] ; then
		revert
	fi
	count=$((count-1))
	echo $count > /root/count_file
}
 
root@OpenWrt:~# /etc/init.d/unbrick enable
root@OpenWrt:~# echo 3 >  /root/count_file 
root@OpenWrt:~# mkdir /root/cfgbak

before modifying files in /etc/config, put an usable copy in /root/cfgbak.
if the script can run perfectly, echo 3 > /root/count_file after every reboot.
disable this script if the config files are valid and need no more change.
if any config file is wrong, reboot 3 times to unblick.

标签:
  1. Stephanie D. Rogers
    九 19th, 201113:27

    Thanks for sharing this source code. I’m sure that this could help me a lot. You truly save my day,a big thanks to you for sharing your knowledge to us.

  2. Hoervey Shui
    十 13th, 201110:11

    Truly impressive blog. Seemingly I am enjoying reading that content on this blog. Thanks!

  3. Estelle V. Cleveland
    十 13th, 201110:17

    The codes you provide in this post are very useful and helpful to me and also to others :) . i’m sure many of us are very thankful that there is still a person who always share their knowledge to us like you :) .

  4. Jessie
    十 13th, 201110:20

    Perhaps that last step was a bit over-confident, although I’ve upgraded Asus boxes many times this way (albeit not to this SVN code). I also forgot to check whether boot_wait was on or off before doing this.

  5. jenny.adlaon
    十 26th, 201114:30

    The codes that you post are so useful and really helps me a lot. Thanks for the post!

  6. Dancel Del Jerte
    十 27th, 201112:53

    I’m sure many of us are very thankful that there is still a person who always share their knowledge towards the readers. I’ve learning your blog much. Thanks!

  7. Jacqueline V. Robbins
    十 27th, 201112:57

    Impressive blog.The codes you provide in this post are very useful and helpful to me and also to others .A big thanks to you.

  8. Sharlot
    十 27th, 201115:01

    I think you don’t need to get one more WZR-HP-G300NH.
    Just try tftp method on wiki with bricked one. If it doesn’t go well, try it again and again.

  9. Maxine
    十一 28th, 201109:43

    I was happy enough that I got some cool code that can be helpful to fix my stuff. I check it later to modify the files if this can be workable on interfacing. Thanks

  10. May
    十二 5th, 201110:26

    You truly save my day,a big thanks to you for sharing your knowledge to us. You hit the nail on the head. Keep it up!

  11. Alliah
    十二 5th, 201112:28

    A track of code that you’ll providing here that makes me knowledgeable enough to do so. I will bookmark this site promptly.

    african mango

  12. Inspiration nature
    一 2nd, 201208:13
    #12
*