diff --git a/bootanim.sh b/bootanim.sh index 395da39..b5b6079 100644 --- a/bootanim.sh +++ b/bootanim.sh @@ -1,6 +1,4 @@ #!/system/bin/sh -DEBUG="false" - # ======== variables ======== persist_dir=/data/adb/bootanimation MODDIR=/data/adb/modules/bootanimation-module-ronux @@ -29,6 +27,7 @@ abort_msg(){ else echo "ERROR\n\n$abortInp" fi + log -t bootanimation-module-ronux-bootanim "E: $abortInp" exit 1 } log_msg() @@ -44,17 +43,19 @@ log_msg() # ======== main func ======== set_ani(){ [ ! -f "$user_anipath" ] && abort_msg 'Bootanimation file not found!' - mkdir -p "$persist_dir" - if [ ! -f "$persist_dir/bootanimation_path.txt" ]; then - $MODDIR/create_bootanimation_pathfile.sh - [ "$?" = "100" ] && abort_msg 'Bootanimation file was not found in the system path' + mkdir -p "$persist_dir" || abort_msg 'Could not create persist directory' + "$MODDIR/create_bootanimation_pathfile.sh" + [ "$?" = "100" ] && abort_msg 'Bootanimation file was not found in the system path' + # fail-safe + tmp_path="$bootani_path.tmp" + if ! cp -f "$user_anipath" "$tmp_path" || ! chmod 644 "$tmp_path" || ! chown "root:root" "$tmp_path"; then + rm -f "$tmp_path" + abort_msg 'Copy failed, and custom bootanimation not changed' fi + mv -f "$tmp_path" "$bootani_path" || { rm -f "$tmp_path"; abort_msg 'Could not replace bootanimation'; } + chcon "u:object_r:system_file:s0" "$bootani_path" 2>/dev/null rm -f "$persist_dir/disable" - cp -f "$user_anipath" "$bootani_path" - chcon "u:object_r:system_file:s0" "$bootani_path" - chown root:root "$bootani_path" - chmod 644 "$bootani_path" - log_msg 'Bootanimation applied succesfully' + log_msg 'Bootanimation applied successfully' exit } reset_ani(){ @@ -77,40 +78,6 @@ state_ani(){ [ -f "$persist_dir/disable" ] && log_msg 'State: disabled' [ ! -f "$persist_dir/disable" ] && log_msg 'State: enabled' } -debug_mode(){ - [ "$DEBUG" = "false" ] && abort_msg "This feature is disabled in the release versions" - if [ "$isModule" = "yes" ]; then - # Disable Debug mode - if [ -f "$MODDIR/debug_mod" ]; then - read -p 'All settings will be reverted for testing purposes. Do you want to continue (y/N): ' userInp - if [ "$userInp" = 'y' ]; then - rm -rf "$MODDIR/debug_mod" 2>/dev/null - mv "$MODDIR/webroot_disabled" "$MODDIR/webroot" 2>/dev/null - mv "$MODDIR/post-fs-data.sh_disabled" "$MODDIR/post-fs-data.sh" - exit - else - abort_msg 'Aborted' - fi - fi - # Enable Debug mode - touch "$MODDIR/debug_mod" - read -p "Do you want WebUI disabled for testing purposes (y/N): " userInp - if [ "$userInp" = 'y' ]; then - [ -f "$MODDIR/webroot" ] && mv "$MODDIR/webroot" "$MODDIR/webroot_disabled" && log_msg 'WebUI disabled' - fi - read -p "Do you want the post-fs-data script to run every boot (y/N): " userInp - [ "$userInp" = 'y' ] && mv "$MODDIR/post-fs-data.sh" "$MODDIR/post-fs-data.sh_disabled" && log_msg 'post-fs-data.sh disabled' - fi -} - -if [ "$DEBUG" = "true" ]; then - # Detect the environment (for debugging) - if [ -f "$MODDIR/bootanim.sh" ]; then - isModule="yes" - else - isModule="no" - fi -fi [ "$(id -u)" != "0" ] && abort_msg 'Superuser privileges are required!' @@ -121,7 +88,6 @@ case "$user_command" in -r|--reset) reset_ani ;; -st|--state) state_ani ;; -h|--help) help_menu ;; - -dbg|--debug) debug_mode ;; '') help_menu && exit 1 ;; *) help_menu && exit 1 ;; esac diff --git a/customize.sh b/customize.sh index fb04e0d..ba53010 100644 --- a/customize.sh +++ b/customize.sh @@ -3,15 +3,6 @@ persist_dir="/data/adb/bootanimation" ui_print '- Installing Bootanimation Module without OverlayFS' chmod +x $MODPATH/*.sh -for i in "/product/media/bootanimation.zip" "/system/product/media/bootanimation.zip" "/system/media/bootanimation.zip" "/oem/media/bootanimation.zip"; do - if [ -f "$i" ]; then - TARGET_PATH="$i" - break - fi -done -if [ -n "$TARGET_PATH" ]; then - mkdir -p "$persist_dir" - echo "$TARGET_PATH" >"$persist_dir/bootanimation_path.txt" -else - abort '! Bootanimation file was not found in the system path' -fi +"$MODPATH/create_bootanimation_pathfile.sh" +[ "$?" = "100" ] && abort '! Bootanimation file was not found in the system path' +ui_print '- Installed! Please reboot to use!' diff --git a/post-fs-data.sh b/post-fs-data.sh index 604173b..c3257d9 100644 --- a/post-fs-data.sh +++ b/post-fs-data.sh @@ -2,19 +2,22 @@ MODDIR=${0%/*} persist_dir=/data/adb/bootanimation bootani_file=$persist_dir/bootanimation.zip -system_path="$(cat "$persist_dir/bootanimation_path.txt")" -bootani_con="$(ls -Z "$system_path" 2>/dev/null | awk '{print $1}')" [ -f "$persist_dir/disable" ] && exit -if [ ! -f "$bootani_file" ]; then - exit 1 -elif [ -f "$bootani_file" ]; then - if [ ! -f "$system_path" ]; then - [ -f "$persist_dir/bootanimation_path.txt" ] && rm "$persist_dir/bootanimation_path.txt" - $MODDIR/create_bootanimation_pathfile.sh - exit - fi - chcon "$bootani_con" "$bootani_file" 2>/dev/null - umount -l "$system_path" - mount --bind "$bootani_file" "$system_path" + + +[ ! -f "$bootani_file" ] && exit 1 +system_path="$(cat "$persist_dir/bootanimation_path.txt")" +bootani_con="$(ls -Z "$system_path" 2>/dev/null | awk '{print $1}')" +if [ ! -f "$system_path" ]; then + [ -f "$persist_dir/bootanimation_path.txt" ] && rm "$persist_dir/bootanimation_path.txt" + "$MODDIR/create_bootanimation_pathfile.sh" || exit + # reassign variables + system_path="$(cat "$persist_dir/bootanimation_path.txt")" + bootani_con="$(ls -Z "$system_path" 2>/dev/null | awk '{print $1}')" fi + + +chcon "$bootani_con" "$bootani_file" 2>/dev/null +umount -l "$system_path" +mount --bind "$bootani_file" "$system_path" diff --git a/service.sh b/service.sh index be1bd42..14642b0 100644 --- a/service.sh +++ b/service.sh @@ -10,5 +10,8 @@ elif [ "$APATCH" = "true" ]; then else [ -w /sbin ] && magisktmp=/sbin [ -w /debug_ramdisk ] && magisktmp=/debug_ramdisk - ln -sf "$MOD_PATH/bootanim.sh" "$magisktmp/bootanim" + # check magisktmp + [ -z "$magisktmp" ] && log -t bootanimation-module-ronux 'MagiskTMP dir not found or inaccessible, bootanim not linked' && exit 1 + # link the bootanim to magisktmp + ln -sf "$MOD_PATH/bootanim.sh" "$magisktmp/bootanim" fi