Guest User

Untitled

a guest
Feb 21st, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 48.65 KB | None | 0 0
  1. #!/bin/bash
  2. TITLE="ArchBang Installation"
  3. _yes="Yes"
  4. _no="No"
  5. _cancel="Cancel"
  6. _continue_label="Continue"
  7. _grubdetectdisks="Generating GRUB device map...\n\n Please be patient."
  8. _errorfscreate="Error creating filesystem"
  9. _errormounting="Error mounting"
  10. _mkswaperr="Error creating swap:"
  11. _swaponerr="Error activating swap:"
  12. _umountingall="Disabling swapspace, unmounting already mounted disk devices..."
  13. _presentlyavaildisks="Available disks:"
  14. _selectdisktouse="Select the hard drive to use"
  15. _enterbootpartsize="Enter the size (MiB) of your /boot partition. Minimum is 16."
  16. _diskspaceleft="Disk space left:"
  17. _errorincorrectsize="ERROR: You entered an invalid size, please enter again."
  18. _errorsizetoobig="ERROR: You entered a too large size, please enter again."
  19. _enterswappartsize="Enter the size (MiB) of your swap partition."
  20. _enterrootpartsize="Enter the size (MiB) of your / (root) partition. The /home partition will use the remaining space."
  21. _homepartsize="Size of /home partition:"
  22. _selecthomerootfs="Select a filesystem for / and /home partitions:"
  23. _fshomeroottobeused="will be used for / and /home. OK?"
  24. _willbeerased='will be COMPLETELY ERASED! Proceed?'
  25. _alreadyprepparts='You have already prepared your partitions!'
  26. _invaliddevice="Invalid device:"
  27. _invaliddestdir="Destination directory invalid:"
  28. _onlyonerootpart="We need exactly one root partition"
  29. _partitionningdev="Partitionning"
  30. _errorpartitionningdev="Error partitionning"
  31. _errordetails="Details displayed on"
  32. _preparationfinished='Preparation finished !'
  33. _partsalreadyprepared='You have already prepared your filesystems !'
  34. _done_entry="DONE"
  35. _other_entry="OTHER"
  36. _none_entry="NONE"
  37. _selectdisktopart="Select the disk to partition (or $_done_entry when you have finished)"
  38. _enterdiskpath="Enter the full path to the device you wish to partition"
  39. _prepartitionmessage="You will now partition the selected disk with cfdisk.\nIf it asks you to reboot, do it, launch this program again and restart installation."
  40. _nowchooseparts2use="You will now select the partitions to use."
  41. _selectswappart="Select the partition to use as swap"
  42. _formatpart="Format"
  43. _allcontentswillbelost='Its contents will be erased!'
  44. _selecttherootpart="Select the partition for / (root)"
  45. _selectfsfor="Select the filesystem for"
  46. _wannamountotherparts="Do you want to mount other static partitions at bootup ? (optional)"
  47. _selectmpoint="Select the mountpoint (directory) for"
  48. _twopartsonamp='ERROR: two partitions on the same directory!'
  49. _formatconfirmmessage="Continue?\n\nSyntax\n------\nDEVICE:TYPE:MOUNTPOINT:FORMAT"
  50. _creatingactswap="Creating and activating swap on"
  51. _activatingswapon="Activating swap on"
  52. _formattingpart="Formatting"
  53. _mountingparton="mounting on"
  54. _mountingpart="Mounting"
  55. _partsmountsuccess="Partitions were successfully mounted."
  56.  
  57. _installationwillstart='Installation will now start. Please be patient!'
  58. _installationinprogress="Installation in progress..."
  59. _installationfail='Installation failed!'
  60. _installationsuccess='Installation succeeded!'
  61.  
  62. _configuringsystem="Configuration in progress..."
  63. _addonsinsttitle=" ==== Addons installation ===="
  64. _wichaddonsinstall="Which addons do you want to install?"
  65. _whichaddonsinst1='1) Choose among available installable addons'
  66. _whichaddonsinst2='2) Install installable addons among currently mounted addons'
  67. _whichaddonsinstn="n) Don't install any add-on"
  68. _installthisaddon="install? [y/N]"
  69. _addoninstalled="installed."
  70. _wantcplivehome="Do you want to copy the current personal folder into the installation? [y/n]"
  71. _wantcplivechg="Do you want to copy into the installation the changes done in live? [y/n]"
  72. _livechg_rwroot="This means the contents of your rwroot folder."
  73. _pressentercont="Press enter to continue..."
  74.  
  75. _isgrubinst="Is GRUB installed? Cannot find"
  76. _autodetectrootfail="Root partition autodetection failed. Modify manually"
  77. _youwilleditmenulst="You will now edit the GRUB configuration file (menu.lst). You just have to check, everything should be already configured."
  78. _nohdfound="No hard disk found"
  79. _whereinststage1="Where do you want to install GRUB's stage1? (most of the time on the MBR, i.e. /dev/sda)."
  80. _installinggrub="Installing GRUB..."
  81. _missingrootpart="Error: missing/invalid root device:"
  82. _cannotfindgrub="GRUB root and setup devices could not be auto-located. You will need to manually run the GRUB shell to install a bootloader."
  83. _bootsonanydisk="useful if you change your hard disk/mainboard"
  84. _chainloadexpl="Optional entry for the system on sda1"
  85. _enterrootdevpath="Enter the path of the root partition"
  86. _errorinstgrub="Error installing GRUB."
  87. _instgrubsuccess="GRUB successfully installed."
  88.  
  89. _machinetimezone="Set the machine time to UTC universal time (recommended) or local time (if you have a dual-boot with a system requiring it)?"
  90. _selectregion="Please select a region"
  91. _selecttimezone="Please select a timezone"
  92. _choosedatetime="Set the date.\nUse <TAB> to navigate and arrow keys to change values."
  93. _choosehourtime="Set the time.\nUse <TAB> to navigate and up/down to change values."
  94.  
  95. _diskpreparation="Hard disk(s) preparation"
  96. _assistprepa="Assisted preparation (erases the whole disk)"
  97. _manualpartit="Partition by hand and choose the partitions to use"
  98. _mainmenulabel="Main menu"
  99. _runninginitcpio="Running mkinitcpio..."
  100. _runninginitcpiotitle="Building initramfs image..."
  101. _mkinitcpiofailerror="ERROR - You will have to run mkinitcpio by hand, either way the system may not boot."
  102.  
  103. _definerootpass="Change root password"
  104. _defineusername="Modify user name"
  105. _defineuserpass="Change user password"
  106. _doeditconfig="Edit system configuration (optional)"
  107. _return_label="Back"
  108. _rcconftext="Main system configuration"
  109. _fstabtext="Mount points (please check)"
  110. _mkinitcpioconftext="Initramfs config (can be lightened)"
  111. _modprobeconftext="Module options (special cases only)"
  112. _resolvconftext="DNS servers (managed by wicd)"
  113. _hoststext="Network hosts (local DNS)"
  114. _hostsdenytext="Blocked network services"
  115. _hostsallowtext="Authorized network services"
  116. _localegentext="Languages (set to EN)"
  117. _mirrorlisttext="Packages mirror list"
  118. _xorgevdevconftext="Xorg keymap"
  119. _xorgkblayouttext="Xorg keyboard layout"
  120. _installabootloader="Install a bootloader?"
  121. _installgrubbl='Install GRUB (needed to boot)'
  122. _installnobl="If you know what you're doing."
  123. _none_label="None"
  124.  
  125. _mainmenuhelp="Use ↓ and ↑ to choose an entry, enter to launch it."
  126. _datetimetext="Set date and time"
  127. _preparediskstext="Disk(s) preparation"
  128. _installsystemtext="Install system"
  129. _configuresystemtext="Configure system"
  130. _instbootloadertext="Install bootloader"
  131. _quittext="Quit"
  132. _installationfinished='Installation finished!'
  133. _cancelinstall="Cancel installation?"
  134. _instwelcomemessage="Welcome to the ArchBang installation program. \nSimply follow the steps in order"'! :D'
  135. _forgotsystemconf="You forgot system configuration. Press enter."
  136. _forgotinstalling="Installing before configuring would seem more logical. Press enter."
  137. _forgotpreparehd="Prepare HD first or mount what you want in /mnt/install and type “perso” here. Press enter."
  138.  
  139. ANSWER="/tmp/.setup"
  140. # use the first VT not dedicated to a running console
  141. LOG="/dev/tty6"
  142. mkdir /mnt/install
  143. DESTDIR="/mnt/install"
  144. arch=$(uname -m)
  145. EDITOR="nano"
  146.  
  147. # abstract the common pacman args
  148. PACMAN="pacman --root ${DESTDIR} --config /tmp/pacman.conf --noconfirm --noprogressbar"
  149.  
  150. # sources
  151. SYNC_URL=
  152. MIRRORLIST="/etc/pacman.d/mirrorlist"
  153. PACKAGES=
  154.  
  155. # clock
  156. HARDWARECLOCK="localtime"
  157. TIMEZONE="America/Montreal"
  158.  
  159. # partitions
  160. PART_ROOT=
  161.  
  162. # default filesystem specs (the + is bootable flag)
  163. # <mountpoint>:<partsize>:<fstype>[:+]
  164. DEFAULTFS="/boot:32:ext2:+ swap:512:swap /:7000:reiserfs /home:*:reiserfs"
  165.  
  166. # install stages
  167. S_SRC=0 # choose install medium
  168. S_NET=0 # network configuration
  169. S_CLOCK=0 # clock and timezone
  170. S_PART=0 # partitioning
  171. S_MKFS=0 # formatting
  172. S_MKFSAUTO=0 # auto fs part/formatting TODO: kill this
  173. S_SELECT=0 # package selection
  174. S_INSTALL=0 # package installation
  175. S_CONFIG=0 # configuration editing
  176. S_GRUB=0 # TODO: kill this - if using grub
  177. S_BOOT="" # bootloader installed (set to loader name instead of 1)
  178.  
  179.  
  180. # main menu selection tracker
  181. CURRENT_SELECTION=""
  182.  
  183. DIALOG() {
  184. # parameters: see dialog(1)
  185. # returns: whatever dialog did
  186. dialog --backtitle "$TITLE" --aspect 15 --yes-label "$_yes" --no-label "$_no" --cancel-label "$_cancel" "$@"
  187. return $?
  188. }
  189.  
  190. # chroot_mount()
  191. # prepares target system as a chroot
  192. #
  193. chroot_mount()
  194. {
  195. [ -e "${DESTDIR}/sys" ] || mkdir "${DESTDIR}/sys"
  196. [ -e "${DESTDIR}/proc" ] || mkdir "${DESTDIR}/proc"
  197. [ -e "${DESTDIR}/dev" ] || mkdir "${DESTDIR}/dev"
  198. mount -t sysfs sysfs "${DESTDIR}/sys"
  199. mount -t proc proc "${DESTDIR}/proc"
  200. mount -o bind /dev "${DESTDIR}/dev"
  201. }
  202.  
  203. # chroot_umount()
  204. # tears down chroot in target system
  205. #
  206. chroot_umount()
  207. {
  208. umount $DESTDIR/proc
  209. umount $DESTDIR/sys
  210. umount $DESTDIR/dev
  211. }
  212.  
  213. finddisks() {
  214. workdir="$PWD"
  215. cd /sys/block
  216. # ide devices
  217. for dev in $(ls | egrep '^hd'); do
  218. if [ "$(cat $dev/device/media)" = "disk" ]; then
  219. echo "/dev/$dev"
  220. [ "$1" ] && echo $1
  221. fi
  222. done
  223. #scsi/sata devices
  224. for dev in $(ls | egrep '^sd'); do
  225. # TODO: what is the significance of 5?
  226. if ! [ "$(cat $dev/device/type)" = "5" ]; then
  227. echo "/dev/$dev"
  228. [ "$1" ] && echo $1
  229. fi
  230. done
  231. # SD/MMC controllers
  232. for dev in $(ls | egrep '^mmcblk'); do
  233. if [ -e /sys/block/$dev ]; then
  234. echo "/dev/$dev"
  235. [ "$1" ] && echo $1
  236. fi
  237. done
  238. # cciss controllers
  239. if [ -d /dev/cciss ] ; then
  240. cd /dev/cciss
  241. for dev in $(ls | egrep -v 'p'); do
  242. echo "/dev/cciss/$dev"
  243. [ "$1" ] && echo $1
  244. done
  245. fi
  246. # Smart 2 controllers
  247. if [ -d /dev/ida ] ; then
  248. cd /dev/ida
  249. for dev in $(ls | egrep -v 'p'); do
  250. echo "/dev/ida/$dev"
  251. [ "$1" ] && echo $1
  252. done
  253. fi
  254.  
  255. cd "$workdir"
  256. }
  257.  
  258. # getuuid()
  259. # converts /dev/[hs]d?[0-9] devices to UUIDs
  260. #
  261. # parameters: device file
  262. # outputs: UUID on success
  263. # nothing on failure
  264. # returns: nothing
  265. getuuid()
  266. {
  267. if [ -n "$(echo ${1} |grep -E '[shv]d[a-z]+[0-9]+$|mmcblk[0-9]+p[0-9]+$')" ]; then
  268. echo "$(blkid -s UUID -o value ${1})"
  269. fi
  270. }
  271.  
  272. findpartitions() {
  273. workdir="$PWD"
  274. for devpath in $(finddisks); do
  275. disk=$(echo $devpath | sed 's|.*/||')
  276. cd /sys/block/$disk
  277. for part in $disk*; do
  278. # check if not already assembled to a raid device
  279. if ! [ "$(cat /proc/mdstat 2>/dev/null | grep $part)" -o "$(fstype 2>/dev/null </dev/$part | grep "lvm2")" -o "$(sfdisk -c /dev/$disk $(echo $part | sed -e "s#$disk##g") 2>/dev/null | grep "5")" ]; then
  280. if [ -d $part ]; then
  281. echo "/dev/$part"
  282. [ "$1" ] && echo $1
  283. fi
  284. fi
  285. done
  286. done
  287. # include any mapped devices
  288. for devpath in $(ls /dev/mapper 2>/dev/null | grep -v control); do
  289. echo "/dev/mapper/$devpath"
  290. [ "$1" ] && echo $1
  291. done
  292. # include any raid md devices
  293. for devpath in $(ls -d /dev/md* | grep '[0-9]' 2>/dev/null); do
  294. if cat /proc/mdstat | grep -qw $(echo $devpath | sed -e 's|/dev/||g'); then
  295. echo "$devpath"
  296. [ "$1" ] && echo $1
  297. fi
  298. done
  299. # inlcude cciss controllers
  300. if [ -d /dev/cciss ] ; then
  301. cd /dev/cciss
  302. for dev in $(ls | egrep 'p'); do
  303. echo "/dev/cciss/$dev"
  304. [ "$1" ] && echo $1
  305. done
  306. fi
  307. # inlcude Smart 2 controllers
  308. if [ -d /dev/ida ] ; then
  309. cd /dev/ida
  310. for dev in $(ls | egrep 'p'); do
  311. echo "/dev/ida/$dev"
  312. [ "$1" ] && echo $1
  313. done
  314. fi
  315. cd "$workdir"
  316. }
  317.  
  318. get_grub_map() {
  319. rm /tmp/dev.map
  320. DIALOG --infobox "$_grubdetectdisks" 0 0
  321. $DESTDIR/sbin/grub --no-floppy --device-map /tmp/dev.map >/tmp/grub.log 2>&1 <<EOF
  322. quit
  323. EOF
  324. }
  325.  
  326. mapdev() {
  327. partition_flag=0
  328. device_found=0
  329. devs=$(cat /tmp/dev.map | grep -v fd | sed 's/ *\t/ /' | sed ':a;$!N;$!ba;s/\n/ /g')
  330. linuxdevice=$(echo $1 | cut -b1-8)
  331. if [ "$(echo $1 | egrep '[0-9]$')" ]; then
  332. # /dev/hdXY
  333. pnum=$(echo $1 | cut -b9-)
  334. pnum=$(($pnum-1))
  335. partition_flag=1
  336. fi
  337. for dev in $devs
  338. do
  339. if [ "(" = $(echo $dev | cut -b1) ]; then
  340. grubdevice="$dev"
  341. else
  342. if [ "$dev" = "$linuxdevice" ]; then
  343. device_found=1
  344. break
  345. fi
  346. fi
  347. done
  348. if [ "$device_found" = "1" ]; then
  349. if [ "$partition_flag" = "0" ]; then
  350. echo "$grubdevice"
  351. else
  352. grubdevice_stringlen=${#grubdevice}
  353. grubdevice_stringlen=$(($grubdevice_stringlen - 1))
  354. grubdevice=$(echo $grubdevice | cut -b1-$grubdevice_stringlen)
  355. echo "$grubdevice,$pnum)"
  356. fi
  357. else
  358. echo "DEVICE NOT FOUND"
  359. fi
  360. }
  361.  
  362. printk()
  363. {
  364. case $1 in
  365. "on") echo 4 >/proc/sys/kernel/printk ;;
  366. "off") echo 0 >/proc/sys/kernel/printk ;;
  367. esac
  368. }
  369.  
  370. # _mkfs()
  371. # Create and mount filesystems in our destination system directory.
  372. #
  373. # args:
  374. # domk: Whether to make the filesystem or use what is already there
  375. # device: Device filesystem is on
  376. # fstype: type of filesystem located at the device (or what to create)
  377. # dest: Mounting location for the destination system
  378. # mountpoint: Mount point inside the destination system, e.g. '/boot'
  379.  
  380. # returns: 1 on failure
  381. _mkfs() {
  382. local _domk=$1
  383. local _device=$2
  384. local _fstype=$3
  385. local _dest=$4
  386. local _mountpoint=$5
  387.  
  388. # we have two main cases: "swap" and everything else.
  389. if [ "${_fstype}" = "swap" ]; then
  390. swapoff ${_device} >/dev/null 2>&1
  391. if [ "${_domk}" = "yes" ]; then
  392. mkswap ${_device} >$LOG 2>&1
  393. if [ $? != 0 ]; then
  394. DIALOG --msgbox "${_mkswaperr} mkswap ${_device}" 0 0
  395. return 1
  396. fi
  397. fi
  398. swapon ${_device} >$LOG 2>&1
  399. if [ $? != 0 ]; then
  400. DIALOG --msgbox "${_swaponerr} swapon ${_device}" 0 0
  401. return 1
  402. fi
  403. else
  404. # make sure the fstype is one we can handle
  405. local knownfs=0
  406. for fs in xfs jfs reiserfs ext2 ext3 ext4; do
  407. [ "${_fstype}" = "${fs}" ] && knownfs=1 && break
  408. done
  409. if [ $knownfs -eq 0 ]; then
  410. DIALOG --msgbox "unknown fstype ${_fstype} for ${_device}" 0 0
  411. return 1
  412. fi
  413. # if we were tasked to create the filesystem, do so
  414. if [ "${_domk}" = "yes" ]; then
  415. local ret
  416. case ${_fstype} in
  417. xfs) mkfs.xfs -f ${_device} >$LOG 2>&1; ret=$? ;;
  418. jfs) yes | mkfs.jfs ${_device} >$LOG 2>&1; ret=$? ;;
  419. reiserfs) yes | mkreiserfs ${_device} >$LOG 2>&1; ret=$? ;;
  420. ext2) mke2fs "${_device}" >$LOG 2>&1; ret=$? ;;
  421. ext3) mke2fs -j ${_device} >$LOG 2>&1; ret=$? ;;
  422. ext4) mke2fs -t ext4 ${_device} >$LOG 2>&1; ret=$? ;;
  423. nilfs2) mkfs.nilfs2 ${_device} >$LOG 2>&1; ret=$? ;;
  424. # don't handle anything else here, we will error later
  425. esac
  426. if [ $ret != 0 ]; then
  427. DIALOG --msgbox "${_errorfscreate} ${_fstype} (${_device})" 0 0
  428. return 1
  429. fi
  430. sleep 2
  431. fi
  432. # create our mount directory
  433. mkdir -p ${_dest}${_mountpoint}
  434. # mount the bad boy
  435. mount -t ${_fstype} ${_device} ${_dest}${_mountpoint} >$LOG 2>&1
  436. if [ $? != 0 ]; then
  437. DIALOG --msgbox "${_errormounting} ${_dest}${_mountpoint}" 0 0
  438. return 1
  439. fi
  440. fi
  441.  
  442. # add to temp fstab
  443. local _uuid="$(getuuid ${_device})"
  444. if [ -n "${_uuid}" ]; then
  445. _device="UUID=${_uuid}"
  446. fi
  447. echo -n "${_device} ${_mountpoint} ${_fstype} defaults 0 " >>/tmp/.fstab
  448.  
  449. if [ "${_fstype}" = "swap" ]; then
  450. echo "0" >>/tmp/.fstab
  451. else
  452. echo "1" >>/tmp/.fstab
  453. fi
  454. }
  455.  
  456. # Disable swap and all mounted partitions for the destination system. Unmount
  457. # the destination root partition last!
  458. _umountall()
  459. {
  460. DIALOG --infobox "$_umountingall" 0 0
  461. swapoff -a >/dev/null 2>&1
  462. umount $(mount | grep -v "${DESTDIR} " | grep "${DESTDIR}" | sed 's|\ .*||g') >/dev/null 2>&1
  463. umount $(mount | grep "${DESTDIR} " | sed 's|\ .*||g') >/dev/null 2>&1
  464. }
  465.  
  466. # _getdisccapacity()
  467. #
  468. # parameters: device file
  469. # outputs: disc capacity in bytes
  470. _getdisccapacity()
  471. {
  472. echo $(($(</sys/dev/block/$((16#$(stat -c %t $1))):$((16#$(stat -c %T $1)))/size)*512))
  473. }
  474.  
  475. # Get a list of available disks for use in the "Available disks" dialogs. This
  476. # will print the disks as follows, getting size info from _getdisccapacity():
  477. # /dev/sda: 625000 MiB (610 GiB)
  478. # /dev/sdb: 476940 MiB (465 GiB)
  479. _getavaildisks()
  480. {
  481. for DISC in $(finddisks); do
  482. DISC_SIZE=$(_getdisccapacity $DISC)
  483. echo "$DISC: $((DISC_SIZE / 2**20)) MiB ($((DISC_SIZE / 2**30)) GiB)\n"
  484. done
  485. }
  486.  
  487. autoprepare()
  488. {
  489. DISCS=$(finddisks)
  490. if [ $(echo $DISCS | wc -w) -gt 1 ]; then
  491. DIALOG --msgbox "${_presentlyavaildisks}\n\n$(_getavaildisks)\n" 0 0
  492. DIALOG --menu "${_selectdisktouse}" 14 55 7 $(finddisks _) 2>$ANSWER || return 1
  493. DISC=$(cat $ANSWER)
  494. else
  495. DISC=$DISCS
  496. fi
  497. SET_DEFAULTFS=""
  498. BOOT_PART_SET=""
  499. SWAP_PART_SET=""
  500. ROOT_PART_SET=""
  501. CHOSEN_FS=""
  502. # disk size in MiB
  503. DISC_SIZE=$(($(_getdisccapacity $DISC) / 2**20))
  504. while [ "$SET_DEFAULTFS" = "" ]; do
  505. [ "$(which mkreiserfs 2>/dev/null)" ] && FSOPTS="reiserfs Reiser3"
  506. [ "$(which mkfs.xfs 2>/dev/null)" ] && FSOPTS="$FSOPTS xfs XFS"
  507. [ "$(which mkfs.jfs 2>/dev/null)" ] && FSOPTS="$FSOPTS jfs JFS"
  508. [ "$(which mkfs.ext2 2>/dev/null)" ] && FSOPTS="$FSOPTS ext2 ext2 ext3 ext3 ext4 ext4"
  509. while [ "$BOOT_PART_SET" = "" ]; do
  510. DIALOG --inputbox "${_enterbootpartsize}\n\n${_diskspaceleft} $DISC_SIZE MiB" 10 65 "32" 2>$ANSWER || return 1
  511. BOOT_PART_SIZE="$(cat $ANSWER)"
  512. if [ "$BOOT_PART_SIZE" = "" ]; then
  513. DIALOG --msgbox "${_errorincorrectsize}" 0 0
  514. else
  515. if [ "$BOOT_PART_SIZE" -ge "$DISC_SIZE" -o "$BOOT_PART_SIZE" -lt "16" -o "$SBOOT_PART_SIZE" = "$DISC_SIZE" ]; then
  516. DIALOG --msgbox "${_errorsizetoobig}" 0 0
  517. else
  518. BOOT_PART_SET=1
  519. fi
  520. fi
  521. done
  522. DISC_SIZE=$(($DISC_SIZE-$BOOT_PART_SIZE))
  523. while [ "$SWAP_PART_SET" = "" ]; do
  524. DIALOG --inputbox "${_enterswappartsize}\n\n${_diskspaceleft} $DISC_SIZE MiB" 10 65 "256" 2>$ANSWER || return 1
  525. SWAP_PART_SIZE=$(cat $ANSWER)
  526. if [ "$SWAP_PART_SIZE" = "" -o "$SWAP_PART_SIZE" -le "0" ]; then
  527. DIALOG --msgbox "${_errorincorrectsize}" 0 0
  528. else
  529. if [ "$SWAP_PART_SIZE" -ge "$DISC_SIZE" ]; then
  530. DIALOG --msgbox "${_errorsizetoobig}" 0 0
  531. else
  532. SWAP_PART_SET=1
  533. fi
  534. fi
  535. done
  536. DISC_SIZE=$(($DISC_SIZE-$SWAP_PART_SIZE))
  537. while [ "$ROOT_PART_SET" = "" ]; do
  538. DIALOG --inputbox "${_enterrootpartsize}\n\n${_diskspaceleft} $DISC_SIZE MiB" 10 65 "7500" 2>$ANSWER || return 1
  539. ROOT_PART_SIZE=$(cat $ANSWER)
  540. if [ "$ROOT_PART_SIZE" = "" -o "$ROOT_PART_SIZE" -le "0" ]; then
  541. DIALOG --msgbox "${_errorincorrectsize}" 0 0
  542. else
  543. if [ "$ROOT_PART_SIZE" -ge "$DISC_SIZE" ]; then
  544. DIALOG --msgbox "${_errorsizetoobig}" 0 0
  545. else
  546. DIALOG --yesno "${_homepartsize} $(($DISC_SIZE-$ROOT_PART_SIZE)) MiB. OK ?" 0 0 && ROOT_PART_SET=1
  547. fi
  548. fi
  549. done
  550. while [ "$CHOSEN_FS" = "" ]; do
  551. DIALOG --menu "${_selecthomerootfs}" 13 45 6 $FSOPTS 2>$ANSWER || return 1
  552. FSTYPE=$(cat $ANSWER)
  553. DIALOG --yesno "$FSTYPE ${_fshomeroottobeused}" 0 0 && CHOSEN_FS=1
  554. done
  555. SET_DEFAULTFS=1
  556. done
  557.  
  558. DIALOG --defaultno --yesno "$DISC ${_willbeerased}" 0 0 || return 1
  559.  
  560. DEVICE=$DISC
  561. FSSPECS=$(echo $DEFAULTFS | sed -e "s|/:7000:reiserfs|/:$ROOT_PART_SIZE:$FSTYPE|g" -e "s|/home:\*:reiserfs|/home:\*:$FSTYPE|g" -e "s|swap:256|swap:$SWAP_PART_SIZE|g" -e "s|/boot:32|/boot:$BOOT_PART_SIZE|g")
  562. sfdisk_input=""
  563.  
  564. case "${DEVICE}" in
  565. *mmcblk*)
  566. PART_ROOT="${DEVICE}p3"
  567. swap_partition="${DEVICE}p2"
  568. ;;
  569. *)
  570. # we assume a /dev/hdX format (or /dev/sdX)
  571. PART_ROOT="${DEVICE}3"
  572. swap_partition="${DEVICE}2"
  573. ;;
  574. esac
  575.  
  576. if [ "$S_MKFS" = "1" ]; then
  577. DIALOG --msgbox "${_alreadyprepparts}" 0 0
  578. return 0
  579. fi
  580.  
  581. # validate DEVICE
  582. if [ ! -b "$DEVICE" ]; then
  583. DIALOG --msgbox "${_invaliddevice} '$DEVICE'" 0 0
  584. return 1
  585. fi
  586.  
  587. # validate DEST
  588. if [ ! -d "$DESTDIR" ]; then
  589. DIALOG --msgbox "${_invaliddestdir} '$DESTDIR'" 0 0
  590. return 1
  591. fi
  592.  
  593. # / required
  594. if [ $(echo $FSSPECS | grep '/:' | wc -l) -ne 1 ]; then
  595. DIALOG --msgbox "${_onlyonerootpart}" 0 0
  596. return 1
  597. fi
  598.  
  599. rm -f /tmp/.fstab
  600.  
  601. _umountall
  602.  
  603. # setup input var for sfdisk
  604. for fsspec in $FSSPECS; do
  605. fssize=$(echo $fsspec | tr -d ' ' | cut -f2 -d:)
  606. if [ "$fssize" = "*" ]; then
  607. fssize_spec=';'
  608. else
  609. fssize_spec=",$fssize"
  610. fi
  611. fstype=$(echo $fsspec | tr -d ' ' | cut -f3 -d:)
  612. if [ "$fstype" = "swap" ]; then
  613. fstype_spec=",S"
  614. else
  615. fstype_spec=","
  616. fi
  617. bootflag=$(echo $fsspec | tr -d ' ' | cut -f4 -d:)
  618. if [ "$bootflag" = "+" ]; then
  619. bootflag_spec=",*"
  620. else
  621. bootflag_spec=""
  622. fi
  623. sfdisk_input="${sfdisk_input}${fssize_spec}${fstype_spec}${bootflag_spec}\n"
  624. done
  625. sfdisk_input=$(printf "$sfdisk_input")
  626.  
  627. # invoke sfdisk
  628. printk off
  629. DIALOG --infobox "${_partitionningdev} $DEVICE" 0 0
  630. sfdisk $DEVICE -uM >$LOG 2>&1 <<EOF
  631. $sfdisk_input
  632. EOF
  633. if [ $? -gt 0 ]; then
  634. DIALOG --msgbox "${_errorpartitionningdev} $DEVICE (${_errordetails} $LOG)" 0 0
  635. printk on
  636. return 1
  637. fi
  638. printk on
  639.  
  640. # need to mount root first, then do it again for the others
  641. part=1
  642. for fsspec in $FSSPECS; do
  643. mountpoint=$(echo $fsspec | tr -d ' ' | cut -f1 -d:)
  644. fstype=$(echo $fsspec | tr -d ' ' | cut -f3 -d:)
  645. if echo $mountpoint | tr -d ' ' | grep '^/$' 2>&1 > /dev/null; then
  646. _mkfs yes ${DEVICE}${part} "$fstype" "$DESTDIR" "$mountpoint" || return 1
  647. fi
  648. part=$(($part + 1))
  649. done
  650.  
  651. # make other filesystems
  652. part=1
  653. for fsspec in $FSSPECS; do
  654. mountpoint=$(echo $fsspec | tr -d ' ' | cut -f1 -d:)
  655. fstype=$(echo $fsspec | tr -d ' ' | cut -f3 -d:)
  656. if [ $(echo $mountpoint | tr -d ' ' | grep '^/$' | wc -l) -eq 0 ]; then
  657. _mkfs yes ${DEVICE}${part} "$fstype" "$DESTDIR" "$mountpoint" || return 1
  658. fi
  659. part=$(($part + 1))
  660. done
  661.  
  662. DIALOG --msgbox "${_preparationfinished}" 0 0
  663. S_MKFSAUTO=1
  664. }
  665.  
  666. partition() {
  667. if [ "$S_MKFSAUTO" = "1" ]; then
  668. DIALOG --msgbox "${_partsalreadyprepared}" 0 0
  669. return 0
  670. fi
  671.  
  672. _umountall
  673.  
  674. # Select disk to partition
  675. DISCS=$(finddisks _)
  676. DISCS="$DISCS ${_other_entry} - ${_done_entry} +"
  677. DIALOG --msgbox "${_presentlyavaildisks}\n\n$(_getavaildisks)\n" 0 0
  678. DISC=""
  679. while true; do
  680. # Prompt the user with a list of known disks
  681. DIALOG --menu "${_selectdisktopart}" 14 55 7 $DISCS 2>$ANSWER || return 1
  682. DISC=$(cat $ANSWER)
  683. if [ "$DISC" = "$_other_entry" ]; then
  684. DIALOG --inputbox "${_enterdiskpath}" 8 65 "/dev/sda" 2>$ANSWER || return 1
  685. DISC=$(cat $ANSWER)
  686. fi
  687. # Leave our loop if the user is done partitioning
  688. [ "$DISC" = "$_done_entry" ] && break
  689. # Partition disc
  690. DIALOG --msgbox "${_prepartitionmessage}" 18 70
  691. cfdisk $DISC
  692. done
  693. S_PART=1
  694. }
  695.  
  696. mountpoints() {
  697. if [ "$S_MKFSAUTO" = "1" ]; then
  698. DIALOG --msgbox "${_alreadyprepparts}" 0 0
  699. return 0
  700. fi
  701. while [ "$PARTFINISH" != "$_done_entry" ]; do
  702. : >/tmp/.fstab
  703. : >/tmp/.parts
  704.  
  705. # Determine which filesystems are available
  706. [ "$(which mkreiserfs 2>/dev/null)" ] && FSOPTS="reiserfs Reiser3"
  707. [ "$(which mkfs.xfs 2>/dev/null)" ] && FSOPTS="$FSOPTS xfs XFS"
  708. [ "$(which mkfs.jfs 2>/dev/null)" ] && FSOPTS="$FSOPTS jfs JFS"
  709. [ "$(which mkfs.ext2 2>/dev/null)" ] && FSOPTS="$FSOPTS ext2 ext2 ext3 ext3 ext4 ext4"
  710.  
  711. # Select mountpoints
  712. DIALOG --msgbox "${_nowchooseparts2use}" 0 0
  713. DIALOG --msgbox "${_presentlyavaildisks}\n\n$(_getavaildisks)\n" 0 0
  714. PARTS=$(findpartitions _)
  715. DIALOG --menu "${_selectswappart}" 21 50 13 ${_none_entry} - $PARTS 2>$ANSWER || return 1
  716. PART=$(cat $ANSWER)
  717. swap_partition="$PART"
  718. PARTS="$(echo $PARTS | sed -e "s#${PART}\ _##g")"
  719. if [ "$PART" != "${_none_entry}" ]; then
  720. DOMKFS="no"
  721. DIALOG --yesno "${_formatpart} $PART ?\n\n(${_allcontentswillbelost})" 0 0 && DOMKFS="yes"
  722. echo "$PART:swap:swap:$DOMKFS" >>/tmp/.parts
  723. fi
  724.  
  725. DIALOG --menu "${_selecttherootpart}" 21 50 13 $PARTS 2>$ANSWER || return 1
  726. PART=$(cat $ANSWER)
  727. PARTS="$(echo $PARTS | sed -e "s#${PART}\ _##g")"
  728. PART_ROOT=$PART
  729. # Select root filesystem type
  730. DIALOG --menu "${_selectfsfor} $PART" 15 60 6 $FSOPTS 2>$ANSWER || return 1
  731. FSTYPE=$(cat $ANSWER)
  732. DOMKFS="no"
  733. DIALOG --yesno "${_formatpart} $PART ?\n\n(${_allcontentswillbelost})" 0 0 && DOMKFS="yes"
  734. echo "$PART:$FSTYPE:/:$DOMKFS" >>/tmp/.parts
  735.  
  736. #
  737. # Additional partitions
  738. #
  739. DIALOG --menu "${_wannamountotherparts}" 21 50 13 $PARTS ${_done_entry} _ 2>$ANSWER || return 1
  740. PART=$(cat $ANSWER)
  741. while [ "$PART" != "$_done_entry" ]; do
  742. PARTS="$(echo $PARTS | sed -e "s#${PART}\ _##g")"
  743. # Select a filesystem type
  744. DIALOG --menu "${_selectfsfor} $PART" 15 60 6 $FSOPTS 2>$ANSWER || return 1
  745. FSTYPE=$(cat $ANSWER)
  746. MP=""
  747. while [ "${MP}" = "" ]; do
  748. DIALOG --inputbox "${_selectmpoint} $PART" 8 65 "/boot" 2>$ANSWER || return 1
  749. MP=$(cat $ANSWER)
  750. if grep ":$MP:" /tmp/.parts; then
  751. DIALOG --msgbox "${_twopartsonamp}" 8 65
  752. MP=""
  753. fi
  754. done
  755. DOMKFS="no"
  756. DIALOG --yesno "${_formatpart} $PART ?\n\n(${_allcontentswillbelost})" 0 0 && DOMKFS="yes"
  757. echo "$PART:$FSTYPE:$MP:$DOMKFS" >>/tmp/.parts
  758. DIALOG --menu "${_wannamountotherparts}" 21 50 13 $PARTS ${_done_entry} _ 2>$ANSWER || return 1
  759. PART=$(cat $ANSWER)
  760. done
  761. DIALOG --yesno "${_formatconfirmmessage}\n\n$(for i in $(cat /tmp/.parts); do echo "$i\n";done)" 18 0 && PARTFINISH="$_done_entry"
  762. done
  763.  
  764. _umountall
  765.  
  766. for line in $(cat /tmp/.parts); do
  767. PART=$(echo $line | cut -d: -f 1)
  768. FSTYPE=$(echo $line | cut -d: -f 2)
  769. MP=$(echo $line | cut -d: -f 3)
  770. DOMKFS=$(echo $line | cut -d: -f 4)
  771. umount ${DESTDIR}${MP}
  772. if [ "$DOMKFS" = "yes" ]; then
  773. if [ "$FSTYPE" = "swap" ]; then
  774. DIALOG --infobox "${_creatingactswap} $PART" 0 0
  775. else
  776. DIALOG --infobox "${_formattingpart} $PART ($FSTYPE), ${_mountingparton} ${DESTDIR}${MP}" 0 0
  777. fi
  778. _mkfs yes $PART $FSTYPE $DESTDIR $MP || return 1
  779. else
  780. if [ "$FSTYPE" = "swap" ]; then
  781. DIALOG --infobox "${_activatingswapon} $PART" 0 0
  782. else
  783. DIALOG --infobox "${_mountingpart} $PART ⇒ ${DESTDIR}${MP}" 0 0
  784. fi
  785. _mkfs no $PART $FSTYPE $DESTDIR $MP || return 1
  786. fi
  787. sleep 1
  788. done
  789.  
  790. DIALOG --msgbox "${_partsmountsuccess}" 0 0
  791. S_MKFS=1
  792. }
  793.  
  794. # installsystem()
  795. # installs to the target folder
  796. installsystem() {
  797. DIALOG --msgbox "${_installationwillstart}" 0 0
  798. mkdir -p $DESTDIR/bypass
  799. (cd $DESTDIR && unsquashfs -da 32 -fr 32 -d ./vomi /bootmnt/arch/${arch}/root-image.fs.sfs && mount vomi/root-image.fs $DESTDIR/bypass && echo -e "\n Now copying files :D" && cp -raf $DESTDIR/bypass/* $DESTDIR/ &>/dev/null)
  800. echo $? > /tmp/.install-retcode
  801. if [ $(cat /tmp/.install-retcode) -ne 0 ]; then echo -e "\n${_installationfail}" >>/tmp/unsquasherror.log
  802. else echo -e "\n${_installationsuccess}" >>/tmp/unsquasherror.log
  803. fi
  804. sed -i '/dir_scan: failed to open directory [^ ]*, because File exists/d' /tmp/unsquasherror.log
  805.  
  806. # finished, display scrollable output
  807. local _result=''
  808. if [ $(cat /tmp/.install-retcode) -ne 0 ]; then
  809. _result="${_installationfail}"
  810. else
  811. _result="${_installationsuccess}"
  812. fi
  813. rm /tmp/.install-retcode
  814.  
  815. DIALOG --title "$_result" --exit-label "${_continue_label}" \
  816. --textbox "/tmp/unsquasherror.log" 18 83 || return 1
  817.  
  818. # ensure the disk is synced
  819. sync
  820.  
  821. S_INSTALL=1
  822.  
  823. # automagic time!
  824. # any automatic configuration should go here
  825. DIALOG --infobox "${_configuringsystem}" 6 40
  826.  
  827. hd_config
  828. auto_fstab
  829. }
  830.  
  831.  
  832. hd_config()
  833. {
  834. #grub
  835. mkdir -p $DESTDIR/boot/grub
  836. cp -r /usr/lib/grub/i386-pc/* $DESTDIR/boot/grub/
  837. #nm
  838. rm $DESTDIR/etc/xdg/autostart/nm-applet.desktop &>/dev/null
  839. #little bonus
  840. cp /etc/hosts ${DESTDIR}/etc &>/dev/null
  841. mkdir -p ${DESTDIR}/usr/share/slim &>/dev/null
  842. mkdir -p ${DESTDIR}/usr/share/wallpapers &>/dev/null
  843. cp -rp /usr/share/wallpapers ${DESTDIR}/usr/share &>/dev/null
  844. cp -rp /usr/share/slim ${DESTDIR}/usr/share
  845. cp -ra /etc/skel/.[a-zA-Z0-9]* ${DESTDIR}/root/ &>/dev/null
  846. cp -a /src/menu.xml ${DESTDIR}/root/.config/openbox/menu.xml &>/dev/null
  847. cp -a /src/rc.xml ${DESTDIR}/root/.config/openbox/rc.xml &>/dev/null
  848. cp -a /src/.conkyrc ${DESTDIR}/root/.conkyrc &>/dev/null
  849. cp -a /src/.Xdefaults ${DESTDIR}/root/.Xdefaults &>/dev/null
  850. cp -a /src/oblogout.conf ${DESTDIR}/etc/oblogout.conf
  851. cp -a /src/rc.local ${DESTDIR}/etc/rc.local
  852. cp -a /src/pacman.conf ${DESTDIR}/etc/pacman.conf
  853. cp -a /usr/bin/conkyswitcher ${DESTDIR}/usr/bin/conkyswitcher
  854. cp -a /usr/bin/conkywonky ${DESTDIR}/usr/bin/conkywonky
  855. cp -a /usr/bin/archbey ${DESTDIR}/usr/bin/archbey
  856. cp -r /usr/share/slim/themes/archbang/ ${DESTDIR}/usr/share/slim/themes/archbang/ &>/dev/null
  857. cp /etc/slim.conf ${DESTDIR}/etc/
  858. cp /src/inittab ${DESTDIR}/etc/inittab
  859. cp /etc/X11/xorg.conf.d/20-gpudriver.conf ${DESTDIR}/etc/X11/xorg.conf.d/20-gpudriver.conf &>/dev/null
  860. sed '/^#\S/ s|#||' -i ${DESTDIR}/etc/pacman.d/mirrorlist &>/dev/null
  861. cp -a /src/rc.conf ${DESTDIR}/etc/rc.conf &>/dev/null
  862. }
  863.  
  864. # auto_fstab()
  865. # preprocess fstab file
  866. # comments out old fields and inserts new ones
  867. # according to partitioning/formatting stage
  868. #
  869. auto_fstab()
  870. {
  871. if [ "$S_MKFS" = "1" -o "$S_MKFSAUTO" = "1" ]; then
  872. if [ -f /tmp/.fstab ]; then
  873. # comment out stray /dev entries
  874. sed -i 's/^\/dev/#\/dev/g' $DESTDIR/etc/fstab
  875. # append entries from new configuration
  876. sort /tmp/.fstab >>$DESTDIR/etc/fstab
  877. fi
  878. fi
  879. }
  880.  
  881. dogrub() {
  882. get_grub_map
  883. local grubmenu="$DESTDIR/boot/grub/menu.lst"
  884. if [ ! -f $grubmenu ]; then
  885. DIALOG --msgbox "${_isgrubinst} $grubmenu" 0 0
  886. return 1
  887. fi
  888. # try to auto-configure GRUB...
  889. if [ "$PART_ROOT" != "" -a "$S_GRUB" != "1" ]; then
  890. grubdev=$(mapdev $PART_ROOT)
  891. local _rootpart="${PART_ROOT}"
  892. local _uuid="$(getuuid ${PART_ROOT})"
  893. # attempt to use a UUID if the root device has one
  894. if [ -n "${_uuid}" ]; then
  895. _rootpart="/dev/disk/by-uuid/${_uuid}"
  896. fi
  897. # look for a separately-mounted /boot partition
  898. bootdev=$(mount | grep $DESTDIR/boot | cut -d' ' -f 1)
  899. if [ "$grubdev" != "" -o "$bootdev" != "" ]; then
  900. subdir=
  901. if [ "$bootdev" != "" ]; then
  902. grubdev=$(mapdev $bootdev)
  903. else
  904. subdir="/boot"
  905. fi
  906. # keep the file from being completely bogus
  907. if [ "$grubdev" = "DEVICE NOT FOUND" ]; then
  908. DIALOG --msgbox "${_autodetectrootfail} 'root (hd0,0)'" 0 0
  909. grubdev="(hd0,0)"
  910. fi
  911. # generate resume string for suspend to disk
  912. [ -z "${swap_partition}" -o "${swap_partition}" = "${_none_entry}" ] || hibernpart='resume=/dev/disk/by-uuid/'"$(blkid -s UUID -o value -p ${swap_partition})"
  913. # remove default entries by truncating file at our little tag (#-*)
  914. sed -i -e '/#-\*/q' $grubmenu
  915. sed -i 's/timeout 10/timeout 3/' $grubmenu
  916. sed -i 's/default 3/default 0/' $grubmenu
  917. cat >>$grubmenu <<EOF
  918.  
  919. # (0) ArchBang Linux
  920. title ArchBang Linux
  921. root $grubdev
  922. kernel $subdir/vmlinuz-linux root=${_rootpart} loglevel=3 ro quiet ${hibernpart} $(grep -Eo 'vga=[^ ]*' /proc/cmdline) $(grep -Eo '[^ ]*\.modeset=[^ ]*' /proc/cmdline |tr '\n' ' ') $(grep -o 'nomodeset' /proc/cmdline)
  923. initrd $subdir/initramfs-linux.img
  924.  
  925. # (1) ArchBang Linux fallback (${_bootsonanydisk})
  926. title ArchBang Linux Fallback
  927. root $grubdev
  928. kernel $subdir/vmlinuz-linux root=${_rootpart} loglevel=3 ro quiet
  929. initrd $subdir/initramfs-linux-fallback.img
  930.  
  931. # (2) ${_chainloadexpl}
  932. #title sda1
  933. #rootnoverify (hd0,0)
  934. #makeactive
  935. #chainloader +1
  936. EOF
  937. fi
  938. fi
  939.  
  940. DIALOG --msgbox "${_youwilleditmenulst}" 0 0
  941. $EDITOR $grubmenu
  942.  
  943. DEVS=$(finddisks _)
  944. DEVS="$DEVS $(findpartitions _)"
  945. if [ "$DEVS" = "" ]; then
  946. DIALOG --msgbox "${_nohdfound}" 0 0
  947. return 1
  948. fi
  949. DIALOG --menu "${_whereinststage1}" 14 55 7 $DEVS 2>$ANSWER || return 1
  950. ROOTDEV=$(cat $ANSWER)
  951. DIALOG --infobox "${_installinggrub}" 3 30
  952. cp -a $DESTDIR/usr/lib/grub/i386-pc/* $DESTDIR/boot/grub/
  953. sync
  954.  
  955. # look for a separately-mounted /boot partition
  956. bootpart=$(mount | grep $DESTDIR/boot | cut -d' ' -f 1)
  957. if [ "$bootpart" = "" ]; then
  958. if [ "$PART_ROOT" = "" ]; then
  959. DIALOG --inputbox "${_enterrootdevpath}" 8 65 "/dev/sda3" 2>$ANSWER || return 1
  960. bootpart=$(cat $ANSWER)
  961. else
  962. bootpart=$PART_ROOT
  963. fi
  964. fi
  965. #DIALOG --defaultno --yesno "Si vous avez monté un RAID : installer GRUB sur un autre disque ?\nGénéralement, non." 0 0
  966. #if [ $? -eq 0 ]; then
  967. # DIALOG --menu "Sélectionnez la partition de boot, elle ne peut pas être détectée.\nRefaites ensuite l'installation de GRUB partout où il doit se trouver." 14 55 7 $DEVS 2>$ANSWER || return 1
  968. # bootpart=$(cat $ANSWER)
  969. #fi
  970. bootpartgrub=$(mapdev $bootpart)
  971. bootdev=$(mapdev $ROOTDEV)
  972. if [ "$bootpart" = "" ]; then
  973. DIALOG --msgbox "${_missingrootpart} $bootpart" 0 0
  974. return 1
  975. fi
  976. if [ "$bootpartgrub" = "DEVICE NOT FOUND" -o "$bootdev" = "DEVICE NOT FOUND" ]; then
  977. DIALOG --msgbox "${_cannotfindgrub}" 0 0
  978. return 1
  979. fi
  980.  
  981. # freeze xfs filesystems if any, to enable grub installation on xfs filesystems
  982. if [ -x /usr/sbin/xfs_freeze ]; then
  983. if [ "$(blkid -o value -s TYPE -p $(findmnt -o source -n $DESTDIR/boot))" == "xfs" ];then
  984. /usr/sbin/xfs_freeze -f $DESTDIR/boot > /dev/null 2>&1
  985. unfreezeboot=y
  986. fi
  987. if [ "$(blkid -o value -s TYPE -p $(findmnt -o source -n $DESTDIR))" == "xfs" ];then
  988. /usr/sbin/xfs_freeze -f $DESTDIR/ > /dev/null 2>&1
  989. unfreezeroot=y
  990. fi
  991. fi
  992.  
  993. #Install stage1
  994. grub --no-floppy --batch >/tmp/grub.log 2>&1 <<EOF
  995. root $bootpartgrub
  996. setup $bootdev
  997. quit
  998. EOF
  999.  
  1000. # unfreeze xfs filesystems if any
  1001. if [ -x /usr/sbin/xfs_freeze ]; then
  1002. [ -z "$unfreezeboot" ] && /usr/sbin/xfs_freeze -u $DESTDIR/boot > /dev/null 2>&1
  1003. [ -z "$unfreezeroot" ] && /usr/sbin/xfs_freeze -u $DESTDIR/ > /dev/null 2>&1
  1004. fi
  1005.  
  1006. cat /tmp/grub.log >$LOG
  1007.  
  1008. if grep "Error [0-9]*: " /tmp/grub.log >/dev/null; then
  1009. DIALOG --msgbox "${_errorinstgrub} (${_errordetails} $LOG)" 0 0
  1010. return 1
  1011. fi
  1012. DIALOG --msgbox "${_instgrubsuccess}" 0 0
  1013. S_GRUB=1
  1014. }
  1015.  
  1016. # set_clock()
  1017. # prompts user to set hardware clock and timezone
  1018. #
  1019. # params: none
  1020. # returns: 1 on failure
  1021. set_clock()
  1022. {
  1023. # utc or local?
  1024. DIALOG --menu "${_machinetimezone}" 10 72 2 \
  1025. "UTC" " " \
  1026. "localtime" " " \
  1027. 2>$ANSWER || return 1
  1028. HARDWARECLOCK=$(cat $ANSWER)
  1029.  
  1030. # timezone?
  1031. REGIONS=""
  1032. for i in $(grep '^[A-Z]' /usr/share/zoneinfo/zone.tab | cut -f 3 | sed -e 's#/.*##g'| sort -u); do
  1033. REGIONS="$REGIONS $i -"
  1034. done
  1035. region=""
  1036. zone=""
  1037. while [ -z "$zone" ];do
  1038. region=""
  1039. while [ -z "$region" ];do
  1040. :>$ANSWER
  1041. DIALOG --menu "${_selectregion}" 0 0 0 $REGIONS 2>$ANSWER
  1042. region=$(cat $ANSWER)
  1043. done
  1044. ZONES=""
  1045. for i in $(grep '^[A-Z]' /usr/share/zoneinfo/zone.tab | grep $region/ | cut -f 3 | sed -e "s#$region/##g"| sort -u); do
  1046. ZONES="$ZONES $i -"
  1047. done
  1048. :>$ANSWER
  1049. DIALOG --menu "${_selecttimezone}" 0 0 0 $ZONES 2>$ANSWER
  1050. zone=$(cat $ANSWER)
  1051. done
  1052. TIMEZONE="$region/$zone"
  1053.  
  1054. # set system clock from hwclock - stolen from rc.sysinit
  1055. local HWCLOCK_PARAMS=""
  1056. if [ "$HARDWARECLOCK" = "UTC" ]; then
  1057. HWCLOCK_PARAMS="$HWCLOCK_PARAMS --utc"
  1058. else
  1059. HWCLOCK_PARAMS="$HWCLOCK_PARAMS --localtime"
  1060. fi
  1061. if [ "$TIMEZONE" != "" -a -e "/usr/share/zoneinfo/$TIMEZONE" ]; then
  1062. /bin/rm -f /etc/localtime
  1063. /bin/cp "/usr/share/zoneinfo/$TIMEZONE" /etc/localtime
  1064. fi
  1065. /sbin/hwclock --hctosys $HWCLOCK_PARAMS --noadjfile
  1066.  
  1067. # display and ask to set date/time
  1068. dialog --calendar "${_choosedatetime}" 0 0 0 0 0 2> $ANSWER || return 1
  1069. local _date="$(cat $ANSWER)"
  1070. dialog --timebox "${_choosehourtime}" 0 0 2> $ANSWER || return 1
  1071. local _time="$(cat $ANSWER)"
  1072. echo "date: $_date time: $_time" >$LOG
  1073.  
  1074. # save the time
  1075. # DD/MM/YYYY hh:mm:ss -> YYYY-MM-DD hh:mm:ss
  1076. local _datetime="$(echo "$_date" "$_time" | sed 's#\(..\)/\(..\)/\(....\) \(..\):\(..\):\(..\)#\3-\2-\1 \4:\5:\6#g')"
  1077. echo "setting date to: $_datetime" >$LOG
  1078. date -s "$_datetime" 2>&1 >$LOG
  1079. /sbin/hwclock --systohc $HWCLOCK_PARAMS --noadjfile
  1080.  
  1081. S_CLOCK=1
  1082. }
  1083.  
  1084. prepare_harddrive()
  1085. {
  1086. S_MKFSAUTO=0
  1087. S_MKFS=0
  1088. DONE=0
  1089. local CURRENT_SELECTION=""
  1090. while [ "$DONE" = "0" ]; do
  1091. if [ -n "$CURRENT_SELECTION" ]; then
  1092. DEFAULT="--default-item $CURRENT_SELECTION"
  1093. else
  1094. DEFAULT=""
  1095. fi
  1096. DIALOG $DEFAULT --menu "${_diskpreparation}" 12 60 5 \
  1097. "1" "${_assistprepa}" \
  1098. "2" "${_manualpartit}" \
  1099. "3" "${_mainmenulabel}" 2>$ANSWER
  1100. CURRENT_SELECTION="$(cat $ANSWER)"
  1101. case $(cat $ANSWER) in
  1102. "1")
  1103. autoprepare ;;
  1104. "2")
  1105. partition
  1106. PARTFINISH=""
  1107. mountpoints ;;
  1108. *)
  1109. DONE=1 ;;
  1110. esac
  1111. done
  1112. }
  1113.  
  1114. # run_mkinitcpio()
  1115. # runs mkinitcpio on the target system, displays output
  1116. #
  1117. run_mkinitcpio()
  1118. {
  1119. chroot_mount
  1120. # all mkinitcpio output goes to /tmp/mkinitcpio.log, which we tail
  1121. # into a dialog
  1122. ( \
  1123. touch /tmp/setup-mkinitcpio-running
  1124. echo "${_runninginitcpio}" > /tmp/mkinitcpio.log; \
  1125. echo >> /tmp/mkinitcpio.log; \
  1126. chroot "$DESTDIR" /sbin/depmod >>/tmp/mkinitcpio.log 2>&1
  1127. chroot "$DESTDIR" /sbin/mkinitcpio -p linux >>/tmp/mkinitcpio.log 2>&1
  1128. echo $? > /tmp/.mkinitcpio-retcode
  1129. echo >> /tmp/mkinitcpio.log
  1130. rm -f /tmp/setup-mkinitcpio-running
  1131. ) &
  1132.  
  1133. sleep 2
  1134.  
  1135. DIALOG --title "${_runninginitcpiotitle}" \
  1136. --no-kill --tailboxbg "/tmp/mkinitcpio.log" 18 70 2>$ANSWER
  1137. while [ -f /tmp/setup-mkinitcpio-running ]; do
  1138. sleep 1
  1139. done
  1140. kill $(cat $ANSWER)
  1141.  
  1142. chroot_umount
  1143.  
  1144. # alert the user to fatal errors
  1145. if [ $(cat /tmp/.mkinitcpio-retcode) -ne 0 ]; then
  1146. DIALOG --title "${_mkinitcpiofailerror}" --exit-label \
  1147. "${_continue_label}" --textbox "/tmp/mkinitcpio.log" 18 70
  1148. return 1
  1149. fi
  1150. }
  1151.  
  1152. configure_system()
  1153. {
  1154. ## PREPROCESSING ##
  1155. # only done on first invocation of configure_system
  1156. if [ $S_CONFIG -eq 0 ]; then
  1157.  
  1158. # /etc/rc.conf
  1159. # insert timezone and utc info
  1160. sed -i -e "s/^TIMEZONE=.*/TIMEZONE=\"$(echo $TIMEZONE | sed "s/\//\\\\\//g")\"/g" \
  1161. -e "s/^HARDWARECLOCK=.*/HARDWARECLOCK=\"$HARDWARECLOCK\"/g" \
  1162. ${DESTDIR}/etc/rc.conf
  1163. fi
  1164.  
  1165. ## END PREPROCESS ##
  1166.  
  1167. local CURRENT_SELECTION=""
  1168. while true; do
  1169. # if [ -n "$CURRENT_SELECTION" ]; then
  1170. # DEFAULT="--default-item $CURRENT_SELECTION"
  1171. # else
  1172. DIALOG $DEFAULT --menu "Configuration" 17 80 10 \
  1173. "Root-Password" "${_definerootpass}" \
  1174. "User-Name" "${_defineusername}" \
  1175. "Config-system" "${_doeditconfig}" \
  1176. "${_return_label}" "${_mainmenulabel}" 2>$ANSWER || CURRENT_SELECTION="${_return_label}"
  1177. CURRENT_SELECTION="$(cat $ANSWER)"
  1178.  
  1179. if [ "$CURRENT_SELECTION" = "${_return_label}" -o -z "$CURRENT_SELECTION" ]; then # exit
  1180. break
  1181. elif [ "$CURRENT_SELECTION" = "Root-Password" ]; then
  1182. while true; do
  1183. chroot ${DESTDIR} passwd root && break
  1184. done
  1185. elif [ "$CURRENT_SELECTION" = "User-Name" ]; then
  1186. cp /usr/bin/mvuser.sh $DESTDIR/root/
  1187. chroot ${DESTDIR} mkdir -p /home/live &> /dev/null
  1188. chroot ${DESTDIR} useradd -u 1000 -g users -G storage,optical,audio,video,network,wheel,power,lp,log -d /home/live live &> /dev/null
  1189. chroot ${DESTDIR} rm -rf /home/live/.[a-zA-Z0-9]* &> /dev/null
  1190. cp -r /etc/skel/.[a-zA-Z0-9]* $DESTDIR/home/live/ &> /dev/null
  1191. cp /etc/skel/DOC $DESTDIR/home/live/ &> /dev/null
  1192. rm $DESTDIR/home/live/.config/openbox/menu.xml
  1193. cp -a /src/menu.xml $DESTDIR/home/live/.config/openbox/menu.xml
  1194. rm $DESTDIR/home/live/.config/openbox/rc.xml
  1195. cp -a /src/rc.xml $DESTDIR/home/live/.config/openbox/rc.xml
  1196. rm $DESTDIR/home/live/.conkyrc
  1197. cp -a /src/.conkyrc $DESTDIR/home/live/.conkyrc
  1198. rm $DESTDIR/home/live/.conkyrc1
  1199. cp -a /src/.conkyrc1 $DESTDIR/home/live/.conkyrc1
  1200. rm $DESTDIR/home/live/.Xdefaults
  1201. cp -a /src/.Xdefaults $DESTDIR/home/live/.Xdefaults &>/dev/null
  1202. chroot ${DESTDIR} chown live:users /home/live -R &> /dev/null
  1203. chroot ${DESTDIR} /root/mvuser.sh
  1204. rm $DESTDIR/root/mvuser.sh
  1205. mkinitcpio -k /bootmnt/arch/boot/${arch}/vmlinuz -c /etc/mkinitcpio.conf -g ${DESTDIR}/boot/initramfs-linux.img
  1206. mkinitcpio -k /bootmnt/arch/boot/${arch}/vmlinuz -c /etc/mkinitcpio.conf -g ${DESTDIR}/boot/initramfs-linux-fallback.img
  1207. cp /bootmnt/arch/boot/${arch}/vmlinuz ${DESTDIR}/boot/vmlinuz-linux
  1208. elif [ "$CURRENT_SELECTION" = "Config-system" ]; then
  1209. while true; do
  1210. if [ -n "$CURRENT_SELECTION" ]; then
  1211. DEFAULT="--default-item $CURRENT_SELECTION"
  1212. else
  1213. DEFAULT=""
  1214. fi
  1215. DIALOG $DEFAULT --menu "Configuration" 17 80 10 \
  1216. "/etc/rc.conf" "${_rcconftext}" \
  1217. "/etc/fstab" "${_fstabtext}" \
  1218. "/etc/mkinitcpio.conf" "${_mkinitcpioconftext}" \
  1219. "/etc/modprobe.d/modprobe.conf" "${_modprobeconftext}" \
  1220. "/etc/resolv.conf" "${_resolvconftext}" \
  1221. "/etc/hosts" "${_hoststext}" \
  1222. "/etc/hosts.deny" "${_hostsdenytext}" \
  1223. "/etc/hosts.allow" "${_hostsallowtext}" \
  1224. "/etc/X11/xorg.conf.d/01-keyboard-layout.conf" "${_xorgkblayouttext}" \
  1225. "/etc/locale.gen" "${_localegentext}" \
  1226. "/etc/pacman.d/mirrorlist" "${_mirrorlisttext}" \
  1227. "/etc/X11/xorg.conf.d/10-evdev.conf" "${_xorgevdevconftext}" \
  1228. "${_return_label}" "${_return_label}" 2>$ANSWER || CURRENT_SELECTION="${_return_label}"
  1229. CURRENT_SELECTION="$(cat $ANSWER)"
  1230.  
  1231. if [ "$CURRENT_SELECTION" = "${_return_label}" -o -z "$CURRENT_SELECTION" ]; then # exit
  1232. break
  1233. else
  1234. $EDITOR ${DESTDIR}${CURRENT_SELECTION}
  1235. fi
  1236. done
  1237. else
  1238. $EDITOR ${DESTDIR}${CURRENT_SELECTION}
  1239. fi
  1240. done
  1241.  
  1242. ## POSTPROCESSING ##
  1243. run_mkinitcpio
  1244. # /etc/locale.gen
  1245. #
  1246. chroot ${DESTDIR} locale-gen
  1247. # /etc/localtime
  1248. cp /etc/localtime ${DESDIR}/etc/localtime &> /dev/null
  1249.  
  1250. ## END POSTPROCESSING ##
  1251. rm -f ${DESTDIR}/usr/bin/abinstall &> /dev/null
  1252. rm -f ${DESTDIR}/usr/bin/mvuser.sh &> /dev/null
  1253. rm -rf ${DESTDIR}/vomi &> /dev/null
  1254. rm -rf ${DESTDIR}/bypass &> /dev/null
  1255. rm -rf ${DESTDIR}/src &> /dev/null
  1256. rmdir ${DESTDIR}/bypass &> /dev/null
  1257. rmdir ${DESTDIR}/src &> /dev/null
  1258. rm ${DESTDIR}/etc/lastmin &> /dev/null
  1259. rm ${DESTDIR}/lib/initcpio/archiso_pxe_nbd &> /dev/null
  1260. rm ${DESTDIR}/lib/initcpio/hooks/archiso &> /dev/null
  1261. rm ${DESTDIR}/lib/initcpio/hooks/archiso_loop_mnt &> /dev/null
  1262. rm ${DESTDIR}/lib/initcpio/hooks/archiso_pxe_nbd &> /dev/null
  1263. rm ${DESTDIR}/lib/initcpio/install/archiso &> /dev/null
  1264. rm ${DESTDIR}/lib/initcpio/install/archiso_loop_mnt &> /dev/null
  1265. rm ${DESTDIR}/lib/initcpio/install/archiso_pxe_nbd &> /dev/null
  1266.  
  1267. S_CONFIG=1
  1268. }
  1269.  
  1270. install_bootloader()
  1271. {
  1272. DIALOG --colors --menu "${_installabootloader}\n\n" \
  1273. 10 65 2 \
  1274. "GRUB" "${_installgrubbl}" \
  1275. "${_none_label}" "${_installnobl}" 2>$ANSWER
  1276. case $(cat $ANSWER) in
  1277. "GRUB") dogrub ;;
  1278. esac
  1279. }
  1280.  
  1281. mainmenu()
  1282. {
  1283. if [ -n "$CURRENT_SELECTION" ]; then
  1284. DEFAULT="--default-item $CURRENT_SELECTION"
  1285. else
  1286. DEFAULT=""
  1287. fi
  1288. DIALOG $DEFAULT --title " ${_mainmenulabel} " \
  1289. --menu "${_mainmenuhelp}" 16 55 8 \
  1290. "1" "${_datetimetext}" \
  1291. "2" "${_preparediskstext}" \
  1292. "3" "${_installsystemtext}" \
  1293. "4" "${_configuresystemtext}" \
  1294. "5" "${_instbootloadertext}" \
  1295. "6" "${_quittext}" 2>$ANSWER
  1296. CURRENT_SELECTION="$(cat $ANSWER)"
  1297. case $(cat $ANSWER) in
  1298. "1")
  1299. set_clock ;;
  1300. "2")
  1301. prepare_harddrive;_hd_is_prepared=1
  1302. ;;
  1303. "3")
  1304. if [ "$_hd_is_prepared" == "1" ];then
  1305. installsystem;_system_is_installed=1
  1306. else
  1307. echo "$_forgotpreparehd"
  1308. read
  1309. if [ "$REPLY" == "perso" ];then
  1310. installsystem;_system_is_installed=1
  1311. fi
  1312. fi
  1313. ;;
  1314. "4")
  1315. if [ "$_system_is_installed" == "1" ];then
  1316. configure_system;_system_is_configured=1
  1317. else
  1318. echo "$_forgotinstalling"
  1319. read
  1320. fi
  1321. ;;
  1322. "5")
  1323. if [ "$_system_is_configured" == "1" ];then
  1324. install_bootloader
  1325. else
  1326. echo "$_forgotsystemconf"
  1327. read
  1328. fi
  1329. ;;
  1330. "6")
  1331. echo ""
  1332. echo "${_installationfinished}"
  1333. echo ""
  1334. _umountall &>/dev/null ; sleep 1 ; exit 0
  1335. ;;
  1336. *)
  1337. if DIALOG --yesno "${_cancelinstall}" 6 40;then
  1338. _umountall &>/dev/null ; exit 0
  1339. fi
  1340. ;;
  1341. esac
  1342. }
  1343.  
  1344. #####################
  1345. ## begin execution ##
  1346.  
  1347. DIALOG --msgbox "${_instwelcomemessage}" 12 65
  1348.  
  1349. while true; do
  1350. mainmenu
  1351. done
  1352.  
  1353. exit 0
Add Comment
Please, Sign In to add comment