Lightcord/LULI.sh

344 lines
12 KiB
Bash
Raw Normal View History

2021-04-25 19:18:44 +02:00
#!/bin/sh
# Lightcord unified Linux installer by https://github.com/GermanBread
2021-04-25 19:18:44 +02:00
# POSIX compliance by https://github.com/pryme-svg
2021-01-05 18:40:21 +01:00
#
# CHANGE STUFF HERE
#
# Change this to anything other than "false" to allow installing under NixOS
# Ideally you'd also change $GLOBAL_INSTALL_DIR while you're at it
ALLOW_NIXOS='false'
2021-04-19 11:10:01 +02:00
# If set to anything other than "false" this will allow you to modify the Lightcord installation even if it was
BYPASS_PACKAGEMANAGER='false'
# Make sure to trim the trailing forward-slash (/)
GLOBAL_INSTALL_DIR='/opt'
LOCAL_INSTALL_DIR="$HOME/.lightcord"
#
# DON'T TOUCH BELOW HERE
#
2021-01-15 14:30:19 +01:00
# URL for downloads
ICON='https://raw.githubusercontent.com/Lightcord/Lightcord/master/discord.png'
LC_APPIMAGE='https://lightcord.org/api/gh/releases/Lightcord/Lightcord/dev/lightcord-linux-x86_64.AppImage'
LC='https://lightcord.org/api/v1/gh/releases/Lightcord/Lightcord/dev/lightcord-linux-x64.zip'
2021-01-15 14:30:19 +01:00
# Fallback URL
ALT_LC_APPIMAGE='https://github.com/Lightcord/Lightcord/releases/latest/download/Lightcord-linux-x86_64.AppImage'
ALT_LC='https://github.com/Lightcord/Lightcord/releases/latest/download/lightcord-linux-x64.zip'
2021-01-05 18:40:21 +01:00
# Some helper funtions
2021-04-25 19:18:44 +02:00
Info() {
2021-01-05 18:40:21 +01:00
tput setaf 8
tput bold
printf "==> "
tput setaf 15
printf "$1\n"
tput sgr0
}
2021-04-25 19:18:44 +02:00
SubInfo() {
2021-01-05 18:40:21 +01:00
tput setaf 8
printf "> "
printf "$1\n"
tput sgr0
}
2021-04-25 19:18:44 +02:00
Warning() {
2021-01-05 18:40:21 +01:00
tput setaf 3
tput bold
printf "==> "
tput setaf 11
printf "$1\n"
tput sgr0
}
2021-04-25 19:18:44 +02:00
Error() {
2021-01-05 18:40:21 +01:00
tput setaf 1
tput bold
printf "==> "
tput setaf 9
printf "$1\n"
tput sgr0
}
2021-04-25 19:18:44 +02:00
if [ "$TERM" = dumb ]; then
2021-05-03 22:04:05 +02:00
exit 0
2021-01-05 18:40:21 +01:00
fi
2021-04-25 20:44:23 +02:00
if [ $(id -u) -eq 0 ]; then
2021-01-05 18:40:21 +01:00
Error "Don't run this script as root"
2021-05-03 22:04:05 +02:00
exit 0
2021-01-05 18:40:21 +01:00
fi
2021-05-03 22:30:20 +02:00
# Bedrock Linux warning
if [ -d /bedrock ]; then
Info "Bedrock Linux detected. Here be dragons..."
SubInfo "This script is executed in the $(tput bold && tput setaf 15 && brl which | tr -d '\n') stratum$(tput sgr0 && tput setaf 8). Mention this when filing a bug report!"
fi
2021-02-13 16:22:36 +01:00
# Check if unzip is installed
2021-05-03 22:04:05 +02:00
if [ ! -e /bin/unzip ]; then
Warning "Unzip does not seem to be installed!\n\tThis script depends on this package.\n\tInstall unzip and restart this script."
Info "Press enter if you believe that this is a false-positive."
2021-04-25 19:18:44 +02:00
read -r REPLY
2021-02-13 16:22:36 +01:00
fi
2021-05-03 22:04:05 +02:00
# Library checks (should prevent issues like https://github.com/Lightcord/Lightcord/issues/240)
if [ ! -e /lib/libnspr4.so ] || [ ! -e /lib/libnss3.so ]; then
Warning "Some required libraries seem to not be installed!\n\tMake sure that both 'libnspr4.so' and 'libnss3.so' are present in '/lib'"
2021-05-03 22:24:28 +02:00
if [ -e /bin/pacman ]; then
SubInfo "$(tput setaf 12 && tput bold)Arch Linux or Arch-based$(tput sgr0 && tput setaf 15) sudo pacman -S nss nspr"
fi
if [ -e /bin/apt ]; then
SubInfo "$(tput setaf 13 && tput bold)Debian or Debian-based$(tput sgr0 && tput setaf 15) sudo apt install libnspr4 libnss3"
fi
2021-05-03 22:04:05 +02:00
Info "Press enter if you believe that this is a false-positive."
read -r REPLY
fi
2021-01-05 18:40:21 +01:00
cat << "logo_end"
_ _ _ _ _
| | (_)__ _| |_| |_ __ ___ _ _ __| |
| |__| / _` | ' \ _/ _/ _ \ '_/ _` |
|____|_\__, |_||_\__\__\___/_| \__,_|
|___/
Unified Linux Installer and Updater
logo_end
# First, we need to figure out what kind of install the user wants (AppImage or System-wide?)
printf "Please select\n"
printf "1: Install Lightcord for all users\n"
printf "2: Install Lightcord only for you (Appimage install)\n"
printf "\n"
#Repeat only if the user hasn't entered an integer...
2021-04-25 19:18:44 +02:00
while ! echo $method | grep -Eq "^[0-9]";
2021-01-05 18:40:21 +01:00
do
2021-04-25 19:18:44 +02:00
read -r method;
2021-01-05 18:40:21 +01:00
# If the entered value was not an integer, prompt the user again
2021-04-25 19:18:44 +02:00
if ! echo $method | grep -Eq "^[0-9]"; then
2021-01-05 18:40:21 +01:00
sleep 1
printf "$(tput setaf 9)Please try again$(tput sgr0)\n"
printf "1: Install Lightcord for all users\n"
printf "2: Install Lightcord only for you (Appimage install)\n"
printf "\n"
fi
done
2021-04-25 19:18:44 +02:00
if [ "$method" = 1 ]; then
2021-04-19 11:10:01 +02:00
# If there isn't a indicator file present, refuse to continue
2021-04-25 19:18:44 +02:00
if { [ -d /opt/lightcord ] || [ -d /opt/Lightcord ]; } && [ ! -e $GLOBAL_INSTALL_DIR/Lightcord/script_check ] && [ $BYPASS_PACKAGEMANAGER = 'false' ]; then
2021-04-19 11:12:42 +02:00
Error "Lightcord has been installed via a package manager; refusing to continue.\n\tChange variable BYPASS_PACKAGEMANAGER to anything other than \"false\" if you believe that this is a false positive"
2021-04-19 11:10:01 +02:00
exit 1
fi
2021-04-25 19:18:44 +02:00
Warning "Warning:\n\tBlindly running software as root is a massive security issue.\n\tIf you don't fully trust the software you're running DON'T RUN IT AS ROOT.\n\tIf you know exactly what you are doing, continue.\n\tOtherwise restart this script and choose the second option."
2021-04-25 19:18:44 +02:00
if [ -d "/nix" ] && [ $ALLOW_NIXOS = 'false' ]; then
2021-04-19 11:10:01 +02:00
Error "Error:\n\tUsing the global install option on NixOS is not supported due to the way this distribution handles software not present in the repositories.\n\tUse the AppImage install method instead.\n\tIf you still plan on installing Lightcord this way, change the \"ALLOW_NIXOS\" variable in this script to any value other than \"false\".\n\tYou should also modify the installation path variables if you want LC to not be wiped automatically at boot."
exit 1
fi # We want to prevent NixOS users from installing LC this way because:
# A) NixOS is very "special" i.e. it blocks LC from running
# B) /opt gets cleared upon boot
Info "Please enter your password to proceed"
2021-01-05 20:32:11 +01:00
sudo -K
2021-04-25 19:18:44 +02:00
if [ "$(sudo whoami)" != "root" ]; then
2021-01-05 18:40:21 +01:00
Error "Authentication failed"
exit
fi
Info "Authentication complete"
fi
case $method in
1)
#Standard installer
tput setaf 208
tput sgr0
printf "Please select\n"
printf "1: Install Lightcord\n"
printf "2: Uninstall Lightcord\n"
printf "3: Update Lightcord\n"
printf "\n"
#Repeat only if the user hasn't entered an integer...
2021-04-25 19:18:44 +02:00
while ! echo $selection | grep -Eq "^[0-9]";
2021-01-05 18:40:21 +01:00
do
2021-04-25 19:18:44 +02:00
read -r selection;
2021-01-05 18:40:21 +01:00
# If the entered value was not an integer, prompt the user again
2021-04-25 19:18:44 +02:00
if ! echo $method | grep -Eq "^[0-9]"; then
2021-01-05 18:40:21 +01:00
sleep 1;
printf "$(tput setaf 9)Please try again$(tput sgr0)\n";
printf "1: Install Lightcord\n";
printf "2: Uninstall Lightcord\n";
printf "3: Update Lightcord\n"
printf "\n";
fi
done
case $selection in
1) # Install LC
Info "Installing Lightcord"
SubInfo "Preparing"
rm -rf Lightcord.*;
rm -rf Lightcord;
rm -rf lightcord-linux-x64.*;
SubInfo "Downloading Lightcord"
2021-02-13 16:22:36 +01:00
wget -qO lightcord-linux-x64.zip $LC;
if [ ! $? ]; then
2021-01-15 14:30:19 +01:00
SubInfo "Trying alternate URL"
2021-02-13 16:22:36 +01:00
wget -qO lightcord-linux-x64.zip $ALT_LC;
2021-01-15 14:30:19 +01:00
fi
2021-04-25 19:18:44 +02:00
unzip -qq lightcord-linux-x64.zip -d Lightcord;
cd Lightcord;
chmod +x ./lightcord;
cd ..;
sudo mv Lightcord/ $GLOBAL_INSTALL_DIR;
2021-01-05 18:40:21 +01:00
SubInfo "Downloading Lightcord icon"
2021-02-13 16:22:36 +01:00
wget -qO lightcord.png $ICON;
sudo mkdir -p /usr/share/pixmaps;
2021-04-25 19:18:44 +02:00
sudo mv lightcord.png /usr/share/pixmaps;
2021-01-05 18:40:21 +01:00
SubInfo "Creating Desktop entry"
2021-04-25 19:18:44 +02:00
printf "[Desktop Entry]\nName=Lightcord\nComment[fr_FR]=Un client Discord simple et personalisable\nComment=A simple - customizable - Discord Client\nExec=$GLOBAL_INSTALL_DIR/Lightcord/lightcord\nIcon=lightcord\nTerminal=false\nType=Application\nCategories=Network;InstantMessaging;P2P;" > Lightcord.desktop
2021-01-05 20:32:11 +01:00
sudo mv Lightcord.desktop /usr/share/applications/Lightcord.desktop
2021-01-05 23:12:30 +01:00
sudo chmod +x /usr/share/applications/Lightcord.desktop;
2021-01-05 18:40:21 +01:00
SubInfo "Cleaning up"
rm -rf Lightcord.*;
rm -rf Lightcord;
rm -rf lightcord-linux-x64.*;
2021-04-19 11:10:01 +02:00
sudo touch $GLOBAL_INSTALL_DIR/Lightcord/script_check
2021-01-05 18:40:21 +01:00
;;
2) # Uninstall LC
Info "Uninstalling Lightcord"
SubInfo "Deleting Lightcord folder"
sudo rm -r $GLOBAL_INSTALL_DIR/Lightcord;
2021-01-05 20:40:50 +01:00
SubInfo "Deleting Lightcord icon"
sudo rm /usr/share/pixmaps/lightcord.png;
2021-01-05 20:40:50 +01:00
SubInfo "Deleting Desktop entry"
2021-01-05 18:40:21 +01:00
sudo rm /usr/share/applications/Lightcord.desktop;
sudo rm -f /home/*/.local/share/applications/Lightcord.desktop;
2021-01-05 18:40:21 +01:00
;;
3) # Update LC
Info 'Updating Lightcord'
SubInfo "Preparing"
rm -rf Lightcord.*;
rm -rf Lightcord;
rm -rf lightcord-linux-x64.*;
2021-01-05 20:40:50 +01:00
SubInfo "Deleting Lightcord"
sudo rm -r $GLOBAL_INSTALL_DIR/Lightcord;
2021-01-05 18:40:21 +01:00
SubInfo "Downloading Lightcord"
2021-02-13 16:22:36 +01:00
wget -qO lightcord-linux-x64.zip $LC;
if [ ! $? ]; then
2021-01-15 14:30:19 +01:00
SubInfo "Trying alternate URL"
2021-02-13 16:22:36 +01:00
wget -qO lightcord-linux-x64.zip $ALT_LC;
2021-01-15 14:30:19 +01:00
fi
2021-04-25 19:18:44 +02:00
unzip -qq lightcord-linux-x64.zip -d Lightcord;
cd Lightcord;
chmod +x ./lightcord;
cd ..;
sudo mv Lightcord/ $GLOBAL_INSTALL_DIR;
2021-01-05 18:40:21 +01:00
SubInfo "Cleaning up"
rm -rf Lightcord.*;
rm -rf Lightcord;
rm -rf lightcord-linux-x64.*;
2021-04-19 11:10:01 +02:00
sudo touch $GLOBAL_INSTALL_DIR/Lightcord/script_check
2021-01-05 18:40:21 +01:00
;;
*) # Do nothing
Error 'Aborting install'
;;
esac
;;
2)
# Appimage installer
2021-04-25 19:18:44 +02:00
if [ "$TERM" = dumb ]; then
2021-01-05 18:40:21 +01:00
exit;
fi
tput setaf 208
tput sgr0
printf "Please select\n";
printf "1: Install Lightcord\n";
printf "2: Uninstall Lightcord\n";
printf "3: Update Lightcord\n"
printf "\n";
2021-04-25 19:18:44 +02:00
while ! echo $selection | grep -Eq "^[0-9]";
2021-01-05 18:40:21 +01:00
do
2021-04-25 19:18:44 +02:00
read -r selection;
2021-01-05 18:40:21 +01:00
# If the entered value was not an integer, prompt the user again
2021-04-25 19:18:44 +02:00
if ! echo $method | grep -Eq "^[0-9]"; then
2021-01-05 18:40:21 +01:00
sleep 1;
printf "$(tput setaf 9)Please try again$(tput sgr0)\n";
printf "1: Install Lightcord\n";
printf "2: Uninstall Lightcord\n";
printf "3: Update Lightcord\n"
printf "\n";
fi
done
case $selection in
1) # Install LC
Info 'Installing Lightcord'
2021-01-05 20:40:50 +01:00
SubInfo "Downloading Lightcord"
2021-02-13 16:22:36 +01:00
wget -qO lightcord.AppImage $LC_APPIMAGE;
if [ ! $? ]; then
2021-01-15 14:30:19 +01:00
SubInfo "Trying alternate URL"
2021-02-13 16:22:36 +01:00
wget -qO lightcord.AppImage $ALT_LC_APPIMAGE;
2021-01-15 14:30:19 +01:00
fi
2021-01-05 20:40:50 +01:00
SubInfo "Downloading Lightcord icon"
2021-02-13 16:22:36 +01:00
wget -qO lightcord.png $ICON;
2021-04-25 19:18:44 +02:00
mkdir -p "$LOCAL_INSTALL_DIR";
mv lightcord.AppImage "$LOCAL_INSTALL_DIR";
chmod +x "$LOCAL_INSTALL_DIR/lightcord.AppImage";
2021-01-05 18:40:21 +01:00
mkdir -p ~/.local/share/icons/hicolor/512x512/apps
mv lightcord.png ~/.local/share/icons/hicolor/512x512/apps;
2021-01-05 20:40:50 +01:00
SubInfo "Creating local desktop entry"
2021-04-25 19:18:44 +02:00
printf "[Desktop Entry]\nName=Lightcord\nComment[fr_FR]=Un client Discord simple et personalisable\nComment=A simple - customizable - Discord Client\nExec=$LOCAL_INSTALL_DIR/lightcord.AppImage\nIcon=lightcord\nTerminal=false\nType=Application\nCategories=Network;InstantMessaging;P2P;" >> ~/.local/share/applications/lightcord.desktop;
2021-01-15 14:30:19 +01:00
SubInfo "Cleaning up"
2021-01-05 18:40:21 +01:00
;;
2) # Uninstall LC
Info 'Uninstalling Lightcord'
2021-01-05 20:40:50 +01:00
SubInfo "Deleting Lightcord folder"
2021-04-25 19:18:44 +02:00
rm -r "$LOCAL_INSTALL_DIR";
2021-01-05 20:40:50 +01:00
SubInfo "Deleting Lightcord icon"
2021-01-05 18:40:21 +01:00
rm ~/.local/share/icons/hicolor/512x512/apps/lightcord.png;
2021-01-05 20:40:50 +01:00
SubInfo "Deleting desktop entry"
2021-01-05 18:40:21 +01:00
rm ~/.local/share/applications/lightcord.desktop;
;;
3) # Update LC
Info 'Updating Lightcord'
2021-01-05 20:40:50 +01:00
SubInfo "Deleting Lightcord"
2021-04-25 19:18:44 +02:00
rm "$LOCAL_INSTALL_DIR"/lightcord.AppImage;
2021-01-05 20:40:50 +01:00
SubInfo "Downloading Lightcord"
2021-02-13 16:22:36 +01:00
wget -qO lightcord.AppImage $LC_APPIMAGE;
if [ ! $? ]; then
2021-01-15 14:30:19 +01:00
SubInfo "Trying alternate URL"
2021-02-13 16:22:36 +01:00
wget -qO lightcord.AppImage $ALT_LC_APPIMAGE;
2021-01-15 14:30:19 +01:00
fi
2021-04-25 19:18:44 +02:00
mkdir -p "$LOCAL_INSTALL_DIR";
mv lightcord.AppImage "$LOCAL_INSTALL_DIR";
chmod +x "$LOCAL_INSTALL_DIR/lightcord.AppImage";
2021-01-15 14:30:19 +01:00
SubInfo "Cleaning up"
2021-01-05 18:40:21 +01:00
;;
2021-04-25 19:18:44 +02:00
2021-01-05 18:40:21 +01:00
*)
Error 'Aborting install'
;;
esac
;;
*)
Error 'Aborting install'
;;
esac
2021-04-25 19:18:44 +02:00
exit