]> git.saurik.com Git - cydia.git/blob - Library/firmware.sh
Commit separate errors during popErrorWithTitle:.
[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 ]]; 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 ]]; then
91 pseudo "firmware" "${version}" "almost impressive Apple frameworks"
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; s/^"([^ ]*)"/\1/;
105 s/^-//;
106 / 0$/ d;
107 ' | while read -r name value; do
108 pseudo "gsc.${name}" "${value}" "virtual GraphicsServices dependency"
109
110 if [[ ${name} == ipad ]]; then
111 pseudo "gsc.wildcat" "${value}" "virtual virtual GraphicsServices dependency"
112 fi
113 done
114 fi
115
116 if [[ ${cpu} == arm ]]; then
117 os=ios
118 else
119 os=macosx
120 fi
121
122 pseudo "cy+os.${os}" "${version}" "virtual operating system dependency"
123 pseudo "cy+cpu.${cpu}" "0" "virtual CPU dependency"
124
125 name=${model%%*([0-9]),*([0-9])}
126 version=${model#${name}}
127 name=$(lower <<<${name})
128 version=${version/,/.}
129 pseudo "cy+model.${name}" "${version}" "virtual model dependency"
130
131 pseudo "cy+kernel.$(lower <<<$(sysctl -n kern.ostype))" "$(sysctl -n kern.osrelease)" "virtual kernel dependency"
132
133 } >"${status}"_
134
135 mv -f "${status}"{_,}
136
137 if [[ ${cpu} == arm ]]; then
138 if [[ ! -h /User && -d /User ]]; then
139 cp -afT /User /var/mobile
140 fi && rm -rf /User && ln -s "/var/mobile" /User
141
142 echo 3 >/var/lib/cydia/firmware.ver
143 fi