create_arm_image.sh 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106
  1. #!/usr/bin/bash
  2. # Copyright (C) 2017-2018 Daniel Tartavel-jeannot <contact@librepc.com>
  3. # Jean-Baptiste Biernacki <j.biernacki@free.fr>
  4. # Copyright (C) 2020 Neal Gompa <ngompa13@gmail.com>
  5. #
  6. # This program is free software; you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation; either version 2 of the License,dnf or
  9. # (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. #Change the local to the most global
  19. export LC_ALL=C
  20. function WaitToContinue() {
  21. read -p "Break... Press [ENTER] to continue." GARBAGE
  22. }
  23. function title() {
  24. echo -e "\e[1;32m${1}\e[0m"
  25. }
  26. function info() {
  27. echo -e "\e[36m${1}\e[0m"
  28. }
  29. function warning() {
  30. echo -e "\e[1;35m${1}\e[0m"
  31. }
  32. function error() {
  33. echo -e "\e[1;31m${1}\e[0m"
  34. }
  35. function help() {
  36. echo -e "${CMDNAME} [option] [size of image in Go]"
  37. echo -e "Options:"
  38. echo -e "--all create ready to burn image of Mageia ${MAGEIA_VERSION}"
  39. echo -e "--clean Clean all (suppress all) to make a new image"
  40. echo -e "--size size of image default: 7Go"
  41. echo -e "--build-path Path to the build directory of the image of Mageia ${MAGEIA_VERSION}"
  42. echo -e "--target target system (for now rpi, odroid)"
  43. echo -e "--target-version version of the target (0, 1, 2, 3 for rpi, 3 or 4 for odroid)"
  44. echo -e "--config Path to config files"
  45. echo -e "--bootfs filesystem of boot partition (ext4 or vfat) default: ext4"
  46. echo -e "--nonfree activate nonfree repos"
  47. echo -e "--tainted activate tainted repos"
  48. echo -e "\nBuild levels:"
  49. echo -e "--create-chroot Create the chroot directory"
  50. echo -e "--install-basesystem install base system"
  51. echo -e "--add-urpmimedia add mirrors for urpmi"
  52. echo -e "--chroot chroot to arm directory and launch packages installation"
  53. echo -e "--create-image Create the image of Mageia ${MAGEIA_VERSION}"
  54. echo "--config Path to config files (rpi1 rpi2 rpi3 rpi3+ xu4)"
  55. echo -e "\nFor image size, make sure it fit on physical support. (Default size is 7 Go)"
  56. }
  57. function verify_disk_space()
  58. {
  59. title "Verifying if there is enough space on disk to make the image"
  60. DISK_SPACE=$(/usr/bin/df -BG --output=avail "${INSTALL_PATH}" | sed '1d;s/[^0-9]//g')
  61. info "Free disk space: ${DISK_SPACE}G"
  62. if [ ${DISK_SPACE} -lt ${IMAGE_SIZE} ]; then
  63. warning "image size is greater than disk space"
  64. info "correct the problem and relaunch the script with parameter --create-rpi-image"
  65. info "${0} --size ${IMAGE_SIZE} --create-rpi-image"
  66. return 1
  67. fi
  68. return 0
  69. }
  70. # creation of install path and copy of qemu ( installing it if not yet installed )
  71. function createchroot()
  72. {
  73. title "Making chroot"
  74. if ! [ -f /usr/share/distribution-gpg-keys/mageia/RPM-GPG-KEY-Mageia ]; then
  75. title "distribution-gpg-keys package not present : installing distribution-gpg-keys"
  76. #/usr/bin/dnf --assumeyes --setopt=install_weak_deps=False install distribution-gpg-keys
  77. installpkg "distribution-gpg-keys" "--setopt=install_weak_deps=False"
  78. if [ ${?} -ne 0 ]; then
  79. error "line ${LINENO} can't install distribution-gpg-keys : exiting"
  80. exit ${ERR_1}
  81. fi
  82. fi
  83. if ! [ -f /usr/bin/qemu-arm-static ]; then
  84. title "Qemu package not present : installing qemu packages"
  85. #/usr/bin/dnf --assumeyes --setopt=install_weak_deps=False install qemu-user-static
  86. installpkg "qemu-user-static" "--setopt=install_weak_deps=False"
  87. if [ ${?} -ne 0 ]; then
  88. error "line ${LINENO} can't install qemu-user-static : exiting"
  89. exit ${ERR_1}
  90. fi
  91. fi
  92. # Starting qemu service if not started
  93. /usr/bin/systemctl is-active systemd-binfmt.service
  94. if [ ${?} -ne 0 ]; then
  95. title "Starting systemd-binfmt.service"
  96. /usr/bin/systemctl start systemd-binfmt.service
  97. if [ ${?} -ne 0 ]; then
  98. error "line ${LINENO} can't start qemu-user-static : exiting"
  99. exit ${ERR_1}
  100. fi
  101. else
  102. title "Restarting systemd-binfmt.service"
  103. /usr/bin/systemctl restart systemd-binfmt.service
  104. if [ ${?} -ne 0 ]; then
  105. error "line ${LINENO} can't start qemu-user-static : exiting"
  106. exit ${ERR_1}
  107. fi
  108. fi
  109. return 0
  110. }
  111. # enabling extra Mageia repositories
  112. function genusemirroroptions()
  113. {
  114. DNF_MIRROROPTS="--config=${DNF_CONFIGPATH} --forcearch=${ARM_VERSION} --nogpgcheck --releasever=${MAGEIA_VERSION}"
  115. if [ ! -z "${MIRROR}" ]; then
  116. DNF_MIRROROPTS="${DNF_MIRROROPTS} --disablerepo=* --repofrompath=mgarel,${MIRROR}/media/core/release/ --enablerepo=mgarel"
  117. if [ "${MAGEIA_VERSION}" != "cauldron" ]; then
  118. DNF_MIRROROPTS="${DNF_MIRROROPTS} --repofrompath=mgaup,${MIRROR}/media/core/updates/ --enablerepo=mgaup"
  119. fi
  120. if [ ${NONFREE} -eq 1 ]; then
  121. DNF_MIRROROPTS="${DNF_MIRROROPTS} --repofrompath=mgarel-nonfree,${MIRROR}/media/nonfree/release/ --enablerepo=mgarel-nonfree "
  122. if [ "${MAGEIA_VERSION}" != "cauldron" ]; then
  123. DNF_MIRROROPTS="${DNF_MIRROROPTS} --repofrompath=mgaup-nonfree,${MIRROR}/media/nonfree/updates/ --enablerepo=mgaup-nonfree"
  124. fi
  125. fi
  126. if [ ${TAINTED} -eq 1 ]; then
  127. DNF_MIRROROPTS="${DNF_MIRROROPTS} --repofrompath=mgarel-tainted,${MIRROR}/media/tainted/release/ --enablerepo=mgarel-tainted "
  128. if [ "${MAGEIA_VERSION}" != "cauldron" ]; then
  129. DNF_MIRROROPTS="${DNF_MIRROROPTS} --repofrompath=mgaup-tainted,${MIRROR}/media/tainted/updates/ --enablerepo=mgaup-tainted"
  130. fi
  131. fi
  132. fi
  133. export DNF_MIRROROPTS
  134. return 0
  135. }
  136. # enabling extra Mageia repositories
  137. function enableextrarepos()
  138. {
  139. extrasect_baseprefix="mageia"
  140. # if [ "${MAGEIA_VERSION}" = "cauldron" ]; then
  141. # extrasect_baseprefix="cauldron"
  142. # extrasect_updatesprefix=""
  143. # else
  144. # extrasect_baseprefix="mageia"
  145. extrasect_updatesprefix="updates"
  146. # fi
  147. if [ ${NONFREE} -eq 1 ]; then
  148. title "activating non-free repos"
  149. DNFPARAM=--installroot="${BUILD_PATH}" config-manager --set-enabled "${extrasect_baseprefix}-${ARM_VERSION}-nonfree"
  150. if [ "${MAGEIA_VERSION}" != "cauldron" ]; then
  151. DNFPARAM=$DNFPARAM" --set-enabled ${extrasect_updatesprefix}-${ARM_VERSION}-nonfree"
  152. fi
  153. /usr/bin/dnf $DNFPARAM
  154. err=${?}
  155. if [ ${err} -ne 0 ]; then
  156. error "line ${LINENO} error ${err} - can't activate nonfree repositories : exiting"
  157. exit ${ERR_1}
  158. fi
  159. fi
  160. if [ ${TAINTED} -eq 1 ]; then
  161. title "activating tainted repos"
  162. DNFPARAM=--installroot="${BUILD_PATH}" config-manager --set-enabled "${extrasect_baseprefix}-${ARM_VERSION}-tainted"
  163. if [ "${MAGEIA_VERSION}" != "cauldron" ]; then
  164. DNFPARAM=$DNFPARAM" --set-enabled ${extrasect_updatesprefix}-${ARM_VERSION}-tainted"
  165. fi
  166. /usr/bin/dnf $DNFPARAM
  167. err=${?}
  168. if [ ${err} -ne 0 ]; then
  169. error "line ${LINENO} error ${err} - can't activate tainted repositories : exiting"
  170. exit ${ERR_1}
  171. fi
  172. fi
  173. return 0
  174. }
  175. # adding Mageia urpmi repositories
  176. function addurpmimedia()
  177. {
  178. title "Creating media ${MIRROR}"
  179. info "Removing old media"
  180. /sbin/urpmi.removemedia --urpmi-root "${BUILD_PATH}" -a
  181. info "Adding media"
  182. if [ ! -z "${MIRROR}" ] ; then
  183. /sbin/urpmi.addmedia --urpmi-root "${BUILD_PATH}" --distrib "${MIRROR}"
  184. else
  185. info "MIRROR variable not set, using mirrorlist."
  186. /sbin/urpmi.addmedia --urpmi-root "${BUILD_PATH}" --distrib --mirrorlist "http://mirrors.mageia.org/api/mageia.${MAGEIA_VERSION}.${ARM_VERSION}.list"
  187. fi
  188. err=${?}
  189. if [ ${err} -ne 0 ]; then
  190. error "line ${LINENO} error ${err} - can't add medias from ${MIRROR} : exiting"
  191. exit ${ERR_1}
  192. fi
  193. if [ ${NONFREE} -eq 1 ]; then
  194. title "activating non-free repos"
  195. /sbin/urpmi.update --urpmi-root "${BUILD_PATH}" --no-ignore Nonfree\ Release Nonfree\ Updates
  196. err=${?}
  197. if [ ${err} -ne 0 ]; then
  198. error "line ${LINENO} error ${err} - can't activate medias nonfree : exiting"
  199. exit ${ERR_1}
  200. fi
  201. fi
  202. if [ ${TAINTED} -eq 1 ]; then
  203. title "activating tainted repos"
  204. /sbin/urpmi.update --urpmi-root "${BUILD_PATH}" --no-ignore Tainted\ Release Tainted\ Updates
  205. err=${?}
  206. if [ ${err} -ne 0 ]; then
  207. error "line ${LINENO} error ${err} - can't activate medias tainted : exiting"
  208. exit ${ERR_1}
  209. fi
  210. fi
  211. return 0
  212. }
  213. function installbasesystem()
  214. {
  215. # Create Build path
  216. if ! [ -d "${BUILD_PATH}" ]; then
  217. warning "Build path ( ${BUILD_PATH} ) does not exist, do you want to create it ? [Y|n] "
  218. read yn
  219. if [ -z ${yn} ] || [ ${yn} = "Y" ] || [ ${yn} = "y" ]; then
  220. title "Creating ${BUILD_PATH}"
  221. /usr/bin/mkdir -p "${BUILD_PATH}/usr/bin" "${BUILD_PATH}/usr/lib/binfmt.d"
  222. if [ ${?} -ne 0 ]; then
  223. error "line ${LINENO} can't create ${BUILD_PATH} : exiting"
  224. exit ${ERR_1}
  225. fi
  226. else
  227. exit ${ERR_1}
  228. fi
  229. else
  230. info "Build path exists"
  231. fi
  232. # Workaround mga#26044.
  233. info "Preparing root filesystem tree"
  234. mkdir -p "${BUILD_PATH}/usr/bin"
  235. mkdir -p "${BUILD_PATH}/usr/sbin"
  236. mkdir -p "${BUILD_PATH}/usr/lib"
  237. ln -sr "${BUILD_PATH}/usr/bin" "${BUILD_PATH}/bin"
  238. ln -sr "${BUILD_PATH}/usr/sbin" "${BUILD_PATH}/sbin"
  239. ln -sr "${BUILD_PATH}/usr/lib" "${BUILD_PATH}/lib"
  240. if [ "${ARM_VERSION}" = "aarch64" ]; then
  241. mkdir -p "${BUILD_PATH}/usr/lib64"
  242. ln -sr "${BUILD_PATH}/usr/lib64" "${BUILD_PATH}/lib64"
  243. fi
  244. title "installing basesystem"
  245. #/usr/bin/dnf --installroot="${BUILD_PATH}" ${DNF_MIRROROPTS} --assumeyes install shadow-utils basesystem-minimal
  246. installpkg "shadow-utils basesystem-minimal"
  247. if [ ${?} -ne 0 ]; then
  248. error "line ${LINENO} error installing shadow-utils or basesystem-minimal : exiting"
  249. exit ${ERR_1}
  250. fi
  251. #/usr/bin/dnf --installroot="${BUILD_PATH}" ${DNF_MIRROROPTS} --assumeyes install basesystem-minimal
  252. #if [ ${?} -ne 0 ]; then
  253. # error "line ${LINENO} error installing basesystem-minimal : exiting"
  254. # exit ${ERR_1}
  255. #fi
  256. if [ ${INSTALL_METHOD} = "urpmi" ]; then
  257. installpkg "urpmi locales"
  258. else
  259. installpkg "dnf dnf-plugins-core locales"
  260. fi
  261. #/usr/bin/dnf --installroot="${BUILD_PATH}" ${DNF_MIRROROPTS} --assumeyes install dnf dnf-plugins-core locales
  262. #if [ ${?} -ne 0 ]; then
  263. # error "line ${LINENO} error installing dnf or locales : exiting"
  264. # exit ${ERR_1}
  265. #fi
  266. #if [ "${ARM_VERSION}" = "aarch64" ]; then
  267. #/usr/bin/dnf --installroot="${BUILD_PATH}" ${DNF_MIRROROPTS} --assumeyes install u-boot
  268. # installpkg "/u-boot*"
  269. # if [ ${?} -ne 0 ]; then
  270. # error "line ${LINENO} error installing u-boot : exiting"
  271. # exit ${ERR_1}
  272. # fi
  273. #fi
  274. #/usr/bin/dnf --installroot="${BUILD_PATH}" ${DNF_MIRROROPTS} --assumeyes install urpmi
  275. #installpkg "urpmi"
  276. #if [ ${?} -ne 0 ]; then
  277. # error "line ${LINENO} error installing urpmi : exiting"
  278. # exit ${ERR_1}
  279. #fi
  280. return 0
  281. }
  282. function installpkg()
  283. {
  284. if [ ${INSTALL_METHOD} = "urpmi" ]; then
  285. /usr/sbin/urpmi --urpmi-root "$BUILD_PATH" --ignorearch --no-verify-rpm --auto --split-level 200 --split-length 200 $3 $1;
  286. else
  287. /usr/bin/dnf $2 --installroot="${BUILD_PATH}" ${DNF_MIRROROPTS} --assumeyes install $1;
  288. fi
  289. }
  290. function preparechroot()
  291. {
  292. title "Preparing chrooting in ${BUILD_PATH}"
  293. info "making /etc/hostname"
  294. echo "${HOSTNAME}" > "${BUILD_PATH}/etc/hostname"
  295. info "copying second stage script in ${BUILD_PATH}"
  296. #echo "/usr/bin/cp ${CONFIG_PATH}/second_stage_install.sh ${BUILD_PATH}/"
  297. cp --preserve=mode "${CONFIG_PATH}/second_stage_install.sh" "${BUILD_PATH}/second_stage_install.sh"
  298. if [ ${?} -ne 0 ]; then
  299. error "line ${LINENO} error copying ${CONFIG_PATH}/second_stage_install.sh : exiting"
  300. exit ${ERR_1}
  301. fi
  302. info "configuring second_install_install.sh for ${INSTALL_METHOD}"
  303. if [ ${INSTALL_METHOD} = "urpmi" ]; then
  304. sed -i -e "s/<INSTALL_EXEC>/sbin\/urpmi --no-verify-rpm --auto/g" "${BUILD_PATH}/second_stage_install.sh"
  305. else
  306. sed -i -e "s/<INSTALL_EXEC>/bin\/dnf --nogpgcheck --assumeyes install/g" "${BUILD_PATH}/second_stage_install.sh"
  307. fi
  308. info "Preparation for setting root and user account"
  309. if [ -n "${ROOT_PWD}" ]; then #If root password defined, it will be setted at the end of the chroot of the second_stage_install.sh script
  310. echo -e "/usr/bin/passwd << EOF\n${ROOT_PWD}\n${ROOT_PWD}\nEOF\n" >>"${BUILD_PATH}/second_stage_install.sh"
  311. else
  312. info "No root password... One password will be set at the first login."
  313. echo -e "/usr/bin/passwd -d root\n/usr/bin/passwd -e root\n" >>"${BUILD_PATH}/second_stage_install.sh"
  314. fi
  315. if [ -n "${ID_USER}" ]; then #If user ID defined, it will be setted at the end of the chroot of the second_stage_install.sh script
  316. echo -e " /sbin/useradd ${ID_USER}\n" >>"${BUILD_PATH}/second_stage_install.sh"
  317. if [ -n "${PASSWORD}" ]; then
  318. echo -e "/usr/bin/passwd ${ID_USER} << EOF\n${PASSWORD}\n${PASSWORD}\nEOF" >>"${BUILD_PATH}/second_stage_install.sh"
  319. else
  320. echo -e "/usr/bin/passwd -d ${ID_USER}\n" >>"${BUILD_PATH}/second_stage_install.sh"
  321. fi
  322. else
  323. info "No user defined, no user account created."
  324. fi
  325. # BUG: This line break the default .bashrc file from the package "rootfiles" and the values as PATH (and /usr/sbin programs).
  326. # info "Copying skel in root directory"
  327. # /usr/bin/rsync -rlptH "${BUILD_PATH}/etc/skel/" "${BUILD_PATH}/root/"
  328. postPrepareChroot
  329. if [ ${?} -ne 0 ]; then
  330. error "line ${LINENO} error in postPrepareChroot function."
  331. exit ${ERR_1}
  332. fi
  333. return 0
  334. }
  335. function jumpchroot()
  336. {
  337. title "chrooting to ${BUILD_PATH}"
  338. info "mounting dev, sys, proc directories in chroot"
  339. /usr/bin/mount -B /dev "${BUILD_PATH}/dev"
  340. if [ ${?} -ne 0 ]; then
  341. error "line ${LINENO} error mounting ${BUILD_PATH}/dev : exiting"
  342. exit ${ERR_1}
  343. fi
  344. /usr/bin/mount -B /sys "${BUILD_PATH}/sys"
  345. if [ ${?} -ne 0 ]; then
  346. error "line ${LINENO} error mounting ${BUILD_PATH}/sys : exiting"
  347. exit ${ERR_1}
  348. fi
  349. /usr/bin/mount -B /proc "${BUILD_PATH}/proc"
  350. if [ ${?} -ne 0 ]; then
  351. error "line ${LINENO} error mounting ${BUILD_PATH}/proc : exiting"
  352. exit ${ERR_1}
  353. fi
  354. info "Copying resolv.conf"
  355. /usr/bin/cp -v --preserve=mode /etc/resolv.conf "${BUILD_PATH}/etc/"
  356. if [ ${?} -ne 0 ]; then
  357. error "line ${LINENO} error copying ${BUILD_PATH}/etc/resolv.conf : exiting"
  358. exit ${ERR_1}
  359. fi
  360. info "chrooting to ${BUILD_PATH}"
  361. if [ "$OPT" = "chroot" ]; then
  362. info "/sbin/chroot ${BUILD_PATH}"
  363. /sbin/chroot "${BUILD_PATH}"
  364. RET=${?}
  365. if [ ${RET} -ne 0 ]; then
  366. error "line ${LINENO} Warning : chrooting to ${BUILD_PATH} retrurn an error ${RET}"
  367. ERRORN=$((${ERRORN}+1))
  368. fi
  369. else
  370. info "/sbin/chroot --userspec root:root ${BUILD_PATH} /usr/bin/bash -v -c 'bash /second_stage_install.sh 2>&1'"
  371. /sbin/chroot --userspec root:root "${BUILD_PATH}" /usr/bin/bash -v -c 'bash /second_stage_install.sh 2>&1'
  372. RET=${?}
  373. if [ ${RET} -ne 0 ]; then
  374. error "line ${LINENO} Warning : chrooting to ${BUILD_PATH} retrurn an error ${RET}"
  375. ERRORN=$((${ERRORN}+1))
  376. fi
  377. fi
  378. info "unmounting dev, sys, proc"
  379. /usr/bin/umount -lf "${BUILD_PATH}/dev"
  380. if [ ${?} -ne 0 ]; then
  381. warning "line ${LINENO} Warning : error unmounting ${BUILD_PATH}/dev, continuing anyway"
  382. ERRORN=$((${ERRORN}+1))
  383. fi
  384. /usr/bin/umount -lf "${BUILD_PATH}/sys"
  385. if [ ${?} -ne 0 ]; then
  386. warning "line ${LINENO} Warning : error unmounting ${BUILD_PATH}/sys, continuing anyway"
  387. ERRORN=$((${ERRORN}+1))
  388. fi
  389. /usr/bin/umount -lf "${BUILD_PATH}/proc"
  390. if [ ${?} -ne 0 ]; then
  391. warning "line ${LINENO} Warning : error unmounting ${BUILD_PATH}/proc, continuing anyway"
  392. ERRORN=$((${ERRORN}+1))
  393. fi
  394. return 0
  395. }
  396. function createImageWrap()
  397. {
  398. title "Wrap image creation"
  399. preImgCreation
  400. if [ ${?} -ne 0 ]; then
  401. error "line ${LINENO} error in the process ${CONFIG_PATH}/specialFunctions.sh ."
  402. exit ${ERR_1}
  403. fi
  404. createimage
  405. if [ -z "${BOOTFS}" ]; then
  406. BOOTFS="ext4"
  407. fi
  408. formatpartitions ${BOOTFS} ext4
  409. return 0
  410. }
  411. function createimage()
  412. {
  413. title " in ${IMAGE}"
  414. if [ -f "${INSTALL_PATH}/${IMAGE}" ]; then
  415. warning "Deleting previous image"
  416. /usr/bin/rm -f "${INSTALL_PATH}/${IMAGE}"
  417. if [ ${?} -ne 0 ]; then
  418. error "line ${LINENO} error can't remove previous image at ${INSTALL_PATH}/${IMAGE} : exiting"
  419. exit ${ERR_1}
  420. fi
  421. fi
  422. warning "please wait until end of image creation"
  423. /usr/bin/dd if=/dev/zero of="${INSTALL_PATH}/${IMAGE}" bs=1MB count=$(( ${IMAGE_SIZE} * 1024 )) status=progress
  424. if [ ${?} -ne 0 ]; then
  425. error "line ${LINENO} can't make image at ${INSTALL_PATH}/${IMAGE} : exiting"
  426. exit ${ERR_1}
  427. fi
  428. loopingImage
  429. bunrningBootloader
  430. if [ ${?} -ne 0 ]; then
  431. error "line ${LINENO} error in the process ${CONFIG_PATH}/specialFunctions.sh ."
  432. exit ${ERR_1}
  433. fi
  434. info "making partitions"
  435. echo -e "${FDISK_SCRIPT}" | /sbin/fdisk ${DEVICE}
  436. #Activate 'pY' : /dev/loopXpY
  437. partx -vu "${DEVICE}"
  438. #Previous function give us a list of partition. It is easy to get it and define prior this list the partition.
  439. #But... How to distinguish between the boot p1 and the root p2 if both are empty and ext4 ? ...
  440. if [ 1 -eq ${SEPARATE_BOOT_PARTITION} ]; then
  441. BOOTP="${DEVICE}p1"
  442. ROOTP="${DEVICE}p2"
  443. else
  444. ROOTP="${DEVICE}p1"
  445. fi
  446. return 0
  447. }
  448. function loopingImage()
  449. {
  450. title "Looping image ..."
  451. # Mettre en place et contrôler des périphériques boucle.
  452. # -f, --find trouver le premier périphérique inutilisé
  453. # --show afficher le nom du périphérique après configuration (avec -f)
  454. DEVICE=$(/sbin/losetup -f --show "${INSTALL_PATH}/${IMAGE}")
  455. return 0
  456. }
  457. function formatpartitions()
  458. {
  459. info "Formatting partitions"
  460. if [ 1 -eq ${SEPARATE_BOOT_PARTITION} ]; then
  461. info "Boot : ${BOOTP} as ${1}"
  462. "/sbin/mkfs.${1}" "${BOOTP}"
  463. if [ ${?} -ne 0 ]; then
  464. error "line ${LINENO} error formating ${BOOTP} : exiting"
  465. /sbin/losetup -d "${DEVICE}"
  466. exit ${ERR_1}
  467. fi
  468. BOOT_UUID=$(blkid -s UUID -o value UUID "${BOOTP}")
  469. info "Boot UUID: ${BOOT_UUID}"
  470. fi
  471. info "Root : ${ROOTP} as ${2}"
  472. "/sbin/mkfs.${2}" "${ROOTP}"
  473. if [ ${?} -ne 0 ]; then
  474. error "line ${LINENO} error formating ${ROOTP} : exiting"
  475. /sbin/losetup -d "${DEVICE}"
  476. exit ${ERR_1}
  477. fi
  478. ROOT_UUID=$(blkid -s UUID -o value UUID "${ROOTP}")
  479. info "Root UUID: ${ROOT_UUID}"
  480. return 0
  481. }
  482. function generateExtlinux()
  483. {
  484. info "Generate extlinux if extlinux.conf exists."
  485. if [ -e "${CONFIG_PATH}/extlinux.conf" ]; then
  486. info "\tFound extlinux.conf"
  487. if [ ! -d "${BUILD_PATH}/boot/extlinux" ]; then
  488. info "making /boot/extlinux/extlinux.conf"
  489. /usr/bin/rm -rf "${BUILD_PATH}/boot/extlinux"
  490. mkdir -p "${BUILD_PATH}/boot/extlinux"
  491. fi
  492. if [ ! -f "${BUILD_PATH}/boot/extlinux/extlinux.conf" ]; then
  493. info "\tTuning extlinux.conf"
  494. cp "${CONFIG_PATH}/extlinux.conf" "${BUILD_PATH}/boot/extlinux/extlinux.conf"
  495. #In order to use the UUID, a initrd file is necessary.
  496. sed -i -e "s/<UUID>/${ROOT_UUID}/g" "${BUILD_PATH}/boot/extlinux/extlinux.conf"
  497. sed -i -e "s/<BOOT_ARGS>/${BOOT_ARGS}/g" "${BUILD_PATH}/boot/extlinux/extlinux.conf"
  498. KERNEL_ID=$(basename ${BUILD_PATH}/usr/lib/linux-*)
  499. sed -i -e "s/<FDTDIR>/${KERNEL_ID}/g" "${BUILD_PATH}/boot/extlinux/extlinux.conf"
  500. fi
  501. fi
  502. }
  503. function copyingsystem()
  504. {
  505. generateExtlinux
  506. info "Remove second_stage_install.sh"
  507. /usr/bin/rm -f "${BUILD_PATH}/second_stage_install.sh"
  508. if [ 1 -eq ${SEPARATE_BOOT_PARTITION} ]; then
  509. ARM_BOOT="${BUILD_PATH}/mnt/arm_boot"
  510. if ! [ -d "${ARM_BOOT}" ]; then
  511. rm -rf "${ARM_BOOT}"
  512. mkdir -p "${ARM_BOOT}"
  513. fi
  514. info "copying Mageia image to root partition"
  515. /usr/bin/rsync -rlptogDH --exclude "${ARM_BOOT}/" --exclude "qemu-arm-static*" "${BUILD_PATH}/" "${ROOT}/"
  516. /usr/bin/rsync -rlptogDH "${ARM_BOOT}/" "${BOOT}/"
  517. #/usr/bin/rsync -rlptogDH "${BUILD_PATH}/boot/" "${BOOT}/"
  518. else
  519. info "copying Mageia image to root partition"
  520. /usr/bin/rsync -rlptogDH --exclude "qemu-arm-static*" "${BUILD_PATH}/" "${ROOT}/"
  521. fi
  522. copyingCustomSystem
  523. if [ ${?} -ne 0 ]; then
  524. error "line ${LINENO} error in the process ${CONFIG_PATH}/specialFunctions.sh ."
  525. exit ${ERR_1}
  526. fi
  527. copyingcommon
  528. sync
  529. warning "You can now burn the image ( ${INSTALL_PATH}/${IMAGE} ) on SD card"
  530. return 0
  531. }
  532. function mountPartitions(){
  533. info "mounting partitions, making mountpoint if necessary"
  534. if [ 1 -eq ${SEPARATE_BOOT_PARTITION} ]; then
  535. if ! [ -d "${BOOT}" ]; then
  536. /usr/bin/mkdir "${BOOT}"
  537. if [ ${?} -ne 0 ]; then
  538. error "line ${LINENO} error making directory ${BOOT} : exiting"
  539. exit ${ERR_1}
  540. fi
  541. fi
  542. /usr/bin/mount "${BOOTP}" "${BOOT}"
  543. if [ ${?} -ne 0 ]; then
  544. error "line ${LINENO} error mounting ${BOOTP} : exiting"
  545. exit ${ERR_1}
  546. fi
  547. fi
  548. if ! [ -d "${ROOT}" ]; then
  549. /usr/bin/mkdir "${ROOT}"
  550. if [ ${?} -ne 0 ]; then
  551. error "line ${LINENO} error making directory ${ROOT} : exiting"
  552. exit ${ERR_1}
  553. fi
  554. fi
  555. /usr/bin/mount "${ROOTP}" "${ROOT}"
  556. if [ ${?} -ne 0 ]; then
  557. error "line ${LINENO} error mounting ${ROOTP} : exiting"
  558. exit ${ERR_1}
  559. fi
  560. }
  561. function unmountingPartitions()
  562. {
  563. title "Unmounting partitions..."
  564. # Syncing devices before unmounting
  565. /usr/bin/sync
  566. if [ -z "${BOOTP}" ] && [ -z "${ROOTP}" ] ; then
  567. warning "Root partition and Boot partition not defined !"
  568. for LOOP in $(losetup -l -O NAME,BACK-FILE -n | grep "${IMAGE}" | cut -d ' ' -f 1 ) ; do
  569. IFS=$'\n'
  570. for PARTITION in $(mount -l | grep ${LOOP}); do
  571. MOUNTPOINT=$(echo "$PARTITION" | cut -d ' ' -f 3)
  572. PARTITION=$(echo "$PARTITION" | cut -d ' ' -f 1)
  573. info "unmount ${PARTITION} and remove ${MOUNTPOINT}"
  574. /usr/bin/umount "${PARTITION}"
  575. if [ ${?} -eq 0 ]; then
  576. /usr/bin/rmdir "${MOUNTPOINT}"
  577. else
  578. error "line ${LINENO} error unmounting ${BOOT}..."
  579. fi
  580. done
  581. unset IFS
  582. done
  583. else
  584. if [ ! -z "${BOOTP}" ]; then
  585. /usr/bin/umount "${BOOTP}"
  586. if [ ${?} -eq 0 ]; then
  587. /usr/bin/rmdir "${BOOT}"
  588. else
  589. error "line ${LINENO} error unmounting ${BOOT}..."
  590. fi
  591. fi
  592. /usr/bin/umount "${ROOTP}"
  593. if [ ${?} -eq 0 ]; then
  594. /usr/bin/rmdir "${ROOT}"
  595. else
  596. error "line ${LINENO} error unmounting ${ROOT}..."
  597. fi
  598. fi
  599. return 0
  600. }
  601. function unloopingImage(){
  602. title "Unlooping image..."
  603. # Syncing devices before unmounting
  604. /usr/bin/sync
  605. # [root@jabztop mageia4arm (master)]# losetup -l -O NAME,BACK-FILE -n
  606. # /dev/loop0 /home/jibz/workspaces/mageia4arm/build/Mageia-7-bananaPro1.img (deleted)
  607. info "Looped devices to unmount : $(losetup -l -O NAME,BACK-FILE -n | grep "${IMAGE}" | cut -d ' ' -f 1 ) "
  608. for LOOP in $(losetup -l -O NAME,BACK-FILE -n | grep "${IMAGE}" | cut -d ' ' -f 1 ) ; do
  609. info "removing ${LOOP}"
  610. for PARTITION in ${LOOP}p* ; do
  611. partx -dv "${PARTITION}"
  612. done
  613. # losetup -d "${LOOP}"
  614. kpartx -d "${INSTALL_PATH}/${IMAGE}"
  615. done
  616. return 0
  617. }
  618. # Copying files common to all systems
  619. function copyingcommon()
  620. {
  621. title "Copying common files and configuration"
  622. rsync -rlptDH "${SOURCE_PATH}/common/" "${ROOT}/"
  623. rsync -rlptDH "${SOURCE_PATH}/tools/"*.sh "${ROOT}/usr/local/usr/bin/"
  624. chown root:root "${ROOT}/usr/local/usr/bin/"
  625. return 0
  626. }
  627. function mkfstab()
  628. {
  629. title "making /etc/fstab"
  630. ### BUG : /mnt/arm_boot is set to vfat for all plateforms, odroid configuration says ext4.
  631. #echo -e "proc /proc proc defaults 0 0\nUUID=${BOOT_UUID} /mnt/arm_boot vfat defaults 0 0\nUUID=${ROOT_UUID} / ext4 defaults 0 0" > "${BUILD_PATH}/etc/fstab"
  632. #echo -e "proc\t/proc\tproc\tdefaults\t0\t0\nUUID=${BOOT_UUID}\t/mnt/arm_boot\t${BOOTFS}\tdefaults\t0\t0\nUUID=${ROOT_UUID}\t/\text4\tdefaults\t0\t0" > "${BUILD_PATH}/etc/fstab"
  633. if [ 1 -eq ${SEPARATE_BOOT_PARTITION} ]; then
  634. echo -e "proc\t/proc\tproc\tdefaults\t0\t0\nUUID=${BOOT_UUID}\t/mnt/arm_boot\t${BOOTFS}\tdefaults\t0\t0\nUUID=${ROOT_UUID}\t/\text4\tdefaults\t0\t0" > "${BUILD_PATH}/etc/fstab"
  635. else
  636. echo -e "proc\t/proc\tproc\tdefaults\t0\t0\nUUID=${ROOT_UUID}\t/\text4\tdefaults\t0\t0" > "${BUILD_PATH}/etc/fstab"
  637. fi
  638. return 0
  639. }
  640. # cleaning build space
  641. function clean()
  642. {
  643. title "Cleaning"
  644. unmountingPartitions
  645. unloopingImage
  646. # Removing old Build directory
  647. if [ -d "${BUILD_PATH}" ]; then
  648. info "Removing ${BUILD_PATH}"
  649. /usr/bin/rm -Rf "${BUILD_PATH}"
  650. else
  651. warning "${BUILD_PATH} does not exists"
  652. fi
  653. # removing old image
  654. if [ -e "${INSTALL_PATH}/${IMAGE}" ]; then
  655. info "Removing ${IMAGE}"
  656. /usr/bin/rm -f "${INSTALL_PATH}/${IMAGE}"
  657. else
  658. warning "${IMAGE} does not exists"
  659. fi
  660. return 0
  661. }
  662. function preImgCreation()
  663. {
  664. error "This function is called if no sourced file about fdisk was lauched."
  665. return 1
  666. }
  667. function postPrepareChroot()
  668. {
  669. error "This function is called if no sourced file is containing postPrepareChroot function."
  670. return 1
  671. }
  672. function bunrningBootloader()
  673. {
  674. error "This function is called if no sourced file is containing bunrningBootloader function."
  675. return 1
  676. }
  677. function copyingCustomSystem()
  678. {
  679. error "This function is called if no sourced file is containing bunrningBootloader function."
  680. return 1
  681. }
  682. ERRORN=0
  683. ERR_1=1
  684. ERR_DEFAULT_CONFIG=2
  685. ERR_NO_CONFIG_FILE=3
  686. ERR_NOT_ROOT=4
  687. ERR_DEPENDENCY_MISSING=5
  688. ERR_NO_SPACE=6
  689. ERR_7=7
  690. ERR_8=8
  691. ERR_9=9
  692. SEPARATE_BOOT_PARTITION=1
  693. #######################
  694. # PROGRAMM START HERE #
  695. #######################
  696. info ${0}
  697. #Check dependencies :
  698. #if [ -e /usr/bin/qemu-arm-static ]; then
  699. # error "qemu-user-static package is needed."
  700. # exit ${ERR_DEPENDENCY_MISSING}
  701. #fi
  702. if [ 0 -ne $(id -u) ]; then
  703. error "Script need to be run as root."
  704. exit ${ERR_NOT_ROOT}
  705. fi
  706. SOURCE_PATH="$(/usr/bin/dirname "$(readlink -f "${0}")")"
  707. INSTALL_PATH="$(pwd)/build"
  708. # FILES_PATH="${SOURCE_PATH}/files"
  709. PLATFORMS_PATH="${SOURCE_PATH}/platforms"
  710. CMDNAME=$(/usr/bin/basename "${0}")
  711. if [ ${#} == 0 ]; then
  712. help
  713. exit
  714. fi
  715. # parsing commandline
  716. TEMP=$(getopt -o h,a --long all,help,clean,create-chroot,prepare-chroot,jump-chroot,add-urpmimedia,create-image,,config:,target:,target-version:,chroot,bootfs:,install-basesystem,update-mirror,build-path:,size:,nonfree,tainted -n ${CMDNAME} -- "${@}")
  717. if [ ${?} -ne 0 ] ; then error "line ${LINENO} Failed parsing options." >&2 ; exit ${ERR_1} ; fi
  718. eval set -- "${TEMP}"
  719. echo "${TEMP}"
  720. # Note the quotes around `$TEMP': they are essential! Or not, $( ) do the same as ` `. But there are the ` ' used ?
  721. while true; do
  722. case "${1}" in
  723. -h|--help)
  724. help
  725. exit 0
  726. ;;
  727. -a|--all)
  728. OPT="all"
  729. shift 1
  730. ;;
  731. --clean)
  732. OPT="clean"
  733. shift
  734. ;;
  735. --size)
  736. IMAGE_SIZE_P=${2}
  737. shift 2
  738. ;;
  739. --build-path)
  740. INSTALL_PATH_P=$(readlink -f "${2}")
  741. shift 2
  742. ;;
  743. --chroot)
  744. if [ -z ${OPT} ]; then
  745. OPT="chroot"
  746. fi
  747. shift
  748. ;;
  749. --create-chroot)
  750. if [ -z ${OPT} ]; then
  751. OPT="createchroot"
  752. fi
  753. shift
  754. ;;
  755. --prepare-chroot)
  756. if [ -z ${OPT} ]; then
  757. OPT="preparechroot"
  758. fi
  759. shift
  760. ;;
  761. --jump-chroot)
  762. if [ -z ${OPT} ]; then
  763. OPT="jumpchroot"
  764. fi
  765. shift
  766. ;;
  767. --add-urpmimedia)
  768. if [ -z ${OPT} ]; then
  769. OPT="addurpmimedia"
  770. fi
  771. shift
  772. ;;
  773. --update-mirror)
  774. if [ -z ${OPT} ]; then
  775. OPT="updatemirror"
  776. fi
  777. shift
  778. ;;
  779. --install-basesystem)
  780. if [ -z ${OPT} ]; then
  781. OPT="installbasesystem"
  782. fi
  783. shift
  784. ;;
  785. --create-image)
  786. if [ -z ${OPT} ]; then
  787. CREATEIMAGE=true
  788. OPT="createimage"
  789. fi
  790. shift
  791. ;;
  792. --target)
  793. TARGET_P=${2}
  794. shift 2
  795. ;;
  796. --target-version)
  797. TARGET_VERSION_P=${2}
  798. shift 2
  799. ;;
  800. --config)
  801. CONFIG_PATH="${PLATFORMS_PATH}/${2}"
  802. shift 2
  803. ;;
  804. --bootfs)
  805. BOOTFS_P=${2}
  806. shift 2
  807. ;;
  808. --nonfree)
  809. NONFREE_P=1
  810. shift
  811. ;;
  812. --tainted)
  813. TAINTED_P=1
  814. shift
  815. ;;
  816. --)
  817. shift
  818. break;;
  819. *)
  820. error "Parameter ${1} does not exists "
  821. exit ${ERR_1};;
  822. esac
  823. done
  824. # path of config file
  825. if ! [ -d "${CONFIG_PATH}" ]; then
  826. info " Config path does not exists, defaulting to ./platforms/${TARGET}"
  827. CONFIG_PATH="${PLATFORMS_PATH}/${TARGET}"
  828. warning "Do you want to create it and to copy the template file in? [Y|n] "
  829. read yn
  830. if [ -z ${yn} ] || [ ${yn} = "Y" ] || [ ${yn} = "y" ]; then
  831. /usr/bin/mkdir "${CONFIG_PATH}/"
  832. /usr/bin/cp --preserve=mode "${SOURCE_PATH}/mageia4arm.cfg.template" "${CONFIG_PATH}/mageia4arm.cfg"
  833. warning "You need now to modify the config file (${CONFIG_PATH}/mageia4arm.cfg) and relaunch the script"
  834. exit ${ERR_DEFAULT_CONFIG}
  835. else
  836. error "Error: Can't continue without config file, exiting"
  837. exit ${ERR_NO_CONFIG_FILE}
  838. fi
  839. fi
  840. if [ -e "${CONFIG_PATH}/mageia4arm.cfg" ]; then
  841. info "using ${CONFIG_PATH}/mageia4arm.cfg as config"
  842. source "${CONFIG_PATH}/mageia4arm.cfg" #NOTE1 : Here is sourced a file with variables.
  843. else
  844. warning "Config file does not exists, do you want to copy template ? [Y|n] "
  845. read yn
  846. if [ -z ${yn} ] || [ ${yn} = "Y" ] || [ ${yn} = "y" ]; then
  847. /usr/bin/cp --preserve=mode "${SOURCE_PATH}/mageia4arm.cfg.template" "${CONFIG_PATH}/mageia4arm.cfg"
  848. warning "You need now to modify the config file (${CONFIG_PATH}/mageia4arm.cfg) and relaunch the script"
  849. exit ${ERR_DEFAULT_CONFIG}
  850. fi
  851. fi
  852. if ! [ -z "${IMAGE_SIZE_P}" ]; then
  853. IMAGE_SIZE=${IMAGE_SIZE_P}
  854. fi
  855. if ! [ -z "${INSTALL_PATH_P}" ]; then
  856. INSTALL_PATH=${INSTALL_PATH_P}
  857. fi
  858. if ! [ -z "${TARGET_P}" ]; then
  859. TARGET=${TARGET_P}
  860. fi
  861. if ! [ -z "${TARGET_VERSION_P}" ]; then
  862. TARGET_VERSION=${TARGET_VERSION_P}
  863. fi
  864. if ! [ -z "${BOOTFS_P}" ]; then
  865. BOOTFS=${BOOTFS_P}
  866. fi
  867. if ! [ -z "${NONFREE_P}" ]; then
  868. NONFREE=${NONFREE_P}
  869. else
  870. NONFREE=0
  871. fi
  872. if ! [ -z "${TAINTED_P}" ]; then
  873. TAINTED=${TAINTED_P}
  874. else
  875. TAINTED=0
  876. fi
  877. info "Option: "${OPT}
  878. IMAGE="Mageia-${MAGEIA_VERSION}-${TARGET}${TARGET_VERSION}.img"
  879. BOOT="/mnt/boot"
  880. ROOT="/mnt/root"
  881. BUILD_PATH="${INSTALL_PATH}/build-${TARGET}${TARGET_VERSION}"
  882. # ARM_VERSION="armv7hl"
  883. DNF_CONFIGPATH="$(dirname $(realpath "$0"))/mageia4arm-dnf.conf"
  884. # Assigne a script for creating a particular target image (rpi, odroid, ...)
  885. if [ -e "${CONFIG_PATH}/specialFunctions.sh" ]; then
  886. source "${CONFIG_PATH}/specialFunctions.sh"
  887. fi
  888. info "target : ${TARGET}"
  889. info "target_version : ${TARGET_VERSION}"
  890. info "source path: ${SOURCE_PATH}"
  891. info "Install path: ${INSTALL_PATH}"
  892. info "Build path: ${BUILD_PATH}"
  893. info "Commande : ${CMDNAME}"
  894. info "Firmware path : ${FIRMWARE_PATH}"
  895. info "Firmware dir : ${FIRMWARE_DIR}"
  896. info "Installation method : ${INSTALL_METHOD}"
  897. # Defining default image size to 7 go
  898. if [[ "${IMAGE_SIZE}" -lt 2 ]] || [[ "${IMAGE_SIZE}" -gt 128 ]]; then
  899. IMAGE_SIZE=7
  900. fi
  901. # change dir to install path and create it if not existing
  902. if [ "${OPT}" != "clean" ]; then
  903. info "cd ${INSTALL_PATH}"
  904. if ! [ -e "${INSTALL_PATH}" ]; then
  905. /usr/bin/mkdir -p "${INSTALL_PATH}"
  906. if [ -z ${?} ]; then
  907. error "line ${LINENO} can't make directory ${INSTALL_PATH} , exiting"
  908. exit ${ERR_1}
  909. fi
  910. fi
  911. cd "${INSTALL_PATH}"
  912. if [ -z ${?} ]; then
  913. error "line ${LINENO} can't change to directory ${INSTALL_PATH} , exiting"
  914. exit ${ERR_1}
  915. fi
  916. fi
  917. #if no parameters then display help message
  918. if [ -z ${OPT} ]; then
  919. OPT="--help"
  920. fi
  921. info "Image size is: ${IMAGE_SIZE} GB"
  922. case ${OPT} in
  923. "clean")
  924. clean
  925. ;;
  926. "all")
  927. verify_disk_space
  928. if [ ${?} -ne 0 ]; then
  929. echo -e "Not enough space on disk\nDo you want to continue anyway ? [Y,n]"
  930. read yn
  931. if [ ${yn} = "n" ]; then
  932. exit ${ERR_NO_SPACE}
  933. fi
  934. fi
  935. createImageWrap #Create the empty .img
  936. createchroot #Check qemu and activate it
  937. if [ ${INSTALL_METHOD} = "urpmi" ]; then
  938. addurpmimedia
  939. else
  940. genusemirroroptions #Generate mirror options, if needed
  941. enableextrarepos
  942. fi
  943. installbasesystem #Generate the rootfs, rootfiles, ...
  944. mkfstab
  945. preparechroot
  946. jumpchroot
  947. mountPartitions
  948. copyingsystem
  949. unmountingPartitions
  950. unloopingImage
  951. ;;
  952. "createchroot")
  953. createchroot
  954. ;;
  955. "preparechroot")
  956. preparechroot
  957. ;;
  958. "jumpchroot")
  959. jumpchroot
  960. ;;
  961. "chroot")
  962. jumpchroot
  963. ;;
  964. "addurpmimedia")
  965. addurpmimedia
  966. ;;
  967. "createimage")
  968. verify_disk_space
  969. if [ ${?} -ne 0 ]; then
  970. warning "Not enough space on disk"
  971. exit ${ERR_NO_SPACE}
  972. fi
  973. createImageWrap
  974. ;;
  975. "installbasesystem")
  976. installbasesystem
  977. ;;
  978. esac
  979. if [ ${ERRORN} -ne 0 ]; then
  980. warning "Some errors occurs : ${ERRORN} errors"
  981. fi
  982. exit ${ERRORN}