Compare commits

..

No commits in common. "d077b5a8bf4391a1a6930caa61f9e189fecd1173" and "09133b09f8c492e4b737151940895e693447fec2" have entirely different histories.

8 changed files with 110 additions and 144 deletions

View File

@ -1,6 +1,6 @@
MIT License
Copyright (c) 2024 Madars Batraks
Copyright (c) 2024 madas
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

View File

@ -1,3 +0,0 @@
from cli import main
main()

38
cli.py
View File

@ -1,38 +0,0 @@
import getopt
import sys
import os
import discord
argumentList = sys.argv[1:]
options = "hiu"
long_options = ["help", "install", "uninstall"]
def main():
if os.geteuid() == 0:
print("WARNING: This script is not meant to run as root as it installs discord to the user folder.")
i = input("Do you wish to proceed? (y/n)")
if str(i).upper() != "Y":
return exit()
try:
# Parsing argument
arguments, values = getopt.getopt(argumentList, options, long_options)
# checking each argument
for currentArgument, currentValue in arguments:
if currentArgument in ("-h", "--help"):
print ("Displaying Help")
elif currentArgument in ("-i", "--install"):
discord.install()
elif currentArgument in ("-u", "--uninstall"):
discord.uninstall()
except getopt.error as err:
# output error, and return with an error code
print (str(err))

View File

@ -1,19 +0,0 @@
import os
config = {
"discordUrl" : "https://discord.com/api/download?platform=linux&format=tar.gz",
"asarUrl" : "https://github.com/GooseMod/OpenAsar/releases/download/nightly/app.asar",
"tmpDir" : "/tmp/dup/",
"confDir" : os.path.expanduser("~") + "/.config/dup",
"installDir" : os.path.expanduser("~") + "/.local/lib/Discord",
"linkDir" : os.path.expanduser("~") + "/.local/bin/Discord",
"localDir" : os.path.expanduser("~") + "/.local/share/dup"
}
def get( name: str ):
try:
config[name]
except:
raise Exception("No such configuration variable: " + name)
else:
return config[name]

View File

@ -1,41 +0,0 @@
import tarfile
import os
import shutil
from util import download,rm,mkdir
import config
tmpDir = config.get("tmpDir")
installDir = config.get("installDir")
discordUrl = config.get("discordUrl")
def install():
rm(tmpDir)
mkdir(tmpDir)
print("Downloading Discord...")
download(discordUrl, "discord.tar.gz")
print("Extracting..." )
file = tarfile.open(tmpDir+"/discord.tar.gz")
mkdir("/tmp/dup/discord")
file.extractall(tmpDir+"/discord")
file.close()
print("Installing...")
rm(installDir)
shutil.move(tmpDir+"/discord/Discord", installDir)
os.symlink(installDir + "/Discord", config.get("linkDir"))
print("Running post-install tasks... (Your Discord client will close)")
# TBA
print("Cleaning up...")
rm(tmpDir)
def uninstall():
rm(config.get("installDir"))
rm(config.get("tmpDir"))
rm(config.get("confDir"))
rm(config.get("linkDir"))

109
main.py Normal file
View File

@ -0,0 +1,109 @@
import requests
import tqdm
import tarfile
import os
import shutil
import getopt
import sys
discordUrl = "https://discord.com/api/download?platform=linux&format=tar.gz"
tmpDir = "/tmp/dup/"
confDir = "~/.config/"
installDir = os.path.expanduser("~") + "/.local/lib/Discord"
execDir = os.path.expanduser("~") + "/.local/bin/Discord"
def download(url: str, dest: str):
with open(tmpDir + dest, 'wb') as f:
with requests.get(url, stream=True) as r:
r.raise_for_status()
totalLength = int(r.headers.get('content-length', 0))
tqdm_params = {
'desc': dest,
'total': totalLength,
'miniters': 1,
'bar_format' : "{desc}: |{bar:40}| {percentage:3.1f}% ",
}
with tqdm.tqdm(**tqdm_params) as pb:
for chunk in r.iter_content(chunk_size=8192):
pb.update(len(chunk))
f.write(chunk)
def rm(dir: str):
try:
if os.path.isdir(dir) == True:
shutil.rmtree(dir)
else:
os.remove(dir)
except Exception as err:
print(err)
# def rm(folder: str):
# try:
# shutil.rmtree(folder)
# except Exception as err:
# print(err)
def mkdir(name: str):
try:
os.mkdir(name)
except Exception as err:
print(err)
def installDiscord():
rm(tmpDir)
mkdir(tmpDir)
print("Downloading Discord...")
download(discordUrl, "discord.tar.gz")
print("Extracting..." )
file = tarfile.open(tmpDir+"/discord.tar.gz")
mkdir("/tmp/dup/discord")
file.extractall(tmpDir+"/discord")
file.close()
print("Installing...")
rm(installDir)
shutil.move(tmpDir+"/discord/Discord", installDir)
os.symlink(installDir + "/Discord", execDir)
print("Cleaning up...")
# os.remove(tmpDir+"discord.tar.gz")
rm(tmpDir)
def uninstall():
rm(installDir)
rm(tmpDir)
rm(confDir)
rm(execDir)
argumentList = sys.argv[1:]
# Options
options = "hiu"
# Long options
long_options = ["help", "install", "uninstall"]
try:
# Parsing argument
arguments, values = getopt.getopt(argumentList, options, long_options)
# checking each argument
for currentArgument, currentValue in arguments:
if currentArgument in ("-h", "--help"):
print ("Displaying Help")
elif currentArgument in ("-i", "--install"):
installDiscord()
elif currentArgument in ("-u", "--uninstall"):
uninstall()
except getopt.error as err:
# output error, and return with an error code
print (str(err))

View File

@ -1 +0,0 @@
tqdm

41
util.py
View File

@ -1,41 +0,0 @@
import tqdm
import os
import shutil
import requests
import config
def download(url: str, dest: str):
with open(config.get("tmpDir") + dest, 'wb') as f:
with requests.get(url, stream=True) as r:
r.raise_for_status()
totalLength = int(r.headers.get('content-length', 0))
tqdm_params = {
'desc': dest,
'total': totalLength,
'miniters': 1,
'bar_format' : "{desc}: |{bar:40}| {percentage:3.1f}% ",
}
with tqdm.tqdm(**tqdm_params) as pb:
for chunk in r.iter_content(chunk_size=8192):
pb.update(len(chunk))
f.write(chunk)
def mkdir(name: str):
try:
os.mkdir(name)
except Exception as err:
print(err)
def rm(dir: str):
try:
if os.path.isdir(dir) == True:
shutil.rmtree(dir)
else:
os.remove(dir)
except Exception as err:
print(err)
def rmlist(list: list):
for dir in list:
rm(dir)