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