]> git.saurik.com Git - cydia.git/blame_incremental - Library/firmware.sh
Amortize linear probing with a binary search sort.
[cydia.git] / Library / firmware.sh
... / ...
CommitLineData
1#!/bin/bash
2
3set -e
4
5shopt -s extglob
6shopt -s nullglob
7
8version=$(sw_vers -productVersion)
9cpu=$(uname -p)
10
11if [[ ${cpu} == arm || ${cpu} == arm64 ]]; then
12 data=/var/lib/dpkg
13 model=hw.machine
14 arch=iphoneos-arm
15else
16 data=/Library/Cydia/dpkg
17 model=hw.model
18 arch=cydia
19fi
20
21model=$(sysctl -n "${model}")
22
23status=${data}/status
24
25function lower() {
26 sed -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'
27}
28
29# Generate New Package {{{
30function pseudo() {
31 local package=$1 version=$2 description=$3 name=$4
32 echo "/." >"${data}"/info/"${package}".list
33
34 cat <<EOF
35Package: ${package}
36Essential: yes
37Status: install ok installed
38Priority: required
39Section: System
40Installed-Size: 0
41Architecture: ${arch}
42Version: ${version}
43Description: ${description}
44Maintainer: Jay Freeman (saurik) <saurik@saurik.com>
45Tag: role::cydia
46EOF
47
48 [[ -n ${name} ]] && echo "Name: ${name}"
49 echo
50}
51# }}}
52
53output=$(mktemp "${data}"/status-tmp.XXXXXX)
54chmod 644 "${output}"
55xxxxxx=${output##*/status-tmp.}
56rm -f "${data}"/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
146mv -f "${output}" "${status}"
147
148if [[ ${cpu} == arm || ${cpu} == arm64 ]]; then
149 if [[ ! -h /User && -d /User ]]; then
150 cp -afT /User /var/mobile
151 fi && rm -rf /User && ln -s "/var/mobile" /User
152
153 echo 6 >/var/lib/cydia/firmware.ver
154fi