Skip to content

Instantly share code, notes, and snippets.

@dzid26
Forked from SippieCup/install_deletion_job.sh
Created September 12, 2018 01:47
Show Gist options
  • Save dzid26/9c97eb1a33887a18ec1a79f4a8ccc7c8 to your computer and use it in GitHub Desktop.
Save dzid26/9c97eb1a33887a18ec1a79f4a8ccc7c8 to your computer and use it in GitHub Desktop.
Installer for script & cron job that automatically deletes older drives when free space goes under 10GB.
#!/bin/sh
echo "Creating /data/cleardata/cleardata.sh"
# Create deletion script
mkdir /data/cleardata
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 300MB (300000kB)
if ((\$size<300000)); then
# find all files currently saved by openpilot
find /storage/emulated/0/Android/data/ai.comma.plus.offroad/files/* -mmin +480 -exec rm -f {} \;
fi" > /data/cleardata/cleardata.sh
chmod +x /data/cleardata/cleardata.sh
# Create job file
echo "Creating /data/crontab/root"
mkdir /data/crontab
echo "
00 * * * * /data/cleardata/cleardata.sh" > /data/crontab/root
#start job
echo "Starting cron job"
crond -b -c /data/crontab
# ### 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" >> /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
echo "Done!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment