Merge remote-tracking branch 'refs/remotes/origin/master'

This commit is contained in:
Isaac Shoebottom 2024-02-03 15:14:47 -04:00
commit 30f67ab42b
2 changed files with 186 additions and 0 deletions

View File

@ -0,0 +1,66 @@
# Import json parsing and urllib
import json
import urllib.request
# Import subprocess for running dpkg
import subprocess
# Endpoint for the latest release
API_URL = "https://api.github.com/repos/obsidianmd/obsidian-releases/releases/latest"
# DEB file name, will be filled in later
DEB_NAME = ""
# URL for the latest deb file, will be filled in later
DEB_URL = ""
# Version number, will be filled in later
DEB_VERSION = ""
# Installed version number, will be filled in later
INSTALLED_VERSION = ""
# Get the latest release from the API
with urllib.request.urlopen(API_URL) as url:
data = json.loads(url.read().decode())
assets = data["assets"]
for asset in assets:
if asset["name"].endswith(".deb"):
DEB_NAME = asset["name"]
DEB_URL = asset["browser_download_url"]
# Parse the version number from the deb file name
# Example: obsidian_0.12.15_amd64.deb -> 0.12.15
DEB_VERSION = DEB_NAME.split("_")[1]
print("Latest version: " + DEB_VERSION)
# Get the installed version number by parsing the output of dpkg -s obsidian
output = subprocess.run(["dpkg", "-s", "obsidian"], capture_output=True)
# Parse the output for the version number
# Example: Version: 0.12.15
for line in output.stdout.decode().split("\n"):
if line.startswith("Version:"):
INSTALLED_VERSION = line.split(" ")[1]
print("Installed version: " + INSTALLED_VERSION)
def semver_check_new(old, new):
# Split the version numbers into arrays of numbers
old_split = old.split(".")
new_split = new.split(".")
# Loop through the numbers
for i in range(len(old_split)):
# If the new version is higher, return true
if int(new_split[i]) > int(old_split[i]):
return True
# If the new version is the same or lower, return false
return False
# Check if the new version is higher than the installed version
if semver_check_new(INSTALLED_VERSION, DEB_VERSION):
print("New version available!")
# Download the deb file
urllib.request.urlretrieve(DEB_URL, DEB_NAME)
# Install the deb file
subprocess.run(["pkexec", "apt", "install", f"./{DEB_NAME}"])
# Remove the deb file
subprocess.run(["rm", DEB_NAME])
else:
print("No new version available")

120
OpenAsarInjector/main.py Normal file
View File

@ -0,0 +1,120 @@
ASAR = "app.asar"
ASAR_BACKUP = ASAR + ".bak"
SYMLINK_PATH = ""
REAL_PATH = ""
DISCORD_FOLDER = ""
RESOURCES_PATH = ""
def root():
import os
if os.geteuid() != 0:
print("Script not running as root")
exit()
def backup():
import os
# Check for existing backup
if os.path.isfile(RESOURCES_PATH + ASAR_BACKUP):
print("Backup already exists, openasar is already installed")
exit()
try:
print(RESOURCES_PATH + ASAR)
os.rename(RESOURCES_PATH + ASAR, RESOURCES_PATH + ASAR_BACKUP)
except Exception as e:
print("Couldn't rename file: " + str(e))
def find():
import os
from shutil import which
# Get full path of discord symlink on path
global SYMLINK_PATH
SYMLINK_PATH = which("discord")
# Parse real path of discord symlink
global REAL_PATH
REAL_PATH = os.path.realpath(SYMLINK_PATH)
# Get containing folder
global DISCORD_FOLDER
DISCORD_FOLDER = os.path.dirname(REAL_PATH)
# Add /resources/ to the real path
global RESOURCES_PATH
RESOURCES_PATH = DISCORD_FOLDER + "/resources/"
def download():
import urllib.request
import json
# Get nightly release from github
# url: https://github.com/GooseMod/OpenAsar/
# release: https://github.com/GooseMod/OpenAsar/releases/tag/nightly
API_URL = "https://api.github.com/repos/GooseMod/OpenAsar/releases/latest"
DOWNLOAD_URL = ""
with urllib.request.urlopen(API_URL) as url:
data = json.loads(url.read().decode())
DOWNLOAD_URL = data['assets'][0]['browser_download_url']
# Download the file
urllib.request.urlretrieve(DOWNLOAD_URL, RESOURCES_PATH + ASAR)
def kill():
import os
import signal
import psutil
# Get discord process
for proc in psutil.process_iter():
if proc.name() == "Discord":
# Kill discord
os.kill(proc.pid, signal.SIGTERM)
def uninstall():
import os
if os.path.isfile(RESOURCES_PATH + ASAR_BACKUP):
try:
os.remove(RESOURCES_PATH + ASAR)
os.rename(RESOURCES_PATH + ASAR_BACKUP, RESOURCES_PATH + ASAR)
except Exception as e:
print("Couldn't remove/rename file: " + str(e))
else:
print("No backup found, openasar is not installed")
exit()
# Should check if the package has been updated, as discords asar is much larger
def sanity_check():
import os
# Get file size of asar
asar_size = os.path.getsize(RESOURCES_PATH + ASAR)
# If the asar is larger than 1MB, discord has probably updated
if asar_size > 1000000:
print("Discord has probably updated, please clear backups and reinstall")
print("Would you like to clear backups? (y/n)")
answer = input().lower()
if answer == "y":
os.remove(RESOURCES_PATH + ASAR_BACKUP)
print("Backups cleared, installation will continue as normal")
else:
print("Backups not cleared, please clean manually")
exit()
def main():
import sys
root()
kill()
find()
sanity_check()
if len(sys.argv) > 1:
if sys.argv[1] == "uninstall":
uninstall()
print("Uninstalled openasar")
else:
print("Unknown argument")
else:
backup()
download()
print("Installed openasar")
if __name__ == "__main__":
main()