util.sh 18.8 KB
Newer Older
Bernhard Landauer's avatar
Bernhard Landauer committed
1 2
# !/bin/bash
#
3
# Architect Installation Framework (2016-2017)
Bernhard Landauer's avatar
Bernhard Landauer committed
4
#
5 6 7
# Written by Carl Duff and @mandog for Archlinux
# Heavily modified and re-written by @Chrysostomus to install Manjaro instead
# Contributors: @papajoker, @oberon and the Manjaro-Community.
Bernhard Landauer's avatar
Bernhard Landauer committed
8 9 10 11 12
#
# This program is free software, provided under the GNU General Public License
# as published by the Free Software Foundation. So feel free to copy, distribute,
# or modify it as you wish.

13
# Header
Bernhard Landauer's avatar
Bernhard Landauer committed
14
VERSION="Manjaro Architect Installer v$version"
15 16

# Host system information
17
ARCHI=$(uname -m)  # Display whether 32 or 64 bit system
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
SYSTEM="Unknown"   # Display whether system is BIOS or UEFI. Default is "unknown"
H_INIT=""          # Host init-sys
NW_CMD=""          # command to launch the available network client

# Locale and Language
CURR_LOCALE="en_US.UTF-8"   # Default Locale
FONT=""                     # Set new font if necessary
KEYMAP="us"                 # Virtual console keymap. Default is "us"
XKBMAP="us"                 # X11 keyboard layout. Default is "us"
ZONE=""                     # For time
SUBZONE=""                  # For time
LOCALE="en_US.UTF-8"        # System locale. Default is "en_US.UTF-8"
PROFILES=""                 # iso-profiles path

# Menu highlighting (automated step progression)
HIGHLIGHT=0                 # Highlight items for Main Menu
HIGHLIGHT_SUB=0             # Highlight items for submenus
SUB_MENU=""                 # Submenu to be highlighted
PARENT=""                   # the parent menu

38
# Temporary files to store menu selections and errors
39
ANSWER="/tmp/.answer"       # Basic menu selections
40 41 42
PACKAGES="/tmp/.pkgs"       # Packages to install
MOUNT_OPTS="/tmp/.mnt_opts" # Filesystem Mount options
INIT="/tmp/.init"           # init systemd|openrc
43
ERR="/tmp/.errlog"
patrick's avatar
patrick committed
44
BRANCH="/tmp/.branch"
45

Bernhard Landauer's avatar
Bernhard Landauer committed
46
# Installer-Log
Bernhard Landauer's avatar
Bernhard Landauer committed
47
LOGFILE="/var/log/m-a.log"  # path for the installer log in the live environment
48
[[ ! -e $LOGFILE ]] && touch $LOGFILE
Bernhard Landauer's avatar
Bernhard Landauer committed
49
TARGLOG="/mnt/.m-a.log"     # path to copy the installer log to target install
patrick's avatar
patrick committed
50
INIFILE="/tmp/manjaro-architect.ini"
Bernhard Landauer's avatar
Bernhard Landauer committed
51

52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
# file systems
BTRFS=0
LUKS=0
LUKS_DEV=""
LUKS_NAME=""
LUKS_OPT=""         # Default or user-defined?
LUKS_UUID=""
LVM=0
LVM_LV_NAME=""      # Name of LV to create or use
LVM_VG=""
LVM_VG_MB=0
VG_PARTS=""
LVM_SEP_BOOT=0      # 1 = Seperate /boot, 2 = seperate /boot & LVM
LV_SIZE_INVALID=0   # Is LVM LV size entered valid?
VG_SIZE_TYPE=""     # Is VG in Gigabytes or Megabytes?
patrick's avatar
patrick committed
67

68
# Mounting
69
MOUNT=""                        # Installation: All other mounts branching
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
MOUNTPOINT="/mnt"               # Installation: Root mount from Root
FS_OPTS=""                      # File system special mount options available
CHK_NUM=16                      # Used for FS mount options checklist length
INCLUDE_PART='part\|lvm\|crypt' # Partition types to include for display and selection.
ROOT_PART=""                    # ROOT partition
UEFI_PART=""                    # UEFI partition
UEFI_MOUNT=""                   # UEFI mountpoint (/boot or /boot/efi)

