scripts

Autostart script from USB device with Udev

Stage 1: Create Udev rule
<?php
$URL="http://dl.panticz.de/udev/autorun/70-persistent-usb_autorun.rules";
echo "sudo wget $URL -O /etc/udev/rules.d/70-persistent-usb_autorun.rules";
echo "

";
$c = curl_init();
curl_setopt($c, CURLOPT_URL, $URL);
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
echo htmlspecialchars(curl_exec($c));
curl_close($c);
echo "

";
?>

Stage 2: Create autorun wrapper
<?php
$URL="http://dl.panticz.de/udev/autorun/usb_autorun.sh";
echo "sudo wget $URL -O /usr/sbin/usb_autorun.sh";
echo "\n";
echo "sudo chmod a+x /usr/sbin/usb_autorun.sh";
echo "

";
$c = curl_init();
curl_setopt($c, CURLOPT_URL, $URL);
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
echo htmlspecialchars(curl_exec($c));
curl_close($c);
echo "

";
?>

Stage 3: Create autorun.sh script on your USB device (example)
<?php
$URL="http://dl.panticz.de/udev/autorun/autorun.sh";
echo "cd /media/YOUR_USB_DEVICE";
echo "\n";
echo "wget $URL -O ./autorun.sh";
echo "\n";
echo "chmod a+x ./autorun.sh";
echo "

";
$c = curl_init();
curl_setopt($c, CURLOPT_URL, $URL);
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
echo htmlspecialchars(curl_exec($c));
curl_close($c);
echo "

";
?>