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