]> git.saurik.com Git - cydia.git/blame - Library/firmware.sh
Slim result of NewTag and correct cache iterators.
[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}
069ee788 44Maintainer: Jay Freeman (saurik) <saurik@saurik.com>
01d93940 45Tag: role::cydia
01d93940
JF
46EOF
47
9fe9d6c3
JF
48 [[ -n ${name} ]] && echo "Name: ${name}"
49 echo
50}
51# }}}
01d93940 52
ceffc5bc
JF
53before=$(stat -c '%i-%Y' status)
54
55output=$(mktemp status-tmp.XXXXXX)
56xxxxxx=${output##status-tmp.}
57rm -f status-tmp.!("${xxxxxx}")
58
9fe9d6c3 59{
01d93940 60
9fe9d6c3 61# Delete Old Packages {{{
9b083d03
JF
62 unset firmware
63 unset blank
b4673703 64
9fe9d6c3
JF
65 while IFS= read -r line; do
66 #echo "#${firmware+@}/${blank+@} ${line}" 1>&2
1ca3a01a 67
9fe9d6c3
JF
68 if [[ ${line} == '' && "${blank+@}" ]]; then
69 continue
70 else
71 unset blank
72 fi
a6147124 73
9fe9d6c3
JF
74 if [[ ${line} == "Package: "@(firmware|gsc.*|cy+*) ]]; then
75 firmware=
76 elif [[ ${line} == '' ]]; then
77 blank=
78 fi
01d93940 79
9fe9d6c3
JF
80 if [[ "${firmware+@}" ]]; then
81 if [[ "${blank+@}" ]]; then
82 unset firmware
83 fi
84 continue
85 fi
01d93940 86
9fe9d6c3
JF
87 #echo "${firmware+@}/${blank+@} ${line}" 1>&2
88 echo "${line}"
89 done <"${status}"
ea173384 90
9fe9d6c3
JF
91 #echo "#${firmware+@}/${blank+@} EOF" 1>&2
92 if ! [[ "${blank+@}" || "${firmware+@}" ]]; then
93 echo
94 fi
95# }}}
96
0ca262bb 97 if [[ ${cpu} == arm || ${cpu} == arm64 ]]; then
c81d818a 98 pseudo "firmware" "${version}" "almost impressive Apple frameworks" "iOS Firmware"
9fe9d6c3 99
d890e8b8
JF
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 '
9fe9d6c3
JF
109 /^ [^ ]* = [0-9.]*;$/ ! d;
110 s/^ ([^ ]*) = ([0-9.]*);$/\1 \2/;
55589708
JF
111 s/([A-Z])/-\L\1/g;
112 s/^"([^ ]*)"/\1/;
9fe9d6c3
JF
113 s/^-//;
114 / 0$/ d;
5dcff401
JF
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
9fe9d6c3 124 fi
1ca3a01a 125
0ca262bb 126 if [[ ${cpu} == arm || ${cpu} == arm64 ]]; then
9fe9d6c3
JF
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"
1ca3a01a 140
9fe9d6c3 141 pseudo "cy+kernel.$(lower <<<$(sysctl -n kern.ostype))" "$(sysctl -n kern.osrelease)" "virtual kernel dependency"
01d93940 142
e967efd5
JF
143 pseudo "cy+lib.corefoundation" "$(/usr/libexec/cydia/cfversion)" "virtual corefoundation dependency"
144
ceffc5bc 145} >"${output}"
9fe9d6c3 146
ceffc5bc
JF
147# XXX: this is a poor replacement for flock
148test "${before}" = "$(stat -c '%i-%Y' status)"
149mv -f "${output}" "${status}"
9fe9d6c3 150
0ca262bb 151if [[ ${cpu} == arm || ${cpu} == arm64 ]]; then
9fe9d6c3
JF
152 if [[ ! -h /User && -d /User ]]; then
153 cp -afT /User /var/mobile
154 fi && rm -rf /User && ln -s "/var/mobile" /User
155
5dcff401 156 echo 6 >/var/lib/cydia/firmware.ver
9fe9d6c3 157fi