Compare commits
2 Commits
09133b09f8
...
d077b5a8bf
Author | SHA1 | Date | |
---|---|---|---|
d077b5a8bf | |||
d6c4eea24f |
2
LICENSE
2
LICENSE
@ -1,6 +1,6 @@
|
|||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright (c) 2024 madas
|
Copyright (c) 2024 Madars Batraks
|
||||||
|
|
||||||
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:
|
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:
|
||||||
|
|
||||||
|
3
__main__.py
Normal file
3
__main__.py
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
from cli import main
|
||||||
|
|
||||||
|
main()
|
38
cli.py
Normal file
38
cli.py
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
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))
|
19
config.py
Normal file
19
config.py
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
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]
|
41
discord.py
Normal file
41
discord.py
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
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
109
main.py
@ -1,109 +0,0 @@
|
|||||||
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))
|
|
1
requirements.txt
Normal file
1
requirements.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
tqdm
|
41
util.py
Normal file
41
util.py
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
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)
|
Loading…
Reference in New Issue
Block a user