fix: smb mount issues (#442)
This commit is contained in:
parent
4c7bd31b88
commit
b914851841
2 changed files with 30 additions and 41 deletions
|
|
@ -12,7 +12,7 @@ ENV VITE_RESTIC_VERSION=${RESTIC_VERSION} \
|
||||||
|
|
||||||
RUN apk update --no-cache && \
|
RUN apk update --no-cache && \
|
||||||
apk upgrade --no-cache && \
|
apk upgrade --no-cache && \
|
||||||
apk add --no-cache davfs2=1.6.1-r2 openssh-client fuse3 sshfs tini nfs-utils cifs-utils util-linux
|
apk add --no-cache davfs2=1.6.1-r2 openssh-client fuse3 sshfs tini
|
||||||
|
|
||||||
ENTRYPOINT ["/sbin/tini", "-s", "--"]
|
ENTRYPOINT ["/sbin/tini", "-s", "--"]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -41,48 +41,37 @@ const mount = async (config: BackendConfig, path: string) => {
|
||||||
|
|
||||||
const options = [`port=${config.port}`, `uid=${uid}`, `gid=${gid}`];
|
const options = [`port=${config.port}`, `uid=${uid}`, `gid=${gid}`];
|
||||||
|
|
||||||
const credentialsDir = await fs.mkdtemp(`${os.tmpdir()}/zerobyte-smb-`);
|
if (config.guest) {
|
||||||
const credentialsPath = `${credentialsDir}/credentials`;
|
options.push("user=guest", "pass=");
|
||||||
|
} else {
|
||||||
|
const password = await cryptoUtils.resolveSecret(config.password ?? "");
|
||||||
|
const safePassword = password.replace(/\\/g, "\\\\").replace(/,/g, "\\,");
|
||||||
|
|
||||||
|
options.push(`user=${config.username ?? "user"}`, `pass=${safePassword}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (config.domain) {
|
||||||
|
options.push(`domain=${config.domain}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (config.vers && config.vers !== "auto") {
|
||||||
|
options.push(`vers=${config.vers}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (config.readOnly) {
|
||||||
|
options.push("ro");
|
||||||
|
}
|
||||||
|
|
||||||
|
const args = ["-t", "cifs", "-o", options.join(","), source, path];
|
||||||
|
|
||||||
|
logger.debug(`Mounting SMB volume ${path}...`);
|
||||||
|
logger.info(`Executing mount: mount ${args.join(" ")}`);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const credentialsLines: string[] = [];
|
await executeMount(args);
|
||||||
|
} catch (error) {
|
||||||
if (config.guest) {
|
logger.error(`SMB mount failed: ${toMessage(error)}`);
|
||||||
credentialsLines.push("username=guest", "password=");
|
throw error;
|
||||||
} else {
|
|
||||||
const password = await cryptoUtils.resolveSecret(config.password ?? "");
|
|
||||||
credentialsLines.push(`username=${config.username ?? ""}`, `password=${password}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (config.domain) {
|
|
||||||
credentialsLines.push(`domain=${config.domain}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
await fs.writeFile(credentialsPath, credentialsLines.join("\n"), { mode: 0o600 });
|
|
||||||
options.push(`credentials=${credentialsPath}`);
|
|
||||||
|
|
||||||
if (config.vers && config.vers !== "auto") {
|
|
||||||
options.push(`vers=${config.vers}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (config.readOnly) {
|
|
||||||
options.push("ro");
|
|
||||||
}
|
|
||||||
|
|
||||||
const args = ["-t", "cifs", "-o", options.join(","), source, path];
|
|
||||||
|
|
||||||
logger.debug(`Mounting SMB volume ${path}...`);
|
|
||||||
logger.info(`Executing mount: mount ${args.join(" ")}`);
|
|
||||||
|
|
||||||
try {
|
|
||||||
await executeMount(args);
|
|
||||||
} catch (error) {
|
|
||||||
logger.warn(`Initial SMB mount failed, retrying with -i flag: ${toMessage(error)}`);
|
|
||||||
await executeMount(["-i", ...args]);
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
await fs.rm(credentialsPath, { force: true });
|
|
||||||
await fs.rm(credentialsDir, { force: true, recursive: true });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.info(`SMB volume at ${path} mounted successfully.`);
|
logger.info(`SMB volume at ${path} mounted successfully.`);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue