buildpkg.sh.in 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678
  1. #!/usr/bin/env sh
  2. #
  3. # Fake Root Solaris/SVR4/SVR5 Build System - Prototype
  4. #
  5. # The following code has been provide under Public Domain License. I really
  6. # don't care what you use it for. Just as long as you don't complain to me
  7. # nor my employer if you break it. - Ben Lindstrom (mouring@eviladmin.org)
  8. #
  9. umask 022
  10. #
  11. # Options for building the package
  12. # You can create a openssh-config.local with your customized options
  13. #
  14. REMOVE_FAKE_ROOT_WHEN_DONE=yes
  15. #
  16. # uncommenting TEST_DIR and using
  17. # configure --prefix=/var/tmp --with-privsep-path=/var/tmp/empty
  18. # and
  19. # PKGNAME=tOpenSSH should allow testing a package without interfering
  20. # with a real OpenSSH package on a system. This is not needed on systems
  21. # that support the -R option to pkgadd.
  22. #TEST_DIR=/var/tmp # leave commented out for production build
  23. PKGNAME=OpenSSH
  24. # revisions within the same version (REV=a)
  25. #REV=
  26. SYSVINIT_NAME=opensshd
  27. AWK=${AWK:="nawk"}
  28. MAKE=${MAKE:="make"}
  29. SSHDUID=67 # Default privsep uid
  30. SSHDGID=67 # Default privsep gid
  31. # uncomment these next three as needed
  32. #PERMIT_ROOT_LOGIN=no
  33. #X11_FORWARDING=yes
  34. #USR_LOCAL_IS_SYMLINK=yes
  35. # System V init run levels
  36. SYSVINITSTART=S98
  37. SYSVINITSTOPT=K30
  38. # We will source these if they exist
  39. POST_MAKE_INSTALL_FIXES=./pkg-post-make-install-fixes.sh
  40. POST_PROTOTYPE_EDITS=./pkg-post-prototype-edit.sh
  41. # We'll be one level deeper looking for these
  42. PKG_PREINSTALL_LOCAL=../pkg-preinstall.local
  43. PKG_POSTINSTALL_LOCAL=../pkg-postinstall.local
  44. PKG_PREREMOVE_LOCAL=../pkg-preremove.local
  45. PKG_POSTREMOVE_LOCAL=../pkg-postremove.local
  46. PKG_REQUEST_LOCAL=../pkg-request.local
  47. # end of sourced files
  48. #
  49. OPENSSHD=opensshd.init
  50. OPENSSH_MANIFEST=openssh.xml
  51. OPENSSH_FMRI=svc:/site/${SYSVINIT_NAME}:default
  52. SMF_METHOD_DIR=/lib/svc/method/site
  53. SMF_MANIFEST_DIR=/var/svc/manifest/site
  54. PATH_GROUPADD_PROG=@PATH_GROUPADD_PROG@
  55. PATH_USERADD_PROG=@PATH_USERADD_PROG@
  56. PATH_PASSWD_PROG=@PATH_PASSWD_PROG@
  57. #
  58. # list of system directories we do NOT want to change owner/group/perms
  59. # when installing our package
  60. SYSTEM_DIR="/etc \
  61. /etc/init.d \
  62. /etc/rcS.d \
  63. /etc/rc0.d \
  64. /etc/rc1.d \
  65. /etc/rc2.d \
  66. /etc/opt \
  67. /lib \
  68. /lib/svc \
  69. /lib/svc/method \
  70. /lib/svc/method/site \
  71. /opt \
  72. /opt/bin \
  73. /usr \
  74. /usr/bin \
  75. /usr/lib \
  76. /usr/sbin \
  77. /usr/share \
  78. /usr/share/man \
  79. /usr/share/man/man1 \
  80. /usr/share/man/man8 \
  81. /usr/local \
  82. /usr/local/bin \
  83. /usr/local/etc \
  84. /usr/local/libexec \
  85. /usr/local/man \
  86. /usr/local/man/man1 \
  87. /usr/local/man/man8 \
  88. /usr/local/sbin \
  89. /usr/local/share \
  90. /var \
  91. /var/opt \
  92. /var/run \
  93. /var/svc \
  94. /var/svc/manifest \
  95. /var/svc/manifest/site \
  96. /var/tmp \
  97. /tmp"
  98. # We may need to build as root so we make sure PATH is set up
  99. # only set the path if it's not set already
  100. [ -d /opt/bin ] && {
  101. echo $PATH | grep ":/opt/bin" > /dev/null 2>&1
  102. [ $? -ne 0 ] && PATH=$PATH:/opt/bin
  103. }
  104. [ -d /usr/local/bin ] && {
  105. echo $PATH | grep ":/usr/local/bin" > /dev/null 2>&1
  106. [ $? -ne 0 ] && PATH=$PATH:/usr/local/bin
  107. }
  108. [ -d /usr/ccs/bin ] && {
  109. echo $PATH | grep ":/usr/ccs/bin" > /dev/null 2>&1
  110. [ $? -ne 0 ] && PATH=$PATH:/usr/ccs/bin
  111. }
  112. export PATH
  113. #
  114. [ -f Makefile ] || {
  115. echo "Please run this script from your build directory"
  116. exit 1
  117. }
  118. # we will look for openssh-config.local to override the above options
  119. [ -s ./openssh-config.local ] && . ./openssh-config.local
  120. START=`pwd`
  121. FAKE_ROOT=$START/pkg
  122. ## Fill in some details, like prefix and sysconfdir
  123. for confvar in prefix exec_prefix bindir sbindir libexecdir datadir mandir sysconfdir piddir srcdir
  124. do
  125. eval $confvar=`grep "^$confvar=" Makefile | cut -d = -f 2`
  126. done
  127. ## Are we using Solaris' SMF?
  128. DO_SMF=0
  129. if egrep "^#define USE_SOLARIS_PROCESS_CONTRACTS" config.h > /dev/null 2>&1
  130. then
  131. DO_SMF=1
  132. fi
  133. ## Collect value of privsep user
  134. for confvar in SSH_PRIVSEP_USER
  135. do
  136. eval $confvar=`awk '/#define[ \t]'$confvar'/{print $3}' config.h`
  137. done
  138. ## Set privsep defaults if not defined
  139. if [ -z "$SSH_PRIVSEP_USER" ]
  140. then
  141. SSH_PRIVSEP_USER=sshd
  142. fi
  143. ## Extract common info requires for the 'info' part of the package.
  144. VERSION=`./ssh -V 2>&1 | sed -e 's/,.*//'`
  145. ARCH=`uname -m`
  146. DEF_MSG="\n"
  147. OS_VER=`uname -v`
  148. SCRIPT_SHELL=/sbin/sh
  149. UNAME_R=`uname -r`
  150. UNAME_S=`uname -s`
  151. case ${UNAME_S} in
  152. SunOS) UNAME_S=Solaris
  153. OS_VER=${UNAME_R}
  154. ARCH=`uname -p`
  155. RCS_D=yes
  156. DEF_MSG="(default: n)"
  157. ;;
  158. SCO_SV) case ${UNAME_R} in
  159. 3.2) UNAME_S=OpenServer5
  160. OS_VER=`uname -X | grep Release | sed -e 's/^Rel.*3.2v//'`
  161. ;;
  162. 5) UNAME_S=OpenServer6
  163. ;;
  164. esac
  165. SCRIPT_SHELL=/bin/sh
  166. RC1_D=no
  167. DEF_MSG="(default: n)"
  168. ;;
  169. esac
  170. case `basename $0` in
  171. buildpkg.sh)
  172. ## Start by faking root install
  173. echo "Faking root install..."
  174. [ -d $FAKE_ROOT ] && rm -fr $FAKE_ROOT
  175. mkdir $FAKE_ROOT
  176. ${MAKE} install-nokeys DESTDIR=$FAKE_ROOT
  177. if [ $? -gt 0 ]
  178. then
  179. echo "Fake root install failed, stopping."
  180. exit 1
  181. fi
  182. ## Setup our run level stuff while we are at it.
  183. if [ $DO_SMF -eq 1 ]
  184. then
  185. # For Solaris' SMF, /lib/svc/method/site is the preferred place
  186. # for start/stop scripts that aren't supplied with the OS, and
  187. # similarly /var/svc/manifest/site for manifests.
  188. mkdir -p $FAKE_ROOT${TEST_DIR}${SMF_METHOD_DIR}
  189. mkdir -p $FAKE_ROOT${TEST_DIR}${SMF_MANIFEST_DIR}
  190. cp ${OPENSSHD} $FAKE_ROOT${TEST_DIR}${SMF_METHOD_DIR}/${SYSVINIT_NAME}
  191. chmod 744 $FAKE_ROOT${TEST_DIR}${SMF_METHOD_DIR}/${SYSVINIT_NAME}
  192. cat ${OPENSSH_MANIFEST} | \
  193. sed -e "s|__SYSVINIT_NAME__|${SYSVINIT_NAME}|" \
  194. -e "s|__SMF_METHOD_DIR__|${SMF_METHOD_DIR}|" \
  195. > $FAKE_ROOT${TEST_DIR}${SMF_MANIFEST_DIR}/${SYSVINIT_NAME}.xml
  196. chmod 644 $FAKE_ROOT${TEST_DIR}${SMF_MANIFEST_DIR}/${SYSVINIT_NAME}.xml
  197. else
  198. mkdir -p $FAKE_ROOT${TEST_DIR}/etc/init.d
  199. cp ${OPENSSHD} $FAKE_ROOT${TEST_DIR}/etc/init.d/${SYSVINIT_NAME}
  200. chmod 744 $FAKE_ROOT${TEST_DIR}/etc/init.d/${SYSVINIT_NAME}
  201. fi
  202. [ "${PERMIT_ROOT_LOGIN}" = no ] && \
  203. perl -p -i -e "s/#PermitRootLogin yes/PermitRootLogin no/" \
  204. $FAKE_ROOT${sysconfdir}/sshd_config
  205. [ "${X11_FORWARDING}" = yes ] && \
  206. perl -p -i -e "s/#X11Forwarding no/X11Forwarding yes/" \
  207. $FAKE_ROOT${sysconfdir}/sshd_config
  208. # fix PrintMotd
  209. perl -p -i -e "s/#PrintMotd yes/PrintMotd no/" \
  210. $FAKE_ROOT${sysconfdir}/sshd_config
  211. # We don't want to overwrite config files on multiple installs
  212. mv $FAKE_ROOT${sysconfdir}/ssh_config $FAKE_ROOT${sysconfdir}/ssh_config.default
  213. mv $FAKE_ROOT${sysconfdir}/sshd_config $FAKE_ROOT${sysconfdir}/sshd_config.default
  214. # local tweeks here
  215. [ -s "${POST_MAKE_INSTALL_FIXES}" ] && . ${POST_MAKE_INSTALL_FIXES}
  216. cd $FAKE_ROOT
  217. ## Ok, this is outright wrong, but it will work. I'm tired of pkgmk
  218. ## whining.
  219. for i in *; do
  220. PROTO_ARGS="$PROTO_ARGS $i=/$i";
  221. done
  222. ## Build info file
  223. echo "Building pkginfo file..."
  224. cat > pkginfo << _EOF
  225. PKG=$PKGNAME
  226. NAME="OpenSSH Portable for ${UNAME_S}"
  227. DESC="Secure Shell remote access utility; replaces telnet and rlogin/rsh."
  228. VENDOR="OpenSSH Portable Team - https://www.openssh.com/portable.html"
  229. ARCH=$ARCH
  230. VERSION=$VERSION$REV
  231. CATEGORY="Security,application"
  232. BASEDIR=/
  233. CLASSES="none"
  234. PSTAMP="${UNAME_S} ${OS_VER} ${ARCH} `date '+%d%b%Y %H:%M'`"
  235. _EOF
  236. ## Build empty depend file that may get updated by $POST_PROTOTYPE_EDITS
  237. echo "Building depend file..."
  238. touch depend
  239. ## Build space file
  240. echo "Building space file..."
  241. if [ $DO_SMF -eq 1 ]
  242. then
  243. # XXX Is this necessary? If not, remove space line from mk-proto.awk.
  244. touch space
  245. else
  246. cat > space << _EOF
  247. # extra space required by start/stop links added by installf
  248. # in postinstall
  249. $TEST_DIR/etc/rc0.d/${SYSVINITSTOPT}${SYSVINIT_NAME} 0 1
  250. $TEST_DIR/etc/rc2.d/${SYSVINITSTART}${SYSVINIT_NAME} 0 1
  251. _EOF
  252. [ "$RC1_D" = no ] || \
  253. echo "$TEST_DIR/etc/rc1.d/${SYSVINITSTOPT}${SYSVINIT_NAME} 0 1" >> space
  254. [ "$RCS_D" = yes ] && \
  255. echo "$TEST_DIR/etc/rcS.d/${SYSVINITSTOPT}${SYSVINIT_NAME} 0 1" >> space
  256. fi
  257. ## Build preinstall file
  258. echo "Building preinstall file..."
  259. cat > preinstall << _EOF
  260. #! ${SCRIPT_SHELL}
  261. #
  262. _EOF
  263. # local preinstall changes here
  264. [ -s "${PKG_PREINSTALL_LOCAL}" ] && . ${PKG_PREINSTALL_LOCAL}
  265. cat >> preinstall << _EOF
  266. #
  267. if [ "\${PRE_INS_STOP}" = "yes" ]
  268. then
  269. if [ $DO_SMF -eq 1 ]
  270. then
  271. svcadm disable $OPENSSH_FMRI
  272. else
  273. ${TEST_DIR}/etc/init.d/${SYSVINIT_NAME} stop
  274. fi
  275. fi
  276. exit 0
  277. _EOF
  278. ## Build postinstall file
  279. echo "Building postinstall file..."
  280. cat > postinstall << _EOF
  281. #! ${SCRIPT_SHELL}
  282. #
  283. [ -f \${PKG_INSTALL_ROOT}${sysconfdir}/ssh_config ] || \\
  284. cp -p \${PKG_INSTALL_ROOT}${sysconfdir}/ssh_config.default \\
  285. \${PKG_INSTALL_ROOT}${sysconfdir}/ssh_config
  286. [ -f \${PKG_INSTALL_ROOT}${sysconfdir}/sshd_config ] || \\
  287. cp -p \${PKG_INSTALL_ROOT}${sysconfdir}/sshd_config.default \\
  288. \${PKG_INSTALL_ROOT}${sysconfdir}/sshd_config
  289. # make rc?.d dirs only if we are doing a test install
  290. [ -n "${TEST_DIR}" ] && [ $DO_SMF -ne 1 ] && {
  291. [ "$RCS_D" = yes ] && mkdir -p ${TEST_DIR}/etc/rcS.d
  292. mkdir -p ${TEST_DIR}/etc/rc0.d
  293. [ "$RC1_D" = no ] || mkdir -p ${TEST_DIR}/etc/rc1.d
  294. mkdir -p ${TEST_DIR}/etc/rc2.d
  295. }
  296. if [ $DO_SMF -eq 1 ]
  297. then
  298. # Delete the existing service, if it exists, then import the
  299. # new one.
  300. if svcs $OPENSSH_FMRI > /dev/null 2>&1
  301. then
  302. svccfg delete -f $OPENSSH_FMRI
  303. fi
  304. # NOTE, The manifest disables sshd by default.
  305. svccfg import ${TEST_DIR}${SMF_MANIFEST_DIR}/${SYSVINIT_NAME}.xml
  306. else
  307. if [ "\${USE_SYM_LINKS}" = yes ]
  308. then
  309. [ "$RCS_D" = yes ] && \\
  310. installf ${PKGNAME} \${PKG_INSTALL_ROOT}$TEST_DIR/etc/rcS.d/${SYSVINITSTOPT}${SYSVINIT_NAME}=../init.d/${SYSVINIT_NAME} s
  311. installf ${PKGNAME} \${PKG_INSTALL_ROOT}$TEST_DIR/etc/rc0.d/${SYSVINITSTOPT}${SYSVINIT_NAME}=../init.d/${SYSVINIT_NAME} s
  312. [ "$RC1_D" = no ] || \\
  313. installf ${PKGNAME} \${PKG_INSTALL_ROOT}$TEST_DIR/etc/rc1.d/${SYSVINITSTOPT}${SYSVINIT_NAME}=../init.d/${SYSVINIT_NAME} s
  314. installf ${PKGNAME} \${PKG_INSTALL_ROOT}$TEST_DIR/etc/rc2.d/${SYSVINITSTART}${SYSVINIT_NAME}=../init.d/${SYSVINIT_NAME} s
  315. else
  316. [ "$RCS_D" = yes ] && \\
  317. installf ${PKGNAME} \${PKG_INSTALL_ROOT}$TEST_DIR/etc/rcS.d/${SYSVINITSTOPT}${SYSVINIT_NAME}=\${PKG_INSTALL_ROOT}$TEST_DIR/etc/init.d/${SYSVINIT_NAME} l
  318. installf ${PKGNAME} \${PKG_INSTALL_ROOT}$TEST_DIR/etc/rc0.d/${SYSVINITSTOPT}${SYSVINIT_NAME}=\${PKG_INSTALL_ROOT}$TEST_DIR/etc/init.d/${SYSVINIT_NAME} l
  319. [ "$RC1_D" = no ] || \\
  320. installf ${PKGNAME} \${PKG_INSTALL_ROOT}$TEST_DIR/etc/rc1.d/${SYSVINITSTOPT}${SYSVINIT_NAME}=\${PKG_INSTALL_ROOT}$TEST_DIR/etc/init.d/${SYSVINIT_NAME} l
  321. installf ${PKGNAME} \${PKG_INSTALL_ROOT}$TEST_DIR/etc/rc2.d/${SYSVINITSTART}${SYSVINIT_NAME}=\${PKG_INSTALL_ROOT}$TEST_DIR/etc/init.d/${SYSVINIT_NAME} l
  322. fi
  323. fi
  324. # If piddir doesn't exist we add it. (Ie. --with-pid-dir=/var/opt/ssh)
  325. [ -d $piddir ] || installf ${PKGNAME} \${PKG_INSTALL_ROOT}$TEST_DIR$piddir d 0755 root sys
  326. _EOF
  327. # local postinstall changes here
  328. [ -s "${PKG_POSTINSTALL_LOCAL}" ] && . ${PKG_POSTINSTALL_LOCAL}
  329. cat >> postinstall << _EOF
  330. installf -f ${PKGNAME}
  331. # Use chroot to handle PKG_INSTALL_ROOT
  332. if [ ! -z "\${PKG_INSTALL_ROOT}" ]
  333. then
  334. chroot="chroot \${PKG_INSTALL_ROOT}"
  335. fi
  336. # If this is a test build, we will skip the groupadd/useradd/passwd commands
  337. if [ ! -z "${TEST_DIR}" ]
  338. then
  339. chroot=echo
  340. fi
  341. echo "PrivilegeSeparation user always required."
  342. if cut -f1 -d: \${PKG_INSTALL_ROOT}/etc/passwd | egrep '^'$SSH_PRIVSEP_USER'\$' >/dev/null
  343. then
  344. echo "PrivSep user $SSH_PRIVSEP_USER already exists."
  345. SSH_PRIVSEP_GROUP=\`grep "^$SSH_PRIVSEP_USER:" \${PKG_INSTALL_ROOT}/etc/passwd | awk -F: '{print \$4}'\`
  346. SSH_PRIVSEP_GROUP=\`grep ":\$SSH_PRIVSEP_GROUP:" \${PKG_INSTALL_ROOT}/etc/group | awk -F: '{print \$1}'\`
  347. else
  348. DO_PASSWD=yes
  349. fi
  350. [ -z "\$SSH_PRIVSEP_GROUP" ] && SSH_PRIVSEP_GROUP=$SSH_PRIVSEP_USER
  351. # group required?
  352. if cut -f1 -d: \${PKG_INSTALL_ROOT}/etc/group | egrep '^'\$SSH_PRIVSEP_GROUP'\$' >/dev/null
  353. then
  354. echo "PrivSep group \$SSH_PRIVSEP_GROUP already exists."
  355. else
  356. DO_GROUP=yes
  357. fi
  358. # create group if required
  359. [ "\$DO_GROUP" = yes ] && {
  360. # Use gid of 67 if possible
  361. if cut -f3 -d: \${PKG_INSTALL_ROOT}/etc/group | egrep '^'$SSHDGID'\$' >/dev/null
  362. then
  363. :
  364. else
  365. sshdgid="-g $SSHDGID"
  366. fi
  367. echo "Creating PrivSep group \$SSH_PRIVSEP_GROUP."
  368. \$chroot ${PATH_GROUPADD_PROG} \$sshdgid \$SSH_PRIVSEP_GROUP
  369. }
  370. # Create user if required
  371. [ "\$DO_PASSWD" = yes ] && {
  372. # Use uid of 67 if possible
  373. if cut -f3 -d: \${PKG_INSTALL_ROOT}/etc/passwd | egrep '^'$SSHDUID'\$' >/dev/null
  374. then
  375. :
  376. else
  377. sshduid="-u $SSHDUID"
  378. fi
  379. echo "Creating PrivSep user $SSH_PRIVSEP_USER."
  380. \$chroot ${PATH_USERADD_PROG} -c 'SSHD PrivSep User' -s /bin/false -g $SSH_PRIVSEP_USER \$sshduid $SSH_PRIVSEP_USER
  381. \$chroot ${PATH_PASSWD_PROG} -l $SSH_PRIVSEP_USER
  382. }
  383. if [ "\${POST_INS_START}" = "yes" ]
  384. then
  385. if [ $DO_SMF -eq 1 ]
  386. then
  387. svcadm enable $OPENSSH_FMRI
  388. else
  389. ${TEST_DIR}/etc/init.d/${SYSVINIT_NAME} start
  390. fi
  391. fi
  392. exit 0
  393. _EOF
  394. ## Build preremove file
  395. echo "Building preremove file..."
  396. cat > preremove << _EOF
  397. #! ${SCRIPT_SHELL}
  398. #
  399. if [ $DO_SMF -eq 1 ]
  400. then
  401. svcadm disable $OPENSSH_FMRI
  402. else
  403. ${TEST_DIR}/etc/init.d/${SYSVINIT_NAME} stop
  404. fi
  405. _EOF
  406. # local preremove changes here
  407. [ -s "${PKG_PREREMOVE_LOCAL}" ] && . ${PKG_PREREMOVE_LOCAL}
  408. cat >> preremove << _EOF
  409. exit 0
  410. _EOF
  411. ## Build postremove file
  412. echo "Building postremove file..."
  413. cat > postremove << _EOF
  414. #! ${SCRIPT_SHELL}
  415. #
  416. if [ $DO_SMF -eq 1 ]
  417. then
  418. if svcs $OPENSSH_FMRI > /dev/null 2>&1
  419. then
  420. svccfg delete -f $OPENSSH_FMRI
  421. fi
  422. fi
  423. _EOF
  424. # local postremove changes here
  425. [ -s "${PKG_POSTREMOVE_LOCAL}" ] && . ${PKG_POSTREMOVE_LOCAL}
  426. cat >> postremove << _EOF
  427. exit 0
  428. _EOF
  429. ## Build request file
  430. echo "Building request file..."
  431. cat > request << _EOF
  432. trap 'exit 3' 15
  433. _EOF
  434. [ -x /usr/bin/ckyorn ] || cat >> request << _EOF
  435. ckyorn() {
  436. # for some strange reason OpenServer5 has no ckyorn
  437. # We build a striped down version here
  438. DEFAULT=n
  439. PROMPT="Yes or No [yes,no,?,quit]"
  440. HELP_PROMPT=" Enter y or yes if your answer is yes; n or no if your answer is no."
  441. USAGE="usage: ckyorn [options]
  442. where options may include:
  443. -d default
  444. -h help
  445. -p prompt
  446. "
  447. if [ \$# != 0 ]
  448. then
  449. while getopts d:p:h: c
  450. do
  451. case \$c in
  452. h) HELP_PROMPT="\$OPTARG" ;;
  453. d) DEFAULT=\$OPTARG ;;
  454. p) PROMPT=\$OPTARG ;;
  455. \\?) echo "\$USAGE" 1>&2
  456. exit 1 ;;
  457. esac
  458. done
  459. shift \`expr \$OPTIND - 1\`
  460. fi
  461. while true
  462. do
  463. echo "\${PROMPT}\\c " 1>&2
  464. read key
  465. [ -z "\$key" ] && key=\$DEFAULT
  466. case \$key in
  467. [n,N]|[n,N][o,O]|[y,Y]|[y,Y][e,E][s,S]) echo "\${key}\\c"
  468. exit 0 ;;
  469. \\?) echo \$HELP_PROMPT 1>&2 ;;
  470. q|quit) echo "q\\c" 1>&2
  471. exit 3 ;;
  472. esac
  473. done
  474. }
  475. _EOF
  476. if [ $DO_SMF -eq 1 ]
  477. then
  478. # This could get hairy, as the running sshd may not be under SMF.
  479. # We'll assume an earlier version of OpenSSH started via SMF.
  480. cat >> request << _EOF
  481. PRE_INS_STOP=no
  482. POST_INS_START=no
  483. # determine if should restart the daemon
  484. if [ -s ${piddir}/sshd.pid ] && \\
  485. /usr/bin/svcs -H $OPENSSH_FMRI 2>&1 | egrep "^online" > /dev/null 2>&1
  486. then
  487. ans=\`ckyorn -d n \\
  488. -p "Should the running sshd daemon be restarted? ${DEF_MSG}"\` || exit \$?
  489. case \$ans in
  490. [y,Y]*) PRE_INS_STOP=yes
  491. POST_INS_START=yes
  492. ;;
  493. esac
  494. else
  495. # determine if we should start sshd
  496. ans=\`ckyorn -d n \\
  497. -p "Start the sshd daemon after installing this package? ${DEF_MSG}"\` || exit \$?
  498. case \$ans in
  499. [y,Y]*) POST_INS_START=yes ;;
  500. esac
  501. fi
  502. # make parameters available to installation service,
  503. # and so to any other packaging scripts
  504. cat >\$1 <<!
  505. PRE_INS_STOP='\$PRE_INS_STOP'
  506. POST_INS_START='\$POST_INS_START'
  507. !
  508. _EOF
  509. else
  510. cat >> request << _EOF
  511. USE_SYM_LINKS=no
  512. PRE_INS_STOP=no
  513. POST_INS_START=no
  514. # Use symbolic links?
  515. ans=\`ckyorn -d n \\
  516. -p "Do you want symbolic links for the start/stop scripts? ${DEF_MSG}"\` || exit \$?
  517. case \$ans in
  518. [y,Y]*) USE_SYM_LINKS=yes ;;
  519. esac
  520. # determine if should restart the daemon
  521. if [ -s ${piddir}/sshd.pid -a -f ${TEST_DIR}/etc/init.d/${SYSVINIT_NAME} ]
  522. then
  523. ans=\`ckyorn -d n \\
  524. -p "Should the running sshd daemon be restarted? ${DEF_MSG}"\` || exit \$?
  525. case \$ans in
  526. [y,Y]*) PRE_INS_STOP=yes
  527. POST_INS_START=yes
  528. ;;
  529. esac
  530. else
  531. # determine if we should start sshd
  532. ans=\`ckyorn -d n \\
  533. -p "Start the sshd daemon after installing this package? ${DEF_MSG}"\` || exit \$?
  534. case \$ans in
  535. [y,Y]*) POST_INS_START=yes ;;
  536. esac
  537. fi
  538. # make parameters available to installation service,
  539. # and so to any other packaging scripts
  540. cat >\$1 <<!
  541. USE_SYM_LINKS='\$USE_SYM_LINKS'
  542. PRE_INS_STOP='\$PRE_INS_STOP'
  543. POST_INS_START='\$POST_INS_START'
  544. !
  545. _EOF
  546. fi
  547. # local request changes here
  548. [ -s "${PKG_REQUEST_LOCAL}" ] && . ${PKG_REQUEST_LOCAL}
  549. cat >> request << _EOF
  550. exit 0
  551. _EOF
  552. ## Next Build our prototype
  553. echo "Building prototype file..."
  554. cat >mk-proto.awk << _EOF
  555. BEGIN { print "i pkginfo"; print "i depend"; \\
  556. print "i preinstall"; print "i postinstall"; \\
  557. print "i preremove"; print "i postremove"; \\
  558. print "i request"; print "i space"; \\
  559. split("$SYSTEM_DIR",sys_files); }
  560. {
  561. for (dir in sys_files) { if ( \$3 != sys_files[dir] )
  562. { if ( \$1 == "s" )
  563. { \$5=""; \$6=""; }
  564. else
  565. { \$5="root"; \$6="sys"; }
  566. }
  567. else
  568. { \$4="?"; \$5="?"; \$6="?"; break;}
  569. } }
  570. { print; }
  571. _EOF
  572. find . | egrep -v "prototype|pkginfo|mk-proto.awk" | sort | \
  573. pkgproto $PROTO_ARGS | ${AWK} -f mk-proto.awk > prototype
  574. # /usr/local is a symlink on some systems
  575. [ "${USR_LOCAL_IS_SYMLINK}" = yes ] && {
  576. grep -v "^d none /usr/local ? ? ?$" prototype > prototype.new
  577. mv prototype.new prototype
  578. }
  579. ## Step back a directory and now build the package.
  580. cd ..
  581. # local prototype tweeks here
  582. [ -s "${POST_PROTOTYPE_EDITS}" ] && . ${POST_PROTOTYPE_EDITS}
  583. echo "Building package.."
  584. pkgmk -d ${FAKE_ROOT} -f $FAKE_ROOT/prototype -o
  585. echo | pkgtrans -os ${FAKE_ROOT} ${START}/$PKGNAME-$VERSION$REV-$UNAME_S-$ARCH.pkg
  586. ;;
  587. justpkg.sh)
  588. rm -fr ${FAKE_ROOT}/${PKGNAME}
  589. grep -v "^PSTAMP=" $FAKE_ROOT/pkginfo > $$tmp
  590. mv $$tmp $FAKE_ROOT/pkginfo
  591. cat >> $FAKE_ROOT/pkginfo << _EOF
  592. PSTAMP="${UNAME_S} ${OS_VER} ${ARCH} `date '+%d%b%Y %H:%M'`"
  593. _EOF
  594. pkgmk -d ${FAKE_ROOT} -f $FAKE_ROOT/prototype -o
  595. echo | pkgtrans -os ${FAKE_ROOT} ${START}/$PKGNAME-$VERSION$REV-$UNAME_S-$ARCH.pkg
  596. ;;
  597. esac
  598. [ "${REMOVE_FAKE_ROOT_WHEN_DONE}" = yes ] && rm -rf $FAKE_ROOT
  599. exit 0