#!/bin/ash failed(){ echo "Error: Command $1 failed." exit 1 } debian_install(){ mkdir -p /tmp/newroot mount -t ext4 ${1} /tmp/newroot debootstrap --arch=mipsel --include=vim,openssh-server,ntpdate,cron,locales,udev,ca-certificates,apt-transport-https,vlan jessie /tmp/newroot http://httpredir.debian.org/debian || failed debootstrap } debian_fix(){ cat << EOF > /tmp/newroot/etc/network/interfaces auto lo iface lo inet loopback auto eth0.1 iface eth0.1 inet static address 192.168.1.1 netmask 255.255.255.0 auto eth0.2 iface eth0.2 inet dhcp EOF mkdir /tmp/newroot/rom mknod /tmp/newroot/dev/console c 5 1 mknod /tmp/newroot/dev/ttyS0 c 4 64 mknod /tmp/newroot/dev/tty0 c 4 0 mknod /tmp/newroot/dev/tty1 c 4 1 sed -i "s/^root:\*:/root:\$6\$l80E2NNrh32z0N\$HX1nhaV6TcdM3OcMm8PVyzQZAl6c9Q2GYugdS9MuDcG6NkxW3eLCvLbw05tMKkbyRlieU1QeZ4tngZpaS9Fnf0:/" /tmp/newroot/etc/shadow mkdir -p /tmp/newroot/etc/cron.d echo "10 */4 * * * root /usr/sbin/ntpdate -u pool.ntp.org " > /tmp/newroot/etc/cron.d/ntp sed -i "s/^exit 0/ntpdate -u pool.ntp.org\nexit 0/g" /tmp/newroot/etc/rc.local echo "gnubee-pc1.gnubee" > /tmp/newroot/etc/hostname echo "LABEL=GNUBEE-ROOT / ext4 noatime,errors=remount-ro 0 1" >> /tmp/newroot/etc/fstab sed -i "s/^127.0.0.1.*/& gnubee-pc1 gnubee-pc1.gnubee/" /tmp/newroot/etc/hosts sed -i "s/^PermitRootLogin.*/PermitRootLogin yes/" /tmp/newroot/etc/ssh/sshd_config sync } format_partition(){ echo -n "Partition will be formatted, please type CONFIRM if you agree: " read IN if [[ $IN == "CONFIRM" ]] then umount ${1} echo "Formatting ${1}, please wait..." echo y | mkfs.ext4 -m 2 -L GNUBEE-ROOT ${1} debian_install ${1} debian_fix echo "Debian successfully installed into ${1}, please reboot your device now." else echo "Operation cancelled." fi } error_partition(){ echo "Partition not found, operation cancelled." } choose_partition(){ echo "Detecting connected partitions, please wait a few moments." OPTIONS=`blkid | grep "/dev/sd\|/dev/md0"` echo "$OPTIONS" echo -n "Choose partition to install (will be formatted !!!): "; read STR echo echo "$OPTIONS" | grep "^${STR}:" && format_partition ${STR} || error_partition } choose_partition