Skip to content

Commit de1c9f4

Browse files
authored
Merge pull request #14 from Yakiyo:feature/install-script
bash installation script
2 parents ec06d69 + 4130af5 commit de1c9f4

File tree

3 files changed

+197
-2
lines changed

3 files changed

+197
-2
lines changed

.changeset/wise-snails-type.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"dsm": patch
3+
---
4+
5+
Shell script to install dsm

.github/workflows/release.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,7 @@ jobs:
106106
esac;
107107
BIN_NAME="${{ needs.crate_metadata.outputs.name }}${EXE_suffix}"
108108
BIN_PATH="target/${{ matrix.target }}/release/${BIN_NAME}"
109-
BUILD_NAME="${{ needs.crate_metadata.outputs.name }}-${{
110-
needs.crate_metadata.outputs.version }}-${{ matrix.target
109+
BUILD_NAME="${{ needs.crate_metadata.outputs.name }}-${{ matrix.target
111110
}}${EXE_suffix}"
112111
mv ${BIN_PATH} ${BUILD_NAME}
113112

tools/install.sh

+191
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
OS=$(echo `uname -s`|tr '[:upper:]' '[:lower:]')
6+
7+
case "$OS" in
8+
mingw*) OS='windows';;
9+
msys*) OS='windows';;
10+
esac
11+
12+
VERSION="latest"
13+
INSTALL_DIR="$HOME/.dsm"
14+
FILE=""
15+
16+
# TODO: Implement this
17+
show_help() {
18+
echo "dsm installation script"
19+
echo ""
20+
echo "USAGE:"
21+
echo " ./install.sh [OPTIONS]"
22+
echo ""
23+
echo "OPTIONS:"
24+
echo " -d, --install-dir Directory to install to."
25+
echo " -s, --skip-shell Skip shell setup"
26+
echo " -v, --version The version of dsm to install"
27+
echo " -F, --filename Manually override the filename of dsm to use."
28+
echo ""
29+
echo "For any queries, help or bug, please open an issue at https://github.com/Yakiyo/dsm/issues"
30+
31+
exit 0
32+
}
33+
34+
clap() {
35+
while [[ $# -gt 0 ]]; do
36+
key="$1"
37+
38+
case $key in
39+
-h | --help)
40+
show_help
41+
;;
42+
-d | --install-dir)
43+
INSTALL_DIR="$2"
44+
shift
45+
shift
46+
;;
47+
-s | --skip-shell)
48+
SKIP_SHELL="true"
49+
shift
50+
;;
51+
-v | --version)
52+
VERSION="$2"
53+
shift
54+
shift
55+
;;
56+
-F | --filename)
57+
FILENAME="$2"
58+
shift
59+
shift
60+
;;
61+
*)
62+
echo "Unrecognized argument $key. Use the `--help` flag to see usage"
63+
exit 1
64+
;;
65+
esac
66+
done
67+
}
68+
69+
# Duct taped this to somewhat work
70+
filename() {
71+
if [ "$OS" = "linux" ]; then
72+
case "$(uname -m)" in
73+
arm | armv7*)
74+
FILENAME="arm-unknown-linux-gnueabihf"
75+
;;
76+
*)
77+
FILENAME="x86_64-unknown-linux-musl"
78+
esac
79+
elif [ "$OS" = "darwin" ]; then
80+
FILENAME="x86_64-apple-darwin"
81+
elif [ "$OS" = "windows" ]; then
82+
FILENAME="x86_64-pc-windows-msvc.exe"
83+
else
84+
echo "OS $OS is not supported."
85+
echo "If you think that's a bug - please file an issue to https://github.com/Yakiyo/dsm/issues"
86+
exit 1
87+
fi
88+
FILE="dsm-$FILENAME"
89+
}
90+
91+
download () {
92+
if [ "$VERSION" = "latest" ]; then
93+
URL="https://github.com/Yakiyo/dsm/releases/latest/download/$FILE"
94+
else
95+
URL="https://github.com/Yakiyo/dsm/releases/download/$VERSION/$FILE"
96+
fi
97+
echo "Downloading from $URL ...."
98+
99+
TMP=$(mktemp -d)
100+
mkdir -p "$INSTALL_DIR" &>/dev/null
101+
102+
if ! curl --progress-bar --fail -L "$URL" -o "$TMP/$FILE"; then
103+
echo "Download failed. Check that the release/filename are correct."
104+
exit 1
105+
fi
106+
107+
EXE=""
108+
if [ "$OS" = "windows" ]; then
109+
EXE=".exe"
110+
fi
111+
112+
mv "$TMP/$FILE" "$INSTALL_DIR/dsm$EXE"
113+
114+
chmod u+x "$INSTALL_DIR/dsm$EXE"
115+
}
116+
117+
ensure_dir () {
118+
local CONTAINING_DIR
119+
CONTAINING_DIR="$(dirname "$1")"
120+
if [ ! -d "$CONTAINING_DIR" ]; then
121+
echo " >> Creating directory $CONTAINING_DIR"
122+
mkdir -p "$CONTAINING_DIR"
123+
fi
124+
}
125+
126+
# Courtesy of https://github.com/Schniz/fnm/blob/master/.ci/install.sh
127+
setup_shell() {
128+
CURRENT_SHELL="$(basename "$SHELL")"
129+
130+
if [ "$CURRENT_SHELL" = "zsh" ]; then
131+
CONF_FILE=${ZDOTDIR:-$HOME}/.zshrc
132+
ensure_dir "$CONF_FILE"
133+
echo "Installing for Zsh. Appending the following to $CONF_FILE:"
134+
echo ""
135+
echo ' # dsm'
136+
echo ' export PATH="'"$INSTALL_DIR"':$PATH"'
137+
echo ' eval "`dsm env`"'
138+
139+
echo '' >>$CONF_FILE
140+
echo '# dsm' >>$CONF_FILE
141+
echo 'export PATH="'$INSTALL_DIR':$PATH"' >>$CONF_FILE
142+
echo 'eval "`dsm env`"' >>$CONF_FILE
143+
144+
elif [ "$CURRENT_SHELL" = "fish" ]; then
145+
CONF_FILE=$HOME/.config/fish/conf.d/dsm.fish
146+
ensure_dir "$CONF_FILE"
147+
echo "Installing for Fish. Appending the following to $CONF_FILE:"
148+
echo ""
149+
echo ' # dsm'
150+
echo ' set PATH "'"$INSTALL_DIR"'" $PATH'
151+
echo ' dsm env | source'
152+
153+
echo '# dsm' >>$CONF_FILE
154+
echo 'set PATH "'"$INSTALL_DIR"'" $PATH' >>$CONF_FILE
155+
echo 'dsm env | source' >>$CONF_FILE
156+
157+
elif [ "$CURRENT_SHELL" = "bash" ]; then
158+
if [ "$OS" = "Darwin" ]; then
159+
CONF_FILE=$HOME/.profile
160+
else
161+
CONF_FILE=$HOME/.bashrc
162+
fi
163+
ensure_dir "$CONF_FILE"
164+
echo "Installing for Bash. Appending the following to $CONF_FILE:"
165+
echo ""
166+
echo ' # dsm'
167+
echo ' export PATH="'"$INSTALL_DIR"':$PATH"'
168+
echo ' eval "`dsm env`"'
169+
170+
echo '' >>$CONF_FILE
171+
echo '# dsm' >>$CONF_FILE
172+
echo 'export PATH="'"$INSTALL_DIR"':$PATH"' >>$CONF_FILE
173+
echo 'eval "`dsm env`"' >>$CONF_FILE
174+
175+
else
176+
echo "Could not infer shell type. Please set up manually."
177+
exit 1
178+
fi
179+
180+
echo ""
181+
echo "In order to apply the changes, open a new terminal or run the following command:"
182+
echo ""
183+
echo " source $CONF_FILE"
184+
}
185+
186+
filename
187+
clap "$@"
188+
download
189+
if [ "$SKIP_SHELL" != "true" ]; then
190+
setup_shell
191+
fi

0 commit comments

Comments
 (0)