Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

executable file 259 lines (236 sloc) 6.315 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259
#!/bin/sh

if [ -r "`dirname "$0"`"/tve-setup.sh ]; then
. "`dirname "$0"`"/tve-setup.sh
else
. "$TVEROOT"/usr/lib/tve-setup.sh
fi

# Handle switches
INTERACTIVE=0
while [ $# -gt 0 ]; do
case "$1" in
-i)
INTERACTIVE=1
shift
;;
-d*)
TVEDB="`echo "$1" | cut -c3-`"
if [ -z "$TVEDB" ]; then
TVEDB=">>"
fi
shift
;;
-t*)
OAUTHTOKENFILE="`echo "$1" | cut -c3-`"
if [ -z "$OAUTHTOKENFILE" ]; then
OAUTHTOKENFILE=">>"
fi
shift
;;
-*)
echo "Unsupported switch $1" 1>&2
exit 1
;;
*)
if [ "$TVEDB" = ">>" ]; then
TVEDB="$1"
shift
elif [ "$OAUTHTOKENFILE" = ">>" ]; then
OAUTHTOKENFILE="$1"
shift
else # We have hit the first non-switch
break
fi
;;
esac
done

# Check that a package was specified to install
if [ -z "$1" ]; then
echo "No package was specified." 1>&2
exit 1
fi

# Verify the presence of oauthsign
if ! cmdexists oauthsign; then
echo "You need the oauthsign utility from oauth-utils installed to use this script." 1>&2
exit 1
fi

# Auto-select install prefix
if [ -z "$PREFIX" ]; then
PREFIX="$TVEROOT/"
fi

# Select directory for install logs
LOGDIR=""
if [ -d "$TVEROOT/Library/Caches" ]; then
LOGDIR="$TVEROOT/Library/Caches/tve-remove"
else
LOGDIR="$TVEROOT/var/cache/tve-remove"
fi
if ! mkdir -p "$LOGDIR"; then
LOGDIR="$HOME/.tve-remove"
if ! mkdir -p "$LOGDIR"; then
echo "Could not access the install log directory." 1>&2
exit 1
fi
fi

# Select a temporary directory
if [ ! -z "$TMPDIR" ]; then
temp="$TMPDIR"
elif [ ! -z "$TEMP" ]; then
temp="$TEMP"
elif [ ! -z "$TMP" ]; then
temp="$TMP"
elif [ -d "/tmp" ]; then
temp="/tmp"
else
#fallback
temp="."
fi
# Try to use mktemp
if cmdexists mktemp; then
temp="`mktemp -d "$temp/tve-install-$$-XXXXXX"`"
else
temp="$temp/tve-install-$$-$RANDOM-$RANDOM" #$RANDOM is non-standard and likely blank on your shell
mkdir -p "$temp"
fi

# Determine if there is an external package manager to use
if ! cmdexists apt-get; then
EXTERNAL=""
else
EXTERNAL="apt-get install -y"
fi

# Determine which command to use for installing internal packages
INTERNAL="`cmdexists dpkg`"
if [ $? != 0 -o "`whoami`" != "root" ]; then
INTERNAL="sh `findTVEscript undeb " "`"
else
INTERNAL="dpkg --root="$TVEROOT/" -i"
fi

DEPENDS="`findTVEbinary depends`"
SEARCH="`findTVEbinary search`"
MD5UTIL="`findTVEbinary md5 " "`"
STATUS="`findTVEbinary status`"

MUST_REBOOT=0

