13 changed files with 21 additions and 3573 deletions
			
			
		| @ -1,521 +0,0 @@ | |||
| #!/bin/sh | |||
| 
 | |||
| # Auto-Record-Cleaner (aurecl) - automatically remove old recorded events | |||
| 
 | |||
| # Copyright (C) 2014 LtCmdrLuke | |||
| # | |||
| # This program is free software; you can redistribute it and/or modify | |||
| # it under the terms of the GNU General Public License as published by | |||
| # the Free Software Foundation; either version 2 of the License, or | |||
| # (at your option) any later version. | |||
| # | |||
| # This program is distributed in the hope that it will be useful, | |||
| # but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
| # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
| # GNU General Public License for more details. | |||
| # | |||
| # You should have received a copy of the GNU General Public License | |||
| # along with this program; if not, write to the Free Software | |||
| # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA | |||
| 
 | |||
| 
 | |||
| # This is a test-script for automatically handling the oldest records in a | |||
| # specified directory after the directory has reached a certain size. Files | |||
| # which will be deleted next are first moved to a "last-chance" directory | |||
| # before they are finally deleted. In each run, only as much files will be | |||
| # really deleted as needed to limit the maximum allowed size of the directory. | |||
| 
 | |||
| # The main intention of this script is its usage in conjunction with the | |||
| # "channel-crawling"-feature of the Auto-Timer on a neutrino-based set top box. | |||
| # Basic idea: | |||
| #   Record every event of certain channels and delete always the | |||
| #   oldest recordings in the record directory, but give the user a chance | |||
| #   to see what is about to be deleted next. By running this script regularly | |||
| #   you can keep always the latest x days of all events from a certain channel | |||
| #   available for watching anytime, i.e. fully independent of broadcasting | |||
| #   times. (It basically resembles 'Sky Anytime') | |||
| 
 | |||
| # Install & usage: | |||
| # - Copy the script somewhere on your box and make it executable | |||
| # - Edit the following variables to correspond to your environment, e.g. | |||
| #   which directory should be watched and how much space you want to give it | |||
| # - call it regularly, either manually, or in some automated way. When calling | |||
| #   it, provide the command line option "--yes" to confirm, you really want | |||
| #   files to be deleted. Without this command line option, it will perform a | |||
| #   dry run, i.e. just tell you what it would do now. | |||
| 
 | |||
| # Related files: | |||
| #	General Configuration:		/var/tuxbox/config/auto-record-cleaner.conf | |||
| #	Controlled directories:		/var/tuxbox/config/auto-record-cleaner.rules | |||
| 
 | |||
| VERSION=0.2 | |||
| 
 | |||
| # Changelog: | |||
| # | |||
| # 0.2 | |||
| #	- Added new command line options: | |||
| #		-y|--yes twice to deactivate the 5s safety | |||
| #		-q|--quiet deactivate all console output (and also deactivate the 5s safety) | |||
| #		-h|--help shows the command line options | |||
| #	- Logs now to a logfile (besides the console, if not deactivated with -q) | |||
| #	- Now uses own configuration file under /var/tuxbox/config/auto-record-cleaner.conf | |||
| #	  * Here the default path for the log-file and the rule-file can be changed | |||
| #	  * Provided a template file (auto-record-cleaner.conf.template); default values should be fine. | |||
| #	- Now uses own rules file under /var/tuxbox/config/auto-record-cleaner.rules | |||
| #	  * An arbitrary number of different directories can now be cleaned | |||
| #	  * Provided a template (auto-record-cleaner.rules.template) with examples | |||
| #	  * Basic Syntax is CLEANING_PATH,MAX_SIZE_CP;LAST_CHANCE_PATH,MAX_SIZE_LCP | |||
| # | |||
| # 0.1 | |||
| #	- Initial release | |||
| #	- Restrictions: | |||
| #	  * only one controlled directory | |||
| #	  * Configuration directly in the script | |||
| #	  * Shell-only, no information in neutrino | |||
| #	  * No log-file, logs to stdout | |||
| 
 | |||
| # Beyond this point, no user-configurable settings | |||
| ############################################################################### | |||
| 
 | |||
