summaryrefslogtreecommitdiffstats
path: root/replicant_gta04_install.sh
diff options
context:
space:
mode:
Diffstat (limited to 'replicant_gta04_install.sh')
-rwxr-xr-xreplicant_gta04_install.sh383
1 files changed, 290 insertions, 93 deletions
diff --git a/replicant_gta04_install.sh b/replicant_gta04_install.sh
index dcca69c..9d1f41d 100755
--- a/replicant_gta04_install.sh
+++ b/replicant_gta04_install.sh
@@ -2,7 +2,7 @@
# Replicant GTA04 installer
#
-# Copyright (C) 2012-2013 Paul Kocialkowski, GPLv2
+# Copyright (C) 2012-2014 Paul Kocialkowski, GPLv2
#
# Based on mkcard.sh v0.5
# Copyright (C) 2009 Graeme Gregory <dp@xora.org.uk>, GPLv2
@@ -18,13 +18,13 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
-# Env vars
+# Environment
#
export LC_ALL=C
#
-# Global vars
+# Globals
#
DRIVE=""
@@ -33,7 +33,10 @@ DRIVE_SIZE=""
DRIVE_CYLINDERS=""
DRIVE_PART=""
-FILES_BASE="./"
+SYSTEM_ZIP="replicant-4.2-gta04.zip"
+BOOT_FILES="MLO u-boot.bin boot.scr splash.rgb16z recovery.img"
+
+FILES_BASE="."
MOUNT_BASE="/media"
#
@@ -42,25 +45,34 @@ MOUNT_BASE="/media"
# Display
+display_help() {
+ echo "Usage: $0 [COMMAND] [DRIVE]"
+ echo ""
+ echo "It is expected that the following files are located in $FILES_BASE:"
+ echo " $BOOT_FILES for setup"
+ echo " $SYSTEM_ZIP for install"
+ echo ""
+ echo "Commands:"
+ echo " setup - setup the drive and copy the base files"
+ echo " install - install the system on the drive"
+ echo ""
+ echo "Optional arguments:"
+ echo " [DRIVE] - drive node to use"
+}
+
display_banner() {
echo "Replicant GTA04 installer"
echo ""
}
-display_help() {
- echo "Usage: $0 [FILES_BASE] [DRIVE]"
+display_complete() {
echo ""
- echo "Arguments:"
- echo "- The [FILES_BASE] argument is the path to the files"
- echo " The following files must be in that directory:"
- echo " MLO, u-boot.bin, splash.rgb16z, boot.scr, boot.img, system.tar.bz2"
- echo "- The [DRIVE] argument is the sdcard drive node and can be omitted"
+ echo "Process completed!"
}
# Drive
-drive_select_list()
-{
+drive_select_list() {
drives_dir="/dev/disk/by-id/"
count=0
@@ -95,8 +107,7 @@ drive_select_list()
done
}
-drive_select()
-{
+drive_select() {
echo "Available devices:"
drive_select_list "show"
@@ -107,10 +118,37 @@ drive_select()
echo ""
}
-drive_select_confirm() {
+drive_umount() {
+ list=$( mount | grep $DRIVE | sed "s|$DRIVE[0-9]* on \([^ ]*\) .*|\1|g" )
+
+ for mount_point in $list
+ do
+ echo "Unmounting $mount_point"
+
+ umount "$mount_point"
+ if [ $? != 0 ]
+ then
+ echo "Unmounting $mount_point failed, arborting!"
+ exit 1
+ fi
+ done
+}
+
+drive_part() {
+ if [ -e "${DRIVE}p1" ]
+ then
+ DRIVE_PART="${DRIVE}p"
+ else
+ DRIVE_PART="${DRIVE}"
+ fi
+}
+
+# Setup
+
+setup_drive_confirm() {
if [ "$DRIVE" = "" ]
then
- echo "Wrong drive block"
+ echo "Invalid drive block"
exit 1
fi
@@ -127,8 +165,8 @@ drive_select_confirm() {
for mount_point in $list
do
- mount_point_dir=$( dirname $mount_point )
- if [ "$mount_point_dir" != "/media" ] && [ "$mount_point_dir" != "/mnt" ] && [ "$mount_point" != "/media" ] && [ "$mount_point" != "/mnt" ]
+ mount_point_check=$( dirname $mount_point | grep -P "^/mnt|mount" )
+ if [ "$mount_point_check" != "" ]
then
echo ""
echo "Warning: the drive is mounted as $mount_point!"
@@ -149,23 +187,9 @@ drive_select_confirm() {
fi
}
-drive_umount() {
- list=$( mount | grep $DRIVE | sed "s|$DRIVE[0-9]* on \([^ ]*\) .*|\1|g" )
-
- for mount_point in $list
- do
- echo "Unmounting $mount_point"
+setup_drive_empty() {
+ drive_umount
- umount "$mount_point"
- if [ $? != 0 ]
- then
- echo "Unmounting $mount_point failed, arborting!"
- exit 1
- fi
- done
-}
-
-drive_empty() {
# Backup
dd if="$DRIVE" of=".drive_start_backup" bs=1024 count=1024
@@ -177,7 +201,7 @@ drive_empty() {
fi
}
-drive_rescue() {
+setup_drive_rescue() {
if [ -f ".drive_start_backup" ]
then
echo -n "Something went wrong, do you want to restore drive start backup? [Y/N] "
@@ -188,19 +212,14 @@ drive_rescue() {
fi
}
-drive_infos_get() {
+setup_drive_infos() {
DRIVE_SIZE=$( fdisk -l "$DRIVE" | grep Disk | grep bytes | awk '{print $5}' )
DRIVE_CYLINDERS=$( echo "$DRIVE_SIZE/255/63/512" | bc )
}
-drive_eject() {
- rm -rf ".drive_start_backup"
- eject "$DRIVE"
-}
-
-drive_partitions_set() {
+setup_drive_partition() {
boot_size=$( echo "(50 * 1024 * 1024) / ($DRIVE_SIZE/$DRIVE_CYLINDERS)" | bc )
- system_size=$( echo "(250 * 1024 * 1024) / ($DRIVE_SIZE/$DRIVE_CYLINDERS)" | bc )
+ system_size=$( echo "(350 * 1024 * 1024) / ($DRIVE_SIZE/$DRIVE_CYLINDERS)" | bc )
cache_size=$( echo "(100 * 1024 * 1024) / ($DRIVE_SIZE/$DRIVE_CYLINDERS)" | bc )
{
@@ -217,32 +236,28 @@ drive_partitions_set() {
sleep 1
- if [ -e "${DRIVE}p1" ]
- then
- DRIVE_PART="${DRIVE}p"
- else
- DRIVE_PART="${DRIVE}"
- fi
+ drive_part
mkfs.vfat -F 32 -n "boot" "${DRIVE_PART}1"
- mkfs.ext2 -L "system" "${DRIVE_PART}2"
- mkfs.ext2 -L "cache" "${DRIVE_PART}3"
- mkfs.ext2 -L "data" "${DRIVE_PART}4"
+ mkfs.ext4 -L "system" "${DRIVE_PART}2"
+ mkfs.ext4 -L "cache" "${DRIVE_PART}3"
+ mkfs.ext4 -L "data" "${DRIVE_PART}4"
sleep 1
}
-drive_write() {
- echo "Writing boot files"
+setup_boot_install() {
+ echo "Installing boot files"
+
+ drive_part
mkdir -p "$MOUNT_BASE/boot"
mount "${DRIVE_PART}1" "$MOUNT_BASE/boot"
- cp $FILES_BASE/MLO "$MOUNT_BASE/boot/"
- cp $FILES_BASE/u-boot.bin "$MOUNT_BASE/boot/"
- cp $FILES_BASE/splash.rgb16z "$MOUNT_BASE/boot"
- cp $FILES_BASE/boot.scr "$MOUNT_BASE/boot"
- cp $FILES_BASE/boot.img "$MOUNT_BASE/boot"
+ for file in $BOOT_FILES
+ do
+ cp "$FILES_BASE/$file" "$MOUNT_BASE/boot/"
+ done
dir=$( pwd )
echo "Syncing boot files"
@@ -252,52 +267,223 @@ drive_write() {
umount "$MOUNT_BASE/boot"
rmdir "$MOUNT_BASE/boot"
+}
+
+setup_drive_eject() {
+ rm -rf ".drive_start_backup"
+ eject "$DRIVE"
+}
- echo "Writing system files"
+# Install
- mkdir -p "$MOUNT_BASE/system"
- mount "${DRIVE_PART}2" "$MOUNT_BASE/system"
+install_package_extract_dir() {
+ destination="$MOUNT_BASE"$( dirname "$2")
- tar -p -xf "system.tar.bz2" -C "$MOUNT_BASE/system/" --strip-components=1 "system/"
- if [ $? != 0 ]
+ if [ $# -lt 2 ]
then
- umount "$MOUNT_BASE/system"
- rmdir "$MOUNT_BASE/system"
+ return
+ fi
- exit 1
+ unzip -o "$FILES_BASE/$SYSTEM_ZIP" "$1/**" -d "$destination"
+}
+
+install_package_extract_file() {
+ destination="$MOUNT_BASE"$( dirname "$2")
+
+ if [ $# -lt 2 ]
+ then
+ return
+ fi
+
+ unzip -o "$FILES_BASE/$SYSTEM_ZIP" "$1" -d "$destination"
+}
+
+install_symlink() {
+ source=""
+
+ if [ $# -lt 2 ]
+ then
+ return
+ fi
+
+ for path in $@
+ do
+ if [ "$source" = "" ]
+ then
+ source="$path"
+ continue
+ fi
+
+ unlink "$MOUNT_BASE$path"
+ ln -s "$source" "$MOUNT_BASE$path"
+ done
+}
+
+install_set_perm() {
+ uid=""
+ gid=""
+ mode=""
+
+ if [ $# -lt 4 ]
+ then
+ return
fi
+ for value in $@
+ do
+ if [ "$uid" = "" ]
+ then
+ uid="$value"
+ continue
+ fi
+
+ if [ "$gid" = "" ]
+ then
+ gid="$value"
+ continue
+ fi
+
+ if [ "$mode" = "" ]
+ then
+ mode="$value"
+ continue
+ fi
+
+ chown "$uid:$gid" "$MOUNT_BASE$value"
+ chmod "$mode" "$MOUNT_BASE$value"
+ done
+}
+
+install_set_perm_recursive() {
+ uid=""
+ gid=""
+ dir_mode=""
+ file_mode=""
+
+ if [ $# -lt 4 ]
+ then
+ return
+ fi
+
+ for value in $@
+ do
+ if [ "$uid" = "" ]
+ then
+ uid="$value"
+ continue
+ fi
+
+ if [ "$gid" = "" ]
+ then
+ gid="$value"
+ continue
+ fi
+
+ if [ "$dir_mode" = "" ]
+ then
+ dir_mode="$value"
+ continue
+ fi
+
+ if [ "$file_mode" = "" ]
+ then
+ file_mode="$value"
+ continue
+ fi
+
+ find "$MOUNT_BASE$value" -type d -exec chown "$uid:$gid" {} \; -exec chmod "$dir_mode" {} \;
+ find "$MOUNT_BASE$value" -type f -exec chown "$uid:$gid" {} \; -exec chmod "$file_mode" {} \;
+ done
+}
+
+install_command() {
+ command=$( echo "$1" | sed "s/[ \t]*\([^(]*\)(.*/\1/g" )
+ arguments=$( echo "$1" | sed -e "s/[^(]*(\([^)]*\));.*/\1/g" -e "s/[ \t]*,[ \t]*/ /g" | tr -d '"')
+
+ case "$command" in
+ "package_extract_dir")
+ install_package_extract_dir $arguments
+ ;;
+ "package_extract_file")
+ install_package_extract_file $arguments
+ ;;
+ "symlink")
+ install_symlink $arguments
+ ;;
+ "set_perm")
+ install_set_perm $arguments
+ ;;
+ "set_perm_recursive")
+ install_set_perm_recursive $arguments
+ ;;
+ esac
+}
+
+install_script() {
+ unzip -p "$FILES_BASE/$SYSTEM_ZIP" "META-INF/com/google/android/updater-script" | while read line
+ do
+ end_test=$( echo "$line" | grep -P "\);$" )
+
+ COMMAND="$COMMAND$line"
+
+ if [ "$end_test" != "" ]
+ then
+ install_command "$COMMAND"
+
+ COMMAND=""
+ fi
+ done
+}
+
+install_mount() {
+ drive_part
+
+ drive_umount
+
+ mkdir -p "$MOUNT_BASE/boot"
+ mount "${DRIVE_PART}1" "$MOUNT_BASE/boot"
+
+ mkdir -p "$MOUNT_BASE/system"
+ mount "${DRIVE_PART}2" "$MOUNT_BASE/system"
+}
+
+install_umount() {
+ drive_part
+
dir=$( pwd )
- echo "Syncing system files"
+ echo "Syncing files"
+
+ cd "$MOUNT_BASE/boot"
+ sync
+ cd "$dir"
+
cd "$MOUNT_BASE/system"
sync
cd "$dir"
+ umount "$MOUNT_BASE/boot"
+ rmdir "$MOUNT_BASE/boot"
+
umount "$MOUNT_BASE/system"
rmdir "$MOUNT_BASE/system"
}
-display_end() {
- echo ""
- echo "Your drive is now ready to be used!"
+install_eject() {
+ eject "$DRIVE"
}
-# Script start
+#
+# Main
+#
-if [ $# -eq 0 ] || [ $# -gt 2 ] || [ "$1" = "--help" ] || [ "$1" = "help" ]
+if [ $# -lt 1 ] || [ $# -gt 2 ]
then
display_help
exit 1
fi
-if [ $# -eq 1 ]
-then
- FILES_BASE=$1
-fi
-
-if [ $# -eq 2 ]
+if [ $# -gt 1 ]
then
- FILES_BASE=$1
DRIVE=$2
fi
@@ -308,15 +494,26 @@ then
drive_select
fi
-# Drive
-drive_select_confirm
-drive_umount
-drive_empty
-drive_infos_get
-
-drive_partitions_set
-drive_write
-
-# Finishing
-display_end
-drive_eject
+case $1 in
+ "setup")
+ setup_drive_confirm
+ drive_umount
+ setup_drive_empty
+ setup_drive_infos
+ setup_drive_partition
+ setup_boot_install
+ setup_drive_eject
+
+ display_complete
+ ;;
+ "install")
+ install_mount
+ install_script
+ install_umount
+ install_eject
+ ;;
+ *)
+ display_help
+ exit 1
+ ;;
+esac