File: fh-update

package info (click to toggle)
flashybrid 0.002
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 120 kB
  • ctags: 5
  • sloc: sh: 194; makefile: 44
file content (44 lines) | stat: -rwxr-xr-x 1,302 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/bin/sh
# flashybrid flash update program
# This script can assume a full debian system is available.

CONFDIR=/etc/flashybrid

set -e

. $CONFDIR/config

if [ -e $CONFDIR/partial ]; then
	for item in $(grep -v '^#' $CONFDIR/partial); do
		if [ -z "$DISKMOUNT" ]; then
			echo "error: DISKMOUNT is not set in /etc/flashybrid/config, cannot use partial directories" >&2 
			exit 1
		fi
	
		# Glob wildcards relative to the disk so they expand.
		for file in $(ls -1 $DISKMOUNT/$item | sed "s:^$DISKMOUNT::"); do
			DESTDIR=$FLASHMOUNT/$(dirname $file).partial
			if [ -e $DISKMOUNT/$file ]; then
				echo "Updating $file"
				mkdir -p $DESTDIR
				mkdir -p $FLASHMOUNT/$(dirname $file)
				rsync -a $DISKMOUNT/$file $DESTDIR/
			else
				echo "Skipping missing $file"
			fi
			# Mark the partial dir as such.
			touch $DESTDIR/.partial
		done
	done

	# Now sweep through the partial directories and clean up any
	# obsolete files.
	for dir in $(grep -v '^#' $CONFDIR/partial | sed 's:/.[^/]*$::' | sort | uniq); do
		for file in $(find $FLASHMOUNT/$dir.partial -mindepth 1 -maxdepth 1 -printf "%f\n"); do
			if [ "$file" != ".partial" -a ! -e $DISKMOUNT/$dir/$file ]; then
				echo "Deleting obsolete $file from $FLASHMOUNT/$dir.partial"
				rm -f $FLASHMOUNT/$dir.partial/$file
			fi
		done
	done
fi