| NAME="Auto-Record-Cleaner" | |||
| ME=${0##*/} | |||
| 
 | |||
| CONFIG_FILE=/var/tuxbox/config/$ME.conf | |||
| PID_FILE=/var/run/$ME.pid | |||
| 
 | |||
| EXIT_NORMAL=0 | |||
| EXIT_SIGNAL=1 | |||
| EXIT_NO_RULE_FILE=2 | |||
| EXIT_ALREADY_RUNNING=3 | |||
| EXIT_UNKNOWN_COMMAND_OPTION=4 | |||
| 
 | |||
| ####################################################################################### | |||
| #BEGIN SECTION "Helper functions" | |||
| 
 | |||
| signal_handler() { | |||
| 	#Handle INT, TERM signals and clean up. | |||
| 	log "Caught signal. Cleaning up." | |||
| 	cleanup | |||
| 	set +f | |||
| 	log "done." | |||
| 	log "$ME V${VERSION} exiting now." | |||
| 	exit $EXIT_SIGNAL | |||
| } | |||
| 
 | |||
| cleanup() { | |||
| 	# Remove the pid-file | |||
| 	rm -rf $PID_FILE 2>/dev/null | |||
| } | |||
| 
 | |||
| log() { | |||
| 	#Log message to log file | |||
| 	#$*: Log message | |||
| 	if [ "$LOG_FILE" != "" ]; then | |||
| 		echo -e $(date +'%F %H:%M:%S') [$$]: "$*" >> $LOG_FILE | |||
| 	fi | |||
| 	if [ $quiet == 0 ]; then | |||
| 		echo -e "$*" | |||
| 	fi | |||
| } | |||
| 
 | |||
| begin_ifs_block() { | |||
| 	#Backup IFS (input field separator) to restore it after parsing arguments | |||
| 	IFS_SAVE=$IFS | |||
| 	set -f | |||
| } | |||
| 
 | |||
| end_ifs_block() { | |||
| 	#Restore (input field separator) IFS after parsing arguments | |||
| 	IFS=$IFS_SAVE | |||
| 	set +f | |||
| } | |||
| 
 | |||
| #END SECTION "Helper functions" | |||
| ####################################################################################### | |||
| 
 | |||
| ####################################################################################### | |||
| #BEGIN SECTION "Initialization" | |||
| 
 | |||
| init_config() { | |||
| 	#Parse config file (default: /var/tuxbox/config/auto-record-cleaner.conf) | |||
| 	if [ -e $CONFIG_FILE ]; then | |||
| 		source $CONFIG_FILE 2>/dev/null | |||
| 	fi | |||
| 
 | |||
| 	# Initialize the logfile first, so we can write to it... | |||
| 	if [ ! -d "${LOG_FILE%/*}" ]; then | |||
| 		case $LOG_FILE in | |||
| 			[oO][fF][fF]) | |||
| 				LOG_FILE='' | |||
| 				;; | |||
| 			*) | |||
| 				LOG_FILE=/tmp/${ME}_$(date +'%F').log | |||
| 				;; | |||
| 		esac | |||
| 	fi | |||
| 	echo -e "\n\n========================== $NAME started new log at $(date) ======================================" >> $LOG_FILE | |||
| 
 | |||
| 	# Check other settings and reset them to default if unset or invalid | |||
| 	if [ ! -e "$RULE_FILE" ]; then | |||
| 		RULE_FILE=/var/tuxbox/config/$ME.rules | |||
| 		if [ ! -e "$RULE_FILE" ]; then | |||
| 			log "ERROR: Rules file '$RULE_FILE' does not exist! Exiting." | |||
| 			exit $EXIT_NO_RULE_FILE | |||
| 		fi | |||
| 	fi | |||
| } | |||
| 
 | |||
| #END SECTION "Initialization" | |||
| ####################################################################################### | |||
| 
 | |||
| ####################################################################################### | |||
| #BEGIN SECTION "Command line options handling" | |||
| 
 | |||
| parse_options() { | |||
| 	#Parse auto-record-cleaner command line arguments | |||
| 	local option | |||
| 
 | |||
| 	while [ $# -gt 0 ] | |||
| 	do | |||
| 		option=$1 | |||
| 		shift | |||
| 
 | |||
| 		case "$option" in | |||
| 			-y|--yes) | |||
| 				dry_run=$((dry_run-1)) | |||
| 			;; | |||
| 			-q|--quiet) | |||
| 				quiet=1 | |||
| 			;; | |||
| 			-h|--help) | |||
| 				usage | |||
| 				exit $EXIT_NORMAL | |||
| 			;; | |||
| 			*) | |||
| 				echo "Unknown command line option '$option'. What did you want to do? Exiting!" | |||
| 				usage | |||
| 				exit $EXIT_UNKNOWN_COMMAND_OPTION | |||
| 			;; | |||
| 		esac | |||
| 	done | |||
| } | |||
| 
 | |||
| usage() { | |||
| 	# Print short usage message on console | |||
| 	echo -e "Usage: $ME [options]" | |||
| 	echo -e "Valid options are:" | |||
| 	echo -e "\t-y|--yes\t\tSwitches safety off and really deletes/moves files. Use twice to deactivate 5s safety interval." | |||
| 	echo -e "\t-q|--quiet\t\tDeactivates all output on console. Also deactivates 5s safety interval." | |||
| 	echo -e "\t-h|--help\t\tPrint this help and exit." | |||
| } | |||
| 
 | |||
| #END SECTION "Command line options handling" | |||
| ####################################################################################### | |||
| 
 | |||
| ####################################################################################### | |||
| #BEGIN SECTION "Work functions" | |||
| 
 | |||
