/[gentoo-x86]/eclass/eutils.eclass
Gentoo

Diff of /eclass/eutils.eclass

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.329 Revision 1.349
1# Copyright 1999-2009 Gentoo Foundation 1# Copyright 1999-2009 Gentoo Foundation
2# Distributed under the terms of the GNU General Public License v2 2# Distributed under the terms of the GNU General Public License v2
3# $Header: /var/cvsroot/gentoo-x86/eclass/eutils.eclass,v 1.329 2010/01/28 22:00:12 betelgeuse Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/eutils.eclass,v 1.349 2010/08/19 21:32:26 vapier Exp $
4 4
5# @ECLASS: eutils.eclass 5# @ECLASS: eutils.eclass
6# @MAINTAINER: 6# @MAINTAINER:
7# base-system@gentoo.org 7# base-system@gentoo.org
8# @BLURB: many extra (but common) functions that are used in ebuilds 8# @BLURB: many extra (but common) functions that are used in ebuilds
49 sleep 1 49 sleep 1
50 done 50 done
51 fi 51 fi
52} 52}
53 53
54else
55
56ebeep() {
57 ewarn "QA Notice: ebeep is not defined in EAPI=${EAPI}, please file a bug at http://bugs.gentoo.org"
58}
59
60epause() {
61 ewarn "QA Notice: epause is not defined in EAPI=${EAPI}, please file a bug at http://bugs.gentoo.org"
62}
63
64fi
65
66# @FUNCTION: eqawarn
67# @USAGE: [message]
68# @DESCRIPTION:
69# Proxy to einfo for package managers that don't provide eqawarn and use the PM
70# implementation if available.
71if ! declare -F eqawarn >/dev/null ; then
72 eqawarn() {
73 einfo "$@"
74 }
54fi 75fi
55 76
56# @FUNCTION: ecvs_clean 77# @FUNCTION: ecvs_clean
57# @USAGE: [list of dirs] 78# @USAGE: [list of dirs]
58# @DESCRIPTION: 79# @DESCRIPTION:
73 [[ -z $* ]] && set -- . 94 [[ -z $* ]] && set -- .
74 find "$@" -type d -name '.svn' -prune -print0 | xargs -0 rm -rf 95 find "$@" -type d -name '.svn' -prune -print0 | xargs -0 rm -rf
75} 96}
76 97
77# @FUNCTION: eshopts_push 98# @FUNCTION: eshopts_push
78# @USAGE: [options to `set`] 99# @USAGE: [options to `set` or `shopt`]
79# @DESCRIPTION: 100# @DESCRIPTION:
80# Often times code will want to enable a shell option to change code behavior. 101# Often times code will want to enable a shell option to change code behavior.
81# Since changing shell options can easily break other pieces of code (which 102# Since changing shell options can easily break other pieces of code (which
82# assume the default state), eshopts_push is used to (1) push the current shell 103# assume the default state), eshopts_push is used to (1) push the current shell
83# options onto a stack and (2) pass the specified arguments to set. 104# options onto a stack and (2) pass the specified arguments to set.
105#
106# If the first argument is '-s' or '-u', we assume you want to call `shopt`
107# rather than `set` as there are some options only available via that.
84# 108#
85# A common example is to disable shell globbing so that special meaning/care 109# A common example is to disable shell globbing so that special meaning/care
86# may be used with variables/arguments to custom functions. That would be: 110# may be used with variables/arguments to custom functions. That would be:
87# @CODE 111# @CODE
88# eshopts_push -o noglob 112# eshopts_push -o noglob
96# @CODE 120# @CODE
97eshopts_push() { 121eshopts_push() {
98 # have to assume __ESHOPTS_SAVE__ isn't screwed with 122 # have to assume __ESHOPTS_SAVE__ isn't screwed with
99 # as a `declare -a` here will reset its value 123 # as a `declare -a` here will reset its value
100 local i=${#__ESHOPTS_SAVE__[@]} 124 local i=${#__ESHOPTS_SAVE__[@]}
125 if [[ $1 == -[su] ]] ; then
101 __ESHOPTS_SAVE__[$i]=$- 126 __ESHOPTS_SAVE__[$i]=$(shopt -p)
102 [[ $# -eq 0 ]] && return 0 127 [[ $# -eq 0 ]] && return 0
128 shopt "$@" || die "eshopts_push: bad options to shopt: $*"
129 else
130 __ESHOPTS_SAVE__[$i]=$-
131 [[ $# -eq 0 ]] && return 0
103 set "$@" || die "eshopts_push: bad options to set: $*" 132 set "$@" || die "eshopts_push: bad options to set: $*"
133 fi
104} 134}
105 135
106# @FUNCTION: eshopts_pop 136# @FUNCTION: eshopts_pop
107# @USAGE: 137# @USAGE:
108# @DESCRIPTION: 138# @DESCRIPTION:
112 [[ $# -ne 0 ]] && die "eshopts_pop takes no arguments" 142 [[ $# -ne 0 ]] && die "eshopts_pop takes no arguments"
113 local i=$(( ${#__ESHOPTS_SAVE__[@]} - 1 )) 143 local i=$(( ${#__ESHOPTS_SAVE__[@]} - 1 ))
114 [[ ${i} -eq -1 ]] && die "eshopts_{push,pop}: unbalanced pair" 144 [[ ${i} -eq -1 ]] && die "eshopts_{push,pop}: unbalanced pair"
115 local s=${__ESHOPTS_SAVE__[$i]} 145 local s=${__ESHOPTS_SAVE__[$i]}
116 unset __ESHOPTS_SAVE__[$i] 146 unset __ESHOPTS_SAVE__[$i]
147 if [[ ${s} == "shopt -"* ]] ; then
148 eval "${s}" || die "eshopts_pop: sanity: invalid shopt options: ${s}"
149 else
117 set +$- || die "eshopts_pop: sanity: invalid shell settings: $-" 150 set +$- || die "eshopts_pop: sanity: invalid shell settings: $-"
118 set -${s} || die "eshopts_pop: sanity: unable to restore saved shell settings: ${s}" 151 set -${s} || die "eshopts_pop: sanity: unable to restore saved shell settings: ${s}"
152 fi
119} 153}
120 154
121# @VARIABLE: EPATCH_SOURCE 155# @VARIABLE: EPATCH_SOURCE
122# @DESCRIPTION: 156# @DESCRIPTION:
123# Default directory to search for patches. 157# Default directory to search for patches.
399 EPATCH_SOURCE=${EPATCH_SOURCE} \ 433 EPATCH_SOURCE=${EPATCH_SOURCE} \
400 EPATCH_SUFFIX="patch" \ 434 EPATCH_SUFFIX="patch" \
401 EPATCH_FORCE="yes" \ 435 EPATCH_FORCE="yes" \
402 EPATCH_MULTI_MSG="Applying user patches from ${EPATCH_SOURCE} ..." \ 436 EPATCH_MULTI_MSG="Applying user patches from ${EPATCH_SOURCE} ..." \
403 epatch 437 epatch
404 break 438 return 0
405 fi 439 fi
406 done 440 done
441 return 1
407} 442}
408 443
409# @FUNCTION: emktemp 444# @FUNCTION: emktemp
410# @USAGE: [temp dir] 445# @USAGE: [temp dir]
411# @DESCRIPTION: 446# @DESCRIPTION:
683 fi 718 fi
684 ;; 719 ;;
685 720
686 *) 721 *)
687 if [[ -z $@ ]] ; then 722 if [[ -z $@ ]] ; then
688 useradd ${opts} \ 723 useradd -r ${opts} \
689 -c "added by portage for ${PN}" \ 724 -c "added by portage for ${PN}" \
690 ${euser} \ 725 ${euser} \
691 || die "enewuser failed" 726 || die "enewuser failed"
692 else 727 else
693 einfo " - Extra: $@" 728 einfo " - Extra: $@"
694 useradd ${opts} "$@" \ 729 useradd -r ${opts} "$@" \
695 ${euser} \ 730 ${euser} \
696 || die "enewuser failed" 731 || die "enewuser failed"
697 fi 732 fi
698 ;; 733 ;;
699 esac 734 esac
812 esac 847 esac
813 groupadd -g ${egid} ${egroup} || die "enewgroup failed" 848 groupadd -g ${egid} ${egroup} || die "enewgroup failed"
814 ;; 849 ;;
815 850
816 *) 851 *)
852 # We specify -r so that we get a GID in the system range from login.defs
817 groupadd ${opts} ${egroup} || die "enewgroup failed" 853 groupadd -r ${opts} ${egroup} || die "enewgroup failed"
818 ;; 854 ;;
819 esac 855 esac
820 export SANDBOX_ON="${oldsandbox}" 856 export SANDBOX_ON="${oldsandbox}"
821} 857}
822 858
833 869
834# Make a desktop file ! 870# Make a desktop file !
835# Great for making those icons in kde/gnome startmenu ! 871# Great for making those icons in kde/gnome startmenu !
836# Amaze your friends ! Get the women ! Join today ! 872# Amaze your friends ! Get the women ! Join today !
837# 873#
838# make_desktop_entry(<command>, [name], [icon], [type], [path]) 874# make_desktop_entry(<command>, [name], [icon], [type], [fields])
839# 875#
840# binary: what command does the app run with ? 876# binary: what command does the app run with ?
841# name: the name that will show up in the menu 877# name: the name that will show up in the menu
842# icon: give your little like a pretty little icon ... 878# icon: give your little like a pretty little icon ...
843# this can be relative (to /usr/share/pixmaps) or 879# this can be relative (to /usr/share/pixmaps) or
844# a full path to an icon 880# a full path to an icon
845# type: what kind of application is this ? for categories: 881# type: what kind of application is this ? for categories:
846# http://standards.freedesktop.org/menu-spec/latest/apa.html 882# http://standards.freedesktop.org/menu-spec/latest/apa.html
847# path: if your app needs to startup in a specific dir 883# fields: extra fields to append to the desktop file; a printf string
848make_desktop_entry() { 884make_desktop_entry() {
849 [[ -z $1 ]] && eerror "make_desktop_entry: You must specify the executable" && return 1 885 [[ -z $1 ]] && die "make_desktop_entry: You must specify the executable"
850 886
851 local exec=${1} 887 local exec=${1}
852 local name=${2:-${PN}} 888 local name=${2:-${PN}}
853 local icon=${3:-${PN}} 889 local icon=${3:-${PN}}
854 local type=${4} 890 local type=${4}
855 local path=${5} 891 local fields=${5}
856 892
857 if [[ -z ${type} ]] ; then 893 if [[ -z ${type} ]] ; then
858 local catmaj=${CATEGORY%%-*} 894 local catmaj=${CATEGORY%%-*}
859 local catmin=${CATEGORY##*-} 895 local catmin=${CATEGORY##*-}
860 case ${catmaj} in 896 case ${catmaj} in
861 app) 897 app)
862 case ${catmin} in 898 case ${catmin} in
863 accessibility) type=Accessibility;; 899 accessibility) type=Accessibility;;
864 admin) type=System;; 900 admin) type=System;;
865 antivirus) type=System;; 901 antivirus) type=System;;
866 arch) type=Archiving;; 902 arch) type=Archiving;;
867 backup) type=Archiving;; 903 backup) type=Archiving;;
868 cdr) type=DiscBurning;; 904 cdr) type=DiscBurning;;
869 dicts) type=Dictionary;; 905 dicts) type=Dictionary;;
870 doc) type=Documentation;; 906 doc) type=Documentation;;
871 editors) type=TextEditor;; 907 editors) type=TextEditor;;
872 emacs) type=TextEditor;; 908 emacs) type=TextEditor;;
873 emulation) type=Emulator;; 909 emulation) type=Emulator;;
874 laptop) type=HardwareSettings;; 910 laptop) type=HardwareSettings;;
875 office) type=Office;; 911 office) type=Office;;
876 pda) type=PDA;; 912 pda) type=PDA;;
877 vim) type=TextEditor;; 913 vim) type=TextEditor;;
878 xemacs) type=TextEditor;; 914 xemacs) type=TextEditor;;
879 *) type=;;
880 esac 915 esac
881 ;; 916 ;;
882 917
883 dev) 918 dev)
884 type="Development" 919 type="Development"
885 ;; 920 ;;
886 921
887 games) 922 games)
888 case ${catmin} in 923 case ${catmin} in
889 action|fps) type=ActionGame;; 924 action|fps) type=ActionGame;;
890 arcade) type=ArcadeGame;; 925 arcade) type=ArcadeGame;;
891 board) type=BoardGame;; 926 board) type=BoardGame;;
892 emulation) type=Emulator;; 927 emulation) type=Emulator;;
893 kids) type=KidsGame;; 928 kids) type=KidsGame;;
894 puzzle) type=LogicGame;; 929 puzzle) type=LogicGame;;
895 roguelike) type=RolePlaying;; 930 roguelike) type=RolePlaying;;
896 rpg) type=RolePlaying;; 931 rpg) type=RolePlaying;;
897 simulation) type=Simulation;; 932 simulation) type=Simulation;;
898 sports) type=SportsGame;; 933 sports) type=SportsGame;;
899 strategy) type=StrategyGame;; 934 strategy) type=StrategyGame;;
900 *) type=;;
901 esac 935 esac
902 type="Game;${type}" 936 type="Game;${type}"
903 ;; 937 ;;
904 938
905 gnome) 939 gnome)
914 type="Network;Email" 948 type="Network;Email"
915 ;; 949 ;;
916 950
917 media) 951 media)
918 case ${catmin} in 952 case ${catmin} in
953 gfx)
919 gfx) type=Graphics;; 954 type=Graphics
955 ;;
956 *)
957 case ${catmin} in
920 radio) type=Tuner;; 958 radio) type=Tuner;;
921 sound) type=Audio;; 959 sound) type=Audio;;
922 tv) type=TV;; 960 tv) type=TV;;
923 video) type=Video;; 961 video) type=Video;;
924 *) type=;; 962 esac
963 type="AudioVideo;${type}"
964 ;;
925 esac 965 esac
926 type="AudioVideo;${type}"
927 ;; 966 ;;
928 967
929 net) 968 net)
930 case ${catmin} in 969 case ${catmin} in
931 dialup) type=Dialup;; 970 dialup) type=Dialup;;
932 ftp) type=FileTransfer;; 971 ftp) type=FileTransfer;;
933 im) type=InstantMessaging;; 972 im) type=InstantMessaging;;
934 irc) type=IRCClient;; 973 irc) type=IRCClient;;
935 mail) type=Email;; 974 mail) type=Email;;
936 news) type=News;; 975 news) type=News;;
937 nntp) type=News;; 976 nntp) type=News;;
938 p2p) type=FileTransfer;; 977 p2p) type=FileTransfer;;
939 *) type=;; 978 voip) type=Telephony;;
940 esac 979 esac
941 type="Network;${type}" 980 type="Network;${type}"
942 ;; 981 ;;
943 982
944 sci) 983 sci)
945 case ${catmin} in 984 case ${catmin} in
946 astro*) type=Astronomy;; 985 astro*) type=Astronomy;;
947 bio*) type=Biology;; 986 bio*) type=Biology;;
948 calc*) type=Calculator;; 987 calc*) type=Calculator;;
949 chem*) type=Chemistry;; 988 chem*) type=Chemistry;;
950 elec*) type=Electronics;; 989 elec*) type=Electronics;;
951 geo*) type=Geology;; 990 geo*) type=Geology;;
952 math*) type=Math;; 991 math*) type=Math;;
953 physics) type=Physics;; 992 physics) type=Physics;;
954 visual*) type=DataVisualization;; 993 visual*) type=DataVisualization;;
955 *) type=;;
956 esac 994 esac
957 type="Science;${type}" 995 type="Education;Science;${type}"
958 ;; 996 ;;
959 997
960 sys) 998 sys)
961 type="System" 999 type="System"
962 ;; 1000 ;;
963 1001
964 www) 1002 www)
965 case ${catmin} in 1003 case ${catmin} in
966 client) type=WebBrowser;; 1004 client) type=WebBrowser;;
967 *) type=;;
968 esac 1005 esac
969 type="Network" 1006 type="Network;${type}"
970 ;; 1007 ;;
971 1008
972 *) 1009 *)
973 type= 1010 type=
974 ;; 1011 ;;
979 else 1016 else
980 local desktop_name="${PN}-${SLOT}" 1017 local desktop_name="${PN}-${SLOT}"
981 fi 1018 fi
982 local desktop="${T}/$(echo ${exec} | sed 's:[[:space:]/:]:_:g')-${desktop_name}.desktop" 1019 local desktop="${T}/$(echo ${exec} | sed 's:[[:space:]/:]:_:g')-${desktop_name}.desktop"
983 #local desktop=${T}/${exec%% *:-${desktop_name}}.desktop 1020 #local desktop=${T}/${exec%% *:-${desktop_name}}.desktop
1021
1022 # Don't append another ";" when a valid category value is provided.
1023 type=${type%;}${type:+;}
1024
1025 eshopts_push -s extglob
1026 if [[ -n ${icon} && ${icon} != /* ]] && [[ ${icon} == *.xpm || ${icon} == *.png || ${icon} == *.svg ]]; then
1027 ewarn "As described in the Icon Theme Specification, icon file extensions are not"
1028 ewarn "allowed in .desktop files if the value is not an absolute path."
1029 icon=${icon%.@(xpm|png|svg)}
1030 fi
1031 eshopts_pop
984 1032
985 cat <<-EOF > "${desktop}" 1033 cat <<-EOF > "${desktop}"
986 [Desktop Entry] 1034 [Desktop Entry]
987 Name=${name} 1035 Name=${name}
988 Type=Application 1036 Type=Application
989 Comment=${DESCRIPTION} 1037 Comment=${DESCRIPTION}
990 Exec=${exec} 1038 Exec=${exec}
991 TryExec=${exec%% *} 1039 TryExec=${exec%% *}
992 Icon=${icon} 1040 Icon=${icon}
993 Categories=${type}; 1041 Categories=${type}
994 EOF 1042 EOF
995 1043
996 [[ ${path} ]] && echo "Path=${path}" >> "${desktop}" 1044 if [[ ${fields:-=} != *=* ]] ; then
1045 # 5th arg used to be value to Path=
1046 ewarn "make_desktop_entry: update your 5th arg to read Path=${fields}"
1047 fields="Path=${fields}"
1048 fi
1049 [[ -n ${fields} ]] && printf '%b\n' "${fields}" >> "${desktop}"
997 1050
998 ( 1051 (
999 # wrap the env here so that the 'insinto' call 1052 # wrap the env here so that the 'insinto' call
1000 # doesn't corrupt the env of the caller 1053 # doesn't corrupt the env of the caller
1001 insinto /usr/share/applications 1054 insinto /usr/share/applications
1002 doins "${desktop}" 1055 doins "${desktop}"
1003 ) 1056 ) || die "installing desktop file failed"
1004} 1057}
1005 1058
1006# @FUNCTION: validate_desktop_entries 1059# @FUNCTION: validate_desktop_entries
1007# @USAGE: [directories] 1060# @USAGE: [directories]
1008# @MAINTAINER: 1061# @MAINTAINER:
1287 [[ -z ${src} ]] && die "Could not locate source for '${src_input}'" 1340 [[ -z ${src} ]] && die "Could not locate source for '${src_input}'"
1288 1341
1289 local shrtsrc=$(basename "${src}") 1342 local shrtsrc=$(basename "${src}")
1290 echo ">>> Unpacking ${shrtsrc} to ${PWD}" 1343 echo ">>> Unpacking ${shrtsrc} to ${PWD}"
1291 if [[ -z ${skip} ]] ; then 1344 if [[ -z ${skip} ]] ; then
1292 local ver=$(grep -a '#.*Makeself' "${src}" | awk '{print $NF}') 1345 local ver=$(grep -m1 -a '#.*Makeself' "${src}" | awk '{print $NF}')
1293 local skip=0 1346 local skip=0
1294 exe=tail 1347 exe=tail
1295 case ${ver} in 1348 case ${ver} in
1296 1.5.*|1.6.0-nv) # tested 1.5.{3,4,5} ... guessing 1.5.x series is same 1349 1.5.*|1.6.0-nv) # tested 1.5.{3,4,5} ... guessing 1.5.x series is same
1297 skip=$(grep -a ^skip= "${src}" | cut -d= -f2) 1350 skip=$(grep -a ^skip= "${src}" | cut -d= -f2)
1299 2.0|2.0.1) 1352 2.0|2.0.1)
1300 skip=$(grep -a ^$'\t'tail "${src}" | awk '{print $2}' | cut -b2-) 1353 skip=$(grep -a ^$'\t'tail "${src}" | awk '{print $2}' | cut -b2-)
1301 ;; 1354 ;;
1302 2.1.1) 1355 2.1.1)
1303 skip=$(grep -a ^offset= "${src}" | awk '{print $2}' | cut -b2-) 1356 skip=$(grep -a ^offset= "${src}" | awk '{print $2}' | cut -b2-)
1304 let skip="skip + 1" 1357 (( skip++ ))
1305 ;; 1358 ;;
1306 2.1.2) 1359 2.1.2)
1307 skip=$(grep -a ^offset= "${src}" | awk '{print $3}' | head -n 1) 1360 skip=$(grep -a ^offset= "${src}" | awk '{print $3}' | head -n 1)
1308 let skip="skip + 1" 1361 (( skip++ ))
1309 ;; 1362 ;;
1310 2.1.3) 1363 2.1.3)
1311 skip=`grep -a ^offset= "${src}" | awk '{print $3}'` 1364 skip=`grep -a ^offset= "${src}" | awk '{print $3}'`
1312 let skip="skip + 1" 1365 (( skip++ ))
1313 ;; 1366 ;;
1314 2.1.4|2.1.5) 1367 2.1.4|2.1.5)
1315 skip=$(grep -a offset=.*head.*wc "${src}" | awk '{print $3}' | head -n 1) 1368 skip=$(grep -a offset=.*head.*wc "${src}" | awk '{print $3}' | head -n 1)
1316 skip=$(head -n ${skip} "${src}" | wc -c) 1369 skip=$(head -n ${skip} "${src}" | wc -c)
1317 exe="dd" 1370 exe="dd"
1326 esac 1379 esac
1327 debug-print "Detected Makeself version ${ver} ... using ${skip} as offset" 1380 debug-print "Detected Makeself version ${ver} ... using ${skip} as offset"
1328 fi 1381 fi
1329 case ${exe} in 1382 case ${exe} in
1330 tail) exe="tail -n +${skip} '${src}'";; 1383 tail) exe="tail -n +${skip} '${src}'";;
1331 dd) exe="dd ibs=${skip} skip=1 obs=1024 conv=sync if='${src}'";; 1384 dd) exe="dd ibs=${skip} skip=1 if='${src}'";;
1332 *) die "makeself cant handle exe '${exe}'" 1385 *) die "makeself cant handle exe '${exe}'"
1333 esac 1386 esac
1334 1387
1335 # lets grab the first few bytes of the file to figure out what kind of archive it is 1388 # lets grab the first few bytes of the file to figure out what kind of archive it is
1336 local tmpfile=$(emktemp) 1389 local tmpfile=$(emktemp)
1469 export CDROM_ROOT=${CD_ROOT_1:-${CD_ROOT}} 1522 export CDROM_ROOT=${CD_ROOT_1:-${CD_ROOT}}
1470 einfo "Found CD #${CDROM_CURRENT_CD} root at ${CDROM_ROOT}" 1523 einfo "Found CD #${CDROM_CURRENT_CD} root at ${CDROM_ROOT}"
1471 export CDROM_SET=-1 1524 export CDROM_SET=-1
1472 for f in ${CDROM_CHECK_1//:/ } ; do 1525 for f in ${CDROM_CHECK_1//:/ } ; do
1473 ((++CDROM_SET)) 1526 ((++CDROM_SET))
1474 [[ -e ${CD_ROOT}/${f} ]] && break 1527 [[ -e ${CDROM_ROOT}/${f} ]] && break
1475 done 1528 done
1476 export CDROM_MATCH=${f} 1529 export CDROM_MATCH=${f}
1477 return 1530 return
1478 fi 1531 fi
1479 1532

Legend:
Removed from v.1.329  
changed lines
  Added in v.1.349

  ViewVC Help
Powered by ViewVC 1.1.20