File: keyword_merge.sh

package info (click to toggle)
geeqie 1%3A2.6.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 16,992 kB
  • sloc: cpp: 95,956; xml: 11,502; sh: 3,654; awk: 124; perl: 88; python: 80; makefile: 24
file content (85 lines) | stat: -rwxr-xr-x 2,196 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/bin/sh

## @file
## @brief Merge the keyword tree of one Geeqie configuration file into another.  
##
## The keyword trees are simply concatenated. When Geeqie loads
## the resulting configuration file, any duplicates are discarded.
##
## There is no error checking.
##

merge_file()
{
flag=0
while read -r line_merge
do
	if [ "$flag" -eq 0 ]
	then
		if [ "$line_merge" != "${line_merge%<keyword_tree>*}" ]
		then
			flag=1
		fi
	else
		if [ "$line_merge" != "${line_merge%<keyword_tree>*}" ]
		then
			flag=0
		else
			printf '%s\n' "$line_merge" >> "$2"
		fi
	fi
done < "$1"
}

np=$#

zenity --info --text="This script will merge the keywords from one Geeqie\nconfiguration file into another.\n\n\The command format is:\nkeyword_merge.sh {config. file to merge into} {config. file to merge from}\n\nIf you do not supply parameters, you are prompted.\n\nYou are given the option to backup the main config. file before it is overwritten with the merged data.\n\nEnsure that Geeqie is not running." --title="Geeqie merge keywords"
if [ $? -eq 1 ]
then
	exit
fi


if [ "$np" -ge 3 ]
then
	zenity --error --text "Too many parameters"
	exit
elif [ "$np" -eq 0 ]
then
	config_main=$(zenity --file-selection --file-filter="geeqierc.xml" --file-filter="*.xml" --file-filter="*" --title="Select main configuration file")
	if [ $? -eq 1 ]
	then
		exit
	fi
	config_merge=$(zenity --file-selection --file-filter="geeqierc.xml" --file-filter="*.xml" --file-filter="*"-- title="Select configuration file to merge from")
	if [ $? -eq 1 ]
	then
		exit
	fi
elif [ "$np" -eq 1 ]
then
	config_merge=$(zenity --file-selection --file-filter="geeqierc.xml" --file-filter="*.xml" --file-filter="*" --title="Select configuration file to merge from")
	if [ $? -eq 1 ]
	then
		exit
	fi
fi

tmp_file=$(mktemp "${TMPDIR:-/tmp}/geeqie.XXXXXXXXXX")

while read -r line_main
do
	if [ "$line_main" != "${line_merge%<keyword_tree>*}" ]
	then
		merge_file "$config_merge" "$tmp_file"
	fi
	printf '%s\n' "$line_main" >> "$tmp_file"
done < "$config_main"


if zenity --question --text="Backup configuration file before overwriting?"
then
	cp "$config_main" "$config_main.$(date +%Y%m%d%H%M%S)"
fi

mv "$tmp_file" "$config_main"