manjaro-arm-installer 20.3 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.1.1
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
142 143 144 145 146 147 148 149 150
        if [[ "$DEVICE" = "on2" ]]; then
    if [[ "$EDITION" = "kde" ]] || [[ "$EDITION" = "cubocore" ]]; then
    $NSPAWN $TMPDIR/root pacman -R sddm sddm-kcm --noconfirm
    $NSPAWN $TMPDIR/root pacman -S sddm-n2 sddm-kcm --noconfirm
    elif [[ "$EDITION" = "lxqt" ]]; then
    $NSPAWN $TMPDIR/root pacman -R sddm sddm-qt-manjaro-theme --noconfirm
    $NSPAWN $TMPDIR/root pacman -S sddm-n2 sddm-qt-manjaro-theme --noconfirm
    fi
    fi
Dan Johansen's avatar
Dan Johansen committed
151
    
152
    info "Enabling services..."
Dan Johansen's avatar
Dan Johansen committed
153
    # Enable services
154
    $NSPAWN $TMPDIR/root systemctl enable getty.target haveged.service 1> /dev/null 2>&1
Dan Johansen's avatar
Dan Johansen committed
155
    $NSPAWN $TMPDIR/root systemctl enable $SRV_EDITION 1> /dev/null 2>&1
Dan Johansen's avatar
Dan Johansen committed
156

157
    info "Applying overlay for $EDITION..."
