-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.bash_functions.sailfishos
118 lines (111 loc) · 3.8 KB
/
.bash_functions.sailfishos
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# vim: ft=bash noet:
! declare 2>&1 | grep -wq ^colors= && [ $BASH_VERSINFO -ge 4 ] && source $initDir/.colors
test "$debug" -gt 0 && echo "=> Running $bold${colors[blue]}$(basename ${BASH_SOURCE[0]})$normal ..."
function androidCodeName {
( [ $# -ge 2 ] || echo $1 | egrep -q -- "^--?(h|u)" ) && echo "=> Usage : $FUNCNAME [androidRelease]" 1>&2 && return 1
local androidRelease=unknown
local androidCodeName=unknown
if echo $1 | egrep -q "[0-9.]+"; then
androidRelease=$1
androidCodeName="REL" # Do not use "androidCodeName" when it equals to "REL" but infer it from "androidRelease"
elif [ -n "$(getprop ro.build.version.release 2>/dev/null)" ]; then
androidRelease=$(getprop ro.build.version.release)
androidCodeName=$(getprop ro.build.version.codename)
else
echo "=> [$FUNCNAME] ERROR: Could not detect android release on this device" >&2
return 2
fi
# Time "androidRelease" x10 to test it as an integer
case $androidRelease in
[0-9].[0-9]|[0-9].[0-9].|[0-9].[0-9].[0-9]) androidRelease=$(echo $androidRelease | cut -d. -f1-2 | tr -d .);;
[0-9].) androidRelease=$(echo $androidRelease | sed 's/\./0/');;
[0-9]) androidRelease+="0";;
esac
[ -n "$androidRelease" ] && [ $androidCodeName = REL ] && {
# Do not use "androidCodeName" when it equals to "REL" but infer it from "androidRelease"
androidCodeName="${colors[blue]}"
case $androidRelease in
10) androidCodeName+=NoCodename;;
11) androidCodeName+="Petit Four";;
15) androidCodeName+=Cupcake;;
20|21) androidCodeName+=Eclair;;
22) androidCodeName+=FroYo;;
23) androidCodeName+=Gingerbread;;
30|31|32) androidCodeName+=Honeycomb;;
40) androidCodeName+="Ice Cream Sandwich";;
41|42|43) androidCodeName+="Jelly Bean";;
44) androidCodeName+=KitKat;;
50|51) androidCodeName+=Lollipop;;
60) androidCodeName+=Marshmallow;;
70|71) androidCodeName+=Nougat;;
80|81) androidCodeName+=Oreo;;
90) androidCodeName+=Pie;;
100) androidCodeName+=ToBeReleased;;
*) androidCodeName=${colors[red]}unknown;;
esac
}
echo $androidCodeName$normal
}
function rebalance {
type -P btrfs-balancer >/dev/null && {
df /
echo
set -x
sudo systemctl stop aliendalvik.service
set +x
for i in $(seq 5)
do
printf "=> Balancing #%2d\n" $i
set -x
sudo btrfs-balancer allocation
set -x
echo
time sudo btrfs-balancer balance || break
echo
sync
sleep 3
set -x
sudo btrfs-balancer allocation
set +x
done
echo
df /
set -x
sudo systemctl start aliendalvik.service
set +x
}
}
function sailFishOSUpgrade {
test $1 && {
local currentRelease=$(version | awk '{print$2}')
local nextRelease=$1
local logFile=~/log/sailFishOSUpgrade_${currentRelease}_upto_$nextRelease.log
mkdir -p ~/log
if [ $nextRelease = $currentRelease ]; then
echo "=> The current release is already $currentRelease." >&2
return 2
else
echo "=> Disabling the openrepos repositories ..." >&2
ssu repos | awk '/openrepos/{print $2}' | \xargs -rtl ssu disablerepo
echo "=> DONE." >&2
set -x
ssu status
ssu release
version --dup
version --verify
fi 2>&1 | tee -a $logFile
set +x
return 0
} || {
echo "=> Usage: $FUNCNAME nextRelease" >&2
return 1
}
}
function topf {
command find . $findPrunePathsExpression -xdev -type f -size +10240k -exec ls -l --block-size=M --time-style=+"%Y-%m-%d %T" {} \; 2>/dev/null | sort -nrk5 | column -t | head -n "$1" | awk '{total+=$5;print}END{if(total) print"=> total = "total" MiB"}'
}
function topflines {
command find "$@" $findPrunePathsExpression -xdev -type f -size +10240k -exec ls -l --block-size=M --time-style=+"%Y-%m-%d %T" {} \; 2>/dev/null | sort -nrk5 | column -t | head -n $(($LINES-4)) | awk '{total+=$5;print}END{if(total) print"=> total = "total" MiB"}'
}
set +x
test "$debug" -gt 0 && echo "=> END of $bold${colors[blue]}$(basename ${BASH_SOURCE[0]})$normal"