archvortex

fluxarinstall

Feb 18th, 2012
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VIM 47.99 KB | None | 0 0
  1. #!/bin/bash
  2.   TITLE="Fluxar Linux 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="Partitioning"
  30.   _errorpartitionningdev="Error partitioning"
  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 cuz stress kills!!'
  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 the up and down arrows 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 Fluxar Installation Program. \nSimply follow the steps in order"'! :D'
  135.   _forgotsystemconf="Doh!! You forgot system configuration. Press enter."
  136.   _forgotinstalling="Installing before configuring would seem more logical, Mr. Spock. 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 /run/archiso/bootmnt/arch/${arch}/root-image.fs.sfs && mount vomi/root-image.fs $DESTDIR/bypass && echo -e "\n About to start copying files. Press enter to continue and press enter again once done copying :D" && read && vcp -Rp $DESTDIR/bypass/ $DESTDIR/)
  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 -ra /etc/skel/.[a-zA-Z0-9]* ${DESTDIR}/root/ &>/dev/null
  841. #cp -a /src/menu.xml ${DESTDIR}/etc/skel/.config/openbox/menu.xml &>/dev/null
  842. cp -a /src/rc.xml ${DESTDIR}/etc/skel/.config/openbox/rc.xml &>/dev/null
  843. #cp -a /src/.conkyrc ${DESTDIR}/etc/skel/.conkyrc &>/dev/null
  844. cp -a /src/.Xdefaults ${DESTDIR}/etc/skel/.Xdefaults &>/dev/null
  845. #cp -a /src/menu.xml ${DESTDIR}/root/.config/openbox/menu.xml &>/dev/null
  846. #cp -a /src/rc.xml ${DESTDIR}/root/.config/openbox/rc.xml &>/dev/null
  847. #cp -a /src/.conkyrc ${DESTDIR}/root/.conkyrc &>/dev/null
  848. cp -a /src/.Xdefaults ${DESTDIR}/root/.Xdefaults &>/dev/null
  849. #cp -a /src/oblogout.conf ${DESTDIR}/etc/oblogout.conf
  850. cp -a /src/rc.local ${DESTDIR}/etc/rc.local
  851. cp /src/inittab ${DESTDIR}/etc/inittab
  852. cp /etc/X11/xorg.conf.d/20-gpudriver.conf ${DESTDIR}/etc/X11/xorg.conf.d/20-gpudriver.conf &>/dev/null
  853. cp -a /src/rc.conf ${DESTDIR}/etc/rc.conf &>/dev/null
  854. }
  855.  
  856. # auto_fstab()
  857. # preprocess fstab file
  858. # comments out old fields and inserts new ones
  859. # according to partitioning/formatting stage
  860. #
  861. auto_fstab()
  862. {
  863.    if [ "$S_MKFS" = "1" -o "$S_MKFSAUTO" = "1" ]; then
  864.        if [ -f /tmp/.fstab ]; then
  865.            # comment out stray /dev entries
  866.            sed -i 's/^\/dev/#\/dev/g' $DESTDIR/etc/fstab
  867.            # append entries from new configuration
  868.            sort /tmp/.fstab >>$DESTDIR/etc/fstab
  869.        fi
  870.    fi
  871. }
  872.  
  873. dogrub() {
  874.    get_grub_map
  875.    local grubmenu="$DESTDIR/boot/grub/menu.lst"
  876.    if [ ! -f $grubmenu ]; then
  877.        DIALOG --msgbox "${_isgrubinst} $grubmenu" 0 0
  878.        return 1
  879.    fi
  880.    # try to auto-configure GRUB...
  881.    if [ "$PART_ROOT" != "" -a "$S_GRUB" != "1" ]; then
  882.        grubdev=$(mapdev $PART_ROOT)
  883.        local _rootpart="${PART_ROOT}"
  884.        local _uuid="$(getuuid ${PART_ROOT})"
  885.        # attempt to use a UUID if the root device has one
  886.        if [ -n "${_uuid}" ]; then
  887.            _rootpart="/dev/disk/by-uuid/${_uuid}"
  888.        fi
  889.        # look for a separately-mounted /boot partition
  890.        bootdev=$(mount | grep $DESTDIR/boot | cut -d' ' -f 1)
  891.        if [ "$grubdev" != "" -o "$bootdev" != "" ]; then
  892.            subdir=
  893.            if [ "$bootdev" != "" ]; then
  894.                grubdev=$(mapdev $bootdev)
  895.            else
  896.                subdir="/boot"
  897.            fi
  898.            # keep the file from being completely bogus
  899.            if [ "$grubdev" = "DEVICE NOT FOUND" ]; then
  900.                DIALOG --msgbox "${_autodetectrootfail} 'root (hd0,0)'" 0 0
  901.                grubdev="(hd0,0)"
  902.            fi
  903.            # generate resume string for suspend to disk
  904.            [ -z "${swap_partition}" -o "${swap_partition}" = "${_none_entry}" ] || hibernpart='resume=/dev/disk/by-uuid/'"$(blkid -s UUID -o value -p ${swap_partition})"
  905.            # remove default entries by truncating file at our little tag (#-*)
  906.            sed -i -e '/#-\*/q' $grubmenu
  907.            sed -i 's/timeout   10/timeout 3/' $grubmenu
  908.            sed -i 's/default   3/default 0/' $grubmenu
  909.            cat >>$grubmenu <<EOF
  910.  
  911. # (0) Fluxar Linux
  912. title  Fluxar Linux
  913. root   $grubdev
  914. 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)
  915. initrd $subdir/initramfs-linux.img
  916.  
  917. # (1) Fluxar Linux fallback (${_bootsonanydisk})
  918. title  Fluxar Linux Fallback
  919. root   $grubdev
  920. kernel $subdir/vmlinuz-linux root=${_rootpart} loglevel=3 ro quiet
  921. initrd $subdir/initramfs-linux-fallback.img
  922.  
  923. # (2) ${_chainloadexpl}
  924. #title sda1
  925. #rootnoverify (hd0,0)
  926. #makeactive
  927. #chainloader +1
  928. EOF
  929.        fi
  930.    fi
  931.  
  932.    DIALOG --msgbox "${_youwilleditmenulst}" 0 0
  933.    $EDITOR $grubmenu
  934.  
  935.    DEVS=$(finddisks _)
  936.    DEVS="$DEVS $(findpartitions _)"
  937.    if [ "$DEVS" = "" ]; then
  938.        DIALOG --msgbox "${_nohdfound}" 0 0
  939.        return 1
  940.    fi
  941.    DIALOG --menu "${_whereinststage1}" 14 55 7 $DEVS 2>$ANSWER || return 1
  942.    ROOTDEV=$(cat $ANSWER)
  943.    DIALOG --infobox "${_installinggrub}" 3 30
  944.    cp -a $DESTDIR/usr/lib/grub/i386-pc/* $DESTDIR/boot/grub/
  945.    sync
  946.  
  947.    # look for a separately-mounted /boot partition
  948.    bootpart=$(mount | grep $DESTDIR/boot | cut -d' ' -f 1)
  949.    if [ "$bootpart" = "" ]; then
  950.        if [ "$PART_ROOT" = "" ]; then
  951.            DIALOG --inputbox "${_enterrootdevpath}" 8 65 "/dev/sda3" 2>$ANSWER || return 1
  952.            bootpart=$(cat $ANSWER)
  953.        else
  954.            bootpart=$PART_ROOT
  955.        fi
  956.    fi
  957.    #DIALOG --defaultno --yesno "Si vous avez monté un RAID : installer GRUB sur un autre disque ?\nGénéralement, non." 0 0
  958.    #if [ $? -eq 0 ]; then
  959.    #    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
  960.     #    bootpart=$(cat $ANSWER)
  961.     #fi
  962.     bootpartgrub=$(mapdev $bootpart)
  963.     bootdev=$(mapdev $ROOTDEV)
  964.     if [ "$bootpart" = "" ]; then
  965.         DIALOG --msgbox "${_missingrootpart} $bootpart" 0 0
  966.         return 1
  967.     fi
  968.     if [ "$bootpartgrub" = "DEVICE NOT FOUND" -o "$bootdev" = "DEVICE NOT FOUND" ]; then
  969.         DIALOG --msgbox "${_cannotfindgrub}" 0 0
  970.         return 1
  971.     fi
  972.  
  973.     # freeze xfs filesystems if any, to enable grub installation on xfs filesystems
  974.     if [ -x /usr/sbin/xfs_freeze ]; then
  975.      if [ "$(blkid -o value -s TYPE -p $(findmnt -o source -n $DESTDIR/boot))" == "xfs" ];then
  976.       /usr/sbin/xfs_freeze -f $DESTDIR/boot > /dev/null 2>&1
  977.       unfreezeboot=y
  978.      fi
  979.      if [ "$(blkid -o value -s TYPE -p $(findmnt -o source -n $DESTDIR))" == "xfs" ];then
  980.       /usr/sbin/xfs_freeze -f $DESTDIR/ > /dev/null 2>&1
  981.       unfreezeroot=y
  982.      fi
  983.     fi
  984.  
  985.     #Install stage1
  986.     grub --no-floppy --batch >/tmp/grub.log 2>&1 <<EOF
  987. root $bootpartgrub
  988. setup $bootdev
  989. quit
  990. EOF
  991.  
  992.     # unfreeze xfs filesystems if any
  993.     if [ -x /usr/sbin/xfs_freeze ]; then
  994.      [ -z "$unfreezeboot" ] && /usr/sbin/xfs_freeze -u $DESTDIR/boot > /dev/null 2>&1
  995.      [ -z "$unfreezeroot" ] && /usr/sbin/xfs_freeze -u $DESTDIR/ > /dev/null 2>&1
  996.     fi
  997.  
  998.     cat /tmp/grub.log >$LOG
  999.  
  1000.     if grep "Error [0-9]*: " /tmp/grub.log >/dev/null; then
  1001.         DIALOG --msgbox "${_errorinstgrub} (${_errordetails} $LOG)" 0 0
  1002.         return 1
  1003.     fi
  1004.     DIALOG --msgbox "${_instgrubsuccess}" 0 0
  1005.     S_GRUB=1
  1006. }
  1007.  
  1008. # set_clock()
  1009. # prompts user to set hardware clock and timezone
  1010. #
  1011. # params: none
  1012. # returns: 1 on failure
  1013. set_clock()
  1014. {
  1015.     # utc or local?
  1016.     DIALOG --menu "${_machinetimezone}" 10 72 2 \
  1017.         "UTC" " " \
  1018.         "localtime" " " \
  1019.         2>$ANSWER || return 1
  1020.     HARDWARECLOCK=$(cat $ANSWER)
  1021.  
  1022.     # timezone?
  1023.     REGIONS=""
  1024.     for i in $(grep '^[A-Z]' /usr/share/zoneinfo/zone.tab | cut -f 3 | sed -e 's#/.*##g'| sort -u); do
  1025.       REGIONS="$REGIONS $i -"
  1026.     done
  1027.     region=""
  1028.     zone=""
  1029.     while [ -z "$zone" ];do
  1030.       region=""
  1031.       while [ -z "$region" ];do
  1032.         :>$ANSWER
  1033.         DIALOG --menu "${_selectregion}" 0 0 0 $REGIONS 2>$ANSWER
  1034.         region=$(cat $ANSWER)
  1035.       done
  1036.       ZONES=""
  1037.       for i in $(grep '^[A-Z]' /usr/share/zoneinfo/zone.tab | grep $region/ | cut -f 3 | sed -e "s#$region/##g"| sort -u); do
  1038.         ZONES="$ZONES $i -"
  1039.       done
  1040.       :>$ANSWER
  1041.       DIALOG --menu "${_selecttimezone}" 0 0 0 $ZONES 2>$ANSWER
  1042.       zone=$(cat $ANSWER)
  1043.     done
  1044.     TIMEZONE="$region/$zone"
  1045.  
  1046.     # set system clock from hwclock - stolen from rc.sysinit
  1047.     local HWCLOCK_PARAMS=""
  1048.     if [ "$HARDWARECLOCK" = "UTC" ]; then
  1049.         HWCLOCK_PARAMS="$HWCLOCK_PARAMS --utc"
  1050.     else
  1051.         HWCLOCK_PARAMS="$HWCLOCK_PARAMS --localtime"
  1052.     fi
  1053.     if [ "$TIMEZONE" != "" -a -e "/usr/share/zoneinfo/$TIMEZONE" ]; then
  1054.         /bin/rm -f /etc/localtime
  1055.         /bin/cp "/usr/share/zoneinfo/$TIMEZONE" /etc/localtime
  1056.     fi
  1057.     /sbin/hwclock --hctosys $HWCLOCK_PARAMS --noadjfile
  1058.  
  1059.     # display and ask to set date/time
  1060.     dialog --calendar "${_choosedatetime}" 0 0 0 0 0 2> $ANSWER || return 1
  1061.     local _date="$(cat $ANSWER)"
  1062.     dialog --timebox "${_choosehourtime}" 0 0 2> $ANSWER || return 1
  1063.     local _time="$(cat $ANSWER)"
  1064.     echo "date: $_date time: $_time" >$LOG
  1065.  
  1066.     # save the time
  1067.     # DD/MM/YYYY hh:mm:ss -> YYYY-MM-DD hh:mm:ss
  1068.     local _datetime="$(echo "$_date" "$_time" | sed 's#\(..\)/\(..\)/\(....\) \(..\):\(..\):\(..\)#\3-\2-\1 \4:\5:\6#g')"
  1069.     echo "setting date to: $_datetime" >$LOG
  1070.     date -s "$_datetime" 2>&1 >$LOG
  1071.     /sbin/hwclock --systohc $HWCLOCK_PARAMS --noadjfile
  1072.  
  1073.     S_CLOCK=1
  1074. }
  1075.  
  1076. prepare_harddrive()
  1077. {
  1078.     S_MKFSAUTO=0
  1079.     S_MKFS=0
  1080.     DONE=0
  1081.     local CURRENT_SELECTION=""
  1082.     while [ "$DONE" = "0" ]; do
  1083.         if [ -n "$CURRENT_SELECTION" ]; then
  1084.             DEFAULT="--default-item $CURRENT_SELECTION"
  1085.         else
  1086.             DEFAULT=""
  1087.         fi
  1088.         DIALOG $DEFAULT --menu "${_diskpreparation}" 12 60 5 \
  1089.             "1" "${_assistprepa}" \
  1090.             "2" "${_manualpartit}" \
  1091.             "3" "${_mainmenulabel}" 2>$ANSWER
  1092.         CURRENT_SELECTION="$(cat $ANSWER)"
  1093.         case $(cat $ANSWER) in
  1094.             "1")
  1095.                 autoprepare ;;
  1096.             "2")
  1097.                 partition
  1098.                 PARTFINISH=""
  1099.                 mountpoints ;;
  1100.             *)
  1101.                 DONE=1 ;;
  1102.         esac
  1103.     done
  1104. }
  1105.  
  1106. # run_mkinitcpio()
  1107. # runs mkinitcpio on the target system, displays output
  1108. #
  1109. run_mkinitcpio()
  1110. {
  1111.     chroot_mount
  1112.     # all mkinitcpio output goes to /tmp/mkinitcpio.log, which we tail
  1113.     # into a dialog
  1114.     ( \
  1115.         touch /tmp/setup-mkinitcpio-running
  1116.         echo "${_runninginitcpio}" > /tmp/mkinitcpio.log; \
  1117.         echo >> /tmp/mkinitcpio.log; \
  1118.         chroot "$DESTDIR" /sbin/depmod >>/tmp/mkinitcpio.log 2>&1
  1119.         chroot "$DESTDIR" /sbin/mkinitcpio -p linux >>/tmp/mkinitcpio.log 2>&1
  1120.         echo $? > /tmp/.mkinitcpio-retcode
  1121.         echo >> /tmp/mkinitcpio.log
  1122.         rm -f /tmp/setup-mkinitcpio-running
  1123.     ) &
  1124.  
  1125.     sleep 2
  1126.  
  1127.     DIALOG --title "${_runninginitcpiotitle}" \
  1128.         --no-kill --tailboxbg "/tmp/mkinitcpio.log" 18 70 2>$ANSWER
  1129.     while [ -f /tmp/setup-mkinitcpio-running ]; do
  1130.         sleep 1
  1131.     done
  1132.     kill $(cat $ANSWER)
  1133.  
  1134.     chroot_umount
  1135.  
  1136.     # alert the user to fatal errors
  1137.     if [ $(cat /tmp/.mkinitcpio-retcode) -ne 0 ]; then
  1138.         DIALOG --title "${_mkinitcpiofailerror}" --exit-label \
  1139.         "${_continue_label}" --textbox "/tmp/mkinitcpio.log" 18 70
  1140.         return 1
  1141.     fi
  1142. }
  1143.  
  1144. configure_system()
  1145. {
  1146.     ## PREPROCESSING ##
  1147.     # only done on first invocation of configure_system
  1148.     if [ $S_CONFIG -eq 0 ]; then
  1149.  
  1150.         # /etc/rc.conf
  1151.         # insert timezone and utc info
  1152.         sed -i -e "s/^TIMEZONE=.*/TIMEZONE=\"$(echo $TIMEZONE | sed "s/\//\\\\\//g")\"/g" \
  1153.                -e "s/^HARDWARECLOCK=.*/HARDWARECLOCK=\"$HARDWARECLOCK\"/g" \
  1154.                ${DESTDIR}/etc/rc.conf
  1155.     fi
  1156.  
  1157.     ## END PREPROCESS ##
  1158.  
  1159.     local CURRENT_SELECTION=""
  1160.   while true; do
  1161.        # if [ -n "$CURRENT_SELECTION" ]; then
  1162.        #     DEFAULT="--default-item $CURRENT_SELECTION"
  1163.        # else
  1164.         DIALOG $DEFAULT --menu "Configuration" 17 80 10 \
  1165.             "Root-Password"             "${_definerootpass}" \
  1166.             "User-Name"                 "${_defineusername}" \
  1167.             "Config-system"             "${_doeditconfig}" \
  1168.             "${_return_label}"          "${_mainmenulabel}" 2>$ANSWER || CURRENT_SELECTION="${_return_label}"
  1169.         CURRENT_SELECTION="$(cat $ANSWER)"
  1170.  
  1171.         if [ "$CURRENT_SELECTION" = "${_return_label}" -o -z "$CURRENT_SELECTION" ]; then       # exit
  1172.             break
  1173.         elif [ "$CURRENT_SELECTION" = "Root-Password" ]; then
  1174.             while true; do
  1175.                 chroot ${DESTDIR} passwd root && break
  1176.             done
  1177.         elif [ "$CURRENT_SELECTION" = "User-Name" ]; then
  1178.                 cp /usr/bin/mvuser.sh $DESTDIR/root/
  1179.                 rm $DESTDIR/home/live/.config/openbox/menu.xml
  1180.                 cp -a /src/menu.xml $DESTDIR/home/live/.config/openbox/menu.xml
  1181.                 rm $DESTDIR/home/live/.config/openbox/rc.xml
  1182.                 cp -a /src/rc.xml $DESTDIR/home/live/.config/openbox/rc.xml
  1183.                 rm $DESTDIR/home/live/.conkyrc
  1184.                 cp -a /src/.conkyrc $DESTDIR/home/live/.conkyrc
  1185.                 rm $DESTDIR/home/live/.conkyrc1
  1186.                 cp -a /src/.conkyrc1 $DESTDIR/home/live/.conkyrc1
  1187.                 rm $DESTDIR/home/live/.Xdefaults
  1188.                 cp -a /src/.Xdefaults $DESTDIR/home/live/.Xdefaults &>/dev/null
  1189.                 chroot ${DESTDIR} chown live:users /home/live -R &> /dev/null
  1190.                 chroot ${DESTDIR} /root/mvuser.sh
  1191.                 rm $DESTDIR/root/mvuser.sh
  1192.                 mkinitcpio -k /run/archiso/bootmnt/arch/boot/${arch}/vmlinuz -c /etc/mkinitcpio.conf -g ${DESTDIR}/boot/initramfs-linux.img
  1193.                 mkinitcpio -k /run/archiso/bootmnt/arch/boot/${arch}/vmlinuz -c /etc/mkinitcpio.conf -g ${DESTDIR}/boot/initramfs-linux-fallback.img
  1194.                 cp /run/archiso/bootmnt/arch/boot/${arch}/vmlinuz ${DESTDIR}/boot/vmlinuz-linux
  1195.         elif [ "$CURRENT_SELECTION" = "Config-system" ]; then
  1196.     while true; do
  1197.         if [ -n "$CURRENT_SELECTION" ]; then
  1198.             DEFAULT="--default-item $CURRENT_SELECTION"
  1199.         else
  1200.             DEFAULT=""
  1201.         fi
  1202.         DIALOG $DEFAULT --menu "Configuration" 17 80 10 \
  1203.             "/etc/rc.conf"              "${_rcconftext}" \
  1204.             "/etc/fstab"                "${_fstabtext}" \
  1205.             "/etc/mkinitcpio.conf"      "${_mkinitcpioconftext}" \
  1206.             "/etc/modprobe.d/modprobe.conf" "${_modprobeconftext}" \
  1207.             "/etc/resolv.conf"          "${_resolvconftext}" \
  1208.             "/etc/hosts"                "${_hoststext}" \
  1209.             "/etc/hosts.deny"           "${_hostsdenytext}" \
  1210.             "/etc/hosts.allow"          "${_hostsallowtext}" \
  1211.             "/etc/X11/xorg.conf.d/01-keyboard-layout.conf"      "${_xorgkblayouttext}" \
  1212.             "/etc/locale.gen"           "${_localegentext}" \
  1213.             "/etc/pacman.d/mirrorlist"  "${_mirrorlisttext}" \
  1214.             "/etc/X11/xorg.conf.d/10-evdev.conf"  "${_xorgevdevconftext}" \
  1215.             "${_return_label}"        "${_return_label}" 2>$ANSWER || CURRENT_SELECTION="${_return_label}"
  1216.         CURRENT_SELECTION="$(cat $ANSWER)"
  1217.  
  1218.         if [ "$CURRENT_SELECTION" = "${_return_label}" -o -z "$CURRENT_SELECTION" ]; then       # exit
  1219.             break
  1220.         else
  1221.             $EDITOR ${DESTDIR}${CURRENT_SELECTION}
  1222.         fi
  1223.     done
  1224.         else
  1225.             $EDITOR ${DESTDIR}${CURRENT_SELECTION}
  1226.         fi
  1227.   done
  1228.  
  1229.     ## POSTPROCESSING ##
  1230.     run_mkinitcpio
  1231.     # /etc/locale.gen
  1232.     #
  1233.     chroot ${DESTDIR} locale-gen
  1234.     # /etc/localtime
  1235.     cp /etc/localtime ${DESDIR}/etc/localtime &> /dev/null
  1236.  
  1237.     ## END POSTPROCESSING ##
  1238.     rm -f ${DESTDIR}/usr/bin/abinstall &> /dev/null
  1239.     rm -f ${DESTDIR}/usr/bin/mvuser.sh &> /dev/null
  1240.     rm -rf ${DESTDIR}/vomi &> /dev/null
  1241.     rm -rf ${DESTDIR}/bypass &> /dev/null
  1242.     rm -rf ${DESTDIR}/src &> /dev/null
  1243.     rmdir ${DESTDIR}/bypass &> /dev/null
  1244.     rmdir ${DESTDIR}/src &> /dev/null
  1245.     rm ${DESTDIR}/etc/lastmin &> /dev/null
  1246.     rm ${DESTDIR}/lib/initcpio/archiso_pxe_nbd &> /dev/null
  1247.     rm ${DESTDIR}/lib/initcpio/hooks/archiso &> /dev/null
  1248.     rm ${DESTDIR}/lib/initcpio/hooks/archiso_loop_mnt &> /dev/null
  1249.     rm ${DESTDIR}/lib/initcpio/hooks/archiso_pxe_nbd &> /dev/null
  1250.     rm ${DESTDIR}/lib/initcpio/install/archiso &> /dev/null
  1251.     rm ${DESTDIR}/lib/initcpio/install/archiso_loop_mnt &> /dev/null
  1252.     rm ${DESTDIR}/lib/initcpio/install/archiso_pxe_nbd &> /dev/null
  1253.  
  1254.     S_CONFIG=1
  1255. }
  1256.  
  1257. install_bootloader()
  1258. {
  1259.     DIALOG --colors --menu "${_installabootloader}\n\n" \
  1260.         10 65 2 \
  1261.         "GRUB" "${_installgrubbl}" \
  1262.         "${_none_label}" "${_installnobl}" 2>$ANSWER
  1263.     case $(cat $ANSWER) in
  1264.         "GRUB") dogrub ;;
  1265.     esac
  1266. }
  1267.  
  1268. mainmenu()
  1269. {
  1270.     if [ -n "$CURRENT_SELECTION" ]; then
  1271.         DEFAULT="--default-item $CURRENT_SELECTION"
  1272.     else
  1273.         DEFAULT=""
  1274.     fi
  1275.     DIALOG $DEFAULT --title " ${_mainmenulabel} " \
  1276.         --menu "${_mainmenuhelp}" 16 55 8 \
  1277.         "1" "${_datetimetext}" \
  1278.         "2" "${_preparediskstext}" \
  1279.         "3" "${_installsystemtext}" \
  1280.         "4" "${_configuresystemtext}" \
  1281.         "5" "${_instbootloadertext}" \
  1282.         "6" "${_quittext}" 2>$ANSWER
  1283.     CURRENT_SELECTION="$(cat $ANSWER)"
  1284.     case $(cat $ANSWER) in
  1285.         "1")
  1286.             set_clock ;;
  1287.         "2")
  1288.             prepare_harddrive;_hd_is_prepared=1
  1289.         ;;
  1290.         "3")
  1291.             if [ "$_hd_is_prepared" == "1" ];then
  1292.              installsystem;_system_is_installed=1
  1293.             else
  1294.              echo "$_forgotpreparehd"
  1295.              read
  1296.              if [ "$REPLY" == "perso" ];then
  1297.               installsystem;_system_is_installed=1
  1298.              fi
  1299.             fi
  1300.         ;;
  1301.         "4")
  1302.             if [ "$_system_is_installed" == "1" ];then
  1303.              configure_system;_system_is_configured=1
  1304.             else
  1305.              echo "$_forgotinstalling"
  1306.              read
  1307.             fi
  1308.         ;;
  1309.         "5")
  1310.             if [ "$_system_is_configured" == "1" ];then
  1311.              install_bootloader
  1312.             else
  1313.              echo "$_forgotsystemconf"
  1314.              read
  1315.             fi
  1316.         ;;
  1317.         "6")
  1318.             echo ""
  1319.             echo "${_installationfinished}"
  1320.             echo ""
  1321.             _umountall &>/dev/null ; sleep 1 ; exit 0
  1322.         ;;
  1323.         *)
  1324.             if DIALOG --yesno "${_cancelinstall}" 6 40;then
  1325.              _umountall &>/dev/null ; exit 0
  1326.             fi
  1327.         ;;
  1328.     esac
  1329. }
  1330.  
  1331. #####################
  1332. ## begin execution ##
  1333.  
  1334. DIALOG --msgbox "${_instwelcomemessage}" 12 65
  1335.  
  1336. while true; do
  1337.     mainmenu
  1338. done
  1339.  
  1340. exit 0
Advertisement
Add Comment
Please, Sign In to add comment