-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
680 additions
and
758 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@scow/portal-server": patch | ||
--- | ||
|
||
portal-server 启动时在/etc/profile.d 配置 shell 打开文件所需功能 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
sdown () { | ||
if [ "$1" == "-h" ]; then | ||
echo "Usage: sdown [-h] [FILE]" | ||
echo "Downloading the specified file (only valid in SCOW)." | ||
return 0 | ||
fi | ||
if [ $# -eq 0 ];then | ||
echo "Please enter the file name you want to download." | ||
return 0 | ||
fi | ||
if [ $# -gt 1 ];then | ||
echo "Please enter only one file name. Multiple file names are not supported." | ||
return 0 | ||
fi | ||
result=$(echo $@ | grep "/") | ||
if [[ "$result" != "" ]] | ||
then | ||
echo "sdown does not support relative paths. Please enter the file name." | ||
return 0 | ||
fi | ||
if [ ! -f "$@" ]; then | ||
echo "File $@ does not exist." | ||
return 0 | ||
fi | ||
echo "SCOW is downloading file $@ in directory `pwd`" | ||
echo "This command is only valid for SCOW web shells." | ||
} | ||
sopen () { | ||
if [ "$1" == "-h" ]; then | ||
echo "Usage: sopen [-h]" | ||
echo "Open file explorer (only valid in SCOW)." | ||
return 0 | ||
fi | ||
echo "SCOW is opening the file system `pwd`" | ||
echo "This command is only valid for SCOW web shells." | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/** | ||
* Copyright (c) 2022 Peking University and Peking University Institute for Computing and Digital Economy | ||
* SCOW is licensed under Mulan PSL v2. | ||
* You can use this software according to the terms and conditions of the Mulan PSL v2. | ||
* You may obtain a copy of Mulan PSL v2 at: | ||
* http://license.coscl.org.cn/MulanPSL2 | ||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, | ||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, | ||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. | ||
* See the Mulan PSL v2 for more details. | ||
*/ | ||
|
||
import { sftpChmod } from "@scow/lib-ssh"; | ||
import { getClusterLoginNode, sshConnect } from "src/utils/ssh"; | ||
import { Logger } from "ts-log"; | ||
|
||
|
||
const SHELL_FILE_LOCAL = "assets/scow-shell-file.sh"; | ||
const PROFILE_DIRECTORY = "/etc/profile.d"; | ||
const SHELL_FILE_REMOTE = "/etc/profile.d/scow-shell-file.sh"; | ||
|
||
|
||
export async function initShellFile(cluster: string, logger: Logger) { | ||
|
||
const host = getClusterLoginNode(cluster); | ||
if (!host) { throw new Error(`Cluster ${cluster} has no login node`); } | ||
|
||
return await sshConnect(host, "root", logger, async (ssh) => { | ||
// make sure directory /etc/profile.d exists. | ||
await ssh.mkdir(PROFILE_DIRECTORY); | ||
const sftp = await ssh.requestSFTP(); | ||
|
||
await ssh.putFile(SHELL_FILE_LOCAL, SHELL_FILE_REMOTE); | ||
await sftpChmod(sftp)(SHELL_FILE_REMOTE, "755"); | ||
logger.info(`Copy scow-shell-file.sh to the ${SHELL_FILE_REMOTE} of the login node of cluster ${cluster}.`); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/** | ||
* Copyright (c) 2022 Peking University and Peking University Institute for Computing and Digital Economy | ||
* SCOW is licensed under Mulan PSL v2. | ||
* You can use this software according to the terms and conditions of the Mulan PSL v2. | ||
* You may obtain a copy of Mulan PSL v2 at: | ||
* http://license.coscl.org.cn/MulanPSL2 | ||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, | ||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, | ||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. | ||
* See the Mulan PSL v2 for more details. | ||
*/ | ||
|
||
import { sftpExists, sftpStat, sshConnect } from "@scow/lib-ssh"; | ||
import { rootKeyPair } from "src/config/env"; | ||
import { initShellFile } from "src/utils/shell"; | ||
import { getClusterLoginNode } from "src/utils/ssh"; | ||
|
||
const SHELL_FILE_REMOTE = "/etc/profile.d/scow-shell-file.sh"; | ||
|
||
it("To test whether the scow-shell-file.sh is automatically copied", async () => { | ||
const cluster = "hpc01"; | ||
|
||
await initShellFile(cluster, console); | ||
const host = getClusterLoginNode(cluster); | ||
if (!host) { throw new Error(`Cluster ${cluster} has no login node`); } | ||
|
||
await sshConnect(host, "test", rootKeyPair, console, async (ssh) => { | ||
const sftp = await ssh.requestSFTP(); | ||
const result = await sftpExists(sftp, SHELL_FILE_REMOTE); | ||
expect(result).toEqual(true); | ||
const stats = await sftpStat(sftp)(SHELL_FILE_REMOTE); | ||
const testNumberPermission = (stats.mode & parseInt("777", 8)).toString(8); | ||
expect(testNumberPermission).toEqual("755"); | ||
}); | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.