30 Star 207 Fork 28

快编程 / axe.store

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
bottle.gua 17.53 KB
一键复制 编辑 原始数据 按行查看 历史
dudu_axe 提交于 2022-09-26 18:06 . 修复bottle
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557
con importUtil = import("util")
con importPath = import('path')
con importConfig = import('config')
con cPathBottleOutput = '/usr/local/axe/meta/.bottle.output'
con cPackageInstalled = []
con isJson = importConfig.config.isJson
con wirteLogFile = importUtil.wirteLogFile
con axeBottleFromDb = function(type, name) {
return importUtil.guaSearchFromDb(type, name)
}
con hasMacosBottle = function(bottle, mac) {
con files = bottle['bottle']['stable']['files']
con keys = files.keys()
return importUtil.guaArrayHas(keys, mac)
}
con search = function(name) {
con type = 'bottle'
con mac = macosName()
var s = axeBottleFromDb(type, name)
var lines = s.split('\n')
var searchNames = []
for (i, e in lines) {
if (e == '') {
continue
}
var line = e.split('|')
var itemName = line[0]
var item = json.loads(line[1])
if (not hasMacosBottle(item, mac)) {
continue
}
con version = versionFromBottle(item)
con _item = {
'name': itemName,
'version': version,
'token': itemName,
'installed': false,
}
searchNames.add(_item)
}
return searchNames
}
con tokenExist = function(token) {
con b = bottleFromName(token)
con e = b != null
return e
}
con bottleFromName = function(name) {
var s = importUtil.guaItemFromDb('bottle',name)
if (s.length() > 0) {
var line = s.split('|')
var item = line[1]
return json.loads(item)
} else {
return null
}
}
con versionFromBottle = function(bottle) {
con versions = bottle['versions']
con version = versions['stable']
return version
}
con macosVersion = function() {
con c = 'sw_vers'
con content = importUtil.call(c)
con lines = content.split('\n')
for (var i = 0; i < lines.length(); i += 1) {
con line = lines[i]
if (line.startswith('ProductVersion')) {
con version = line.split('\t')[1]
return version
}
}
return null
}
con macosCPUArch = function() {
con c = 'uname -m'
con content = importUtil.call(c)
con arch = content.strip()
return arch
}
con macosName = function() {
con version = macosVersion()
var prefix = ''
if (macosCPUArch() == 'arm64') {
prefix = 'arm64_'
}
if (version.startswith('12')) {
return prefix + 'monterey'
} else if (version.startswith('11')) {
return prefix + 'big_sur'
} else if (version.startswith('10.15')) {
return 'catalina'
} else if (version.startswith('10.14')) {
return 'mojave'
} else if (version.startswith('10.13')) {
return 'high_sierra'
} else {
return null
}
}
con hasDownload = function(name, sha256) {
con p = importPath.pathBottleFileDownload(name)
con exist = importUtil.guaFileExist(p)
if (exist) {
con _sha256 = importUtil.guaFileSha256(p)
return sha256 == _sha256
} else {
return false
}
}
con dependenciesFromName = function(name) {
con bottle = bottleFromName(name)
con d = bottle['dependencies']
return d
}
con prepare = function() {
importUtil.guaFileMkdir(importPath.pathHome())
importUtil.guaFileMkdir(importPath.pathBottleDownload())
importUtil.guaFileMkdir(importPath.pathBottleLib())
importUtil.guaFileMkdir(importPath.pathBottleBin())
importUtil.guaFileMkdir(importPath.pathLib())
importUtil.guaFileMkdir(importPath.pathOpt())
}
con urlForBottle = function(name) {
con baseURL = 'https://mirrors.cloud.tencent.com/homebrew-bottles'
var fileInfo = fileInfoFromName(name)
var fullName = fileInfo.fullName
var version = fileInfo.versions.stable
var osName = macosName()
var rebuild = ''
if (fileInfo.rebuild > 0) {
rebuild = '{}.'.format(fileInfo.rebuild)
}
var url = '{}/{}-{}.{}.bottle.{}tar.gz'.format(baseURL, fullName, version, osName, rebuild)
return url
}
const fileInfoFromName = function(name) {
const macOs = macosName()
const item = bottleFromName(name)
const bottle = item['bottle']
if (bottle.length() == 0) {
const file = {
'url': item['urls']['stable']['url'],
'sha256': null,
}
return file
} else {
const mirrorConfig = importConfig.config.mirrorUrl()
const files = bottle['stable']['files']
const bottleName = item['name']
var version = item['versions']['stable']
var revision = item['revision']
if (revision > 0) {
version = version + "_{}".format(revision)
}
var rebuild = bottle['stable']['rebuild']
if (files.has(macOs)) {
const sha256 = files[macOs]['sha256']
if (rebuild == 0) {
rebuild = ''
var url = "{}/{}-{}.{}.bottle.tar.gz".format(mirrorConfig, bottleName, version, macOs)
const file = {
'url': url,
'sha256': sha256,
}
return file
}
var url = "{}/{}-{}.{}.bottle.{}.tar.gz".format(mirrorConfig, bottleName, version, macOs, rebuild)
const file = {
'url': url,
'sha256': sha256,
}
return file
} else {
const sha256 = files['all']['sha256']
if (rebuild == 0) {
rebuild = ''
var url = "{}/{}-{}.all.bottle.tar.gz".format(mirrorConfig, bottleName, version, macOs)
const file = {
'url': url,
'sha256': sha256,
}
return file
}
var url = "{}/{}-{}.all.bottle.{}.tar.gz".format(mirrorConfig, bottleName, version, rebuild)
const file = {
'url': url,
'sha256': sha256,
}
return file
}
}
}
con download = function(name, retryTimes=5) {
const fileInfo = fileInfoFromName(name)
var url = fileInfo['url']
const sha256 = fileInfo['sha256']
const h = hasDownload(name, sha256)
const _times = retryTimes
if (not h) {
const f = importPath.pathBottleFileDownload(name)
while (retryTimes > 0) {
const c = 'curl --location "{}" > "{}"'.format(url, f)
importUtil.callWithoutOutput(c)
const _sha256 = importUtil.guaFileSha256(f)
if (_sha256 != sha256) {
url = importConfig.config.switchedMirrorUrl(url)
retryTimes -= 1
} else {
return true
}
}
return false
} else {
return true
}
}
con tar = function(name) {
con d = importPath.pathBottlePackage(name)
con clear = 'rm -rf {}'.format(d)
importUtil.call(clear)
importUtil.guaFileMkdir(d)
con f = importPath.pathBottleFileDownload(name)
con c = 'tar xf "{}" -C "{}" --strip-components=1'.format(f, d)
importUtil.callWithoutOutput(c)
importUtil.guaFilePermissionWriteAdd(d)
}
con _pathForFrameworks = function(paths) {
con f = 'Frameworks'
con lenPaths = paths.length()
if (lenPaths == 0) {
return null
} else {
con firstPath = paths[0]
var i = 0
while (i < lenPaths) {
con path = paths[i]
if (path.has(f)) {
return path
}
i += 1
}
return firstPath
}
}
con pathLibOfPackage = function(packageName) {
con path = importPath.pathBottlePackage(packageName)
con dirName = 'lib'
con libs = importUtil.guaFileDirectoriesByName(path, dirName)
return _pathForFrameworks(libs)
}
con pathExeOfPackage = function(packageName) {
con path = importPath.pathBottlePackage(packageName)
con dirName = 'bin'
con libs = importUtil.guaFileDirectoriesByName(path, dirName)
return _pathForFrameworks(libs)
}
con fix7z = function(filePath) {
con isShell = importUtil.guaFileIsScript(filePath)
con isText = importUtil.guaFileIsText(filePath)
if (isShell or isText) {
con brewCellar = '@@HOMEBREW_CELLAR@@'
con brewPrefixOpt = '@@HOMEBREW_PREFIX@@/opt'
con brewPrefix = '@@HOMEBREW_PREFIX@@'
con brewPerl = '@@HOMEBREW_PERL@@'
con c1 = `sed -i -e 's?{}?{}?g' {} > /dev/null 2>&1`.format(brewCellar, importPath.pathBottleLib(), filePath)
con c2 = `sed -i -e 's?{}?{}?g' {} > /dev/null 2>&1`.format(brewPrefixOpt, importPath.pathOpt(), filePath)
con c3 = `sed -i -e 's?{}?{}?g' {} > /dev/null 2>&1`.format(brewPrefix, importPath.pathBottleLib(), filePath)
con c4 = `sed -i -e 's?{}?{}?g' {} > /dev/null 2>&1`.format(brewPerl, '/usr/bin/env perl', filePath)
importUtil.callWithoutOutput(c1)
importUtil.callWithoutOutput(c2)
importUtil.callWithoutOutput(c3)
importUtil.callWithoutOutput(c4)
}
}
con allExeFilesOfPackage = function(packageName) {
con path = importPath.pathBottlePackage(packageName)
con files = importUtil.guaFileAllExeInDirectory(path)
return files
}
con pathDylibAbsolute = function(pathDylibInPackage) {
if (pathDylibInPackage.startswith('opt/')) {
pathDylibInPackage = pathDylibInPackage.cut(4)
}
var split = pathDylibInPackage.split('/')
con namePackage = split[0]
con nameDylib = split[-1]
con _path = '{}/{}'.format(importPath.pathBottleLib(), pathDylibInPackage)
if (importUtil.guaFileExist(_path)) {
return _path
} else {
con pathPackageLib = pathLibOfPackage(namePackage)
con pathDylib = '{}/{}'.format(pathPackageLib, nameDylib)
return pathDylib
}
}
con parsedBottle = function() {
var commands = []
con content = stringFromFile(cPathBottleOutput)
var lines = content.split('\n')
var i = 0
con l = lines.length()
while (i < l) {
con line = lines[i]
i += 1
if (line.length() == 0) {
break
}
if (line.startswith("Load command")) {
con cmd = lines[i].strip('\n').strip(' ').split(' ')[-1]
i += 1
if (cmd == "LC_ID_DYLIB" or cmd == "LC_LOAD_DYLIB") {
i += 1
con newLine = lines[i].strip('\n').strip(' ')
i += 1
con name = newLine.split(' ')[1]
if (name.has('@@')) {
con _c = {
'cmd': cmd,
'name': name,
}
commands.add(_c)
}
}
}
}
return commands
}
con otoolDylib = function(pathDylib) {
con c = 'otool -l "{}" > "{}"'.format(pathDylib, cPathBottleOutput)
importUtil.callWithoutOutput(c)
return parsedBottle()
}
con otoolExe = function(pathExe) {
con c = 'otool -L "{}"'.format(pathExe)
if (not pathExe.startswith('/usr/local/axe')) {
if (isJson) {
wirteLogFile('{} not exist'.format(pathExe))
} else {
log('???', pathExe)
}
}
con r = importUtil.call(c)
con lines = r.split('\n')
var dylibs = []
var i = 0
con l = lines.length()
while (i < l) {
con line = lines[i]
if (line.has('@@/')) {
con name = line.strip(' ').split(' (')[0]
con pathDylib = line.split('@@/')[1].split(' (')[0]
con dylib = {
'name': name,
'path': pathDylib,
}
dylibs.add(dylib)
}
i += 1
}
return dylibs
}
con modifyDylibId = function(newName, path) {
con c = 'install_name_tool -id {} "{}"'.format(newName, path)
importUtil.call(c)
}
con modifyDylibLoad = function(oldName, newName, pathFile) {
con c = 'install_name_tool -change {} {} "{}"'.format(oldName, newName, pathFile)
importUtil.call(c)
}
con modifyExe = function(name, pathLib, pathExe) {
con c = 'install_name_tool -change {} {} "{}"'.format(name, pathLib, pathExe)
importUtil.call(c)
}
con modifyRpath = function(pathExe) {
con fileType = importUtil.guaFileType(pathExe)
if (fileType.has('Mach-O 64-bit executable x86_64')) {
con pathLib = importPath.pathLib()
con c = 'install_name_tool -add_rpath {} "{}"'.format(pathLib, pathExe)
importUtil.call(c)
}
}
con hackBottleDylib = function(pathDylibInPackage) {
con pathFile = pathDylibInPackage
con itemsReplace = otoolDylib(pathFile)
var i = 0
con l = itemsReplace.length()
while (i < l) {
con item = itemsReplace[i]
con cmd = item['cmd']
con name = item['name']
con pathUseless = name.split('@@/')[1]
con pathDylib = pathDylibAbsolute(pathUseless)
if (cmd == 'LC_ID_DYLIB') {
modifyDylibId(pathDylib, pathFile)
} else if (cmd == 'LC_LOAD_DYLIB') {
modifyDylibLoad(name, pathDylib, pathFile)
} else {
if (isJson) {
wirteLogFile('brew bottle error {}'.format(name))
} else {
log('brew bottle error {}'.format(name))
}
}
i += 1
}
}
con hackBottleDylibs = function(packageName) {
con p = pathLibOfPackage(packageName)
if (p == null) {
return
}
con allFiles = importUtil.guaFilesInDirectory(p, false)
var i = 0
con l = allFiles.length()
while (i < l) {
con file = allFiles[i]
if (file.endswith('dylib')) {
hackBottleDylib(file)
}
i += 1
}
if (p != null) {
linkToLib(p)
}
}
con linkToLib = function(packageLibPath) {
con files = importUtil.guaFilesInDirectory(packageLibPath)
con pathLib = importPath.pathLib()
var i = 0
con l = files.length()
while (i < l) {
con file = files[i]
importUtil.guaFileSymbolicLink(file, pathLib)
i += 1
}
}
con linkToBin = function(pathExe) {
con pathBin = importPath.pathBottleBin()
return importUtil.guaFileSymbolicLink(pathExe, pathBin)
}
con handleLibexec = function(packageName) {
con pathPackage = importPath.pathBottlePackage(packageName)
var pathLibexec = importUtil.guaFileDirectoriesByName(pathPackage, 'libexec')
if (pathLibexec.length() == 0) {
return
} else {
pathLibexec = pathLibexec[0]
if (importUtil.guaFileExist(pathLibexec, true)) {
con pathBin = '{}/{}'.format(pathLibexec, 'bin')
con pathLib = '{}/{}'.format(pathLibexec, 'lib')
if (importUtil.guaFileExist(pathBin, true)) {
con files = importUtil.guaFilesInDirectory(pathBin, false)
con l = files.length()
var i = 0
while (i < l) {
con file = files[i]
if (importUtil.guaFileIsExecutable(file)) {
fix7z(file)
}
importUtil.guaFileSymbolicLink(file, importPath.pathBottleBin())
i += 1
}
}
if (importUtil.guaFileExist(pathLib, true)) {
con dirs = importUtil.guaFilesInDirectory(pathLib, true, false)
con l = dirs.length()
var i = 0
while (i < l) {
con dir = dirs[i]
var c = 'cp -a "{}" "{}" 2>/dev/null'.format(dir, importPath.pathLib())
var r = importUtil.callWithoutOutput(c)
i += 1
}
}
return
} else {
return
}
}
}
con hackBottleExes = function(packageName) {
con exeFiles = allExeFilesOfPackage(packageName)
for (var i=0; i < exeFiles.length(); i+=1) {
con pathExe = exeFiles[i]
con dylibs = otoolExe(pathExe)
for (var j = 0; j < dylibs.length(); j+=1) {
con dylib = dylibs[j]
con path = dylib['path']
con name = dylib['name']
con pathDylib = pathDylibAbsolute(path)
modifyExe(name, pathDylib, pathExe)
}
modifyRpath(pathExe)
}
}
con slBottleExes = function(packageName) {
var p = pathExeOfPackage(packageName)
if (p == null) {
p = importPath.pathBottlePackage(packageName)
}
con files = importUtil.guaFilesInDirectory(p, false)
for (var i = 0; i < files.length(); i+=1) {
con file = files[i]
con e = importUtil.guaFileIsExecutable(file)
if (e) {
fix7z(file)
linkToBin(file)
}
}
}
con slOpt = function(packageName) {
con pathLib = importPath.pathBottlePackage(packageName)
con dirPackage = importUtil.guaFilesInDirectory(pathLib, true, false)
if (dirPackage.length() == 0) {
return
}
con pathVersion = dirPackage[0]
con pathOpt = importPath.pathOptPackage(packageName)
importUtil.guaFileSymbolicLink(pathVersion, pathOpt)
}
con hackBottle = function(name) {
hackBottleDylibs(name)
hackBottleExes(name)
handleLibexec(name)
slBottleExes(name)
slOpt(name)
}
con getApp = function(name) {
if (importUtil.guaArrayHas(cPackageInstalled, name)) {
return true
} else {
}
con downloadSuccess = download(name)
if (not downloadSuccess) {
if (isJson) {
wirteLogFile("download failed {}".format(name))
} else {
log("download failed {}".format(name))
}
return false
}
cPackageInstalled.add(name)
tar(name)
con deps = dependenciesFromName(name)
for (var i = 0; i < deps.length(); i+=1) {
con dep = deps[i]
con _name = dep
con r = getApp(_name)
if (not r) {
return false
}
}
hackBottle(name)
return true
}
1
https://gitee.com/kuaibiancheng/store.git
git@gitee.com:kuaibiancheng/store.git
kuaibiancheng
store
axe.store
master

搜索帮助