| limit_directory() { | |||
| 	# Moves or deletes oldest files in a given directory | |||
| 	# Parameters: | |||
| 	# $1: The directory from which the files should be moved/deleted | |||
| 	# $2: the maximum size of the directory in kB | |||
| 	# $3: optional: the directory into which files should be moved. If this | |||
| 	#     parameter is missing, files will be deleted | |||
| 	# Precondition: All provided directories must exist. | |||
| 
 | |||
| 	local dir max_dir_size dir_size dest_dir over_limit ts_files ts | |||
| 
 | |||
| 	dir="$1" | |||
| 	max_dir_size="$2" | |||
| 	dir_size=$(du -s -k "$dir" | cut -f1) | |||
| 	dest_dir="$3" | |||
| 
 | |||
| 	# in case there is a destination folder given, we need to get its size | |||
| 	# and subtract this from the current dir size | |||
| 	if [ -n "$dest_dir" ]; then | |||
| 		dest_dir_size=$(du -s -k "$dest_dir" | cut -f1) | |||
| 		dir_size=$((dir_size-dest_dir_size)) | |||
| 		log "\t\t\tLimiting '$dir' to max size $((max_dir_size/(1024*1024)))GB by moving the oldest files to '$dest_dir' ... " | |||
| 	else | |||
| 		log "\t\t\tLimiting '$dir' to max size $((max_dir_size/(1024*1024)))GB by deleting the oldest files ..." | |||
| 	fi | |||
| 
 | |||
| 	if [ $dir_size -gt $max_dir_size ]; then | |||
| 		over_limit=$((dir_size-max_dir_size)) | |||
| 		if [ -z "$dest_dir" ]; then | |||
| 			log "\t\t\t\tWe need to delete $((over_limit/(1024*1024)))GB (${over_limit}kB) from '$dir' ..." | |||
| 		else | |||
| 			log "\t\t\t\tWe need to move $((over_limit/(1024*1024)))GB (${over_limit}kB) from '$dir' to '$dest_dir' ..." | |||
| 		fi | |||
| 	else | |||
| 		log "\t\t\t\tNothing to do in directory '$dir'. Current size has not reached the limit." | |||
| 		return 0 | |||
| 	fi | |||
| 
 | |||
| 	# we don't want to use the ls command since its output is not POSIX-standard | |||
| 	# therefore, we first find all files and then we use the date command to | |||
| 	# determine the modification time | |||
| 
 | |||
| 	# first collect all *.ts files | |||
| 	ts_files=$(find "$dir" -name "*.ts") | |||
| 
 | |||
| 	# now gather additional information, like modification time and size | |||
| 	# (we could have got this info from ls in ONE call..) | |||
| 	begin_ifs_block | |||
| 		IFS=$'\n' | |||
| 		for ts in $ts_files; do | |||
| 			ts_date=$(date -r "$ts" +%s) | |||
| 			ts_size=$(du -k "$ts" | cut -f1) | |||
| 			ts_files_ext="${ts_files_ext}${ts}|$ts_date|$ts_size\n" | |||
| 			#echo "$ts|$ts_date|$ts_size" | |||
| 		done | |||
| 	end_ifs_block | |||
| 
 | |||
| 	# sort the final list with respect to the modification time | |||
| 	sorted_ts_files_ext=$(echo -ne "$ts_files_ext" | sort -t '|' -k2) | |||
| 
 | |||
| 	count=0 | |||
| 	# now (re)move until limit is reached | |||
| 	begin_ifs_block | |||
| 		IFS=$'\n' | |||
| 		for ts_file in $sorted_ts_files_ext; do | |||
| 			IFS='|' | |||
| 			set -- $ts_file | |||
| 			filename=$1 | |||
| 			filetime=$2 | |||
| 			filesize=$3 | |||
| 
 | |||
| 			# skip the file, if it is already in dest_dir | |||
| 			if [ "${filename%/*}" == "$dest_dir" ]; then | |||
| 				#echo -e "\tSkipping $filename .." | |||
| 				continue | |||
| 			fi | |||
| 
 | |||
| 			xml_file=${filename%".ts"}".xml" | |||
| 
 | |||
| 			if [ $dry_run == 0 ]; then | |||
| 				if [ -z "$dest_dir" ]; then | |||
| 					log "\t\t\t\tDeleting now '$filename' (${filesize}kB).." | |||
| 					rm "$filename" 2>/dev/null | |||
| 					if [ -f "$xml_file" ];then | |||
| 						log "\t\t\t\tDeleting now also the corresponding '$xml_file' ... " | |||
| 						rm "$xml_file" 2>/dev/null | |||
| 					fi | |||
| 				else | |||
| 					log "\t\t\t\tMoving '$filename' (${filesize}kB) to '$dest_dir' ..." | |||
| 					mv "$filename" "$dest_dir" 2>/dev/null | |||
| 					if [ -f "$xml_file" ];then | |||
| 						log "\t\t\t\tMoving now also the corresponding '$xml_file' to '$dest_dir' ... " | |||
| 						mv "$xml_file" "$dest_dir" 2>/dev/null | |||
| 					fi | |||
| 				fi | |||
| 			else | |||
| 				if [ -z "$dest_dir" ]; then | |||
| 					log "\t\t\t\tDRY-RUN: Would remove now '$filename' (${filesize}kB).." | |||
| 					if [ -f "$xml_file" ];then | |||
| 						log "\t\t\t\tDRY-RUN: Would delete now also the corresponding '$xml_file' ... " | |||
| 					fi | |||
| 				else | |||
| 					log "\t\t\t\tDRY-RUN: Would move now '$filename' (${filesize}kB) to '$dest_dir' ..." | |||
| 					if [ -f "$xml_file" ];then | |||
| 						log "\t\t\t\tDRY-RUN: Would move now also the corresponding '$xml_file' to '$dest_dir' ... " | |||
| 					fi | |||
| 				fi | |||
| 			fi | |||
| 
 | |||
| 			over_limit=$((over_limit-filesize)) | |||
| 			count=$((count+1)) | |||
| 
 | |||
| 			if [ $over_limit -le 0 ]; then | |||
| 				removed=$((dir_size-max_dir_size-over_limit)) | |||
| 
 | |||
| 				if [ $dry_run == 0 ]; then | |||
| 					if [ -z "$dest_dir" ]; then | |||
| 						log "\t\t\t\tDone. Removed $((removed/(1024*1024)))GB (${removed}kB) by deleting $count recorded events." | |||
| 					else | |||
| 						log "\t\t\t\tDone. Moved $((removed/(1024*1024)))GB (${removed}kB) in $count recorded events to directory '$dest_dir'." | |||
| 					fi | |||
| 				else | |||
| 					if [ -z "$dest_dir" ]; then | |||
| 						log "\t\t\t\tDRY_RUN: Done. Would have removed $((removed/(1024*1024)))GB (${removed}kB) by deleting $count recorded events." | |||
| 					else | |||
| 						log "\t\t\t\tDRY_RUN: Done. Would have moved $((removed/(1024*1024)))GB (${removed}kB) in $count recorded events to directory '$dest_dir'." | |||
| 					fi | |||
| 				fi | |||
| 				# we are done, so break from the loop | |||
| 				break | |||
| 			fi | |||
| 		done | |||
| 	end_ifs_block | |||
| 
 | |||
| 	return 0 | |||
| } | |||
| 
 | |||
