Annotation of elwix/config/rc.subr, revision 1.12

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

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