rsuinux

update openwrt for cubieboard without cubie

Jul 14th, 2014
318
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 8.75 KB | None | 0 0
  1. #/bin/bash
  2. # -----------------------------------------------------------------------------
  3. # mise à jour de openwrt sur cubieboard
  4. # execution à une date, création d'un répertoire à cette date, téléchargement
  5. # des fichiers, copies des fichiers.
  6. # -----------------------------------------------------------------------------
  7. # par R. Suinot <[email protected]>
  8. # le 10 fevrier 2014
  9. # rev° 26 mai 2014
  10. # rev° 14 juil 2014
  11. # rev° 15 juil 2014
  12. # rev° 13 sept 2014
  13. # rev° 20 sept 2014
  14. # rev° 22 avril 2015
  15. # -----------------------------------------------------------------------------
  16. #
  17. #------------ Formatages de textes -----------------
  18. NORMAL="\e[0m"
  19. GRAS="\e[1m"
  20. ROUGE="\e[31m"
  21. # ---------------------------------------------------
  22.  
  23. BASE=`pwd`
  24.  
  25. rep=$BASE"/"$(date +%d%m%Y)
  26. SAUVG=$rep"/sauvegarde_configurations"
  27. ETC=$SAUVG"/etc"
  28. USR=$SAUVG"/usr"
  29. LIB=$SAUVG"/lib"
  30. ROOT=$SAUVG"/root"
  31.  
  32. # PARTITION="/dev/sdc"
  33. PARTITION="/dev/mmcblk0"
  34. # PARTITION_BOOT="/dev/sdc1"
  35. PARTITION_BOOT="/dev/mmcblk0p1"
  36. # PARTITION_ROOT="/dev/sdc2"
  37. PARTITION_ROOT="/dev/mmcblk0p2"
  38.  
  39. DEST="/mnt"
  40. dest_kmod="/mnt/root/"
  41. config="/mnt/etc/config/"
  42.  
  43. adresse="http://downloads.openwrt.org/snapshots/trunk/sunxi/generic"
  44. # adresse="ftp://bo.mirror.garr.it/pub/1/openwrt/snapshots/trunk/sunxi/generic"
  45.  
  46. # Vous devez être root pour executer ce script!!!
  47. if [ $(whoami) != "root" ]; then
  48.         echo -e $GRAS
  49.         echo "Vous devez executer ce script sous l'utilisateur Root."
  50.         echo "Use 'sudo $0' then enter your password when prompted."
  51.         echo -e $NORMAL
  52.         exit 1
  53. fi
  54.  
  55. if [ -b "$PARTITION_BOOT" ]
  56. then
  57.         echo "présence de $PARTITION_BOOT sur la carte sd."
  58.         if [ -b "$PARTITION_ROOT" ]
  59.         then
  60.                 echo "présence de $PARTITION_ROOT sur la carte sd."
  61.         else
  62.                 echo -e $ROUGE
  63.                 echo "Pas de périphérique $PARTITION_ROOT (racine)"
  64.                 echo " Corrigez le problème et recommencez. Merci."
  65.                 echo -e $NORMAL
  66.                 exit 1
  67.         fi
  68. else
  69.         echo -e $ROUGE
  70.         echo " Pas de périphérique $PARTITION_BOOT (boot)"
  71.         echo " Corrigez le problème et recommencez. Merci."
  72.         echo -e $NORMAL
  73.         exit 1
  74. fi
  75.  
  76. if [[ ! ( -d "$rep" ) ]]
  77. then
  78.         read -p "création du répertoire local $rep (y/n)?" REPLY
  79.         if [ $REPLY != "y" ]; then
  80.                 echo "Exiting..."
  81.                 exit 1
  82.         else
  83.                 mkdir $rep
  84.                 cd $rep
  85.                 mkdir $SAUVG
  86.         fi
  87. else
  88.     cd $rep
  89. fi
  90.  
  91. # avant de lancer les download, on récupère les configurations sur la carte $PARTITION_ROOT
  92. if mount | grep $PARTITION_ROOT > /dev/null; then
  93.         tmp=$(mount | grep $PARTITION_ROOT | awk {'print $3'})
  94.         umount $tmp
  95. fi
  96.  
  97. echo "  => montage $PARTITION_ROOT $DEST"
  98. echo "mount $PARTITION_ROOT $DEST"
  99. mount $PARTITION_ROOT $DEST
  100.  
  101. mkdir $ETC
  102.  
  103. echo "   ==> copie des fichiers et repertoires:"
  104. echo "     ==> /etc/config "
  105. cp -R /mnt/etc/config/ $ETC  
  106.  
  107. echo "     ==> /etc/crontabs "
  108. cp -R /mnt/etc/crontabs/ $ETC
  109.  
  110. echo "     ==> /etc/samba "
  111. cp -R /mnt/etc/samba/ $ETC
  112.  
  113. echo "     ==> /lib/firmware "
  114. mkdir $LIB
  115. cp -R /mnt/lib/firmware/ $LIB
  116.  
  117. echo "     ==> /etc/profile "
  118. cp /mnt/etc/profile $ETC
  119.  
  120. echo "     ==> /etc/rc.local "
  121. cp /mnt/etc/rc.local $ETC
  122.  
  123. echo "     ==> /etc/passwd "
  124. cp /mnt/etc/passwd $ETC
  125.  
  126. echo "     ==> /etc/shadow "
  127. cp /mnt/etc/shadow $ETC
  128.  
  129. echo "     ==> /etc/group "
  130. cp /mnt/etc/group $ETC
  131.  
  132. echo "     ==> /usr/local/ "
  133. mkdir -p $USR
  134. cp -R /mnt/usr/local/ $USR
  135.  
  136. echo "     ==> /root "
  137. mkdir $ROOT
  138. cp -R /mnt/root/* $ROOT
  139.  
  140. echo "  ==> demontage $DEST"
  141. umount $DEST
  142.  
  143. # wget http://downloads.openwrt.org/snapshots/trunk/sunxi/generic/uboot-sunxi-Cubieboard/openwrt-sunxi-Cubieboard-boot.scr
  144. wget $adresse"/uboot-sunxi-Cubieboard/openwrt-sunxi-Cubieboard-boot.scr"
  145.  
  146. # wget http://downloads.openwrt.org/snapshots/trunk/sunxi/generic/uboot-sunxi-Cubieboard/openwrt-sunxi-Cubieboard-uEnv.txt
  147. wget $adresse"/uboot-sunxi-Cubieboard/openwrt-sunxi-Cubieboard-uEnv.txt"
  148.  
  149. # wget http://downloads.openwrt.org/snapshots/trunk/sunxi/generic/uboot-sunxi-Cubieboard/openwrt-sunxi-Cubieboard-u-boot-with-spl.bin
  150. wget $adresse"/uboot-sunxi-Cubieboard/openwrt-sunxi-Cubieboard-u-boot-with-spl.bin"
  151.  
  152. # wget http://downloads.openwrt.org/snapshots/trunk/sunxi/generic/md5sums
  153.  wget $adresse"/md5sums"
  154.  
  155. # wget http://downloads.openwrt.org/snapshots/trunk/sunxi/generic/openwrt-sunxi-uImage
  156. wget $adresse"/openwrt-sunxi-uImage"
  157.  
  158. # wget http://downloads.openwrt.org/snapshots/trunk/sunxi/generic/openwrt-sunxi-root.ext4
  159. wget $adresse"/openwrt-sunxi-root.ext4"
  160.  
  161. # wget http://downloads.openwrt.org/snapshots/trunk/sunxi/generic/sun4i-a10-cubieboard.dtb
  162. wget $adresse"/sun4i-a10-cubieboard.dtb"
  163.  
  164. # ---------------------------------------------------------------------------------------------------------
  165.  
  166. echo " ==> resize de la PARTITION root ..."
  167. resize2fs openwrt-sunxi-root.ext4 240M
  168. echo "  ==> resize terminée!"
  169. echo " "
  170. echo -e $GRAS
  171. echo "All completed downloads... "
  172. read -p "Arreter ici (y/n)?" REPLY
  173. echo -e $NORMAL
  174. if [ $REPLY == "y" ]; then
  175.         echo "Exiting..."
  176.         exit 1
  177. fi
  178.  
  179. echo -e $GRAS
  180. echo "  ==> application du  boot avec spl?"
  181. read -p "(y/n)?" REPLY
  182. if [ $REPLY == "y" ]; then
  183.     echo "dd if=openwrt-sunxi-Cubieboard-u-boot-with-spl.bin of=$PARTITION bs=1024 seek=8"
  184.         dd if=openwrt-sunxi-Cubieboard-u-boot-with-spl.bin of=$PARTITION bs=1024 seek=8
  185. fi
  186. echo -e $NORMAL
  187.  
  188.  
  189. if mount | grep $PARTITION_BOOT > /dev/null; then
  190.         tmp=$(mount | grep $PARTITION_BOOT | awk {'print $3'})
  191.         umount $tmp
  192. fi
  193.  
  194. echo -e $GRAS
  195. echo "  ==> mount $PARTITION_BOOT "
  196. read -p "(y/n)?" REPLY
  197. if [ $REPLY == "y" ]; then
  198.     mkfs.vfat $PARTITION_BOOT
  199.         mount -t vfat $PARTITION_BOOT $DEST
  200. fi
  201. echo -e $NORMAL
  202.  
  203. echo -e $GRAS
  204. echo "    ==> write boot.scr "
  205. read -p "(y/n)?" REPLY
  206. if [ $REPLY == "y" ]; then
  207.         echo "cp openwrt-sunxi-Cubieboard-boot.scr $DEST/boot.scr "
  208.         cp openwrt-sunxi-Cubieboard-boot.scr $DEST/boot.scr
  209. fi
  210. echo -e $NORMAL
  211.  
  212. echo -e $GRAS
  213. echo "    ==> write uEnv.txt "
  214. read -p "(y/n)?" REPLY
  215. if [ $REPLY == "y" ]; then
  216.         cp openwrt-sunxi-Cubieboard-uEnv.txt $DEST/uEnv.txt
  217. fi
  218. echo -e $NORMAL
  219.  
  220. echo -e $GRAS
  221. echo "    ==> write uImage "
  222. read -p "(y/n)?" REPLY
  223. if [ $REPLY == "y" ]; then
  224.         cp openwrt-sunxi-uImage $DEST/uImage
  225. fi
  226. echo -e $NORMAL
  227.  
  228. echo -e $GRAS
  229. echo "    ==> write dtb "
  230. read -p "(y/n)?" REPLY
  231. if [ $REPLY == "y" ]; then
  232.         cp sun4i-a10-cubieboard.dtb $DEST/dtb
  233. fi
  234. echo -e $NORMAL
  235.  
  236. echo -e $GRAS
  237. echo "  ==> umount $PARTITION_BOOT "
  238. read -p "(y/n)?" REPLY
  239. if [ $REPLY == "y" ]; then
  240.         umount $DEST
  241. fi
  242. echo -e $NORMAL
  243.  
  244. if mount | grep $PARTITION_ROOT > /dev/null; then
  245.         tmp=$(mount | grep $PARTITION_ROOT | awk {'print $3'})
  246.         umount $tmp
  247. fi
  248.  
  249. echo -e $ROUGE
  250. echo "ATTENTION: prochaine action = ecriture de la PARTITION root."
  251. echo "CELA VA ECRASER CONPLETEMENT L'ANCIENNE PARTITION !!! "
  252.  
  253. read -p "Arreter la (y) ou Ecrire quand même (n)?" REPLY
  254. echo -e $NORMAL
  255. if [ $REPLY != "y" ]; then
  256.         echo "  ==> ecriture de  openwrt-sunxi-root.ext4 ... please wait..."
  257.     echo "dd if=openwrt-sunxi-root.ext4 of=$PARTITION_ROOT bs=128k"
  258.         dd if=openwrt-sunxi-root.ext4 of=$PARTITION_ROOT bs=128k
  259.         echo "ok!"
  260. fi
  261.  
  262. sync
  263.  
  264. echo "  => montage $PARTITION_ROOT $DEST"
  265. mount $PARTITION_ROOT $DEST
  266. cd $SAUVG
  267.  
  268. echo "  ==> recopie des fichiers dans root ..."
  269. echo "cp -R root/* /mnt/root/"
  270. cp -r root/* /mnt/root/
  271.  
  272. echo "  ==> recopie des fichiers de configurations ..."
  273. echo "cp -R etc/* /mnt/etc/"
  274. cp -R etc/* /mnt/etc/
  275.  
  276. echo "  ==> recopie du répertoire lib ..."
  277. cp -R lib/* /mnt/lib/
  278.  
  279. echo "  ==> recopie du répertoire usr ..."
  280. cp -R usr/* /mnt/usr/
  281.  
  282. mkdir /mnt/home
  283.  
  284. # avant de terminer on va ecrire le fichier indiquant qu'il faut finir la mise à jour au prochain redemarrage
  285. touch /mnt/etc/mise_a_jour
  286. echo " création du fichier indiquant qu'on vent de faire une mise à jour complete"
  287. echo "  ==> touch /mnt/etc/mise_a_jour"
  288.  
  289. echo "  ==> demontage $DEST"
  290.  
  291. umount $DEST
  292. sync
  293.  
  294. echo -e $GRAS$ROUGE
  295. echo "Correction de la PARTITION $PARTITION_ROOT? "
  296. read -p "(y/n)?" REPLY
  297. echo -e $NORMAL
  298. if [ $REPLY == "y" ]; then
  299.         e2fsck -f -y -v -C 0 $PARTITION_ROOT
  300.         echo "  "
  301. fi
  302. echo -e $GRAS$ROUGE
  303. echo "Vérification de la partiton et agrandissement? "
  304. read -p "(y/n)?" REPLY
  305. echo -e $NORMAL
  306. if [ $REPLY == "y" ]; then
  307.         resize2fs -p $PARTITION_ROOT
  308.         echo " "
  309. fi
  310. echo " Terminé."
  311. echo -e $GRAS
  312. echo " +---------------------------------------------+"
  313. echo " | Vous pouvez reprendre une activité normale. |"
  314. echo " +---------------------------------------------+"
  315. echo -e $NORMAL
  316. exit 0
Advertisement
Add Comment
Please, Sign In to add comment