| #END SECTION "Work functions" | |||
| ####################################################################################### | |||
| 
 | |||
| ############################################################################### | |||
| #BEGIN Section "Main" | |||
| 
 | |||
| # initialize some more variables | |||
| dry_run=1 | |||
| quiet=0 | |||
| 
 | |||
| # set the signal handler | |||
| trap signal_handler INT TERM | |||
| 
 | |||
| # First initialize the values from the config, otherwise we cannot log anywhere | |||
| init_config | |||
| 
 | |||
| # Now get command line option, as these might override some values from the config or default variables | |||
| parse_options $@ | |||
| 
 | |||
| if [ -e $PID_FILE ]; then | |||
| 	log "$ME ist already running. Exiting..." | |||
| 	exit $EXIT_ALREADY_RUNNING | |||
| else | |||
| 	echo $$ > $PID_FILE | |||
| fi | |||
| 
 | |||
| # We happily started.. | |||
| log "" | |||
| log "$ME V$VERSION initialized and starting main operations." | |||
| 
 | |||
| if [ $dry_run == 1 ]; then | |||
| 	log "\tThis is a dry run, i.e. no files will be harmed. Use '-y' or '--yes' to deactivate the safety." | |||
| elif [ $dry_run == 0 ] && [ $quiet == 0 ]; then | |||
| 	log "\t!!! WARNING!!! This is now the real thing - files WILL BE DELETED. You can still abort within the next 5 seconds. !!! WARNING !!!" | |||
| 	echo "Waiting for 5 more seconds.." | |||
| 	sleep 1 | |||
| 	echo "Waiting for 4 more seconds.." | |||
| 	sleep 1 | |||
| 	echo "Waiting for 3 more seconds.." | |||
| 	sleep 1 | |||
| 	echo "Waiting for 2 more seconds.." | |||
| 	sleep 1 | |||
| 	echo "Waiting for 1 more seconds.." | |||
| 	sleep 1 | |||
| 	echo "You have been warned. Proceeding..." | |||
| else | |||
| 	log "\t!!! WARNING!!! $ME is armed and targeting your files. !!! WARNING !!!" | |||
| fi | |||
| 
 | |||
| # now process each directory given in the rule-file | |||
| 
 | |||
| rule_line=0 | |||
| cat $RULE_FILE | while read line; do | |||
| 	rule_line=$((${rule_line}+1)) | |||
| 	if echo $line | egrep -q '^[[:space:]]*([^#;]+),([0-9]+);?([^;]+)?(,[0-9]+)?$'; then | |||
| 
 | |||
| 		log "" | |||
| 		log "\tProcessing rule: '$line'" | |||
| 
 | |||
| 		# split rule line | |||
| 		begin_ifs_block | |||
| 			IFS=';' | |||
| 			set -- $line | |||
| 			record_part=$1 | |||
| 			last_chance_part=$2 | |||
| 		end_ifs_block | |||
| 
 | |||
| 		# split record_part | |||
| 		begin_ifs_block | |||
| 			IFS=',' | |||
| 			set -- $record_part | |||
| 			record_dir=$1 | |||
| 			record_dir_size=$2 | |||
| 		end_ifs_block | |||
| 
 | |||
| 		if [ -n "$last_chance_part" ]; then | |||
| 			# split last_chance_part | |||
| 			begin_ifs_block | |||
| 				IFS=',' | |||
| 				set -- $last_chance_part | |||
| 				last_chance_dir=$1 | |||
| 				last_chance_dir_size=$2 | |||
| 			end_ifs_block | |||
| 			if [ -z $last_chance_dir_size ]; then | |||
| 				last_chance_dir_size=$((record_dir_size / 10)) | |||
| 			fi | |||
| 		else | |||
| 			last_chance_dir="last_chance" | |||
| 			last_chance_dir_size=$((record_dir_size / 10)) | |||
| 		fi | |||
| 
 | |||
| 		# convert GB into kB | |||
| 		record_dir_size_k=$((record_dir_size * 1024 * 1024)) | |||
| 		last_chance_dir_size_k=$((last_chance_dir_size * 1024 * 1024)) | |||
| 
 | |||
| 		# print the collected information to the log: | |||
| 		log "\t\tCleaning path: '$record_dir', Maximum size: ${record_dir_size}GB (${record_dir_size_k}kB)" | |||
| 		log "\t\tLast chance subdirectory: '$last_chance_dir', Maximum size: ${last_chance_dir_size}GB (${last_chance_dir_size_k}kB)" | |||
| 
 | |||
| 		# now check if directories exist | |||
| 		# if the cleaning directory does not exist, print an error and continue with next rule | |||
| 		if [ ! -d "$record_dir" ]; then | |||
| 			log "\t\tThe given directory '$record_dir' does not exist. Create it or correct this rule. Skipping this rule." | |||
| 			continue | |||
| 		fi | |||
| 
 | |||
| 		#convert the last_chance relative path to an absolut one | |||
| 		last_chance_dir="${record_dir%/}/$last_chance_dir" | |||
| 
 | |||
| 		# if the last chance directory does not exist yet, create it. | |||
| 		if [ ! -d "$last_chance_dir" ]; then | |||
| 
 | |||
| 			if [ $dry_run == 0 ]; then | |||
| 				log "\t\tCreating directory '$last_chance_dir' for last chance files, as it does not exist yet." | |||
| 				mkdir "$last_chance_dir" | |||
| 			else | |||
| 				log "\t\tWould now create directory '$last_chance_dir' for last chance files, as it does not exist yet. (dry-run, i.e. NOT performing any action)" | |||
| 			fi | |||
| 		fi | |||
| 
 | |||