# Edit Files
FILE=""          # File(s) to be reviewed

# Installation
DM_INST=""       # Which DMs have been installed?
DM_ENABLED=0     # Has a display manager been enabled?
NM_INST=""       # Which NMs have been installed?
NM_ENABLED=0     # Has a network connection manager been enabled?
GRAPHIC_CARD=""  # graphics card
INTEGRATED_GC="" # Integrated graphics card for NVIDIA
NVIDIA_INST=0    # Indicates if NVIDIA proprietary driver has been installed
NVIDIA=""        # NVIDIA driver(s) to install depending on kernel(s)
VB_MOD=""        # headers packages to install depending on kernel(s)
SHOW_ONCE=0      # Show de_wm information only once
COPY_PACCONF=0   # Copy over installer /etc/pacman.conf to installed system?

Bernhard Landauer's avatar
Bernhard Landauer committed
94 95 96 97
import(){
    if [[ -r $1 ]];then
        source $1
    else
Bernhard Landauer's avatar
Bernhard Landauer committed
98
        echo "Could not import $1"
Bernhard Landauer's avatar
Bernhard Landauer committed
99
    fi
Bernhard Landauer's avatar
Bernhard Landauer committed
100
}
Bernhard Landauer's avatar
Bernhard Landauer committed
101

102
DIALOG() {
Bernhard Landauer's avatar
Bernhard Landauer committed
103
    dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --column-separator "|" --exit-label "$_Back" --title "$@"
104 105
}

patrick's avatar
patrick committed
106
# store datas in ini file
107 108
# read: value=$(ini system.init)
# set:  ini system.init "openrc"
patrick's avatar
patrick committed
109 110 111 112 113 114
ini() {
    local section="$1" value="$2"
    [[ ! -f "$INIFILE" ]] && echo "">"$INIFILE"
    if [[ ! "$section" =~ \. ]]; then
        section="manjaro-architect.${section}"
    fi
patrick's avatar
patrick committed
115
    ini_val "$INIFILE" "$section" "$value" 2>/dev/null
patrick's avatar
patrick committed
116 117 118 119 120 121 122 123
}

function finishini {
    [[ -f "$INIFILE" ]] && mv "$INIFILE" "/var/log/m-a.ini" &>/dev/null
    ((debug)) && cat "/var/log/m-a.ini"
}
trap finishini EXIT

124 125 126 127 128
# progress through menu entries until number $1 is reached
submenu() {
    if [[ $SUB_MENU != "$PARENT" ]]; then
        SUB_MENU="$PARENT"
        HIGHLIGHT_SUB=1
Bernhard Landauer's avatar
Bernhard Landauer committed
129
    elif [[ $HIGHLIGHT_SUB != "$1" ]]; then
130 131 132 133 134 135 136
        HIGHLIGHT_SUB=$(( HIGHLIGHT_SUB + 1 ))
    fi
}

