How to pretend to be a tty when trying to freebsd-update from a shell script?

£可爱£侵袭症+ 提交于 2019-12-14 03:12:23

问题


We usually use a custom script to setup new FreeBSD machines after system installation, which installs tools from ports tree and sets up system environment. we also need to automate update newly installed FreeBSD-8.2 machines to FreeBSD-8.2p3 by freebsd-update. As I know, freebsd-update doesn't allow me to execute it from a shell script without a "cron" option. So I try to preload a custom program to cheat freebsd-update:

${CAT} > /tmp/isatty.c     <<EOF                                                                                                                                                                                         
int isatty(const int fd) { return 1; }                                                                                                                                                                               
EOF                                                                                                                                                                                                                  
${CC} -shared -fPIC -o /tmp/isatty.so     /tmp/isatty.c                                                                                                                                                                          
${ENV} LD_PRELOAD=/tmp/isatty.so LESS="-E" ${FREEBSD_UPDATE} fetch install < /dev/null   

with this tweak, I can sucessfully run freebsd-update from my custom script, but after the freebsd-installer fetched files from update server, I got this error message:

Fetching metadata signature for 8.3-RELEASE from update5.FreeBSD.org... done.
Fetching metadata index... done.
Fetching 2 metadata files... gunzip: standard input is a terminal -- ignoring
metadata is corrupt.

Do I have any chance to solve this?


回答1:


You set up your LD_PRELOAD which will also be picked up by any and all processes that freebsd-update spawns. The better solution would be to create a modified version of freebsd-update that would allow you to run it from the command line without requiring user interaction.




回答2:


This utility may be what you need: empty - run processes and applications under pseudo-terminal (PTY)

This way you should be able start freebsd-update from script.



来源:https://stackoverflow.com/questions/10527207/how-to-pretend-to-be-a-tty-when-trying-to-freebsd-update-from-a-shell-script

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!