diff --git a/UpdateRootfs.sh.in b/UpdateRootfs.sh.in index 89ff561..3e4b29d 100644 --- a/UpdateRootfs.sh.in +++ b/UpdateRootfs.sh.in @@ -4,7 +4,7 @@ uuencode=0 binary=1 ##TAR_PARAMETERS="-C / --exclude=./opt --exclude=./etc/inittab -xzvf -" -TMP_PATH="/__GfA_Update" +TMP_PATH="$GFA_PREFIX/__GfA_Update" TAR_PARAMETERS="-C $TMP_PATH -xzvf -" untar_payload () @@ -25,6 +25,131 @@ untar_payload () fi } +if [ -z $1 ] +then +## prepare for chrooted environment +chmod +x /bin/bash +updatename=`realpath $0` +echo -e "===\n prepare chroot and update script\n===\n" +(\ +cat << EOF +#! /bin/bash +CHROOT=/__GfA_chroot + +#--------------------- +recurse () +# Param 1 is the nuumber of spaces that the output will be prepended with +# Param 2 full path to library +{ +#Use 'readelf -d' to find dependencies +dependencies=\$(readelf -d \${2} | grep NEEDED | awk '{ print \$5 }' | tr -d '[]') +for d in \$dependencies; do + echo "\${1}\${d} :: \${2}" + rsync -lpR \${2} \${CHROOT} + if [ -L \${2} ] ; then + LIBNAM=\`readlink -f \${2}\` + rsync -lpR \${LIBNAM} \${CHROOT} + echo "\${1}-->\${LIBNAM}" + fi + nm=\${d##*/} + #libstdc++ hack for the '+'-s + nm1=\${nm//"+"/"\+"} + # /lib /lib64 /usr/lib and /usr/lib are searched + children=\$(find / -name \${d} 2>/dev/null | grep -E "(^/(lib|lib32|usr/lib|usr/lib32)/\${nm1})") + rc=\$? + #at least locate... didn't fail + if [ \${rc} == "0" ] ; then + #we have at least one dependency + if [ \${#children[@]} -gt 0 ]; then + #check the dependeny's dependencies + for c in \$children; do + recurse " \${1}" \${c} + done + else + echo "\${1}no children found" + fi + else + echo "\${1}locate failed for ${d}" + fi +done +} +# -- recurse needs 2 params could/should be supplied from cmdline +echo "==== PREPARE CHROOT ENVIRONMENT in \${CHROOT} ====" +rm -rf \$CHROOT +mkdir -p \$CHROOT +#------------------------------------ +tt=/bin/bash +echo -e "===\n \$tt\n" +recurse "" \$tt + +tt=/bin/sh +echo -e "===\n \$tt\n" +recurse "" \$tt + +tt=/bin/busybox +echo -e "===\n \$tt\n" +recurse "" \$tt + +tt=/usr/sbin/fbset +echo -e "===\n \$tt\n" +recurse "" \$tt + +tt=/usr/bin/awk +echo -e "===\n \$tt\n" +recurse "" \$tt + +tt=/usr/bin/cut +echo -e "===\n \$tt\n" +recurse "" \$tt + +tt=/usr/bin/tail +echo -e "===\n \$tt\n" +recurse "" \$tt + +tt=/sbin/reboot +echo -e "===\n \$tt\n" +recurse "" \$tt + +#---------------------------------------- +cp -a /lib/ld-* \${CHROOT}/lib +cp -a /bin/* \${CHROOT}/bin + +ln -s ./realroot/root \${CHROOT}/root + +mkdir -p \${CHROOT}/proc +mkdir -p \${CHROOT}/dev +mkdir -p \${CHROOT}/sys +mkdir -p \${CHROOT}/etc +mkdir -p \${CHROOT}/realroot +mkdir -p \${CHROOT}/var +mkdir -p \${CHROOT}/tmp +mkdir -p \${CHROOT}/mnt + +mkdir -p \${CHROOT}/realroot/media/usb0 +mkdir -p \${CHROOT}/realroot/media/usb1 + +mount -o bind /proc \${CHROOT}/proc +mount -o bind /dev \${CHROOT}/dev +mount -o bind /sys \${CHROOT}/sys +mount -o bind /etc \${CHROOT}/etc +mount -o bind /var \${CHROOT}/var +mount -o bind /tmp \${CHROOT}/tmp +mount -o bind / \${CHROOT}/realroot + +mount -o bind /media/usb0 \${CHROOT}/realroot/media/usb0 +mount -o bind /media/usb1 \${CHROOT}/realroot/media/usb1 + +echo -e "\n===========\nchroot environment ready in \n \${CHROOT}\n===========\n" +chroot \${CHROOT} sh -c 'GFA_PREFIX=/realroot sh /realroot${updatename} DoRealUpdate' + +EOF +) > /root/GfA_prep_chroot.sh + +chmod a+x /root/GfA_prep_chroot.sh +#--- execute built script +echo "==>>> execute chroot update script" +/root/GfA_prep_chroot.sh +else ## --- Kommandos zum Installieren ## -- get bootpartition such="root=/dev/mmcblk1" @@ -54,26 +179,26 @@ cp $TMP_PATH/*.dtb /mnt mkdir -p $TMP_PATH/bu_cfg -if [ -e /etc/network/interfaces ] +if [ -e $GFA_PREFIX/etc/network/interfaces ] then - cp /etc/network/interfaces $TMP_PATH/bu_cfg - rm /etc/network/interfaces + cp $GFA_PREFIX/etc/network/interfaces $TMP_PATH/bu_cfg + rm $GFA_PREFIX/etc/network/interfaces fi -if [ -e /etc/wpa_supplicant.conf ] +if [ -e $GFA_PREFIX/etc/wpa_supplicant.conf ] then - cp /etc/wpa_supplicant.conf $TMP_PATH/bu_cfg/wpa_supplicant.conf_old - rm /etc/wpa_supplicant.conf + cp $GFA_PREFIX/etc/wpa_supplicant.conf $TMP_PATH/bu_cfg/wpa_supplicant.conf_old + rm $GFA_PREFIX/etc/wpa_supplicant.conf fi -if [ -e /etc/wpa_supplicant/wpa_supplicant.conf ] +if [ -e $GFA_PREFIX/etc/wpa_supplicant/wpa_supplicant.conf ] then - cp /etc/wpa_supplicant/wpa_supplicant.conf $TMP_PATH/bu_cfg - rm /etc/wpa_supplicant/wpa_supplicant.conf + cp $GFA_PREFIX/etc/wpa_supplicant/wpa_supplicant.conf $TMP_PATH/bu_cfg + rm $GFA_PREFIX/etc/wpa_supplicant/wpa_supplicant.conf fi #rootfs auspacken -tar -C / --exclude=./tmp --exclude=./etc/inittab \ +tar -C $GFA_PREFIX/ --exclude=./tmp --exclude=./etc/inittab \ --exclude=./etc/hosts --exclude=./etc/hostname \ --exclude=./etc/passwd --exclude=./etc/shadow \ --exclude=./etc/vncpwd --exclude=./etc/init.d/S99tincd \ @@ -97,10 +222,10 @@ auto lo iface lo inet loopback EOF -) > /etc/network/interfaces +) > $GFA_PREFIX/etc/network/interfaces awk -v par=$INTERFACE '/^iface/ && $2==par {f=1}/^iface/ && $2!=par {f=0}f && !/^\s*#/d && !/^\s*$/d {print $0 }' $TMP_PATH/bu_cfg/interfaces \ ->> /etc/network/interfaces +>> $GFA_PREFIX/etc/network/interfaces (\ cat << EOF @@ -114,52 +239,52 @@ iface wlan0 inet dhcp wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf # EOF -) >> /etc/network/interfaces +) >> $GFA_PREFIX/etc/network/interfaces -if [ -e /etc/init.d/S98usb_g_ether ] +if [ -e $GFA_PREFIX/etc/init.d/S98usb_g_ether ] then - cp /etc/init.d/S98usb_g_ether /etc/init.d/M98usb_g_ether - rm /etc/init.d/S98usb_g_ether + cp $GFA_PREFIX/etc/init.d/S98usb_g_ether $GFA_PREFIX/etc/init.d/M98usb_g_ether + rm $GFA_PREFIX/etc/init.d/S98usb_g_ether fi -if [ -e /etc/init.d/S80ti-sgx ] +if [ -e $GFA_PREFIX/etc/init.d/S80ti-sgx ] then - rm /etc/init.d/S80ti-sgx + rm $GFA_PREFIX/etc/init.d/S80ti-sgx fi -if [ -e /etc/init.d/M99_wlan_usb ] +if [ -e $GFA_PREFIX/etc/init.d/M99_wlan_usb ] then - rm /etc/init.d/M99_wlan_usb + rm $GFA_PREFIX/etc/init.d/M99_wlan_usb fi -if [ -e /etc/init.d/S99_wlan_usb ] +if [ -e $GFA_PREFIX/etc/init.d/S99_wlan_usb ] then - rm /etc/init.d/S99_wlan_usb + rm $GFA_PREFIX/etc/init.d/S99_wlan_usb fi -if [ -e /etc/init.d/M80dhcp-relay ] +if [ -e $GFA_PREFIX/etc/init.d/M80dhcp-relay ] then - rm /etc/init.d/M80dhcp-relay + rm $GFA_PREFIX/etc/init.d/M80dhcp-relay fi -if [ -e /etc/init.d/S80dhcp-relay ] +if [ -e $GFA_PREFIX/etc/init.d/S80dhcp-relay ] then - rm /etc/init.d/S80dhcp-relay + rm $GFA_PREFIX/etc/init.d/S80dhcp-relay fi -if [ -e /etc/init.d/M80dhcp-server ] +if [ -e $GFA_PREFIX/etc/init.d/M80dhcp-server ] then - rm /etc/init.d/M80dhcp-server + rm $GFA_PREFIX/etc/init.d/M80dhcp-server fi -if [ -e /etc/init.d/S80dhcp-server ] +if [ -e $GFA_PREFIX/etc/init.d/S80dhcp-server ] then - rm /etc/init.d/S80dhcp-server + rm $GFA_PREFIX/etc/init.d/S80dhcp-server fi -if [ -d /etc/dhcp ] +if [ -d $GFA_PREFIX/etc/dhcp ] then - rm -rf /etc/dhcp + rm -rf $GFA_PREFIX/etc/dhcp fi #echo "Update Firmware" @@ -170,7 +295,7 @@ fi #/root/gfa_spi -v #================================ #--create mountable run folder insted of link -RUNDIR=/run +RUNDIR=$GFA_PREFIX/run if [ -L $RUNDIR ]; then mv $RUNDIR $RUNDIR'_WRK' mkdir $RUNDIR @@ -182,28 +307,29 @@ if [ -L $RUNDIR ]; then rm $RUNDIR'_WRK' fi #--- craete missing nogroup group -GID_NOGROUP=`awk -F\: '/nogroup/ {print $3}' /etc/group` +GID_NOGROUP=`awk -F\: '/nogroup/ {print $3}' $GFA_PREFIX/etc/group` if [ -z "$GID_NOGROUP" ]; then - addgroup -S -g 65534 nogroup +# addgroup -S -g 65534 nogroup + echo "nogroup:x:65534:" >> $GFA_PREFIX/etc/group fi #--create missing users for mysql, -if [ -z `awk -F\: '/mysql/ {print $3}' /etc/passwd` ]; then - UID_MY=`awk -F: '{uid[$3]=1}END{for(x=1000; x<=1500; x++) {if(uid[x] != ""){}else{print x; exit;}}}' /etc/passwd` - echo "mysql:x:$UID_MY:65534:MySQL daemon:/var/mysql:/bin/false" >> /etc/passwd +if [ -z `awk -F\: '/mysql/ {print $3}' $GFA_PREFIX/etc/passwd` ]; then + UID_MY=`awk -F: '{uid[$3]=1}END{for(x=1000; x<=1500; x++) {if(uid[x] != ""){}else{print x; exit;}}}' $GFA_PREFIX/etc/passwd` + echo "mysql:x:$UID_MY:65534:MySQL daemon:/var/mysql:/bin/false" >> $GFA_PREFIX/etc/passwd fi #--create missing users for postgresql, -if [ -z `awk -F\: '/postgres/ {print $3}' /etc/passwd` ]; then - UID_PG=`awk -F: '{uid[$3]=1}END{for(x=1000; x<=1500; x++) {if(uid[x] != ""){}else{print x; exit;}}}' /etc/passwd` - GID_PG=`awk -F\: '/postgres/ {print $3}' /etc/group` +if [ -z `awk -F\: '/postgres/ {print $3}' $GFA_PREFIX/etc/passwd` ]; then + UID_PG=`awk -F: '{uid[$3]=1}END{for(x=1000; x<=1500; x++) {if(uid[x] != ""){}else{print x; exit;}}}' $GFA_PREFIX/etc/passwd` + GID_PG=`awk -F\: '/postgres/ {print $3}' $GFA_PREFIX/etc/group` if [ -z "$GID_PG" ]; then - GID_PG=`awk -F: '{uid[$3]=1}END{for(x=1000; x<=1500; x++) {if(uid[x] != ""){}else{print x; exit;}}}' /etc/group` - echo "postgres:x:$GID_PG:" >> /etc/group + GID_PG=`awk -F: '{uid[$3]=1}END{for(x=1000; x<=1500; x++) {if(uid[x] != ""){}else{print x; exit;}}}' $GFA_PREFIX/etc/group` + echo "postgres:x:$GID_PG:" >> $GFA_PREFIX/etc/group fi - echo "postgres:x:$UID_PG:$GID_PG:PostgreSQL Server:/var/lib/pgsql:/bin/sh" >> /etc/passwd + echo "postgres:x:$UID_PG:$GID_PG:PostgreSQL Server:/var/lib/pgsql:/bin/sh" >> $GFA_PREFIX/etc/passwd fi #------------------ -chown -Rv mysql:nogroup /var/mysql -chown -Rv postgres:postgres /var/lib/pgsql +chown -Rv mysql:nogroup $GFA_PREFIX/var/mysql +chown -Rv postgres:postgres $GFA_PREFIX/var/lib/pgsql #============================================================================== # Get Graphics resolution and set dtb to the right resolution BASEBOARD=`cat /tmp/BASEBOARD` @@ -288,4 +414,11 @@ fi echo "Update Done, pls. reboot System" umount /mnt echo "." +echo "restart system !!!" +sleep 2 +#----------------- +reboot +exit 0 +fi +#------------- exit 0