# Adapted from AIS. Checks if system is made by Apple, whether the system is BIOS or UEFI,
# and for LVM and/or LUKS.
id_system() {
137
    printf "\n    :: $(pacman -Q manjaro-architect) ::\n\n" >> ${LOGFILE}
Bernhard Landauer's avatar
Bernhard Landauer committed
138

patrick's avatar
patrick committed
139 140 141 142
    echo "">"$INIFILE"
    ini version "$version"
    ini date "$(date +%D\ %T)"

143 144 145 146 147 148
    # Apple System Detection
    if [[ "$(cat /sys/class/dmi/id/sys_vendor)" == 'Apple Inc.' ]] || [[ "$(cat /sys/class/dmi/id/sys_vendor)" == 'Apple Computer, Inc.' ]]; then
        modprobe -r -q efivars || true  # if MAC
    else
        modprobe -q efivarfs             # all others
    fi
patrick's avatar
patrick committed
149

150 151 152 153 154 155 156 157
    # BIOS or UEFI Detection
    if [[ -d "/sys/firmware/efi/" ]]; then
        # Mount efivarfs if it is not already mounted
        if [[ -z $(mount | grep /sys/firmware/efi/efivars) ]]; then
            mount -t efivarfs efivarfs /sys/firmware/efi/efivars
        fi
        SYSTEM="UEFI"
    else
Bernhard Landauer's avatar
Bernhard Landauer committed
158
        SYSTEM="BIOS"
159
    fi
patrick's avatar
patrick committed
160
    ini system.bios "$SYSTEM"
161 162 163 164 165 166 167

    # init system
    if [ $(cat /proc/1/comm) == "systemd" ]; then
        H_INIT="systemd"
    else
        H_INIT="openrc"
    fi
patrick's avatar
patrick committed
168
    ini system.init "$H_INIT"
169 170

    ## TODO: Test which nw-client is available, including if the service according to $H_INIT is running
171 172 173
    [[ $H_INIT == "systemd" ]] && [[ $(systemctl is-active NetworkManager) == "active" ]] && NW_CMD=nmtui 2>$ERR

    check_for_error "system: $SYSTEM, init: $H_INIT nw-client: $NW_CMD"
174 175 176

    # evaluate host branch
    ini system.branch "$(grep -oE -m 1 "unstable|stable|testing" /etc/pacman.d/mirrorlist)"
177 178
}

179
# If there is an error, display it and go back to main menu. In any case, write to logfile.
Bernhard Landauer's avatar
Bernhard Landauer committed
180
# param 2 : error code is optional
patrick's avatar
patrick committed
181
# param 3 : return menu function , optional, default: main_menu_online
182
check_for_error() {
Bernhard Landauer's avatar
Bernhard Landauer committed
183 184
    local _msg="$1"
    local _err="${2:-0}"
185
    local _function_menu="${3:-main_menu}"
Bernhard Landauer's avatar
Bernhard Landauer committed
186
    ((${_err}!=0)) && _msg="[${_msg}][${_err}]"
Bernhard Landauer's avatar
Bernhard Landauer committed
187
    [[ -f "${ERR}" ]] && {
Bernhard Landauer's avatar
Bernhard Landauer committed
188
        _msg="${_msg} $(head -n1 ${ERR})"
189 190
        rm "${ERR}"
    }
patrick's avatar
patrick committed
191 192 193
    if ((${_err}!=0)) ; then
        # and function varsdump ? _msg="$_msg \n $(declare -p | grep -v " _")"
        local _fpath="${FUNCNAME[*]:1:2}()"
patrick's avatar
patrick committed
194
        _fpath=" --${_fpath// /()<-}"
Bernhard Landauer's avatar
Bernhard Landauer committed
195 196
        ! ((debug)) && _fpath=""
        echo -e "$(date +%D\ %T) ERROR ${_msg}${_fpath}" >> "${LOGFILE}"
Matti Hyttinen's avatar
Matti Hyttinen committed
197
        if [[  "${_function_menu}" != "SKIP" ]]; then
198
            DIALOG " $_ErrTitle " --msgbox "\n${_msg}\n" 0 0
patrick's avatar
patrick committed
199 200
            # return error for return to parent menu
            return $_err
Bernhard Landauer's avatar
Bernhard Landauer committed
201
        fi
202
    else
patrick's avatar
patrick committed
203
        # add $FUNCNAME limit to 20 max for control if recursive
Bernhard Landauer's avatar
Bernhard Landauer committed
204 205
        ((debug)) && _msg="${_msg} --${FUNCNAME[*]:1:20}"
        echo -e "$(date +%D\ %T) ${_msg}" >> "${LOGFILE}"
206 207 208
    fi
}

