Last active
May 24, 2017 19:09
-
-
Save braian87b/995fdb99050daee2c57eca855b37a491 to your computer and use it in GitHub Desktop.
How to Setup an OpenWRT / LEDE box to rip Floppy Disks data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This script allow to setup a working OpenWRT / LEDE router with two USB ports | |
# or a USB Hub with a PenDrive and a Floppy Disk USB Drive, | |
# it will automatically create a Floppy Disk image and copy all data to a directory too. | |
# Optionally (disabled because it takes ages) will erase all data and blank it and format it. | |
# Floppy Disk rip process takes about 50 seconds, erasing and formating idk but takes more than 3 minutes. | |
opkg update | |
# Needed to mount filesystems | |
opkg install block-mount | |
# Kernel support for USB Mass Storage devices | |
opkg install kmod-usb-storage # brings: kmod-scsi-core | |
# Support to be able to mount floppy disks (formatted usually on MSDOS) | |
opkg install kmod-fs-msdos | |
# Support to be able to mount floppy disk images | |
opkg install kmod-loop | |
# To be able to fsck fat partitions | |
opkg install dosfstools | |
# Now insert a fat or fat32 formatted PenDrive and watch if it was detected properly using `dmesg`, `logread` and `block detect` | |
mkdir /mnt/usb | |
block detect > /etc/config/fstab | |
uci set fstab.@mount[0].target='/mnt/usb' | |
uci set fstab.@mount[0].enabled='1' | |
uci commit fstab | |
# to be able to see floppy disk images saved on /mnt/usb from browser | |
ln -s /mnt/usb/ /www/images | |
http://192.168.1.1/images/ | |
# create mounting point | |
mkdir /mnt/floppy/ | |
# you will probably will have a "led_usb" but replace with proper one, see using `uci show system | grep =led` | |
rm /root/led*.sh | |
cat<<'EOF' > /root/led_off.sh | |
#!/bin/sh | |
uci set system.led_usb.trigger='none' | |
uci set system.led_usb.default='0' | |
/etc/init.d/led restart | |
EOF | |
chmod +x /root/led_off.sh | |
cat<<'EOF' > /root/led_on.sh | |
#!/bin/sh | |
uci set system.led_usb.trigger='none' | |
uci set system.led_usb.default='1' | |
/etc/init.d/led restart | |
EOF | |
chmod +x /root/led_on.sh | |
cat<<'EOF' > /root/led_blinking_fast.sh | |
#!/bin/sh | |
uci set system.led_usb.trigger='timer' | |
uci set system.led_usb.delayon='100' | |
uci set system.led_usb.delayoff='100' | |
/etc/init.d/led restart | |
EOF | |
chmod +x /root/led_blinking_fast.sh | |
cat<<'EOF' > /root/led_blinking_slowly.sh | |
#!/bin/sh | |
uci set system.led_usb.trigger='timer' | |
uci set system.led_usb.delayon='250' | |
uci set system.led_usb.delayoff='1000' | |
/etc/init.d/led restart | |
EOF | |
chmod +x /root/led_blinking_slowly.sh | |
cat<<'EOF' > /root/led_blinking_more_slowly.sh | |
#!/bin/sh | |
uci set system.led_usb.trigger='timer' | |
uci set system.led_usb.delayon='1000' | |
uci set system.led_usb.delayoff='1000' | |
/etc/init.d/led restart | |
EOF | |
chmod +x /root/led_blinking_more_slowly.sh | |
cat<<'EOF' > /root/rip_floppy_disk.sh | |
#!/bin/sh | |
floppy=/dev/sdb | |
today=`date +%Y%m%d%H%M%S` | |
basename="/mnt/usb/floppy_$today" | |
filename="/mnt/usb/floppy_$today.img" | |
indexfile="/mnt/usb/floppy_$today""_contents.txt" | |
resultsfile="/mnt/usb/floppy_$today""_results.txt" | |
errorfile="/mnt/usb/floppy_$today""_error.txt" | |
/root/led_blinking_slowly.sh | |
echo "Create Floppy Disk Image..." | /usr/bin/tee -a $resultsfile | |
dd if=$floppy of=$filename >> $resultsfile 2>&1 | |
RESULT=$? | |
if [ $RESULT -eq 0 ]; then | |
echo "Mounting Floppy Disk Image..." | /usr/bin/tee -a $resultsfile | |
mount -o loop $filename /mnt/floppy/ >> $resultsfile 2>&1 | |
RESULT_MOUNT=$? | |
if [ $RESULT_MOUNT -eq 0 ]; then | |
echo "Saving mounting status..." | /usr/bin/tee -a $resultsfile | |
# optional, read Label and UUID (requires `opkg install lsblk`) | |
if type lsblk > /dev/null; then | |
lsblk -o name,mountpoint,label,size,uuid /dev/sda /dev/sdb >> $indexfile 2>&1 | /usr/bin/tee -a $resultsfile | |
fi | |
echo -n "Floppy Disk Label: " >> $indexfile 2>&1 | /usr/bin/tee -a $resultsfile | |
fatlabel /dev/sda >> $indexfile 2>&1 | /usr/bin/tee -a $resultsfile | |
df -Th | grep floppy >> $indexfile 2>&1 | /usr/bin/tee -a $resultsfile | |
echo "Saving contents list..." | /usr/bin/tee -a $resultsfile | |
ls -lath /mnt/floppy/ >> $indexfile 2>&1 | /usr/bin/tee -a $resultsfile | |
echo "Creating directory for contents of the Floppy Disk Image..." | /usr/bin/tee -a $resultsfile | |
mkdir $basename 2>&1 | /usr/bin/tee -a $resultsfile | |
echo "Copy Contents of Floppy Disk Image..." | /usr/bin/tee -a $resultsfile | |
cp -p -r /mnt/floppy/* $basename 2>&1 | /usr/bin/tee -a $resultsfile | |
sync | |
echo "Unmount Floppy Disk Image..." | /usr/bin/tee -a $resultsfile | |
umount /mnt/floppy/ 2>&1 | /usr/bin/tee -a $resultsfile | |
fi | |
# Optional: Clean Floppy Disk Image (Warning this will take LONG!!!) | |
# /root/clean_floppy_disk.sh $floppy $today | |
/root/led_off.sh | |
else | |
/root/led_blinking_fast.sh | |
echo "Has been an error during Floppy Disk Image Creation..." | /usr/bin/tee -a $errorfile | |
fi | |
EOF | |
chmod +x /root/rip_floppy_disk.sh | |
cat<<'EOF' > /root/clean_floppy_disk.sh | |
#!/bin/sh | |
floppy=${1:-/dev/sdb} | |
today=${2:-`date +%Y%m%d%H%M%S`} | |
resultsfile="/mnt/usb/floppy_$today""_clean_results.txt" | |
/root/led_blinking_more_slowly.sh | |
echo "Erasing using random data..." | /usr/bin/tee -a $resultsfile | |
dd if=/dev/urandom of=$floppy count=2880 2>&1 | /usr/bin/tee -a $resultsfile | |
sync | |
echo "Cleaning using zeroes..." | /usr/bin/tee -a $resultsfile | |
dd if=/dev/zero of=$floppy count=2880 2>&1 | /usr/bin/tee -a $resultsfile | |
sync | |
echo "Formatting Floppy Disk..." | /usr/bin/tee -a $resultsfile | |
# "mkfs.msdos" for OpenWRT, "mkfs.fat" for LEDE | |
if type mkfs.msdos > /dev/null; then | |
mkfs.msdos -I $floppy 1440 2>&1 | /usr/bin/tee -a $resultsfile | |
else | |
mkfs.fat -I $floppy 1440 2>&1 | /usr/bin/tee -a $resultsfile | |
fi | |
sync | |
/root/led_off.sh | |
EOF | |
chmod +x /root/clean_floppy_disk.sh | |
# procd buttons seems to work badly with some duplicated triggering, we will disable it and use hotplug instead | |
mv /etc/rc.button/reset /etc/rc.button/reset.bak | |
mv /etc/rc.button/rfkill /etc/rc.button/rfkill.bak | |
# Just in case you want to use procd button, if not, continue with commands bottom: | |
ln -s /root/rip_floppy_disk.sh /etc/rc.button/rfkill | |
# disable procd button trigger (it does not work properly, we will use hotplug instead...) | |
rm /etc/rc.button/rfkill | |
# enable hotplug button using UCI | |
cat<<'EOF' > /etc/hotplug.d/button/00-button | |
#!/bin/sh | |
. /lib/functions.sh | |
do_button () { | |
local button | |
local action | |
local handler | |
local min | |
local max | |
config_get button $1 button | |
config_get action $1 action | |
config_get handler $1 handler | |
config_get min $1 min | |
config_get max $1 max | |
[ "$ACTION" = "$action" -a "$BUTTON" = "$button" -a -n "$handler" ] && { | |
[ -z "$min" -o -z "$max" ] && eval $handler | |
[ -n "$min" -a -n "$max" ] && { | |
[ $min -le $SEEN -a $max -ge $SEEN ] && eval $handler | |
} | |
} | |
} | |
config_load system | |
config_foreach do_button button | |
EOF | |
# setup button triggering | |
uci del system.rip_floppy_disk | |
uci set system.rip_floppy_disk=button | |
# use proper button name according your Device | |
uci set system.rip_floppy_disk.button='wps' | |
uci set system.rip_floppy_disk.button='rfkill' | |
uci set system.rip_floppy_disk.action='released' | |
uci set system.rip_floppy_disk.handler='logger "******** Riping Floppy Disk"; /root/rip_floppy_disk.sh' | |
uci set system.rip_floppy_disk.min='0' | |
uci set system.rip_floppy_disk.max='2' | |
uci commit system | |
/etc/init.d/system restart | |
# Additional: If you want to save Floppy Disk Images to a CIFS/SAMBA Network Share (and avoid using a Pendrive): | |
# enable to be able to mount CIFS/SAMBA network shares | |
opkg install kmod-fs-cifs | |
# creates mounting point for samba network share | |
mkdir /mnt/samba | |
cat<<'EOF' > /root/mount_share.sh | |
#!/bin/sh | |
# wait 5 seconds | |
/bin/sleep 5 | |
/bin/mount -t cifs //192.168.1.2/share /mnt/samba -o user=Username,password=Password | |
# link /dev/sdb to /dev/sda (because of scripts pointing to Floppy Disk Drive on /dev/sdb) | |
ln /dev/sda /dev/sdb | |
EOF | |
chmod +x /root/mount_share.sh | |
/root/mount_share.sh | |
# check if mounted | |
df -Th | |
# create directory for images | |
mkdir -p /mnt/samba/floppy-disk-images | |
# link directory to Floppy Disk Images Directory | |
rmdir /mnt/usb | |
ln -s /mnt/samba/floppy-disk-images/ /mnt/usb | |
# Disable not needed fstab mounting for PenDrive | |
uci set fstab.@mount[0].enabled='0' | |
uci commit fstab | |
# Run at startup | |
cat<<'EOF' > /etc/rc.local | |
#!/bin/sh | |
/root/mount_share.sh & | |
exit 0 | |
EOF | |
chmod +x /etc/rc.local | |
# reboot and check if it mounts at startup, if needed add more seconds to /root/mount_share.sh | |
reboot |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment