File:  [ELWIX - Embedded LightWeight unIX -] / elwix / config / rc.subr
Revision 1.8.2.1: download - view: text, annotated - select for diffs - revision graph
Tue Jan 14 23:38:26 2014 UTC (10 years, 5 months ago) by misho
Branches: elwix2_2
Diff to: branchpoint 1.8: preferred, unified
fixed base.fs

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

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