Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /bin/sh
- # Script to install debian onto /dev/md0 of a MyBook World Edition White Light
- # This is only intended as a demonstration of how to get debian working
- # Please install debian using one of the prepared images instead of this script if possible
- #
- # You must upgrade to the latest official WD firmware before running this script.
- #
- # If you want the power and recovery buttons to work, you'll need to download some
- # modified kernel modules from http://www.mediafire.com/?ro0ee294lq4oqqi (includes source code)
- #
- # References used while writing this script:
- # http://zeroone.homeunix.net/~blip/computer/mbwe/ [only online during certain hours]
- # http://devnull.samersoff.net/pub/MyBook_me/
- # http://mybookworld.wikidot.com/forum/t-163056/mylenny-firmware
- # WD GPL source code
- #
- # A huge thanks to the people behind those resources :)
- WORKING_DIR="/var/upgrade/debian-install/"
- # check if lenny has been moved to archive.debian.org and set mirror accordingly
- wget --spider http://ftp.debian.org/debian/dists/lenny/main/binary-armel/Packages.gz -O /dev/null --quiet
- RETURN=$?
- if [ "$RETURN" == "0" ]; then
- LENNY_MIRROR="http://ftp.debian.org/debian/"
- else
- wget --spider http://archive.debian.org/debian/dists/lenny/main/binary-armel/Packages.gz -O /dev/null --quiet
- RETURN=$?
- if [ "$RETURN" == "0" ]; then
- LENNY_MIRROR="http://archive.debian.org/debian/"
- else
- echo 'Oh $#|t'! I cant find any lenny packages!
- echo "Please edit this script and set the LENNY_MIRROR variable manually"
- fi
- fi
- SQUEEZE_MIRROR="http://ftp.debian.org/debian/"
- if [ ! -f /etc/model ]; then
- echo You must execute this on your mybook, not on a PC!
- exit
- fi
- # test that cdebootstrap is installed
- which cdebootstrap-static > /dev/null
- CDEB_EXISTS=$?
- if [ $CDEB_EXISTS != "0" ]; then
- echo Understandably, you do not have cdebootstrap-static installed
- echo Unfortunately this script depends on cdebootstrap and cannot install it automatically because ar and tar are not installed on the mybook.
- echo To install cdebootstrap yourself, please go to http://ftp.debian.org/debian/pool/main/c/cdebootstrap/ on a PC and download a static copy for the armel architecture, for example http://ftp.debian.org/debian/pool/main/c/cdebootstrap/cdebootstrap-static_0.5.7_armel.deb
- echo Next run \"ar x cdebootstrap-static*.deb\"
- echo Then run \"tar xvf data.tar.gz\"
- echo "Then copy the stuff in the newly created usr/ (not /usr/!) to your mybook, maybe like this:"
- echo scp -r usr/* root@ip-of-your-mybook:/usr/
- echo "then try running this script again :)"
- echo I\'m sorry to inconvenience you like this, but it couldn\'t be helped. This is the only manual part of the installation.
- exit
- fi
- echo "This script will download and install a debian system to /dev/md0, wiping the vendor's firmware in the process. You will be able to ssh into the new system using the root password "mybook" once installation has finished, but note that the ip address of your mybook may have changed."
- echo
- echo "-- DISCLAIMER --"
- echo "This script is provided \"as is\" - it works for me, but I can't guarantee it will for you. I take no responsibility for anything that happens, especially if you don't make backups. A great idea would be to copy the first 10GB of your mybook hard drive onto a spare hard drive, and then run this script on the spare. That way, even if everything goes wrong, you'll still have your original hard drive intact."
- echo
- echo "Now then, which version of debian would you like to install?"
- echo "Your choices are:"
- echo "1) debian 5.0 lenny"
- echo "2) debian 6.0 squeeze"
- echo "Note that we have to use the kernel provided by Western Digital, which is very old. The version of udev provided with squeeze will not run on such an old kernel, so to make squeeze run it will be installed with the version of udev from lenny and apt-get will be told not to upgrade udev."
- echo -n "Please enter either 1 (for lenny) or 2 (for squeeze): "
- read INPUT
- # validate input
- while [ "$INPUT" != "1" ] && [ "$INPUT" != "2" ]; do
- echo -n "That is not a 1 or a 2! Please enter one of those numbers: "
- read INPUT
- done
- # process input
- if [ "$INPUT" == "1" ]; then
- VERSION="lenny"
- MIRROR="$LENNY_MIRROR"
- else
- VERSION="squeeze"
- MIRROR="$SQUEEZE_MIRROR"
- fi
- # check working dir doesn't already exist
- if [ -e "$WORKING_DIR" ]; then
- echo -n "$WORKING_DIR already exists! Delete it [y/n]?"
- read DELETE
- if [ "$DELETE" == "y" ] || [ "$DELETE" == "Y" ] || [ "$DELETE" == "yes" ]; then
- rm -r "$WORKING_DIR"
- elif [ "$DELETE" == "n" ] || [ "$DELETE" == "N" ] || [ "$DELETE" == "no" ]; then
- exit
- else
- echo "Not a valid answer. Exiting..."
- exit
- fi
- fi
- mkdir "$WORKING_DIR"
- echo "downloading a debian ${VERSION} system (this may take a while) ..."
- # download the debian system
- cdebootstrap-static --allow-unauthenticated --include=openssh-server,udev,ntp,less,ntfs-3g "$VERSION" "$WORKING_DIR" "$MIRROR"
- echo
- # set the root password - see, no nastiness!
- echo "I will now run passwd to set the root password. If you don't trust me with your root password, just check my source code - I swear my intentions are honorable!"
- chroot "$WORKING_DIR" passwd
- # apply the squeeze udev hack
- if [ $VERSION == "squeeze" ]; then
- echo "replacing squeeze's udev with lenny's..."
- chroot "$WORKING_DIR" sh -c "yes | apt-get remove udev"
- echo "deb $LENNY_MIRROR lenny main" > "${WORKING_DIR}/etc/apt/sources.list"
- chroot "$WORKING_DIR" apt-get update
- chroot "$WORKING_DIR" sh -c "yes | apt-get install udev"
- chroot "$WORKING_DIR" sh -c "echo \"udev hold\" | dpkg --set-selections" # stop apt-get from ever upgrading udev
- echo > "${WORKING_DIR}/etc/apt/sources.list"
- fi
- # copy across the relevant files to the debian filesystem
- echo "copying required files from the vendor's firmware to the debian system..."
- cp -r "/lib/modules/2.6.24.4/" "${WORKING_DIR}/lib/modules/" 2> /dev/null # kernel modules
- [ -e "${WORKING_DIR}/lib/firmware/" ] || mkdir "${WORKING_DIR}/lib/firmware/"
- cp /usr/lib/hotplug/firmware/gmac_copro_firmware "${WORKING_DIR}/lib/firmware/" # ethernet firmware
- cp /etc/network/interfaces "${WORKING_DIR}/etc/network/interfaces" # network config
- # write config files using here documents
- echo "writing config files..."
- cat >> "${WORKING_DIR}/etc/modules" << 'EOF'
- # gmac is loaded in /etc/inittab
- ehci_hcd
- nfsd
- rtc_ds1307
- i2c_oxnas_bitbash
- vfat
- nls_iso8859_1
- nls_cp437
- user_recovery_button
- thermAndFan
- rng-core
- scsi_wait_scan
- hfsplus
- aes_generic
- pcbc
- michael_mic
- arc4
- ecb
- # 2-disk users can try "power_button invert_leds=0", but I don't think it does anything
- power_button
- # I haven't tested this, but I think 2-disk users will probably want to use "oxnas-wd810-leds negative_led_logic=1" instead
- oxnas-wd810-leds
- EOF
- mv "${WORKING_DIR}/etc/inittab" "${WORKING_DIR}/etc/inittab.original"
- echo 'GM::sysinit:/sbin/modprobe gmac mac_adr=$mac_adr' > "${WORKING_DIR}/etc/inittab"
- cat "${WORKING_DIR}/etc/inittab.original" >> "${WORKING_DIR}/etc/inittab"
- echo 'T0:23:respawn:/sbin/getty -L ttyS0 115200 vt100' >> "${WORKING_DIR}/etc/inittab"
- mknod "${WORKING_DIR}/dev/ttyS0" c 4 64 # create static serial port device node in case udev fails (not that it ever would...)
- echo "deb ${MIRROR} ${VERSION} main non-free contrib" > "${WORKING_DIR}/etc/apt/sources.list"
- # hack to allow mounting ntfs without specifying "-t ntfs-3g"
- chroot "${WORKING_DIR}" ln -s /sbin/mount.ntfs-3g /sbin/mount.ntfs
- cat >> "${WORKING_DIR}/etc/fstab" << 'EOF'
- /dev/md0 / ext3 defaults 0 0
- /dev/md1 swap swap defaults 0 0
- /dev/md2 /mnt/data/ xfs defaults 0 0
- EOF
- mkdir "${WORKING_DIR}/mnt/data/"
- echo "MyBookWorld" > "${WORKING_DIR}/etc/hostname"
- cat > "${WORKING_DIR}"/etc/rc.power_button_short_press << 'EOF'
- #! /bin/bash
- # This script is executed when the power button is held for less than 3 seconds
- echo 15 > /sys/class/leds/oxnas-wd810-leds\:st/brightness
- halt
- EOF
- chmod +x "${WORKING_DIR}"/etc/rc.power_button_short_press
- cat > "${WORKING_DIR}"/etc/rc.power_button_long_press << 'EOF'
- #! /bin/bash
- # This script is executed when the power button is held for 3 seconds or more
- echo 15 > /sys/class/leds/oxnas-wd810-leds\:st/brightness
- halt
- EOF
- chmod +x "${WORKING_DIR}"/etc/rc.power_button_long_press
- cat > "${WORKING_DIR}"/etc/rc.recovery_button << 'EOF'
- #! /bin/bash
- # This script is executed when the recovery button is held for 3 seconds or more
- # enter upgrade mode, this will replace the root filesystem with the contents of {md3}/upgrade/rootfs.arm.ext2
- echo -n 1 | dd of=/dev/sda bs=512 seek=290
- reboot
- EOF
- chmod +x "${WORKING_DIR}"/etc/rc.recovery_button
- echo running apt-get update...
- chroot "$WORKING_DIR" apt-get update
- # in case you want to distribute the generated filesystem ;p
- echo > "${WORKING_DIR}"/etc/resolv.conf
- # the working dir now contains the finished debian system
- # to install it we'll use the "firmware upgrade" feature of u-boot
- # this loads an upgrade kernel and initrd from the start of the harddrive, which then perform the upgrade
- # we could provide our own but instead we'll just use the ones WD have already put there
- # WD's initrd expects a filesystem image at {md3}/upgrade/rootfs.arm.ext2
- # it will then call mkfs.ext3 on /dev/md0 and copy the contents of the image there
- # create the image
- echo "Preparing for upgrade mode..."
- dd if=/dev/zero of=/var/upgrade/rootfs.arm.ext2 bs=1M count=200
- yes | mkfs.ext2 /var/upgrade/rootfs.arm.ext2
- mkdir /mnt/rootfs.arm.ext2
- mount -o loop /var/upgrade/rootfs.arm.ext2 /mnt/rootfs.arm.ext2
- echo "Copying filesystem..."
- cp -a "${WORKING_DIR}"/* /mnt/rootfs.arm.ext2/ 2>/dev/null
- umount /mnt/rootfs.arm.ext2
- rmdir /mnt/rootfs.arm.ext2
- rm -r "${WORKING_DIR}"
- # WD's initrd also upgrades the kernel using {md3}/upgrade/uImage
- # We presumably don't want this to happen
- [ -f /var/upgrade/uImage ] && mv /var/upgrade/uImage /var/upgrade/uImage.moved
- # set the upgrade flag
- echo -n 1 | dd of=/dev/sda bs=512 seek=290
- # reboot
- echo
- echo "Finished! :)"
- echo "Debian will install on next reboot"
- echo "Press any key to reboot now"
- read REBOOT
- reboot
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement