-
Notifications
You must be signed in to change notification settings - Fork 0
/
andlib
34 lines (29 loc) · 2.56 KB
/
andlib
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/bin/sh
_copyright(){ echo "
ozh lightweight shell extensions
2008-2016 - anx @ ulzq de (Sebastian Glaser)
Licensed under GNU GPL v3"; }
_license(){ echo "
ozh 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 2, or (at your option)
any later version.
ozh 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 this software; see the file COPYING. If not, write to
the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
Boston, MA 02111-1307 USA
http://www.gnu.org/licenses/gpl.html"; }
## androlib - 0003
test -f /bin/sh && _shebang(){ echo "#!/bin/sh"; }
test -f /system/bin/sh && _shebang(){ echo "#!/system/bin/sh"; }
is_gzip(){ test "$(uhd_range $1 0 2)" = "1f8b"; }
is_bootimg(){ test "$(head -c 8 "$1")" = "ANDROID!"; }
sysrw(){ mount -o remount,rw /$1; }
sysro(){ mount -o remount,ro /$1; }
lofree(){ IMAGE="$1"; B=busybox; L="$B losetup"; if [ -n "($L -f)" ]; then $L -f | busybox grep -o '[0-9]\{1,3\}'; return 0; fi; if $L | busybox grep "$IMAGE" >/dev/null 2>&1;then ID=$($L | busybox grep "$IMAGE" | cut -d: -f1 | cut -dp -f2 | tail -n 1); $L -d /dev/block/loop$ID; else LAST=$($L | cut -d: -f1 | cut -dp -f2 | tail -n 1); ID=$(( $LAST + 1 )); fi; echo $ID; }
lomount(){ IMAGE="$1"; MOUNT="$2"; MODE="$3"; test -z "$IMAGE" -o -z "$MOUNT" -o ! -f "$IMAGE" -o ! -d "$MOUNT" && { echo 'USAGE: lomount $IMAGE $MOUNTDIR [rw|ro]'; test -f "$IMAGE" || echo "IMAGE: '$IMAGE' [\x1b[33mdoes not exist\x1b[0m]"; test -d "$MOUNT" || echo "MOUNTDIR: '$MOUNT' [\x1b[33mdoes not exist\x1b[0m]"; return 1; }; B=busybox; L="$B losetup"; M="$B mount"; ID=$(lofree $IMAGE); LOOP="/dev/block/loop$ID"; test -z "$MODE" || MODE=rw; test -e "$LOOP" || mknod "$LOOP" b 7 $ID || { echo "\x1b[31mError\x1b[0m: $LOOP can't be created!"; return 2; }; $L "$LOOP" "$IMAGE" || { echo "\x1b[31mError\x1b[0m: $IMAGE can't be bound to $LOOP!"; return 2; }; $M -o rw,relatime,data=ordered "$LOOP" "$MOUNT" || { echo "\x1b[31mError\x1b[0m: $IMAGE can't be mounted to $MOUNT!"; return 3; }; return 0; }
homeof(){ local dir=; which getent >/dev/null 2>&1 && dir=$(getent passwd "$1" 2>/dev/null | cut -d: -f6); [ -z "$dir" -a "$1" = "root" -a -d /root ] && dir="/root"; [ -z "$dir" -a -d "/home/$1" ] && dir="/home/$1"; echo $dir; }