manjaro-arm-installer 18.1 KB
Newer Older
Dan Johansen's avatar
Dan Johansen committed
1 2
#! /bin/bash

3
# *****************************
Helmut Stult's avatar
Helmut Stult committed
4
#       Version 1.0.2
5 6
# *****************************

Dan Johansen's avatar
Dan Johansen committed
7
# Set globals
8
TMPDIR=/var/tmp/manjaro-arm-installer
9
ARCH='aarch64'
10
NSPAWN='systemd-nspawn -q --resolv-conf=copy-host --timezone=off -D'
Dan Johansen's avatar
Dan Johansen committed
11

12 13 14 15 16
# clearing variables
DEVICE=""
EDITION=""
USER=""
PASSWORD=""
17 18
CONFIRMPASSWORD=""
CONFIRMROOTPASSWORD=""
19 20
ROOTPASSWORD=""
SDCARD=""
21 22
SDTYP=""
SDDEV=""
23
DEV_NAME=""
24 25
TIMEZONE=""
LOCALE=""
26

27
# check if root
28 29 30 31 32 33
if [ "$EUID" -ne 0 ]; then
    echo "*******************************************************************************************"
    echo "*                                                                                         *"
    echo "*     This script requires root permissions to run. Please run as root or with sudo!      *"
    echo "*                                                                                         *"
    echo "*******************************************************************************************"
34 35 36
  exit
fi

37
# Sanity checks for dependencies
38
if [ ! -f /usr/bin/git ]; then
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
    echo "git command is missing! Please install git!"
    exit 1
    elif [ ! -f /usr/bin/parted ]; then
    echo "parted command is missing! Please install parted!"
    exit 1
    elif [ ! -f /usr/bin/systemd-nspawn ]; then
    echo "systemd-nspawn command is missing! Please install systemd!"
    exit 1
    elif [ ! -f /usr/bin/wget ]; then
    echo "wget command is missing! Please install wget!"
    exit 1
    elif [ ! -f /usr/bin/dialog ]; then
    echo "dialog command is missing! Please install dialog!"
    exit 1
    elif [ ! -f /usr/bin/bsdtar ]; then
    echo "bsdtar command is missing! Please install libarchive!"
    exit 1
56
    elif [ ! -f /usr/bin/mkpasswd ]; then
57
    echo "mkpasswd command is missing! Please install debian-whois-mkpasswd!"
58 59 60 61
    exit 1
    elif [ ! -f /usr/bin/awk ]; then
    echo "awk command is missing! Please install gawk!"
    exit 1
62
fi
63

Dan Johansen's avatar
Dan Johansen committed
64 65

# Functions
66 67 68 69 70 71 72 73
msg() {
    ALL_OFF="\e[1;0m"
    BOLD="\e[1;1m"
    GREEN="${BOLD}\e[1;32m"
      local mesg=$1; shift
      printf "${GREEN}==>${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
 }

74 75 76 77 78 79 80
info() {
    ALL_OFF="\e[1;0m"
    BOLD="\e[1;1m"
    BLUE="${BOLD}\e[1;34m"
      local mesg=$1; shift
      printf "${BLUE}  ->${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
 }
Dan Johansen's avatar
Dan Johansen committed
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102

usage_build_installer() {
    echo "Usage: ${0##*/} [options]"
    echo '    -h                 This help'
    echo ''
    echo ''
    exit $1
}

get_timer(){
    echo $(date +%s)
}

# $1: start timer
elapsed_time(){
    echo $(echo $1 $(get_timer) | awk '{ printf "%0.2f",($2-$1)/60 }')
}

show_elapsed_time(){
    msg "Time %s: %s minutes..." "$1" "$(elapsed_time $2)"
}

