-
-
Save dkw72n/18342594b9f76c5234ca to your computer and use it in GitHub Desktop.
an auxiliary android shell script that keeps your Apps "staying" on your SD card after an update
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/system/bin/sh | |
# What is this? | |
# PSD (Pin to the SD card), is an auxiliary script that keeps your Apps "staying" on your SD card. | |
# "staying" is quoted because what it actually do is moving your app back to the SD card again after an update. | |
# Why? | |
# a. Since Android Lollipop, the apps you moved to the SD card will back to internal storage after an update. | |
# b. My phone has a small internal storage and running Android Lollipop. | |
# c. I am not going to buy another phone or downgrade to Kitkat. | |
# d. The internal storage can't hold all my apps. | |
# combination of a,b,c,d,e is the reason why. | |
# How to use? | |
# I just mention one way to use, my way. There are many other ways out there for it is just a shell script. | |
# What you need: the "terminal" app, that's it. | |
# Let me assume you put your script at /sdcard/psd | |
# 0x0. | |
# you have to move your apps to the SD card manually the very first time. | |
# 0x1. (backup) | |
# run the command below in Terminal. | |
# # sh /sdcard/psd d | |
# this creates a file that contains all names of which need to be moved. | |
# consider it a screenshot. | |
# 0x2. (restore) | |
# run the command below in Terminal. | |
# # sh /sdcard/psd l | |
# move the apps to the sdcard according to the file that 0x1 creates | |
# 0x3. | |
# it is up to you when to backup and restore | |
# | |
# !!!!!!!!!!!!!!!!!!!!! IMPORTANT !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | |
# This script is tested ONLY on my phone, use at your own risk. | |
# | |
# See Copyright Notice at the end of this file | |
# the file that contains all your apps on the sdcard | |
db=/sdcard/psd_db | |
psddump(){ | |
echo "[*] dumping..." | |
# do a backup, just in case | |
mv "$db" "$db.old" | |
touch "$db" || echo "[!] failed to create db" | |
test -f "$db" || exit 1 | |
# for all apps: | |
for i in $(pm list packages) | |
do | |
#check if it is on the sdcard | |
pm path ${i:8}|grep mnt >/dev/null || continue | |
echo "[*] adding ${i:8} ..." | |
echo ${i:8} >> "$db" | |
done | |
echo "[*] finished" | |
exit 0 | |
} | |
psdload(){ | |
echo "[*] loading" | |
# make sure we can read | |
cat "$db" 2>&1 >/dev/null || exit 1 | |
# for each app listed in the file: | |
for p in $(cat "$db") | |
do | |
# get the app's path if it is not already on the sdcard | |
pkgpath=$(pm path $p|grep -v mnt) | |
# cannot get the path , could be uninstalled or unnecessary to be moved | |
# simply skip for either reason | |
test -z "$pkgpath" && continue | |
echo "[*] moving $p to sdcard..." | |
pm install -rs -i "$p" "${pkgpath:8}" > /dev/null | |
done | |
echo "[*] finished" | |
} | |
case "$1" in | |
d) | |
psddump | |
;; | |
l) | |
psdload | |
;; | |
*) | |
echo "Move your apps back to the sdcard after update." | |
echo "usage: " | |
echo " $0 l : move the apps back according to the dump file" | |
echo " $0 d : dump all your now-on-sdcard apps to file(so that we know what to be move back)" | |
esac | |
# Copyright (c) 2016 dkw72n | |
# Permission is hereby granted, free of charge, to any person obtaining a copy | |
# of this software and associated documentation files (the "Software"), to deal | |
# in the Software without restriction, including without limitation the rights | |
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
# copies of the Software, and to permit persons to whom the Software is | |
# furnished to do so, subject to the following conditions: | |
# The above copyright notice and this permission notice shall be included in all | |
# copies or substantial portions of the Software. | |
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | |
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | |
# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR | |
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE | |
# OR OTHER DEALINGS IN THE SOFTWARE. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment