File:  [ELWIX - Embedded LightWeight unIX -] / elwix / config / rc.subr
Revision 1.10.2.1: download - view: text, annotated - select for diffs - revision graph
Mon Jun 12 08:47:24 2017 UTC (7 years ago) by misho
Branches: elwix2_6
Diff to: branchpoint 1.10: preferred, unified
adds pkg subsystem

    1: #
    2: # ELWIX project build helper subroutines
    3: #
    4: # (C) AITNET ltd - Sofia/Bulgaria <office@aitnet.org>
    5: #    by Michael Pounov <misho@elwix.org>
    6: #
    7: # $Id: rc.subr,v 1.10.2.1 2017/06/12 08:47:24 misho Exp $
    8: #
    9: 
   10: ### Dont edit this file !!!
   11: 
   12: CheckVer()
   13: {
   14: 	[ -z "$1" -o ! -r "$1" ] && return 1
   15: 
   16: 	cat $1 | awk '($1 == "ELWIX") { split($3, arr, ":"); printf("%s", arr[2]); }'
   17: 	return 0
   18: }
   19: 
   20: SnitVer()
   21: {
   22: 	install -d ${TOPDIR}
   23: 
   24: 	V=$(CheckVer $1)
   25: 
   26: 	if [ $? -ne 0 ]; then
   27: # file not found
   28: 		return 1
   29: 	elif [ X"$V" != X"${VERSION}" ]; then
   30: # different ELWIX version
   31: 		return 2
   32: 	fi
   33: 
   34: # already present file with same version
   35: 	return 0
   36: }
   37: 
   38: Create_etc_motd()
   39: {
   40: 	ELWIX_VER="ELWIX-${VERSION}_$2_${TARGET_ARCH}";
   41: 	ELWIX_HDR_MOTD="${ELWIX_VER} :: Build date ${BUILD_DATE}";
   42: 
   43: 	awk -v fo="${1:-motd}" 'BEGIN { print "'"${ELWIX_HDR_MOTD}"'" > fo; } { print $0 >> fo; }' \
   44: 		   ${CFGDIR}/elwix_signature.txt;
   45: }
   46: 
   47: # $1 = fs/elwix
   48: # $2 = config/etc/default
   49: MakeFS_var()
   50: {
   51: 	cd $1
   52: 
   53: 	install -d altroot;
   54: 	install -d altroot/var;
   55: 	install -d altroot/var/account;
   56: 	install -d altroot/var/at;
   57: 	install -d altroot/var/at/jobs;
   58: 	install -d altroot/var/at/spool;
   59: 	install -d -g 63 -m 0770 altroot/var/authpf;
   60: 	install -d -m 0750 altroot/var/cron;
   61: 	install -d -m 0700 altroot/var/cron/tabs;
   62: 	install -d altroot/var/db;
   63: 	install -d -m 0555 altroot/var/empty;
   64: 	install -d altroot/var/log;
   65: 	install -d -o 80 -g 80 -m 0700 altroot/var/log/lighttpd;
   66: 	install -d -o 101 -g 101 altroot/var/log/quagga;
   67: 	install -d -o 883 -g 883 altroot/var/mqtt;
   68: 	install -d altroot/var/frm;
   69: 	install -d altroot/var/pkg;
   70: 	install -d altroot/var/pkg/keys;
   71: 	install -d altroot/var/pkg/keys/revoked;
   72: 	install -d altroot/var/pkg/keys/trusted;
   73: 	install -d altroot/var/run;
   74: 	install -d -o 80 -g 80 altroot/var/run/lighttpd;
   75: 	install -d -o 101 -g 101 altroot/var/run/quagga;
   76: 	install -d altroot/var/spool;
   77: 	install -d -o 66 -g 68 -m 0775 altroot/var/spool/lock;
   78: 	install -d -o 80 -g 80 -m 0775 altroot/var/spool/lighttpd;
   79: 	install -d -o 80 -g 80 altroot/var/spool/lighttpd/sockets;
   80: 	install -d -g 1 altroot/var/spool/lpd;
   81: 	install -d -g 1 altroot/var/spool/output;
   82: 	install -d -g 1 altroot/var/spool/output/lpd;
   83: 	install -d -o 59 -g 59 altroot/var/unbound;
   84: 
   85: 	ln -fs /tmp altroot/var/tmp;
   86: 
   87: 	touch altroot/var/run/utmp
   88: 
   89: 	touch altroot/var/account/acct
   90: 
   91: 	touch altroot/var/log/elwix
   92: 	touch altroot/var/log/lastlog
   93: 	touch altroot/var/log/wifi.log
   94: 	touch altroot/var/log/utx.log
   95: 
   96: 	touch altroot/var/log/auth.log
   97: 	touch altroot/var/log/cron
   98: 	touch altroot/var/log/console.log
   99: 	touch altroot/var/log/debug.log
  100: 	touch altroot/var/log/init.log
  101: 	touch altroot/var/log/lpd-errs
  102: 	touch altroot/var/log/maillog
  103: 	touch altroot/var/log/messages
  104: 	touch altroot/var/log/security
  105: 	touch altroot/var/log/xferlog
  106: 	touch altroot/var/log/ppp.log
  107: 	chgrp 69 altroot/var/log/ppp.log
  108: 
  109: 	install -v $2/resolv.safe altroot/var/run/resolv.conf
  110: 
  111: 	cd -
  112: }
  113: 
  114: # $1 = fs/elwix
  115: # $2 = config/etc/default
  116: # $3 = name
  117: MakeFS_etc()
  118: {
  119: 	InstallDir $2 $1/etc
  120: 
  121: 	chown -R root:wheel $1/etc;
  122: 
  123: 	case "$3" in
  124: 		uboot)
  125: 			;;
  126: 		*)
  127: #			chmod 0600 $1/etc/opieaccess;
  128: #			chmod 0600 $1/etc/opiekeys;
  129: 			;;
  130: 	esac
  131: 
  132: 	chmod 0600 $1/etc/master.passwd;
  133: 	chmod 0600 $1/etc/spwd.db;
  134: 	chmod 0600 $1/etc/ssh/ssh_host_dsa_key;
  135: 	chmod 0600 $1/etc/ssh/ssh_host_key;
  136: 	chmod 0600 $1/etc/ssh/ssh_host_rsa_key;
  137: 	chmod 0600 $1/etc/ssh/ssh_host_ecdsa_key;
  138: 	chmod 0600 $1/etc/ssh/ssh_host_ed25519_key;
  139: 
  140: 	chmod 0440 $1/etc/sudoers;
  141: 
  142: #	chgrp 80 $1/etc/config.xml;
  143: #	chmod 0660 $1/etc/config.xml;
  144: 
  145: 	mkdir -p $1/etc/mqtt;
  146: 	chgrp -R 883 $1/etc/mqtt;
  147: 	chown -R 883 $1/etc/mqtt;
  148: 
  149: 	ln -sf /etc/rc.s $1/etc/rc.S
  150: 
  151: 	ln -sf /usr/share/zoneinfo/${TIMEZONE} $1/etc/localtime;
  152: 	ln -sf /usr/share/misc/termcap $1/etc/termcap;
  153: 
  154: 	ln -sf /var/run/resolv.conf $1/etc/resolv.conf;
  155: 
  156: #	ln -sf /elwix/pkg/etc/mk.conf $1/etc/mk.conf;
  157: 
  158: 	echo ${TARGET_ARCH} >$1/etc/platform;
  159: 
  160: 	Create_etc_motd $1/etc/motd $3;
  161: 
  162: 	CleanCVS $1
  163: 	CleanCVS $1/etc
  164: }
  165: 
  166: # $1 = fs/elwix
  167: MakeFS_home()
  168: {
  169: 	install -d $1/root/.ssh
  170: 	[ -r ${CFGDIR}/root.skel/ssh/authorized_keys2 ] && \
  171: 		install -v ${CFGDIR}/root.skel/ssh/authorized_keys2 $1/root/.ssh;
  172: 
  173: 	install -v ${CFGDIR}/root.skel/cshrc $1/root/.cshrc;
  174: 	install -v ${CFGDIR}/root.skel/login $1/root/.login;
  175: 	install -v ${CFGDIR}/root.skel/logout $1/root/.logout;
  176: 	install -v ${CFGDIR}/root.skel/profile $1/root/.profile;
  177: 	install -v ${CFGDIR}/root.skel/vimrc $1/root/.vimrc;
  178: }
  179: 
  180: # $1 = fs/elwix
  181: MakeFS_backup()
  182: {
  183: 	mkdir -p $1/altroot/backup
  184: 
  185: 	cd $1
  186: #	cp -p etc/config.xml altroot/backup
  187: 	tar -czf altroot/backup/.etc.tgz etc
  188: 
  189: 	cd altroot
  190: 	tar -czf backup/.var.tgz var
  191: }
  192: 
  193: # $1 = fs
  194: MakeFS_boot()
  195: {
  196: 	InstallDir ${WORLD}/boot $1/boot
  197: 
  198: 	install -m 644 ${CFGDIR}/boot/boot.config $1;
  199: 
  200: 	case ${TARGET} in
  201: 		i386|amd64)
  202: 			install -m 444 ${CFGDIR}/boot/logo-elwix.4th $1/boot;
  203: 			install -m 444 ${CFGDIR}/boot/brand-elwix.4th $1/boot;
  204: 			install -m 444 ${CFGDIR}/boot/menu.4th $1/boot;
  205: 			;;
  206: 		*)
  207: 			;;
  208: 	esac
  209: 
  210: 	install -m 444 ${KERNDEVHINTS} $1/boot/device.hints;
  211: 
  212: 	if [ -r ${CFGDIR}/boot/loader_${TARGET_ARCH}.conf ]; then
  213: 		install -m 644 ${CFGDIR}/boot/loader_${TARGET_ARCH}.conf $1/boot/loader.conf;
  214: 	fi;
  215: }
  216: 
  217: # $1 = ELWIX install list config
  218: # $2 = From World dir
  219: # $3 = To Dest dir
  220: InstallList()
  221: {
  222: 	local TMPFILE=$(mktemp -q /tmp/instlist.XXXXXX)
  223: 	if [ $? -ne 0 ]; then
  224: 		echo "Error:: Can't create temp file, exiting..."
  225: 		exit 1
  226: 	fi
  227: 
  228: 	sed -nE -e 's/^ *([^ #]+) */\1/p' < $1 | tr ':' '\n' >$TMPFILE
  229: 	cd $2
  230: 	for i in $(cat $TMPFILE); do
  231: 		if [ -x $i ]; then
  232: 			echo "Strip '$i'"
  233: 			${CEXEC} chflags -f noschg $i
  234: 			${CEXEC} strip -s $i
  235: 		fi
  236: 	done
  237: 	cd -
  238: 	tar -C $2 -cvf - -T $TMPFILE | tar -C $3 -x -f -
  239: 	rm -f $TMPFILE
  240: }
  241: 
  242: # $1 = From dir
  243: # $2 = To dir
  244: InstallDir()
  245: {
  246: 	cd $1
  247: 	pax -rw -pe -X . $2
  248: 	cd -
  249: }
  250: 
  251: # $* = Program arguments for install tool
  252: InstallProg()
  253: {
  254: 	install -c $*
  255: }
  256: 
  257: # $1 = file_pattern
  258: # $2 = From dir
  259: # $3 = To dir
  260: InstallFiles()
  261: {
  262: 	if [ -d "$2" ]; then
  263: 		cd $2
  264: 		find . -type f -name "$1" | 
  265: 			tar -cvf - -T - | tar -C $3 -xf -
  266: 		cd -
  267: 	fi
  268: }
  269: 
  270: # $1 = From dir
  271: # $2 = To dir
  272: InstallLibs()
  273: {
  274: 	${CEXEC} find -X $2 ! -name "*.ko" -and -type f | \
  275: 		xargs readelf -d 2>&- | grep "NEEDED" | sort | uniq | \
  276: 		awk '($2 == "(NEEDED)") { print substr($5, 2, length($5) - 2); }' \
  277: 		2>/dev/null >${DEST}/elwix_mklibs.tmp
  278: 	for i in $(cat ${DEST}/elwix_mklibs.tmp); do
  279: 		echo $i
  280: 		${CEXEC} find $1 -type f -name $i -exec install -v {} $LIBS \\\;
  281: 		${CEXEC} chflags -f noschg $LIBS/$i
  282: 		${CEXEC} strip -s $LIBS/$i
  283: 	done
  284: #	${CEXEC} find -X $2 ! -name "*.ko" -and -type f -and -perm +111 | \
  285: #		xargs ldd -f "%p\n" 2> /dev/null | sort | uniq | \
  286: #		sed 's|^/||' >${DEST}/elwix_mklibs.conf
  287: #	InstallList ${DEST}/elwix_mklibs.conf $1 $2
  288: }
  289: 
  290: # $1 = Directory for clean
  291: CleanCVS()
  292: {
  293: 	find $1 -type d -name CVS -exec rm -rf {} \; >/dev/null 2>&1
  294: 	find $1 -type f -name .#\* -exec rm -f {} \; >/dev/null 2>&1
  295: }
  296: 
  297: # $1 = file_pattern
  298: # $2 = From dir
  299: StripFiles()
  300: {
  301: 	if [ -d "$2" ]; then
  302: 		local TMPFILE=$(mktemp -q /tmp/instlist.XXXXXX)
  303: 		if [ $? -ne 0 ]; then
  304: 			echo "Error:: Can't create temp file, exiting..."
  305: 			exit 1
  306: 		fi
  307: 
  308: 		cd $2
  309: 		find . -type f -name "$1" >$TMPFILE
  310: 		for i in $(cat $TMPFILE); do
  311: 			if [ -x $i ]; then
  312: 				echo "Strip '$i'"
  313: 				${CEXEC} chflags -f noschg $i
  314: 				${CEXEC} strip -s $i
  315: 			fi
  316: 		done
  317: 		cd -
  318: 		rm -f $TMPFILE
  319: 	fi
  320: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>