158
    cp -ap $TMPDIR/arm-profiles/overlays/$EDITION/* $TMPDIR/root/
Dan Johansen's avatar
Dan Johansen committed
159
    
160
    info "Setting up users..."
Dan Johansen's avatar
Dan Johansen committed
161
    #setup users
162
    echo "$USER" > $TMPDIR/user
163 164 165 166 167 168 169 170
    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
171

172
    info "Enabling user services..."
Dan Johansen's avatar
Dan Johansen committed
173
    if [[ "$EDITION" = "minimal" ]] || [[ "$EDITION" = "server" ]]; then
174
        msg "No user services for $EDITION edition"
Dan Johansen's avatar
Dan Johansen committed
175
    else
Dan Johansen's avatar
Dan Johansen committed
176
        $NSPAWN $TMPDIR/root --user $(cat $TMPDIR/user) systemctl --user enable pulseaudio.service 1> /dev/null 2>&1
Dan Johansen's avatar
Dan Johansen committed
177 178
    fi

179
    info "Setting up system settings..."
Dan Johansen's avatar
Dan Johansen committed
180
    #system setup
Dan Johansen's avatar
Dan Johansen committed
181
    $NSPAWN $TMPDIR/root chmod u+s /usr/bin/ping 1> /dev/null 2>&1
182 183 184 185
    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
186 187
    $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
188
    echo "LANG=$LOCALE" | tee --append $TMPDIR/root/etc/locale.conf 1> /dev/null 2>&1
Dan Johansen's avatar
Dan Johansen committed
189
    $NSPAWN $TMPDIR/root locale-gen
190
    echo "KEYMAP=$KEYMAP" | tee --append $TMPDIR/root/etc/vconsole.conf 1> /dev/null 2>&1
Dan Johansen's avatar
Dan Johansen committed
191
    $NSPAWN $TMPDIR/root localectl set-x11-keymap $KEYMAP 1> /dev/null 2>&1
192 193 194
    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
195
    
196
    info "Doing device specific setups for $DEVICE..."
Dan Johansen's avatar
Dan Johansen committed
197
    if [[ "$DEVICE" = "rpi2" ]] || [[ "$DEVICE" = "rpi3" ]]; then
Dan Johansen's avatar
Dan Johansen committed
198 199 200
        echo "dtparam=audio=on" | tee --append $TMPDIR/root/boot/config.txt 1> /dev/null 2>&1
        echo "blacklist vchiq" | tee --append $TMPDIR/root/etc/modprobe.d/blacklist-vchiq.conf 1> /dev/null 2>&1
        echo "blacklist snd_bcm2835" | tee --append $TMPDIR/root/etc/modprobe.d/blacklist-vchiq.conf 1> /dev/null 2>&1
201
        echo "LABEL=BOOT  /boot   vfat    defaults        0       0" | tee --append $TMPDIR/root/etc/fstab 1> /dev/null 2>&1
Dan Johansen's avatar
Dan Johansen committed
202
    elif [[ "$DEVICE" = "oc1" ]] || [[ "$DEVICE" = "oc2" ]]; then
203
        $NSPAWN $TMPDIR/root systemctl enable amlogic.service 1> /dev/null 2>&1
204 205
    elif [[ "$DEVICE" = "on2" ]]; then
        $NSPAWN $TMPDIR/root systemctl disable dhcpcd.service 1> /dev/null 2>&1
206
        echo "LABEL=BOOT  /boot   vfat    defaults        0       0" | tee --append $TMPDIR/root/etc/fstab 1> /dev/null 2>&1
Dan Johansen's avatar
Dan Johansen committed
207
    elif [[ "$DEVICE" = "pinebook" ]]; then
Dan Johansen's avatar
Dan Johansen committed
208
        $NSPAWN $TMPDIR/root systemctl enable pinebook-post-install.service 1> /dev/null 2>&1
Dan Johansen's avatar
Dan Johansen committed
209
    else
Dan Johansen's avatar
Dan Johansen committed
210
        echo "No device specific setting needed for $DEVICE"
Dan Johansen's avatar
Dan Johansen committed
211 212
    fi
    
213
    info "Cleaning install for unwanted files..."
Dan Johansen's avatar
Dan Johansen committed
214
       if [[ "$DEVICE" = "oc1" ]] || [[ "$DEVICE" = "rpi2" ]] || [[ "$DEVICE" = "xu4" ]]; then
215
        rm $TMPDIR/root/usr/bin/qemu-arm-static
Dan Johansen's avatar
Dan Johansen committed
216
    else
217
        rm $TMPDIR/root/usr/bin/qemu-aarch64-static
Dan Johansen's avatar
Dan Johansen committed
218
    fi
219 220 221 222
    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
223 224
    
    # Remove temp files on host
225 226
    rm -rf $TMPDIR/user $TMPDIR/password $TMPDIR/rootpassword
    rm -rf $TMPDIR/Manjaro-ARM-$ARCH-latest.tar.gz*
Dan Johansen's avatar
Dan Johansen committed
227

228
    msg "$DEVICE $EDITION install complete"
Dan Johansen's avatar
Dan Johansen committed
229 230 231
}

prepare_card () {
232
    msg "Getting $SDCARD ready for $DEVICE..."
Dan Johansen's avatar
Dan Johansen committed
233 234
    # For Raspberry Pi devices
    if [[ "$DEVICE" = "rpi2" ]] || [[ "$DEVICE" = "rpi3" ]]; then
235 236 237 238
        # 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
239
        #partition with boot and root
240 241
        parted -s $SDCARD mklabel msdos 1> /dev/null 2>&1
        parted -s $SDCARD mkpart primary fat32 0% 100M 1> /dev/null 2>&1
242
        START=`cat /sys/block/$DEV_NAME/${DEV_NAME}1/start` 
Dan Johansen's avatar
Dan Johansen committed
243
        SIZE=`cat /sys/block/$DEV_NAME/${DEV_NAME}1/size`
244
        END_SECTOR=$(expr $START + $SIZE)
245 246
        parted -s $SDCARD mkpart primary ext4 "${END_SECTOR}s" 100% 1> /dev/null 2>&1
        partprobe $SDCARD 1> /dev/null 2>&1
247 248
        mkfs.vfat "${SDCARD}${SDDEV}1" -n BOOT 1> /dev/null 2>&1
        mkfs.ext4 "${SDCARD}${SDDEV}2" -L ROOT 1> /dev/null 2>&1
249 250
        
        #Mount SD card
Dan Johansen's avatar
Dan Johansen committed
251 252
        mkdir -p $TMPDIR/root
        mkdir -p $TMPDIR/boot
253 254
        mount ${SDCARD}${SDDEV}1 $TMPDIR/boot
        mount ${SDCARD}${SDDEV}2 $TMPDIR/root
Dan Johansen's avatar
Dan Johansen committed
255 256 257

    # For Odroid devices
    elif [[ "$DEVICE" = "oc1" ]] || [[ "$DEVICE" = "oc2" ]] || [[ "$DEVICE" = "xu4" ]]; then
258 259
        # umount SD card
        umount ${SDCARD}${SDDEV}1 1> /dev/null 2>&1
260
        umount ${SDCARD}${SDDEV}2 1> /dev/null 2>&1
261

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

Dan Johansen's avatar
Dan Johansen committed
265
    #partition with a single root partition
266 267 268
        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
269
        mkfs.ext4 -O ^metadata_csum,^64bit ${SDCARD}${SDDEV}1 -L ROOT 1> /dev/null 2>&1
270 271
        
        #Mount SD card
Dan Johansen's avatar
Dan Johansen committed
272
        mkdir -p $TMPDIR/root
273
        chmod 777 -R $TMPDIR/root
274
        mount ${SDCARD}${SDDEV}1 $TMPDIR/root
275 276
        
   elif [[ "$DEVICE" = "on2" ]]; then
Helmut Stult's avatar
Helmut Stult committed
277 278 279 280
        # umount SD card
        umount ${SDCARD}${SDDEV}1 1> /dev/null 2>&1
        umount ${SDCARD}${SDDEV}2 1> /dev/null 2>&1

281 282 283 284 285 286 287 288 289 290 291
        #Clear first 8 mb
        dd if=/dev/zero of=${LDEV} bs=1M count=8 1> /dev/null 2>&1
        
    #partition with 2 partitions
        parted -s $LDEV mklabel msdos 1> /dev/null 2>&1
        parted -s $LDEV mkpart primary fat32 0% 256M 1> /dev/null 2>&1
        START=`cat /sys/block/$DEV/${DEV}p1/start`
        SIZE=`cat /sys/block/$DEV/${DEV}p1/size`
        END_SECTOR=$(expr $START + $SIZE)
        parted -s $LDEV mkpart primary ext4 "${END_SECTOR}s" 100% 1> /dev/null 2>&1
        partprobe $LDEV 1> /dev/null 2>&1
292 293
        mkfs.vfat "${LDEV}p1" -n BOOT 1> /dev/null 2>&1
        mkfs.ext4 "${LDEV}p2" -L ROOT 1> /dev/null 2>&1
294 295 296 297 298 299
        
    #copy rootfs contents over to the FS
        mkdir -p $TMPDIR/root
        mkdir -p $TMPDIR/boot
        mount ${LDEV}p1 $TMPDIR/boot
        mount ${LDEV}p2 $TMPDIR/root
Dan Johansen's avatar
Dan Johansen committed
300

301
    # For pine devices
302 303 304
    elif [[ "$DEVICE" = "pinebook" ]] || [[ "$DEVICE" = "sopine" ]]; then
        # umount SD card
        umount ${SDCARD}${SDDEV}1 1> /dev/null 2>&1
305
        umount ${SDCARD}${SDDEV}2 1> /dev/null 2>&1
Dan Johansen's avatar
Dan Johansen committed
306 307

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

Dan Johansen's avatar
Dan Johansen committed
310
    #partition with a single root partition
311 312 313
        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
314
        mkfs.ext4 -O ^metadata_csum,^64bit ${SDCARD}${SDDEV}1 -L ROOT 1> /dev/null 2>&1
315 316
        
        # Mount SD card
Dan Johansen's avatar
Dan Johansen committed
317
        mkdir -p $TMPDIR/root
318
        chmod 777 -R $TMPDIR/root
319
        mount ${SDCARD}${SDDEV}1 $TMPDIR/root
320

Dan Johansen's avatar
Dan Johansen committed
321
    # For rockpro64 device
322
    elif [[ "$DEVICE" = "rock64" ]] || [[ "$DEVICE" = "rockpro64" ]]; then
323 324
        # umount SD card
        umount ${SDCARD}${SDDEV}1 1> /dev/null 2>&1
325
        umount ${SDCARD}${SDDEV}2 1> /dev/null 2>&1
Dan Johansen's avatar
Dan Johansen committed
326 327

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

Dan Johansen's avatar
Dan Johansen committed
330
    #partition with a single root partition
331 332 333
        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
334
        mkfs.ext4 -O ^metadata_csum,^64bit ${SDCARD}${SDDEV}1 -L ROOT 1> /dev/null 2>&1
335 336
        
        # Mount SD card
Dan Johansen's avatar
Dan Johansen committed
337
        mkdir -p $TMPDIR/root
338
        chmod 777 -R $TMPDIR/root
339
        mount ${SDCARD}${SDDEV}1 $TMPDIR/root
340 341 342 343 344 345 346
    fi
}

cleanup () {
    msg "Writing bootloader and cleaning up after install..."
   # For Raspberry Pi devices
    if [[ "$DEVICE" = "rpi2" ]] || [[ "$DEVICE" = "rpi3" ]]; then
347
       #move boot files
348
        mv $TMPDIR/root/boot/* $TMPDIR/boot
349 350
        
        #clean up
351 352 353 354
        umount $TMPDIR/root
        umount $TMPDIR/boot
        rm -r $TMPDIR/root $TMPDIR/boot
        partprobe $SDCARD 1> /dev/null 2>&1
355
        
356
    # For Odroid devices
357 358 359
    elif [[ "$DEVICE" = "oc1" ]] || [[ "$DEVICE" = "oc2" ]] || [[ "$DEVICE" = "xu4" ]]; then
    #flash bootloader
        cd $TMPDIR/root/boot/
360
        ./sd_fusing.sh $SDCARD 1> /dev/null 2>&1
361 362 363
        cd ~

    #clean up
364 365 366
        umount $TMPDIR/root
        rm -r $TMPDIR/root
        partprobe $SDCARD 1> /dev/null 2>&1
367
        
368 369 370 371 372 373 374 375 376 377 378 379 380 381
    elif [[ "$DEVICE" = "on2" ]]; then
    
    # move boot files
        mv $TMPDIR/root/boot/* $TMPDIR/boot
    #flash bootloader
        dd if=$TMPDIR/boot/u-boot.bin of=${SDCARD} conv=fsync,notrunc bs=512 seek=1 1> /dev/null 2>&1
        
    #clean up
        umount $TMPDIR/root
        umount $TMPDIR/boot
        losetup -d $LDEV 1> /dev/null 2>&1
        rm -r $TMPDIR/root $TMPDIR/boot
        partprobe $LDEV 1> /dev/null 2>&1
        
382
    # For pinebook device
383
    elif [[ "$DEVICE" = "pinebook" ]] || [[ "$DEVICE" = "sopine" ]]; then
384
    #flash bootloader
385
        dd if=$TMPDIR/root/boot/u-boot-sunxi-with-spl-$DEVICE.bin of=${SDCARD} bs=8k seek=1 1> /dev/null 2>&1
386 387
        
    #clean up
388 389 390
        umount $TMPDIR/root
        rm -r $TMPDIR/root
        partprobe $SDCARD 1> /dev/null 2>&1
Dan Johansen's avatar
Dan Johansen committed
391
        
392 393
        
    # For rockpro64 device
394
    elif [[ "$DEVICE" = "rock64" ]] || [[ "$DEVICE" = "rockpro64" ]]; then
Dan Johansen's avatar
Dan Johansen committed
395
    #flash bootloader
396 397 398
        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
399 400
        
    #clean up
401 402 403
        umount $TMPDIR/root
        rm -r $TMPDIR/root
        partprobe $SDCARD 1> /dev/null 2>&1
404 405
        
fi
Dan Johansen's avatar
Dan Johansen committed
406 407
}

408 409

# Using Dialog to ask for user input for variables
410
DEVICE=$(dialog --clear --title "Manjaro ARM Installer" \
Helmut Stult's avatar
Helmut Stult committed
411
        --menu "Choose a device:" 20 75 10 \
412 413 414 415 416
		"pinebook"  "Pinebook" \
		"rock64"    "ROCK64" \
		"rockpro64" "ROCKPro64" \
		"sopine"    "SOPINE / PINE A64-LTS" \
		"oc2"       "Odroid C2" \
417
		"on2"       "Odroid N2" \
Helmut Stult's avatar
Helmut Stult committed
418
		"rpi3"      "Raspberry Pi 3" \
419 420 421 422
		"oc1"       "Odroid C1/C1+    (unmaintained)" \
		"xu4"       "Odroid XU4       (unmaintained)" \
		"rpi2"      "Raspberry Pi 2   (unmaintained)" \
		3>&1 1>&2 2>&3 3>&-)
423 424 425


#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
Helmut Stult's avatar
Helmut Stult committed
426 427 428 429 430 431 432 433 434 435
if [ ! -z "$DEVICE" ]; then
	EDITION=$(dialog --clear --title "Manjaro ARM Installer" \
		--menu "Choose an edition:" 20 75 10 \
		"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)" \
		3>&1 1>&2 2>&3 3>&-) 
436 437 438 439 440 441 442

else 
	clear
	exit 1
fi


Helmut Stult's avatar
Helmut Stult committed
443 444
if [ ! -z "$EDITION" ]; then
	USER=$(dialog --clear --title "Manjaro ARM Installer" \
445
	--inputbox "Enter username:" 8 50 \
Helmut Stult's avatar
Helmut Stult committed
446
	3>&1 1>&2 2>&3 3>&-)
447 448 449 450 451 452 453 454
else 
	clear
	exit 1
fi




Helmut Stult's avatar
Helmut Stult committed
455 456
if [ ! -z "$USER" ]; then
	PASSWORD=$(dialog --clear --title "Manjaro ARM Installer" \
457
	--insecure --passwordbox "Enter Password for $USER:" 8 50 \
Helmut Stult's avatar
Helmut Stult committed
458
	3>&1 1>&2 2>&3 3>&- \
459 460 461 462 463 464
	)
else 
	clear
	exit 1
fi

Helmut Stult's avatar
Helmut Stult committed
465 466
if [ ! -z "$PASSWORD" ]; then
	CONFIRMPASSWORD=$(dialog --clear --title "Manjaro ARM Installer" \
467
	--insecure --passwordbox "Confirm Password for $USER:" 8 50 \
Helmut Stult's avatar
Helmut Stult committed
468
	3>&1 1>&2 2>&3 3>&- \
469 470 471 472 473
	)
else 
	clear
	exit 1
fi
474

475
if [[ "$PASSWORD" != "$CONFIRMPASSWORD" ]]; then
Helmut Stult's avatar
Helmut Stult committed
476 477 478
	clear
	msg "User passwords do not match! Please restart the installer and try again."
	exit 1
479
fi
480

Helmut Stult's avatar
Helmut Stult committed
481 482
if [ ! -z "$CONFIRMPASSWORD" ]; then
	ROOTPASSWORD=$(dialog --clear --title "Manjaro ARM Installer" \
483
	--insecure --passwordbox "Enter Root Password:" 8 50 \
Helmut Stult's avatar
Helmut Stult committed
484
	3>&1 1>&2 2>&3 3>&- \
485 486 487 488 489 490
	)
else 
	clear
	exit 1
fi

Helmut Stult's avatar
Helmut Stult committed
491 492
if [ ! -z "$ROOTPASSWORD" ]; then
	CONFIRMROOTPASSWORD=$(dialog --clear --title "Manjaro ARM Installer" \
493
	--insecure --passwordbox "Confirm Root Password:" 8 50 \
Helmut Stult's avatar
Helmut Stult committed
494
	3>&1 1>&2 2>&3 3>&- \
495 496 497 498 499
	)
else 
	clear
	exit 1
fi
500

501
if [[ "$ROOTPASSWORD" != "$CONFIRMROOTPASSWORD" ]]; then
Helmut Stult's avatar
Helmut Stult committed
502 503 504
	clear
	msg "Root passwords do not match! Please restart the installer and try again."
	exit 1
505
fi
506

507
if [ ! -z "$CONFIRMROOTPASSWORD" ]
508 509 510
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	
Helmut Stult's avatar
Helmut Stult committed
511 512 513 514 515 516 517
	let i=0
	W=()
	while read -r line; do
		let i=$i+1
		W+=($line "")
	done < <( lsblk -dn -o NAME )
	SDCARD=$(dialog --title "Manjaro ARM Installer" \
518
	--menu "Choose your SDCard - Be sure the correct drive is selected!" 20 50 10 \
Helmut Stult's avatar
Helmut Stult committed
519
	"${W[@]}" 3>&2 2>&1 1>&3)
520 521

# add /dev/ to the selected option above
Helmut Stult's avatar
Helmut Stult committed
522 523 524
	DEV_NAME=$SDCARD
	SDCARD=/dev/$SDCARD
	SDTYP=${SDCARD:5:2}
525 526 527
else 
	clear
	exit 1
Helmut Stult's avatar
Helmut Stult committed
528
fi
529

Helmut Stult's avatar
Helmut Stult committed
530 531 532 533 534 535 536
if [[ "$SDTYP" = "sd" ]]; then
	SDDEV=""
elif [[ "$SDTYP" = "mm" ]]; then
	SDDEV="p"
else 
	clear
	exit 1
537 538 539
fi


Helmut Stult's avatar
Helmut Stult committed
540 541 542 543 544 545 546 547 548 549
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" \
	--menu "Choose your timezone!" 20 50 15 \
	"${W[@]}" 3>&1 1>&2 2>&3 3>&- \
550 551 552 553 554
	)
else 
	clear
	exit 1
fi
555 556


Helmut Stult's avatar
Helmut Stult committed
557 558 559 560 561 562 563 564 565 566 567
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" \
		--menu "Choose your locale!" 20 50 15 \
		"${W[@]}" 3>&1 1>&2 2>&3 3>&- \
		)
568 569 570 571 572
else 
	clear
	exit 1
fi

Helmut Stult's avatar
Helmut Stult committed
573 574 575 576 577 578 579 580 581 582
if [ ! -z "$LOCALE" ]; then
	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" \
		--menu "Choose your keyboard layout:" 20 50 15 \
		"${W[@]}" 3>&1 1>&2 2>&3 3>&- \
583 584 585 586 587 588
	)
else 
	clear
	exit 1
fi

Helmut Stult's avatar
Helmut Stult committed
589 590
if [ ! -z "$KEYMAP" ]; then
	HOSTNAME=$(dialog --clear --title "Manjaro ARM Installer" \
591
	--inputbox "Enter desired hostname for this system:" 8 50 \
592
	3>&1 1>&2 2>&3 3>&- \
593 594 595 596 597 598
	)
else 
	clear
	exit 1
fi

Helmut Stult's avatar
Helmut Stult committed
599 600
if [ ! -z "$HOSTNAME" ]; then
	dialog --clear --title "Manjaro ARM Installer" \
601 602 603 604
    --yesno "Is the below information correct:
    Username = $USER
    Password for $USER = $PASSWORD
    Password for root = $ROOTPASSWORD
605
    SD Card = $SDCARD
606
    Timezone = $TIMEZONE
607 608
    Locale = $LOCALE
    Keyboard layout = $KEYMAP
Helmut Stult's avatar
Helmut Stult committed
609
    Hostname = $HOSTNAME" 20 70 \
610 611
    3>&1 1>&2 2>&3 3>&-
else
Helmut Stult's avatar
Helmut Stult committed
612 613
	clear
	exit 1
614 615 616 617 618 619 620 621 622
fi

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

623

Dan Johansen's avatar
Dan Johansen committed
624 625 626 627 628 629
if [[ "$DEVICE" = "oc1" ]] || [[ "$DEVICE" = "rpi2" ]] || [[ "$DEVICE" = "xu4" ]]; then
    ARCH='armv7h'
else
    ARCH='aarch64'
fi

630 631
# get the profiles
getarmprofiles
Dan Johansen's avatar
Dan Johansen committed
632 633

#Package lists
634 635 636
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
637

638

Dan Johansen's avatar
Dan Johansen committed
639
# Commands
640
timer_start=$(get_timer)
Dan Johansen's avatar
Dan Johansen committed
641 642

prepare_card
643 644 645 646
create_install
cleanup
show_elapsed_time "${FUNCNAME}" "${timer_start}"
sync