Fixup fromcvs/togit conversion
[pkgsrcv2.git] / emulators / compat_netbsd / INSTALL.ELF
1 # $NetBSD: INSTALL.ELF,v 1.1 2007/08/21 22:49:24 jlam Exp $
2
3 # Generate a +ROOT_ACTIONS script that runs certain actions that require
4 # superuser privileges.
5 #
6 case "${STAGE},$1" in
7 UNPACK,|UNPACK,+ROOT_ACTIONS)
8         ${CAT} > ./+ROOT_ACTIONS << 'EOF'
9 #!@SH@
10 #
11 # +ROOT_ACTIONS - run actions requiring superuser privileges
12 #
13 # Usage: ./+ROOT_ACTIONS ADD|REMOVE [metadatadir]
14 #
15 # This script runs certain actions that require superuser privileges.
16 # If such privileges are not available, then simply output a message
17 # asking the user to run this script with the appropriate elevated
18 # privileges.
19 #
20 # Lines starting with "# SYMLINK: " are data read by this script that
21 # name the source paths and corresponding symlink that is managed by
22 # this script.  If the symlink path is relative, then it is taken to be
23 # relative to ${PKG_PREFIX}.  The source path is always unchanged.
24 #
25 #       # SYMLINK: /dev/rcd0a ${EMULSUBDIR}/dev/cdrom
26 #
27
28 CAT="@CAT@"
29 CHMOD="@CHMOD@"
30 ECHO="@ECHO@"
31 ID="@ID@"
32 LN="@LN@"
33 PWD_CMD="@PWD_CMD@"
34 RM="@RM@"
35 SED="@SED@"
36 TEST="@TEST@"
37
38 SELF=$0
39 ACTION=$1
40
41 CURDIR=`${PWD_CMD}`
42 PKG_METADATA_DIR="${2-${CURDIR}}"
43 : ${PKGNAME=${PKG_METADATA_DIR##*/}}
44 : ${PKG_PREFIX=@PREFIX@}
45
46 ROOT_ACTIONS_COOKIE="./+ROOT_ACTIONS_done"
47 EUID=`${ID} -u`
48
49 exitcode=0
50 case $ACTION,$EUID in
51 ADD,0)
52         ${ECHO} "" > ${ROOT_ACTIONS_COOKIE}
53         ${CHMOD} g+w ${ROOT_ACTIONS_COOKIE}
54         ${SED} -n "/^\# SYMLINK: /{s/^\# SYMLINK: //;p;}" ${SELF} |
55         while read src dst; do
56                 case $src in
57                 "")     continue ;;
58                 [!/]*)  src="${PKG_PREFIX}/$src" ;;
59                 esac
60                 case $dst in
61                 "")     continue ;;
62                 [!/]*)  dst="${PKG_PREFIX}/$dst" ;;
63                 esac
64
65                 if ${TEST} ! -f "$dst"; then
66                         ${ECHO} "${PKGNAME}: linking $dst -> $src"
67                         ${LN} -fs "$src" "$dst"
68                 else
69                         ${ECHO} "${PKGNAME}: $dst already exists"
70                 fi
71         done
72         ;;
73
74 REMOVE,0)
75         ${SED} -n "/^\# SYMLINK: /{s/^\# SYMLINK: //;p;}" ${SELF} |
76         while read src dst; do
77                 case $src in
78                 "")     continue ;;
79                 esac
80                 case $dst in
81                 "")     continue ;;
82                 [!/]*)  dst="${PKG_PREFIX}/$dst" ;;
83                 esac
84
85                 if ${TEST} -h "$dst"; then
86                         ${ECHO} "${PKGNAME}: removing $dst"
87                         ${RM} -f "$dst"
88                 fi
89         done
90         ${RM} -f ${ROOT_ACTIONS_COOKIE}
91         ;;
92
93 ADD,*)
94         if ${TEST} ! -f ${ROOT_ACTIONS_COOKIE}; then
95                 ${CAT} << EOM
96 ==============================================================================
97 Please run the following command with superuser privileges to complete
98 the installation of ${PKGNAME}:
99
100     cd ${PKG_METADATA_DIR} && ${SELF} ADD
101
102 ==============================================================================
103 EOM
104         fi
105         ;;
106
107 REMOVE,*)
108         if ${TEST} -f ${ROOT_ACTIONS_COOKIE}; then
109                 ${CAT} << EOM
110 ==============================================================================
111 Please run the following command with superuser privileges to begin the
112 removal of ${PKGNAME}:
113
114     cd ${PKG_METADATA_DIR} && ${SELF} REMOVE
115
116 Then, please run pkg_delete(1) again to complete the removal of this
117 package.
118
119 ==============================================================================
120 EOM
121                 exitcode=1
122         fi
123         ;;
124 esac
125 exit $exitcode
126
127 EOF
128         ${SED} -n "/^\# SYMLINK: /p" ${SELF} >> ./+ROOT_ACTIONS
129         ${CHMOD} +x ./+ROOT_ACTIONS
130         ;;
131 esac
132
133 case "${STAGE}" in
134 POST-INSTALL)
135         ${TEST} ! -x ./+ROOT_ACTIONS ||
136                 ./+ROOT_ACTIONS ADD ${PKG_METADATA_DIR}
137         ;;
138 esac