Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Installer for script & cron job that automatically deletes older drives when free space goes under 5GB.
#!/bin/sh
# Create deletion script
if [ ! -d /data/cleardata ]
then
echo "Creating /data/cleardata folder"
mkdir /data/cleardata
else
echo "/data/cleardata folder already exists..."
fi
if [ ! -f /data/cleardata/cleardata.sh ]
then
echo "Creating /data/cleardata/cleardata.sh script"
else
echo "Updating /data/cleardata/cleardata.sh script"
fi
echo "#!/bin/sh
# get the available space left on the device
size=\$(df -k /storage/emulated/0/Android/data | tail -1 | awk '{print \$4}')
# check if the available space is smaller than 5GB (5000000kB)
if ((\$size<5000000)); then
# find all files currently saved by openpilot in the past 7 hours and delete them.
find /data/media/0/realdata/* -mmin +420 -exec rm -rf {} \;
fi" > /data/cleardata/cleardata.sh
chmod +x /data/cleardata/cleardata.sh
# Create job file to run every 10 minutes.
if [ ! -d /data/crontab ]
then
echo "Creating /data/crontab"
mkdir /data/crontab
else
echo "/data/crontab folder already exists..."
fi
if [ ! -f /data/crontab/root ]
then
echo "Creating /data/crontab/root cron job"
else
echo "Updating existing /data/crontab/root cron job"
fi
echo "
*/10 * * * * /data/cleardata/cleardata.sh" > /data/crontab/root
#start job
cron_args="crond -b -c /data/crontab"
if [[ `ps -o args | grep "crond -b -c /data/crontab" | head -1` == "crond -b -c /data/crontab" ]]
then
echo "cronjob already running"
else
echo "Starting cron job"
crond -b -c /data/crontab
fi
if [ ! -f /system/etc/init.d/crond ]
then
echo "Persisting cron job after reboot"
# Remount /system to be read/write
mount -o rw,remount /dev/block/bootdevice/by-name/system /system
# Use Busybox crond
echo "
crond -b -c /data/crontab" >> /system/etc/init.d/crond
chmod +x /system/etc/init.d/crond
# Remount /system to be read only
mount -o ro,remount /dev/block/bootdevice/by-name/system /system
elif [[ `grep -r "crond -b -c /data/crontab" /system/etc/init.d/crond` == "crond -b -c /data/crontab" ]]
then
echo "Busybox crond already configured"
else
### For persistance after reboot
echo "Persisting cron job after reboot"
# Remount /system to be read/write
mount -o rw,remount /dev/block/bootdevice/by-name/system /system
# Use Busybox crond
echo "
crond -b -c /data/crontab" >> /system/etc/init.d/crond
chmod +x /system/etc/init.d/crond
# Remount /system to be read only
mount -o ro,remount /dev/block/bootdevice/by-name/system /system
fi
echo "Done!"
@tentious

This comment has been minimized.

Copy link
Owner Author

tentious commented Sep 5, 2018

Updated to reflect new video/data location.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.