Arduino Sever PXE Script
From Combustory
Revision as of 18:23, 4 November 2012 by Jvaughters (Talk | contribs)
#/bin/bash #tc_pxe_build v0.1 # Written by John Vaughters at http://www.combustory.com # This script will build the entire pxe directory structure needed to start a tinycore arduino server # Check if already installed if [ -d tc_pxe ] then echo '********************* Directory tc_pxe already exists. Please remove tc_pxe directory to run this Intall' exit 0 fi # Create Directories echo '*********************Creating Directories' mkdir tc_downloads mkdir tc_pxe_mnt mkdir tc_pxe mkdir tc_pxe/pxelinux.cfg mkdir tc_pxe/tc_pxe_dev mkdir tc_pxe/tc_pxe_dev/core_root # Download and copy TinyCore echo '*********************Downloading, Extracting and Copying TinyCore-current.iso' cd tc_downloads if [ ! -f TinyCore-current.iso ] then wget http://distro.ibiblio.org/tinycorelinux/4.x/x86/release/TinyCore-current.iso fi mount TinyCore-current.iso ../tc_pxe_mnt -o loop,ro cp -r ../tc_pxe_mnt/* ../tc_pxe umount ../tc_pxe_mnt cp ../tc_pxe/boot/core.gz ../tc_pxe/tc_pxe_dev cd ../tc_pxe/tc_pxe_dev/core_root zcat ../core.gz | sudo cpio -i -H newc -d # Make directories and scripts for arduino initialization echo '*********************Build new rootfs and add scripts for PXE boot' mkdir home/scada mkdir home/scada/scripts mkdir home/scada/data echo '#!/bin/bash' > home/scada/scripts/arduino_init echo '# arduino_init - initialization tasks for scada' >> home/scada/scripts/arduino_init echo '### Main script starts here ###' >> home/scada/scripts/arduino_init echo '# Store file name of arduino' >> home/scada/scripts/arduino_init echo 'FILE="/dev/arduino_1"' >> home/scada/scripts/arduino_init echo ' ' >> home/scada/scripts/arduino_init echo '# Arduino Communications' >> home/scada/scripts/arduino_init echo '# set serial commuication for arduino' >> home/scada/scripts/arduino_init echo 'stty -F $FILE cs8 115200 ignbrk -brkint -icrnl -imaxbel -opost -onlcr -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke noflsh -ixon -crtscts' >> home/scada/scripts/arduino_init echo '# make sure file (serial device) exist and is readable' >> home/scada/scripts/arduino_init echo 'if ! pidof socat TCP-LISTEN:2111,fork OPEN:/dev/arduino_1; then' >> home/scada/scripts/arduino_init echo ' echo "$FILE is not logging"' >> home/scada/scripts/arduino_init echo ' if [ ! -c $FILE ]; then' >> home/scada/scripts/arduino_init echo ' echo "$FILE : does not exists"' >> home/scada/scripts/arduino_init echo ' exit 1' >> home/scada/scripts/arduino_init echo ' elif [ ! -r $FILE ]; then' >> home/scada/scripts/arduino_init echo ' echo "$FILE: can not read"' >> home/scada/scripts/arduino_init echo ' exit 2' >> home/scada/scripts/arduino_init echo ' else' >> home/scada/scripts/arduino_init echo ' socat TCP-LISTEN:2111,fork OPEN:/dev/arduino_1' >> home/scada/scripts/arduino_init echo ' echo "start process - socat TCP-LISTEN:2111,fork OPEN:$FILE"' >> home/scada/scripts/arduino_init echo ' fi' >> home/scada/scripts/arduino_init echo 'fi' >> home/scada/scripts/arduino_init echo 'exit 0' >> home/scada/scripts/arduino_init chmod 755 home/scada/scripts/arduino_init # Add services to the boot script echo '/etc/init.d/dropbear start' >> opt/bootlocal.sh echo 'sh /home/scada/scripts/arduino_init &' >> opt/bootlocal.sh echo 'SUBSYSTEMS=="usb", ATTRS{serial}=="A700618T", ATTRS{product}=="FT232R USB UART", ATTRS{idProduct}=="6001", ATTRS{idVendor}=="0403", NAME="arduino_1"' > etc/udev/rules.d/98-arduino.rules # Build tiny_core rootfs find | cpio -o -H newc | gzip -2 > ../ard-core.gz cd .. cp ard-core.gz ../boot/ # Create build_tinycore script echo 'cd core-root' > build_tinycore echo 'find | cpio -o -H newc | gzip -2 > ../ard-core.gz' >> build_tinycore echo 'cd ..' >> build_tinycore echo 'cp ard-core.gz ../boot/' >> build_tinycore chmod 700 build_tinycore # Download optional software packages echo '*********************Downloading Additional Packages for TinyCore' cd ../../tc_downloads # Get ssh dropbear if [ -f dropbear.tcz ] then cp dropbear.tcz ../tc_pxe/cde/optional/ else wget http://distro.ibiblio.org/tinycorelinux/4.x/x86/tcz/dropbear.tcz cp dropbear.tcz ../tc_pxe/cde/optional/ fi # Get net utility socat if [ -f socat.tcz ] then cp socat.tcz ../tc_pxe/cde/optional/ else wget http://distro.ibiblio.org/tinycorelinux/4.x/x86/tcz/socat.tcz cp socat.tcz ../tc_pxe/cde/optional/ fi # Get usb to serial utility if [ -f usb-serial-3.0.21-tinycore.tcz ] then cp usb-serial-3.0.21-tinycore.tcz ../tc_pxe/cde/optional/ else wget http://distro.ibiblio.org/tinycorelinux/4.x/x86/tcz/usb-serial-3.0.21-tinycore.tcz cp usb-serial-3.0.21-tinycore.tcz ../tc_pxe/cde/optional/ fi cd ../tc_pxe # Check if file exists before copy. If it does not exist then download the syslinux and extract if [ -f "/usr/share/syslinux/pxelinux.0" ] then cp /usr/share/syslinux/pxelinux.0 . else echo '*********************Unable to find /usr/share/syslinux/pxelinux.0 downloading syslinux' cd ../tc_downloads if [ ! -f "syslinux-4.06/core/pxelinux.0" ] then if [ ! -f "syslinux-4.06.tar.gz" ] then wget http://www.kernel.org/pub/linux/utils/boot/syslinux/4.xx/syslinux-4.06.tar.gz fi tar -zxf syslinux-4.06.tar.gz cp syslinux-4.06/core/pxelinux.0 ../tc_pxe/pxelinux.0 else cp syslinux-4.06/core/pxelinux.0 ../tc_pxe/pxelinux.0 fi cd ../tc_pxe fi cd pxelinux.cfg echo 'default boot/vmlinuz' > default echo 'append initrd=boot/ard-core.gz tftplist=192.168.1.1:/tc_pxe/cde/onboot_x.lst xvesa=800x600x32' >> default cd ../cde echo '/tc_pxe/cde/optional/Xlibs.tcz' > onboot_x.lst echo '/tc_pxe/cde/optional/Xprogs.tcz' >> onboot_x.lst echo '/tc_pxe/cde/optional/Xvesa.tcz' >> onboot_x.lst echo '/tc_pxe/cde/optional/fltk-1.10.tcz' >> onboot_x.lst echo '/tc_pxe/cde/optional/wbar.tcz' >> onboot_x.lst echo '/tc_pxe/cde/optional/flwm_topside.tcz' >> onboot_x.lst echo '/tc_pxe/cde/optional/usb-serial-3.0.21-tinycore.tcz' >> onboot_x.lst echo '/tc_pxe/cde/optional/dropbear.tcz' >> onboot_x.lst echo '/tc_pxe/cde/optional/socat.tcz' >> onboot_x.lst echo '*********************Install Complete'