| 		# get the current size of the directories (in kB)... | |||
| 		current_record_dir_usage_k=$(du -s -k "$record_dir" | cut -f1) | |||
| 		current_last_chance_dir_size_k=$(du -s -k "$last_chance_dir" | cut -f1) | |||
| 
 | |||
| 		# ... and print them into the log | |||
| 		log "\t\tCurrent full size of '$record_dir' (recursively) is $((current_record_dir_usage_k/(1024*1024)))GB (${current_record_dir_usage_k}kB)." | |||
| 		log "\t\tCurrent size of '$last_chance_dir' is $((current_last_chance_dir_size_k/(1024*1024)))GB (${current_last_chance_dir_size_k}kB)." | |||
| 
 | |||
| 		# perform some initial checks, if we actually need to do something | |||
| 		if [ $((current_record_dir_usage_k-current_last_chance_dir_size_k)) -le $((record_dir_size_k-last_chance_dir_size_k)) ] && [ $current_last_chance_dir_size_k -le $last_chance_dir_size_k ] ;then | |||
| 			log "\t\tNothing to do for this rule - disk usage is within the given specification." | |||
| 			continue | |||
| 		fi | |||
| 
 | |||
| 		over_limit=0 | |||
| 		if [ $current_record_dir_usage_k -gt $record_dir_size_k ];then | |||
| 			over_limit=$((current_record_dir_usage_k-record_dir_size_k)) | |||
| 			log "\t\tWe need to remove $((over_limit/(1024*1024)))GB (${over_limit}kB) from directory '$record_dir'." | |||
| 		fi | |||
| 
 | |||
| 		if [ $((current_record_dir_usage_k-current_last_chance_dir_size_k-over_limit)) -gt $((record_dir_size_k-last_chance_dir_size_k)) ];then | |||
| 			move_size=$((current_record_dir_usage_k-current_last_chance_dir_size_k-over_limit-(record_dir_size_k-last_chance_dir_size_k))) | |||
| 			log "\t\tWe need to move $((move_size/(1024*1024)))GB (${move_size}kB) from directory '$record_dir' to '$last_chance_dir'." | |||
| 		fi | |||
| 
 | |||
| 		# first we delete the oldest files from the main directory (including last chance) | |||
| 		# if your last_chance is too small, some files will never appear in there | |||
| 		limit_directory "$record_dir" "$record_dir_size_k" | |||
| 
 | |||
| 		# now fill the last chance directory | |||
| 		limit_directory "$record_dir" "$((record_dir_size_k-last_chance_dir_size_k))" "$last_chance_dir" | |||
| 
 | |||
| 		# final status | |||
| 		new_record_dir_usage_k=$(du -s -k "$record_dir" | cut -f1) | |||
| 		new_last_chance_dir_size_k=$(du -s -k "$last_chance_dir" | cut -f1) | |||
| 
 | |||
| 		log "\t\tNew full size of '$record_dir' (recursively) is $((new_record_dir_usage_k/(1024*1024)))GB (${new_record_dir_usage_k}kB)." | |||
| 		log "\t\tNew size of '$last_chance_dir' is $((new_last_chance_dir_size_k/(1024*1024)))GB (${new_last_chance_dir_size_k}kB)." | |||
| 	fi | |||
| done | |||
| 
 | |||
| log "" | |||
| log "$ME V${VERSION} finished rule processing." | |||
| 
 | |||
| cleanup | |||
| log "========================== $NAME finished at $(date) ======================================" | |||
| exit $EXIT_NORMAL; | |||
| @ -1,9 +0,0 @@ | |||
| # General configuration for the auto-record-cleaner | |||
| 
 | |||
| # Activate the following to change the default path of the rule file | |||
| #RULE_FILE=/var/tuxbox/config/$ME.rules | |||
| 
 | |||
| # Deactivate the logfile (default is ON) | |||
| #LOG_FILE=off | |||
| # Activate the following to change the default location of the log-file | |||
| #LOG_FILE=/tmp/${ME}_$(date +'%F').log | |||
| @ -1,47 +0,0 @@ | |||
| # auto-record-cleaner.rules | |||
| # | |||
| # ---------------------------------------------------------------------------- | |||
| # | |||
| # Syntax: CLEANING_PATH,MAX_SIZE_CP;LAST_CHANCE_PATH,MAX_SIZE_LCP | |||
| # | |||
| # CLEANING_PATH		The path which should be cleaned | |||
| #					Example: /media/sda1/movies | |||
| #					The argument is mandatory. | |||
| # | |||
| # MAX_SIZE_CP		The maximum size of the CLEANING_PATH given in GB | |||
| #					When the size grows beyond this value, the oldest files will be deleted | |||
| #					Example: 450 | |||
| #					The argument is mandatory. | |||
| # | |||
| # LAST_CHANCE_PATH	The name of the directory, which should be created for files | |||
| #					which will be deleted soon. | |||
| #					Example: last_chance | |||
| #					The argument is optional, if not given "last_chance" is used. | |||
| # | |||
| # MAX_SIZE_LCP		The maximum size of the LAST_CHANCE_PATH given in GB | |||
| #					Example: 50 | |||
| #					The argument is optional, if not given 10% of MAX_SIZE_CP is used | |||
| # | |||
| 
 | |||
| ## Examples (remove leading # to activate): | |||
| 
 | |||
| ## Keep at most 500 GB of recorded files in /media/sda1/movies/sky | |||
| ## The size is calculated recursive incl. the last_chance directory | |||
| ## that is, the oldest 50 GB are in the directory last_chance | |||
| #/media/sda1/movies/sky,500;last_chance,50 | |||
| 
 | |||
