LULI.sh 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. #!/bin/bash
  2. # Original script by https://github.com/GermanBread
  3. # Lightcord unified Linux installer by Germanbread
  4. # Some variables
  5. ALLOW_NIXOS='false'
  6. GLOBAL_INSTALL_DIR='/opt'
  7. LOCAL_INSTALL_DIR="$HOME/.lightcord"
  8. # URL for downloads
  9. ICON='https://raw.githubusercontent.com/Lightcord/Lightcord/master/discord.png'
  10. LC_APPIMAGE='https://lightcord.org/api/gh/releases/Lightcord/Lightcord/dev/lightcord-linux-x86_64.AppImage'
  11. LC='https://lightcord.org/api/v1/gh/releases/Lightcord/Lightcord/dev/lightcord-linux-x64.zip'
  12. # Fallback URL
  13. ALT_LC_APPIMAGE='https://github.com/Lightcord/Lightcord/releases/latest/download/Lightcord-linux-x86_64.AppImage'
  14. ALT_LC='https://github.com/Lightcord/Lightcord/releases/latest/download/lightcord-linux-x64.zip'
  15. # Some helper funtions
  16. function Info {
  17. tput setaf 8
  18. tput bold
  19. printf "==> "
  20. tput setaf 15
  21. printf "$1\n"
  22. tput sgr0
  23. }
  24. function SubInfo {
  25. tput setaf 8
  26. printf "> "
  27. printf "$1\n"
  28. tput sgr0
  29. }
  30. function Warning {
  31. tput setaf 3
  32. tput bold
  33. printf "==> "
  34. tput setaf 11
  35. printf "$1\n"
  36. tput sgr0
  37. }
  38. function Error {
  39. tput setaf 1
  40. tput bold
  41. printf "==> "
  42. tput setaf 9
  43. printf "$1\n"
  44. tput sgr0
  45. }
  46. if [[ $TERM == dumb ]]; then
  47. exit
  48. fi
  49. if [[ "$(whoami)" == "root" ]]; then
  50. Error "Don't run this script as root"
  51. exit
  52. fi
  53. # Check if unzip is installed
  54. if [ ! -e /usr/bin/unzip ]; then
  55. Warning "Unzip does not seem to be installed!\n\tThis script depends on this package.\n\tInstall unzip and restart this script.\n\tPress enter if you believe that this is a false-positive."
  56. read
  57. fi
  58. cat << "logo_end"
  59. _ _ _ _ _
  60. | | (_)__ _| |_| |_ __ ___ _ _ __| |
  61. | |__| / _` | ' \ _/ _/ _ \ '_/ _` |
  62. |____|_\__, |_||_\__\__\___/_| \__,_|
  63. |___/
  64. Unified Linux Installer and Updater
  65. logo_end
  66. # First, we need to figure out what kind of install the user wants (AppImage or System-wide?)
  67. printf "Please select\n"
  68. printf "1: Install Lightcord for all users\n"
  69. printf "2: Install Lightcord only for you (Appimage install)\n"
  70. printf "\n"
  71. #Repeat only if the user hasn't entered an integer...
  72. while ! [[ $method =~ ^[0-9]+$ ]];
  73. do
  74. read method;
  75. # If the entered value was not an integer, prompt the user again
  76. if ! [[ $method =~ ^[0-9]+$ ]]; then
  77. sleep 1
  78. printf "$(tput setaf 9)Please try again$(tput sgr0)\n"
  79. printf "1: Install Lightcord for all users\n"
  80. printf "2: Install Lightcord only for you (Appimage install)\n"
  81. printf "\n"
  82. fi
  83. done
  84. if [[ $method == 1 ]]; then
  85. 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."
  86. if [ -d "/nix" ] && [ $ALLOW_NIXOS == 'false' ]; then
  87. 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 by NixOS."
  88. exit;
  89. fi # We want to prevent NixOS users from installing LC this way because:
  90. # A) NixOS is very "special" i.e. it blocks LC from running
  91. # B) /opt gets cleared upon boot
  92. Info "Please enter your password to proceed"
  93. sudo -K
  94. if [[ "$(sudo whoami)" != "root" ]]; then
  95. Error "Authentication failed"
  96. exit
  97. fi
  98. Info "Authentication complete"
  99. fi
  100. case $method in
  101. 1)
  102. #Standard installer
  103. tput setaf 208
  104. tput sgr0
  105. printf "Please select\n"
  106. printf "1: Install Lightcord\n"
  107. printf "2: Uninstall Lightcord\n"
  108. printf "3: Update Lightcord\n"
  109. printf "\n"
  110. #Repeat only if the user hasn't entered an integer...
  111. while ! [[ $selection =~ ^[0-9]+$ ]];
  112. do
  113. read selection;
  114. # If the entered value was not an integer, prompt the user again
  115. if ! [[ $selection =~ ^[0-9]+$ ]]; then
  116. sleep 1;
  117. printf "$(tput setaf 9)Please try again$(tput sgr0)\n";
  118. printf "1: Install Lightcord\n";
  119. printf "2: Uninstall Lightcord\n";
  120. printf "3: Update Lightcord\n"
  121. printf "\n";
  122. fi
  123. done
  124. case $selection in
  125. 1) # Install LC
  126. Info "Installing Lightcord"
  127. SubInfo "Preparing"
  128. rm -rf Lightcord.*;
  129. rm -rf Lightcord;
  130. rm -rf lightcord-linux-x64.*;
  131. SubInfo "Downloading Lightcord"
  132. wget -qO lightcord-linux-x64.zip $LC;
  133. if [ ! $? ]; then
  134. SubInfo "Trying alternate URL"
  135. wget -qO lightcord-linux-x64.zip $ALT_LC;
  136. fi
  137. unzip -qq lightcord-linux-x64.zip -d Lightcord;
  138. cd Lightcord;
  139. chmod +x ./lightcord;
  140. cd ..;
  141. sudo mv Lightcord/ $GLOBAL_INSTALL_DIR;
  142. SubInfo "Downloading Lightcord icon"
  143. wget -qO lightcord.png $ICON;
  144. sudo mkdir -p /usr/share/pixmaps;
  145. sudo mv lightcord.png /usr/share/pixmaps;
  146. SubInfo "Creating Desktop entry"
  147. echo -e "[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
  148. sudo mv Lightcord.desktop /usr/share/applications/Lightcord.desktop
  149. sudo chmod +x /usr/share/applications/Lightcord.desktop;
  150. SubInfo "Cleaning up"
  151. rm -rf Lightcord.*;
  152. rm -rf Lightcord;
  153. rm -rf lightcord-linux-x64.*;
  154. ;;
  155. 2) # Uninstall LC
  156. Info "Uninstalling Lightcord"
  157. SubInfo "Deleting Lightcord folder"
  158. sudo rm -r $GLOBAL_INSTALL_DIR/Lightcord;
  159. SubInfo "Deleting Lightcord icon"
  160. sudo rm /usr/share/pixmaps/lightcord.png;
  161. SubInfo "Deleting Desktop entry"
  162. sudo rm /usr/share/applications/Lightcord.desktop;
  163. sudo rm -f /home/*/.local/share/applications/Lightcord.desktop;
  164. ;;
  165. 3) # Update LC
  166. Info 'Updating Lightcord'
  167. SubInfo "Preparing"
  168. rm -rf Lightcord.*;
  169. rm -rf Lightcord;
  170. rm -rf lightcord-linux-x64.*;
  171. SubInfo "Deleting Lightcord"
  172. sudo rm -r $GLOBAL_INSTALL_DIR/Lightcord;
  173. SubInfo "Downloading Lightcord"
  174. wget -qO lightcord-linux-x64.zip $LC;
  175. if [ ! $? ]; then
  176. SubInfo "Trying alternate URL"
  177. wget -qO lightcord-linux-x64.zip $ALT_LC;
  178. fi
  179. unzip -qq lightcord-linux-x64.zip -d Lightcord;
  180. cd Lightcord;
  181. chmod +x ./lightcord;
  182. cd ..;
  183. sudo mv Lightcord/ $GLOBAL_INSTALL_DIR;
  184. SubInfo "Cleaning up"
  185. rm -rf Lightcord.*;
  186. rm -rf Lightcord;
  187. rm -rf lightcord-linux-x64.*;
  188. ;;
  189. *) # Do nothing
  190. Error 'Aborting install'
  191. ;;
  192. esac
  193. ;;
  194. 2)
  195. # Appimage installer
  196. if [[ $TERM == dumb ]]; then
  197. exit;
  198. fi
  199. tput setaf 208
  200. tput sgr0
  201. printf "Please select\n";
  202. printf "1: Install Lightcord\n";
  203. printf "2: Uninstall Lightcord\n";
  204. printf "3: Update Lightcord\n"
  205. printf "\n";
  206. while ! [[ $selection =~ ^[0-9]+$ ]];
  207. do
  208. read selection;
  209. # If the entered value was not an integer, prompt the user again
  210. if ! [[ $selection =~ ^[0-9]+$ ]]; then
  211. sleep 1;
  212. printf "$(tput setaf 9)Please try again$(tput sgr0)\n";
  213. printf "1: Install Lightcord\n";
  214. printf "2: Uninstall Lightcord\n";
  215. printf "3: Update Lightcord\n"
  216. printf "\n";
  217. fi
  218. done
  219. case $selection in
  220. 1) # Install LC
  221. Info 'Installing Lightcord'
  222. SubInfo "Downloading Lightcord"
  223. wget -qO lightcord.AppImage $LC_APPIMAGE;
  224. if [ ! $? ]; then
  225. SubInfo "Trying alternate URL"
  226. wget -qO lightcord.AppImage $ALT_LC_APPIMAGE;
  227. fi
  228. SubInfo "Downloading Lightcord icon"
  229. wget -qO lightcord.png $ICON;
  230. mkdir -p $LOCAL_INSTALL_DIR;
  231. mv lightcord.AppImage $LOCAL_INSTALL_DIR;
  232. chmod +x $LOCAL_INSTALL_DIR/lightcord.AppImage ;
  233. mkdir -p ~/.local/share/icons/hicolor/512x512/apps
  234. mv lightcord.png ~/.local/share/icons/hicolor/512x512/apps;
  235. SubInfo "Creating local desktop entry"
  236. echo -e "[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;
  237. SubInfo "Cleaning up"
  238. ;;
  239. 2) # Uninstall LC
  240. Info 'Uninstalling Lightcord'
  241. SubInfo "Deleting Lightcord folder"
  242. rm -r $LOCAL_INSTALL_DIR;
  243. SubInfo "Deleting Lightcord icon"
  244. rm ~/.local/share/icons/hicolor/512x512/apps/lightcord.png;
  245. SubInfo "Deleting desktop entry"
  246. rm ~/.local/share/applications/lightcord.desktop;
  247. ;;
  248. 3) # Update LC
  249. Info 'Updating Lightcord'
  250. SubInfo "Deleting Lightcord"
  251. rm $LOCAL_INSTALL_DIR/lightcord.AppImage;
  252. SubInfo "Downloading Lightcord"
  253. wget -qO lightcord.AppImage $LC_APPIMAGE;
  254. if [ ! $? ]; then
  255. SubInfo "Trying alternate URL"
  256. wget -qO lightcord.AppImage $ALT_LC_APPIMAGE;
  257. fi
  258. mkdir -p $LOCAL_INSTALL_DIR;
  259. mv lightcord.AppImage $LOCAL_INSTALL_DIR;
  260. chmod +x $LOCAL_INSTALL_DIR/lightcord.AppImage;
  261. SubInfo "Cleaning up"
  262. ;;
  263. *)
  264. Error 'Aborting install'
  265. ;;
  266. esac
  267. ;;
  268. *)
  269. Error 'Aborting install'
  270. ;;
  271. esac
  272. printf "Do you want to keep the install script? [y/N] "; # Ask if the script should delete itself
  273. read a;
  274. case $a in
  275. y)
  276. Info "Kept install script"
  277. exit;
  278. ;;
  279. Y)
  280. Info "Kept install script"
  281. exit;
  282. ;;
  283. esac
  284. # Remove the script
  285. rm LULI.sh;
  286. Info "Removed install script"
  287. exit;