this repo has no description
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request #126 from X0rg/request

Improvements for darling script

+67 -21
+67 -21
src/dyld/darling
··· 24 24 25 25 selfmtime=$(stat -c %Y "$DARLING_PREFIX/bin/darling") 26 26 27 + check_prefix() { 28 + 29 + if [ ! -d "$DPREFIX" -o ! -f "$DPREFIX/.update-timestamp" ]; then 30 + setup_prefix "$DPREFIX" 31 + else 32 + 33 + updatets=$(cat $DPREFIX/.update-timestamp) 34 + if [ "$updatets" != "disable" -a "$updatets" -lt $selfmtime ]; then 35 + setup_prefix "$DPREFIX" 36 + fi 37 + fi 38 + } 39 + 27 40 setup_prefix() { 28 41 prefix_pkg="/tmp/prefix.$$.pkg" 29 42 ··· 85 98 "${DARLING_PREFIX}/libexec/darling/usr/bin/installer" -pkg "/system-root${pkgpath}" -target / 86 99 87 100 rm -rf "$temp" 101 + } 102 + 103 + is_sudo_allowed() { 104 + if type -p sudo &> /dev/null; then 105 + sudo -nl "$@" &> /dev/null && return 0 106 + fi 107 + return 1 108 + } 109 + 110 + launch_with_su() { 111 + if [ "$(id -u)" == 0 ]; then 112 + "$@" 113 + elif is_sudo_allowed; then 114 + sudo "$@" 115 + else 116 + local cmd=$(printf '%q ' "$@") 117 + su --shell=$BASH --command "$cmd" 118 + fi 119 + } 120 + 121 + darling_check() { 122 + # Returning values: 123 + # 0: module is loaded, file permissions are good 124 + # 1: module is loaded, file permissions are wrong 125 + # 2: module is not loaded 126 + grep -q darling_mach "/proc/modules" 127 + if [ $? -eq 0 ]; then 128 + [ -r "/dev/mach" -a -w "/dev/mach" ] && return 0 || return 1 129 + else 130 + return 2 131 + fi 88 132 } 89 133 90 134 darling_load() { 91 - modprobe darling-mach 135 + if $(darling_check); then 136 + >&2 echo "Module is already loaded." 137 + else 138 + >&2 echo -n "Loading module... " 139 + launch_with_su modprobe darling-mach && >&2 echo "Done." || >&2 echo "Fail." 140 + sleep 1 # Wait for module loading 141 + launch_with_su chmod a+rw "/dev/mach" 142 + fi 143 + 92 144 } 93 145 94 146 darling_unload() { 95 - rmmod darling-mach 147 + if $(darling_check); then 148 + >&2 echo -n "Unloading module... " 149 + launch_with_su rmmod darling-mach && >&2 echo "Done." || >&2 echo "Fail." 150 + else 151 + >&2 echo "Module is not loaded, so it can't be unloaded." 152 + fi 96 153 } 97 154 98 155 if [ $# -eq 0 ]; then ··· 105 162 >&2 echo -e "\tdarling shell\t\t\tStart bash shell in prefix" 106 163 #>&2 echo -e "\tdarling hdiutil\t\t\tMount DMG disk images" 107 164 #>&2 echo -e "\tdarling pkgutil\t\t\tInstall PKG packages" 165 + >&2 echo -e "\tdarling load\t\t\tLoad kernel module" 166 + >&2 echo -e "\tdarling unload\t\t\tUnload kernel module" 108 167 >&2 echo 109 168 >&2 echo "The prefix is specified by the DPREFIX environment variable." 110 169 >&2 echo "The default DPREFIX is \$HOME/.darling" ··· 117 176 export DPREFIX="$HOME/.darling" 118 177 fi 119 178 120 - if [ ! -d "$DPREFIX" -o ! -f "$DPREFIX/.update-timestamp" ]; then 121 - setup_prefix "$DPREFIX" 122 - else 123 - 124 - updatets=$(cat $DPREFIX/.update-timestamp) 125 - if [ "$updatets" != "disable" -a "$updatets" -lt $selfmtime ]; then 126 - setup_prefix "$DPREFIX" 127 - fi 128 - 179 + if ! $(darling_check) && [ "$1" != "load" ] && [ "$1" != "unload" ]; then 180 + 2>&1 echo "Cannot open /dev/mach, running 'darling load'." 181 + darling_load 129 182 fi 130 183 131 184 #dyld_path="${0%darling}dyld" ··· 133 186 134 187 case "$1" in 135 188 "shell") 189 + check_prefix 190 + 136 191 if [ $# -gt 1 ]; then 137 192 exec "${dyld_path}" "${DPREFIX}/bin/bash" -c "${*:2}" 138 193 else ··· 148 203 # exit 1 149 204 # ;; 150 205 "load") 151 - if [ "$(id -u)" != 0 ]; then 152 - 2>&1 "You need to be root for this command." 153 - exit 1 154 - fi 155 - 156 206 darling_load 157 207 ;; 158 208 "unload") 159 - if [ "$(id -u)" != 0 ]; then 160 - 2>&1 "You need to be root for this command." 161 - exit 1 162 - fi 163 - 164 209 darling_unload 165 210 ;; 166 211 *) 212 + check_prefix 167 213 exec "${dyld_path}" "$1" "${@:2}" 168 214 ;; 169 215 esac