209 210 211
set_language() {
    if [[ ! $(grep font /var/log/m-a.ini 2>/dev/null) ]]; then
        select_language
212 213
    else
        CURR_LOCALE="$(grep lang /var/log/m-a.ini | cut -d' ' -f3)"
214 215 216 217
        KEYMAP="$(grep keymap /var/log/m-a.ini | cut -d' ' -f3)"
        FONT="$(grep font /var/log/m-a.ini | cut -d' ' -f3)"
        TRANS="$(grep translation /var/log/m-a.ini | cut -d' ' -f3)"
        import $DATADIR/translations/$TRANS.trans
Bernhard Landauer's avatar
Bernhard Landauer committed
218
        ini translation "$TRANS"
219

220
        # does user want to change the old settings?
221
        DIALOG " $_SelLang " --yes-label "$_Keep" --no-label "$_Change" --yesno "\n${_Lang}: ${TRANS^}\n " 0 0 || select_language
222
    fi
223

224
    # Generate locale and set language
Bernhard Landauer's avatar
Bernhard Landauer committed
225
    DIALOG " $_Config " --infobox "\n$_ApplySet\n " 0 0
Bernhard Landauer's avatar
Bernhard Landauer committed
226 227 228 229
    sed -i "s/#${CURR_LOCALE}/${CURR_LOCALE}/" /etc/locale.gen
    locale-gen >/dev/null 2>$ERR
    export LANG=${CURR_LOCALE}
    check_for_error "set LANG=${CURR_LOCALE}" $?
patrick's avatar
patrick committed
230
    ini system.lang "$CURR_LOCALE"
231

232 233
    setfont $FONT 2>$ERR
    check_for_error "set font $FONT" $?
Bernhard Landauer's avatar
Bernhard Landauer committed
234
    ini linux.font "$FONT"
Bernhard Landauer's avatar
Bernhard Landauer committed
235

Bernhard Landauer's avatar
Bernhard Landauer committed
236
    set_keymap
237
}
238

