-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·105 lines (71 loc) · 3.05 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·105 lines (71 loc) · 3.05 KB
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
#!/bin/sh
# MIT License
# Copyright (c) 2026 Geoffrey Gontard
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
REPO='ggtrd/kontext'
# Stop script if missing dependency
required_commands="curl git unzip"
for command in $required_commands; do
if [ -z "$(command -v $command)" ]; then
echo "error: required command not found: $command"
exit
fi
done
REPO_URL="https://github.com/$REPO"
MAIN_NAME="$(echo $REPO | cut -d/ -f2)"
LATEST_TAG="$(git ls-remote --tags $REPO_URL | sed 's|.*tags/\(.*\)|\1|' | tail -n 1)"
ARTIFACT_URL="https://github.com/$REPO/archive/refs/tags/$LATEST_TAG.zip"
INSTALL_DIR="$HOME/.local/bin"
# CONFIG_DIR="$HOME/.config/$MAIN_NAME"
# VERSION_FILE="$CONFIG_DIR/$MAIN_NAME.version"
# Download $ARTIFACT_URL from release
# Usage: donwload_artifact
donwload_artifact() {
local tmp_path="/tmp/$MAIN_NAME"
local archive_path="$tmp_path.zip"
# Clean /tmp before get new files
rm -rf $tmp_path
rm -rf $archive_path
# Download and extract
curl -ksL $ARTIFACT_URL > $archive_path
unzip -qd $tmp_path/ $archive_path
}
# Install given file (downloaded from $ARTIFACT_URL) to $PATH
# Usage: install_artifact <downloaded_zip_sub_path>
install_artifact() {
local artifact_sub_path="$1"
if [ ! -f "$artifact_sub_path" ]; then
echo "error: missing artifact from $artifact_sub_path"
return
fi
# Ensure dir exists
mkdir -p $INSTALL_DIR
# Install the artifact
cp $artifact_sub_path "$INSTALL_DIR/$MAIN_NAME"
}
donwload_artifact # https://github.com/ggtrd/kontext/archive/refs/tags/tag.zip -> download + extract to /tmp/kontext/
install_artifact "/tmp/$MAIN_NAME/$MAIN_NAME-$LATEST_TAG/$MAIN_NAME.sh" # /tmp/kontext/kontext-tag/kontext.sh -> copy to $HOME/.bin/local/kontext.sh
# Simple log message
if [ -f "$INSTALL_DIR/$MAIN_NAME" ]; then
echo 'successful installation !'
echo "usage: $MAIN_NAME"
echo ''
echo 'you may need to reload your Shell'
else
echo "error: $MAIN_NAME not installed"
fi
exit