fix: Update local scripts tab to scan /scripts/ct directory

- Add getCtScripts() method to ScriptManager to scan ct subdirectory
- Add getCtScripts tRPC endpoint for local scripts tab
- Update ScriptsList component to use getCtScripts instead of getScripts
- Fix script path construction to use relative paths for terminal
- Local scripts tab now correctly shows scripts from /scripts/ct folder
This commit is contained in:
Michel Roegl-Brunner
2025-09-10 15:10:10 +02:00
parent c739196dc2
commit 7258f7bcfd
9 changed files with 197 additions and 6 deletions

View File

@@ -1,5 +1,6 @@
#!/usr/bin/env bash
this SCRIPT_DIR="$(dirname "$0")" source "$SCRIPT_DIR/../core/build.func"
SCRIPT_DIR="$(dirname "$0")"
source "$SCRIPT_DIR/../core/build.func"
# Copyright (c) 2021-2025 community-scripts ORG
# Author: jkrgr0
# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE

View File

@@ -1,5 +1,6 @@
#!/usr/bin/env bash
this SCRIPT_DIR="$(dirname "$0")" source "$SCRIPT_DIR/../core/build.func"
SCRIPT_DIR="$(dirname "$0")"
source "$SCRIPT_DIR/../core/build.func"
# Copyright (c) 2021-2025 community-scripts ORG
# Author: MickLesk (CanbiZ)
# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE

42
scripts/ct/adguard.sh Normal file
View File

@@ -0,0 +1,42 @@
#!/usr/bin/env bash
SCRIPT_DIR="$(dirname "$0")"
source "$SCRIPT_DIR/../core/build.func"
# Copyright (c) 2021-2025 tteck
# Author: tteck (tteckster)
# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE
# Source: https://adguard.com/
APP="Adguard"
var_tags="${var_tags:-adblock}"
var_cpu="${var_cpu:-1}"
var_ram="${var_ram:-512}"
var_disk="${var_disk:-2}"
var_os="${var_os:-debian}"
var_version="${var_version:-12}"
var_unprivileged="${var_unprivileged:-1}"
header_info "$APP"
variables
color
catch_errors
function update_script() {
header_info
check_container_storage
check_container_resources
if [[ ! -d /opt/AdGuardHome ]]; then
msg_error "No ${APP} Installation Found!"
exit
fi
msg_error "Adguard Home should be updated via the user interface."
exit
}
start
build_container
description
msg_ok "Completed Successfully!\n"
echo -e "${CREATING}${GN}${APP} setup has been successfully initialized!${CL}"
echo -e "${INFO}${YW} Access it using the following URL:${CL}"
echo -e "${TAB}${GATEWAY}${BGN}http://${IP}:3000${CL}"

View File

@@ -0,0 +1,47 @@
#!/usr/bin/env bash
SCRIPT_DIR="$(dirname "$0")"
source "$SCRIPT_DIR/../core/build.func"
# Copyright (c) 2021-2025 community-scripts ORG
# Author: MickLesk (CanbiZ)
# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE
# Source: https://adguardhome.com/
APP="Alpine-AdGuard"
var_tags="${var_tags:-alpine;adblock}"
var_cpu="${var_cpu:-1}"
var_ram="${var_ram:-256}"
var_disk="${var_disk:-1}"
var_os="${var_os:-alpine}"
var_version="${var_version:-3.22}"
var_unprivileged="${var_unprivileged:-1}"
header_info "$APP"
variables
color
catch_errors
function update_script() {
header_info
msg_info "Updating Alpine Packages"
$STD apk -U upgrade
msg_ok "Updated Alpine Packages"
msg_info "Updating AdGuard Home"
$STD /opt/AdGuardHome/AdGuardHome --update
msg_ok "Updated AdGuard Home"
msg_info "Restarting AdGuard Home"
$STD rc-service adguardhome restart
msg_ok "Restarted AdGuard Home"
exit 0
}
start
build_container
description
msg_ok "Completed Successfully!\n"
echo -e "${CREATING}${GN}${APP} setup has been successfully initialized!${CL}"
echo -e "${INFO}${YW} Access it using the following URL:${CL}"
echo -e "${TAB}${GATEWAY}${BGN}http://${IP}:3000${CL}"

View File