239 240
# set locale, keymap and font and source translation file for installer
select_language() {
Bernhard Landauer's avatar
Bernhard Landauer committed
241
    fl="1" # terminus-font variation supporting most languages
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311
    DIALOG " Select Language " --default-item '3' --menu "\n " 0 0 11 \
      "1" $"Danish|(da_DK)" \
      "2" $"Dutch|(nl_NL)" \
      "3" $"English|(en_**)" \
      "4" $"French|(fr_FR)" \
      "5" $"German|(de_DE)" \
      "6" $"Hungarian|(hu_HU)" \
      "7" $"Italian|(it_IT)" \
      "8" $"Portuguese|(pt_PT)" \
      "9" $"Portuguese [Brasil]|(pt_BR)" \
      "10" $"Russian|(ru_RU)" \
      "11" $"Spanish|(es_ES)" 2>${ANSWER}

    case $(cat ${ANSWER}) in
        "1") TRANS="danish"
             CURR_LOCALE="da_DK.UTF-8"
             KEYMAP="dk"
             ;;
        "2") TRANS="dutch"
             CURR_LOCALE="nl_NL.UTF-8"
             KEYMAP="nl"
             ;;
        "3") TRANS="english"
             CURR_LOCALE="en_US.UTF-8"
             KEYMAP="us"
             ;;
        "4") TRANS="french"
             CURR_LOCALE="fr_FR.UTF-8"
             KEYMAP="fr"
             ;;
        "5") TRANS="german"
             CURR_LOCALE="de_DE.UTF-8"
             KEYMAP="de"
             ;;
        "6") TRANS="hungarian"
             CURR_LOCALE="hu_HU.UTF-8"
             KEYMAP="hu"
             fl="2"
             ;;
        "7") TRANS="italian"
             CURR_LOCALE="it_IT.UTF-8"
             KEYMAP="it"
             ;;
        "8") TRANS="portuguese"
             CURR_LOCALE="pt_PT.UTF-8"
             KEYMAP="pt-latin1"
             ;;
        "9") TRANS="portuguese_brasil"
             CURR_LOCALE="pt_BR.UTF-8"
             KEYMAP="pt-latin1"
             ;;
        "10") TRANS="russian"
             CURR_LOCALE="ru_RU.UTF-8"
             KEYMAP="ru"
             fl="u"
             ;;
        "11") TRANS="spanish"
             CURR_LOCALE="es_ES.UTF-8"
             KEYMAP="es"
             ;;
        *) clear && exit 0
             ;;
    esac

    # source translation file
    import $DATADIR/translations/$TRANS.trans
    ini translation "$TRANS"

    # adjust terminus font size depending on resolution
    biggest_resolution=$(head -n 1 /sys/class/drm/card*/*/modes | awk -F'[^0-9]*' '{print $1}' | awk 'BEGIN{a=   0}{if ($1>a) a=$1 fi} END{print a}')
312 313 314 315 316 317 318
    if [[ $biggest_resolution -gt 1920 ]]; then
        fs="24"
    elif [[ $biggest_resolution -eq 1920 ]]; then
        fs="18"
    else
        fs="16"
    fi
319

320 321
    FONT="ter-${fl}${fs}n"
    ini linux.font "$FONT"
322 323
}

324
select_keymap() {
325 326 327
    # does user want to change the default settings?
    DIALOG " $_VCKeymapTitle " --yes-label "$_Keep" --no-label "$_Change" --yesno "\n${_DefKeymap}\n\n[ ${KEYMAP} ]\n " 0 0 && return 0

328 329 330 331 332 333 334 335 336
    KEYMAPS=""
    for i in $(ls -R /usr/share/kbd/keymaps | grep "map.gz" | sed 's/\.map\.gz//g' | sort); do
        KEYMAPS="${KEYMAPS} ${i} -"
    done

    DIALOG " $_VCKeymapTitle " --menu "\n$_VCKeymapBody\n " 20 40 20 ${KEYMAPS} 2>${ANSWER} || return 0
    KEYMAP=$(cat ${ANSWER})
}

Bernhard Landauer's avatar
Bernhard Landauer committed
337 338 339 340 341 342
set_keymap() {
    loadkeys $KEYMAP 2>$ERR
    check_for_error "loadkeys $KEYMAP" "$?"
    ini linux.keymap "$KEYMAP"
}

343
mk_connection() {
Bernhard Landauer's avatar
Bernhard Landauer committed
344
    if [[ ! $(ping -c 2 google.com) ]]; then
Bernhard Landauer's avatar
Bernhard Landauer committed
345
        DIALOG " $_NoCon " --yesno "\n$_EstCon\n " 0 0 && $NW_CMD && return 0 || clear && exit 0
346 347 348 349 350 351
    fi
}

# Check user is root, and that there is an active internet connection
# Seperated the checks into seperate "if" statements for readability.
check_requirements() {
Bernhard Landauer's avatar
Bernhard Landauer committed
352
    DIALOG " $_ChkTitle " --infobox "\n$_ChkBody\n " 0 0
353 354 355
    sleep 2

    if [[ `whoami` != "root" ]]; then
Bernhard Landauer's avatar
Bernhard Landauer committed
356
        DIALOG " $_Erritle " --infobox "\n$_RtFailBody\n " 0 0
357 358 359 360
        sleep 2
        exit 1
    fi

Bernhard Landauer's avatar
Bernhard Landauer committed
361
    if [[ ! $(ping -c 1 google.com) ]]; then
Bernhard Landauer's avatar
Bernhard Landauer committed
362
        DIALOG " $_ErrTitle " --infobox "\n$_ConFailBody\n " 0 0
363 364 365 366 367 368
        sleep 2
        exit 1
    fi

    # This will only be executed where neither of the above checks are true.
    # The error log is also cleared, just in case something is there from a previous use of the installer.
Bernhard Landauer's avatar
Bernhard Landauer committed
369
    DIALOG " $_ReqMetTitle " --infobox "\n$_ReqMetBody\n\n$_UpdDb\n " 0 0
370 371
    sleep 2
    clear
372
    echo "" > $ERR
373
    pacman -Syy 2>$ERR
Bernhard Landauer's avatar
Bernhard Landauer committed
374
    check_for_error "refresh database" $? SKIP
375 376 377 378
}

# Greet the user when first starting the installer
greeting() {
Bernhard Landauer's avatar
Bernhard Landauer committed
379
    DIALOG " $_WelTitle $VERSION " --msgbox "\n$_WelBody\n " 0 0
380 381
}

382 383
# Originally adapted from AIS. Added option to allow users to edit the mirrorlist.
configure_mirrorlist() {
384 385 386
    HIGHLIGHT_SUB=1
    declare -i loopmenu=1
    while ((loopmenu)); do
Bernhard Landauer's avatar
Bernhard Landauer committed
387
        DIALOG " $_MirrorlistTitle " --default-item ${HIGHLIGHT_SUB} --menu "\n$_MirrorlistBody\n " 0 0 4 \
388
          "1" "$_MirrorPacman" \
389
          "2" "$_MirrorConfig" \
390
          "3" "$_MirrorRankTitle" \
391 392 393
          "4" "$_Back" 2>${ANSWER}

        case $(cat ${ANSWER}) in
394
            "1") nano /etc/pacman.conf
Bernhard Landauer's avatar
Bernhard Landauer committed
395
                DIALOG " $_MirrorPacman " --yesno "\n$_MIrrorPacQ\n " 0 0 && COPY_PACCONF=1 || COPY_PACCONF=0
396
                check_for_error "edit pacman.conf $COPY_PACCONF"
Bernhard Landauer's avatar
Bernhard Landauer committed
397
                DIALOG "" --infobox "\n$_UpdDb\n " 0 0
398
                pacman -Syy
399 400 401 402 403 404 405 406 407 408
                HIGHLIGHT_SUB=2
                ;;
            "2") nano /etc/pacman-mirrors.conf
                check_for_error "edit pacman-mirrors.conf"
                HIGHLIGHT_SUB=3
                ;;
            "3") rank_mirrors
                HIGHLIGHT_SUB=4
                ;;

409
            *) HIGHLIGHT_SUB=1
410 411 412
                loopmeu=0
                return 0
                ;;
413
        esac
414
    done
415 416
}

417
rank_mirrors() {
patrick's avatar
patrick committed
418
    #Choose the branch for mirrorlist
Bernhard Landauer's avatar
Bernhard Landauer committed
419
    DIALOG " $_MirrorBranch " --radiolist "\n$_UseSpaceBar\n " 0 0 3 \
420
      "stable" "-" on \
421
      "testing" "-" off \
422
      "unstable" "-" off 2>${ANSWER}
Bernhard Landauer's avatar
Bernhard Landauer committed
423
    local branch="$(<${ANSWER})"
Bernhard Landauer's avatar
Bernhard Landauer committed
424
    clear
425
    if [[ ! -z ${branch} ]]; then
426
        DIALOG " $_MirrorBranch " --msgbox "\n$_RankMirrors\n " 0 0
Bernhard Landauer's avatar
Bernhard Landauer committed
427
        clear
428
        pacman-mirrors -gib "${branch}"
Bernhard Landauer's avatar
Bernhard Landauer committed
429
        echo ""
430
        ini branch "${branch}"
Bernhard Landauer's avatar
Bernhard Landauer committed
431
    fi
432 433
}

434 435
# Simple code to show devices / partitions.
show_devices() {
436 437
    lsblk -o NAME,MODEL,TYPE,FSTYPE,SIZE,MOUNTPOINT | grep "disk\|part\|lvm\|crypt\|NAME\|MODEL\|TYPE\|FSTYPE\|SIZE\|MOUNTPOINT" > /tmp/.devlist
    DIALOG " $_DevShowOpt " --textbox /tmp/.devlist 0 0
438 439 440 441 442 443 444 445 446 447
}

# Adapted from AIS. An excellent bit of code!
arch_chroot() {
    manjaro-chroot $MOUNTPOINT "${1}"
}

# Ensure that a partition is mounted
check_mount() {
    if [[ $(lsblk -o MOUNTPOINT | grep ${MOUNTPOINT}) == "" ]]; then
Bernhard Landauer's avatar
Bernhard Landauer committed
448
        DIALOG " $_ErrTitle " --msgbox "\n$_ErrNoMount\n " 0 0
Bernhard Landauer's avatar
Bernhard Landauer committed
449
        ANSWER=0
450
        HIGHLIGHT=0
451
        return 1
452 453 454 455 456
    fi
}

# Ensure that Manjaro has been installed
check_base() {
Bernhard Landauer's avatar
Bernhard Landauer committed
457 458
    check_mount
    if [[ $? -eq 0 ]]; then
459
        if [[ ! -e /mnt/.base_installed ]]; then
Bernhard Landauer's avatar
Bernhard Landauer committed
460
            DIALOG " $_ErrTitle " --msgbox "\n$_ErrNoBase\n " 0 0
Bernhard Landauer's avatar
Bernhard Landauer committed
461
            ANSWER=1
462
            HIGHLIGHT=1
463
            HIGHLIGHT_SUB=2
464 465
            return 1
        fi
Bernhard Landauer's avatar
Bernhard Landauer committed
466 467
    else
        return 1
468 469 470
    fi
}

471 472
check_desktop() {
    if [[ -e /mnt/.desktop_installed ]]; then
Bernhard Landauer's avatar
Bernhard Landauer committed
473
        DIALOG " $_InstDETitle " --yesno "\n$_DesktopInstalled\n " 0 0 || return 1
474 475 476
    fi
}

Bernhard Landauer's avatar
Bernhard Landauer committed
477
# install a pkg in the live session if not installed
478
inst_needed() {
Bernhard Landauer's avatar
Bernhard Landauer committed
479
    if [[ ! $(pacman -Q $1) ]]; then
Bernhard Landauer's avatar
Bernhard Landauer committed
480
        DIALOG " $_InstPkg " --infobox "\n$_InstPkg '${1}'\n " 0 0
481
        sleep 2
Bernhard Landauer's avatar
Bernhard Landauer committed
482
        clear
483
        pacman -Sy --noconfirm $1 2>$ERR
patrick's avatar
patrick committed
484 485
        check_for_error "Install needed pkg $1." $?
    fi
486
}
Bernhard Landauer's avatar
Bernhard Landauer committed
487

488 489
# return list of profiles not containing >openrc flag in Packages-Desktop
evaluate_profiles() {
490 491 492 493 494
    echo "" > /tmp/.systemd_only
    for p in $(find $PROFILES/{manjaro,community} -mindepth 1 -maxdepth 1 -type d ! -name 'netinstall' ! -name 'architect'); do
        [[ ! $(grep ">openrc" $p/Packages-Desktop) ]] && echo $p | cut -f7 -d'/' >> /tmp/.systemd_only
    done
    echo $(cat /tmp/.systemd_only)
495 496 497 498
}

# verify if profile is available for openrc
evaluate_openrc() {
499
    if [[ ! $(grep ">openrc" $PROFILES/*/$(cat /tmp/.desktop)/Packages-Desktop) ]]; then
