forked from rendiix/rendiix.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfix-dpkg-perm.sh
85 lines (76 loc) · 2.18 KB
/
fix-dpkg-perm.sh
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/data/data/com.termux/files/usr/bin/bash
# File : fix-dpkg-perm.sh
# Author : rendiix <[email protected]>
# Create date: 6-Jul-2019 19:00
# fix-dpkg-perm.sh
# Copyright (c) 2019 rendiix <[email protected]>
#
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
# Version 2, December 2004
#
# Everyone is permitted to copy and distribute verbatim or
# modified copies of this license document,and changing it
# is allowed as long as the name is changed.
#
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
# TERMS AND CONDITIONS FOR COPYING,
# DISTRIBUTION AND MODIFICATION
#
# 0. You just DO WHAT THE FUCK YOU WANT TO.
unset LD_PRELOAD
if [ -z "$1" ]; then
echo -e "Usage: $0 [file or dir]"
exit 1
fi
USER=$(whoami)
USER_INPUT="$1"
INPUT=$(realpath $USER_INPUT)
NO='\033[00m';ME='\033[31m';HI='\033[32m';KU='\033[33m'BI='\033[34m';CY='\033[36m';PU='\033[37m'
MET='\033[01;31m';HIT='\033[01;32m';KUT='\033[01;33m';BIT='\033[01;34m';CYT='\033[01;36m';PUT='\033[01;37m';MGT='\033[01;35m'
function checkstorage() {
ls $HOME/storage/shared > /dev/null 2>&1
}
function check_prerequisite() {
echo -e "checking weather termux has storage-permissions...\c"
while checkstorage; [ $? -ne 0 ];do
echo -e "${ME} no${NO}\nplease grant permission to acces storage?"
termux-setup-storage
done
sleep 1
echo -e "${HI} yes${NO}"
echo -e "checking weather tsu is installed...\c"
if [ -z $(which tsu) ]; then
echo -e "${ME} no${NO}\n\tinstalling tsu..\c"
apt-get install tsu -y > /dev/null 2>&1
echo -e "${ME} done${NO}"
else
echo -e "${HI} yes${NO}"
fi
echo -e "checking weather restorecon is present on your devive...\c"
if [ -x "/system/bin/restorecon" ]; then
echo -e "${HI} yes${NO}"
TYPE_FIX=1
else
echo -e "${ME} no${NO}"
fi
}
function resetviabackup() {
TMPDIR=${HOME}/storage/shared/script/backup
mkdir -p $TMPDIR
cp -r $INPUT $TMPDIR/
tsu -c rm -rf $INPUT
cp -r $TMPDIR/* $INPUT
rm -rf $TMPDIR
echo "done"
}
function viarestorecon() {
tsu -c chown -R $USER:$USER $INPUT
tsu -c /system/bin/restorecon -DRFv $INPUT
}
check_prerequisitei
INPUT=$(realpath $USER_INPUT)
if [ "$TYPE_FIX" = "1" ]; then
viarestorecon;
else
resetviabackup;
fi