[Q] Debloat script coding - Android Q&A, Help & Troubleshooting

Hello all,
I'm trying to cleanup/simplify some code to debloat a stock samsung rom. Im using osm0sis (https://forum.xda-developers.com/an...-complete-shell-script-flashable-zip-t2934449) shell script to do this:
Code:
STOCK_APPS="ANTHalService
ANTPlusPlugins
ANTPlusTest
ANTRadioService"
debloat_sysapps () {
for app in $(STOCK_APPS); do
if [ -d "/system/priv-app/${app}" ]; then
mkdir -p "/sdcard/stock_backups/priv-app/";
mv "/system/priv-app/${app}" "/sdcard/stock_backups/priv-app/";
fi;
else [ -d "/system/app/${app}" ]; then
mkdir -p "/sdcard/stock_backups/app/";
mv "/system/priv-app/${app}" "/sdcard/stock_backups/app/";
fi;
done;
}
Which when I flash in TWRP, returns error 2. Anyone got any tips/insight on how to make it work?
(Im aware that the usual delete_recursive works, which is what Ive been using usually.)
Thanks in advance,
yass

Related

need help to translate MIUI V4 (ICS)

Hi,
i tried to translate a MIUI for Galaxy Nexus rom into french (can also be an other language)
i wrote an unix script to automate the process.
What i do is quite simple:
i get a specific MIUI V4 version for my device and the same translated version for the nexus S (because the nexus S has a french version)
i decompile each apk from the french rom, an put the french files into to decompile galaxy nexus directories
i recompile each apk
and i copy the compiled resources into the origin galaxy nexus apks
and i build the new ROM
but i get a bootloop any ideas ?
here is my script
if there are any part of this script that isn't clear, i could try to explain them.
of course this script could also be used on other device or other translation with some changes.
Thanks in advance .
Code:
#!/bin/bash
# MIUI-FRENCH TRANSLATE SCRIPT FOR GNEX V1.0 By Alain57
BASE_DIR=$PWD
FRENCH_DIR=$BASE_DIR/french_rom
ORIGINAL_DIR=$BASE_DIR/original_rom
OUTPUT_ROM_DIR=$BASE_DIR/output_rom
OUT_DIR=$BASE_DIR/out
WORK_DIR=$BASE_DIR/workdir
ORIGIN_APK_DIR=$WORK_DIR/origin
TRANSLATION_DIR=$WORK_DIR/translation
DECODED_APK_DIR=$WORK_DIR/decoded
LOG_FILE=$BASE_DIR/log.txt
TEMP_DIR=$BASE_DIR/temp
# clean the log file and create the missing directories if they don't exist (for exemple on first run)
function cleanLog(){
rm -fr $LOG_FILE
ARRAY_DIR=( $FRENCH_DIR $ORIGINAL_DIR $OUTPUT_ROM_DIR $OUT_DIR $WORK_DIR $ORIGIN_APK_DIR $TRANSLATION_DIR $DECODED_APK_DIR $TEMP_DIR )
echo "creating missing directoriesi if needed"
for DIR in ${ARRAY_DIR[@]}; do
if [ ! -d $DIR ]; then
mkdir $DIR
fi
done
}
# configure apktool to use framework-res and framework-miui-res
function setFramework(){
cd $FRENCH_DIR
echo "<- apktool if system/framework/framework-res.apk ->" >> $LOG_FILE
apktool if framework-res.apk >> $LOG_FILE 2>&1
echo "<- apktool if system/framework/framework-miui-res.apk ->" >> $LOG_FILE
apktool if framework-miui-res.apk >> $LOG_FILE 2>&1
}
#decompile all apk file from the english Gnex miui rom
function decompileOriginFiles(){
cd $ORIGINAL_DIR
COUNT_ORIGINAL_ZIP=`ls . | grep '.zip' | wc -l`
if [ "$COUNT_ORIGINAL_ZIP" -eq "1" ]; then
mv *.zip en.zip
echo "unzip the original rom"
unzip -q -o en.zip
echo "copy the apks to the origin dir"
cp -a system/framework/*.apk $ORIGIN_APK_DIR
cp -a system/app/*apk $ORIGIN_APK_DIR
cd $ORIGIN_APK_DIR
for F in *.apk; do
echo "decompiling origianl file $F ..." | tee -a $LOG_FILE
apktool d $F $DECODED_APK_DIR/${F%.apk} >> $LOG_FILE 2>&1
done
else
echo "there need to be ONE zip file in the original directory"
exit
fi
}
# decompile all apk files from the french Nexus S ROM
function decompileTranslatedFiles(){
cd $FRENCH_DIR
COUNT_FRENCH_ZIP=`ls . | grep '.zip' | wc -l`
if [ "$COUNT_FRENCH_ZIP" -eq "1" ]; then
mv *.zip fr.zip
echo "unzip the french rom"
unzip -q -o fr.zip
setFramework
echo "copy the apks to the working dir"
cp -a system/framework/*.apk $WORK_DIR
cp -a system/app/*.apk $WORK_DIR
cd $WORK_DIR
for F in *.apk; do
echo "decompiling french file $F ..." | tee -a $LOG_FILE
apktool d $F $TRANSLATION_DIR/${F%.apk} >> $LOG_FILE 2>&1
done
else
echo "there neeed to be ONE zip file in the french directory"
exit
fi
}
# Delete the given directory, because it is not needed
function deleteDirectoryWithoutTranslation(){
echo " ---> directory useless, removed"
cd $TRANSLATION_APK_DIR
rm -fr $1
}
# delete all useless data from the french apks
function cleanTranslatedFiles(){
cd $TRANSLATION_DIR
for d in *; do
echo "cleaning the directory $d"
cd $TRANSLATION_DIR/$d
if [ -d "res" ]; then
ls . | grep -v res | xargs -o rm -fr
cd "res"
CONTAINS_FRENCH_TRANSLATION=`ls .| grep '\-fr' | wc -l`
if [ "$CONTAINS_FRENCH_TRANSLATION" -eq "0" ]; then
deleteDirectoryWithoutTranslation $d
else
echo "---> transltation here, clean it"
ls . | grep -v '\-fr\|\./\|\.\./' | xargs -o rm -fr
fi
else
echo "no res directory"
deleteDirectoryWithoutTranslation $d
fi
if [ ! -f $ORIGIN_APK_DIR/$d.apk ];then
echo "directory not in original rom $d"
deleteDirectoryWithoutTranslation $d
fi
done
}
# merge the decoded translation in the decoded english files
function mergeTranslations(){
cd $DECODED_APK_DIR
mv $TRANSLATION_DIR/* .
cd $WORK_DIR
rm -f *.apk
}
# compile new apks including french files
function compileApk(){
cd $ORIGIN_APK_DIR
for f in *.apk; do
echo "compiling $f"
echo "apktool b $DECODED_APK_DIR/${f%.apk} $WORK_DIR/$f"
apktool b $DECODED_APK_DIR/${f%.apk} $WORK_DIR/$f >> $LOG_FILE 2>&1
done
}
# delete apk in work directory and put the original apks there
function deleteWorkFileAndCopyOriginalApk(){
cd $WORK_DIR
rm -f *.apk
cp -a $ORIGIN_APK_DIR/*.apk .
}
# put the compiled modified files in the original apk files
function finalMerge(){
cd $DECODED_APK_DIR
for F in *.apk; do
echo "doing final build $F"
cd $TEMP_DIR
rm -fr *
unzip -q $DECODED_DIR/$F
ls . | grep -v 'res\|classes.dex\|resources.arsc\|\./\|\.\./' | xargs -o rm -fr
if [ -d res ]; then
cd res
ls . | grep -v '\-fr\|\./\|\.\./' | xargs -o rm -fr
HAS_FR=`ls . | grep '\-fr' | wc -l`
if [ "$HAS_FR" -eq "0" ]; then
cd ..
rm -fr res
else
cd ..
fi
fi
zip -r $WORK_DIR/$F *
done
}
#replace the english apk files with the new french apk files, change the build.prop value and create an unsigned zip that can be flashed
function createRom(){
cd $OUTPUT_ROM_DIR
mv $ORIGINAL_DIR/system $ORIGINAL_DIR/boot.img $ORIGINAL_DIR/META-INF .
mv $WORK_DIR/*.apk system/app
mv system/app/framework*.apk system/framework
mv system/build.prop build.prop
sed 's/=en/=fr/g' build.prop > build1.prop
rm -f build.prop
sed 's/=US/=FR/g' build1.prop > system/build.prop
rm -f build1.prop
zip -r $BASE_DIR/new_rom.zip *
}
cleanLog
decompileTranslatedFiles
decompileOriginFiles
cleanTranslatedFiles
mergeTranslations
compileApk
deleteWorkFileAndCopyOriginalApk
finalMerge
createRom
Questions or Problems Should Not Be Posted in the Development Forum
Please Post in the Correct Forums & Read the Forum Rules
Moving to Q&A

[Q] debian, webtopMOD and post #865

Re: [MOD] Full Linux (Debian) inside WebTop! v0.2.7
I managed to unlock, root and install WebTopMOD on my new2me searet Atrix 4g. Great feeling for an android n00b! I can run iceweasel, gimp and whatever I like just like any linux distro on the webtop as long as I start a new shell to launch linux apps. I had wanted to continue on to using the instructions in post #865 by jissee44 to get the xfce4 window manager running. No luck! I can launch (I think) xfce4 manually and the entire view changes - new wallpaper, new toolbar, but no access to the linux filesystem - everything connects to the android filesystem.
Here is what I think is needed to see what went wrong. There are only two files to edit when following post #865. I am including the entire file as the posting I was following does not include diffs.
/osh/usr/sbin/linux
Code:
#!/bin/bash
CHROOTDIR="/osh/opt/WebTopMOD/root"
LOOPDEVICE="/dev/block/loop50"
function enablex {
xhost +
}
function mountlinuxdisk {
loopdevice
sudo mount -t ext3 -o loop=$LOOPDEVICE $FILENAME $CHROOTDIR
touch /tmp/linuxdiskactive
}
function umountlinuxdisk {
sudo umount $CHROOTDIR
sudo umount $LOOPDEVICE
rm /tmp/linuxdiskactive
}
function startfulllinuxchroot {
mountlinuxdisk
sudo mount -o bind /proc $CHROOTDIR/proc
sudo mount -o bind /dev $CHROOTDIR/dev
sudo mount -o bind /dev/pts $CHROOTDIR/dev/pts
sudo mount -o bind /dev/shm $CHROOTDIR/dev/shm
#sudo mount -o bind /proc/bus/usb $CHROOTDIR/proc/bus/usb
sudo mount -o bind /sys $CHROOTDIR/sys
sudo mount -o bind /tmp $CHROOTDIR/tmp
sudo mount -o bind /var/tmp $CHROOTDIR/var/tmp
sudo mount -o bind /var/run/dbus/ $CHROOTDIR/var/run/dbus
sudo mount -t vfat /dev/block/vold/179:18 $CHROOTDIR/sdcard
sudo mount -t vfat /dev/block/vold/179:33 $CHROOTDIR/sdcard-ext
sudo mount -o bind /etc $CHROOTDIR/mnt/DEVICE/etc
sudo mount -o bind /usr $CHROOTDIR/mnt/DEVICE/usr
touch /tmp/fulllinuxchrootactive
}
function startxterm {
# sudo chroot $CHROOTDIR /usr/bin/xterm pdmenu
sudo chroot $CHROOTDIR /usr/bin/xterm
}
function startxfce {
kill $(ps -ef | grep 5000 | grep webtop-wallpaper | cut -c10-15)
kill $(ps -ef | grep 5000 | grep xscreensaver | cut -c10-15
sudo chroot $CHROOTDIR /usr/bin/xfce4-session
}
function stopfullchroot {
CHECKS=0
until [ "$CHECKS" -eq "15" ]
do
TOUMOUNT=`sudo mount | grep "$CHROOTDIR" | awk '{ print $3 }'`
if [ "$TOUMOUNT" = "" ]; then break; fi
for i in $TOUMOUNT
do
sudo umount $i
done
CHECKS=$(( $CHECKS + 1 ))
done
rm /tmp/fulllinuxchrootactive
mountlinuxdisk
}
function checkwhereislinux {
if [ -e /sdcard/WebTopMOD/linuxdisk ]; then
FILENAME="/sdcard/WebTopMOD/linuxdisk"
if [ "$1" -eq 1 ]; then
/usr/bin/xmessage "Found image in /sdcard/WebTopMOD/linu
xdisk!"
checklinuxdisk
fi
else
if [ -e /sdcard-ext/WebTopMOD/linuxdisk ]; then
FILENAME="/sdcard-ext/WebTopMOD/linuxdisk"
if [ "$1" -eq 1 ]; then
/usr/bin/xmessage "Found image in /sdcard-ext/We
bTopMOD/linuxdisk!"
checklinuxdisk
fi
else
if [ "$1" -eq 1 ]; then
/usr/bin/xmessage "Sorry, no image available...
put linuxdisk in /sdcard/WebTopMOD/ OR /sdcard-ext/WebTopMOD/linuxdisk"
exit 1
fi
fi
fi
}
function checklinuxdisk {
if [ ! -s $FILENAME ]; then
/usr/bin/xmessage "But... Wait... Your disk looks damaged, maybe
you tried to copy an image larger then 4gB? This is a FAT32 limit."
exit 1
fi
if [ -d $FILENAME ]; then
/usr/bin/xmessage "Damn! linuxdisk is a file and it MUST be plac
ed in /sdcard/WebTopMOD/ OR /sdcard-ext/WebTopMOD/ folder. Otherwise this mod CA
N'T work' "
exit 1
fi
}
function loopdevice {
if [ -e $LOOPDEVICE ]; then
echo "Device exist"
else
sudo mknod -m600 $LOOPDEVICE b 7 50
fi
}
enablex
if [ -e /tmp/linuxdiskactive ]; then
if [ -e /tmp/fulllinuxchrootactive ]; then
startxterm
else
checkwhereislinux 0
startfulllinuxchroot
startxterm
fi
else
checkwhereislinux 1
mountlinuxdisk
startfulllinuxchroot
startxfce
# startxterm
fi
#RUNNINGXTERM=`ps -C xterm h | wc -l`
#if [ "$RUNNINGXTERM" -eq 0 ]
#then
# stopfullchroot
# umountlinuxdisk
#fi
exit 0
/osh/usr/local/bin/start-oshwt-2.sh
Code:
#! /bin/sh
### BEGIN INIT INFO
# Provides: start_lxde2.sh
# Required-Start:
# Required-Stop:
# Default-Start:
# Default-Stop:
# Short-Description: started by adas user at login
### END INIT INFO
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
export LD_LIBRARY_PATH=/usr/lib:/usr/local/lib
. /lib/lsb/init-functions
log_action_msg "Will now start OSHWT 2 scripts"
# start OSHWT 2 scripts
sfalv -i "lxpanel"
#sfalv -i "awn-autostart"
sfalv -i "webtop-panel"
sfalv -i "webtop-wallpaper"
sfalv -i "evbridge"
sfalv -i "window_switcher"
sr-test avahi_start &
Can someone give me some clues as to what has gone wrong? I'm not sure if something is missing or if I broke something in my edits, and there are no follow up questions on the post. There are 13 thanks.
ruarri
making progress?
Okay, I'm just hearing the crickets.
> startxfce4
provides some of the results I want, but leaves AWN in control. Now that the new ICS ROMs are coming out I'll have to see if I can just make webtopMOD usable until something better comes along. It would be good to see better documentation for n00bs. The forums are a little rambling. There is a lot of good info, its just scattered.
ruarri
ruarri said:
no access to the linux filesystem - everything connects to the android filesystem.
Click to expand...
Click to collapse
Hi,
What do you mean ?
The Debian is a Chroot
Good'nough
jisse44 said:
The Debian is a Chroot
Click to expand...
Click to collapse
Thanks for the terse explanation, jisse44. It took me a while to get around to reading the docs on chroot. It makes sense that webtop isrunning in a sandbox. That is inherently limiting.
I still love webtop and my lapdock. It will be interesting to see what happens with webtop and the ICS ROMs on the Atrix 4G.
ruarri said:
It will be interesting to see what happens with webtop and the ICS ROMs on the Atrix 4G.
Click to expand...
Click to collapse
Or not....
By now you can only run last new "webtop" on ICS Roms, and this is not THE webtop, it's a tablet mode: no Ubuntu or debian, only Android....

[Q] Repurpose Eris?

I have two of these devices sitting around and I was wondering how people were repurposing them. I just picked up a Raspberry Pi with the intention of setting up a home automation system. Isn't the Eris also an ARMv6 processor? Could they be used as smart WiIP video security cameras? Is there a Linux distro somewhere? Anyone have any experience?
Greetings! There's a thread here you might be interested in. http://forum.xda-developers.com/showthread.php?t=823564&highlight=linux
roirraW "edor" ehT said:
Greetings! There's a thread here you might be interested in. http://forum.xda-developers.com/showthread.php?t=823564&highlight=linux
Click to expand...
Click to collapse
http://www.4shared.com/zip/uiPl7NhN/ubuntu.html Link to Ubuntu.img
to mount you can use this:
linuxboot.sh
#option if you wish to load a different file than the rc_enter just replace the rc_enter.sh with the script file you want to run
# i.e init.sh below this script I will post the initl.ls if you wan to replace the rc_enter.sh
Code:
#!/system/bin/sh
(
# If $BINDS does not exist, then done of the others are set iether.
if [ -z "$BINDS" ]; then
export DIST="debian squeeze"
export FILESYSTEM=/sdcard/ubuntu.img
export MOUNTPOINT=/sdcard/linux
export PATH=/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:$PATH
export TERM=linux
export HOME=/root
export USER=root
export LOGNAME=root
export UID=0
export SHELL=bash
export FS=ext3
export busybox="/data/data/com.galoula.LinuxInstall/bin/busybox"
export BINDS="1"
unset TMPDIR
fi
createLinuxBoot() {
if $busybox [ -d "$FILESYSTEM" ]
then
echo "I: Directory chroot !"
if $busybox [ ! -z "$($busybox mount | $busybox grep "$MOUNTPOINT/proc")" ]; then
# If the loop device is already mounted, we do nothing.
echo "W: $DIST is already mounted. Entering chroot..."
else
echo "I: Mounting device for $DIST..."
# Bind some Android dirs to the linux filesystem
if $busybox [ $BINDS -eq 1 ]
then
# Create mtab
echo > "${MOUNTPOINT}/etc/mtab"
$busybox cat /proc/mounts > "${MOUNTPOINT}/etc/mtab"
# for i in `$busybox cat /proc/mounts | $busybox cut -d " " -f 2`
for i in $( $busybox cat /proc/mounts | $busybox awk '{print $2}' )
do
$busybox mkdir -p "${MOUNTPOINT}/$i" 2> /dev/null
$busybox mount -o bind "${i}" "${MOUNTPOINT}/${i}" 2> /dev/null
#echo "${i}" >> "${MOUNTPOINT}/etc/mtab"
done
fi
fi
else
if $busybox [ ! -z "$($busybox mount | $busybox grep "$MOUNTPOINT ")" ]; then
# If the loop device is already mounted, we do nothing.
echo "W: $DIST is already mounted. Entering chroot..."
else
echo "I: Mounting device for $DIST..."
if $busybox [ ! -d $MOUNTPOINT ]; then
# Create the mount point if it does not already exist
$busybox mkdir -p $MOUNTPOINT 2> /dev/null
if $busybox [ ! -d $MOUNTPOINT ]; then
echo "F: It was not possible to create the missing mount location ($MOUNTPOINT)"
return 0
fi
fi
if $busybox [ -f "$FILESYSTEM" ]
then
# Android places loop devices in /dev/block/ instead of root /dev/
# If there are none in /dev/ we create links between /dev/loopX and /dev/block/loopX so that losetup will work as it should.
if $busybox [ ! -e /dev/block/loop0 ]; then
i=0
while [ $i -le 8 ]
do
$busybox mknod /dev/block/loop$i b 7 $i
let i=1+$i
done
fi
# Locate the current loop device file
if $busybox [ ! -z "$($busybox losetup | $busybox grep "$FILESYSTEM")" ]; then
# If the filesystem file is already attached to an loop device, we get the path to the device file.
loblk=$($busybox losetup | $busybox grep "$FILESYSTEM" | $busybox cut -d ":" -f 1)
else
# If the filesystem file is not yet attached, we attach it.
loblk=$($busybox losetup -f)
$busybox losetup $loblk $FILESYSTEM 2> /dev/null
# Make sure that the device was successfully attached to a loop device file
if $busybox [ -z "$($busybox losetup | $busybox grep "$FILESYSTEM")" ]; then
echo "F: It was not possible to attach the device to a loop device file"
return 0
fi
fi
fi
if $busybox [ -b "$FILESYSTEM" ]
then
loblk=$FILESYSTEM
fi
# Mount the filesystem
$busybox mount -t $FS $loblk $MOUNTPOINT 2> /dev/null
if $busybox [ ! -z "$($busybox mount | $busybox grep "$MOUNTPOINT ")" ]; then
# Bind some Android dirs to the linux filesystem
if $busybox [ $BINDS -eq 1 ]
then
# Create mtab
echo > "${MOUNTPOINT}/etc/mtab"
$busybox cat /proc/mounts > "${MOUNTPOINT}/etc/mtab"
# for i in `$busybox cat /proc/mounts | $busybox cut -d " " -f 2`
for i in $( $busybox cat /proc/mounts | $busybox awk '{print $2}' )
do
# /sdcard/Mon mount/Linux
$busybox mkdir -p "${MOUNTPOINT}/$i" 2> /dev/null
$busybox mount -o bind "${i}" "${MOUNTPOINT}/${i}" 2> /dev/null
#echo "${i}" >> "${MOUNTPOINT}/etc/mtab"
done
fi
#for i in $BINDS
#do
# # Bind the dirs if they are not already binded
# if $busybox [ -z "$($busybox mount | $busybox grep "$MOUNTPOINT/$i ")" ]; then
# # Create any missing dirs in the mountpoint
# if $busybox [ ! -d $MOUNTPOINT/$i ]; then
# $busybox mkdir -p $MOUNTPOINT/$i
# fi
# $busybox mount -o bind $i $MOUNTPOINT$i
# fi
#done
else
echo "F: It was not possible to mount $DIST at the specified location ($MOUNTPOINT)"
return 0
fi
fi
fi
# FIX the "stdin: is not a tty" error in direct hadware case.
if $busybox [ -z "$($busybox mount | $busybox grep "$MOUNTPOINT/dev/pts ")" ]; then
$busybox mount -t devpts devpts $MOUNTPOINT/dev/pts
fi
# For the network.
#sysctl -w net.ipv4.ip_forward=1
echo 1 > /proc/sys/net/ipv4/ip_forward
# Cleanup tmp folder.
$busybox rm -rf $MOUNTPOINT/tmp/*
if $busybox [ -f $MOUNTPOINT/etc/init.android/rc_mount.sh ]; then
# Execute the mount init file, if it exists
echo "I: Executing /etc/init.android/rc_mount.sh"
$busybox chroot $MOUNTPOINT /etc/init.android/rc_mount.sh
fi
echo "I: Entering chroot..."
return 1
}
removeLinuxBoot() {
if $busybox [ -d "$FILESYSTEM" ]
then
echo "I: Directory chroot !"
# Unmount pts
if $busybox [ ! -z "$($busybox mount | $busybox grep "$MOUNTPOINT/dev/pts ")" ]; then
$busybox umount $MOUNTPOINT/dev/pts 2> /dev/null
fi
for i in $BINDS
do
# Unmount all binding dirs
if $busybox [ ! -z "$($busybox mount | $busybox grep "$MOUNTPOINT/$i ")" ]; then
$busybox umount $MOUNTPOINT/$i
fi
done
for i in `$busybox cat /proc/mounts | $busybox tac | $busybox grep -v "$MOUNTPOINT " | $busybox grep "$MOUNTPOINT" | $busybox cut -d " " -f 2`;do umount $i 2> /dev/null;done
else
if $busybox [ -z "$($busybox mount | $busybox grep "$MOUNTPOINT ")" ]; then
# If linux is not mounted, then do nothing.
echo "W: $DIST is already unmounted"
else
echo "I: Unmounting $DIST..."
if $busybox [ -f $MOUNTPOINT/etc/init.android/rc_unmount.sh ]; then
echo "I: Executing /etc/init.android/rc_unmount.sh"
# Execute the unmount init script, if it exist.
$busybox chroot $MOUNTPOINT /etc/init.android/rc_unmount.sh
fi
sync
# Make sure that we have an loop device file to use
if $busybox [ -f "$FILESYSTEM" ]
then
if $busybox [ ! -z "$($busybox losetup | $busybox grep "$FILESYSTEM")" ]; then
# Get the loop device file
loblk=$($busybox losetup | $busybox grep "$FILESYSTEM" | $busybox cut -d ":" -f 1)
else
echo "E: Could not locate the loop device file. $DIST was not unmounted successfully"
fi
fi
if $busybox [ -b "$FILESYSTEM" ]
then
loblk=$FILESYSTEM
fi
# Unmount pts
if $busybox [ ! -z "$($busybox mount | $busybox grep "$MOUNTPOINT/dev/pts ")" ]; then
$busybox umount $MOUNTPOINT/dev/pts
fi
for i in `$busybox cat /proc/mounts | $busybox tac | $busybox grep -v "$MOUNTPOINT " | $busybox grep "$MOUNTPOINT" | $busybox cut -d " " -f 2`;do umount $i 2> /dev/null;done
for i in $BINDS
do
# Unmount all binding dirs
if $busybox [ ! -z "$($busybox mount | $busybox grep "$MOUNTPOINT/$i ")" ]; then
$busybox umount $MOUNTPOINT/$i
fi
done
sync && sleep 1
# Unmount the device
$busybox umount $MOUNTPOINT 2> /dev/null && sleep 1
# If the device could not be unmounted
if $busybox [ ! -z "$($busybox mount | $busybox grep "$MOUNTPOINT ")" ]; then
echo "E: $DIST could not be unmounted. Trying to kill attached processes..."
# Try to kill all processes holding the device
for i in `$busybox grep "$MOUNTPOINT" /proc/*/maps 2> /dev/null | $busybox cut -d":" -f 1 | $busybox sort | $busybox uniq | $busybox cut -d "/" -f 3`; do kill $i 2> /dev/null; echo; done
fuser -k -9 $MOUNTPOINT
for i in `$busybox grep "$MOUNTPOINT" /proc/*/maps 2> /dev/null | $busybox cut -d":" -f 1 | $busybox sort | $busybox uniq | $busybox cut -d "/" -f 3`; do kill -9 $i 2> /dev/null; echo; done
# Use umount with the -l option to take care of the rest
$busybox umount -l $MOUNTPOINT 2> /dev/null && sleep 1
fi
# Make sure the device has been successfully unmounted
if $busybox [ -z "$($busybox mount | $busybox grep "$MOUNTPOINT ")" ]; then
if $busybox [ -f "$FILESYSTEM" ]
then
# Try to detach the device from the loop device file
$busybox losetup -d $loblk 2> /dev/null
# Make sure that the device was successfully detached
if $busybox [ -z "$($busybox losetup | $busybox grep "$FILESYSTEM")" ]; then
echo "I: $DIST has been successfully unmounted"
else
echo "E: $DIST has been unmounted, but could not detach the loop device"
fi
fi
if $busybox [ -b "$FILESYSTEM" ]
then
if $busybox [ -z "$($busybox mount | $busybox grep "$MOUNTPOINT ")" ]; then
echo "I: $DIST has been successfully unmounted"
else
echo "E: $DIST has been unmounted, but could not detach the loop device"
fi
fi
else
echo "E: $DIST could not be unmounted successfully"
fi
fi
fi
}
if $busybox [ "$1" = "unmount" ]; then
removeLinuxBoot
else
createLinuxBoot
if $busybox [ $? -eq 1 ]; then
if $busybox [ -f $MOUNTPOINT/etc/init.android/rc_enter.sh ]; then
echo "I: Executing /etc/init.android/rc_enter.sh"
$busybox chroot $MOUNTPOINT /etc/init.android/rc_enter.sh
else
echo "I: To run command when enterring Linux create executable file at /etc/init.android/rc_enter.sh"
fi
$busybox chroot $MOUNTPOINT /bin/bash -i
if $busybox [ -f $MOUNTPOINT/etc/init.android/rc_leave.sh ]; then
echo "I: Executing /etc/init.android/rc_leave.sh ..."
$busybox chroot $MOUNTPOINT /etc/init.android/rc_leave.sh
else
echo "I: To run command when leaving Linux create executable file at /etc/init.android/rc_leave.sh"
fi
echo "Q: Do you want to unmount the $DIST environment, or leave it as is ? Y will kill all process as required; any other key will leave services running."
read REPLY
if $busybox [ "y$REPLY" = "yy" ] || $busybox [ "y$REPLY" = "yY" ]; then
removeLinuxBoot
fi
fi
fi
)
or you can mount it with this linuxboot.sh:
Code:
# Check Permissions
if [ $(whoami) != root ]; then
echo "This script must be run as root."
exit
fi
# Script Variables
NAME=ubuntu
PATH=$(dirname $0)
# Enviroment Variables
export BIN=/system/bin
export HOME=/root
export MOUNT=/data/local/mnt/$NAME
export PATH=$BIN:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin
export TERM=linux
export USER=root
# Change Directory
cd $PATH
# Create Mount Point
mkdir -p $MOUNT
# Remount System Read/Write
mount -o remount,rw /system
# Check Loop Block Device
if [ ! -b /dev/block/loop_$NAME ]; then
# Create Loop Block Device
mknod /dev/block/loop_$NAME b 7 255
fi
# Setup Loop Block Device
losetup /dev/block/loop_$NAME $NAME.img
# Mount Loop Block Device To Mount Point
mount -t ext3 /dev/block/loop_$NAME $MOUNT
# Add Mount Points
mount -o bind /dev $MOUNT/dev
mount -o bind /dev/pts $MOUNT/dev/pts
mount -o bind /dev/shm $MOUNT/dev/shm
mount -o bind /sdcard $MOUNT/media
mount -t proc none $MOUNT/proc
mount -t sysfs none $MOUNT/sys
# Set Options
echo "127.0.0.1 localhost" > $MOUNT/etc/hosts
echo "nameserver 8.8.4.4" > $MOUNT/etc/resolv.conf
echo "nameserver 8.8.8.8" >> $MOUNT/etc/resolv.conf
rm -rf $MOUNT/lost+found
sysctl -w net.ipv4.ip_forward=1 > /dev/null
sysctl -w net.ipv6.conf.all.forwarding=1 > /dev/null
# Enter Linux
chroot $MOUNT /bin/bash -c "source /etc/profile; bash"
# Remove Mount Points
umount $MOUNT/sys
umount $MOUNT/proc
umount $MOUNT/media
umount $MOUNT/dev/shm
umount $MOUNT/dev/pts
umount $MOUNT/dev
# Clean Up
umount $MOUNT
losetup -d /dev/block/loop_$NAME
rm /dev/block/loop_$NAME
rmdir $MOUNT
this is not the init.sh.
the init.sh is iniside the ubuntu.img so to boot using the init.sh you can edit the rc_enter.sh to start init.sh like so:
./init.sh
you can also start a service like so:
service hostname start

[Q] How to use string array in init.d script?

I want to make app symlinks to sd-ext on booting.
I made a short init.d script, And It correctly worked on JB based rom.
But after I downgraded to GB, It doesn't work anymore.
I founded that pure bone shell doesn't support arrays.
The script uses string array to declare apk list I want to symlink.
So is there a way to use string array or make similar effect?
Here is my script.
Code:
#!/system/bin/sh
if [ -z "$SD_EXT_DIRECTORY" ]; then SD_EXT_DIRECTORY=/sd-ext; fi
SYSBLOCK=`mount | grep system | cut -f 1 -d ' '`
sysapp2sd=("BackupRestoreConfirmation.apk" "BasicDreams.apk" "Bluetooth.apk" "CertInstaller.apk" "Calculator.apk" "CMFileManager.apk" "CMScreenshot.apk" "DSPManager.apk" "DrmProvider.apk" "Email.apk" "Email2.apk" "Exchange.apk" "Exchange2.apk" "Gmail.apk" "GoogleBackupTransport.apk" "InputDevices.apk" "Music.apk" "OneTimeInitializer.apk" "PhotoTable.apk" "PicoTts.apk" "SamsungTTS.apk" "SharedStorageBackup.apk" "SoundRecorder.apk" "Talk.apk" "ThemeChooser.apk" "ThemeManager.apk" "Torch.apk" "VpnDialogs.apk" "WAPPushManager.apk")
app2sd_exception=("com.UCMobile" "com.adobe.flashplayer" "com.android.lmt" "com.fiberthemax.OpQ2keyboard" "com.fiberthemax.OpQ2keyboard.dict.ko" "com.google.android.gms" "com.google.android.googlequicksearchbox" "com.jungsup.thecall" "com.mobint.hololauncher" "com.mobint.hololauncherplus" "com.mobitobi.android.gentlealarm" "com.myhome.mytheme" "com.rs.autorun" "com.teslacoilsw.launcher" "com.vladlee.callconfirm.free" "eu.chainfire.supersu" "kz.mek.DialerOne" "me.dennis.weather.naver" "net.dinglisch.android.taskerm" "net.everythingandroid.smspopup" )
# make sure $SD_EXT_DIRECTORY is actually mounted
if ! awk -vDIR="$SD_EXT_DIRECTORY" '$2 == DIR { exit 1; }' /proc/mounts ; then
mount -rw -o remount SYSBLOCK /system
mkdir -p /sd-ext/symlink/system/app
# /system/app/ -> /sd-ext/symlink/system/app/
FILES=`find /system/app -maxdepth 1 -type f`
for file in $FILES; do
filename=`basename $file`
for pattern in ${sysapp2sd[@]}; do
if [[ $filename == $pattern ]]; then
cp /system/app/$filename /sd-ext/symlink/system/app/
rm -f /system/app/$filename
ln -s /sd-ext/symlink/system/app/$filename /system/app/$filename
fi
done
done
# /data/app/ -> /sd-ext/symlink/data/app/
FILES=`find /data/app -maxdepth 1 -type f`
for file in $FILES; do
filename=`basename $file`
match=false
for pattern in ${app2sd_exception[@]}; do
if [[ $filename == $pattern* ]]; then
match=true
fi
done
if ! $match; then
cp /data/app/$filename /sd-ext/symlink/data/app/
rm -f /data/app/$filename
ln -s /sd-ext/symlink/data/app/$filename /data/app/$filename
fi
done
mount -r -o remount SYSBLOCK /system
fi
You can use echo or cat command to wrap list and grab it with awk.
and add another for loop over for loop for getting the counted numbers to be used on awk...

[Q] How to reenable an App symlinked to SD "not installed" after reboot

Hi all,
I have a ZP980 rooted running android 4.2.1 that has 1.5GB for app storage and another partition of 26GB in the internal memory mounted as /sdcard used for data.
I wanted to use the big partition to store apps too and since none of the app I tried worked to move some apps to the fake SD I tried to do a script on my own.
PROBLEM:
The script works good but the problem is that if I reboot the phone all files and symlinks are still there but the app is "not installed" so I can't lunch it, I think android makes a scan on boot and maybe /sdcard is not available at that time.
TEMPORARY SOLUTION:
The only way to make it work again is to move the apk back to /data/app and reboot, or remove the symlink and use:
# pm install -r PACKAGE
WHAT I TRIED:
#pm enable PACKAGE
but it looks like it's not disabled that way
WHAT I'D LIKE TO HAVE:
I'd like to find a way to reenable the PACKAGE without having to reinstall it, any clue where android memorize that the app is "installed" or a command to do only that tiny bit and not the whole install process?
SCRIPT (for who interested)
Code:
#!/system/bin/sh
sdcard="/storage/sdcard0/Apps"
internal="/data"
data="/data/data"
package="$2"
usage()
{
echo "Usage: $0 [OPTION] [PACKAGE]"
echo
echo "This script copy app and dalvik cache from internal memory to sd and back creating a symlink."
echo
echo "OPTIONS:"
echo " -a Move app and dalvik cache to sd"
echo " -b Move app and dalvik cache back to internal memory"
echo " -r Restore apps after reboot"
echo
echo "PACKAGE"
echo " without .apk"
echo " ES. to move candycrush to sd:"
echo " mv2sd -a com.king.candycrushsaga"
}
function setperm
{
local file=$1
case $type in
"app")
group="system"
;;
"dalvik-cache")
local group=$(ls -ld $data/$package | awk '{print $4}')
;;
esac
chown system:$group $file
chmod 644 $file
}
function mvfile
{
local fileFrom=$1
local fileTo=$2
if [ "$back" -eq 1 ]; then
rm -f $fileTo
local destination="data"
else
local destination="sd"
fi
cp -a $fileFrom $fileTo
if [ $? -ne 0 ]; then
exit $?
else
echo "$package $type moved to $destination"
rm -f $fileFrom
if [ $back -eq 0 ]; then
ln -s $fileTo $fileFrom
else
setperm $fileTo
fi
fi
}
function mvfiles
{
type=$1
case $type in
"app")
local uri="$type/$filename"
;;
"dalvik-cache")
local uri="$type/[email protected]@[email protected]"
;;
esac
intFile="$internal/$uri"
sdFile="$sdcard/$uri"
if [ "$back" -eq 0 ] && [ -f "$intFile" ]; then
mvfile $intFile $sdFile
elif [ "$back" -eq 1 ] && [ -L "$intFile" ] && [ -f "$sdFile" ]; then
mvfile $sdFile $intFile
else
echo "$type file or symlink not found"
fi
}
#initialize
back=2
restore=0
while getopts "abrh" option
do
case $option in
a)
back=0;
;;
b)
back=1;
;;
r)
restore=1;
;;
h)
usage
exit
;;
esac
done
if [ "$back" -eq "2" ] && [ "$restore" -eq "0" ]; then
usage
exit 1
fi
#restore
if [ "$restore" -eq "1" ]; then
for file in $sdcard/app/*.apk
do
filename=$(basename "$file")
intFile="$internal/app/$filename"
sdFile="$sdcard/app/$filename"
intDalvik="$internal/dalvik-cache/[email protected]@[email protected]"
sdDalvik="$sdcard/dalvik-cache/[email protected]@[email protected]"
package="${filename%-*}"
if [ -L "$intFile" ] && [ -f "$sdFile" ] && [ -L "$intDalvik" ] && [ -f "$sdDalvik" ]; then
rm -f $intFile
rm -f $intDalvik
rm -f $sdDalvik
pm install -r $sdFile
rm -f $sdFile
mv2sd -a $package
fi
done
else
file=$(ls $internal/app/$package-*)
filename=$(basename "$file")
#move app
mvfiles "app"
mvfiles "dalvik-cache"
fi
shift $(($OPTIND -1))
I found something, thanks to this nice article:
http://www.kpbird.com/2012/10/in-depth-android-package-manager-and.html
So I tried to reboot and I see that in /data/system/packages.xml all apps I symlinked have flags="0"
Before:
<package name="com.king.candycrushsaga" codePath="/data/app/com.king.candycrushsaga-1.apk" nativeLibraryPath="/data/app-lib/com.king.candycrushsaga-1" flags="572996" ft="1435aa87ca0" it="140f50e81fe" ut="14303810da6" version="102212" userId="10084">
Click to expand...
Click to collapse
After:
<package name="com.king.candycrushsaga" codePath="/data/app/com.king.candycrushsaga-1.apk" nativeLibraryPath="/data/app-lib/com.king.candycrushsaga-1" flags="0" ft="1435aa87ca0" it="140f50e81fe" ut="14303810da6" version="102212" userId="10084">
Click to expand...
Click to collapse
Changing that value on runtime doesn't work.
I'm still looking how to change it maybe PackageManagerService.grantPermissionsLP()
https://android.googlesource.com/pl.../android/server/pm/PackageManagerService.java
At the end I solved the problem.
I'm not sure why but if an app is symlinked to anything on sdcard is disabled at start, but if it's symlinked on another folder on /data or /system it keeps working after reboot.
So first I tried to symlink /data/sdcard => /sdcard but it's not working because it can still see the final destination is the sdcard, so I mounted the sdcard on /data/sdcard and symlink /data/app/some.app-1.apk => /data/sdcard/app/some.app-1.apk and it's working
sdcard need to be mounted on start inside an init.d script so it's available when the scan happens.
Moving forward I decided to create an ext2 filesystem in a file, keep it in my sdcard partition and mount it on /data/sdcard.
This way, with a modified and improved version of my script I can move apks, libs, dalvik-cache and all the data folder for each app I want keeping the right file permissions

Categories

Resources