# do_install KIND PACKAGE
do_install () {
# If interactive, ask for confirmation
if [ $INTERACTIVE != 0 ]; then
read -p "Install $1 ${2}? [Yn] " YN
if [ "$YN" = "N" -o "$YN" = "n" -o "$YN" = "No" -o "$YN" = "no" ]; then
echo "You opted not to install $1 ${2}. Aborting install..."
exit 2
fi
fi
# Extract the download URL from the database
DATA="`TVEDB="$TVEDB" "$SEARCH" -nve "$2"`"
URL="`echo "$DATA" | grep Download | cut -d' ' -f2`"
if [ -z "$URL" ]; then
echo "Package $2 not found." 1>&2
exit 1
fi
# Get token for this BASEURL
BASEURL="`echo "$DATA" | grep BaseURL | cut -d' ' -f2`"
TOKENS="`getTVETokens "$BASEURL" "$OAUTHTOKENFILE"`"
# Sign the URL with oauth utils (oauthsign)
if [ -n "$TOKENS" ]; then
URL="`getTVEAuthRequest "$TOKENS" "$URL"`"
fi
# Get remote URL and download deb file with net2stdout
if ! net2stdout "$URL" > "$temp/$2.deb"; then
echo "Error downloading ${2}... Aborting..."
exit 1
fi
# Verify size and MD5 from database
SIZE="`echo "$DATA" | grep Size | cut -d' ' -f2`"
REALSIZE="`wc -c "$temp/$2.deb" | awk '{ print $1 }'`"
if [ "$SIZE" != "$REALSIZE" ]; then
echo "Integrity check for $2 failed. Size does not match." 1>&2
exit 1
fi
MD5="`echo "$DATA" | grep MD5sum | cut -d' ' -f2`"
REALMD5="`"$MD5UTIL" -q "$temp/$2.deb"`"
if [ "$MD5" != "$REALMD5" ]; then
echo "Integrity check for $2 failed. MD5 sum does not match." 1>&2
exit 1
fi
# Install deb file with $INTERNAL
export LOG="$LOGDIR/$2" RMPATH="$LOGDIR/$2" PREFIX="$TVEROOT/"
if ! eval $INTERNAL "$temp/$2.deb"; then
if [ $? -eq 110 ]; then
MUST_REBOOT=1
else
echo "Error unpacking ${2}."
exit 1
fi
fi
# UPDATE status in DB
if [ "$1" = "dependency" ]; then
if [ "`"$STATUS" "$2"`" -ne 0 ]; then
"$STATUS" "$2" .
else
"$STATUS" "$2" 2 # Set to 2 if installing for the first time as a dependency
fi
else
"$STATUS" "$2" .
# Add Uninstall entry on Windows
if cmdexists reg; then
reg ADD "HKLM\\Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\$2" /v "DisplayName" /d "$2" /f
reg ADD "HKLM\\Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\$2" /v "UninstallString" /d "\$\\\"$TVEROOT\\bin\\sh.exe\$\\\" -c tve-remove $2" /f
reg ADD "HKLM\\Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\$2" /v "NoModify" /t REG_DWORD /d 1 /f
reg ADD "HKLM\\Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\$2" /v "NoRepair" /t REG_DWORD /d 1 /f
fi
fi
}

# do_manual PACKAGE
do_manual() {

# Get dependencies
DEP="`TVEDB="$TVEDB" "$DEPENDS" "$1"`"
if [ $? != 0 ]; then
# Error message was already output by the depends command
exit 1
fi

# Install dependencies
EXT2INSTALL=""

# Set IFS so that for splits on newlines and not spaces
OIFS="$IFS"
IFS="
"
for LINE in $DEP; do
IFS="$OIFS"
package="`echo "$LINE" | cut -d' ' -f2`"
if [ "`echo "$LINE" | cut -d' ' -f1`" = "E" ]; then
if [ -z "$EXTERNAL" ]; then
echo "No external package manager found to install ${package}." 1>&2
exit 1
fi
EXT2INSTALL="$EXT2INSTALL $package"
else
do_install "dependency" "$package"
fi
done

# Actually install external dependencies, if there are any
if [ ! -z "$EXT2INSTALL" ]; then
# If interactive, ask for confirmation
if [ $INTERACTIVE != 0 ]; then
read -p "Install external dependencies ${EXT2INSTALL}? [Yn] " YN
if [ "$YN" = "N" -o "$YN" = "n" -o "$YN" = "No" -o "$YN" = "no" ]; then
echo "You opted not to install required dependencies ${EXT2INSTALL}. Aborting install..."
exit 2
fi
fi
# $EXTERNAL $EXT2INSTALL
if [ $? != 0 ]; then
echo "External dependency install failure." 1>&2
exit 1
fi
fi

do_install "" "$1"

echo "$1 sucessfully installed (with all dependencies)."

}

while [ $# -gt 0 ]; do
do_manual "$1"
shift
done

# remove temp dir
rm -rf "$temp"

if [ $MUST_REBOOT -eq 1 ]; then
exit 110
fi
Something went wrong with that request. Please try again.