aboutsummaryrefslogtreecommitdiffstats
path: root/packages/nslu2-binary-only/unslung-rootfs-2.3r25/unsling
blob: c640630bbad5a3c0a68c4f58558cdbcb87c50e24 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/bin/sh

usage="Usage: $0 [flash|hdd|flash-data|hdd-data|jffs2-flash|jffs2-hdd|jffs2-flash-data|jffs2-hdd-data]"

# Set or seach for target disk

if [ $# -gt 1 ] ; then
    echo $usage
    exit 1
fi

if [ $# -eq 1 ] ; then
    if [ "$1" = "flash-data" ] ; then
	targ=/share/flash/data
	copy=true
    elif [ "$1" = "hdd-data" ] ; then
	targ=/share/hdd/data
	copy=true
    elif [ "$1" = "flash" ] ; then
	targ=/share/flash/conf
	copy=true
    elif [ "$1" = "hdd" ] ; then
	targ=/share/hdd/conf
	copy=true
    elif [ "$1" = "jffs2-flash-data" ] ; then
	targ=/share/flash/data
	copy=
    elif [ "$1" = "jffs2-hdd-data" ] ; then
	targ=/share/hdd/data
	copy=
    elif [ "$1" = "jffs2-flash" ] ; then
	targ=/share/flash/conf
	copy=
    elif [ "$1" = "jffs2-hdd" ] ; then
	targ=/share/hdd/conf
	copy=
    else
	echo $usage
	exit 1
    fi
else
    echo $usage
    exit 1
fi

# Check it's a real mount point

if grep $targ /proc/mounts >/dev/null 2>&1 ; then
    echo "Target disk is $targ"
else
    echo "Error: $targ is not a mounted disk"
    exit 1
fi

# Start at the root directory

cd /

if [ -z "$copy" ] ; then

    # Ensure /opt is there.

    if [ ! -d $targ/opt ] ; then
	echo "Creating new /opt directory on target disk."
	mkdir -p $targ/opt
    else
	echo "Preserving existing /opt directory on target disk."
    fi
  
    if [ -d /opt -a ! -h /opt ] ; then
	echo "Copying existing /opt directory from root disk to target disk."
	tar cf - opt | ( cd $targ ; tar xf - )
	mv /opt /opt.old
    fi

    echo "Linking /opt directory from target disk to root disk."
    rm -f /opt ; ln -s $targ/opt /opt

    # Ensure /usr/lib/ipkg is there.

    if [ ! -d $targ/usr/lib/ipkg ] ; then
	echo "Creating new /usr/lib/ipkg directory on target disk."
	mkdir -p $targ/usr/lib/ipkg
    fi
  
    if [ ! -f $targ/usr/lib/ipkg/status -a -d /usr/lib/ipkg -a ! -h /usr/lib/ipkg ] ; then
	echo "Copying existing /usr/lib/ipkg directory from root disk to target disk."
	tar cf - usr/lib/ipkg | ( cd $targ ; tar xf - )
    else
	echo "Preserving existing ipkg database on target disk."
    fi

    if [ -d /usr/lib/ipkg -a ! -h /usr/lib/ipkg ] ; then
	echo "Saving /usr/lib/ipkg directory on root disk in /usr/lib/ipkg.old"
	rm -rf /usr/lib/ipkg.old
	mv /usr/lib/ipkg /usr/lib/ipkg.old
    fi

    echo "Linking /usr/lib/ipkg directory from target disk to root disk."
    rm -f /usr/lib/ipkg ; ln -s $targ/usr/lib/ipkg /usr/lib/ipkg

else

    # Copy the complete rootfs to the target.

    /usr/bin/find / -print0 -mount | /usr/bin/cpio -p -0 -d -m -u $targ
    rm -rf $targ/dev ; mv $targ/dev.state $targ/dev
    rm -rf $targ/var ; mv $targ/var.state $targ/var

    rm -f /.sda1root /.sda2root /.sdb1root /.sdb2root
    rm -f $targ/.sda1root $targ/.sda2root $targ/.sdb1root $targ/.sdb2root

    if [ "$targ" = "/share/hdd/data" ] ; then
	echo > /.sda1root
	echo > $targ/.sda1root
    elif [ "$targ" = "/share/hdd/conf" ] ; then
	echo > /.sda2root
	echo > $targ/.sda2root
    elif [ "$targ" = "/share/flash/data" ] ; then
	echo > /.sdb1root
	echo > $targ/.sdb1root
    elif [ "$targ" = "/share/flash/conf" ] ; then
	echo > /.sdb2root
	echo > $targ/.sdb2root
    fi

fi

exit 0