summaryrefslogtreecommitdiffstats
path: root/nslu2-binary-only/nslu2-unslung-ramdisk/unsling
blob: f0345aba700e201a7c07701dfbd031e281bd8927 (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
#!/bin/sh

# Only do this if we have booted from the ramdisk.

if [ "`cat /proc/sys/kernel/real-root-dev`" != 256 ] ; then
    echo "Cannot unsling an active unslung root partition!"
    exit 0
fi 

# Set or seach for target disk

if [ $# -gt 1 ] ; then
    echo "Usage: $0 [flash|hdd]"
    exit 1
fi

if [ $# -eq 1 ] ; then
    if [ "$1" = "flash" -o "$1" = "hdd" ] ; then
	targ=/share/$1/conf
    else
	echo "Usage: $0 [flash|hdd]"
	exit 1
    fi
elif [ -d /share/hdd/conf/lost+found ] ; then
    targ=/share/hdd/conf
elif [ -d /share/flash/conf/lost+found ] ; then
    targ=/share/flash/conf
else
    echo "Cannot locate target root partition"
    exit 1
fi

echo "Target root partition is $targ"

echo "Removing conflicts from old unslung root partition."
rm -f $targ/bin/ipkg

# Unsling it!

copyfiles=".unslung bin dev etc home lib linuxrc mnt sbin usr"

echo "Copying ramdisk files to new unslung root partition."
cd /
tar cf - $copyfiles | ( cd $targ ; tar xf - )

# Create other required directories.

echo "Creating required mount points and empty directories."

rm -rf $targ/tmp                && mkdir $targ/tmp

[ ! -d $targ/share ]            && mkdir $targ/share
[ ! -d $targ/share/flash ]      && mkdir $targ/share/flash
[ ! -d $targ/share/flash/conf ] && mkdir $targ/share/flash/conf
[ ! -d $targ/share/flash/data ] && mkdir $targ/share/flash/data
[ ! -d $targ/share/hdd ]        && mkdir $targ/share/hdd
[ ! -d $targ/share/hdd/conf ]   && mkdir $targ/share/hdd/conf
[ ! -d $targ/share/hdd/data ]   && mkdir $targ/share/hdd/data
[ ! -d $targ/mnt ]              && mkdir $targ/mnt
[ ! -d $targ/mnt/backup ]       && mkdir $targ/mnt/backup
[ ! -d $targ/mnt/repair ]       && mkdir $targ/mnt/repair
[ ! -d $targ/mnt/tmpmnt ]       && mkdir $targ/mnt/tmpmnt
[ ! -d $targ/proc ]             && mkdir $targ/proc
[ ! -d $targ/upload ]           && mkdir $targ/upload
[ ! -d $targ/var ]       	&& mkdir $targ/var
[ ! -d $targ/var/empty ] 	&& mkdir $targ/var/empty
[ ! -d $targ/var/lock ]  	&& mkdir $targ/var/lock
[ ! -d $targ/var/log ]   	&& mkdir $targ/var/log
[ ! -d $targ/var/run ]   	&& mkdir $targ/var/run
[ ! -d $targ/var/tmp ]   	&& mkdir $targ/var/tmp

# Ensure /unslung is there.

if [ ! -d $targ/unslung ] ; then

    echo "Creating new /unslung directory on unslung root partition."

    mkdir $targ/unslung
  
else
    echo "Preserving existing /unslung directory on unslung root partition."
fi
  
# Ensure /root is there.

if [ ! -d $targ/root ] ; then

    echo "Creating new /root directory on unslung root partition."

    mkdir $targ/root
  
else
    echo "Preserving existing /root directory on unslung root partition."
fi
  
# Ensure /opt is there.

if [ ! -d $targ/opt ] ; then

    echo "Creating new /opt directory on unslung root partition."

    mkdir $targ/opt
  
else
    echo "Preserving existing /opt directory on unslung root partition."
fi
  
echo "Unslinging any default root passwords."
  
[ -f $targ/passwd ] && sed -i -e 's/^root:WeeOvKUvbQ6nI:0:0:root:/root:t1PLUeOinN\/eI:0:0:root:/' $targ/passwd
[ -f $targ/usr/local/passwd ] && sed -i -e 's/^root:WeeOvKUvbQ6nI:0:0:root:/root:t1PLUeOinN\/eI:0:0:root:/' $targ/usr/local/passwd
 
exit 0