Skip to content

Commit 4c91d9e

Browse files
committed
miniscript-docker:install
1 parent a7ca11c commit 4c91d9e

File tree

1 file changed

+84
-115
lines changed

1 file changed

+84
-115
lines changed

miniscript-docker

Lines changed: 84 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,24 @@
11
#!/usr/bin/env bash
22

3+
[[ -z "$(command -v miniscript-docker)" ]] && \
4+
install $0 /usr/local/bin || true
5+
36
PORT=${PORT:80}
47
VERBOSE=${VERBOSE:- }
58

69
FORCE=${FORCE:- }
710
NOCACHE=${NOCACHE:- } ## default rebuild without --no-cache
811
TAG=${TAG:-miniscript}
912

13+
PYTHON3=$(which python3)
14+
15+
if [[ "$(uname -s)" == "Darwin" ]];
16+
then
17+
DOCKER=${DOCKER:-"/Applications/Docker.app/Contents/MacOS/Docker"}
18+
fi
19+
## echo $DOCKER; ##exit
20+
## [[ -z "$DOCKER" ]] && echo "????" && DOCKER=${DOCKER:docker}
21+
1022
## MINT_000
1123

1224
## MINT_001
@@ -23,129 +35,59 @@ MINT_003="or(99@thresh(2,thresh(2,pk(A1),pk(A2),pk(A3),after(1004)),or(10@thresh
2335
## MINT_004
2436
MINT_004="or(99@thresh(3,thresh(2,pk(P1),pk(P2),pk(P3),after(1002),after(1003)),thresh(2,pk(A1),pk(A2),pk(A3),after(1004)),thresh(1,pk(SA1),pk(SA2),pk(SA3))),1@and(thresh(2,pk(M1),pk(M2),pk(M3)),after(1005)))"
2537