103
getarmprofiles () {
104
    info "Getting package lists ready for $DEVICE $EDITION edition..."
105 106 107
    if ls $TMPDIR/arm-profiles/* 1> /dev/null 2>&1; then
        cd $TMPDIR/arm-profiles
        git pull 1> /dev/null 2>&1
108
    else
109 110
        mkdir -p $TMPDIR
        chmod 777 $TMPDIR
111 112
        cd $TMPDIR
        git clone https://gitlab.com/Strit/arm-profiles.git 1> /dev/null 2>&1
113 114 115 116 117 118 119 120 121 122 123 124
    fi

}

create_install() {
 if [[ "$DEVICE" = "oc1" ]] || [[ "$DEVICE" = "rpi2" ]] || [[ "$DEVICE" = "xu4" ]]; then
        ARCH='armv7h'
    else
        ARCH='aarch64'
    fi

    msg "Creating install for $DEVICE..."
125
    msg "Used device is ${SDCARD}${SDDEV}x"
126 127
    
    # fetch and extract rootfs
128
    info "Downloading latest $ARCH rootfs..."
129
    cd $TMPDIR
130
    wget -q --show-progress --progress=bar:force:noscroll https://www.strits.dk/files/Manjaro-ARM-$ARCH-latest.tar.gz
131
    
132
    info "Extracting $ARCH rootfs..."
133
    bsdtar -xpf $TMPDIR/Manjaro-ARM-$ARCH-latest.tar.gz -C $TMPDIR/root
Dan Johansen's avatar
Dan Johansen committed
134
    
135
    info "Setting up keyrings..."
Dan Johansen's avatar
Dan Johansen committed
136 137
    $NSPAWN $TMPDIR/root pacman-key --init 1> /dev/null 2>&1
    $NSPAWN $TMPDIR/root pacman-key --populate archlinuxarm manjaro manjaro-arm 1> /dev/null 2>&1
Dan Johansen's avatar
Dan Johansen committed
138
    
139
    info "Installing packages for $EDITION on $DEVICE..."
Dan Johansen's avatar
Dan Johansen committed
140
    # Install device and editions specific packages
141
    $NSPAWN $TMPDIR/root pacman -Syyu base $PKG_DEVICE $PKG_EDITION --noconfirm
Dan Johansen's avatar
Dan Johansen committed
142
    
143
    info "Enabling services..."
Dan Johansen's avatar
Dan Johansen committed
144
    # Enable services
Dan Johansen's avatar
Dan Johansen committed
145 146
    $NSPAWN $TMPDIR/root systemctl enable systemd-networkd.service getty.target haveged.service dhcpcd.service 1> /dev/null 2>&1
    $NSPAWN $TMPDIR/root systemctl enable $SRV_EDITION 1> /dev/null 2>&1
Dan Johansen's avatar
Dan Johansen committed
147

148
    info "Applying overlay for $EDITION..."
149
    cp -ap $TMPDIR/arm-profiles/overlays/$EDITION/* $TMPDIR/root/
Dan Johansen's avatar
Dan Johansen committed
150
    
151
    info "Setting up users..."
Dan Johansen's avatar
Dan Johansen committed
152
    #setup users
153
    echo "$USER" > $TMPDIR/user
154 155 156 157 158 159 160 161
    echo "$PASSWORD" > $TMPDIR/password
    echo "$ROOTPASSWORD" > $TMPDIR/rootpassword

    info "setting password for root ..."
    $NSPAWN $TMPDIR/root awk -i inplace -F: "BEGIN {OFS=FS;} \$1 == \"root\" {\$2=\"$(mkpasswd --hash=SHA-512 $(cat $TMPDIR/rootpassword))\"} 1" /etc/shadow 1> /dev/null 2>&1

    info "Adding user..."
    $NSPAWN $TMPDIR/root useradd -m -g users -G wheel,storage,network,power -p $(mkpasswd --hash=SHA-512 $(cat $TMPDIR/password)) -s /bin/bash $(cat $TMPDIR/user) 1> /dev/null 2>&1
162

163
    info "Enabling user services..."
Dan Johansen's avatar
Dan Johansen committed
164
    if [[ "$EDITION" = "minimal" ]] || [[ "$EDITION" = "server" ]]; then
165
        msg "No user services for $EDITION edition"
Dan Johansen's avatar
Dan Johansen committed
166
    else
Dan Johansen's avatar
Dan Johansen committed
167
        $NSPAWN $TMPDIR/root --user $(cat $TMPDIR/user) systemctl --user enable pulseaudio.service 1> /dev/null 2>&1
Dan Johansen's avatar
Dan Johansen committed
168 169
    fi

170
    info "Setting up system settings..."
Dan Johansen's avatar
Dan Johansen committed
171
    #system setup
Dan Johansen's avatar
Dan Johansen committed
172
    $NSPAWN $TMPDIR/root chmod u+s /usr/bin/ping 1> /dev/null 2>&1
173 174 175 176
    rm -f $TMPDIR/root/etc/ssl/certs/ca-certificates.crt
    rm -f $TMPDIR/root/etc/ca-certificates/extracted/tls-ca-bundle.pem
    cp -a /etc/ssl/certs/ca-certificates.crt $TMPDIR/root/etc/ssl/certs/
    cp -a /etc/ca-certificates/extracted/tls-ca-bundle.pem $TMPDIR/root/etc/ca-certificates/extracted/
Dan Johansen's avatar
Dan Johansen committed
177 178
    $NSPAWN $TMPDIR/root ln -sf /usr/share/zoneinfo/"$TIMEZONE" /etc/localtime 1> /dev/null 2>&1
    $NSPAWN $TMPDIR/root sed -i s/"#$LOCALE"/"$LOCALE"/g /etc/locale.gen 1> /dev/null 2>&1
179
    echo "LANG=$LOCALE" | tee --append $TMPDIR/root/etc/locale.conf 1> /dev/null 2>&1
Dan Johansen's avatar
Dan Johansen committed
180
    $NSPAWN $TMPDIR/root locale-gen
181
    echo "KEYMAP=$KEYMAP" | tee --append $TMPDIR/root/etc/vconsole.conf 1> /dev/null 2>&1
Dan Johansen's avatar
Dan Johansen committed
182
    $NSPAWN $TMPDIR/root localectl set-x11-keymap $KEYMAP 1> /dev/null 2>&1
183 184 185
    echo "$HOSTNAME" | tee --append $TMPDIR/root/etc/hostname 1> /dev/null 2>&1
    chown -R root:root $TMPDIR/root/etc 1> /dev/null 2>&1
    chown root:polkitd $TMPDIR/root/etc/polkit-1/rules.d 1> /dev/null 2>&1
Dan Johansen's avatar
Dan Johansen committed
186
    
187
    info "Doing device specific setups for $DEVICE..."
Dan Johansen's avatar
Dan Johansen committed
188
    if [[ "$DEVICE" = "rpi2" ]] || [[ "$DEVICE" = "rpi3" ]]; then
189 190 191 192
        echo "dtparam=audio=on" | tee --append $TMPDIR/root/boot/config.txt
        echo "hdmi_drive=2" | tee --append $TMPDIR/root/boot/config.txt
        echo "audio_pwm_mode=2" | tee --append $TMPDIR/root/boot/config.txt
        echo "/dev/mmcblk0p1  /boot   vfat    defaults        0       0" | tee --append $TMPDIR/root/etc/fstab
Dan Johansen's avatar
Dan Johansen committed
193
    elif [[ "$DEVICE" = "oc1" ]] || [[ "$DEVICE" = "oc2" ]]; then
194
        $NSPAWN $TMPDIR/root systemctl enable amlogic.service 1> /dev/null 2>&1
Dan Johansen's avatar
Dan Johansen committed
195
    elif [[ "$DEVICE" = "pinebook" ]]; then
Dan Johansen's avatar
Dan Johansen committed
196
        $NSPAWN $TMPDIR/root systemctl enable pinebook-post-install.service 1> /dev/null 2>&1
Dan Johansen's avatar
Dan Johansen committed
197
    else
Dan Johansen's avatar
Dan Johansen committed
198
        echo "No device specific setting needed for $DEVICE"
Dan Johansen's avatar
Dan Johansen committed
199 200
    fi
    
201
    info "Cleaning install for unwanted files..."
Dan Johansen's avatar
Dan Johansen committed
202
       if [[ "$DEVICE" = "oc1" ]] || [[ "$DEVICE" = "rpi2" ]] || [[ "$DEVICE" = "xu4" ]]; then
203
        rm $TMPDIR/root/usr/bin/qemu-arm-static
Dan Johansen's avatar
Dan Johansen committed
204
    else
205
        rm $TMPDIR/root/usr/bin/qemu-aarch64-static
Dan Johansen's avatar
Dan Johansen committed
206
    fi
207 208 209 210
    rm -rf $TMPDIR/root/var/cache/pacman/pkg/*
    rm -rf $TMPDIR/root/var/log/*
    rm -rf $TMPDIR/root/usr/lib/systemd/system/systemd-firstboot.service
    rm -rf $TMPDIR/root/etc/machine-id
211 212
    
    # Remove temp files on host
213 214
    rm -rf $TMPDIR/user $TMPDIR/password $TMPDIR/rootpassword
    rm -rf $TMPDIR/Manjaro-ARM-$ARCH-latest.tar.gz*
Dan Johansen's avatar
Dan Johansen committed
215

216
    msg "$DEVICE $EDITION install complete"
Dan Johansen's avatar
Dan Johansen committed
217 218 219
}

prepare_card () {
220
    msg "Getting $SDCARD ready for $DEVICE..."
Dan Johansen's avatar
Dan Johansen committed
221 222
    # For Raspberry Pi devices
    if [[ "$DEVICE" = "rpi2" ]] || [[ "$DEVICE" = "rpi3" ]]; then
223 224 225 226
        # umount SD card
        umount ${SDCARD}${SDDEV}1 1> /dev/null 2>&1
        umount ${SDCARD}${SDDEV}2 1> /dev/null 2>&1

Dan Johansen's avatar
Dan Johansen committed
227
        #partition with boot and root
228 229
        parted -s $SDCARD mklabel msdos 1> /dev/null 2>&1
        parted -s $SDCARD mkpart primary fat32 0% 100M 1> /dev/null 2>&1
230
        START=`cat /sys/block/$DEV_NAME/${DEV_NAME}1/start` 
Dan Johansen's avatar
Dan Johansen committed
231
        SIZE=`cat /sys/block/$DEV_NAME/${DEV_NAME}1/size`
232
        END_SECTOR=$(expr $START + $SIZE)
233 234
        parted -s $SDCARD mkpart primary ext4 "${END_SECTOR}s" 100% 1> /dev/null 2>&1
        partprobe $SDCARD 1> /dev/null 2>&1
235 236
        mkfs.vfat "${SDCARD}${SDDEV}1" 1> /dev/null 2>&1
        mkfs.ext4 "${SDCARD}${SDDEV}2" 1> /dev/null 2>&1
237 238
        
        #Mount SD card
Dan Johansen's avatar
Dan Johansen committed
239 240
        mkdir -p $TMPDIR/root
        mkdir -p $TMPDIR/boot
241 242
        mount ${SDCARD}${SDDEV}1 $TMPDIR/boot
        mount ${SDCARD}${SDDEV}2 $TMPDIR/root
Dan Johansen's avatar
Dan Johansen committed
243 244 245

    # For Odroid devices
    elif [[ "$DEVICE" = "oc1" ]] || [[ "$DEVICE" = "oc2" ]] || [[ "$DEVICE" = "xu4" ]]; then
246 247
        # umount SD card
        umount ${SDCARD}${SDDEV}1 1> /dev/null 2>&1
248
        umount ${SDCARD}${SDDEV}2 1> /dev/null 2>&1
249

Dan Johansen's avatar
Dan Johansen committed
250
        #Clear first 8mb
251
        dd if=/dev/zero of=${SDCARD} bs=1M count=8 1> /dev/null 2>&1
252

Dan Johansen's avatar
Dan Johansen committed
253
    #partition with a single root partition
254 255 256
        parted -s $SDCARD mklabel msdos 1> /dev/null 2>&1
        parted -s $SDCARD mkpart primary ext4 0% 100% 1> /dev/null 2>&1
        partprobe $SDCARD 1> /dev/null 2>&1
257
        mkfs.ext4 -O ^metadata_csum,^64bit ${SDCARD}${SDDEV}1 1> /dev/null 2>&1
258 259
        
        #Mount SD card
Dan Johansen's avatar
Dan Johansen committed
260
        mkdir -p $TMPDIR/root
261
        chmod 777 -R $TMPDIR/root
262
        mount ${SDCARD}${SDDEV}1 $TMPDIR/root
Dan Johansen's avatar
Dan Johansen committed
263

264
    # For pine devices
265 266 267
    elif [[ "$DEVICE" = "pinebook" ]] || [[ "$DEVICE" = "sopine" ]]; then
        # umount SD card
        umount ${SDCARD}${SDDEV}1 1> /dev/null 2>&1
268
        umount ${SDCARD}${SDDEV}2 1> /dev/null 2>&1
Dan Johansen's avatar
Dan Johansen committed
269 270

    #Clear first 8mb
271
        dd if=/dev/zero of=${SDCARD} bs=1M count=8 1> /dev/null 2>&1
272

Dan Johansen's avatar
Dan Johansen committed
273
    #partition with a single root partition
274 275 276
        parted -s $SDCARD mklabel msdos 1> /dev/null 2>&1
        parted -s $SDCARD mkpart primary ext4 0% 100% 1> /dev/null 2>&1
        partprobe $SDCARD 1> /dev/null 2>&1
277
        mkfs.ext4 -O ^metadata_csum,^64bit ${SDCARD}${SDDEV}1 1> /dev/null 2>&1
278 279
        
        # Mount SD card
Dan Johansen's avatar
Dan Johansen committed
280
        mkdir -p $TMPDIR/root
281
        chmod 777 -R $TMPDIR/root
282
        mount ${SDCARD}${SDDEV}1 $TMPDIR/root
283

Dan Johansen's avatar
Dan Johansen committed
284
    # For rockpro64 device
285
    elif [[ "$DEVICE" = "rock64" ]] || [[ "$DEVICE" = "rockpro64" ]]; then
286 287
        # umount SD card
        umount ${SDCARD}${SDDEV}1 1> /dev/null 2>&1
288
        umount ${SDCARD}${SDDEV}2 1> /dev/null 2>&1
Dan Johansen's avatar
Dan Johansen committed
289 290

    #Clear first 8mb
291
        dd if=/dev/zero of=${SDCARD} bs=1M count=32 1> /dev/null 2>&1
292

Dan Johansen's avatar
Dan Johansen committed
293
    #partition with a single root partition
294 295 296
        parted -s $SDCARD mklabel msdos 1> /dev/null 2>&1
        parted -s $SDCARD mkpart primary ext4 32M 100% 1> /dev/null 2>&1
        partprobe $SDCARD 1> /dev/null 2>&1
297
        mkfs.ext4 -O ^metadata_csum,^64bit ${SDCARD}${SDDEV}1 1> /dev/null 2>&1
298 299
        
        # Mount SD card
Dan Johansen's avatar
Dan Johansen committed
300
        mkdir -p $TMPDIR/root
301
        chmod 777 -R $TMPDIR/root
302
        mount ${SDCARD}${SDDEV}1 $TMPDIR/root
303 304 305 306 307 308 309 310
    fi
}

cleanup () {
    msg "Writing bootloader and cleaning up after install..."
   # For Raspberry Pi devices
    if [[ "$DEVICE" = "rpi2" ]] || [[ "$DEVICE" = "rpi3" ]]; then
       #copy rootfs contents over to the FS
311
        mv $TMPDIR/root/boot/* $TMPDIR/boot
312 313
        
        #clean up
314 315 316 317
        umount $TMPDIR/root
        umount $TMPDIR/boot
        rm -r $TMPDIR/root $TMPDIR/boot
        partprobe $SDCARD 1> /dev/null 2>&1
318 319 320 321 322
        
# For Odroid devices
    elif [[ "$DEVICE" = "oc1" ]] || [[ "$DEVICE" = "oc2" ]] || [[ "$DEVICE" = "xu4" ]]; then
    #flash bootloader
        cd $TMPDIR/root/boot/
323
        ./sd_fusing.sh $SDCARD 1> /dev/null 2>&1
324 325 326
        cd ~

    #clean up
327 328 329
        umount $TMPDIR/root
        rm -r $TMPDIR/root
        partprobe $SDCARD 1> /dev/null 2>&1
330 331
        
    # For pinebook device
332
    elif [[ "$DEVICE" = "pinebook" ]] || [[ "$DEVICE" = "sopine" ]]; then
333
    #flash bootloader
334
        dd if=$TMPDIR/root/boot/u-boot-sunxi-with-spl-$DEVICE.bin of=${SDCARD} bs=8k seek=1 1> /dev/null 2>&1
335 336
        
    #clean up
337 338 339
        umount $TMPDIR/root
        rm -r $TMPDIR/root
        partprobe $SDCARD 1> /dev/null 2>&1
Dan Johansen's avatar
Dan Johansen committed
340
        
341 342
        
    # For rockpro64 device
343
    elif [[ "$DEVICE" = "rock64" ]] || [[ "$DEVICE" = "rockpro64" ]]; then
Dan Johansen's avatar
Dan Johansen committed
344
    #flash bootloader
345 346 347
        dd if=$TMPDIR/root/boot/idbloader.img of=${SDCARD} seek=64 conv=notrunc 1> /dev/null 2>&1
        dd if=$TMPDIR/root/boot/uboot.img of=${SDCARD} seek=16384 conv=notrunc 1> /dev/null 2>&1
        dd if=$TMPDIR/root/boot/trust.img of=${SDCARD} seek=24576 conv=notrunc 1> /dev/null 2>&1
Dan Johansen's avatar
Dan Johansen committed
348 349
        
    #clean up
350 351 352
        umount $TMPDIR/root
        rm -r $TMPDIR/root
        partprobe $SDCARD 1> /dev/null 2>&1
353 354
        
fi
Dan Johansen's avatar
Dan Johansen committed
355 356
}

357 358

# Using Dialog to ask for user input for variables
359
DEVICE=$(dialog --clear --title "Manjaro ARM Installer" \
Helmut Stult's avatar
Helmut Stult committed
360
        --menu "Choose a device:" 20 75 10 \
361 362 363 364 365 366 367 368 369 370
		"pinebook"  "Pinebook" \
		"rock64"    "ROCK64" \
		"rockpro64" "ROCKPro64" \
		"sopine"    "SOPINE / PINE A64-LTS" \
		"oc2"       "Odroid C2" \
		"rpi3"      "Raspberry Pi 3" \
		"oc1"       "Odroid C1/C1+    (unmaintained)" \
		"xu4"       "Odroid XU4       (unmaintained)" \
		"rpi2"      "Raspberry Pi 2   (unmaintained)" \
		3>&1 1>&2 2>&3 3>&-)
371 372 373 374 375


#The if statement makes sure that the user has put in something in the previous prompt. If not (left blank or pressed cancel) the script will end
if [ ! -z "$DEVICE" ]
then
376
EDITION=$(dialog --clear --title "Manjaro ARM Installer" \
Helmut Stult's avatar
Helmut Stult committed
377
	--menu "Choose an edition:" 20 75 10 \
Helmut Stult's avatar
Helmut Stult committed
378 379 380 381 382 383
	"minimal"   "Minimal Edition            (only CLI)" \
	"kde"       "Full KDE/Plasma Desktop    (full featured)" \
	"lxqt"      "Full LXQT Desktop and apps (lightweight)" \
	"i3"        "Mininal i3 WM with apps    (very light)" \
	"cubocore"  "QT based Desktop           (lightweight)" \
	"mate"      "Full MATE desktop and apps (lightweight, unmaintained)" \
384
	3>&1 1>&2 2>&3 3>&-) 
385 386 387 388 389 390 391 392 393

else 
	clear
	exit 1
fi


if [ ! -z "$EDITION" ]
then
394
USER=$(dialog --clear --title "Manjaro ARM Installer" \
395 396 397 398 399 400 401 402 403 404 405 406
	--inputbox "Enter username:" 8 50 \
        3>&1 1>&2 2>&3 3>&-)
else 
	clear
	exit 1
fi




if [ ! -z "$USER" ]
then
407
PASSWORD=$(dialog --clear --title "Manjaro ARM Installer" \
408
	--insecure --passwordbox "Enter Password for $USER:" 8 50 \
409 410 411 412 413 414 415
        3>&1 1>&2 2>&3 3>&- \
	)
else 
	clear
	exit 1
fi

416 417 418 419 420 421 422 423 424 425
if [ ! -z "$PASSWORD" ]
then
CONFIRMPASSWORD=$(dialog --clear --title "Manjaro ARM Installer" \
	--insecure --passwordbox "Confirm Password for $USER:" 8 50 \
        3>&1 1>&2 2>&3 3>&- \
	)
else 
	clear
	exit 1
fi
426

427 428 429 430 431
if [[ "$PASSWORD" != "$CONFIRMPASSWORD" ]]; then
    clear
    msg "User passwords do not match! Please restart the installer and try again."
    exit 1
fi
432

433
if [ ! -z "$CONFIRMPASSWORD" ]
434
then
435
ROOTPASSWORD=$(dialog --clear --title "Manjaro ARM Installer" \
436
	--insecure --passwordbox "Enter Root Password:" 8 50 \
437 438 439 440 441 442 443
        3>&1 1>&2 2>&3 3>&- \
	)
else 
	clear
	exit 1
fi

444 445 446 447 448 449 450 451 452 453
if [ ! -z "$ROOTPASSWORD" ]
then
CONFIRMROOTPASSWORD=$(dialog --clear --title "Manjaro ARM Installer" \
	--insecure --passwordbox "Confirm Root Password:" 8 50 \
        3>&1 1>&2 2>&3 3>&- \
	)
else 
	clear
	exit 1
fi
454

455 456 457 458 459
if [[ "$ROOTPASSWORD" != "$CONFIRMROOTPASSWORD" ]]; then
    clear
    msg "Root passwords do not match! Please restart the installer and try again."
    exit 1
fi
460

461
if [ ! -z "$CONFIRMROOTPASSWORD" ]
462 463 464 465 466 467 468 469
then

# simple command to put the results of lsblk (just the names of the devices) into an array and make that array populate the options	
let i=0
W=()
while read -r line; do
    let i=$i+1
    W+=($line "")
470
done < <( lsblk -dn -o NAME )
471
SDCARD=$(dialog --title "Manjaro ARM Installer" \
472
	--menu "Choose your SDCard - Be sure the correct drive is selected!" 20 50 10 \
473 474 475
       	"${W[@]}" 3>&2 2>&1 1>&3)

# add /dev/ to the selected option above
476
DEV_NAME=$SDCARD
477
SDCARD=/dev/$SDCARD
478
SDTYP=${SDCARD:5:2}
479 480 481
else 
	clear
	exit 1
482 483 484 485 486 487 488 489
	fi

if [[ "$SDTYP" = "sd" ]]
then
    SDDEV=""
elif [[ "$SDTYP" = "mm" ]]
then
    SDDEV="p"
490 491 492
fi


493 494 495 496 497 498 499 500 501
if [ ! -z "$SDCARD" ]
then
let i=0
W=()
while read -r line; do
    let i=$i+1
    W+=($line "")
done < <( timedatectl list-timezones )
TIMEZONE=$(dialog --clear --title "Manjaro ARM Installer" \
Dan Johansen's avatar
Dan Johansen committed
502
    --menu "Choose your timezone!" 20 50 15 \
503 504 505 506 507 508
        "${W[@]}" 3>&1 1>&2 2>&3 3>&- \
	)
else 
	clear
	exit 1
fi
509 510


511 512 513 514 515 516 517 518 519
if [ ! -z "$TIMEZONE" ]
then
let i=0
W=()
while read -r line; do
    let i=$i+1
    W+=($line "")
done < <( cat /etc/locale.gen | grep "UTF-8" | tail -n +2 | awk '{print $1}' | sed -e 's/^#*//' )
LOCALE=$(dialog --clear --title "Manjaro ARM Installer" \
Dan Johansen's avatar
Dan Johansen committed
520
	--menu "Choose your locale!" 20 50 15 \
521 522 523 524 525 526 527 528 529
        "${W[@]}" 3>&1 1>&2 2>&3 3>&- \
	)
else 
	clear
	exit 1
fi

if [ ! -z "$LOCALE" ]
then
530 531 532 533 534 535 536
let i=0
W=()
while read -r line; do
    let i=$i+1
    W+=($line "")
done < <( localectl list-keymaps )
KEYMAP=$(dialog --clear --title "Manjaro ARM Installer" \
Dan Johansen's avatar
Dan Johansen committed
537
	--menu "Choose your keyboard layout:" 20 50 15 \
538 539 540 541 542 543 544 545 546 547 548
        "${W[@]}" 3>&1 1>&2 2>&3 3>&- \
	)
else 
	clear
	exit 1
fi

if [ ! -z "$KEYMAP" ]
then
HOSTNAME=$(dialog --clear --title "Manjaro ARM Installer" \
	--inputbox "Enter desired hostname for this system:" 8 50 \
549
	3>&1 1>&2 2>&3 3>&- \
550 551 552 553 554 555 556 557
	)
else 
	clear
	exit 1
fi

if [ ! -z "$HOSTNAME" ]
then
558 559 560 561 562
dialog --clear --title "Manjaro ARM Installer" \
    --yesno "Is the below information correct:
    Username = $USER
    Password for $USER = $PASSWORD
    Password for root = $ROOTPASSWORD
563
    SD Card = $SDCARD
564
    Timezone = $TIMEZONE
565 566
    Locale = $LOCALE
    Keyboard layout = $KEYMAP
Helmut Stult's avatar
Helmut Stult committed
567
    Hostname = $HOSTNAME" 20 70 \
568 569 570 571 572 573 574 575 576 577 578 579 580
    3>&1 1>&2 2>&3 3>&-
else
    clear
    exit 1
fi

response=$?
case $response in
   0) clear; msg "Proceeding....";;
   1) clear; msg "Installation aborted...."; exit 1;;
   255) clear; msg "Installation aborted..."; exit 1;;
esac

581

Dan Johansen's avatar
Dan Johansen committed
582 583 584 585 586 587
if [[ "$DEVICE" = "oc1" ]] || [[ "$DEVICE" = "rpi2" ]] || [[ "$DEVICE" = "xu4" ]]; then
    ARCH='armv7h'
else
    ARCH='aarch64'
fi

588 589
# get the profiles
getarmprofiles
Dan Johansen's avatar
Dan Johansen committed
590 591

#Package lists
592 593 594
PKG_DEVICE=$(grep "^[^#;]" $TMPDIR/arm-profiles/devices/$DEVICE | awk '{print $1}')
PKG_EDITION=$(grep "^[^#;]" $TMPDIR/arm-profiles/editions/$EDITION | awk '{print $1}')
SRV_EDITION=$(grep "^[^#;]" $TMPDIR/arm-profiles/services/$EDITION | awk '{print $1}')
Dan Johansen's avatar
Dan Johansen committed
595

596

Dan Johansen's avatar
Dan Johansen committed
597
# Commands
598
timer_start=$(get_timer)
Dan Johansen's avatar
Dan Johansen committed
599 600

prepare_card
601 602 603 604
create_install
cleanup
show_elapsed_time "${FUNCNAME}" "${timer_start}"
sync