uengine-apt-root/add.py

174 lines
6.6 KiB
Python
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python3
import os
import sys
import random
import datetime
import subprocess
programPath = os.path.split(os.path.realpath(__file__))[0] # 返回 string
#os.chdir(programPath)
# 获取版本号和架构
def GetDebVersion(deb: str):
global all
tempPath = f"/tmp/get-deb-{random.randint(0, 10000)}"
os.system(f"dpkg -e '{deb}' '{tempPath}'")
version = "1.0.0"
arch = "amd64"
package = "demo"
v = False
with open(f"{tempPath}/control", "r") as file:
all = file.read()
with open(f"{tempPath}/control", "r") as file:
while True:
read = file.readline().replace("\n", "")
if read == "":
break
if "version:" == read[:8].lower() and not v:
version = read.replace("\n", "").replace("Version:", "").strip().replace(" ", "")
v = True
if "Architecture:" in read:
arch = read.replace("\n", "").replace("Architecture:", "").strip().replace(" ", "")
if "Package:" in read:
package = read.replace("\n", "").replace("Package:", "").strip().replace(" ", "")
os.system(f"rm -rfv '{tempPath}'")
return [arch, version, package]
debInfo = GetDebVersion(sys.argv[1])
if not os.path.exists(f"{programPath}/{debInfo[2][0].lower()}/{debInfo[2]}"):
os.makedirs(f"{programPath}/{debInfo[2][0].lower()}/{debInfo[2]}")
os.system(f"cp -v '{sys.argv[1]}' '{programPath}/{debInfo[2][0].lower()}/{debInfo[2]}/{debInfo[2]}_{debInfo[1]}_{debInfo[0]}.deb'")
os.chdir(programPath)
os.system(f"bash ../shell/incremental-updating-packages.sh '{programPath}'")
os.system("apt-ftparchive release . > Release")
os.system("rm Release.gpg")
os.system("rm InRelease")
os.system("rm gpg.asc")
os.system("gpg --armor --detach-sign -o Release.gpg Release")
os.system("gpg --clearsign -o InRelease Release")
os.system("gpg --armor --output gpg.asc --export 3025613752@qq.com")
# 更新 pages
try:
with open(f"{programPath}/../apt-packages-websize-program/list.html", "r") as file:
html = file.read()
except:
html = ""
html = f"""<h2>{debInfo[2]}_{debInfo[1]}_{debInfo[0]}.deb</h2>
<p><b>下载链接:<a href='https://code.gitlink.org.cn/gfdgd-xi-org/apt-packages-program/raw/branch/master/{debInfo[2][0].lower()}/{debInfo[2]}/{debInfo[2]}_{debInfo[1]}_{debInfo[0]}.deb'>https://code.gitlink.org.cn/gfdgd-xi-org/apt-packages-program/raw/branch/master/{debInfo[2][0].lower()}/{debInfo[2]}/{debInfo[2]}_{debInfo[1]}_{debInfo[0]}.deb</a></b></p>
<pre><code>{all}</code></pre>
{html}"""
with open(f"{programPath}/../apt-packages-websize-program/list.html", "w") as file:
file.write(html)
indexHtml = f"""<!DOCTYPE html>
<head>
<title>APT 库列表By RacoonGX Team</title>
<meta name="viewport" content="width=device-width" initial-scale="1" />
<meta charset='UTF-8'>
<meta http-equiv="content-language" content="zh-cn">
<meta name="description" content="APT 库列表By RacoonGX Team" >
<style type="text/css">
pre {{
overflow: auto;
}}
a {{
word-break:break-all;
word-wrap:break-word;
}}
h2 {{
overflow: auto;
word-break:break-all;
word-wrap:break-word;
}}
</style>
</head>
<body>
<h1>APT 库列表By RacoonGX Team</h1>
<p>点击下方链接下载</p>
<h3>推荐直接添加该源,添加方法:</h3>
<pre><code>
wget https://code.gitlink.org.cn/gfdgd-xi-org/apt-packages-program/raw/branch/master/sources/gitlink.sh; bash gitlink.sh; rm gitlink.sh
</code></pre>
<p>论坛:<a href='http://bbs.racoongx.cn'>http://bbs.racoongx.cn</a></p>
<p>程序分享站:<a href='https://bbs.racoongx.cn/t/cpu-China-APP'>https://bbs.racoongx.cn/t/cpu-China-APP</a></p>
<p><a href='tree.html'>在这里查看 APT 源目录树</a></p>
<h3>更新时间:{datetime.datetime.now().year}{datetime.datetime.now().month}{datetime.datetime.now().day}{datetime.datetime.now().hour}:{datetime.datetime.now().minute}:{datetime.datetime.now().second}</h3>
<hr/>
{html}
<hr/>
<h1 id="copyright">©2020~{datetime.datetime.now().year} gfdgd xi、为什么您不喜欢熊出没和阿布呢</h1>
</body>
<script>
window.onload = function(){{
var d = new Date();
document.getElementById("copyright").innerHTML = "©2020~" + d.getFullYear() + " gfdgd xi、为什么您不喜欢熊出没和阿布呢";
}}
</script>
<script>
var _hmt = _hmt || [];
(function() {{
var hm = document.createElement("script");
hm.src = "https://hm.baidu.com/hm.js?807ee27dfca59506248e7f74c812ca3d";
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(hm, s);
}})();
</script>
"""
with open(f"{programPath}/../apt-packages-websize-program/index.html", "w") as file:
file.write(indexHtml)
with open(f"{programPath}/../apt-packages-websize-program/tree.html", "w") as file:
file.write(f"""<!DOCTYPE html>
<head>
<title>APT 库目录树By RacoonGX Team</title>
<meta name="viewport" content="width=device-width" initial-scale="1" />
<meta charset='UTF-8'>
<meta http-equiv="content-language" content="zh-cn">
<meta name="description" content="APT 库列表By RacoonGX Team" >
<style type="text/css">
pre {{
overflow: auto;
}}
a {{
word-break:break-all;
word-wrap:break-word;
}}
h2 {{
overflow: auto;
word-break:break-all;
word-wrap:break-word;
}}
</style>
</head>
<body>
<h1>APT 库目录树By RacoonGX Team</h1>
<p>论坛:<a href='http://bbs.racoongx.cn'>http://bbs.racoongx.cn</a></p>
<p>程序分享站:<a href='https://bbs.racoongx.cn/t/cpu-China-APP'>https://bbs.racoongx.cn/t/cpu-China-APP</a></p>
<h3>更新时间:{datetime.datetime.now().year}{datetime.datetime.now().month}{datetime.datetime.now().day}{datetime.datetime.now().hour}:{datetime.datetime.now().minute}:{datetime.datetime.now().second}</h3>
<hr/>
<pre><code>
{subprocess.getoutput(f"cd '{programPath}' ; tree")}
</code></pre>
<hr/>
<h1 id="copyright">©2020~{datetime.datetime.now().year} gfdgd xi、为什么您不喜欢熊出没和阿布呢</h1>
</body>
<script>
window.onload = function(){{
var d = new Date();
document.getElementById("copyright").innerHTML = "©2020~" + d.getFullYear() + " gfdgd xi、为什么您不喜欢熊出没和阿布呢";
}}
</script>
<script>
var _hmt = _hmt || [];
(function() {{
var hm = document.createElement("script");
hm.src = "https://hm.baidu.com/hm.js?807ee27dfca59506248e7f74c812ca3d";
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(hm, s);
}})();
</script>
""")