File:  [ELWIX - Embedded LightWeight unIX -] / elwix / config / rc.subr
Revision 1.10.2.5: download - view: text, annotated - select for diffs - revision graph
Mon Jun 19 20:26:48 2017 UTC (7 years ago) by misho
Branches: elwix2_6
Diff to: branchpoint 1.10: preferred, unified
finish base image

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

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