87 lines
3.2 KiB
Bash
Executable file
87 lines
3.2 KiB
Bash
Executable file
#!/sbin/ash
|
|
# shellcheck shell=dash
|
|
|
|
# Copyright 2017 Attila Szöllősi
|
|
#
|
|
# This file is part of postmarketos-android-recovery-installer.
|
|
#
|
|
# postmarketos-android-recovery-installer is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# postmarketos-android-recovery-installer is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with postmarketos-android-recovery-installer. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
# shellcheck source=pmos_install_functions
|
|
. /tmp/postmarketos/bin/pmos_install_functions "$1" "$2"
|
|
# shellcheck source=/dev/null
|
|
. "$WORKING_DIR"/install_options
|
|
|
|
exec > "$WORKING_DIR"/pmos.log 2>&1
|
|
set -ex
|
|
|
|
ui_print "postmarketOS recovery installer"
|
|
|
|
ui_print "Extracting partition info from fstab..."
|
|
extract_partition_table
|
|
ui_print "Entering working directory..."
|
|
cd "$WORKING_DIR"
|
|
ui_print "Extracting files..."
|
|
unzip -o "$ZIP"
|
|
mkdir /lib
|
|
ui_print "Symlinking .so files to /lib/..."
|
|
ln -s "$WORKING_DIR"/lib/* /lib/
|
|
ui_print "Unmounting /$INSTALL_PARTITION..."
|
|
umount_install_partition
|
|
ui_print "Creating partition table on $INSTALL_DEVICE..."
|
|
# parted returns nonzero even when command executed successfully
|
|
partition_install_device || :
|
|
if [ "$FDE" = "true" ]
|
|
then
|
|
ui_print "Generating temporary keyfile with random data..."
|
|
dd bs=512 count=4 if=/dev/urandom of="$WORKING_DIR"/lukskey
|
|
ui_print "Initializing LUKS device..."
|
|
cryptsetup luksFormat --use-urandom -c "$CIPHER" -q "$ROOT_PARTITION" "$WORKING_DIR"/lukskey
|
|
ui_print "Opening LUKS partition..."
|
|
cryptsetup luksOpen -d "$WORKING_DIR"/lukskey "$ROOT_PARTITION" pm_crypt
|
|
ui_print "Formatting LUKS partition..."
|
|
make_ext4fs -L 'pmOS_root' /dev/mapper/pm_crypt
|
|
ui_print "Mounting LUKS partition..."
|
|
mount -t ext4 -rw /dev/mapper/pm_crypt /"$INSTALL_PARTITION"
|
|
else
|
|
ui_print "Formatting root partition..."
|
|
make_ext4fs -L 'pmOS_root' "$ROOT_PARTITION"
|
|
ui_print "Mounting root partition..."
|
|
mount -t ext4 -rw "$ROOT_PARTITION" /"$INSTALL_PARTITION"
|
|
fi
|
|
ui_print "Formatting pmOS_boot..."
|
|
mkfs.ext2 -q -L 'pmOS_boot' "$PMOS_BOOT"
|
|
ui_print "Mounting pmOS_boot..."
|
|
mkdir /"$INSTALL_PARTITION"/boot
|
|
mount -t ext2 -rw "$PMOS_BOOT" /"$INSTALL_PARTITION"/boot || {
|
|
ui_print "Failed to format/mount ext2 partition."
|
|
ui_print "Trying ext4..."
|
|
make_ext4fs -L 'pmOS_boot' "$PMOS_BOOT"
|
|
mount -t ext4 -rw "$PMOS_BOOT" /"$INSTALL_PARTITION"/boot
|
|
}
|
|
ui_print "Installing rootfs..."
|
|
tar -xf rootfs.tar.gz -C /"$INSTALL_PARTITION"
|
|
if [ "$FLASH_BOOTIMG" = "true" ]
|
|
then
|
|
ui_print "Flashing boot.img..."
|
|
dd if=boot.img of="$BOOT"
|
|
fi
|
|
if [ "$FDE" = "true" ]
|
|
then
|
|
ui_print "Creating a symlink for password setting script in /sbin/..."
|
|
ln -s "$WORKING_DIR"/bin/pmos_setpw /sbin/
|
|
ui_print "Do not forget to add a password to the LUKS partition!"
|
|
ui_print "Run the command: pmos_setpw from the terminal/adb shell!"
|
|
fi
|
|
ui_print "Installation done."
|