summaryrefslogtreecommitdiff
path: root/standalone/android/runshell
blob: 2f591fcd2e1971d511b7bcbfb1ad4f3eb083e837 (plain)
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
#!/system/bin/sh
# This is run by the Android app, and runs a shell in an environment
# configured for git-annex.

set -e

# I'm installed as lib/lib.runshell.so
orig="$(pwd)"
cd "$0/../.."
base="$(pwd)"

# Cannot rely on Android providing a sane HOME
HOME="/sdcard/git-annex.home"
export HOME

# As good a start point as any.
cd "$HOME"

setup () {
	echo "Installation starting to $base"
	cat "$base/lib/lib.version.so"

	mkdir -p "$base/bin"
	for prog in busybox git-annex git-shell git-upload-pack git gpg rsync ssh ssh-keygen; do
		echo "installing $prog"
		if [ -e "$base/bin/$prog" ]; then
			rm "$base/bin/$prog"
		fi
		ln "$base/lib/lib.$prog.so" "$base/bin/$prog"
	done

	mkdir -p "$base/bin.new"
	$base/bin/busybox --install $base/bin.new
	mv $base/bin.new/* $base/bin
	rmdir "$base/bin.new"

	$base/bin/tar zxf $base/lib/lib.git.tar.gz.so
	for prog in git git-shell git-upload-pack; do
		for link in $(cat $base/links/$prog); do
			echo "linking $link to $prog"
			if [ -e "$base/$link" ]; then
				rm "$base/$link"
			fi
			ln "$base/bin/$prog" "$base/$link"
		done
		rm "$base/links/$prog"
	done

	mkdir -p "$base/templates"
	mkdir -p "$base/tmp"

	cat "$base/lib/lib.version.so" > "$base/installed-version"
	echo "Installation complete"
}

if [ ! -d "$base/bin" ]; then
	if ! mkdir -p "$HOME"; then
		echo "mkdir of $HOME failed!"
	fi
	if ! setup > $HOME/git-annex-install.log 2>&1; then
		echo "Installation failed! Please report a bug and attach $HOME/git-annex-install.log"
		sh
	fi
elif [ ! -e "$base/installed-version" ] || ! cmp "$base/installed-version" "$base/lib/lib.version.so" >/dev/null; then
	if ! setup > $HOME/git-annex-install.log 2>&1; then
		echo "Upgrade failed! Please report a bug and attach $HOME/git-annex-install.log"
	fi
fi

PATH="$base/bin:$PATH"
export PATH

ORIG_GIT_EXEC_PATH="$GIT_EXEC_PATH"
export ORIG_GIT_EXEC_PATH
GIT_EXEC_PATH=$base/libexec/git-core
export GIT_EXEC_PATH

ORIG_GIT_TEMPLATE_DIR="$GIT_TEMPLATE_DIR"
export ORIG_GIT_TEMPLATE_DIR
GIT_TEMPLATE_DIR="$base/templates"
export GIT_TEMPLATE_DIR

# Indicate which variables were exported above.
GIT_ANNEX_STANDLONE_ENV="GIT_EXEC_PATH GIT_TEMPLATE_DIR"
export GIT_ANNEX_STANDLONE_ENV

# This is a temporary directory on a non-crippled filesystem.
# This needs to be as short a path as possible.
GIT_ANNEX_TMP_DIR=$base/tmp
export GIT_ANNEX_TMP_DIR

if [ "$1" ]; then
	cmd="$1"
	shift 1
	exec "$cmd" "$@"
else
	sh
fi