Bernhard Landauer's avatar
Bernhard Landauer committed
500
        DIALOG " $_ErrInit " --menu "\n[Manjaro-$(cat /tmp/.desktop)] $_WarnInit\n " 0 0 2 \
501 502 503 504 505 506 507 508 509 510
          "1" "$_DiffPro" \
          "2" "$_InstSystd" 2>${ANSWER}
        check_for_error "selected systemd-only profile [$(cat /tmp/.desktop)] with openrc base. -> $(cat ${ANSWER})"
        case $(cat ${ANSWER}) in
            "1") install_desktop_menu
            ;;
            "2") install_base
            ;;
        esac
    fi
511 512 513 514 515 516
}

grub_mkconfig() {
    arch_chroot "grub-mkconfig -o /boot/grub/grub.cfg" 2>$ERR
    check_for_error "grub-mkconfig" $?
}
Matti Hyttinen's avatar
Matti Hyttinen committed
517

518
final_check() {
Matti Hyttinen's avatar
Matti Hyttinen committed
519 520 521
    CHECKLIST=/tmp/.final_check
    # Empty the list
    echo "" > ${CHECKLIST}
522

Matti Hyttinen's avatar
Matti Hyttinen committed
523
    # Check if base is installed
524
    if [[ ! -e /mnt/.base_installed ]]; then
525
        echo "- $_BaseCheck" >> ${CHECKLIST}
Matti Hyttinen's avatar
Matti Hyttinen committed
526
    else
527 528
        # Check if bootloader is installed
        if [[ $SYSTEM == "BIOS" ]]; then
529
            arch_chroot "pacman -Qq grub" &> /dev/null || echo "- $_BootlCheck" >> ${CHECKLIST}
530
        else
531
            [[ -e /mnt/boot/efi/EFI/manjaro_grub/grubx64.efi ]] || [[ -e /mnt/boot/EFI/manjaro_grub/grubx64.efi ]] || echo "- $_BootlCheck" >> ${CHECKLIST}
532 533 534
        fi

        # Check if fstab is generated
535
        $(grep -qv '^#' /mnt/etc/fstab 2>/dev/null) || echo "- $_FstabCheck" >> ${CHECKLIST}
536

537
        # Check if video-driver has been installed
538
        [[ ! -e /mnt/.video_installed ]] && echo "- $_GCCheck" >> ${CHECKLIST}
539

540
        # Check if locales have been generated
541
        [[ $(manjaro-chroot /mnt 'locale -a' | wc -l) -ge '3' ]] || echo "- $_LocaleCheck" >> ${CHECKLIST}
542 543

        # Check if root password has been set
544
        manjaro-chroot /mnt 'passwd --status root' | cut -d' ' -f2 | grep -q 'NP' && echo "- $_RootCheck" >> ${CHECKLIST}
545 546

        # check if user account has been generated
547
        [[ $(ls /mnt/home 2>/dev/null) == "" ]] && echo "- $_UserCheck" >> ${CHECKLIST}
Matti Hyttinen's avatar
Matti Hyttinen committed
548
    fi
549
}
Bernhard Landauer's avatar
Bernhard Landauer committed
550 551

