]> git.saurik.com Git - cydia.git/blame - Library/firmware.sh
I am too tired to figure out why that didn't work.
[cydia.git] / Library / firmware.sh
CommitLineData
1ca3a01a 1#!/bin/bash
01d93940 2
a6147124 3set -e
9fe9d6c3 4
01d93940 5shopt -s extglob
9fe9d6c3 6shopt -s nullglob
1ca3a01a
JF
7
8version=$(sw_vers -productVersion)
9fe9d6c3 9cpu=$(uname -p)
1ca3a01a 10
0ca262bb 11if [[ ${cpu} == arm || ${cpu} == arm64 ]]; then
9fe9d6c3
JF
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
ea173384 20
9fe9d6c3 21model=$(sysctl -n "${model}")
ea173384 22
9fe9d6c3 23status=${data}/status
a6147124 24
9fe9d6c3 25function lower() {
2fafd6eb 26 sed -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'
9fe9d6c3 27}
a6147124 28
9fe9d6c3
JF
29# Generate New Package {{{
30function pseudo() {
31 local package=$1 version=$2 description=$3 name=$4
32 echo "/." >"${data}"/info/"${package}".list
ea173384 33
9fe9d6c3
JF
34 cat <<EOF
35Package: ${package}
1ca3a01a
JF
36Essential: yes
37Status: install ok installed
38Priority: required
39Section: System
40Installed-Size: 0
9fe9d6c3 41Architecture: ${arch}
1ca3a01a 42Version: ${version}
9fe9d6c3 43Description: ${description}
01d93940 44Tag: role::cydia
01d93940
JF
45EOF
46
9fe9d6c3
JF
47 [[ -n ${name} ]] && echo "Name: ${name}"
48 echo
49}
50# }}}
01d93940 51
9fe9d6c3 52{
01d93940 53
9fe9d6c3 54# Delete Old Packages {{{
9b083d03
JF
55 unset firmware
56 unset blank
b4673703 57
9fe9d6c3
JF
58 while IFS= read -r line; do
59 #echo "#${firmware+@}/${blank+@} ${line}" 1>&2
1ca3a01a 60
9fe9d6c3
JF
61 if [[ ${line} == '' && "${blank+@}" ]]; then
62 continue
63 else
64 unset blank
65 fi
a6147124 66
9fe9d6c3
JF
67 if [[ ${line} == "Package: "@(firmware|gsc.*|cy+*) ]]; then
68 firmware=
69 elif [[ ${line} == '' ]]; then
70 blank=
71 fi
01d93940 72
9fe9d6c3
JF
73 if [[ "${firmware+@}" ]]; then
74 if [[ "${blank+@}" ]]; then
75 unset firmware
76 fi
77 continue
78 fi
01d93940 79
9fe9d6c3
JF
80 #echo "${firmware+@}/${blank+@} ${line}" 1>&2
81 echo "${line}"
82 done <"${status}"
ea173384 83
9fe9d6c3
JF
84 #echo "#${firmware+@}/${blank+@} EOF" 1>&2
85 if ! [[ "${blank+@}" || "${firmware+@}" ]]; then
86 echo
87 fi
88# }}}
89
0ca262bb 90 if [[ ${cpu} == arm || ${cpu} == arm64 ]]; then
c81d818a 91 pseudo "firmware" "${version}" "almost impressive Apple frameworks" "iOS Firmware"
9fe9d6c3 92
d890e8b8
JF
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 '
9fe9d6c3
JF
102 /^ [^ ]* = [0-9.]*;$/ ! d;
103 s/^ ([^ ]*) = ([0-9.]*);$/\1 \2/;
55589708
JF
104 s/([A-Z])/-\L\1/g;
105 s/^"([^ ]*)"/\1/;
9fe9d6c3
JF
106 s/^-//;
107 / 0$/ d;
5dcff401
JF
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
9fe9d6c3 117 fi
1ca3a01a 118
0ca262bb 119 if [[ ${cpu} == arm || ${cpu} == arm64 ]]; then
9fe9d6c3
JF
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"
1ca3a01a 133
9fe9d6c3 134 pseudo "cy+kernel.$(lower <<<$(sysctl -n kern.ostype))" "$(sysctl -n kern.osrelease)" "virtual kernel dependency"
01d93940 135
e967efd5
JF
136 pseudo "cy+lib.corefoundation" "$(/usr/libexec/cydia/cfversion)" "virtual corefoundation dependency"
137
9fe9d6c3
JF
138} >"${status}"_
139
140mv -f "${status}"{_,}
141
0ca262bb 142if [[ ${cpu} == arm || ${cpu} == arm64 ]]; then
9fe9d6c3
JF
143 if [[ ! -h /User && -d /User ]]; then
144 cp -afT /User /var/mobile
145 fi && rm -rf /User && ln -s "/var/mobile" /User
146
5dcff401 147 echo 6 >/var/lib/cydia/firmware.ver
9fe9d6c3 148fi