]> git.saurik.com Git - cydia.git/blob - Library/firmware.sh
For progress JS on iOS 10 to solve race and flash.
[cydia.git] / Library / firmware.sh
1 #!/bin/bash
2
3 set -e
4
5 shopt -s extglob
6 shopt -s nullglob
7
8 version=$(sw_vers -productVersion)
9 cpu=$(uname -p)
10
11 if [[ ${cpu} == arm || ${cpu} == arm64 ]]; then
12 data=/var/lib/dpkg
13 model=hw.machine
14 arch=iphoneos-arm
15 else
16 data=/Library/Cydia/dpkg
17 model=hw.model
18 arch=cydia
19 fi
20
21 model=$(sysctl -n "${model}")
22
23 status=${data}/status
24
25 function lower() {
26 sed -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'
27 }
28
29 # Generate New Package {{{
30 function pseudo() {
31 local package=$1 version=$2 description=$3 name=$4
32 echo "/." >"${data}"/info/"${package}".list
33
34 cat <<EOF
35 Package: ${package}
36 Essential: yes
37 Status: install ok installed
38 Priority: required
39 Section: System
40 Installed-Size: 0
41 Architecture: ${arch}
42 Version: ${version}
43 Description: ${description}
44 Maintainer: Jay Freeman (saurik) <saurik@saurik.com>
45 Tag: role::cydia
46 EOF
47
48 [[ -n ${name} ]] && echo "Name: ${name}"
49 echo
50 }
51 # }}}
52
53 before=$(stat -c '%i-%Y' status)
54
55 output=$(mktemp status-tmp.XXXXXX)
56 xxxxxx=${output##status-tmp.}
57 rm -f status-tmp.!("${xxxxxx}")
58
59 {
60
61 # Delete Old Packages {{{
62 unset firmware
63 unset blank
64
65 while IFS= read -r line; do
66 #echo "#${firmware+@}/${blank+@} ${line}" 1>&2
67
68 if [[ ${line} == '' && "${blank+@}" ]]; then
69 continue
70 else
71 unset blank
72 fi
73
74 if [[ ${line} == "Package: "@(firmware|gsc.*|cy+*) ]]; then
75 firmware=
76 elif [[ ${line} == '' ]]; then
77 blank=
78 fi
79
80 if [[ "${firmware+@}" ]]; then
81 if [[ "${blank+@}" ]]; then
82 unset firmware
83 fi
84 continue
85 fi
86
87 #echo "${firmware+@}/${blank+@} ${line}" 1>&2
88 echo "${line}"
89 done <"${status}"
90
91 #echo "#${firmware+@}/${blank+@} EOF" 1>&2
92 if ! [[ "${blank+@}" || "${firmware+@}" ]]; then
93 echo
94 fi
95 # }}}
96
97 if [[ ${cpu} == arm || ${cpu} == arm64 ]]; then
98 pseudo "firmware" "${version}" "almost impressive Apple frameworks" "iOS Firmware"
99
100 while [[ 1 ]]; do
101 gssc=$(gssc 2>&1)
102 if [[ ${gssc} != *'(null)'* ]]; then
103 break
104 fi
105 sleep 1
106 done
107
108 echo "${gssc}" | sed -re '
109 /^ [^ ]* = [0-9.]*;$/ ! d;
110 s/^ ([^ ]*) = ([0-9.]*);$/\1 \2/;
111 s/([A-Z])/-\L\1/g;
112 s/^"([^ ]*)"/\1/;
113 s/^-//;
114 / 0$/ d;
115 ' | while read -r name value; do case "${name}" in
116 (ipad) for name in ipad wildcat; do
117 pseudo "gsc.${name}" "${value}" "this device has a very large screen" "iPad"
118 done;;
119
120 (*)
121 pseudo "gsc.${name}" "${value}" "virtual GraphicsServices dependency"
122 ;;
123 esac; done
124 fi
125
126 if [[ ${cpu} == arm || ${cpu} == arm64 ]]; then
127 os=ios
128 else
129 os=macosx
130 fi
131
132 pseudo "cy+os.${os}" "${version}" "virtual operating system dependency"
133 pseudo "cy+cpu.${cpu}" "0" "virtual CPU dependency"
134
135 name=${model%%*([0-9]),*([0-9])}
136 version=${model#${name}}
137 name=$(lower <<<${name})
138 version=${version/,/.}
139 pseudo "cy+model.${name}" "${version}" "virtual model dependency"
140
141 pseudo "cy+kernel.$(lower <<<$(sysctl -n kern.ostype))" "$(sysctl -n kern.osrelease)" "virtual kernel dependency"
142
143 pseudo "cy+lib.corefoundation" "$(/usr/libexec/cydia/cfversion)" "virtual corefoundation dependency"
144
145 } >"${output}"
146
147 # XXX: this is a poor replacement for flock
148 test "${before}" = "$(stat -c '%i-%Y' status)"
149 mv -f "${output}" "${status}"
150
151 if [[ ${cpu} == arm || ${cpu} == arm64 ]]; then
152 if [[ ! -h /User && -d /User ]]; then
153 cp -afT /User /var/mobile
154 fi && rm -rf /User && ln -s "/var/mobile" /User
155
156 echo 6 >/var/lib/cydia/firmware.ver
157 fi