# $FreeBSD: branches/pkg_install/Keywords/pkg_install.awk 364121 2014-08-05 16:58:58Z antoine $ # # MAINTAINER: portmgr@FreeBSD.org # # @sample somefile.conf.sample # -> # @comment begin @sample somefile.conf.sample # @unexec if cmp -s %D/etc/somefile.conf %D/etc/somefile.conf.sample; then rm -f %D/etc/somefile.conf; fi # etc/somefile.conf.sample # @exec if [ ! -f %D/etc/somefile.conf ]; then cp %D/etc/somefile.conf.sample %D/etc/somefile.conf; fi # @comment end @sample somefile.conf.sample # # @shell bin/shell # -> # @comment begin @shell bin/shell # @exec cp /etc/shells /etc/shells.bak; (grep -v %D/%F /etc/shells.bak; echo %D/%F) >/etc/shells; rm -f /etc/shells.bak # @unexec cp /etc/shells /etc/shells.bak; (grep -v %D/%F /etc/shells.bak) >/etc/shells; rm -f /etc/shells.bak # @comment end @shell bin/shell function join(array, start, end, sep, result, i) { if (sep == "") sep = " " else if (sep == SUBSEP) # magic value sep = "" result = array[start] for (i = start + 1; i <= end; i++) result = result sep array[i] return result } $1 ~ /@dir\(.*,.*,[1234567890]*\)/ { target_perms=substr($1, 6, length($1) - 6) cmd_len=length($1) + 1 directory=substr($0, cmd_len + 1, length($0) - cmd_len) split(target_perms, ugp, ",") print "@comment begin " $0 print "@comment target_perms=" target_perms " |" $1 "|" if ($2 ~ /^\//) { print "@unexec rmdir \"" directory "\" 2>/dev/null || true" print "@exec mkdir -p \"" directory "\" 2>/dev/null || true" if (ugp[1] != "") { print "@exec chown " ugp[1] " \"" directory "\"" } if (ugp[2] != "") { print "@exec chgrp " ugp[2] " \"" directory "\"" } if (ugp[3] != "") { print "@exec chmod " ugp[3] " \"" directory "\"" } } else if ("/$2" ~ /^%D/) { print "@unexec rmdir \"/" directory "\" 2>/dev/null || true" print "@exec mkdir -p \"/" directory "\" 2>/dev/null || true" if (ugp[1] != "") { print "@exec chown " ugp[1] " \"/" directory "\"" } if (ugp[2] != "") { print "@exec chgrp " ugp[2] " \"/" directory "\"" } if (ugp[3] != "") { print "@exec chmod " ugp[3] " \"/" directory "\"" } } else { print "@unexec rmdir \"%D/" directory "\" 2>/dev/null || true" print "@exec mkdir -p \"%D/" directory "\" 2>/dev/null || true" if (ugp[1] != "") { print "@exec chown " ugp[1] " \"%D/" directory "\"" } if (ugp[2] != "") { print "@exec chgrp " ugp[2] " \"%D/" directory "\"" } if (ugp[3] != "") { print "@exec chmod " ugp[3] " \"%D/" directory "\"" } } print "@comment end " $0 next } $1 ~ /@\(.*,.*,[1234567890]*\)/ { target_perms=substr($1, 3, length($1) - 3) cmd_len=length($1) + 1 target_file=substr($0, cmd_len + 1, length($0) - cmd_len) split(target_perms, ugp, ",") print "@comment begin " $0 print "@comment target_perms=" target_perms " |" $1 "|" if ($2 ~ /^\//) { print target_file if (ugp[1] != "") { print "@exec chown " ugp[1] " \"" target_file "\"" } if (ugp[2] != "") { print "@exec chgrp " ugp[2] " \"" target_file "\"" } if (ugp[3] != "") { print "@exec chmod " ugp[3] " \"" target_file "\"" } } else if ("/$2" ~ /^%D/) { print "/" target_file if (ugp[1] != "") { print "@exec chown " ugp[1] " \"/" target_file "\"" } if (ugp[2] != "") { print "@exec chgrp " ugp[2] " \"/" target_file "\"" } if (ugp[3] != "") { print "@exec chmod " ugp[3] " \"/" target_file "\"" } } else { print target_file if (ugp[1] != "") { print "@exec chown " ugp[1] " \"%D/" target_file "\"" } if (ugp[2] != "") { print "@exec chgrp " ugp[2] " \"%D/" target_file "\"" } if (ugp[3] != "") { print "@exec chmod " ugp[3] " \"%D/" target_file "\"" } } print "@comment end " $0 next } $1 == "@desktop-file-utils" { print "@comment begin " $0 print "@unexec update-desktop-database -q" print "@exec update-desktop-database -q" print "@comment end " $0 next } $1 == "@glib-schemas" { print "@comment begin " $0 print "@unexec %D/bin/glib-compile-schemas %D/share/glib-2.0/schemas > /dev/null || true" print "@exec %D/bin/glib-compile-schemas %D/share/glib-2.0/schemas > /dev/null || true" print "@comment end " $0 next } $1 == "@shared-mime-info" { directory_path=$2 print "@comment begin " $0 if ($2 ~ /^\//) { print "@unexec update-mime-database " directory_path print "@exec update-mime-database " directory_path } else { print "@unexec update-mime-database %D/" directory_path print "@exec update-mime-database %D/" directory_path } print "@comment end " $0 next } $1 == "@sample" { sample_file=$2 # Take out .sample target_file=substr(sample_file, 0, length(sample_file) - 7) print "@comment begin " $0 if ($2 ~ /^\//) { print "@unexec if cmp -s '" target_file "' '" sample_file "'; then rm -f '" target_file "'; fi" print sample_file print "@exec if [ ! -f '" target_file "' ]; then /bin/cp -p '" sample_file "' '" target_file "'; fi" } else { print "@unexec if cmp -s '%D/" target_file "' '%D/" sample_file "'; then rm -f '%D/" target_file "'; fi" print sample_file print "@exec if [ ! -f '%D/" target_file "' ]; then /bin/cp -p '%D/" sample_file "' '%D/" target_file "'; fi" } print "@comment end " $0 next } $1 ~ /@sample\(.*,.*,[1234567890]*\)/ { target_perms=substr($1, 9, length($1) - 9) cmd_len=length($1) + 1 sample_file=substr($0, cmd_len + 1, length($0) - cmd_len) target_file=substr(sample_file, 0, length(sample_file) - 7) if (sample_file ~ / /) { split(sample_file, sampledest, " ") sample_file=sampledest[1] target_file=sampledest[2] } split(target_perms, ugp, ",") print "@comment begin " $0 print "@comment target_perms=" target_perms " |" $1 "|" print "@comment target_file=" target_file print "@comment sample_file=" sample_file if ($2 ~ /^\//) { print "@unexec if cmp -s '" target_file "' '" sample_file "'; then rm -f '" target_file "'; fi || true" print sample_file if (ugp[1] != "") { print "@exec chown " ugp[1] " \"" sample_file "\"" } if (ugp[2] != "") { print "@exec chgrp " ugp[2] " \"" sample_file "\"" } if (ugp[3] != "") { print "@exec chmod " ugp[3] " \"" sample_file "\"" } print "@exec if [ ! -f '" target_file "' ]; then /bin/cp -p '" sample_file "' '" target_file "'; fi || true" } else { print "@unexec if cmp -s '%D/" target_file "' '%D/" sample_file "'; then rm -f '%D/" target_file "'; fi || true" print sample_file if (ugp[1] != "") { print "@exec chown " ugp[1] " \"%D/" sample_file "\"" } if (ugp[2] != "") { print "@exec chgrp " ugp[2] " \"%D/" sample_file "\"" } if (ugp[3] != "") { print "@exec chmod " ugp[3] " \"%D/" sample_file "\"" } print "@exec if [ ! -f '%D/" target_file "' ]; then /bin/cp -p '%D/" sample_file "' '%D/" target_file "'; fi || true" } print "@comment end " $0 next } $1 == "@fmtutil" { print "@comment begin " $0 list=$2 print "@unexec set -- " list " ; for f in " list " ; do rm -f $f ; rmdir -p ${f%/*} 2>/dev/null ; done" print "@exec fmtutil-sys --missing >/dev/null" print "@comment end " $0 next } $1 == "@fcfontsdir" { print "@comment begin " $0 if ($2 ~ /^\//) { directory = $2 } else { directory = "%D/" $2 } print "@unexec mkfontscale '" directory "' 2>/dev/null || true" print "@unexec if [ -e '" directory "/fonts.scale' -a \"`stat -f '%%z' '" directory "/fonts.scale' 2>/dev/null`\" = '2' ]; then rm '" directory "/fonts.scale' ; fi" print "@unexec mkfontdir '" directory "' 2>/dev/null || true" print "@unexec if [ -e '" directory "/fonts.dir' -a \"`stat -f '%%z' '" directory "/fonts.dir' 2>/dev/null`\" = '2' ]; then rm '" directory "/fonts.dir' ; fi" print "@unexec fc-cache -s '" directory "' 2>/dev/null || true" print "@exec fc-cache -s '" directory "' 2>/dev/null || true" print "@exec mkfontscale '" directory "' 2>/dev/null || true" print "@exec mkfontdir '" directory "' 2>/dev/null || true" print "@comment end " $0 next } #$1 == "@fcfontsdir" { # font_dir=$2 # print "@comment begin " $0 # print "@exec fc-cache -s %D/" font_dir " 2>/dev/null || true" # print "@exec mkfontscale %D/" font_dir " 2>/dev/null || true" # print "@exec mkfontdir %D/" font_dir " 2>/dev/null || true" # print "@unexec fc-cache -s %D/" font_dir " 2>/dev/null || true" # print "@unexec mkfontscale %D/" font_dir " 2>/dev/null || true" # print "@unexec if [ -e %D/fonts.scale -a \"`stat -f '%%z' %D/" font_dir "/fonts.scale 2>/dev/null`\" = '2' ]; then rm %D/" font_dir "/fonts.scale ; fi" # print "@unexec mkfontdir %D/" font_dir " 2>/dev/null || true" # print "@unexec if [ -e %D/" font_dir "/fonts.dir -a \"`stat -f '%%z' %D/" font_dir "/fonts.dir 2>/dev/null`\" = '2' ]; then rm %D/" font_dir "/fonts.dir ; fi" # print "@unexec rmdir %D/"font_dir" 2>/dev/null || true" # print "@comment end " $0 # next #} # $1 == "@fontsdir" { directory = $2 print "@comment begin " $0 if ($2 ~ /^\//) { directory = $2 } else { directory = "%D/" $2 } print "@unexec mkfontscale '" directory "' 2>/dev/null || true" print "@unexec if [ -e '" directory "/fonts.scale' -a \"`stat -f '%%z' '" directory "/fonts.scale' 2>/dev/null`\" = '2' ]; then rm '" directory "/fonts.scale' ; fi" print "@unexec mkfontdir '" directory "' 2>/dev/null || true" print "@unexec if [ -e '" directory "/fonts.dir' -a \"`stat -f '%%z' '" directory "/fonts.dir' 2>/dev/null`\" = '2' ]; then rm '" directory "/fonts.dir' ; fi" print "@exec mkfontscale '" directory "' 2>/dev/null || true" print "@exec mkfontdir '" directory "' 2>/dev/null || true" print "@comment end " $0 next } $1 == "@shell" { shell_file=$2 print "@comment begin " $0 print shell_file print "@exec cp /etc/shells /etc/shells.bak; (grep -v %D/%F /etc/shells.bak; echo %D/%F) >/etc/shells; rm -f /etc/shells.bak" print "@unexec cp /etc/shells /etc/shells.bak; (grep -v %D/%F /etc/shells.bak) >/etc/shells; rm -f /etc/shells.bak" print "@comment end " $0 next } $1 == "@fc" { print "@comment begin " $0 if ($2 ~ /^\//) { directory = $2 } else { directory = "%D/" $2 } print "@unexec fc-cache -s '" directory "' 2>/dev/null || true" print "@exec fc-cache -s '" directory "' 2>/dev/null || true" print "@comment end " $0 next } #$1 == "@fc" { # font_dir=$2 # print "@comment begin " $0 # print "@exec fc-cache -s %D/" font_dir " 2>/dev/null || true" # print "@unexec fc-cache -s %D/" font_dir " 2>/dev/null || true" # print "@unexec rmdir %D/"font_dir" 2>/dev/null || true" # print "@comment end " $0 # next #} # #$1 == "@fontsdir" { # font_dir=$2 # print "@comment begin " $0 # print "@exec mkfontscale %D/" font_dir " 2>/dev/null || true" # print "@exec mkfontdir %D/" font_dir " 2>/dev/null || true" # print "@unexec mkfontscale %D/" font_dir " 2>/dev/null || true" # print "@unexec if [ -e %D/%@/fonts.scale -a \"`stat -f '%%z' %D/" font_dir "/fonts.scale 2>/dev/null`\" = '2' ]; then rm %D/" font_dir "/fonts.scale ; fi" # print "@unexec mkfontdir %D/" font_dir " 2>/dev/null || true" # print "@unexec if [ -e %D/" font_dir "/fonts.dir -a \"`stat -f '%%z' %D/" font_dir "/fonts.dir 2>/dev/null`\" = '2' ]; then rm %D/" font_dir "/fonts.dir ; fi" # print "@unexec rmdir %D/"font_dir" 2>/dev/null || true" # print "@comment end " $0 # next #} $1 == "@dir" { directory=substr($0, 6, length($0) - 4) print "@comment begin " $0 if ($2 ~ /^\//) { print "@unexec rmdir \"" directory "\" 2>/dev/null || true" print "@exec mkdir -p \"" directory "\" 2>/dev/null || true" } else if ("/$2" ~ /^%D/) { print "@unexec rmdir \"/" directory "\" 2>/dev/null || true" print "@exec mkdir -p \"/" directory "\" 2>/dev/null || true" } else { print "@unexec rmdir \"%D/" directory "\" 2>/dev/null || true" print "@exec mkdir -p \"%D/" directory "\" 2>/dev/null || true" } print "@comment end " $0 next } $1 == "@dirrmtry" { directory=substr($0, 11, length($0) - 10) print "@comment begin " $0 if ($2 ~ /^\//) { print "@unexec rmdir \"" directory "\" 2>/dev/null || true" } else if ("/$2" ~ /^%D/) { print "@unexec rmdir \"/" directory "\" 2>/dev/null || true" } else { print "@unexec rmdir \"%D/" directory "\" 2>/dev/null || true" } print "@comment end " $0 next } $1 == "@dirrm" { directory=substr($0, 8, length($0) - 7) print "@comment begin " $0 if ($2 ~ /^\//) { print "@unexec rmdir \"" directory "\" 2>/dev/null || true" } else if ("/$2" ~ /^%D/) { print "@unexec rmdir \"/" directory "\" 2>/dev/null || true" } else { print "@unexec rmdir \"%D/" directory "\" 2>/dev/null || true" } print "@comment end " $0 next } $1 == "@kld" { directory=substr($0, 6, length($0) - 5) print "@comment begin " $0 if ($2 ~ /^\//) { print "@unexec rmdir -p \"" directory "\" 2>/dev/null || true" kmoddir=directory } else if ("/$2" ~ /^%D/) { print "@unexec rmdir -p \"/" directory "\" 2>/dev/null || true" kmoddir="/" directory } else { print "@unexec rmdir -p \"%D/" directory "\" 2>/dev/null || true" kmoddir="%D/" directory } print "@exec /usr/sbin/kldxref " kmoddir print "@unexec /usr/sbin/kldxref " kmoddir print "@comment end " $0 next } $1 == "@rmtry" { file=substr($0, 8, length($0) - 7) print "@comment begin " $0 if ($2 ~ /^\//) { print "@unexec rm \"" file "\" 2>/dev/null || true" } else if ("/$2" ~ /^%D/) { print "@unexec rm \"/" file "\" 2>/dev/null || true" } else { print "@unexec rm \"%D/" file "\" 2>/dev/null || true" } print "@comment end " $0 next } $1 == "@fmtutil" { print "@comment begin " $0 print "@exec fmtutil-sys --missing >/dev/null" for (i = 2; i <= NF; i++) print "@unexec rm -f "$i"; rmdir -p `dirname "$1"` 2>/dev/null" print "@comment end " $0 next } $1 == "@rootinst" { file=substr($0, 11, length($0) - 10) target=substr(file, 2, length(file) - 1) if (target ~ /\//) { last=split(target, path, "/") tmppath=join(path, 1, (last - 1), "/") } print "@comment begin " $0 if ($2 ~ /^\//) { print "@cwd /" # print "@unexec rm \"" file "\" 2>/dev/null || true" # print "@exec mkdir -p \"" tmppath "\"" print target print "@cwd " # print "@exec mv \"" target "\" \"" file "\"" # print "@exec rmdir -p \"" tmppath "\"" } else if ("/$2" ~ /^%D/) { print "@unexec rm \"/" file "\" 2>/dev/null || true" } else { print "@unexec rm \"%D/" file "\" 2>/dev/null || true" } print "@comment end " $0 next } $1 == "@rootdir" { directory=substr($0, 10, length($0) - 9) print "@comment begin " $0 if ($2 ~ /^\//) { print "@unexec rmdir -p \"" directory "\" 2>/dev/null || true" print "@exec mkdir -p \"" directory "\" 2>/dev/null || true" } else if ("/$2" ~ /^%D/) { print "@unexec rmdir -p \"/" directory "\" 2>/dev/null || true" print "@exec mkdir -p \"/" directory "\" 2>/dev/null || true" } else { print "@unexec rmdir -p \"/" directory "\" 2>/dev/null || true" print "@exec mkdir -p \"/" directory "\" 2>/dev/null || true" } print "@comment end " $0 next } $1 == "@terminfo" { print "@comment begin " $0 print "@exec sh -c \"terminfodir=%D/share/misc ; terminfodb=${terminfodir}/terminfo.db ; if [ -e ${terminfodb}.default ] && which -s tic; then cp ${terminfodb}.default ${terminfodb} ; find -s ${terminfodir} -name '*.terminfo' -exec tic {} \\; ; fi\" 2>/dev/null || true" print "@unexec sh -c \"terminfodir=%D/share/misc ; terminfodb=${terminfodir}/terminfo.db ; if [ -e ${terminfodb}.default ] && which -s tic; then cp ${terminfodb}.default ${terminfodb} ; find -s ${terminfodir} -name '*.terminfo' -exec tic {} \\; ; else rm -f ${terminfodb} ; fi\" 2>/dev/null || true" print "@comment end " $0 next } # Print everything else as-is { print $0 }