| ## Equivalent to the above rule | |||
| #/media/sda1/movies/sky,500 | |||
| 
 | |||
| ## Keep at most 1TB of recorded files in /mnt/autofs/record/sky/ | |||
| #/mnt/autofs/record/sky,1000 | |||
| 
 | |||
| ## Like above but only keep 50 GB (instead of 100).  | |||
| ## Use the directory 'soon_deleted' | |||
| #/mnt/autofs/record/sky/,1000;soon_deleted,50 | |||
| 
 | |||
| ## Like above but the default 100 GB in  | |||
| ## the custom directory 'oldest' | |||
| #/mnt/autofs/record/sky/,1000;oldest | |||
| 
 | |||
| # Don't forget the newline after the last entry. | |||
								
									
										File diff suppressed because it is too large
									
								
							
						
					| @ -1,7 +0,0 @@ | |||
| type=3 | |||
| name=Auto-Timer | |||
| desc=Automatisches Anlegen von Rec/Zap-Timern | |||
| needfb=1 | |||
| needlcd=0 | |||
| needrc=1 | |||
| needoffsets=1 | |||
| @ -1,96 +0,0 @@ | |||
| # activate the following setting to record all new movies from SKY Cinema | |||
| #SKY_CINEMA="HD" | |||
| # or | |||
| #SKY_CINEMA="SD;Weekend,18:00-00:00;/mnt/rec/sky_cinema" | |||
| 
 | |||
| # The maximum time an EPG might "move" to still be considered the same event | |||
| MAX_DIFF_MINS=10 | |||
| 
 | |||
| # How many tuners are available in this box (or how many are you willing to use with the autotimer?) | |||
| # Notes: | |||
| #  * Setting this to more than available might break some recordings if more timers are set in a timespan, than real tuners are available | |||
| #  * If something is to be recorded, but there are already timers blocking this time span, the new timer will not be added. | |||
| #    Hence, make sure, that the more important shows are listed earlier in the rules-file. | |||
| MAX_TUNERS=2 | |||
| 
 | |||
| # How many parallel recordings are allowed. The default ist 8, which is also the maximum the CS supports. | |||
| # In case your box is to slow, or you experience some problems when there are many parallel recordings, try reducing this number. | |||
| # Note: This is different from MAX_TUNERS, since multiple recordings on the same transponder require only a single tuner. | |||
| MAX_RECORDS=8 | |||
| 
 | |||
| # Automatically generate/update the show history file. | |||
| # When this is set to 1, pr-auto-timer will collect all recorded shows from all paths given in MYRECORDPATHS and update the show history file. | |||
| # More precisely, it will search through these paths for *.xml files from recordings and extract from there the information necessary | |||
| # to detect if the same show was already recorded at some other time. Note that already existing entries in $ME.show_history will *not* be removed. | |||
| # Therefore, you can delete some recordings or add manually shows to this file and they will be kept until you delete them manually or you delete the entire file. | |||
| # With a big collection of recordings it might take some time, when pr-auto-timer first generates this (on the first occurrence of a rule with the D-flag) | |||
| # This time can be avoided by setting the following setting to 0 and calling pr-auto-timer with the command line option "--gen_show_history" before running | |||
| # pr-auto-timer without options. Default is 1, i.e. automatically generate this info. | |||
| AUTOGEN_SHOW_HISTORY=1 | |||
| 
 | |||
| # The following setting controls the behavior of pr-auto-timer with respect to records, which went wrong. This only applies if pr-auto-timer automatically | |||
| # generates the show history (i.e. AUTOGEN_SHOW_HISTORY=1). Currently only two types of "broken records" can be handled: | |||
| # - Only the *.xml-file of some event exist and no *.ts file can be found (this could also be used to manually indicate to pr-auto-timer, that you want a event | |||
| #   to be recorded again; to do so, simply delete ONLY the *.ts file, and leave the *.xml file intact. | |||
| # - The *.ts files exists but it's size is under 2k. This is a common situation, when a record goes wrong - a file of ~1k remains there, but contains nothing. | |||
| # Possible options: | |||
| # 0: Feature deactivated - no handling of broken records | |||
| # 1: Detect broken records and remove them from the history index. Hence, they will be recorded again if encountered. [default] | |||
| # 2: Detect and REMOVE broken records. Like 1, but also **DELETE** the broken files (xml and ts) from your disk. (Files will be deleted irreversible.) | |||
| BROKEN_RECORD_HANDLING=1 | |||
| 
 | |||
| # Set the following to activate/deactivate saving information about manually deleted timers | |||
| # 0: feature is activated (saves timer info) and manually deleted timers will not be added again | |||
| # 1: feature is activated (saves timer info), but manually deleted timers will be added again | |||
| # 2: feature is deactivated, i.e. timers will not be stored [default] | |||
| DEL_TIMER_REFRESH=2 | |||
| 
 | |||
| # The maximum number of timers to remember, in order to not set it again after it has been manually deleted | |||
| # This setting is only relevant if the above DEL_TIMER_REFRESH is 0 or 1 | |||
| MAX_TMR2_COUNT=250 | |||
| 
 | |||
| # This setting limits the size of your $ME.show_history file. The feature is activated by setting the value to something else than 0, e.g. 1000 [default]. | |||
| # pr-auto-timer will then try to remove n entries, so that the maximum entries given in MAX_HISTORY_ENTRIES is not violated. Hereby the oldest | |||
| # entries, determined by the timestamp, will be removed. However, only entries, to which no recorded file exists on your disk will be removed. | |||
| # A setting of MAX_HISTORY_ENTRIES=0 deactivates the size check. If there are more physically available files, than entries allowed, then MAX_HISTORY_ENTRIES | |||
| # will be ignored and a warning is issued in the logfile. | |||
| MAX_HISTORY_ENTRIES=1000 | |||
| 
 | |||
