The concept (installs discord to ~/.local/bin/)
This commit is contained in:
parent
eca3d077fe
commit
09133b09f8
76
main.py
76
main.py
@ -3,11 +3,14 @@ import tqdm
|
|||||||
import tarfile
|
import tarfile
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
|
import getopt
|
||||||
|
import sys
|
||||||
|
|
||||||
discordUrl = "https://discord.com/api/download?platform=linux&format=tar.gz"
|
discordUrl = "https://discord.com/api/download?platform=linux&format=tar.gz"
|
||||||
tmpDir = "/tmp/dup/"
|
tmpDir = "/tmp/dup/"
|
||||||
confDir = "~/.config/"
|
confDir = "~/.config/"
|
||||||
installDir = os.path.expanduser("~") + "/.local/lib/Discord"
|
installDir = os.path.expanduser("~") + "/.local/lib/Discord"
|
||||||
|
execDir = os.path.expanduser("~") + "/.local/bin/Discord"
|
||||||
|
|
||||||
def download(url: str, dest: str):
|
def download(url: str, dest: str):
|
||||||
with open(tmpDir + dest, 'wb') as f:
|
with open(tmpDir + dest, 'wb') as f:
|
||||||
@ -26,32 +29,81 @@ def download(url: str, dest: str):
|
|||||||
pb.update(len(chunk))
|
pb.update(len(chunk))
|
||||||
f.write(chunk)
|
f.write(chunk)
|
||||||
|
|
||||||
def rm(file):
|
def rm(dir: str):
|
||||||
print("TBA")
|
try:
|
||||||
def rmdir():
|
if os.path.isdir(dir) == True:
|
||||||
print("TBA")
|
shutil.rmtree(dir)
|
||||||
def mkdir():
|
else:
|
||||||
print("TBA")
|
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():
|
def installDiscord():
|
||||||
#os.mkdir(tmpDir)
|
rm(tmpDir)
|
||||||
|
mkdir(tmpDir)
|
||||||
|
|
||||||
print("Downloading Discord...")
|
print("Downloading Discord...")
|
||||||
download(discordUrl, "discord.tar.gz")
|
download(discordUrl, "discord.tar.gz")
|
||||||
|
|
||||||
print("Extracting..." )
|
print("Extracting..." )
|
||||||
file = tarfile.open(tmpDir+"/discord.tar.gz")
|
file = tarfile.open(tmpDir+"/discord.tar.gz")
|
||||||
os.mkdir("/tmp/dup/discord")
|
mkdir("/tmp/dup/discord")
|
||||||
file.extractall(tmpDir+"/discord")
|
file.extractall(tmpDir+"/discord")
|
||||||
file.close()
|
file.close()
|
||||||
|
|
||||||
print("Installing...")
|
print("Installing...")
|
||||||
shutil.rmtree(installDir)
|
rm(installDir)
|
||||||
shutil.move(tmpDir+"/discord/Discord", installDir)
|
shutil.move(tmpDir+"/discord/Discord", installDir)
|
||||||
|
|
||||||
|
os.symlink(installDir + "/Discord", execDir)
|
||||||
|
|
||||||
print("Cleaning up...")
|
print("Cleaning up...")
|
||||||
# os.remove(tmpDir+"discord.tar.gz")
|
# os.remove(tmpDir+"discord.tar.gz")
|
||||||
shutil.rmtree(tmpDir)
|
rm(tmpDir)
|
||||||
|
|
||||||
|
def uninstall():
|
||||||
installDiscord()
|
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))
|
||||||
|
Loading…
Reference in New Issue
Block a user