3 M_TITLE="Install RootFS from tar.gz"
6 # echo "ERROR: $1" >/dev/tty0
7 # exec $SH_SHELL </dev/tty0 >/dev/tty0 2>&1
11 test -e /etc/altboot.func && . /etc/altboot.func || die "ERROR: /etc/altboot.func not found. Check your installation!"
21 for source in /home /media/card /media/cf
23 #echo "source: [$source]"
24 rootfs_files="`ls -1 $source | grep "rootfs.tar.gz"`"
26 #echo "rootfs_file: [$rootfs_files]"
27 if test "`echo "$rootfs_files" | wc -l | tr -d " "`" -gt 1
29 echo "Multiple rootfs files not supported, yet"
31 if test -n "$rootfs_files"
33 rootfs_source="$source/$rootfs_files"
34 echo "Using [$rootfs_source]"
40 test -z "$rootfs_source" && die "No rootfs.tar.gz found"
42 echo -e "\nPlease choose the target of this installation:\n"
44 echo -e "\t [1] SD / MMC"
45 echo -e "\t [2] Compact Flash"
50 echo -n "Your target: "
54 1) if (mount | grep -q "/media/card ")
56 rootfs_target="/media/card"; break
58 echo -e "\nInstallation target [/media/card] not mounted\n"
60 2) if (mount | grep -q "/media/cf ")
62 rootfs_target="/media/cf"; break
64 echo -e "\nInstallation target [/media/cf] not mounted\n"
69 echo -e "\nPlease choose the type of this installation:\n"
71 echo -e "\t [1] Imagefile (loopfile)"
72 echo -e "\t [2] Direct Install"
77 echo -n "Install type: "
81 1) if test -x /sbin/mkfs.ext2
86 echo -e "\nNOTE: mkfs.ext2 (from e2fsprogs-mke2fs) not found, loop-images not supported\n"
88 2) rootfs_type="direct" ; break ;;
92 case "$rootfs_type" in
93 image) install_rootfs_image "$rootfs_target";;
94 direct) install_rootfs_direct "$rootfs_target";;
99 test "$1" = "/" -o "$1" = "/ " && die "clear_directories(): You don't want to do that."
101 ! test -d "$1" && die "clear_directories(): [$1] not found."
103 for d in bin dev media proc sys usr boot etc lib mnt sbin tmp var
107 echo "Removing [$1/$d]..."
115 install_rootfs_direct(){
117 mount | grep -q "$1 " || die "Installation target [$1] not mounted"
119 echo -e "Do you want to remove existing directories from [$1]\n before installing the new rootfs?"
124 echo -n "Remove old directories? [Y|n] "
125 read junk </dev/tty0 >/dev/tty0 2>&1
128 Y|y|"") clear_directories "$1"; break ;;
132 echo "Please press <ENTER> to begin the installation"
133 read junk </dev/tty0 >/dev/tty0 2>&1
135 test -d "$1" || die "Directory [$1] not found"
137 echo -n "Installing rootfs, please wait..."
138 tar -xzf "$rootfs_source" -C "$1" >/dev/null 2>&1 && echo ok || die "tar -xzf \"$rootfs_source\" -C \"$1\" failed!"
140 echo -n "Syncing drives..."
146 echo "Press <ENTER> to bring up the altboot menu"
147 read junk </dev/tty0 >/dev/tty0 2>&1
148 exec /sbin/init.altboot -force
152 install_rootfs_image(){
154 mount | grep -q "$1 " || die "Installation target [$1] not mounted"
157 echo "Please enter a name for the image file."
158 echo "Do not use the <space> character"
164 echo -n "Image name: "
169 if test -e "$1/boot-images/${junk}-rootfs.bin"
171 echo -e "\nFile [$1/boot-images/${junk}-rootfs.bin] already exists."
175 echo -n "Overwrite? [y|N] "
180 n|N|"") install_rootfs_image "$1"
184 rootfs_image_name="${junk}-rootfs.bin"
187 echo -n "Use [$junk] as name? [Y|n] "
191 "Y"|"y"|"") rootfs_image_name="${junk}-rootfs.bin"
193 *) echo "err ]$junk]";;
200 echo "Please enter the image size in MegaBytes"
201 echo "Must be at least 30Mb"
206 echo -n "Image size: "
209 junk="`echo "$junk" | sed "s/[a-zA-Z]//g"`"
213 if test "$junk" -gt 29
215 echo -n "Is [${junk}Mb] correct? [Y|n] "
219 Y|y|"") rootfs_image_size="$junk"
224 echo "Image size of [${junk}Mb] is too small!"
229 test -z "$rootfs_image_name" -o -z "$rootfs_image_size" && die "DEBUG: Empty VAR in install_rootfs_image()"
232 echo "Creating [$rootfs_image_name] (${rootfs_image_size}Mb) on [$1]"
233 echo "Please wait..."
234 mkdir -p "$1/boot-images"
236 dd if=/dev/zero of="$1/boot-images/$rootfs_image_name" bs=1024k count=$rootfs_image_size >/dev/null
238 echo -n "Creating an ext2 filesystem on $rootfs_image_name..."
239 losetup /dev/loop0 "$1/boot-images/$rootfs_image_name" || die "losetup /dev/loop0 \"$1/boot-images/$rootfs_image_name\" failed!"
240 mkfs.ext2 -m0 /dev/loop0 >/dev/null 2>&1 && echo done || die "mkfs.ext2 -m0 /dev/loop0 failed!"
242 echo -n "Mounting loopfile..."
243 mkdir -p /media/image
244 mount /dev/loop0 /media/image && echo ok || die "mount /dev/loop0 /media/image failed!"
246 echo -n "Installing rootfs, please wait..."
247 tar -xzf "$rootfs_source" -C "/media/image" >/dev/null 2>&1 && echo ok || die "tar -xzf \"$rootfs_source\" -C \"$1\" failed!"
249 echo -n "Syncing drives..."
253 umount "/media/image" && losetup -d /dev/loop0
255 echo "Press <ENTER> to bring up the altboot menu"
256 read junk </dev/tty0 >/dev/tty0 2>&1
257 exec /sbin/init.altboot -force
266 title) echo "$M_TITLE";;
267 run) run_module "$2";;