Skip to content

Commit

Permalink
feat: fixed update only for amd64 for now
Browse files Browse the repository at this point in the history
refactor: removed useless conditional checks
  • Loading branch information
AyushSehrawat committed Apr 19, 2023
1 parent ef01f75 commit 7de9b4c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 31 deletions.
7 changes: 1 addition & 6 deletions neurons/discord.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,11 @@ update() {
}

if [[ $1 =~ (-install) ]]; then
# check if current version is 0.0.0 ( which means not installed )
if [[ "$CURRENT_VERSION" == "0.0.0" ]]; then
echo "Installing Discord..."
unpack
else
echo "Discord is already installed ($CURRENT_VERSION)."
read -r -p "Do you want to update discord? (y/n) " answer
if [[ $answer =~ ^([yY][eE][sS]|[yY])$ ]]; then
update
fi
echo "Discord is already installed ($CURRENT_VERSION). If you want to update use brain update <name>."
fi
echo "Downloading Discord $LATEST_VERSION..."
unpack
Expand Down
27 changes: 12 additions & 15 deletions neurons/edge.sh
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
#!/bin/bash

ARCH=$(uname -m)
PACKAGE_MANAGER=
PACKAGE_MANAGER_UPDATE_CMD=
PACKAGE_MANAGER_INSTALL_CMD=
PACKAGE_MANAGER_UNINSTALL_CMD=

case "$ARCH" in
x86_64 | amd64)
if [ -x "$(command -v dpkg)" ]; then
PACKAGE_MANAGER="apt-get"
PACKAGE_MANAGER_UPDATE_CMD="sudo dpkg -i ./microsoft-edge-stable_*.deb"
PACKAGE_MANAGER_INSTALL_CMD="sudo dpkg -i ./microsoft-edge-stable_*.deb"
PACKAGE_MANAGER_UNINSTALL_CMD="sudo apt remove microsoft-edge-stable"
URL=$(curl -s https://packages.microsoft.com/repos/edge/pool/main/m/microsoft-edge-stable/ | grep -o '<a href="[^"]*deb"' | grep -o '[^"]*deb' | sort -V | tail -n 1 | awk '{print "https://packages.microsoft.com/repos/edge/pool/main/m/microsoft-edge-stable/"$0}')
elif [ -x "$(command -v rpm)" ]; then
PACKAGE_MANAGER="dnf"
PACKAGE_MANAGER_UPDATE_CMD="sudo rpm -i ./microsoft-edge-stable_*.rpm"
PACKAGE_MANAGER_INSTALL_CMD="sudo rpm -U ./microsoft-edge-stable_*.rpm"
PACKAGE_MANAGER_UNINSTALL_CMD="sudo rpm -e microsoft-edge-stable"
Expand All @@ -33,10 +30,6 @@ esac

case "$1" in
-install)
if [ -z "$PACKAGE_MANAGER" ]; then
echo "Unknown package manager"
exit 1
fi
if [ ! -f "$(basename "$URL")" ]; then
echo "Downloading package..."
curl -O "$URL"
Expand All @@ -47,11 +40,19 @@ case "$1" in
echo "Done!"
;;
-update)
if [ -z "$PACKAGE_MANAGER" ]; then
echo "Unknown package manager"
exit 1
fi
echo "Updating package..."
if [ "$ARCH" = "amd64" ]; then
VERSION_URL=$(curl -s https://packages.microsoft.com/repos/edge/pool/main/m/microsoft-edge-stable/ | grep -o '<a href="[^"]*deb"' | grep -o '[^"]*deb' | sort -V | tail -n 1)
LATEST_WEB_VERSION=$(basename "$VERSION_URL" | grep -oP "(?<=microsoft-edge-stable_)\d+(\.\d+)+(-\d+)?")
LATEST_LOCAL_VERSION=$(dpkg -s microsoft-edge-stable | grep Version | awk '{print $2}')
fi
echo "Latest web version: $LATEST_WEB_VERSION"
echo "Latest local version: $LATEST_LOCAL_VERSION"
if [ "$LATEST_WEB_VERSION" = "$LATEST_LOCAL_VERSION" ]; then
echo "Already up to date!"
exit 0
fi

if [ ! -f "$(basename "$URL")" ]; then
echo "Downloading package..."
curl -O "$URL"
Expand All @@ -61,10 +62,6 @@ case "$1" in
echo "Done!"
;;
-uninstall)
if [ -z "$PACKAGE_MANAGER" ]; then
echo "Unknown package manager"
exit 1
fi
echo "Uninstalling package..."
$PACKAGE_MANAGER_UNINSTALL_CMD
echo "Done!"
Expand Down
6 changes: 1 addition & 5 deletions neurons/golang.sh
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,7 @@ if [[ $1 =~ (-install) ]]; then
echo "Installing Go..."
unpack
else
echo "Go is already installed ($CURRENT_VERSION)."
read -r -p "Do you want to update Go? (y/n) " answer
if [[ $answer =~ ^([yY][eE][sS]|[yY])$ ]]; then
update
fi
echo "Go is already installed ($CURRENT_VERSION). If you want to update use brain update <name>"
fi
elif [[ $1 =~ (-update) ]]; then
update
Expand Down
6 changes: 1 addition & 5 deletions neurons/vscode.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,7 @@ if [[ $1 =~ (-install) ]]; then
echo "Installing Visual Studio Code..."
unpack
else
echo "Visual Studio Code is already installed ($CURRENT_VERSION)."
read -r -p "Do you want to update Visual Studio Code? (y/n) " answer
if [[ $answer =~ ^([yY][eE][sS]|[yY])$ ]]; then
update
fi
echo "Visual Studio Code is already installed ($CURRENT_VERSION). If you want to update use brain update <name>"
fi
elif [[ $1 =~ (-update) ]]; then
update
Expand Down

0 comments on commit 7de9b4c

Please sign in to comment.