Last active
January 19, 2023 16:37
-
-
Save spotlightishere/c92a272eaa0310ca1deb to your computer and use it in GitHub Desktop.
A small command to update atom. Please comment if you see anything wrong, I am just beginning to explore bash as a control language.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
########################### | |
#FUNCTIONS and DEFINITIONS# | |
########################### | |
#The following function was taken from https://gist.github.com/crazy-max/5695540. | |
function wgetFilter() { | |
local flag=2 c count cr=$'\r' nl=$'\n' | |
while IFS='' read -d '' -rn 1 c | |
do | |
if [ $flag == 1 ] | |
then | |
printf '%c' "$c" | |
if [[ "$c" =~ (s$) ]] | |
then | |
flag=0 | |
echo "" | |
fi | |
elif [ $flag != 0 ] | |
then | |
if [[ $c != $cr && $c != $nl ]] | |
then | |
count=0 | |
else | |
((count++)) | |
if ((count > 1)) | |
then | |
flag=1 | |
fi | |
fi | |
fi | |
done | |
} | |
GIST_URL="https://gist.github.com/awesomebing1/c92a272eaa0310ca1deb" | |
# End of functions | |
########################### | |
# CODE # | |
########################### | |
# Gaining sudo access. | |
printf "[!] The following code requires super user access. Please enter your password in the prompt below.\n" | |
sudo printf "[-] Thank you, unless you've changed your sudo config you won't have to enter your password again.\n" | |
# A double check to check if we've already downloaded something. | |
if [ ! -f /tmp/atom.deb ]; then | |
# If we have downloaded something, remove it, please. | |
echo "[-] Removing previously downloaded files... " | |
rm -rf /tmp/atom.deb | |
printf "done.\n" | |
fi | |
printf "[+] Now downloading the Atom package: \n" | |
# We've either done nothing or removed stuff. Let's download the file. | |
wget --progress=bar:force "https://atom.io/download/deb" -O /tmp/atom.deb 2>&1 | wgetFilter | |
echo "[-] Checking if download was a success... " | |
if [ -f /tmp/atom.deb ]; then | |
printf "it was. \n" | |
echo "[!] Now installing package." | |
sudo dpkg --install /tmp/atom.deb | |
if [ $? -eq 0 ]; then | |
echo "[-] Now upgrading all Atom packages." | |
apm upgrade --confirm false | |
if [ $? -eq 0 ]; then | |
echo "[-] We're done! Enjoy your new version of Atom!" | |
exit 0 | |
else | |
echo "[!] For some reason, your Atom packages did not upgrade." | |
echo "[!] If this was reached, please comment on the following gist: $(GIST_URL)" | |
echo "[!] Exiting." | |
exit 213 | |
fi | |
else | |
echo "[!] For some reason, dpkg failed to install atom." | |
echo "[!] If this was reached, please comment on the following gist: $(GIST_URL)" | |
exit 212 | |
fi | |
else | |
printf "it was not. \n" | |
echo "If this was an error, please comment on the following gist: $(GIST_URL)" | |
exit 211 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment