forked from frankfanslc/pine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrees.sh
142 lines (126 loc) · 3.18 KB
/
trees.sh
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
#!/bin/bash -l
shopt -s expand_aliases
while [[ $# -gt 0 ]]; do
case $1 in
-b | --base)
base="$2"
shift
;;
-n | --name)
name="$2"
shift
;;
-f | --force)
clob=1
;;
-d | --delete)
action=delete
;;
-t | --target)
target="$2"
shift
;;
-h | --help | -* | --*)
action=help
;;
ls | list)
action=list
;;
ck | check)
action=check
;;
co | checkout)
action=checkout
;;
*)
case $action in
checkout)
target=${target:-$1}
;;
*)
name=${name:-$1}
esac
;;
esac
shift
done
## vars
repo=untoreh/$base
appsrepo=untoreh/trees
ostrepo=/var/lib/apps/repo
workdir=/var/tmp/sup/${name}
action=${action:-install}
alias ostree="ostree --repo=$ostrepo"
## ovz
. /etc/ovz &>/dev/null
if [ -z "$OVZ" ]; then
$(which /usr/bin/ostree) admin status | grep -q ovz && \
echo OVZ=1 >/etc/ovz || \
echo OVZ=0 >/etc/ovz
fi
. /etc/ovz
## actions
help() {
cat << EOF
Usage: trees APP [FLAGS]...
'APP' Install apps through ostree deltas checkouts.
-b, --base base image (alp,trub...)
-n, --name same as APP (etcd,hhvm...)
-f, --force clear before install
-d, --delete clear checkout and prune ostree repo
ck, check make sure the apps repo is mounted
co, checkout builds the trees of links for the specified APP
-t optional path where to build the tree
EOF
exit
}
delete() {
[ -z "$name" ] && exit 1
rm -rf --one-file-system $ostrepo/$name
ostree refs --delete $name
ostree prune --refs-only
/usr/bin/ostree admin cleanup
}
install() {
## prepare files
mkdir -p $workdir && \
cd $workdir && \
\
[ -n "$clob" ] && \
rm -f $workdir/* && \
ostree refs --delete $name && \
rm -rf --one-file-system $ostrepo/$name
## data
## ovz is only for the alpine base since they share with host repo
if [ $OVZ = 1 ] && [ "$base" = "pine" -o -z "$base" ]; then
artf="${name}_ovz.tar"
else
artf="${name}.tar"
fi
fetch_artifact ${appsrepo}:${name} $artf $workdir
rev=$(b64name $workdir)
[ -z "$rev" ] && err "error: app not found..." && exit 1
## install
applied=$(ostree static-delta apply-offline $rev && echo true || echo false)
! $applied && err "error: troubles applying the delta..." && exit 1
ostree refs --create=$name $rev
}
checkout() {
## apps is available
check
mkdir -p $ostrepo/$name
dest=${target:-$ostrepo/$name/rootfs}
union="--union-add"
if [ -z "$(ostree refs $name)" ]; then
install
union=
fi
ostree checkout --require-hardlinks $union $name $dest
}
check() {
if [ ! -d $ostrepo ] || ! mountpoint -q $ostrepo ; then
printdb "linking ostree repo for apps.."
sup local ostree-apps
fi
}
eval $action