source: src-sh/pbi-manager10/module-examples/convertoldmod.sh @ 651bd28

9.2-releasereleng/10.0releng/10.0.1releng/10.0.2releng/10.0.3releng/10.1
Last change on this file since 651bd28 was 651bd28, checked in by Kris Moore <kris@…>, 16 months ago

Add a new pbi-manager10 copy, this will be used for FreeBSD > 10

  • Property mode set to 100644
File size: 9.4 KB
Line 
1#!/bin/sh
2# Helper script to convert old PBI module format to new 9.x format
3
4fix_scripts() {
5        osct="${1}"
6        nsct="${2}"
7        echo "#!/bin/sh" >${nsct}
8        cat "${osct}" | sed 's|/Programs/${PROGDIR}|${PBI_PROGDIRPATH}|g' \
9        | sed 's|/Programs/$PROGDIR|${PBI_PROGDIRPATH}|g' \
10        | sed 's|${PROGDIR}|${PBI_PROGDIRPATH}|g' \
11        | sed 's|$PROGDIR|${PBI_PROGDIRPATH}|g' \
12        | sed 's|${PBIDIR}|${PBI_PROGDIRPATH}|g' \
13        | sed 's|$PBIDIR|${PBI_PROGDIRPATH}|g' \
14        | sed 's|/Programs/rc.d|${PBI_RCDIR}|g' \
15        | sed 's|/Programs/etc|${SYS_LOCALBASE}/etc|g' \
16        | sed 's|\.sbin|${PBI_FAKEBINDIR}|g' \
17        | grep -v "^#" \
18        | grep -v "LAUNCHCLOSE" \
19        | grep -v "/Programs/bin" \
20        | grep -v "/PCBSD/Services/" \
21        | grep -v "kdialog" \
22         >>"${nsct}"
23        _ce=`cat "${nsct}" | grep -v "^#" | sed '/^$/d'`
24        if [ -z "$_ce" ] ; then rm "${nsct}" ; fi
25}
26
27odir="${1}"
28if [ ! -z "$2" ]; then
29        ndir="${2}"
30else
31        ndir="${1}.new"
32fi
33if [ ! -e "${odir}/pbi.conf" ] ; then
34        echo "Invalid module dir!"
35        exit 1
36fi
37
38if [ -d "${ndir}" ] ; then rm -rf "${ndir}" ; fi
39mkdir -p "${ndir}"
40mkdir "${ndir}/scripts"
41mkdir "${ndir}/xdg-desktop"
42mkdir "${ndir}/xdg-menu"
43mkdir "${ndir}/xdg-mime"
44
45# Start by moving obvious files over
46if [ -d "${odir}/overlay-dir" ] ; then
47  mkdir "${ndir}/resources"
48  tar cvf - --exclude .svn -C ${odir}/overlay-dir . 2>/dev/null | tar xvf - -C ${ndir}/resources 2>/dev/null
49fi
50
51if [ -e "${ndir}/resources/LICENSE" ] ; then
52  mv ${ndir}/resources/LICENSE ${ndir}/resources/
53fi
54if [ -e "${ndir}/resources/PBI.SetupScript.sh" ] ; then
55  fix_scripts "${ndir}/resources/PBI.SetupScript.sh" "${ndir}/scripts/post-install.sh"
56  rm "${ndir}/resources/PBI.SetupScript.sh"
57fi
58if [ -e "${ndir}/resources/PBI.RemoveScript.sh" ] ; then
59  fix_scripts "${ndir}/resources/PBI.RemoveScript.sh" "${ndir}/scripts/pre-remove.sh"
60  rm "${ndir}/resources/PBI.RemoveScript.sh"
61fi
62if [ -e "${ndir}/resources/PBI.FirstRun.sh" ] ; then
63  fix_scripts "${ndir}/resources/PBI.FirstRun.sh" "${ndir}/scripts/pre-install.sh"
64  rm "${ndir}/resources/PBI.FirstRun.sh"
65fi
66if [ -e "${odir}/build.sh" ] ; then
67  fix_scripts "${odir}/build.sh" "${ndir}/scripts/post-portmake.sh"
68fi
69if [ -e "${odir}/preportmake.sh" ] ; then
70  fix_scripts "${odir}/preportmake.sh" "${ndir}/scripts/pre-portmake.sh"
71fi
72if [ -e "${ndir}/resources/header.png" ] ; then
73  mv ${ndir}/resources/header.png ${ndir}/resources/gui_banner.png
74fi
75if [ -e "${ndir}/resources/leftside.png" ] ; then
76  mv ${ndir}/resources/leftside.png ${ndir}/resources/gui_sidebanner.png
77fi
78if [ -e "${ndir}/resources/PBI.UpdateURL.sh" ] ; then
79  rm ${ndir}/resources/PBI.UpdateURL.sh
80fi
81if [ -d "${ndir}/resources/autolibs" ] ; then
82  rm -rf ${ndir}/resources/autolibs
83fi
84if [ -d "${ndir}/resources/lib" ] ; then
85  rm -rf ${ndir}/resources/lib
86fi
87
88# Delete empty dirs
89find ${ndir}/resources -depth -empty -type d -exec rmdir {} \;
90
91
92# Update the pbi.conf file
93. ${odir}/pbi.conf
94
95echo "#!/bin/sh
96# PBI Build Configuration
97# Place over-rides and settings here
98#
99# XDG Desktop Menu Spec:
100# http://standards.freedesktop.org/menu-spec/menu-spec-1.0.html
101##############################################################################
102" >${ndir}/pbi.conf
103
104expts=""
105if [ ! -z "${PROGNAME}" ] ; then
106  echo "# Program Name
107PBI_PROGNAME=\"${PROGNAME}\"" >>${ndir}/pbi.conf
108  echo " " >>${ndir}/pbi.conf
109  expts="PBI_PROGNAME" 
110fi
111if [ ! -z "${PROGWEB}" ] ; then
112  echo "# Program Website
113PBI_PROGWEB=\"${PROGWEB}\"" >>${ndir}/pbi.conf
114  echo " " >>${ndir}/pbi.conf
115  expts="${expts} PBI_PROGWEB" 
116fi
117if [ ! -z "${PROGAUTHOR}" ] ; then
118  echo "# Program Author / Vendor
119PBI_PROGAUTHOR=\"${PROGAUTHOR}\"" >>${ndir}/pbi.conf
120  echo " " >>${ndir}/pbi.conf
121  expts="${expts} PBI_PROGAUTHOR" 
122fi
123if [ ! -z "${PROGICON}" ] ; then
124  echo "# Default Icon (Relative to %%PBI_APPDIR%% or resources/)
125PBI_PROGICON=\"${PROGICON}\"" >>${ndir}/pbi.conf
126  echo " " >>${ndir}/pbi.conf
127  expts="${expts} PBI_PROGICON" 
128fi
129if [ ! -z "${PBIPORT}" ] ; then
130  # Fixed PBIPORT
131  fPort=`echo $PBIPORT | sed 's|/usr/ports/||g'`
132  echo "# The target port we are building
133PBI_MAKEPORT=\"${fPort}\"" >>${ndir}/pbi.conf
134  echo " " >>${ndir}/pbi.conf
135  expts="${expts} PBI_MAKEPORT" 
136fi
137if [ ! -z "${MAKEOPTS}" ] ; then
138  echo "# Additional options for make.conf
139PBI_MAKEOPTS=\"${MAKEOPTS}\"" >>${ndir}/pbi.conf
140  echo " " >>${ndir}/pbi.conf
141  expts="${expts} PBI_MAKEOPTS" 
142fi
143if [ ! -z "${OTHERPORT}" ] ; then
144  OP="`echo ${OTHERPORT} | sed 's|/usr/ports/||g'`"
145  echo "# Ports to build before / after
146PBI_MKPORTBEFORE=\"\"
147PBI_MKPORTAFTER=\"${OP}\"" >>${ndir}/pbi.conf
148  echo " " >>${ndir}/pbi.conf
149  expts="${expts} PBI_MKPORTBEFORE PBI_MKPORTAFTER" 
150fi
151
152echo '# Files to be Sym-Linked into the default LOCALBASE
153# One per-line, relative to %%PBI_APPDIR%% and LOCALBASE
154# Defaults to keeping any existing files in LOCALBASE
155# Use action 'binary' for binaries that need wrapper functionality
156
157# TARGET                LINK IN LOCALBASE       ACTION
158#etc/rc.d/servfoo       etc/rc.d/servfoo        keep
159#include/libfoo.h       include/libfoo.h        replace
160#bin/appfoo             bin/appfoo              binary,nocrash
161#bin/appfoo2            bin/appfoo-test         binary
162' > ${ndir}/external-links
163
164# Now check kmenu-dir for desktop entries
165if [ -d "${odir}/kmenu-dir" ] ; then
166        for i in `ls -A ${odir}/kmenu-dir`
167        do
168                if [ "$i" = ".svn" ] ; then continue ; fi
169                i="${odir}/kmenu-dir/${i}"
170                app="" ; icon="" ; desc=""; nodesk=""; nomenu=""; nocrash=""; runroot=""
171                runshell=""; notify=""; link=""; weblink=""; cat=""; nc=""
172
173                app="`cat ${i} | grep 'ExePath: ' | sed 's|ExePath: ||g'`"
174                icon="`cat ${i} | grep 'ExeIcon: ' | sed 's|ExeIcon: ||g'`"
175                desc="`cat ${i} | grep 'ExeDescr: ' | sed 's|ExeDescr: ||g'`"
176                nodesk="`cat ${i} | grep 'ExeNoDesktop: ' | sed 's|ExeNoDesktop: ||g'`"
177                nomenu="`cat ${i} | grep 'ExeNoMenu: ' | sed 's|ExeNoMenu: ||g'`"
178                nocrash="`cat ${i} | grep 'ExeNoCrashHandler: ' | sed 's|ExeNoCrashHandler: ||g'`"
179                runroot="`cat ${i} | grep 'ExeRunRoot: ' | sed 's|ExeRunRoot: ||g'`"
180                runshell="`cat ${i} | grep 'ExeRunShell: ' | sed 's|ExeRunShell: ||g'`"
181                notify="`cat ${i} | grep 'ExeNotify: ' | sed 's|ExeNotify: ||g'`"
182                link="`cat ${i} | grep 'ExeLink: ' | sed 's|ExeLink: ||g'`"
183                weblink="`cat ${i} | grep 'ExeWebLink: ' | sed 's|ExeWebLink: ||g'`"
184                cat="`cat ${i} | grep 'ExeKdeCat: ' | sed 's|ExeKdeCat: ||g'`"
185                bname=`basename $app`
186
187                if [ -z "$saved" ] ; then
188                        saved="$bname"
189                else
190                        saved="$saved $bname"
191                fi
192
193                if [ "$link" = "1" -o "$weblink" = "1" ] ; then continue ; fi
194
195                if [ "$notify" = "1" ] ; then
196                        ntf="true"
197                else
198                        ntf="false"
199                fi
200                if [ "$runroot" = "1" ] ; then
201                        rr="X-KDE-SubstituteUID=true
202X-KDE-Username=root"
203                else
204                        rr=""
205                fi
206                if [ "$runshell" = "1" ] ; then
207                        tt="Terminal=true
208TerminalOptions="
209                else
210                        tt=""
211                fi
212
213                # Convert to correct CAT
214                if [ "$ncat" = "Internet" ] ; then
215                        ncat="Network"
216                fi
217                if [ "$ncat" = "Utilities" ] ; then
218                        ncat="Utility"
219                fi
220                ncat="`echo $cat | sed 's|/|;|g'`;"     
221
222                # Create the menu .desktop file now
223                if [ "$nomenu" = "1" ] ; then
224                        ndis="NoDisplay=true"
225                else
226                        ndis=""
227                fi
228
229                echo -e "#!/usr/bin/env xdg-open
230[Desktop Entry]
231Value=1.0
232Type=Application
233Name=${desc}
234GenericName=${desc}
235Exec=%%PBI_EXEDIR%%/${bname}
236Path=%%PBI_APPDIR%%
237Icon=%%PBI_APPDIR%%/${icon}
238StartupNotify=${ntf}
239$ndis
240$rr
241$tt
242Categories=$ncat" > ${ndir}/xdg-menu/${bname}.desktop
243                sed '/^$/d' ${ndir}/xdg-menu/${bname}.desktop > ${ndir}/xdg-menu/${bname}.desktop.new
244                mv ${ndir}/xdg-menu/${bname}.desktop.new ${ndir}/xdg-menu/${bname}.desktop
245
246                # Create the desktop .desktop file now
247                if [ "$nodesk" != "1" ] ; then
248                bname=`basename $app`
249                echo -e "#!/usr/bin/env xdg-open
250[Desktop Entry]
251Value=1.0
252Type=Application
253Name=${desc}
254GenericName=${desc}
255Exec=%%PBI_EXEDIR%%/${bname}
256Path=%%PBI_APPDIR%%
257Icon=%%PBI_APPDIR%%/${icon}
258StartupNotify=${ntf}
259$rr
260$tt" > ${ndir}/xdg-desktop/${bname}.desktop
261                sed '/^$/d' ${ndir}/xdg-desktop/${bname}.desktop > ${ndir}/xdg-desktop/${bname}.desktop.new
262                mv ${ndir}/xdg-desktop/${bname}.desktop.new ${ndir}/xdg-desktop/${bname}.desktop
263                fi # End of desktop check
264               
265        done
266fi
267
268# Now setup mime types
269if [ -d "${odir}/mime-dir" ] ; then
270        for i in `ls -A ${odir}/mime-dir`
271        do
272                if [ "$i" = ".svn" ] ; then continue ; fi
273                i="${odir}/mime-dir/${i}"
274                ext="" ; icon="" ; prog=""
275
276                ext="`cat ${i} | grep 'MimeExt: ' | sed 's|MimeExt: ||g' | sed 's|;||g'`"
277                icon="`cat ${i} | grep 'MimeIcon: ' | sed 's|MimeIcon: ||g'`"
278                prog="`cat ${i} | grep 'MimeProg: ' | sed 's|MimeProg: ||g' | sed 's| ||g'`"
279
280                # Get the bname of the program this mime-type is associated with
281                count=0
282                bname=""
283                for j in $saved
284                do
285                        if [ "$count" = "$prog" ] ; then bname="$j" ; break ; fi
286                        count="`expr $count + 1`"
287                done
288                if [ -z "$bname" ] ; then echo "Missing mime bname!: $prog - $ext" ; continue ; fi
289
290                comment="`cat ${ndir}/xdg-menu/${bname}.desktop | grep "GenericName" | cut -d '=' -f 2-10`"
291
292                # Add the mime entry to the original .desktop file
293                echo "MimeType=application/x-${bname}" >> ${ndir}/xdg-menu/${bname}.desktop
294                echo "<?xml version=\"1.0\"?>
295<mime-info xmlns='http://www.freedesktop.org/standards/shared-mime-info'>
296  <mime-type type=\"application/x-${bname}\">
297    <comment>${comment} File</comment>" >${ndir}/xdg-mime/${bname}-xdg.xml
298                for j in $ext
299                do     
300                        echo "    <glob weight=\"100\" pattern=\"${j}\"/>" >> ${ndir}/xdg-mime/${bname}-xdg.xml
301                done
302echo " </mime-type>
303</mime-info>" >>${ndir}/xdg-mime/${bname}-xdg.xml
304
305                # See if we have icon as well
306                if [ -e "${ndir}/resources/${icon}" ] ; then
307                        cp "${ndir}/resources/${icon}" "${ndir}/xdg-mime/${bname}-xdg.png"
308                fi
309
310
311        done
312
313fi
314
315echo "export $expts" >> ${ndir}/pbi.conf
Note: See TracBrowser for help on using the repository browser.