@@ -6,7 +6,7 @@ RED='\033[0;31m'
6
6
GREEN=' \033[0;32m'
7
7
YELLOW=' \033[1;33m'
8
8
ORANGE=' \033[38;2;255;140;0m'
9
- NC=' \033[0m' # No Color
9
+ NC=' \033[0m'
10
10
11
11
requested_version=${VERSION:- }
12
12
17
17
arch=$( uname -m)
18
18
19
19
if [[ " $arch " == " aarch64" ]]; then
20
- arch=" arm64"
20
+ arch=" arm64"
21
21
fi
22
22
23
23
filename=" $APP -$os -$arch .tar.gz"
24
24
25
-
26
25
case " $filename " in
27
- * " -linux-" * )
28
- [[ " $arch " == " x86_64" || " $arch " == " arm64" || " $arch " == " i386" ]] || exit 1
26
+ * " -linux-" * )
27
+ [[ " $arch " == " x86_64" || " $arch " == " arm64" || " $arch " == " i386" ]] || exit 1
29
28
;;
30
- * " -mac-" * )
31
- [[ " $arch " == " x86_64" || " $arch " == " arm64" ]] || exit 1
29
+ * " -mac-" * )
30
+ [[ " $arch " == " x86_64" || " $arch " == " arm64" ]] || exit 1
32
31
;;
33
- * )
34
- echo " ${RED} Unsupported OS/Arch: $os /$arch ${NC} "
35
- exit 1
32
+ * )
33
+ echo " ${RED} Unsupported OS/Arch: $os /$arch ${NC} "
34
+ exit 1
36
35
;;
37
36
esac
38
37
@@ -58,9 +57,9 @@ print_message() {
58
57
local color=" "
59
58
60
59
case $level in
61
- info) color=" ${GREEN} " ;;
62
- warning) color=" ${YELLOW} " ;;
63
- error) color=" ${RED} " ;;
60
+ info) color=" ${GREEN} " ;;
61
+ warning) color=" ${YELLOW} " ;;
62
+ error) color=" ${RED} " ;;
64
63
esac
65
64
66
65
echo -e " ${color}${message}${NC} "
@@ -70,7 +69,6 @@ check_version() {
70
69
if command -v opencode > /dev/null 2>&1 ; then
71
70
opencode_path=$( which opencode)
72
71
73
-
74
72
# # TODO: check if version is installed
75
73
# installed_version=$(opencode version)
76
74
installed_version=" 0.0.1"
@@ -87,23 +85,22 @@ check_version() {
87
85
88
86
download_and_install () {
89
87
print_message info " Downloading ${ORANGE} opencode ${GREEN} version: ${YELLOW} $specific_version ${GREEN} ..."
90
- mkdir -p opencodetmp && cd opencodetmp
88
+ temp_dir= $( mktemp -d ) && cd " $temp_dir "
91
89
curl -# -L $url | tar xz
92
90
mv opencode $INSTALL_DIR
93
- cd .. && rm -rf opencodetmp
91
+ cd .. && rm -rf opencodetmp
94
92
}
95
93
96
94
check_version
97
95
download_and_install
98
96
99
-
100
97
add_to_path () {
101
98
local config_file=$1
102
99
local command=$2
103
100
104
101
if [[ -w $config_file ]]; then
105
- echo -e " \n# opencode" >> " $config_file "
106
- echo " $command " >> " $config_file "
102
+ echo -e " \n# opencode" >> " $config_file "
103
+ echo " $command " >> " $config_file "
107
104
print_message info " Successfully added ${ORANGE} opencode ${GREEN} to \$ PATH in $config_file "
108
105
else
109
106
print_message warning " Manually add the directory to $config_file (or similar):"
@@ -115,24 +112,24 @@ XDG_CONFIG_HOME=${XDG_CONFIG_HOME:-$HOME/.config}
115
112
116
113
current_shell=$( basename " $SHELL " )
117
114
case $current_shell in
118
- fish)
119
- config_files=" $HOME /.config/fish/config.fish"
115
+ fish)
116
+ config_files=" $HOME /.config/fish/config.fish"
120
117
;;
121
- zsh)
122
- config_files=" $HOME /.zshrc $HOME /.zshenv $XDG_CONFIG_HOME /zsh/.zshrc $XDG_CONFIG_HOME /zsh/.zshenv"
118
+ zsh)
119
+ config_files=" $HOME /.zshrc $HOME /.zshenv $XDG_CONFIG_HOME /zsh/.zshrc $XDG_CONFIG_HOME /zsh/.zshenv"
123
120
;;
124
- bash)
125
- config_files=" $HOME /.bashrc $HOME /.bash_profile $HOME /.profile $XDG_CONFIG_HOME /bash/.bashrc $XDG_CONFIG_HOME /bash/.bash_profile"
121
+ bash)
122
+ config_files=" $HOME /.bashrc $HOME /.bash_profile $HOME /.profile $XDG_CONFIG_HOME /bash/.bashrc $XDG_CONFIG_HOME /bash/.bash_profile"
126
123
;;
127
- ash)
128
- config_files=" $HOME /.ashrc $HOME /.profile /etc/profile"
124
+ ash)
125
+ config_files=" $HOME /.ashrc $HOME /.profile /etc/profile"
129
126
;;
130
- sh)
131
- config_files=" $HOME /.ashrc $HOME /.profile /etc/profile"
127
+ sh)
128
+ config_files=" $HOME /.ashrc $HOME /.profile /etc/profile"
132
129
;;
133
- * )
134
- # Default case if none of the above matches
135
- config_files=" $HOME /.bashrc $HOME /.bash_profile $XDG_CONFIG_HOME /bash/.bashrc $XDG_CONFIG_HOME /bash/.bash_profile"
130
+ * )
131
+ # Default case if none of the above matches
132
+ config_files=" $HOME /.bashrc $HOME /.bash_profile $XDG_CONFIG_HOME /bash/.bashrc $XDG_CONFIG_HOME /bash/.bash_profile"
136
133
;;
137
134
esac
138
135
@@ -149,32 +146,33 @@ if [[ -z $config_file ]]; then
149
146
exit 1
150
147
fi
151
148
152
- if [[ " :$PATH :" != * " :$INSTALL_DIR :" * ]]; then
149
+ if [[ " :$PATH :" == * " :$INSTALL_DIR :" * ]]; then
150
+ print_message info " PATH already contains install directory: $INSTALL_DIR "
151
+ else
153
152
case $current_shell in
154
- fish)
155
- add_to_path " $config_file " " fish_add_path $INSTALL_DIR "
153
+ fish)
154
+ add_to_path " $config_file " " fish_add_path $INSTALL_DIR "
156
155
;;
157
- zsh)
158
- add_to_path " $config_file " " export PATH=$INSTALL_DIR :\$ PATH"
156
+ zsh)
157
+ add_to_path " $config_file " " export PATH=$INSTALL_DIR :\$ PATH"
159
158
;;
160
- bash)
161
- add_to_path " $config_file " " export PATH=$INSTALL_DIR :\$ PATH"
159
+ bash)
160
+ add_to_path " $config_file " " export PATH=$INSTALL_DIR :\$ PATH"
162
161
;;
163
- ash)
164
- add_to_path " $config_file " " export PATH=$INSTALL_DIR :\$ PATH"
162
+ ash)
163
+ add_to_path " $config_file " " export PATH=$INSTALL_DIR :\$ PATH"
165
164
;;
166
- sh)
167
- add_to_path " $config_file " " export PATH=$INSTALL_DIR :\$ PATH"
165
+ sh)
166
+ add_to_path " $config_file " " export PATH=$INSTALL_DIR :\$ PATH"
168
167
;;
169
- * )
170
- print_message warning " Manually add the directory to $config_file (or similar):"
171
- print_message info " export PATH=$INSTALL_DIR :\$ PATH"
168
+ * )
169
+ print_message warning " Manually add the directory to $config_file (or similar):"
170
+ print_message info " export PATH=$INSTALL_DIR :\$ PATH"
172
171
;;
173
172
esac
174
173
fi
175
174
176
175
if [ -n " ${GITHUB_ACTIONS-} " ] && [ " ${GITHUB_ACTIONS} " == " true" ]; then
177
- echo " $INSTALL_DIR " >> $GITHUB_PATH
176
+ echo " $INSTALL_DIR " >> $GITHUB_PATH
178
177
print_message info " Added $INSTALL_DIR to \$ GITHUB_PATH"
179
178
fi
180
-
0 commit comments