@@ -0,0 +1,50 @@
#!/usr/bin/env bash
# Copyright (c) 2021-2025 tteck
# Author: tteck (tteckster)
# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE
# Source: https://adguard.com/
source /dev/stdin <<<"$FUNCTIONS_FILE_PATH"
color
verb_ip6
catch_errors
setting_up_container
network_check
update_os
msg_info "Installing AdGuard Home"
$STD tar zxvf <(curl -fsSL https://static.adtidy.org/adguardhome/release/AdGuardHome_linux_amd64.tar.gz) -C /opt
msg_ok "Installed AdGuard Home"
msg_info "Creating Service"
cat <<EOF >/etc/systemd/system/AdGuardHome.service
[Unit]
Description=AdGuard Home: Network-level blocker
ConditionFileIsExecutable=/opt/AdGuardHome/AdGuardHome
After=syslog.target network-online.target
[Service]
StartLimitInterval=5
StartLimitBurst=10
ExecStart=/opt/AdGuardHome/AdGuardHome "-s" "run"
WorkingDirectory=/opt/AdGuardHome
StandardOutput=file:/var/log/AdGuardHome.out
StandardError=file:/var/log/AdGuardHome.err
Restart=always
RestartSec=10
EnvironmentFile=-/etc/sysconfig/AdGuardHome
[Install]
WantedBy=multi-user.target
EOF
systemctl enable -q --now AdGuardHome
msg_ok "Created Service"
motd_ssh
customize
msg_info "Cleaning up"
$STD apt-get -y autoremove
$STD apt-get -y autoclean
msg_ok "Cleaned"

View File

@@ -10,7 +10,7 @@ interface ScriptsListProps {
}
export function ScriptsList({ onRunScript }: ScriptsListProps) {
const { data, isLoading, error, refetch } = api.scripts.getScripts.useQuery();
const { data, isLoading, error, refetch } = api.scripts.getCtScripts.useQuery();
const [selectedScript, setSelectedScript] = useState<string | null>(null);
if (isLoading) {
@@ -110,7 +110,7 @@ export function ScriptsList({ onRunScript }: ScriptsListProps) {
View
</button>
<button
onClick={() => onRunScript(script.path, script.name)}
onClick={() => onRunScript(`scripts/ct/${script.name}`, script.name)}
disabled={!script.executable}
className={`px-4 py-2 text-sm font-medium rounded transition-colors ${
script.executable
@@ -129,7 +129,7 @@ export function ScriptsList({ onRunScript }: ScriptsListProps) {
{selectedScript && (
<div className="mt-6">
<Terminal
scriptPath={selectedScript}
scriptPath={`scripts/ct/${selectedScript.split('/').pop()}`}
onClose={() => setSelectedScript(null)}
/>
</div>

View File

@@ -17,6 +17,16 @@ export const scriptsRouter = createTRPCRouter({
};
}),
// Get CT scripts (for local scripts tab)
getCtScripts: publicProcedure
.query(async () => {
const scripts = await scriptManager.getCtScripts();
return {
scripts,
directoryInfo: scriptManager.getScriptsDirectoryInfo()
};
}),
// Get repository status
getRepoStatus: publicProcedure
.query(async () => {

View File

@@ -64,6 +64,46 @@ export class ScriptManager {
}
}
/**
* Get all available scripts in the ct subdirectory
*/
async getCtScripts(): Promise<ScriptInfo[]> {
try {
const ctDir = join(this.scriptsDir, 'ct');
const files = await readdir(ctDir);
const scripts: ScriptInfo[] = [];
for (const file of files) {
const filePath = join(ctDir, file);
const stats = await stat(filePath);
if (stats.isFile()) {
const extension = extname(file);
// Check if file extension is allowed
if (this.allowedExtensions.includes(extension)) {
// Check if file is executable
const executable = await this.isExecutable(filePath);
scripts.push({
name: file,
path: filePath,
extension,
size: stats.size,
lastModified: stats.mtime,
executable
});
}
}
}
return scripts.sort((a, b) => a.name.localeCompare(b.name));
} catch (error) {
console.error('Error reading ct scripts directory:', error);
return [];
}
}
/**
* Check if a file is executable
*/

View File

@@ -46,7 +46,7 @@ export class ScriptDownloaderService {
private modifyScriptContent(content: string): string {
// Replace the build.func source line
const oldPattern = /source <\(curl -fsSL https:\/\/raw\.githubusercontent\.com\/community-scripts\/ProxmoxVE\/main\/misc\/build\.func\)/g;
const newPattern = 'this SCRIPT_DIR="$(dirname "$0")" source "$SCRIPT_DIR/../core/build.func"';
const newPattern = 'SCRIPT_DIR="$(dirname "$0")" \nsource "$SCRIPT_DIR/../core/build.func"';
return content.replace(oldPattern, newPattern);
}