exit_done() {
552
    if [[ $(lsblk -o MOUNTPOINT | grep ${MOUNTPOINT} 2>/dev/null) != "" ]]; then
Bernhard Landauer's avatar
Bernhard Landauer committed
553
        final_check
Bernhard Landauer's avatar
Bernhard Landauer committed
554
        dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --yesno "$(printf "\n$_CloseInstBody\n$(cat ${CHECKLIST})\n ")" 0 0
Bernhard Landauer's avatar
Bernhard Landauer committed
555
        if [[ $? -eq 0 ]]; then
Bernhard Landauer's avatar
Bernhard Landauer committed
556
            check_for_error "exit installer."
Bernhard Landauer's avatar
Bernhard Landauer committed
557
            dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --yesno "\n$_LogInfo ${TARGLOG}\n " 0 0
Bernhard Landauer's avatar
Bernhard Landauer committed
558
            if [[ $? -eq 0 ]]; then
Bernhard Landauer's avatar
Bernhard Landauer committed
559
                [[ -e ${TARGLOG} ]] && cat ${LOGFILE} >> ${TARGLOG} || cp ${LOGFILE} ${TARGLOG}
Bernhard Landauer's avatar
Bernhard Landauer committed
560
            fi
Bernhard Landauer's avatar
Bernhard Landauer committed
561
            umount_partitions
Bernhard Landauer's avatar
Bernhard Landauer committed
562
            clear
Bernhard Landauer's avatar
Bernhard Landauer committed
563
            exit 0
Bernhard Landauer's avatar
Bernhard Landauer committed
564 565
        else
            [[ menu_opt == "advanced" ]] && main_menu_full || main_menu
Bernhard Landauer's avatar
Bernhard Landauer committed
566 567
        fi
    else
Bernhard Landauer's avatar
Bernhard Landauer committed
568
        dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --yesno "\n$_CloseInstBody\n " 0 0
Bernhard Landauer's avatar
Bernhard Landauer committed
569
        if [[ $? -eq 0 ]]; then
Bernhard Landauer's avatar
Bernhard Landauer committed
570
            umount_partitions
Bernhard Landauer's avatar
Bernhard Landauer committed
571
            clear
Bernhard Landauer's avatar
Bernhard Landauer committed
572
            exit 0
Bernhard Landauer's avatar
Bernhard Landauer committed
573 574
        else
            [[ menu_opt == "advanced" ]] && main_menu_full || main_menu
Bernhard Landauer's avatar
Bernhard Landauer committed
575 576 577
        fi
    fi
}