| # What should be done, after pr-auto-timer is done? | |||
| #0: Nothing. The box remains in its previous state. [default] | |||
| #1: Put the box in standby. | |||
| #2: Put the box in DeepStandBy | |||
| #3: Power off the box | |||
| #4: Reboot the box | |||
| END_SHUT_DOWN=0 | |||
| 
 | |||
| # During which time, the should the above END-action be done? | |||
| #0: Do the SHUT_DOWN only from 00:00 to 06:00. [default] | |||
| #1: Do the SHUT_DOWN at any time. | |||
| SHUT_DOWN_ALSO_DAY=0 | |||
| 
 | |||
| # Activate the following to execute an arbitrary script/program before starting | |||
| # Default is no action | |||
| #PRE_ACTION="echo 'Pre-action 1';echo 'Pre-action 2'" | |||
| 
 | |||
| # Activate the following to execute an arbitrary script/program after finishing but before exiting. | |||
| # Default is no action | |||
| #POST_ACTION="echo 'Post-action'" | |||
| 
 | |||
| # Change the following to determine where pr-auto-timer searches for recordings on your disk | |||
| # You can provide more than one path and each path will be searched recursively. Use "std::neutrino" to indicate the standard recording | |||
| # directory from neutrino. If this is not set or invalid, the standard neutrino recording directory is used. | |||
| # Separate multiple paths with a ';', i.e. MYRECORDPATHS="path[;path]... " (Note the quotes!) | |||
| MYRECORDPATHS="std::neutrino" | |||
| 
 | |||
| # Activate the following to change the path of the rule files | |||
| #RULE_FILE=/var/tuxbox/config/$ME.rules | |||
| #RULE_FILE_EXT=/var/tuxbox/config/$ME.rulex | |||
| 
 | |||
| # Activate the following to change the default place for the show history | |||
| #HISTORY_FILE=/var/tuxbox/config/$ME.show_history | |||
| 
 | |||
| # Deactivate the logfile (default is ON) | |||
| #LOG_FILE=off | |||
| # Activate the following to change the default location of the log-file | |||
| #LOG_FILE=/tmp/${ME}_$(date +'%F').log | |||
| @ -1,117 +0,0 @@ | |||
| # pr-auto-timer.rules | |||
| # | |||
| # ---------------------------------------------------------------------------- | |||
| # | |||
| # Syntax: CHANNELNAME;DAYOFWEEK[,TIMESPAN];REGEX[,MODIFIER][;FLAGS][;RECDIR] | |||
| # | |||
| # CHANNELNAME	The (exact) channelname e.g. "Das Erste HD" or | |||
| #				a bouquet-nr prefixed with an asterisk e.g. "*1" | |||
| # | |||
| # DAYOFWEEK		The day of week or an asterisk for all days of week e.g. | |||
| #				"Weekday" or "Mon", "Tue", "Wed", "Thu", "Fri" | |||
| #				"Weekend" or "Sat", "Sun" | |||
| #				"*" | |||
| # | |||
| # TIMESPAN		Defines a period in which the timer must start e.g. | |||
| #				"18:45-20:15" | |||
| #				"*" an asterisk for all times | |||
| #				TIMESPAN is optional; default is "*" | |||
| # | |||
| # REGEX			The name of the show as a regular expression e.g. | |||
| #				"Tatort" | |||
| #				"*" find all shows; this is only usefull in conjunction with MODIFIER | |||
| #				NOTE: This regular expression is matched only against the epg title | |||
| # | |||
| # MODIFIER		The modifier can be used to further refine the selection of the show | |||
| #				by searching the entire description for specified words. | |||
| #				Format is as follows: [+~!-]RegEx1 RegEx2 ... | |||
| #				+RegEx1 RegEx2 ...: INCLUDE ALL - All of these regular expressions must match for selecting the show | |||
| #				~RegEx1 RegEx2 ...: INCLUDE ONE - One of these regular expressions must match for selecting the show | |||
| #				!RegEx1 RegEx2 ...: EXCLUDE ALL - All of these regular expressions must match for excluding the show | |||
| #				-RegEx1 RegEx2 ...: EXCLUDE ONE - One of these regular expressions must match for excluding the show | |||
| #				MODIFIER is optional; default is no modifier. | |||
| #				NOTE: When no modifier is given, this regular expression is matched only against the epg title | |||
| # | |||
| # FLAGS			A coma-separated list of the following flags: | |||
| #				- "R": create a record timer [default] | |||
| #				- "Z": create a zap timer | |||
| #				- "I": ignore time additions to timer | |||
| #				- "F": during one run of pr-auto-timer only the first match will be added as a timer | |||
| #				- "O": the same as "F" but additionally deactivates the corresponding rule in the rules-file | |||
| #				- "D": prevent adding duplicate timers for the same show (at different times) | |||
| #				- "W": Always re-add manually removed timers if the show is found again; overrides the global option DEL_TIMER_REFRESH=0 | |||
| #				- "M": Allow empty info-fields when using duplicate detection | |||
| #				FLAGS is optional; default is a record timer. | |||
| # | |||
| # RECDIR		An alternative recording directory | |||
| #				NOTE: flag-section can be empty, but MUST be defined! See examples below. | |||
| #				RECDIR is optional; default is the neutrino setting | |||
| # | |||
| # ---------------------------------------------------------------------------- | |||
| # | |||
| ## Examples (remove leading # to activate): | |||
| # | |||
| ## Record all shows containing the word 'Tatort' | |||
| ## on channel 'Das Erste HD' on sundays: | |||
| #Das Erste HD;Sun;Tatort | |||
| 
 | |||
