Skip to content

Commit 8bdedb5

Browse files
committed
Update (2): Check for new releases
1 parent 3d92f26 commit 8bdedb5

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

zphisher.sh

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -164,23 +164,31 @@ kill_pid() {
164164
# Check for a newer release
165165
check_update(){
166166
echo -ne "\n${GREEN}[${WHITE}+${GREEN}]${CYAN} Checking for update : "
167+
BASE_DIR="$(realpath "$(dirname "$BASH_SOURCE")")"
167168
relase_url='https://api.github.com/repos/htr-tech/zphisher/releases/latest'
168169
new_version=$(curl -s "${relase_url}" | grep '"tag_name":' | awk -F\" '{print $4}')
169-
tarball_url=https://github.com/htr-tech/zphisher/archive/refs/tags/${new_version}.tar.gz
170+
tarball_url="https://github.com/htr-tech/zphisher/archive/refs/tags/${new_version}.tar.gz"
170171

171172
if [[ $new_version != $__version__ ]]; then
172-
echo -ne "${ORANGE} update found\n"${WHITE}
173+
echo -ne "${ORANGE}update found\n"${WHITE}
173174
sleep 2
174175
echo -ne "\n${GREEN}[${WHITE}+${GREEN}]${ORANGE} Downloading Update..."
175-
pushd "$BASE_DIR/.." > /dev/null 2>&1
176+
pushd "$HOME" > /dev/null 2>&1
176177
curl --silent --insecure --fail --retry-connrefused \
177178
--retry 3 --retry-delay 2 --location --output ".zphisher.tar.gz" "${tarball_url}"
178-
[[ -e ".zphisher.tar.gz" ]] && tar -xf .zphisher.tar.gz -C "$BASE_DIR" --strip-components 1 > /dev/null 2>&1
179-
rm -f .zphisher.tar.gz
180-
popd > /dev/null 2>&1
181-
{ sleep 3; clear; banner_small; }
182-
echo -ne "\n${GREEN}[${WHITE}+${GREEN}] Successfully updated! Run zphisher again\n\n"${WHITE}
183-
{ reset_color ; exit 1; }
179+
180+
if [[ -e ".zphisher.tar.gz" ]]; then
181+
tar -xf .zphisher.tar.gz -C "$BASE_DIR" --strip-components 1 > /dev/null 2>&1
182+
[ $? -ne 0 ] && { echo -e "\n\n${RED}[${WHITE}!${RED}]${RED} Error occured while extracting."; reset_color; exit 1; }
183+
rm -f .zphisher.tar.gz
184+
popd > /dev/null 2>&1
185+
{ sleep 3; clear; banner_small; }
186+
echo -ne "\n${GREEN}[${WHITE}+${GREEN}] Successfully updated! Run zphisher again\n\n"${WHITE}
187+
{ reset_color ; exit 1; }
188+
else
189+
echo -e "\n${RED}[${WHITE}!${RED}]${RED} Error occured while downloading."
190+
{ reset_color; exit 1; }
191+
fi
184192
else
185193
echo -ne "${GREEN}up to date\n${WHITE}" ; sleep .5
186194
fi

0 commit comments

Comments
 (0)