Send stacktrace data also to a /tmp file
[geeqie.git] / scripts / template-desktop.sh
1 #!/bin/sh
2
3
4 ## @file
5 ## @brief Insert updated menu "Valid sections" list into the desktop template file.
6 ##
7 ## This needs to be run only when the menus have changed.
8 ##
9
10 tmp_file=$(mktemp "${TMPDIR:-/tmp}/geeqie.XXXXXXXXXX")
11 path=$(dirname "$(realpath "$0")")
12 srcpath=$(dirname "$path")/src/ui/menu-classic.ui
13 templatepath=$(dirname "$path")/plugins/org.geeqie.template.desktop.in
14
15 awk -v src_path="$srcpath" 'BEGIN {
16 menu_flag = 0
17 template_flag = 0
18 i = 0
19 }
20
21 function get_menus()
22 {
23         {while ((getline line < src_path) > 0 )
24                 {
25                 if (line == "<ui>")
26                         {
27                         menu_flag = 1
28                         }
29                 if (line == "<\047ui>")
30                         {
31                         menu_flag = 0
32                         }
33                 if (menu_flag >= 1)
34                         {
35                         gsub(/\047|"|\/|<|>/, "", line)
36                         split(line, lineArr, "=")
37
38                         if (index(lineArr[1], "menu action") > 0)
39                                 {
40                                 i = i + 1
41                                 menu[i] = lineArr[2]
42                                 if ( i == 3)
43                                         {
44                                         print "#    " menu[1] "/" menu[2] "/"  lineArr[2]
45                                         }
46                                 if ( i == 2)
47                                         {
48                                         print "#    " menu[1] "/"  lineArr[2]
49                                         }
50                                 if (i == 1)
51                                         {
52                                         print "#    " lineArr[2]
53                                         }
54                                 }
55                         if (index(lineArr[1], "placeholder name"))
56                                 {
57                                 if ( i == 2)
58                                         {
59                                         print "#    " menu[1] "/" menu[2] "/" lineArr[2]
60                                         }
61                                 else
62                                         {
63                                         print "#    "   menu[1] "/" lineArr[2]
64                                         }
65                                 }
66                         gsub(" ", "", line)
67                         if (line == "menu")
68                                 {
69                                 i = i - 1
70                                 }
71                         if (lineArr[2] == "PluginsMenu")
72                                 {
73                                 i = i - 1
74                                 }
75                         }
76                 }
77         }
78 }
79
80 /Valid sections/ {template_flag = 1; print; get_menus()}
81 /For other keys/ {template_flag = 0; print ""}
82 (template_flag == 0) {print}
83 '  "$templatepath" > "$tmp_file"
84
85 cat "$tmp_file"
86 printf '%s\n' "$PWD"
87
88 if diff --unified=0 "./plugins/org.geeqie.template.desktop.in" "$tmp_file" | zenity --title="Plugin template update" --text-info --width=700 --height=400
89 then
90         mv "$tmp_file" "$templatepath"
91 else
92         rm "$tmp_file"
93 fi