171 lines
4.4 KiB
PowerShell
171 lines
4.4 KiB
PowerShell
[cmdletbinding()]
|
|
Param(
|
|
[Parameter(Mandatory=$false)]
|
|
[string]$Path
|
|
)
|
|
|
|
|
|
process
|
|
{
|
|
if([string]::IsNullOrWhitespace($Path))
|
|
{
|
|
Add-Type -AssemblyName System.Windows.Forms
|
|
$folderBrowser = New-Object System.Windows.Forms.FolderBrowserDialog
|
|
$folderBrowser.Description = 'Bitte den zu teilenden Ordner wählen'
|
|
$folderBrowser.ShowNewFolderButton = $true
|
|
|
|
$result = $folderBrowser.ShowDialog()
|
|
|
|
if($result -ne [System.Windows.Forms.DialogResult]::OK)
|
|
{
|
|
return;
|
|
}
|
|
$Path = $folderBrowser.SelectedPath
|
|
}
|
|
|
|
Copy-Item $MyInvocation.MyCommand.Path $Path -Force | Out-Null
|
|
|
|
Write-Warning "Initializing Database"
|
|
$null = filebrowser config init -d $db_path -c $config_path | Out-Null
|
|
|
|
Write-Warning "Creating 'guest' User"
|
|
$filebrowserArgs = @(
|
|
'users',
|
|
'add',
|
|
'guest', '""',
|
|
'--perm.download=true',
|
|
'--perm.admin=false',
|
|
'--perm.delete=false',
|
|
'--perm.execute=false',
|
|
'--perm.modify=false',
|
|
'--perm.rename=false',
|
|
'--perm.share=false',
|
|
'--perm.create=false',
|
|
'--locale=de',
|
|
'--viewMode', 'list',
|
|
'--scope', ".",
|
|
'--lockPassword',
|
|
'-d', $db_path,
|
|
'-c', $config_path)
|
|
|
|
& filebrowser @filebrowserArgs | Out-Null
|
|
|
|
Write-Warning "Folgender Ordner ist nun oeffentlich zugaenglich: $Path"
|
|
filebrowser -r $Path -d $db_path -c $config_path -a "0.0.0.0"
|
|
}
|
|
|
|
begin
|
|
{
|
|
[Console]::OutputEncoding = [System.Text.UTF8Encoding]::new()
|
|
$config_json = '{
|
|
"settings": {
|
|
"signup": false,
|
|
"createUserDir": false,
|
|
"userHomeBasePath": "/users",
|
|
"defaults": {
|
|
"scope": ".",
|
|
"locale": "de",
|
|
"viewMode": "list",
|
|
"singleClick": false,
|
|
"sorting": {
|
|
"by": "name",
|
|
"asc": false
|
|
},
|
|
"perm": {
|
|
"admin": false,
|
|
"execute": false,
|
|
"create": false,
|
|
"rename": false,
|
|
"modify": false,
|
|
"delete": false,
|
|
"share": false,
|
|
"download": true
|
|
},
|
|
"commands": [],
|
|
"hideDotfiles": false,
|
|
"dateFormat": false
|
|
},
|
|
"authMethod": "json",
|
|
"branding": {
|
|
"name": "",
|
|
"disableExternal": false,
|
|
"disableUsedPercentage": false,
|
|
"files": "",
|
|
"theme": "",
|
|
"color": ""
|
|
},
|
|
"tus": {
|
|
"chunkSize": 10485760,
|
|
"retryCount": 5
|
|
},
|
|
"commands": {
|
|
"after_copy": [],
|
|
"after_delete": [],
|
|
"after_rename": [],
|
|
"after_save": [],
|
|
"after_upload": [],
|
|
"before_copy": [],
|
|
"before_delete": [],
|
|
"before_rename": [],
|
|
"before_save": [],
|
|
"before_upload": []
|
|
},
|
|
"shell": [],
|
|
"rules": []
|
|
},
|
|
"server": {
|
|
"root": ".",
|
|
"baseURL": "",
|
|
"socket": "",
|
|
"tlsKey": "",
|
|
"tlsCert": "",
|
|
"port": "8080",
|
|
"address": "0.0.0.0",
|
|
"log": "stdout",
|
|
"enableThumbnails": false,
|
|
"resizePreview": false,
|
|
"enableExec": false,
|
|
"typeDetectionByHeader": false,
|
|
"authHook": "",
|
|
"tokenExpirationTime": ""
|
|
},
|
|
"auther": {
|
|
"recaptcha": null
|
|
}
|
|
}'
|
|
|
|
$app_dir = Join-Path $env:PROGRAMDATA 'filebrowser'
|
|
if(-not (Test-Path $app_dir -PathType Container))
|
|
{
|
|
mkdir -p $app_dir
|
|
}
|
|
|
|
$filebrowser_exe = Join-Path $app_dir 'filebrowser.exe'
|
|
if(-not (Test-Path $filebrowser_exe -PathType Leaf))
|
|
{
|
|
try
|
|
{
|
|
Invoke-WebRequest -Uri 'https://git.itsscb.de/itsscb/filebrowser/releases/download/v2.32.0/filebrowser.exe' -OutFile $filebrowser_exe -ErrorAction Stop
|
|
} catch
|
|
{
|
|
throw "Failed to download filebrowser.exe"
|
|
}
|
|
}
|
|
|
|
if(-not (Test-Path $filebrowser_exe -PathType Leaf))
|
|
{
|
|
throw "filebrowser.exe is missing"
|
|
}
|
|
|
|
Set-Alias 'filebrowser' $filebrowser_exe
|
|
$config_path = Join-Path $app_dir 'config.json'
|
|
$config_json | Set-Content -Path $config_path
|
|
|
|
$db_path = Join-Path $app_dir "filebrowser.db"
|
|
if(Test-Path $db_path -PathType Leaf)
|
|
{
|
|
Remove-Item $db_path -Force
|
|
}
|
|
|
|
}
|