| ## Record all shows containing the word 'Tagesschau' | |||
| ## on channel 'Das Erste HD' on all days in a timespan between 11:55 and 12:05: | |||
| #Das Erste HD;*,11:55-12:05;Tagesschau | |||
| 
 | |||
| ## Record all shows containing the word 'Knollenblätterpilz' | |||
| ## on channel 'Das Erste HD': | |||
| #Das Erste HD;*;Knollenblätterpilz | |||
| 
 | |||
| ## Record all shows containing the sentence 'Rumpsteak schmeckt lecker' | |||
| ## on all channels of bouquet 1: | |||
| #*1;*;Rumpsteak schmeckt lecker | |||
| 
 | |||
| ## Zap to all shows containing the word 'Affenhaus' | |||
| ## on channel 'Das Erste HD': | |||
| #Das Erste HD;*;Affenhaus;Z | |||
| 
 | |||
| ## Record first show found containing the word 'Tatort' | |||
| ## on channel 'Das Erste HD' on sundays: | |||
| #Das Erste HD;Sun;Tatort;F | |||
| 
 | |||
| ## Record first show found containing the word 'Tatort' | |||
| ## on channel 'Das Erste HD' on sundays. | |||
| ## After creating timer the rule-line will be deactivated: | |||
| #Das Erste HD;Sun;Tatort;O | |||
| 
 | |||
| ## Record all shows containing the word 'Tatort' | |||
| ## on channel 'Das Erste HD' on weekends. | |||
| ## Using '/media/records/tatort' as recording directory | |||
| #Das Erste HD;Weekend;Tatort;R;/media/records/tatort | |||
| ## or with empty FLAGS section | |||
| #Das Erste HD;Weekend;Tatort;;/media/records/tatort | |||
| 
 | |||
| ## You don't need the special episodes of LOST, | |||
| ## if you plan to view this great series in one run. ;) | |||
| #FOX HD;*;LOST,!Special | |||
| 
 | |||
| ## Records all Episodes of Traumschiff but not these ones: | |||
| ## Oman Bali Malaysia Vegas Savannah Panama Singapur Bintan Perth Spezial | |||
| #ZDF;*,00:00-18:15;Traumschiff,-Oman Bali Malaysia Vegas Savannah Panama Singapur Bintan Perth Spezial | |||
| 
 | |||
| ## Records only Episodes of Traumschiff:  | |||
| ## Oman Bali Malaysia Vegas Savannah Panama Singapur Bintan Perth Spezial | |||
| #ZDF;*,00:00-18:15;Traumschiff,~Oman Bali Malaysia Vegas Savannah Panama Singapur Bintan Perth Spezial | |||
| 
 | |||
| ## Record only Episode "Mord mit der linken Hand" from Columbo once on any channel | |||
| #*;*;Columbo,+Mord mit der linken Hand;O | |||
| 
 | |||
| ## Record all episodes of "Unser Kosmos: Die Reise geht weiter" from NatGeo HD | |||
| ## Avoid recording repetitions of the same episode. | |||
| #NatGeo HD;*;Unser Kosmos;D | |||
| 
 | |||
| ## Record all episodes from "The Big Bang Theory" for Season 7 | |||
| ## The regular expression excludes all episodes with the string "x. Staffel", where x=1..6. | |||
| #TNT Serie HD;*;The Big Bang Theory,![123456]\\.[[:blank:]]Staffel;D | |||
| 
 | |||
| ## Record all episodes from The Walking Dead's season 5 | |||
| ## The regular expression includes only episodes where the string "5. Staffel" was found in the description | |||
| #Fox HD;*;Walking Dead,+5\\.[[:blank:]]Staffel;D | |||
| 
 | |||
| # Don't forget the newline after the last entry. | |||
| @ -1,2 +0,0 @@ | |||
| #!/bin/sh | |||
| /lib/tuxbox/plugins/pr-auto-timer --menu | |||
| Before Width: | Height: | Size: 628 B | 
| @ -1,26 +0,0 @@ | |||
| #!/bin/sh | |||
| 
 | |||
| CP=/bin/cp | |||
| WGET=/bin/wget | |||
| RM=/bin/rm | |||
| 
 | |||
| if [ ! -e /var/tuxbox/config/pr-auto-timer.conf ]; then | |||
| 	$CP /var/tuxbox/config/pr-auto-timer.conf.template /var/tuxbox/config/pr-auto-timer.conf | |||
| fi | |||
| 
 | |||
| if [ ! -e /var/tuxbox/config/pr-auto-timer.rules ]; then | |||
| 	$CP /var/tuxbox/config/pr-auto-timer.rules.template /var/tuxbox/config/pr-auto-timer.rules | |||
| fi | |||
| 
 | |||
| if [ ! -e /var/tuxbox/config/auto-record-cleaner.conf ]; then | |||
| 	$CP /var/tuxbox/config/auto-record-cleaner.conf.template /var/tuxbox/config/auto-record-cleaner.conf | |||
| fi | |||
| 
 | |||
| if [ ! -e /var/tuxbox/config/auto-record-cleaner.rules ]; then | |||
| 	$CP /var/tuxbox/config/auto-record-cleaner.rules.template /var/tuxbox/config/auto-record-cleaner.rules | |||
| fi | |||
| 
 | |||
| $WGET -q -O - "http://localhost/control/message?popup=Auto-Timer%20installiert." | |||
| $WGET -q -O - "http://localhost/control/reloadplugins" | |||
| 
 | |||
| $RM -f /tmp/pr-auto-timer_*.bin | |||
| @ -1 +0,0 @@ | |||
| #!/bin/sh | |||
					Loading…
					
					
				
		Reference in new issue