38+
function docker-start(){
39+
40+
( \
41+
while ! docker system info > /dev/null 2>&1; do\
42+
echo 'Waiting for docker to start...';\
43+
## echo $DOCKER
44+
if [[ "$(uname -s)" == "Linux" ]]; then\
45+
systemctl restart docker.service;\
46+
fi;\
47+
if [[ "$(uname -s)" == "Darwin" ]]; then\
48+
DOCKER="/Applications/Docker.app/Contents/MacOS/Docker";\
49+
open --background -a $DOCKER;\
50+
fi;\
51+
sleep 1;\
52+
done\
53+
)
54+
55+
}
2656
function examples(){
2757

28-
printf "Examples:\n"
29-
printf "\n"
30-
printf "miniscript-docker run \n
31-
\'thresh(2,pk(XPUB1),s:pk(XPUB2),s:pk(XPUB3),snl:older(100))\'
58+
printf "
59+
thresh(2,pk(XPUB1),s:pk(XPUB2),s:pk(XPUB3),snl:older(100))
3260
"
3361
printf "
34-
\'and_v(or_c(pk(B),or_c(pk(C),v:older(1000))),pk(A))\'
62+
and_v(or_c(pk(B),or_c(pk(C),v:older(1000))),pk(A))
3563
"
3664
printf "
37-
\'and(pk(A),or(pk(B),or(9@pk(C),older(1000))))\'
65+
and(pk(A),or(pk(B),or(9@pk(C),older(1000))))
3866
"
39-
printf "\n"
40-
printf "MinT Examples:\n"
41-
printf "\n"
42-
printf "MinT-000"
43-
printf "\n"
44-
printf "
45-
\'and(pk(A),or(pk(B),or(9@pk(C),older(1000))))\'
67+
printf "
68+
and(pk(A),or(pk(B),or(9@pk(C),older(1000))))
4669
"
47-
printf "\n"
48-
printf "MinT-001"
49-
printf "\n"
50-
printf "
51-
\'and(pk(A),or(pk(B),or(9@pk(C),older(1000))))\'
70+
printf "
71+
and(pk(A),or(pk(B),or(9@pk(C),older(1000))))
5272
"
53-
printf "\n"
54-
printf "MinT-002.1"
55-
printf "\n"
56-
printf "
57-
\'$MINT_002_1\'
73+
printf "
74+
$MINT_002_1
5875
"
59-
## 0
60-
## scriptlen=206
61-
## maxops=28
62-
## type=B
63-
## safe=yes
64-
## nonmal=yes
65-
## dissat=yes
66-
## input=-
67-
## output=1
68-
## timelock_mix=no
69-
## miniscript=
70-
## thresh(3,pk(XPUB1),s:pk(XPUB2),s:pk(XPUB3),s:pk(XPUB4),s:pk(XPUB5),snu:older(100),snu:older(200))
71-
printf "\n"
72-
printf "MinT-002.2"
73-
printf "\n"
74-
printf "
75-
\'$MINT_002_2\'
76+
printf "
77+
$MINT_002_2
7678
"
77-
## 0
78-
## scriptlen=211
79-
## maxops=28
80-
## type=B
81-
## safe=yes
82-
## nonmal=yes
83-
## dissat=yes
84-
## input=-
85-
## output=1
86-
## timelock_mix=no
87-
## miniscript=
88-
## thresh(3,pk(XPUB1),s:pk(XPUB2),s:pk(XPUB3),s:pk(XPUB4),s:pk(XPUB5),snu:after(1694563200),snu:after(1694563200))
89-
printf "\n"
90-
printf "MinT-002.3"
91-
printf "\n"
92-
printf "
93-
\'$MINT_002_3\'
79+
printf "
80+
$MINT_002_3
9481
"
95-
## 0
96-
## scriptlen=211
97-
## maxops=28
98-
## type=B
99-
## safe=yes
100-
## nonmal=yes
101-
## dissat=yes
102-
## input=-
103-
## output=1
104-
## timelock_mix=no
105-
## miniscript=
106-
## thresh(3,pk(XPUB1),s:pk(XPUB2),s:pk(XPUB3),s:pk(XPUB4),s:pk(XPUB5),snu:after(1694563200),snu:after(1694476800))
107-
printf "\n"
108-
printf "MinT-002.4\n"
109-
printf "
110-
\'$MINT_002_4\'
82+
printf "
83+
$MINT_002_4
11184
"
112-
printf "\n"
113-
## 0
114-
## scriptlen=209
115-
## maxops=28
116-
## type=B
117-
## safe=yes
118-
## nonmal=yes
119-
## dissat=yes
120-
## input=-
121-
## output=1
122-
## timelock_mix=no
123-
## miniscript=
124-
## thresh(3,pk(XPUB1),s:pk(XPUB2),s:pk(XPUB3),s:pk(XPUB4),s:pk(XPUB5),snu:older(4194400),snu:older(4194500))
125-
printf "\n"
126-
printf "MinT-003\n"
127-
printf "\n"
128-
printf "
129-
\'$MINT_003\'
85+
printf "
86+
$MINT_003
13087
"
131-
## X
132-
## 647.0300000000
133-
## 420
134-
## or_i(and_v(v:thresh(2,pkh(M1),a:pkh(M2),a:pkh(M3)),after(1005)),and_v(v:thresh(2,pk(A1),s:pk(A2),s:pk(A3),sln:after(1004)),or_i(and_v(vc:or_i(pk_h(SA1),or_i(pk_h(SA2),pk_h(SA3))),after(1003)),thresh(2,pk(P1),s:pk(P2),s:pk(P3),sln:after(1002)))))
135-
## or(99@thresh(2,thresh(2,pk(A1),pk(A2),pk(A3),after(1004)),or(10@thresh(2,pk(P1),pk(P2),pk(P3),after(1002)),and(thresh(1,pk(SA1),pk(SA2),pk(SA3)),after(1003)))),and(thresh(2,pk(M1),pk(M2),pk(M3)),after(1005)))\n"
136-
printf "\n"
137-
printf "MinT-004\n"
138-
printf "\n"
13988
printf "
140-
\'$MINT_004\'
89+
$MINT_004
14190
"
142-
printf "\n"
143-
144-
## X
145-
## 728.6930000000
146-
## 444
147-
## or_i(and_v(v:thresh(2,pkh(M1),a:pkh(M2),a:pkh(M3)),after(1005)),and_v(v:thresh(2,pk(P1),s:pk(P2),s:pk(P3),sun:after(1002),sun:after(1003)),and_v(or_c(pk(SA1),or_c(pk(SA3),v:pkh(SA2))),thresh(2,pk(A1),s:pk(A2),s:pk(A3),sln:after(1004)))))
148-
## or(99@thresh(3,thresh(2,pk(P1),pk(P2),pk(P3),after(1002),after(1003)),thresh(2,pk(A1),pk(A2),pk(A3),after(1004)),thresh(1,pk(SA1),pk(SA2),pk(SA3))),1@and(thresh(2,pk(M1),pk(M2),pk(M3)),after(1005)))
14991
exit
15092
}
15193

