Bug fix: Change all .desktop files to RDNS style
[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/layout-util.cc
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 == "\"<\057ui>\";")
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                         }
72                 }
73         }
74 }
75
76 /Valid sections/ {template_flag = 1; print; get_menus()}
77 /For other keys/ {template_flag = 0; print ""}
78 (template_flag == 0) {print}
79 '  "$templatepath" > "$tmp_file"
80
81 cat "$tmp_file"
82 printf '%s\n' "$PWD"
83
84 if diff --unified=0 "./plugins/org.geeqie.template.desktop.in" "$tmp_file" | zenity --title="Plugin template update" --text-info --width=700 --height=400
85 then
86         mv "$tmp_file" "$templatepath"
87 else
88         rm "$tmp_file"
89 fi