notes/Pogoplug Mobile v4 Notes-mv1WdVdH.sh
#pogo files http://pogoplug.com/opensource

#http://blog.qnology.com/2014/07/hacking-pogoplug-v4-series-4-and-mobile.html
#https://wiki.openwrt.org/toh/cloudengines/pogo-v4
#Serial connection is at J11, left of SD as you face SD opening.
#Pins are 0V, Rx, Tx (moving right to left from SD).
#Do not connect +V pin. Make sure your serial device is 3.3V, not 5V. Baud rate is 115200.

#connect
screen /dev/ttyUSB0 115200,cs8,-parenb,-cstopb,-hupcl

#or
stty raw -echo < /dev/ttyUSB0

cat /dev/ttyUSB0
#press a key to enter uboot or wait for Linux to boot

#list partition

cat /proc/partitions
cat /proc/mtd

#remount / as read/write

mount -o remount,rw /

#change root password
passwd root


#start telnetd or ssh server (both are already there)
#startup script can be found here

#(might want to enable dropbear and telnet and disable pogo services 'hbmgr.sh'):
vi /etc/init.d/rcS


#mount sdcard

mkdir /mnt/sdcard
mknod /dev/mmcblk0 b 179 0
mknod /dev/mmcblk0p1 b 179 1
mount /dev/mmcblk0p1 /mnt/sdcard

#mount USB drive

mkdir /mnt/usb
mknod /dev/sda b 8 0
mknod /dev/sda1 b 8 1
mount /dev/sda1 /mnt/usb

#add these lines to /etc/fstab

/dev/sda1 /mnt/usb vfat defaults 0 0
/dev/mmcblk0p1 /mnt/sdcard vfat defaults 0 0

#now that we have storage, you might want to back things up
#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!I have not tried restoring flash from dd !!!!!!!!!!!

#I suggest reading this http://forum.doozan.com/read.php?3,16789,16800

cd /mnt/usb
for i in 0 1 2 3 4;do echo "Backing up mtd$i";dd if=/dev/mtd$i of=mtd$i.img;done
#other tools 'nanddump', 'nandwrite', 'flash_erase', and 'flash_eraseall'
#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

#install busybox

#root fs is 100MB, so plenty of room

df -h
#busybox wit a lot of tools is already installed

#but there are more tools in busybox we can get 


#check architecture
uname -a  #armv5tel


#get busybox binaries 

#note that busybox wget doesn't support ssl
#so you won't be able to download directly to the device
https://busybox.net/downloads/binaries/

#once on device make executable and move to /bin

chmod +x busybox
mv busybox /bin/
#link all commands

busybox --list|while read c;do echo $c;ln -s /bin/busybox $c;done

#download a very basic directory indexer I designed
cd /mnt/usb #cd /mnt/sdcard

#again, no ssl at this point

wget "https://github.com/metalx1000/Directory-Index-for-httpd/archive/master.zip"
unzip master.zip 
mv Directory-Index-for-httpd-master www
cd www
#start web service in forground
httpd -fvvvh /mnt/usb/www

#or as background process
httpd -h /mnt/usb/www

#might want to add this to the startup script


#add to bottom startup script (/etc/init.d/rcS)

#for automounting 

#5 second delay is for a slow usb drive (there are better ways for doing this)

mount /dev/mmcblk0p1
#httpd -h /mnt/usb/www

httpd -h /mnt/sdcard/www
sleep 5;mount /dev/sda1

#Controlling LED

#http://aaronrandall.com/blog/playing-with-pogoplugs-led/
#many sites will show how to control the LED if you have installed Debian or Arch

#here is how you control it from the default OS
#activate it
insmod /usr/local/cloudengines/bin/xce.ko

#Set the LED to green:

echo "led=con" > /dev/xce
#Set the LED to red:

echo "led=dis" > /dev/xce
#Set the LED to orange:
echo "led=err" > /dev/xce

#Set the LED to flash:

echo "led=msg" > /dev/xce

#############SSH DropBear###########

#The version of Dropbear on this device is old

#it uses an old/less secure encryption that your client might not like

#you can override this on your client side like this

ssh -oKexAlgorithms=+diffie-hellman-group1-sha1 root@192.168.1.104
#there is no sftp server, but you can scp like this
scp -oKexAlgorithms=+diffie-hellman-group1-sha1 <file> root@192.168.1.104:

#############upgrade to newer DropBear##########
#cross compile on desktop

sudo apt-get install gcc-arm-linux-gnueabi
wget "https://matt.ucc.asn.au/dropbear/releases/dropbear-2016.74.tar.bz2"
tar -xjf dropbear-2016.74.tar.bz2
cd dropbear-2016.74
./configure --host=arm-linux-gnueabi --prefix=/ --disable-zlib CC=arm-linux-gnueabi-gcc LD=arm-linux-gnueabi-ld
make
#copy to device
scp -oKexAlgorithms=+diffie-hellman-group1-sha1 dropbear root@192.168.1.104:
#test it, backup old version, and replace

killall dropbear #you'll lose your connection so reconnect with telnet or serial
./dropbear #once you make sure it works kill it and move it

killall dropbear 
mv /usr/sbin/dropbear /usr/sbin/dropbear.old
mv dropbear /usr/sbin/dropbear
/usr/sbin/dropbear

syntax highlighted by Code2HTML, v. 0.9.1