aboutsummaryrefslogtreecommitdiff
path: root/rootdir/system/vendor/bin/credmgrfirstboot.sh
blob: 3b3ade9f39953ef1aa2e340fe91e345b5920e0b4 (plain)
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
#!/system/vendor/bin/sh
CREDFOLDER=/data/credmgr
LOG=/cache/credmgr.log

# start new log file
echo -e "\n*********************************\n$(date) - $0 started" > $LOG

# simple error function writing to kernel buffer and logfile
F_ERR(){
    ERR="$1"
    MSG="$2"
    if [ $ERR -ne 0 ];then
        echo "CREDINIT: $MSG failed!" >> $LOG
        exit $ERR
    else
	echo "CREDINIT: $MSG finished successfully" >> $LOG
    fi
}

# If credmgrd data doesn't match our
CREDMGRCNT=$(find $CREDFOLDER -group system -type f -name "credmgr.db" | wc -l )

echo -e "credmgr folder:\n$(ls -la $CREDFOLDER)\ncredmgr match (if any):" >> $LOG
find $CREDFOLDER -group system -type f -name "credmgr.db" >> $LOG


if [ "x$CREDMGRCNT" == "x0" ]; then
	# If /data/credmgr exist remove it
	echo "CREDINIT: Dont match"
	if [ -d "$CREDFOLDER" ]; then
		echo "CREDINIT: Drop old credmgrdata"
		mv -vf $CREDFOLDER ${CREDFOLDER}.$(date +"%Y-%m-%d")  >> $LOG 2>&1
	fi
	# Put binary into /cache
	mkdir $CREDFOLDER >> $LOG 2>&1
	F_ERR $? "mkdir $CREDFOLDER"
	# Set perms on folder
	chown system:system $CREDFOLDER >> $LOG 2>&1
	F_ERR $? "chown $CREDFOLDER"
	chmod 770 $CREDFOLDER >> $LOG 2>&1
	F_ERR $? "chmod 770"
	chcon u:object_r:credmgrd_data_file:s0 $CREDFOLDER >> $LOG 2>&1
	F_ERR $? "chcon $CREDFOLDER"
	echo "CREDINIT: cp initial file" >> $LOG 2>&1
	cp -v /system/vendor/CredentialManagerData /cache/CredentialManagerData >> $LOG 2>&1
	F_ERR $? "copy CredentialManagerData"
	chown system:system /cache/CredentialManagerData >> $LOG 2>&1
	F_ERR $? "chown CredentialManagerData"
else
	F_ERR 0 "credmgr found already. no preparation required."
fi

# Tell init we are ready
setprop sys.credmgrdready true
F_ERR $? "setting property"