]> git.saurik.com Git - cydia.git/blobdiff - Library/firmware.sh
Cytore values need to be _packed (I got lucky :D).
[cydia.git] / Library / firmware.sh
index e91eef344f3e5350abd654c7368fed6bdb7f7e4d..d2f89ebdf2b7f46ee949c5d710502f0c60281580 100755 (executable)
 #!/bin/bash
-set -e
 
-version=$(sw_vers -productVersion)
+set -e
 
-cat /var/lib/dpkg/status | {
+shopt -s extglob
+shopt -s nullglob
 
-while IFS= read -r line; do
-    #echo "#${firmware+@}/${blank+@} ${line}" 1>&2
+version=$(sw_vers -productVersion)
+cpu=$(uname -p)
 
-    if [[ ${line} == '' && "${blank+@}" ]]; then
-        continue
-    else
-        unset blank
-    fi
+if [[ ${cpu} == arm || ${cpu} == arm64 ]]; then
+    data=/var/lib/dpkg
+    model=hw.machine
+    arch=iphoneos-arm
+else
+    data=/Library/Cydia/dpkg
+    model=hw.model
+    arch=cydia
+fi
 
-    if [[ ${line} == 'Package: firmware' ]]; then
-        firmware=
-    elif [[ ${line} == '' ]]; then
-        blank=
-    fi
+model=$(sysctl -n "${model}")
 
-    if [[ "${firmware+@}" ]]; then
-        if [[ "${blank+@}" ]]; then
-            unset firmware
-        fi
-        continue
-    fi
+status=${data}/status
 
-    #echo "${firmware+@}/${blank+@} ${line}" 1>&2
-    echo "${line}"
-done
+function lower() {
+    sed -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'
+}
 
-#echo "#${firmware+@}/${blank+@} EOF" 1>&2
-if ! [[ "${blank+@}" || "${firmware+@}" ]]; then
-    echo
-fi
+# Generate New Package {{{
+function pseudo() {
+    local package=$1 version=$2 description=$3 name=$4
+    echo "/." >"${data}"/info/"${package}".list
 
-cat <<EOF
-Package: firmware
+    cat <<EOF
+Package: ${package}
 Essential: yes
 Status: install ok installed
 Priority: required
 Section: System
 Installed-Size: 0
-Maintainer: Jay Freeman (saurik) <saurik@saurik.com>
-Architecture: iphoneos-arm
+Architecture: ${arch}
 Version: ${version}
-Description: almost impressive Apple frameworks
-Name: iPhone Firmware
-
+Description: ${description}
+Tag: role::cydia
 EOF
 
-} >/var/lib/dpkg/status_
+    [[ -n ${name} ]] && echo "Name: ${name}"
+    echo
+}
+# }}}
 
-mv -f /var/lib/dpkg/status{_,}
+before=$(stat -c '%i-%Y' status)
 
-echo "/." >/var/lib/dpkg/info/firmware.list
+output=$(mktemp status-tmp.XXXXXX)
+xxxxxx=${output##status-tmp.}
+rm -f status-tmp.!("${xxxxxx}")
 
-if [[ ${version} = 1.0* || ${version} = 1.1.[012] ]]; then
-    user=root
-else
-    user=mobile
-fi
+{
+
+# Delete Old Packages {{{
+    unset firmware
+    unset blank
+
+    while IFS= read -r line; do
+        #echo "#${firmware+@}/${blank+@} ${line}" 1>&2
+
+        if [[ ${line} == '' && "${blank+@}" ]]; then
+            continue
+        else
+            unset blank
+        fi
+
+        if [[ ${line} == "Package: "@(firmware|gsc.*|cy+*) ]]; then
+            firmware=
+        elif [[ ${line} == '' ]]; then
+            blank=
+        fi
+
+        if [[ "${firmware+@}" ]]; then
+            if [[ "${blank+@}" ]]; then
+                unset firmware
+            fi
+            continue
+        fi
+
+        #echo "${firmware+@}/${blank+@} ${line}" 1>&2
+        echo "${line}"
+    done <"${status}"
+
+    #echo "#${firmware+@}/${blank+@} EOF" 1>&2
+    if ! [[ "${blank+@}" || "${firmware+@}" ]]; then
+        echo
+    fi
+# }}}
+
+    if [[ ${cpu} == arm || ${cpu} == arm64 ]]; then
+        pseudo "firmware" "${version}" "almost impressive Apple frameworks" "iOS Firmware"
+
+        while [[ 1 ]]; do
+            gssc=$(gssc 2>&1)
+            if [[ ${gssc} != *'(null)'* ]]; then
+                break
+            fi
+            sleep 1
+        done
+
+        echo "${gssc}" | sed -re '
+            /^    [^ ]* = [0-9.]*;$/ ! d;
+            s/^    ([^ ]*) = ([0-9.]*);$/\1 \2/;
+            s/([A-Z])/-\L\1/g;
+            s/^"([^ ]*)"/\1/;
+            s/^-//;
+            / 0$/ d;
+        ' | while read -r name value; do case "${name}" in
+            (ipad) for name in ipad wildcat; do
+                pseudo "gsc.${name}" "${value}" "this device has a very large screen" "iPad"
+            done;;
+
+            (*)
+                pseudo "gsc.${name}" "${value}" "virtual GraphicsServices dependency"
+            ;;
+        esac; done
+    fi
 
-if [[ ! -h /User && -d /User ]]; then
-    cp -afT /User /var/"${user}"
-fi && rm -rf /User && ln -s "/var/${user}" /User
+    if [[ ${cpu} == arm || ${cpu} == arm64 ]]; then
+        os=ios
+    else
+        os=macosx
+    fi
+
+    pseudo "cy+os.${os}" "${version}" "virtual operating system dependency"
+    pseudo "cy+cpu.${cpu}" "0" "virtual CPU dependency"
+
+    name=${model%%*([0-9]),*([0-9])}
+    version=${model#${name}}
+    name=$(lower <<<${name})
+    version=${version/,/.}
+    pseudo "cy+model.${name}" "${version}" "virtual model dependency"
+
+    pseudo "cy+kernel.$(lower <<<$(sysctl -n kern.ostype))" "$(sysctl -n kern.osrelease)" "virtual kernel dependency"
+
+    pseudo "cy+lib.corefoundation" "$(/usr/libexec/cydia/cfversion)" "virtual corefoundation dependency"
+
+} >"${output}"
+
+# XXX: this is a poor replacement for flock
+test "${before}" = "$(stat -c '%i-%Y' status)"
+mv -f "${output}" "${status}"
+
+if [[ ${cpu} == arm || ${cpu} == arm64 ]]; then
+    if [[ ! -h /User && -d /User ]]; then
+        cp -afT /User /var/mobile
+    fi && rm -rf /User && ln -s "/var/mobile" /User
+
+    echo 6 >/var/lib/cydia/firmware.ver
+fi