| 1 | # Copyright 1999-2006 Gentoo Foundation |
1 | # Copyright 1999-2006 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.270 2007/01/20 06:24:17 vapier Exp $ |
3 | # $Header: /var/cvsroot/gentoo-x86/eclass/eutils.eclass,v 1.275 2007/02/17 00:17:39 vapier Exp $ |
| 4 | # |
4 | # |
| 5 | # This eclass is for general purpose functions that most ebuilds |
5 | # This eclass is for general purpose functions that most ebuilds |
| 6 | # have to implement themselves. |
6 | # have to implement themselves. |
| 7 | # |
7 | # |
| 8 | # NB: If you add anything, please comment it! |
8 | # NB: If you add anything, please comment it! |
| … | |
… | |
| 892 | if [ "${SLOT}" == "0" ] ; then |
892 | if [ "${SLOT}" == "0" ] ; then |
| 893 | local desktop_name="${PN}" |
893 | local desktop_name="${PN}" |
| 894 | else |
894 | else |
| 895 | local desktop_name="${PN}-${SLOT}" |
895 | local desktop_name="${PN}-${SLOT}" |
| 896 | fi |
896 | fi |
| 897 | local desktop=${T}/${exec%% *}-${desktop_name}.desktop |
897 | local desktop="${T}/$(echo ${exec} | sed 's:[[:space:]/:]:_:g')-${desktop_name}.desktop" |
| 898 | # local desktop=${T}/${exec%% *:-${desktop_name}}.desktop |
898 | #local desktop=${T}/${exec%% *:-${desktop_name}}.desktop |
| 899 | |
899 | |
|
|
900 | cat <<-EOF > "${desktop}" |
| 900 | echo "[Desktop Entry] |
901 | [Desktop Entry] |
| 901 | Encoding=UTF-8 |
902 | Encoding=UTF-8 |
| 902 | Version=0.9.2 |
903 | Version=0.9.2 |
| 903 | Name=${name} |
904 | Name=${name} |
| 904 | Type=Application |
905 | Type=Application |
| 905 | Comment=${DESCRIPTION} |
906 | Comment=${DESCRIPTION} |
| 906 | Exec=${exec} |
907 | Exec=${exec} |
| 907 | TryExec=${exec%% *} |
908 | TryExec=${exec%% *} |
| 908 | Path=${path} |
909 | Path=${path} |
| 909 | Icon=${icon} |
910 | Icon=${icon} |
| 910 | Categories=Application;${type};" > "${desktop}" |
911 | Categories=Application;${type}; |
|
|
912 | EOF |
| 911 | |
913 | |
| 912 | ( |
914 | ( |
| 913 | # wrap the env here so that the 'insinto' call |
915 | # wrap the env here so that the 'insinto' call |
| 914 | # doesn't corrupt the env of the caller |
916 | # doesn't corrupt the env of the caller |
| 915 | insinto /usr/share/applications |
917 | insinto /usr/share/applications |
| … | |
… | |
| 929 | |
931 | |
| 930 | local title=$1 |
932 | local title=$1 |
| 931 | local command=$2 |
933 | local command=$2 |
| 932 | local desktop=${T}/${wm}.desktop |
934 | local desktop=${T}/${wm}.desktop |
| 933 | |
935 | |
|
|
936 | cat <<-EOF > "${desktop}" |
| 934 | echo "[Desktop Entry] |
937 | [Desktop Entry] |
| 935 | Encoding=UTF-8 |
938 | Encoding=UTF-8 |
| 936 | Name=${title} |
939 | Name=${title} |
| 937 | Comment=This session logs you into ${title} |
940 | Comment=This session logs you into ${title} |
| 938 | Exec=${command} |
941 | Exec=${command} |
| 939 | TryExec=${command} |
942 | TryExec=${command} |
| 940 | Type=Application" > "${desktop}" |
943 | Type=Application |
|
|
944 | EOF |
| 941 | |
945 | |
|
|
946 | ( |
|
|
947 | # wrap the env here so that the 'insinto' call |
|
|
948 | # doesn't corrupt the env of the caller |
| 942 | insinto /usr/share/xsessions |
949 | insinto /usr/share/xsessions |
| 943 | doins "${desktop}" |
950 | doins "${desktop}" |
|
|
951 | ) |
| 944 | } |
952 | } |
| 945 | |
953 | |
| 946 | domenu() { |
954 | domenu() { |
|
|
955 | ( |
|
|
956 | # wrap the env here so that the 'insinto' call |
|
|
957 | # doesn't corrupt the env of the caller |
| 947 | local i j |
958 | local i j ret=0 |
| 948 | insinto /usr/share/applications |
959 | insinto /usr/share/applications |
| 949 | for i in "$@" ; do |
960 | for i in "$@" ; do |
| 950 | if [[ -f ${i} ]] ; then |
961 | if [[ -f ${i} ]] ; then |
| 951 | doins "${i}" |
962 | doins "${i}" |
|
|
963 | ((ret+=$?)) |
| 952 | elif [[ -d ${i} ]] ; then |
964 | elif [[ -d ${i} ]] ; then |
| 953 | for j in "${i}"/*.desktop ; do |
965 | for j in "${i}"/*.desktop ; do |
| 954 | doins "${j}" |
966 | doins "${j}" |
|
|
967 | ((ret+=$?)) |
| 955 | done |
968 | done |
| 956 | fi |
969 | fi |
| 957 | done |
970 | done |
|
|
971 | exit ${ret} |
|
|
972 | ) |
| 958 | } |
973 | } |
| 959 | newmenu() { |
974 | newmenu() { |
|
|
975 | ( |
|
|
976 | # wrap the env here so that the 'insinto' call |
|
|
977 | # doesn't corrupt the env of the caller |
| 960 | insinto /usr/share/applications |
978 | insinto /usr/share/applications |
| 961 | newins "$1" "$2" |
979 | newins "$@" |
|
|
980 | ) |
| 962 | } |
981 | } |
| 963 | |
982 | |
| 964 | doicon() { |
983 | doicon() { |
|
|
984 | ( |
|
|
985 | # wrap the env here so that the 'insinto' call |
|
|
986 | # doesn't corrupt the env of the caller |
| 965 | local i j |
987 | local i j ret |
| 966 | insinto /usr/share/pixmaps |
988 | insinto /usr/share/pixmaps |
| 967 | for i in "$@" ; do |
989 | for i in "$@" ; do |
| 968 | if [[ -f ${i} ]] ; then |
990 | if [[ -f ${i} ]] ; then |
| 969 | doins "${i}" |
991 | doins "${i}" |
|
|
992 | ((ret+=$?)) |
| 970 | elif [[ -d ${i} ]] ; then |
993 | elif [[ -d ${i} ]] ; then |
| 971 | for j in "${i}"/*.png ; do |
994 | for j in "${i}"/*.png ; do |
| 972 | doins "${j}" |
995 | doins "${j}" |
|
|
996 | ((ret+=$?)) |
| 973 | done |
997 | done |
| 974 | fi |
998 | fi |
| 975 | done |
999 | done |
|
|
1000 | exit ${ret} |
|
|
1001 | ) |
| 976 | } |
1002 | } |
| 977 | newicon() { |
1003 | newicon() { |
|
|
1004 | ( |
|
|
1005 | # wrap the env here so that the 'insinto' call |
|
|
1006 | # doesn't corrupt the env of the caller |
| 978 | insinto /usr/share/pixmaps |
1007 | insinto /usr/share/pixmaps |
| 979 | newins "$1" "$2" |
1008 | newins "$@" |
|
|
1009 | ) |
| 980 | } |
1010 | } |
| 981 | |
1011 | |
| 982 | ############################################################## |
1012 | ############################################################## |
| 983 | # END: Handle .desktop files and menu entries # |
1013 | # END: Handle .desktop files and menu entries # |
| 984 | ############################################################## |
1014 | ############################################################## |
| … | |
… | |
| 1021 | # lseek |
1051 | # lseek |
| 1022 | # root@vapier 0 pdv_unpack # strace -elseek ./hldsupdatetool.bin |
1052 | # root@vapier 0 pdv_unpack # strace -elseek ./hldsupdatetool.bin |
| 1023 | # lseek(3, -4, SEEK_END) = 2981250 |
1053 | # lseek(3, -4, SEEK_END) = 2981250 |
| 1024 | # thus we would pass in the value of '4' as the second parameter. |
1054 | # thus we would pass in the value of '4' as the second parameter. |
| 1025 | unpack_pdv() { |
1055 | unpack_pdv() { |
| 1026 | local src=$(find_unpackable_file $1) |
1056 | local src=$(find_unpackable_file "$1") |
| 1027 | local sizeoff_t=$2 |
1057 | local sizeoff_t=$2 |
| 1028 | |
1058 | |
| 1029 | [[ -z ${src} ]] && die "Could not locate source for '$1'" |
1059 | [[ -z ${src} ]] && die "Could not locate source for '$1'" |
| 1030 | [[ -z ${sizeoff_t} ]] && die "No idea what off_t size was used for this pdv :(" |
1060 | [[ -z ${sizeoff_t} ]] && die "No idea what off_t size was used for this pdv :(" |
| 1031 | |
1061 | |
| 1032 | local shrtsrc=$(basename "${src}") |
1062 | local shrtsrc=$(basename "${src}") |
| 1033 | echo ">>> Unpacking ${shrtsrc} to ${PWD}" |
1063 | echo ">>> Unpacking ${shrtsrc} to ${PWD}" |
| 1034 | local metaskip=`tail -c ${sizeoff_t} ${src} | hexdump -e \"%i\"` |
1064 | local metaskip=$(tail -c ${sizeoff_t} "${src}" | hexdump -e \"%i\") |
| 1035 | local tailskip=`tail -c $((${sizeoff_t}*2)) ${src} | head -c ${sizeoff_t} | hexdump -e \"%i\"` |
1065 | local tailskip=$(tail -c $((${sizeoff_t}*2)) "${src}" | head -c ${sizeoff_t} | hexdump -e \"%i\") |
| 1036 | |
1066 | |
| 1037 | # grab metadata for debug reasons |
1067 | # grab metadata for debug reasons |
| 1038 | local metafile="$(emktemp)" |
1068 | local metafile=$(emktemp) |
| 1039 | tail -c +$((${metaskip}+1)) ${src} > ${metafile} |
1069 | tail -c +$((${metaskip}+1)) "${src}" > "${metafile}" |
| 1040 | |
1070 | |
| 1041 | # rip out the final file name from the metadata |
1071 | # rip out the final file name from the metadata |
| 1042 | local datafile="`tail -c +$((${metaskip}+1)) ${src} | strings | head -n 1`" |
1072 | local datafile=$(tail -c +$((${metaskip}+1)) "${src}" | strings | head -n 1) |
| 1043 | datafile="`basename ${datafile}`" |
1073 | datafile=$(basename "${datafile}") |
| 1044 | |
1074 | |
| 1045 | # now lets uncompress/untar the file if need be |
1075 | # now lets uncompress/untar the file if need be |
| 1046 | local tmpfile="$(emktemp)" |
1076 | local tmpfile=$(emktemp) |
| 1047 | tail -c +$((${tailskip}+1)) ${src} 2>/dev/null | head -c 512 > ${tmpfile} |
1077 | tail -c +$((${tailskip}+1)) ${src} 2>/dev/null | head -c 512 > ${tmpfile} |
| 1048 | |
1078 | |
| 1049 | local iscompressed="`file -b ${tmpfile}`" |
1079 | local iscompressed=$(file -b "${tmpfile}") |
| 1050 | if [ "${iscompressed:0:8}" == "compress" ] ; then |
1080 | if [[ ${iscompressed:0:8} == "compress" ]] ; then |
| 1051 | iscompressed=1 |
1081 | iscompressed=1 |
| 1052 | mv ${tmpfile}{,.Z} |
1082 | mv ${tmpfile}{,.Z} |
| 1053 | gunzip ${tmpfile} |
1083 | gunzip ${tmpfile} |
| 1054 | else |
1084 | else |
| 1055 | iscompressed=0 |
1085 | iscompressed=0 |
| 1056 | fi |
1086 | fi |
| 1057 | local istar="`file -b ${tmpfile}`" |
1087 | local istar=$(file -b "${tmpfile}") |
| 1058 | if [ "${istar:0:9}" == "POSIX tar" ] ; then |
1088 | if [[ ${istar:0:9} == "POSIX tar" ]] ; then |
| 1059 | istar=1 |
1089 | istar=1 |
| 1060 | else |
1090 | else |
| 1061 | istar=0 |
1091 | istar=0 |
| 1062 | fi |
1092 | fi |
| 1063 | |
1093 | |
| … | |
… | |
| 1155 | dd) exe="dd ibs=${skip} skip=1 obs=1024 conv=sync if='${src}'";; |
1185 | dd) exe="dd ibs=${skip} skip=1 obs=1024 conv=sync if='${src}'";; |
| 1156 | *) die "makeself cant handle exe '${exe}'" |
1186 | *) die "makeself cant handle exe '${exe}'" |
| 1157 | esac |
1187 | esac |
| 1158 | |
1188 | |
| 1159 | # lets grab the first few bytes of the file to figure out what kind of archive it is |
1189 | # lets grab the first few bytes of the file to figure out what kind of archive it is |
| 1160 | local tmpfile="$(emktemp)" |
1190 | local tmpfile=$(emktemp) |
| 1161 | eval ${exe} 2>/dev/null | head -c 512 > "${tmpfile}" |
1191 | eval ${exe} 2>/dev/null | head -c 512 > "${tmpfile}" |
| 1162 | local filetype="$(file -b "${tmpfile}")" |
1192 | local filetype=$(file -b "${tmpfile}") |
| 1163 | case ${filetype} in |
1193 | case ${filetype} in |
| 1164 | *tar\ archive*) |
1194 | *tar\ archive*) |
| 1165 | eval ${exe} | tar --no-same-owner -xf - |
1195 | eval ${exe} | tar --no-same-owner -xf - |
| 1166 | ;; |
1196 | ;; |
| 1167 | bzip2*) |
1197 | bzip2*) |
| … | |
… | |
| 1212 | return 0 |
1242 | return 0 |
| 1213 | fi |
1243 | fi |
| 1214 | done |
1244 | done |
| 1215 | set +o noglob; set -$shopts #reset old shell opts |
1245 | set +o noglob; set -$shopts #reset old shell opts |
| 1216 | |
1246 | |
| 1217 | local licmsg="$(emktemp)" |
1247 | local licmsg=$(emktemp) |
| 1218 | cat << EOF > ${licmsg} |
1248 | cat <<-EOF > ${licmsg} |
| 1219 | ********************************************************** |
1249 | ********************************************************** |
| 1220 | The following license outlines the terms of use of this |
1250 | The following license outlines the terms of use of this |
| 1221 | package. You MUST accept this license for installation to |
1251 | package. You MUST accept this license for installation to |
| 1222 | continue. When you are done viewing, hit 'q'. If you |
1252 | continue. When you are done viewing, hit 'q'. If you |
| 1223 | CTRL+C out of this, the install will not run! |
1253 | CTRL+C out of this, the install will not run! |
| 1224 | ********************************************************** |
1254 | ********************************************************** |
| 1225 | |
1255 | |
| 1226 | EOF |
1256 | EOF |
| 1227 | cat ${lic} >> ${licmsg} |
1257 | cat ${lic} >> ${licmsg} |
| 1228 | ${PAGER:-less} ${licmsg} || die "Could not execute pager (${PAGER}) to accept ${lic}" |
1258 | ${PAGER:-less} ${licmsg} || die "Could not execute pager (${PAGER}) to accept ${lic}" |
| 1229 | einfon "Do you accept the terms of this license (${l})? [yes/no] " |
1259 | einfon "Do you accept the terms of this license (${l})? [yes/no] " |
| 1230 | read alic |
1260 | read alic |
| 1231 | case ${alic} in |
1261 | case ${alic} in |
| … | |
… | |
| 1593 | # certain USE flags |
1623 | # certain USE flags |
| 1594 | # |
1624 | # |
| 1595 | # Usage: built_with_use [--missing <action>] [-a|-o] <DEPEND ATOM> <List of USE flags> |
1625 | # Usage: built_with_use [--missing <action>] [-a|-o] <DEPEND ATOM> <List of USE flags> |
| 1596 | # ex: built_with_use xchat gtk2 |
1626 | # ex: built_with_use xchat gtk2 |
| 1597 | # |
1627 | # |
| 1598 | # Flags: -a all USE flags should be utilized |
1628 | # Flags: -a all USE flags should be utilized |
| 1599 | # -o at least one USE flag should be utilized |
1629 | # -o at least one USE flag should be utilized |
| 1600 | # --missing peform the specified action if the flag is not in IUSE (true/false/die) |
1630 | # --missing peform the specified action if the flag is not in IUSE (true/false/die) |
|
|
1631 | # --hidden USE flag we're checking is hidden expanded so it isnt in IUSE |
| 1601 | # Note: the default flag is '-a' |
1632 | # Note: the default flag is '-a' |
| 1602 | built_with_use() { |
1633 | built_with_use() { |
|
|
1634 | local hidden="no" |
|
|
1635 | if [[ $1 == "--hidden" ]] ; then |
|
|
1636 | hidden="yes" |
|
|
1637 | shift |
|
|
1638 | fi |
|
|
1639 | |
| 1603 | local missing_action="die" |
1640 | local missing_action="die" |
| 1604 | if [[ $1 == "--missing" ]] ; then |
1641 | if [[ $1 == "--missing" ]] ; then |
| 1605 | missing_action=$2 |
1642 | missing_action=$2 |
| 1606 | shift ; shift |
1643 | shift ; shift |
| 1607 | case ${missing_action} in |
1644 | case ${missing_action} in |
| … | |
… | |
| 1618 | shift |
1655 | shift |
| 1619 | |
1656 | |
| 1620 | local USEFILE=${ROOT}/var/db/pkg/${PKG}/USE |
1657 | local USEFILE=${ROOT}/var/db/pkg/${PKG}/USE |
| 1621 | local IUSEFILE=${ROOT}/var/db/pkg/${PKG}/IUSE |
1658 | local IUSEFILE=${ROOT}/var/db/pkg/${PKG}/IUSE |
| 1622 | |
1659 | |
| 1623 | # if the USE file doesnt exist, assume the $PKG is either |
1660 | # if the IUSE file doesn't exist, the read will error out, we need to handle |
| 1624 | # injected or package.provided |
1661 | # this gracefully |
|
|
1662 | if [[ ! -e ${USEFILE} ]] || [[ ! -e ${IUSEFILE} && ${hidden} == "no" ]] ; then |
|
|
1663 | case ${missing_action} in |
|
|
1664 | true) return 0;; |
|
|
1665 | false) return 1;; |
| 1625 | [[ ! -e ${USEFILE} ]] && die "Unable to determine what USE flags $PKG was built with" |
1666 | die) die "Unable to determine what USE flags $PKG was built with";; |
|
|
1667 | esac |
|
|
1668 | fi |
| 1626 | |
1669 | |
|
|
1670 | if [[ ${hidden} == "no" ]] ; then |
| 1627 | local IUSE_BUILT=$(<${IUSEFILE}) |
1671 | local IUSE_BUILT=$(<${IUSEFILE}) |
| 1628 | # Don't check USE_EXPAND #147237 |
1672 | # Don't check USE_EXPAND #147237 |
| 1629 | local expand |
1673 | local expand |
| 1630 | for expand in $(echo ${USE_EXPAND} | tr '[:upper:]' '[:lower:]') ; do |
1674 | for expand in $(echo ${USE_EXPAND} | tr '[:upper:]' '[:lower:]') ; do |
| 1631 | if [[ $1 == ${expand}_* ]] ; then |
1675 | if [[ $1 == ${expand}_* ]] ; then |
| 1632 | expand="" |
1676 | expand="" |
| 1633 | break |
1677 | break |
| 1634 | fi |
1678 | fi |
| 1635 | done |
1679 | done |
| 1636 | if [[ -n ${expand} ]] ; then |
1680 | if [[ -n ${expand} ]] ; then |
| 1637 | if ! has $1 ${IUSE_BUILT} ; then |
1681 | if ! has $1 ${IUSE_BUILT} ; then |
| 1638 | case ${missing_action} in |
1682 | case ${missing_action} in |
| 1639 | true) return 0;; |
1683 | true) return 0;; |
| 1640 | false) return 1;; |
1684 | false) return 1;; |
| 1641 | die) die "$PKG does not actually support the $1 USE flag!";; |
1685 | die) die "$PKG does not actually support the $1 USE flag!";; |
| 1642 | esac |
1686 | esac |
|
|
1687 | fi |
| 1643 | fi |
1688 | fi |
| 1644 | fi |
1689 | fi |
| 1645 | |
1690 | |
| 1646 | local USE_BUILT=$(<${USEFILE}) |
1691 | local USE_BUILT=$(<${USEFILE}) |
| 1647 | while [[ $# -gt 0 ]] ; do |
1692 | while [[ $# -gt 0 ]] ; do |