]> git.saurik.com Git - cydia.git/blob - Library/firmware.sh
Cytore values need to be _packed (I got lucky :D).
[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 Tag: role::cydia
45 EOF
46
47 [[ -n ${name} ]] && echo "Name: ${name}"
48 echo
49 }
50 # }}}
51
52 before=$(stat -c '%i-%Y' status)
53
54 output=$(mktemp status-tmp.XXXXXX)
55 xxxxxx=${output##status-tmp.}
56 rm -f status-tmp.!("${xxxxxx}")
57
58 {
59
60 # Delete Old Packages {{{
61 unset firmware
62 unset blank
63
64 while IFS= read -r line; do
65 #echo "#${firmware+@}/${blank+@} ${line}" 1>&2
66
67 if [[ ${line} == '' && "${blank+@}" ]]; then
68 continue
69 else
70 unset blank
71 fi
72
73 if [[ ${line} == "Package: "@(firmware|gsc.*|cy+*) ]]; then
74 firmware=
75 elif [[ ${line} == '' ]]; then
76 blank=
77 fi
78
79 if [[ "${firmware+@}" ]]; then
80 if [[ "${blank+@}" ]]; then
81 unset firmware
82 fi
83 continue
84 fi
85
86 #echo "${firmware+@}/${blank+@} ${line}" 1>&2
87 echo "${line}"
88 done <"${status}"
89
90 #echo "#${firmware+@}/${blank+@} EOF" 1>&2
91 if ! [[ "${blank+@}" || "${firmware+@}" ]]; then
92 echo
93 fi
94 # }}}
95
96 if [[ ${cpu} == arm || ${cpu} == arm64 ]]; then
97 pseudo "firmware" "${version}" "almost impressive Apple frameworks" "iOS Firmware"
98
99 while [[ 1 ]]; do
100 gssc=$(gssc 2>&1)
101 if [[ ${gssc} != *'(null)'* ]]; then
102 break
103 fi
104 sleep 1
105 done
106
107 echo "${gssc}" | sed -re '
108 /^ [^ ]* = [0-9.]*;$/ ! d;
109 s/^ ([^ ]*) = ([0-9.]*);$/\1 \2/;
110 s/([A-Z])/-\L\1/g;
111 s/^"([^ ]*)"/\1/;
112 s/^-//;
113 / 0$/ d;
114 ' | while read -r name value; do case "${name}" in
115 (ipad) for name in ipad wildcat; do
116 pseudo "gsc.${name}" "${value}" "this device has a very large screen" "iPad"
117 done;;
118
119 (*)
120 pseudo "gsc.${name}" "${value}" "virtual GraphicsServices dependency"
121 ;;
122 esac; done
123 fi
124
125 if [[ ${cpu} == arm || ${cpu} == arm64 ]]; then
126 os=ios
127 else
128 os=macosx
129 fi
130
131 pseudo "cy+os.${os}" "${version}" "virtual operating system dependency"
132 pseudo "cy+cpu.${cpu}" "0" "virtual CPU dependency"
133
134 name=${model%%*([0-9]),*([0-9])}
135 version=${model#${name}}
136 name=$(lower <<<${name})
137 version=${version/,/.}
138 pseudo "cy+model.${name}" "${version}" "virtual model dependency"
139
140 pseudo "cy+kernel.$(lower <<<$(sysctl -n kern.ostype))" "$(sysctl -n kern.osrelease)" "virtual kernel dependency"
141
142 pseudo "cy+lib.corefoundation" "$(/usr/libexec/cydia/cfversion)" "virtual corefoundation dependency"
143
144 } >"${output}"
145
146 # XXX: this is a poor replacement for flock
147 test "${before}" = "$(stat -c '%i-%Y' status)"
148 mv -f "${output}" "${status}"
149
150 if [[ ${cpu} == arm || ${cpu} == arm64 ]]; then
151 if [[ ! -h /User && -d /User ]]; then
152 cp -afT /User /var/mobile
153 fi && rm -rf /User && ln -s "/var/mobile" /User
154
155 echo 6 >/var/lib/cydia/firmware.ver
156 fi