Skip to content

Commit 87c5394

Browse files
authored
Clean up install.sh (ordinals#2669)
1 parent 64434e4 commit 87c5394

File tree

1 file changed

+28
-35
lines changed

1 file changed

+28
-35
lines changed

install.sh

Lines changed: 28 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env bash
22

33
set -euo pipefail
4+
45
if [ ! -z ${GITHUB_ACTIONS-} ]; then
56
set -x
67
fi
@@ -10,7 +11,7 @@ help() {
1011
Install a binary release of ord hosted on GitHub
1112
1213
USAGE:
13-
install [options]
14+
install.sh [options]
1415
1516
FLAGS:
1617
-h, --help Display this message
@@ -23,25 +24,20 @@ OPTIONS:
2324
EOF
2425
}
2526

26-
git=ordinals/ord
2727
crate=ord
2828
url=https://github.com/ordinals/ord
2929
releases=$url/releases
3030

3131
say() {
32-
echo "install: $@"
33-
}
34-
35-
say_err() {
36-
say "$@" >&2
32+
echo "install.sh: $*" >&2
3733
}
3834

3935
err() {
40-
if [ ! -z ${td-} ]; then
41-
rm -rf $td
36+
if [ ! -z ${tempdir-} ]; then
37+
rm -rf $tempdir
4238
fi
4339

44-
say_err "error: $@"
40+
say "error: $*"
4541
exit 1
4642
}
4743

@@ -86,17 +82,11 @@ need mkdir
8682
need mktemp
8783
need tar
8884

89-
# Optional dependencies
85+
dest=${dest-"$HOME/bin"}
86+
9087
if [ -z ${tag-} ]; then
9188
need cut
92-
need rev
93-
fi
9489

95-
if [ -z ${dest-} ]; then
96-
dest="$HOME/bin"
97-
fi
98-
99-
if [ -z ${tag-} ]; then
10090
tag=$(curl --proto =https --tlsv1.2 -sSf https://api.github.com/repos/ordinals/ord/releases/latest |
10191
grep tag_name |
10292
cut -d'"' -f4
@@ -111,34 +101,37 @@ if [ -z ${target-} ]; then
111101
x86_64-Darwin) target=x86_64-apple-darwin;;
112102
x86_64-Linux) target=x86_64-unknown-linux-gnu;;
113103
*)
114-
err 'Could not determine target from output of `uname -m`-`uname -s`, please use `--target`:' $uname_target
115-
err 'Target architecture is not supported by this install script.'
116-
err 'Consider opening an issue or building from source: https://github.com/ordinals/ord'
104+
say 'Could not determine target from output of `uname -m`-`uname -s`, please use `--target`:' $uname_target
105+
say 'Target architecture is not supported by this install script.'
106+
say 'Consider opening an issue or building from source: https://github.com/ordinals/ord'
107+
exit 1
117108
;;
118109
esac
119110
fi
120111

121112
archive="$releases/download/$tag/$crate-$tag-$target.tar.gz"
122113

123-
say_err "Repository: $url"
124-
say_err "Crate: $crate"
125-
say_err "Tag: $tag"
126-
say_err "Target: $target"
127-
say_err "Destination: $dest"
128-
say_err "Archive: $archive"
114+
say "Repository: $url"
115+
say "Crate: $crate"
116+
say "Tag: $tag"
117+
say "Target: $target"
118+
say "Destination: $dest"
119+
say "Archive: $archive"
120+
121+
tempdir=`mktemp -d || mktemp -d -t tmp`
129122

130-
td=$(mktemp -d || mktemp -d -t tmp)
131-
curl --proto =https --tlsv1.2 -sSfL $archive | tar --directory $td --strip-components 1 -xz
123+
curl --proto =https --tlsv1.2 -sSfL $archive | tar --directory $tempdir --strip-components 1 -xz
132124

133-
for f in $(ls $td); do
134-
test -x $td/$f || continue
125+
for name in `ls $tempdir`; do
126+
file="$tempdir/$name"
127+
test -x $file || continue
135128

136-
if [ -e "$dest/$f" ] && [ $force = false ]; then
137-
err "$f already exists in $dest"
129+
if [ -e "$dest/$name" ] && [ $force = false ]; then
130+
err "$name already exists in $dest"
138131
else
139132
mkdir -p $dest
140-
install -m 755 $td/$f $dest
133+
install -m 755 $file $dest
141134
fi
142135
done
143136

144-
rm -rf $td
137+
rm -rf $tempdir

0 commit comments

Comments
 (0)