source: freewrt/package/base-files/default/bin/firstboot@ e4ba301

freewrt_1_0 freewrt_2_0
Last change on this file since e4ba301 was e4ba301, checked in by Waldemar Brodkorb <wbx@…>, 19 years ago
  • add a specific preinit.arch which executes brcm specific stuff
  • for squashfs based images, use mini_fo as default, no ugly symlinks anymore
  • add a "version" command, which can be used later, to exactly know which FreeWRT version is used (good for postinst scripts and bugreports), some users like to recreate the shell banner, but still need to know which version is used
  • remove nvram sepcific stuff from some of the startup scripts, like syslogd startup params
  • add some checks if ldd / arp is installed in /etc/profile

git-svn-id: svn://www.freewrt.org/trunk/freewrt@182 afb5a338-a214-0410-bd46-81f09a774fd1

  • Property mode set to 100755
File size: 2.1 KB
Line 
1#!/bin/sh
2# $Id: firstboot 3633 2006-04-13 14:43:47Z nbd $
3
4rom=$(awk '/squashfs/ {print $2}' /proc/mounts)
5jffs=$(awk '/jffs2/ {print $2}' /proc/mounts)
6
7dupe() { # <new_root> <old_root>
8 cd $1
9 echo -n "creating directories... "
10 {
11 cd $2
12 find . -xdev -type d
13 echo "./dev ./jffs ./mnt ./proc ./tmp ./sys"
14 # xdev skips mounted directories
15 cd $1
16 } | xargs mkdir -p
17 echo "done"
18
19 echo -n "setting up symlinks... "
20 for file in $(cd $2; find . -xdev -type f;); do
21 case "$file" in
22 ./rom/note) ;; #nothing
23 ./etc/config*|\
24 ./etc/resolv.conf|\
25 ./usr/lib/ipkg/info) cp -af $2/$file $file;;
26 *) ln -sf /rom/${file#./*} $file;;
27 esac
28 done
29 for file in $(cd $2; find . -xdev -type l;); do
30 cp -af $2/${file#./*} $file
31 done
32 echo "done"
33}
34
35pivot() { # <new_root> <old_root>
36 mount -o move /proc $1/proc && \
37 pivot_root $1 $1$2 && {
38 mount -o move $2/dev /dev
39 mount -o move $2/tmp /tmp
40 mount -o move $2/sys /sys
41 return 0
42 }
43}
44
45mountdp() { # <device> <mount_point> <ignored> <fs>
46 dev=$1; mnt=$2; shift 2; opt=$*
47 mount $dev $mnt $opt
48 dupe $mnt $rom
49 pivot $mnt /rom
50}
51
52fopivot() { # <rw_root> <ro_root> <dupe?>
53 root=$1
54 {
55 mount -t mini_fo -o base=/,sto=$1 $1 /mnt 2>&- && root=/mnt
56 } || {
57 [ "$3" = "1" ] && mount -o bind $1 $1 && dupe $1 $rom
58 }
59 pivot $root $2
60}
61
62
63ramoverlay() {
64 mkdir -p /tmp/root
65 mountdp /tmp/root /mnt -o bind
66}
67
68[ "${0##*/}" = "firstboot" ] && {
69 [ -z "$rom" ] && {
70 echo "You do not have a squashfs partition; aborting"
71 echo "(firstboot cannot be run on jffs2 based firmwares)"
72 exit 1
73 }
74
75 [ "$1" = "switch2jffs" ] && {
76 mtd erase data
77 mount -o remount,ro none / # try to avoid fs changing while copying
78 mount -o bind / /mnt
79 mount /dev/mtdblock/4 /rom/jffs -t jffs2
80 echo -n "copying files ... "
81 cp -a /mnt/* /rom/jffs
82 umount /mnt
83 echo "done"
84 pivot /rom /mnt
85 mount -o move /mnt /tmp/root
86 pivot /jffs /rom
87 jffs2root --clean
88 exit 0
89 }
90
91 # script run manually
92 [ \! -z "$jffs" ] && {
93 echo "firstboot has already been run"
94 echo "jffs2 partition is mounted, only resetting files"
95 dupe $jffs $rom
96 exit 0
97 }
98
99 mtd erase data
100 mountdp /dev/mtdblock/4 /jffs -t jffs2
101}
Note: See TracBrowser for help on using the repository browser.