create_arm_img_urpmi.sh 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961
  1. #!/bin/bash
  2. # Copyright (C) 2017-2018 Daniel Tartavel-jeannot <contact@librepc.com>
  3. #
  4. # This program is free software; you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation; either version 2 of the License, or
  7. # (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. function title()
  17. {
  18. echo -e "\e[1;32m$1\e[0m"
  19. }
  20. function info()
  21. {
  22. echo -e "\e[36m$1\e[0m"
  23. }
  24. function warning()
  25. {
  26. echo -e "\e[1;35m$1\e[0m"
  27. }
  28. function error()
  29. {
  30. echo -e "\e[1;31m$1\e[0m"
  31. }
  32. info $0
  33. SOURCE_PATH="$(/bin/dirname "$(readlink -f "$0")")"
  34. INSTALL_PATH="$SOURCE_PATH/arm"
  35. FILES_PATH="$SOURCE_PATH/files"
  36. PLATFORMS_PATH="$SOURCE_PATH/platforms"
  37. CMDNAME=$(/bin/basename "$0")
  38. #while read -r;do
  39. # for MAGEIA_VERSION in $REPLY
  40. # do
  41. # if [ $MAGEIA_VERSION <= 5 ];then
  42. # echo 'Mageia version >= 6 is needed'
  43. # exit
  44. # fi
  45. # break
  46. # done
  47. #done < /etc/version
  48. function help()
  49. {
  50. echo "$CMDNAME [option] [size of image in Go]"
  51. echo "Options:"
  52. echo "--all create ready to burn image of Mageia $MAGEIA_VERSION"
  53. echo "--clean Clean all (suppress all) to make a new image"
  54. echo "--size size of image default: 7Go"
  55. echo "--build-path Path to the build directory of the image of Mageia $MAGEIA_VERSION"
  56. echo "--target target system (for now rpi, odroid)"
  57. echo "--target-version version of the target (0, 1, 2, 3 for rpi, 3 or 4 for odroid)"
  58. echo "--config Path to config files (rpi1 rpi2 rpi3 rpi3+ xu4)"
  59. echo "--bootfs filesystem of boot partition (ext4 or vfat) default: ext4"
  60. echo "--nonfree activate nonfree repos"
  61. echo "--tainted activate tainted repos"
  62. echo "\nBuild levels:"
  63. echo "--create-chroot Create the chroot directory"
  64. echo "--addmedia add mirrors"
  65. echo "--update-mirror update urpmi database"
  66. echo "--install-basesystem install base system"
  67. echo "--chroot chroot to arm directory and launch packages installation"
  68. echo "--create-image Create the image of Mageia $MAGEIA_VERSION"
  69. echo -e "\nFor image size, make sure it fit on physical support. (Default size is 7 Go)"
  70. }
  71. # cleaning build space
  72. function clean()
  73. {
  74. # Unmounting /dev /proc /sys in chroot
  75. title "Cleaning"
  76. if ! [ -z "$(mountpoint -qd "$BUILD_PATH/dev")" ];then
  77. info "Unmounting $BUILD_PATH/dev"
  78. umount "$BUILD_PATH/dev"
  79. if ! [ $? -ne 0 ];then
  80. error "line $LINENO can't unmount $BUILD_PATH/dev : exiting"
  81. #exit 1
  82. fi
  83. fi
  84. if ! [ -z "$(mountpoint -qd "$BUILD_PATH/sys")" ];then
  85. info "Unmounting $BUILD_PATH/sys"
  86. umount "$BUILD_PATH/sys"
  87. if ! [ $? -ne 0 ];then
  88. error "line $LINENO can't unmount $BUILD_PATH/sys : exiting"
  89. #exit 1
  90. fi
  91. fi
  92. if ! [ -z "$(mountpoint -qd "$BUILD_PATH/proc")" ];then
  93. info "Unmounting $BUILD_PATH/proc"
  94. umount "$BUILD_PATH/proc"
  95. if ! [ $? -ne 0 ];then
  96. error "line $LINENO can't unmount $BUILD_PATH/proc : exiting"
  97. #exit 1
  98. fi
  99. fi
  100. # Removing old Build directory
  101. if [ -d "$BUILD_PATH" ];then
  102. info "Removing $BUILD_PATH"
  103. /bin/rm -Rf "$BUILD_PATH"
  104. else
  105. warning "$BUILD_PATH does not exists"
  106. fi
  107. # removing old image
  108. if [ -e "$IMAGE" ];then
  109. info "Removing $IMAGE"
  110. /bin/rm -f "$INSTALL_PATH/$IMAGE"
  111. else
  112. warning "$IMAGE does not exists"
  113. fi
  114. # removing loop devices
  115. for LOOP in $(ls /dev/loop*[0-9]p1)
  116. do
  117. X=${LOOP:0:10}
  118. if [ -e "$X" ];then
  119. info "removing $X"
  120. partx -d "$X"
  121. fi
  122. done
  123. # Removing boot and root directory
  124. if [ -d "$BOOT" ];then
  125. info "Removing $BOOT"
  126. /bin/rmdir "$BOOT"
  127. else
  128. warning "$BOOT does not exists"
  129. fi
  130. if [ -d "$ROOT" ];then
  131. info "Removing $ROOT"
  132. /bin/rmdir "$ROOT"
  133. else
  134. warning "$ROOT does not exists"
  135. fi
  136. exit 0
  137. }
  138. # creation of install path and copy of qemu ( installing it if not yet installed )
  139. function createchroot()
  140. {
  141. title "Making chroot"
  142. if ! [ -f /bin/qemu-arm-static ]; then
  143. title "Qemu package not present : installing qemu packages"
  144. /sbin/urpmi --auto --no-recommends qemu-user-static
  145. if ! [ $? -eq 0 ];then
  146. error "line $LINENO can't install qemu-user-static : exiting"
  147. exit 1
  148. fi
  149. fi
  150. # Starting qemu service if not started
  151. /bin/systemctl is-active systemd-binfmt.service
  152. if [ $? -ne 0 ]; then
  153. title "Starting systemd-binfmt.service"
  154. /bin/systemctl start systemd-binfmt.service
  155. if ! [ $? -ne 0 ];then
  156. error "line $LINENO can't start qemu-user-static : exiting"
  157. exit 1
  158. fi
  159. fi
  160. }
  161. # adding Mageia repositories
  162. function addmedia()
  163. {
  164. title "Creating media $MIRROR"
  165. /sbin/urpmi.addmedia --urpmi-root "$BUILD_PATH" --distrib "$MIRROR"
  166. err=$?
  167. if [ $err -ne 0 ];then
  168. error "line $LINENO error $err - can't add medias from $MIRROR : exiting"
  169. exit 1
  170. fi
  171. if [ $NONFREE -eq 1 ];then
  172. title "activating non-free repos"
  173. /sbin/urpmi.update --urpmi-root "$BUILD_PATH" --no-ignore Nonfree\ Release Nonfree\ Updates
  174. err=$?
  175. if [ $err -ne 0 ];then
  176. error "line $LINENO error $err - can't activate medias nonfree : exiting"
  177. exit 1
  178. fi
  179. fi
  180. if [ $TAINTED -eq 1 ];then
  181. title "activating tainted repos"
  182. /sbin/urpmi.update --urpmi-root "$BUILD_PATH" --no-ignore Tainted\ Release Tainted\ Updates
  183. err=$?
  184. if [ $err -ne 0 ];then
  185. error "line $LINENO error $err - can't activate medias tainted : exiting"
  186. exit 1
  187. fi
  188. fi
  189. }
  190. function updatemirror()
  191. {
  192. title "updating mirror"
  193. /sbin/urpmi.update -a --urpmi-root "$BUILD_PATH"
  194. if [ $? -ne 0 ];then
  195. error "line $LINENO can't update mirrors : exiting"
  196. exit 1
  197. fi
  198. }
  199. function installbasesystem()
  200. {
  201. # Create Build path
  202. if ! [ -d "$BUILD_PATH" ];then
  203. warning "Build path ( $BUILD_PATH ) does not exists, do you want i create it ? [Y|n] "
  204. read yn
  205. if [ -z $yn ] || [ $yn = "Y" ] || [ $yn = "y" ];then
  206. title "Creating $BUILD_PATH"
  207. /bin/mkdir -p "$BUILD_PATH/usr/bin" "$BUILD_PATH/usr/lib/binfmt.d"
  208. if [ $? -ne 0 ];then
  209. error "line $LINENO can't create $BUILD_PATH : exiting"
  210. exit 1
  211. fi
  212. else
  213. exit 1
  214. fi
  215. else
  216. info "Build path exists"
  217. fi
  218. title "installing basesystem"
  219. /sbin/urpmi --urpmi-root "$BUILD_PATH" --ignorearch --no-verify-rpm --auto --split-level 200 --split-length 200 shadow-utils basesystem-minimal
  220. if [ $? -ne 0 ];then
  221. error "line $LINENO error installing shadow-utils or basesystem-minimal : exiting"
  222. exit 1
  223. fi
  224. #/sbin/urpmi --urpmi-root "$BUILD_PATH" --ignorearch --no-verify-rpm --auto --split-level 200 --split-length 200 basesystem-minimal
  225. #if [ $? -ne 0 ];then
  226. # error "line $LINENO error installing basesystem-minimal : exiting"
  227. # exit 1
  228. #fi
  229. /sbin/urpmi --urpmi-root "$BUILD_PATH" --ignorearch --no-verify-rpm --auto --split-level 200 --split-length 200 urpmi locales-fr systemd u-boot
  230. if [ $? -ne 0 ];then
  231. error "line $LINENO error installing urpmi or locales.fr : exiting"
  232. exit 1
  233. fi
  234. }
  235. function preparechroot()
  236. {
  237. title "Preparing chrooting in $BUILD_PATH"
  238. #Copying qemu
  239. /bin/cp /bin/qemu-arm-static "$BUILD_PATH/usr/bin/"
  240. if [ $? -ne 0 ];then
  241. error "line $LINENO can't copy /bin/qemu-user-static to $BUILD_PATH/usr/bin/ : exiting"
  242. exit 1
  243. fi
  244. /bin/cp /usr/lib/binfmt.d/qemu-arm-static.conf "$BUILD_PATH/usr/lib/binfmt.d"
  245. if [ $? -ne 0 ];then
  246. error "line $LINENO can't copy /usr/lib/binfmt.d/qemu-arm-static.conf to $BUILD_PATH/usr/lib/binfmt.d : exiting"
  247. exit 1
  248. fi
  249. info "making /etc/hostname"
  250. echo "$HOSTNAME" > "$BUILD_PATH/etc/hostname"
  251. info "copying second stage script in $BUILD_PATH"
  252. echo "/bin/cp $CONFIG_PATH/second_stage_install.sh $BUILD_PATH/"
  253. cp --preserve=mode "$CONFIG_PATH/second_stage_install.sh" "$BUILD_PATH/second_stage_install.sh"
  254. if [ $? -ne 0 ];then
  255. error "line $LINENO error copying $CONFIG_PATH/second_stage_install.sh : exiting"
  256. exit 1
  257. fi
  258. info "creation of user account"
  259. echo "/bin/passwd << EOF
  260. $ROOT_PWD
  261. $ROOT_PWD
  262. EOF
  263. /sbin/useradd $ID_USER
  264. /bin/passwd $ID_USER << EOF
  265. $PASSWORD
  266. $PASSWORD
  267. EOF" >>"$BUILD_PATH/second_stage_install.sh"
  268. info "Copying skel in root directory"
  269. /bin/rsync -rlptH /etc/skel/ "$BUILD_PATH/root/"
  270. case $TARGET in
  271. odroid)
  272. #TEMPORARY CODE
  273. #copying kernel odroid not existing in mageia repos
  274. info "copying kernel-odroid and u-boot rpms in $BUILD_PATH/root"
  275. echo "/bin/cp $CONFIG_PATH/kernel-odroid-4.14.y-1.armv7hl.rpm $BUILD_PATH/root/"
  276. /usr/bin/cp --preserve=mode "$CONFIG_PATH/kernel-odroid-4.14.y-1.armv7hl.rpm" "$BUILD_PATH/root/"
  277. echo "/bin/cp $CONFIG_PATH/u-boot-20180507-3.mga7.armv7hl.rpm $BUILD_PATH/root/"
  278. /usr/bin/cp --preserve=mode "$CONFIG_PATH/u-boot-20180507-3.mga7.armv7hl.rpm" "$BUILD_PATH/root/"
  279. if [ $? -ne 0 ];then
  280. error "line $LINENO error copying $CONFIG_PATH/kernel-odroid-4.14.y-1.armv7hl.rpm : exiting"
  281. exit 1
  282. fi
  283. ;;
  284. rpi)
  285. ;;
  286. esac
  287. }
  288. function jumpchroot()
  289. {
  290. title "chrooting to $BUILD_PATH"
  291. info "mounting dev, sys, proc directories in chroot"
  292. /bin/mount -B /dev "$BUILD_PATH/dev"
  293. if [ $? -ne 0 ];then
  294. error "line $LINENO error mounting $BUILD_PATH/dev : exiting"
  295. exit 1
  296. fi
  297. /bin/mount -B /sys "$BUILD_PATH/sys"
  298. if [ $? -ne 0 ];then
  299. error "line $LINENO error mounting $BUILD_PATH/sys : exiting"
  300. exit 1
  301. fi
  302. /bin/mount -B /proc "$BUILD_PATH/proc"
  303. if [ $? -ne 0 ];then
  304. error "line $LINENO error mounting $BUILD_PATH/proc : exiting"
  305. exit 1
  306. fi
  307. info "Copying resolv.conf"
  308. /bin/cp -v --preserve=mode /etc/resolv.conf "$BUILD_PATH/etc/"
  309. if [ $? -ne 0 ];then
  310. error "line $LINENO error copying $BUILD_PATH/etc/resolv.conf : exiting"
  311. exit 1
  312. fi
  313. if [ "$OPT" = "chroot" ];then
  314. /sbin/chroot "$BUILD_PATH"
  315. else
  316. /sbin/chroot --userspec root:root "$BUILD_PATH" /bin/bash -v -c 'sh /second_stage_install.sh'
  317. fi
  318. RET=$?
  319. if [ $RET -ne 0 ];then
  320. error "line $LINENO Warning : chrooting to $BUILD_PATH retrurn an error $RET"
  321. ERRORN=$((ERRORN++))
  322. fi
  323. info "unmounting dev, sys, proc"
  324. /bin/umount -lf "$BUILD_PATH/dev"
  325. if [ $? -ne 0 ];then
  326. warning "line $LINENO Warning : error unmounting $BUILD_PATH/dev, continuing anyway"
  327. ERRORN=$((ERRORN++))
  328. fi
  329. /bin/umount -lf "$BUILD_PATH/sys"
  330. if [ $? -ne 0 ];then
  331. warning "line $LINENO Warning : error unmounting $BUILD_PATH/sys, continuing anyway"
  332. ERRORN=$((ERRORN++))
  333. fi
  334. /bin/umount -lf "$BUILD_PATH/proc"
  335. if [ $? -ne 0 ];then
  336. warning "line $LINENO Warning : error unmounting $BUILD_PATH/proc, continuing anyway"
  337. ERRORN=$((ERRORN++))
  338. fi
  339. }
  340. function verify_disk_space()
  341. {
  342. title "Verifying if there is enough space on disk to make the image"
  343. DISK_SPACE=$(/usr/bin/df -BG --output=avail "$INSTALL_PATH" | sed '1d;s/[^0-9]//g')
  344. info "Free disk space: ${DISK_SPACE}G"
  345. if [ $DISK_SPACE -lt $IMAGE_SIZE ];then
  346. warning "image size is greater than disk space"
  347. info "correct the problem and relaunch the script with parameter --create-rpi-image"
  348. info "$0 --size $IMAGE_SIZE --create-rpi-image"
  349. return 1
  350. fi
  351. return 0
  352. }
  353. function createxu3image()
  354. {
  355. title "Creating Odroid XU3-XU4 image"
  356. createimage
  357. if [ -z "$BOOTFS" ];then
  358. BOOTFS="ext4"
  359. fi
  360. formatpartitions "$BOOTFS" ext4
  361. copyingsystem
  362. }
  363. function createrpiimage()
  364. {
  365. title "Creating Pi image"
  366. if ! [ -d "$FIRMWARE_PATH/$FIRMWARE_DIR" ];then # the firmware directory does not exists
  367. echo "$(ls *.zip| wc -l)"
  368. if [ "$(ls *.zip| wc -l)" -eq 0 ];then # the firmware archive does not exists
  369. warning "The raspberry pi firmware need to be downloaded"
  370. info "Downloading FIRMWARE_FILENAME"
  371. wget $FIRMWARE_DOWNLOAD_URL
  372. if [ $? -ne 0 ];then
  373. error "line $LINENO error downloading raspberry firmware at $FIRMWARE_DOWNLOAD_URL :exiting"
  374. exit 1
  375. fi
  376. fi
  377. info "extracting firmware"
  378. unzip -d "$FIRMWARE_PATH" *.zip
  379. if [ $? -ne 0 ];then
  380. error "line $LINENO error unzipping $FIRMWARE_PATH : exiting"
  381. exit 1
  382. fi
  383. fi
  384. title "Making raspberry pi image"
  385. createimage
  386. if [ -z $BOOTFS ];then
  387. BOOTFS="vfat"
  388. fi
  389. formatpartitions $BOOTFS ext4
  390. copyingsystem
  391. }
  392. createimage()
  393. {
  394. title " in $IMAGE"
  395. if [ -f "$INSTALL_PATH/$IMAGE" ];then
  396. warning "Deleting previous image"
  397. /bin/rm -f "$INSTALL_PATH/$IMAGE"
  398. if [ $? -ne 0 ];then
  399. error "line $LINENO error can't remove previous image at $INSTALL_PATH/$IMAGE : exiting"
  400. exit 1
  401. fi
  402. fi
  403. warning "please wait until end of image creation"
  404. /bin/dd if=/dev/zero of="$INSTALL_PATH/$IMAGE" bs=1MB count=$(( $IMAGE_SIZE * 1024 ))
  405. if [ $? -ne 0 ];then
  406. error "line $LINENO can't make image at $INSTALL_PATH/$IMAGE : exiting"
  407. exit 1
  408. fi
  409. DEVICE=$(/sbin/losetup -f --show "$INSTALL_PATH/$IMAGE")
  410. if [ $TARGET = "odroid" ];then
  411. info "installing blobs"
  412. pushd "$CONFIG_PATH/sd_fuse"
  413. if [ $? -ne 0 ];then
  414. error "line $LINENO error directory $CONFIG_PATH/sd_fuse does not exists : exiting"
  415. exit 1
  416. else
  417. ./sd_fusing.sh "$DEVICE"
  418. fi
  419. pushd
  420. fi
  421. info "making partitions"
  422. /sbin/fdisk "$DEVICE" << EOF
  423. n
  424. p
  425. 1
  426. +128M
  427. t
  428. c
  429. n
  430. p
  431. 2
  432. a
  433. 1
  434. a
  435. 2
  436. w
  437. EOF
  438. # Activate loop device
  439. /sbin/losetup -d "$DEVICE"
  440. DEVICE=$(/sbin/partx -va "$INSTALL_PATH/$IMAGE" | /bin/grep -m 1 -E -o '/dev/loop.?')
  441. info "device $DEVICE"
  442. info "partitions list:"
  443. info "$(/sbin/partx -v "$INSTALL_PATH/$IMAGE")"
  444. BOOTP="${DEVICE}p1"
  445. ROOTP="${DEVICE}p2"
  446. }
  447. formatpartitions()
  448. {
  449. info "Formatting partitions"
  450. info "Boot : $BOOTP as $1"
  451. "/sbin/mkfs.$1" "$BOOTP"
  452. if [ $? -ne 0 ];then
  453. error "line $LINENO error formating $BOOTP : exiting"
  454. /sbin/losetup -d "$DEVICE"
  455. exit 1
  456. fi
  457. info "Root : $ROOTP as $2"
  458. "/sbin/mkfs.$2" "$ROOTP"
  459. if [ $? -ne 0 ];then
  460. error "line $LINENO error formating $ROOTP : exiting"
  461. /sbin/losetup -d "$DEVICE"
  462. exit 1
  463. fi
  464. BOOT_UUID=$(blkid -s UUID -o value UUID "$BOOTP")
  465. info "Boot UUID: $BOOT_UUID"
  466. ROOT_UUID=$(blkid -s UUID -o value UUID "$ROOTP")
  467. info "Root UUID: $ROOT_UUID"
  468. }
  469. copyingsystem()
  470. {
  471. info "mounting partitions, making mountpoint if necessary"
  472. if ! [ -d "$BOOT" ];then
  473. /bin/mkdir "$BOOT"
  474. if [ $? -ne 0 ];then
  475. error "line $LINENO error making directory $BOOT : exiting"
  476. exit 1
  477. fi
  478. fi
  479. if ! [ -d "$ROOT" ];then
  480. /bin/mkdir "$ROOT"
  481. if [ $? -ne 0 ];then
  482. error "line $LINENO error making directory $ROOT : exiting"
  483. exit 1
  484. fi
  485. fi
  486. /bin/mount "$BOOTP" "$BOOT"
  487. if [ $? -ne 0 ];then
  488. error "line $LINENO error mounting $BOOTP : exiting"
  489. exit 1
  490. fi
  491. /bin/mount "$ROOTP" "$ROOT"
  492. if [ $? -ne 0 ];then
  493. error "line $LINENO error mounting $ROOTP : exiting"
  494. exit 1
  495. fi
  496. info "making /etc/fstab"
  497. echo "proc /proc proc defaults 0 0
  498. UUID=$BOOT_UUID /mnt/arm_boot vfat defaults 0 0
  499. UUID=$ROOT_UUID / ext4 defaults 0 0" > "$BUILD_PATH"/etc/fstab
  500. if [ ! -d "$BUILD_PATH/boot/extlinux" ];then
  501. info "making /boot/extlinux/extlinux.conf"
  502. mkdir -p "$BUILD_PATH/boot/extlinux"
  503. fi
  504. if [ ! -f "$BUILD_PATH/boot/extlinux/extlinux.conf" ];then
  505. sed -e s/\<UUID\>/$ROOT_UUID/g $CONFIG_PATH/extlinux.conf >"$BUILD_PATH/boot/extlinux/extlinux.conf"
  506. KERNEL_ID=`basename $BUILD_PATH/usr/lib/linux-*`
  507. sed -i -e s/\<FDTDIR\>/$KERNEL_ID/g "$BUILD_PATH/boot/extlinux/extlinux.conf"
  508. fi
  509. case $TARGET in
  510. rpi)
  511. info "copying 10-vchiq-permissions.rules"
  512. cp --preserve=mode "$CONFIG_PATH/10-vchiq-permissions.rules" "$BUILD_PATH/etc/udev/rules.d/"
  513. info "Making /etc/modules"
  514. echo "vchiq
  515. snd_bcm2835
  516. vc4
  517. brcmfmac" >> "$BUILD_PATH"/etc/modules
  518. ARM_BOOT="$BUILD_PATH/mnt/arm_boot"
  519. if ! [ -d "$ARM_BOOT" ];then
  520. mkdir -p "$ARM_BOOT"
  521. fi
  522. info "copying modprobe.conf"
  523. /usr/bin/cp -v --preserve=mode "$CONFIG_PATH/modprobe.conf" "$BUILD_PATH/etc/"
  524. chown root:root "$BUILD_PATH/etc/modprobe.conf"
  525. info "copying firmware, overlays in rpi boot partition"
  526. # cp -v --preserve=mode "$BUILD_PATH/usr/lib/linux-"* "$BOOT/dtb"
  527. cp -v --preserve=mode "$FIRMWARE_PATH/$FIRMWARE_DIR/boot/start"* "$ARM_BOOT/"
  528. cp -v --preserve=mode "$FIRMWARE_PATH/$FIRMWARE_DIR/boot/fixup"* "$ARM_BOOT/"
  529. cp -v --preserve=mode "$FIRMWARE_PATH/$FIRMWARE_DIR/boot/bootcode.bin"* "$ARM_BOOT/"
  530. cp -vR --preserve=mode "$FIRMWARE_PATH/$FIRMWARE_DIR/boot/overlays" "$ARM_BOOT/"
  531. info "copying u-boot binary to $ARM_BOOT"
  532. case $TARGET_VERSION in
  533. 2)
  534. info "copying u-boot for $TARGET 2"
  535. cp --preserve=mode "$BUILD_PATH/usr/lib/u-boot/rpi_2/u-boot.bin" "$ARM_BOOT/kernel.img"
  536. ;;
  537. 0)
  538. info "copying u-boot for $TARGET 0"
  539. cp --preserve=mode "$BUILD_PATH/usr/lib/u-boot/rpi_0_w/u-boot.bin" "$ARM_BOOT/kernel.img"
  540. ;;
  541. 1)
  542. info "copying u-boot for $TARGET 1"
  543. cp --preserve=mode "$BUILD_PATH/usr/lib/u-boot/rpi/u-boot.bin" "$ARM_BOOT/kernel.img"
  544. ;;
  545. 3_32)
  546. info "copying u-boot for $TARGET 3 32 bits"
  547. cp --preserve=mode "$BUILD_PATH/usr/lib/u-boot/rpi_3_32b/u-boot.bin" "$ARM_BOOT/kernel.img"
  548. ;;
  549. 3+)
  550. info "copying u-boot for $TARGET 3b+ 32 bits"
  551. cp --preserve=mode "$BUILD_PATH/usr/lib/u-boot/rpi_3_32b/u-boot.bin" "$ARM_BOOT/kernel.img"
  552. ;;
  553. esac
  554. # info "copying raspberry optionals files in opt"
  555. # /bin/rsync -rlptDH "$FIRMWARE_PATH/$FIRMWARE_DIR/opt/" "$BUILD_PATH/opt/"
  556. info "copying wifi firmware file missing in kernel-firmware-nonfree"
  557. if ! [ -d "$ROOT/usr/lib/firmware/brcm/" ];then
  558. /bin/mkdir -p "$ROOT/usr/lib/firmware/brcm/"
  559. fi
  560. if ! [ -f "$ROOT/usr/lib/firmware/brcm/brcmfmac434"* ];then
  561. /bin/cp --preserve=mode "$CONFIG_PATH/brcmfmac434"* "$ROOT/usr/lib/firmware/brcm/"
  562. if [ $? -ne 0 ];then
  563. error "line $LINENO error copying wifi firmware in $ROOTP/usr/lib/firmware/brcm/ : exiting"
  564. exit 1
  565. fi
  566. fi
  567. info "copying Mageia image to root partition"
  568. /bin/rsync -rlptogDH --exclude "$ARM_BOOT/" --exclude "qemu-arm-static*" "$BUILD_PATH/" "$ROOT/"
  569. /bin/rsync -rlptogDH "$ARM_BOOT/" "$BOOT/"
  570. ;;
  571. odroid)
  572. ODROID_BOOT="$BUILD_PATH/mnt/odroid_boot"
  573. if ! [ -d "$ODROID_BOOT" ];then
  574. mkdir -p "$ODROID_BOOT"
  575. fi
  576. case $TARGET_VERSION in
  577. xu4)
  578. info "copying u-boot for $TARGET $TARGET_VERSION"
  579. cp --preserve=mode "$BUILD_PATH/usr/lib/u-boot/$TARGET-$TARGET_VERSION/u-boot.bin" "$ARM_BOOT/"
  580. ;;
  581. esac
  582. # temporary code waiting inclusion of xu4 in Mageia kernel and u-boot
  583. info "Copying extlinux.conf on $ODROID_BOOT"
  584. cp --preserve=mode -R "$BUILD_PATH/boot/extlinux" "$ODROID_BOOT/"
  585. info "copying Mageia image to root partition"
  586. /bin/rsync -rlptogDH --exclude "$ODROID_BOOT/" --exclude "qemu-arm-static*" "$BUILD_PATH/" "$ROOT/"
  587. /bin/rsync -rlptogDH "$ODROID_BOOT/" "$BOOT/"
  588. ;;
  589. esac
  590. # info "copying tools in /usr/local/bin/"
  591. # /bin/cp -v --preserve=mode "$SOURCE_PATH/tools/" "$BUILD_PATH/usr/local/bin/"
  592. # if ! [ $? -eq 0 ];then
  593. # error "line $LINENO error copying tools"
  594. # ERRORN=$((ERRORN++))
  595. # fi
  596. # /bin/mkdir "$ROOT/boot"
  597. copyingcommon
  598. # Syncing devices before unmounting
  599. /usr/bin/sync
  600. /usr/bin/umount "$BOOT" "$ROOT"
  601. if [ $? -eq 0 ];then
  602. /bin/rmdir "$BOOT" "$ROOT"
  603. else
  604. error "line $LINENO error unmounting $ROOT or $BOOT : exiting"
  605. exit 1
  606. fi
  607. /usr/sbin/partx -d "$DEVICE"
  608. if [ $? -ne 0 ];then
  609. error "line $LINENO warning : error unmounting $DEVICE "
  610. exit 1
  611. fi
  612. warning "You can now burn the image ( $INSTALL_PATH/$IMAGE ) on SD card"
  613. }
  614. # Copying files common to all systems
  615. copyingcommon()
  616. {
  617. title "Copying common files and configuration"
  618. rsync -rlptDH "$SOURCE_PATH/common/" "$ROOT/"
  619. rsync -rlptDH "$SOURCE_PATH/tools/"*.sh "$ROOT/usr/local/bin/"
  620. chown root:root "$ROOT/usr/local/bin/"
  621. }
  622. if [ $# == 0 ];then
  623. help
  624. exit
  625. fi
  626. # parsing commandline
  627. TEMP=$(getopt -o h,a --long all,help,clean,create-chroot,addmedia,create-image,,config:,target:,target-version:,chroot,bootfs:,install-basesystem,update-mirror,build-path:,size:,nonfree,tainted -n $CMDNAME -- "$@")
  628. if [ $? -ne 0 ] ; then error "line $LINENO Failed parsing options." >&2 ; exit 1 ; fi
  629. eval set -- "$TEMP"
  630. echo "$TEMP"
  631. # Note the quotes around `$TEMP': they are essential!
  632. while true;
  633. do
  634. case "$1" in
  635. -h|--help)
  636. help
  637. exit 0
  638. ;;
  639. -a|--all)
  640. OPT="all"
  641. shift 1
  642. ;;
  643. --clean)
  644. OPT="clean"
  645. shift
  646. ;;
  647. --size)
  648. IMAGE_SIZE_P=$2
  649. shift 2
  650. ;;
  651. --build-path)
  652. INSTALL_PATH_P="$2"
  653. shift 2
  654. ;;
  655. --chroot)
  656. if [ -z $OPT ];then
  657. OPT="chroot"
  658. fi
  659. shift
  660. ;;
  661. --create-chroot)
  662. if [ -z $OPT ];then
  663. OPT="createchroot"
  664. fi
  665. shift
  666. ;;
  667. --addmedia)
  668. if [ -z $OPT ];then
  669. OPT="addmedia"
  670. fi
  671. shift
  672. ;;
  673. --update-mirror)
  674. if [ -z $OPT ];then
  675. OPT="updatemirror"
  676. fi
  677. shift
  678. ;;
  679. --install-basesystem)
  680. if [ -z $OPT ];then
  681. OPT="installbasesystem"
  682. fi
  683. shift
  684. ;;
  685. --create-image)
  686. if [ -z $OPT ];then
  687. CREATEIMAGE=true
  688. OPT="createimage"
  689. fi
  690. shift
  691. ;;
  692. --target)
  693. TARGET_P=$2
  694. shift 2
  695. ;;
  696. --target-version)
  697. TARGET_VERSION_P=$2
  698. shift 2
  699. ;;
  700. --config)
  701. CONFIG_PATH="$PLATFORMS_PATH/$2"
  702. shift 2
  703. ;;
  704. --bootfs)
  705. BOOTFS_P=$2
  706. shift 2
  707. ;;
  708. --nonfree)
  709. NONFREE_P=1
  710. shift
  711. ;;
  712. --tainted)
  713. TAINTED_P=1
  714. shift
  715. ;;
  716. --)
  717. shift
  718. break;;
  719. *)
  720. error "Parameter $1 does not exists "
  721. exit 1;;
  722. esac
  723. done
  724. # path of config file
  725. if ! [ -d "$CONFIG_PATH" ];then
  726. info " Config path does not exists, defaulting to ./platforms/$TARGET"
  727. CONFIG_PATH="$PLATFORMS_PATH/$TARGET"
  728. warning "Do you want i make it and copy the template file in? [Y|n] "
  729. read yn
  730. if [ -z $yn ] || [ $yn = "Y" ] || [ $yn = "y" ];then
  731. /usr/bin/mkdir "$CONFIG_PATH/"
  732. /usr/bin/cp --preserve=mode "$SOURCE_PATH/config.template" "$CONFIG_PATH/mageia4arm.cfg"
  733. warning "You need now to modify the config file ($CONFIG_PATH/mageia4arm.cfg) and relaunch the script"
  734. exit 2
  735. else
  736. error "Error: Can't continue without config file, exiting"
  737. exit 3
  738. fi
  739. fi
  740. if [ -e "$CONFIG_PATH/mageia4arm.cfg" ];then
  741. info "using $CONFIG_PATH/mageia4arm.cfg as config"
  742. . "$CONFIG_PATH/mageia4arm.cfg"
  743. else
  744. warning "Config file does not exists, do you want i copy template ? [Y|n] "
  745. read yn
  746. if [ -z $yn ] || [ $yn = "Y" ] || [ $yn = "y" ];then
  747. /usr/bin/cp --preserve=mode "$SOURCE_PATH/mageia4arm.cfg.template" "$CONFIG_PATH/mageia4arm.cfg"
  748. warning "You need now to modify the config file ($CONFIG_PATH/mageia4arm.cfg) and relaunch the script"
  749. exit 2
  750. fi
  751. fi
  752. if ! [ -z "$IMAGE_SIZE_P" ];then
  753. IMAGE_SIZE=$IMAGE_SIZE_P
  754. fi
  755. if ! [ -z "$INSTALL_PATH_P" ];then
  756. INSTALL_PATH=$INSTALL_PATH_P
  757. fi
  758. if ! [ -z "$TARGET_P" ];then
  759. TARGET=$TARGET_P
  760. fi
  761. if ! [ -z "$TARGET_VERSION_P" ];then
  762. TARGET_VERSION=$TARGET_VERSION_P
  763. fi
  764. if ! [ -z "$BOOTFS_P" ];then
  765. BOOTFS=$BOOTFS_P
  766. fi
  767. if ! [ -z "$NONFREE_P" ];then
  768. NONFREE=$NONFREE_P
  769. fi
  770. if ! [ -z "$TAINTED_P" ];then
  771. TAINTED=$TAINTED_P
  772. fi
  773. info "Option: "$OPT
  774. IMAGE="Mageia-${MAGEIA_VERSION}-$TARGET$TARGET_VERSION.img"
  775. BOOT="/mnt/boot"
  776. ROOT="/mnt/root"
  777. BUILD_PATH="$INSTALL_PATH/build"
  778. ARM_VERSION="armv7hl"
  779. # assign function for building image of TARGET ( rpi, odroid )
  780. case $TARGET in
  781. odroid)
  782. CREATEIMG="createxu3image"
  783. ;;
  784. rpi)
  785. CREATEIMG="createrpiimage"
  786. ;;
  787. *)
  788. error "No Target : $TARGET"
  789. exit 1
  790. ;;
  791. esac
  792. info "target : $TARGET"
  793. info "target_version : $TARGET_VERSION"
  794. info "source path: $SOURCE_PATH"
  795. info "Install path: $INSTALL_PATH"
  796. info "Build path: $BUILD_PATH"
  797. info "Commande : $CMDNAME"
  798. info "Firmware path : $FIRMWARE_PATH"
  799. info "Firmware dir : $FIRMWARE_DIR"
  800. # Defining default image size to 7 go
  801. if [[ "$IMAGE_SIZE" -lt 7 ]] || [[ "$IMAGE_SIZE" -gt 128 ]];then
  802. IMAGE_SIZE=7
  803. fi
  804. # change dir to install path and create it if not existing
  805. if [ "$OPT" != "clean" ];then
  806. info "cd $INSTALL_PATH"
  807. if ! [ -e "$INSTALL_PATH" ];then
  808. /bin/mkdir -p "$INSTALL_PATH"
  809. if [ -z $? ];then
  810. error "line $LINENO can't make directory $INSTALL_PATH , exiting"
  811. exit 1
  812. fi
  813. fi
  814. cd "$INSTALL_PATH"
  815. if [ -z $? ];then
  816. error "line $LINENO can't change to directory $INSTALL_PATH , exiting"
  817. exit 1
  818. fi
  819. fi
  820. #if no parameters then display help message
  821. if [ -z $OPT ];then
  822. OPT="--help"
  823. fi
  824. info "Image size is: $IMAGE_SIZE Go"
  825. case $OPT in
  826. clean)
  827. clean
  828. ;;
  829. all)
  830. verify_disk_space
  831. if [ $? -eq 1 ];then
  832. echo -e "Not enough space on disk\nDo you want to continue anyway ? [Y,n]"
  833. read yn
  834. if [ $yn = "n" ];then
  835. exit 6
  836. fi
  837. fi
  838. createchroot
  839. addmedia
  840. updatemirror
  841. installbasesystem
  842. preparechroot
  843. jumpchroot
  844. $CREATEIMG
  845. ;;
  846. createchroot)
  847. createchroot
  848. ;;
  849. chroot)
  850. jumpchroot
  851. ;;
  852. addmedia)
  853. addmedia
  854. ;;
  855. updatemirror)
  856. updatemirror
  857. ;;
  858. createimage)
  859. verify_disk_space
  860. if [ $? -eq 1 ];then
  861. warning "Not enough space on disk"
  862. exit 6
  863. fi
  864. $CREATEIMG
  865. ;;
  866. installbasesystem)
  867. installbasesystem
  868. ;;
  869. esac
  870. if ! [ -z $ERRORN ];then
  871. warning "Some errors occurs : $ERRORN errors"
  872. fi