0014-chroot_env_for_rootfs_update.patch 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. diff --git a/UpdateRootfs.sh.in b/UpdateRootfs.sh.in
  2. index 89ff561..3e4b29d 100644
  3. --- a/UpdateRootfs.sh.in
  4. +++ b/UpdateRootfs.sh.in
  5. @@ -4,7 +4,7 @@ uuencode=0
  6. binary=1
  7. ##TAR_PARAMETERS="-C / --exclude=./opt --exclude=./etc/inittab -xzvf -"
  8. -TMP_PATH="/__GfA_Update"
  9. +TMP_PATH="$GFA_PREFIX/__GfA_Update"
  10. TAR_PARAMETERS="-C $TMP_PATH -xzvf -"
  11. untar_payload ()
  12. @@ -25,6 +25,131 @@ untar_payload ()
  13. fi
  14. }
  15. +if [ -z $1 ]
  16. +then
  17. +## prepare for chrooted environment
  18. +chmod +x /bin/bash
  19. +updatename=`realpath $0`
  20. +echo -e "===\n prepare chroot and update script\n===\n"
  21. +(\
  22. +cat << EOF
  23. +#! /bin/bash
  24. +CHROOT=/__GfA_chroot
  25. +
  26. +#---------------------
  27. +recurse ()
  28. +# Param 1 is the nuumber of spaces that the output will be prepended with
  29. +# Param 2 full path to library
  30. +{
  31. +#Use 'readelf -d' to find dependencies
  32. +dependencies=\$(readelf -d \${2} | grep NEEDED | awk '{ print \$5 }' | tr -d '[]')
  33. +for d in \$dependencies; do
  34. + echo "\${1}\${d} :: \${2}"
  35. + rsync -lpR \${2} \${CHROOT}
  36. + if [ -L \${2} ] ; then
  37. + LIBNAM=\`readlink -f \${2}\`
  38. + rsync -lpR \${LIBNAM} \${CHROOT}
  39. + echo "\${1}-->\${LIBNAM}"
  40. + fi
  41. + nm=\${d##*/}
  42. + #libstdc++ hack for the '+'-s
  43. + nm1=\${nm//"+"/"\+"}
  44. + # /lib /lib64 /usr/lib and /usr/lib are searched
  45. + children=\$(find / -name \${d} 2>/dev/null | grep -E "(^/(lib|lib32|usr/lib|usr/lib32)/\${nm1})")
  46. + rc=\$?
  47. + #at least locate... didn't fail
  48. + if [ \${rc} == "0" ] ; then
  49. + #we have at least one dependency
  50. + if [ \${#children[@]} -gt 0 ]; then
  51. + #check the dependeny's dependencies
  52. + for c in \$children; do
  53. + recurse " \${1}" \${c}
  54. + done
  55. + else
  56. + echo "\${1}no children found"
  57. + fi
  58. + else
  59. + echo "\${1}locate failed for ${d}"
  60. + fi
  61. +done
  62. +}
  63. +# -- recurse needs 2 params could/should be supplied from cmdline
  64. +echo "==== PREPARE CHROOT ENVIRONMENT in \${CHROOT} ===="
  65. +rm -rf \$CHROOT
  66. +mkdir -p \$CHROOT
  67. +#------------------------------------
  68. +tt=/bin/bash
  69. +echo -e "===\n \$tt\n"
  70. +recurse "" \$tt
  71. +
  72. +tt=/bin/sh
  73. +echo -e "===\n \$tt\n"
  74. +recurse "" \$tt
  75. +
  76. +tt=/bin/busybox
  77. +echo -e "===\n \$tt\n"
  78. +recurse "" \$tt
  79. +
  80. +tt=/usr/sbin/fbset
  81. +echo -e "===\n \$tt\n"
  82. +recurse "" \$tt
  83. +
  84. +tt=/usr/bin/awk
  85. +echo -e "===\n \$tt\n"
  86. +recurse "" \$tt
  87. +
  88. +tt=/usr/bin/cut
  89. +echo -e "===\n \$tt\n"
  90. +recurse "" \$tt
  91. +
  92. +tt=/usr/bin/tail
  93. +echo -e "===\n \$tt\n"
  94. +recurse "" \$tt
  95. +
  96. +tt=/sbin/reboot
  97. +echo -e "===\n \$tt\n"
  98. +recurse "" \$tt
  99. +
  100. +#----------------------------------------
  101. +cp -a /lib/ld-* \${CHROOT}/lib
  102. +cp -a /bin/* \${CHROOT}/bin
  103. +
  104. +ln -s ./realroot/root \${CHROOT}/root
  105. +
  106. +mkdir -p \${CHROOT}/proc
  107. +mkdir -p \${CHROOT}/dev
  108. +mkdir -p \${CHROOT}/sys
  109. +mkdir -p \${CHROOT}/etc
  110. +mkdir -p \${CHROOT}/realroot
  111. +mkdir -p \${CHROOT}/var
  112. +mkdir -p \${CHROOT}/tmp
  113. +mkdir -p \${CHROOT}/mnt
  114. +
  115. +mkdir -p \${CHROOT}/realroot/media/usb0
  116. +mkdir -p \${CHROOT}/realroot/media/usb1
  117. +
  118. +mount -o bind /proc \${CHROOT}/proc
  119. +mount -o bind /dev \${CHROOT}/dev
  120. +mount -o bind /sys \${CHROOT}/sys
  121. +mount -o bind /etc \${CHROOT}/etc
  122. +mount -o bind /var \${CHROOT}/var
  123. +mount -o bind /tmp \${CHROOT}/tmp
  124. +mount -o bind / \${CHROOT}/realroot
  125. +
  126. +mount -o bind /media/usb0 \${CHROOT}/realroot/media/usb0
  127. +mount -o bind /media/usb1 \${CHROOT}/realroot/media/usb1
  128. +
  129. +echo -e "\n===========\nchroot environment ready in \n \${CHROOT}\n===========\n"
  130. +chroot \${CHROOT} sh -c 'GFA_PREFIX=/realroot sh /realroot${updatename} DoRealUpdate'
  131. +
  132. +EOF
  133. +) > /root/GfA_prep_chroot.sh
  134. +
  135. +chmod a+x /root/GfA_prep_chroot.sh
  136. +#--- execute built script
  137. +echo "==>>> execute chroot update script"
  138. +/root/GfA_prep_chroot.sh
  139. +else
  140. ## --- Kommandos zum Installieren
  141. ## -- get bootpartition
  142. such="root=/dev/mmcblk1"
  143. @@ -54,26 +179,26 @@ cp $TMP_PATH/*.dtb /mnt
  144. mkdir -p $TMP_PATH/bu_cfg
  145. -if [ -e /etc/network/interfaces ]
  146. +if [ -e $GFA_PREFIX/etc/network/interfaces ]
  147. then
  148. - cp /etc/network/interfaces $TMP_PATH/bu_cfg
  149. - rm /etc/network/interfaces
  150. + cp $GFA_PREFIX/etc/network/interfaces $TMP_PATH/bu_cfg
  151. + rm $GFA_PREFIX/etc/network/interfaces
  152. fi
  153. -if [ -e /etc/wpa_supplicant.conf ]
  154. +if [ -e $GFA_PREFIX/etc/wpa_supplicant.conf ]
  155. then
  156. - cp /etc/wpa_supplicant.conf $TMP_PATH/bu_cfg/wpa_supplicant.conf_old
  157. - rm /etc/wpa_supplicant.conf
  158. + cp $GFA_PREFIX/etc/wpa_supplicant.conf $TMP_PATH/bu_cfg/wpa_supplicant.conf_old
  159. + rm $GFA_PREFIX/etc/wpa_supplicant.conf
  160. fi
  161. -if [ -e /etc/wpa_supplicant/wpa_supplicant.conf ]
  162. +if [ -e $GFA_PREFIX/etc/wpa_supplicant/wpa_supplicant.conf ]
  163. then
  164. - cp /etc/wpa_supplicant/wpa_supplicant.conf $TMP_PATH/bu_cfg
  165. - rm /etc/wpa_supplicant/wpa_supplicant.conf
  166. + cp $GFA_PREFIX/etc/wpa_supplicant/wpa_supplicant.conf $TMP_PATH/bu_cfg
  167. + rm $GFA_PREFIX/etc/wpa_supplicant/wpa_supplicant.conf
  168. fi
  169. #rootfs auspacken
  170. -tar -C / --exclude=./tmp --exclude=./etc/inittab \
  171. +tar -C $GFA_PREFIX/ --exclude=./tmp --exclude=./etc/inittab \
  172. --exclude=./etc/hosts --exclude=./etc/hostname \
  173. --exclude=./etc/passwd --exclude=./etc/shadow \
  174. --exclude=./etc/vncpwd --exclude=./etc/init.d/S99tincd \
  175. @@ -97,10 +222,10 @@ auto lo
  176. iface lo inet loopback
  177. EOF
  178. -) > /etc/network/interfaces
  179. +) > $GFA_PREFIX/etc/network/interfaces
  180. 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 \
  181. ->> /etc/network/interfaces
  182. +>> $GFA_PREFIX/etc/network/interfaces
  183. (\
  184. cat << EOF
  185. @@ -114,52 +239,52 @@ iface wlan0 inet dhcp
  186. wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
  187. #
  188. EOF
  189. -) >> /etc/network/interfaces
  190. +) >> $GFA_PREFIX/etc/network/interfaces
  191. -if [ -e /etc/init.d/S98usb_g_ether ]
  192. +if [ -e $GFA_PREFIX/etc/init.d/S98usb_g_ether ]
  193. then
  194. - cp /etc/init.d/S98usb_g_ether /etc/init.d/M98usb_g_ether
  195. - rm /etc/init.d/S98usb_g_ether
  196. + cp $GFA_PREFIX/etc/init.d/S98usb_g_ether $GFA_PREFIX/etc/init.d/M98usb_g_ether
  197. + rm $GFA_PREFIX/etc/init.d/S98usb_g_ether
  198. fi
  199. -if [ -e /etc/init.d/S80ti-sgx ]
  200. +if [ -e $GFA_PREFIX/etc/init.d/S80ti-sgx ]
  201. then
  202. - rm /etc/init.d/S80ti-sgx
  203. + rm $GFA_PREFIX/etc/init.d/S80ti-sgx
  204. fi
  205. -if [ -e /etc/init.d/M99_wlan_usb ]
  206. +if [ -e $GFA_PREFIX/etc/init.d/M99_wlan_usb ]
  207. then
  208. - rm /etc/init.d/M99_wlan_usb
  209. + rm $GFA_PREFIX/etc/init.d/M99_wlan_usb
  210. fi
  211. -if [ -e /etc/init.d/S99_wlan_usb ]
  212. +if [ -e $GFA_PREFIX/etc/init.d/S99_wlan_usb ]
  213. then
  214. - rm /etc/init.d/S99_wlan_usb
  215. + rm $GFA_PREFIX/etc/init.d/S99_wlan_usb
  216. fi
  217. -if [ -e /etc/init.d/M80dhcp-relay ]
  218. +if [ -e $GFA_PREFIX/etc/init.d/M80dhcp-relay ]
  219. then
  220. - rm /etc/init.d/M80dhcp-relay
  221. + rm $GFA_PREFIX/etc/init.d/M80dhcp-relay
  222. fi
  223. -if [ -e /etc/init.d/S80dhcp-relay ]
  224. +if [ -e $GFA_PREFIX/etc/init.d/S80dhcp-relay ]
  225. then
  226. - rm /etc/init.d/S80dhcp-relay
  227. + rm $GFA_PREFIX/etc/init.d/S80dhcp-relay
  228. fi
  229. -if [ -e /etc/init.d/M80dhcp-server ]
  230. +if [ -e $GFA_PREFIX/etc/init.d/M80dhcp-server ]
  231. then
  232. - rm /etc/init.d/M80dhcp-server
  233. + rm $GFA_PREFIX/etc/init.d/M80dhcp-server
  234. fi
  235. -if [ -e /etc/init.d/S80dhcp-server ]
  236. +if [ -e $GFA_PREFIX/etc/init.d/S80dhcp-server ]
  237. then
  238. - rm /etc/init.d/S80dhcp-server
  239. + rm $GFA_PREFIX/etc/init.d/S80dhcp-server
  240. fi
  241. -if [ -d /etc/dhcp ]
  242. +if [ -d $GFA_PREFIX/etc/dhcp ]
  243. then
  244. - rm -rf /etc/dhcp
  245. + rm -rf $GFA_PREFIX/etc/dhcp
  246. fi
  247. #echo "Update Firmware"
  248. @@ -170,7 +295,7 @@ fi
  249. #/root/gfa_spi -v
  250. #================================
  251. #--create mountable run folder insted of link
  252. -RUNDIR=/run
  253. +RUNDIR=$GFA_PREFIX/run
  254. if [ -L $RUNDIR ]; then
  255. mv $RUNDIR $RUNDIR'_WRK'
  256. mkdir $RUNDIR
  257. @@ -182,28 +307,29 @@ if [ -L $RUNDIR ]; then
  258. rm $RUNDIR'_WRK'
  259. fi
  260. #--- craete missing nogroup group
  261. -GID_NOGROUP=`awk -F\: '/nogroup/ {print $3}' /etc/group`
  262. +GID_NOGROUP=`awk -F\: '/nogroup/ {print $3}' $GFA_PREFIX/etc/group`
  263. if [ -z "$GID_NOGROUP" ]; then
  264. - addgroup -S -g 65534 nogroup
  265. +# addgroup -S -g 65534 nogroup
  266. + echo "nogroup:x:65534:" >> $GFA_PREFIX/etc/group
  267. fi
  268. #--create missing users for mysql,
  269. -if [ -z `awk -F\: '/mysql/ {print $3}' /etc/passwd` ]; then
  270. - UID_MY=`awk -F: '{uid[$3]=1}END{for(x=1000; x<=1500; x++) {if(uid[x] != ""){}else{print x; exit;}}}' /etc/passwd`
  271. - echo "mysql:x:$UID_MY:65534:MySQL daemon:/var/mysql:/bin/false" >> /etc/passwd
  272. +if [ -z `awk -F\: '/mysql/ {print $3}' $GFA_PREFIX/etc/passwd` ]; then
  273. + 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`
  274. + echo "mysql:x:$UID_MY:65534:MySQL daemon:/var/mysql:/bin/false" >> $GFA_PREFIX/etc/passwd
  275. fi
  276. #--create missing users for postgresql,
  277. -if [ -z `awk -F\: '/postgres/ {print $3}' /etc/passwd` ]; then
  278. - UID_PG=`awk -F: '{uid[$3]=1}END{for(x=1000; x<=1500; x++) {if(uid[x] != ""){}else{print x; exit;}}}' /etc/passwd`
  279. - GID_PG=`awk -F\: '/postgres/ {print $3}' /etc/group`
  280. +if [ -z `awk -F\: '/postgres/ {print $3}' $GFA_PREFIX/etc/passwd` ]; then
  281. + 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`
  282. + GID_PG=`awk -F\: '/postgres/ {print $3}' $GFA_PREFIX/etc/group`
  283. if [ -z "$GID_PG" ]; then
  284. - GID_PG=`awk -F: '{uid[$3]=1}END{for(x=1000; x<=1500; x++) {if(uid[x] != ""){}else{print x; exit;}}}' /etc/group`
  285. - echo "postgres:x:$GID_PG:" >> /etc/group
  286. + 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`
  287. + echo "postgres:x:$GID_PG:" >> $GFA_PREFIX/etc/group
  288. fi
  289. - echo "postgres:x:$UID_PG:$GID_PG:PostgreSQL Server:/var/lib/pgsql:/bin/sh" >> /etc/passwd
  290. + echo "postgres:x:$UID_PG:$GID_PG:PostgreSQL Server:/var/lib/pgsql:/bin/sh" >> $GFA_PREFIX/etc/passwd
  291. fi
  292. #------------------
  293. -chown -Rv mysql:nogroup /var/mysql
  294. -chown -Rv postgres:postgres /var/lib/pgsql
  295. +chown -Rv mysql:nogroup $GFA_PREFIX/var/mysql
  296. +chown -Rv postgres:postgres $GFA_PREFIX/var/lib/pgsql
  297. #==============================================================================
  298. # Get Graphics resolution and set dtb to the right resolution
  299. BASEBOARD=`cat /tmp/BASEBOARD`
  300. @@ -288,4 +414,11 @@ fi
  301. echo "Update Done, pls. reboot System"
  302. umount /mnt
  303. echo "."
  304. +echo "restart system !!!"
  305. +sleep 2
  306. +#-----------------
  307. +reboot
  308. +exit 0
  309. +fi
  310. +#-------------
  311. exit 0