summaryrefslogtreecommitdiff
path: root/bin/appstore-init
blob: b721eee21df3cc3f3af1dd597e8fdf50a3794a75 (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
#!/bin/bash

set -e
set -u

APPSTORE_HOME=$(cd $(dirname "$0")/.. && pwd)

. $APPSTORE_HOME/lib/common
# HEADER END

usage() {
  echo "usage [server] [remote path] [name]"
  exit 1
}

if [ $# -ne 3 ]
then
  usage
fi

server=$1; shift
root=$1; shift
name=$1; shift

repos=$root/repos
appstores=$root/appstores

if [ -e "$name" ]
then
  echo "$name already exist!"
  exit 1
fi

tmpfile=tmpfile$$
conffile=conffile$$
echo "Creating remote appstore..."
set +e
ssh "$server" \
      "$APPSTORE_HOME/libexec/appstore-server-init" \
      "$repos" \
      "$appstores" \
      "$name" > "$tmpfile" 2>&1
ret=$?
set -e

sed -n "s,^config: \(.*\),\1,p" $tmpfile > $conffile
repo_path=`app cat-conf -f "$conffile" -k repo.path | cut -f 2- -d =`
repo_ok=`app cat-conf -f "$conffile" -k repo.ok | cut -f 2- -d =`

if [ "$ret" != 0 ]
then
  echo "Initialization failed. Server output:"
  cat $tmpfile
  exit 1
fi

echo "Cloning repository..."
git clone -q "ssh://$server$repo_path" "$name"
cd $name
git remote rename origin cloud
cd ..

echo "$name is open for cloud business!"
rm *$$