]> git.saurik.com Git - cydia.git/blob - Library/firmware.sh
0cf9c1dabed4e2ef47cae892687eacbb493f4af7
[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 firmware=
56
57 while IFS= read -r line; do
58 #echo "#${firmware+@}/${blank+@} ${line}" 1>&2
59
60 if [[ ${line} == '' && "${blank+@}" ]]; then
61 continue
62 else
63 unset blank
64 fi
65
66 if [[ ${line} == "Package: "@(firmware|gsc.*|cy+*) ]]; then
67 firmware=
68 elif [[ ${line} == '' ]]; then
69 blank=
70 fi
71
72 if [[ "${firmware+@}" ]]; then
73 if [[ "${blank+@}" ]]; then
74 unset firmware
75 fi
76 continue
77 fi
78
79 #echo "${firmware+@}/${blank+@} ${line}" 1>&2
80 echo "${line}"
81 done <"${status}"
82
83 #echo "#${firmware+@}/${blank+@} EOF" 1>&2
84 if ! [[ "${blank+@}" || "${firmware+@}" ]]; then
85 echo
86 fi
87 # }}}
88
89 if [[ ${cpu} == arm ]]; then
90 pseudo "firmware" "${version}" "almost impressive Apple frameworks"
91
92 gssc 2>&1 | sed -re '
93 /^ [^ ]* = [0-9.]*;$/ ! d;
94 s/^ ([^ ]*) = ([0-9.]*);$/\1 \2/;
95 s/([A-Z])/-\L\1/g; s/^"([^ ]*)"/\1/;
96 s/^-//;
97 / 0$/ d;
98 ' | while read -r name value; do
99 pseudo "gsc.${name}" "${value}" "virtual GraphicsServices dependency"
100 done
101 fi
102
103 if [[ ${cpu} == arm ]]; then
104 os=ios
105 else
106 os=macosx
107 fi
108
109 pseudo "cy+os.${os}" "${version}" "virtual operating system dependency"
110 pseudo "cy+cpu.${cpu}" "0" "virtual CPU dependency"
111
112 name=${model%%*([0-9]),*([0-9])}
113 version=${model#${name}}
114 name=$(lower <<<${name})
115 version=${version/,/.}
116 pseudo "cy+model.${name}" "${version}" "virtual model dependency"
117
118 pseudo "cy+kernel.$(lower <<<$(sysctl -n kern.ostype))" "$(sysctl -n kern.osrelease)" "virtual kernel dependency"
119
120 } >"${status}"_
121
122 mv -f "${status}"{_,}
123
124 if [[ ${cpu} == arm ]]; then
125 if [[ ! -h /User && -d /User ]]; then
126 cp -afT /User /var/mobile
127 fi && rm -rf /User && ln -s "/var/mobile" /User
128
129 echo 3 >/var/lib/cydia/firmware.ver
130 fi