@@ -160,25 +102,46 @@ function help {
160102
printf " miniscript-docker help [-h --help]\n"
161103
printf " miniscript-docker build [-b --build]\n"
162104
printf "\n"
163-
printf " miniscript-docker run <miniscript>"
105+
printf " miniscript-docker run '<miniscript>'"
164106
printf "\n"
165107
exit;
166108
}
167109

168-
function build {
110+
function build(){
169111

170-
[ "$NOCACHE" ] && docker build --no-cache -t $TAG . && exit;
171-
[ ! -z "$NOCACHE" ] && docker build $NOCACHE -t $TAG . && exit;
112+
echo $DOCKER
113+
echo $NOCACHE
114+
[ "$NOCACHE" ] && $(which docker) build --no-cache -t $TAG . && exit;
115+
[ ! -z "$NOCACHE" ] && $(which docker) build $NOCACHE -t $TAG . && exit;
172116

173117
}
174118

175-
function run () {
119+
function run(){
176120

177-
docker run --rm -v $PWD:/src $TAG sh -c "echo '$1' | miniscript" && \
178-
exit;
121+
docker-start
122+
echo $2
123+
docker \
124+
run \
125+
--rm \
126+
-v $PWD:/src \
127+
$TAG \
128+
sh \
129+
-c "echo '$2' | ./miniscript-run";exit;
130+
131+
## echo $1
132+
docker \
133+
run \
134+
--rm \
135+
-v $PWD:/src \
136+
$TAG \
137+
sh \
138+
-c "echo '$1' | miniscript";
139+
echo $2
179140

180141
}
181142
function shell (){
143+
144+
docker-start
182145
docker \
183146
run \
184147
-t \
@@ -193,6 +156,8 @@ function shell (){
193156
while test $# -gt 0
194157
do
195158
case "$1" in
159+
start) docker-start; exit
160+
;;
196161
verbose) VERBOSE=1; echo $VERBOSE
197162
;;
198163
--verbose) VERBOSE=1; echo $VERBOSE
@@ -215,13 +180,15 @@ do
215180
;;
216181
-b) build
217182
;;
183+
b) build
184+
;;
218185
make) make
219186
;;
220187
--make) make
221188
;;
222189
-m) make
223190
;;
224-
run) run $2 $3 $4
191+
run) RUN=TRUE && run $2 $3 $4
225192
;;
226193
shell) shell
227194
;;
@@ -244,6 +211,8 @@ do
244211
case "$2" in
245212
## support docker-miniscript build -f
246213
## docker-miniscript -f build
214+
start) docker-start; exit
215+
;;
247216
verbose) VERBOSE=1; echo $VERBOSE
248217
;;
249218
--verbose) VERBOSE=1; echo $VERBOSE

0 commit comments

Comments
 (0)