mirror of
https://github.com/whyour/qinglong.git
synced 2025-12-23 15:50:07 +08:00
Add Debian/Armbian support to Linux mirror update functionality
Co-authored-by: whyour <22700758+whyour@users.noreply.github.com>
This commit is contained in:
parent
5c151f93c5
commit
8dc98a6c0e
|
|
@ -218,11 +218,58 @@ export default class SystemService {
|
||||||
...oDoc,
|
...oDoc,
|
||||||
info: { ...oDoc.info, ...info },
|
info: { ...oDoc.info, ...info },
|
||||||
});
|
});
|
||||||
let defaultDomain = 'https://dl-cdn.alpinelinux.org';
|
|
||||||
let targetDomain = 'https://dl-cdn.alpinelinux.org';
|
|
||||||
if (os.platform() !== 'linux') {
|
if (os.platform() !== 'linux') {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let command = '';
|
||||||
|
|
||||||
|
// Check if this is a Debian-based system (including Armbian)
|
||||||
|
const isDebianBased = await fs.promises.access('/etc/apt/sources.list')
|
||||||
|
.then(() => true)
|
||||||
|
.catch(() => false);
|
||||||
|
|
||||||
|
if (isDebianBased) {
|
||||||
|
// Handle Debian/Ubuntu/Armbian systems
|
||||||
|
let defaultDomain = '';
|
||||||
|
let targetDomain = info.linuxMirror || '';
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Read the current sources.list
|
||||||
|
const content = await fs.promises.readFile('/etc/apt/sources.list', {
|
||||||
|
encoding: 'utf-8',
|
||||||
|
});
|
||||||
|
|
||||||
|
// Match the first deb line to extract the current mirror
|
||||||
|
const debMatch = content.match(/^deb\s+(https?:\/\/[^\s]+)/m);
|
||||||
|
if (debMatch) {
|
||||||
|
defaultDomain = debMatch[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (defaultDomain && targetDomain) {
|
||||||
|
// Escape special characters for sed
|
||||||
|
const escapedDefault = defaultDomain.replace(/\//g, '\\/').replace(/\./g, '\\.');
|
||||||
|
const escapedTarget = targetDomain.replace(/\//g, '\\/');
|
||||||
|
|
||||||
|
command = `sed -i 's/${escapedDefault}/${escapedTarget}/g' /etc/apt/sources.list`;
|
||||||
|
|
||||||
|
// Also update sources.list.d if it exists
|
||||||
|
command += ` && if [ -d /etc/apt/sources.list.d ]; then find /etc/apt/sources.list.d -type f -name "*.list" -o -name "*.sources" | xargs -r sed -i 's/${escapedDefault}/${escapedTarget}/g'; fi`;
|
||||||
|
command += ` && apt-get update`;
|
||||||
|
} else if (targetDomain) {
|
||||||
|
// If we can't detect the current domain, just update
|
||||||
|
command = `apt-get update`;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
this.logger.error('Failed to read /etc/apt/sources.list', error);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Handle Alpine Linux systems
|
||||||
|
let defaultDomain = 'https://dl-cdn.alpinelinux.org';
|
||||||
|
let targetDomain = 'https://dl-cdn.alpinelinux.org';
|
||||||
|
|
||||||
|
try {
|
||||||
const content = await fs.promises.readFile('/etc/apk/repositories', {
|
const content = await fs.promises.readFile('/etc/apk/repositories', {
|
||||||
encoding: 'utf-8',
|
encoding: 'utf-8',
|
||||||
});
|
});
|
||||||
|
|
@ -233,13 +280,25 @@ export default class SystemService {
|
||||||
if (info.linuxMirror) {
|
if (info.linuxMirror) {
|
||||||
targetDomain = info.linuxMirror;
|
targetDomain = info.linuxMirror;
|
||||||
}
|
}
|
||||||
const command = `sed -i 's/${defaultDomain.replace(
|
command = `sed -i 's/${defaultDomain.replace(
|
||||||
/\//g,
|
/\//g,
|
||||||
'\\/',
|
'\\/',
|
||||||
)}/${targetDomain.replace(
|
)}/${targetDomain.replace(
|
||||||
/\//g,
|
/\//g,
|
||||||
'\\/',
|
'\\/',
|
||||||
)}/g' /etc/apk/repositories && apk update -f`;
|
)}/g' /etc/apk/repositories && apk update -f`;
|
||||||
|
} catch (error) {
|
||||||
|
this.logger.error('Failed to read /etc/apk/repositories', error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!command) {
|
||||||
|
this.sockService.sendMessage({
|
||||||
|
type: 'updateLinuxMirror',
|
||||||
|
message: 'No supported package manager found or mirror not configured',
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this.scheduleService.runTask(
|
this.scheduleService.runTask(
|
||||||
command,
|
command,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user