Automatic Folder and Share Creation Script

Overview

This script is designed to automate the process of creating folders and shares inside an already existing folder on polybox. It also allows for sending email notifications to users with links to the shared folders.

Prerequisites

  • Bash shell environment
  • curl command-line tool installed
  • Access to polybox with a valid username and password
  • Disabling of the polybox 2 factor authentication (only for the duration of the script) 
  • For people using a Windows environment:

Usage

The script to automatically create shares on polybox can be downloaded here: polybox_folder_share_creation.sh

Starting the Script

To start the script, navigate to the directory containing the script and run the following command in the terminal:

bash polybox_folder_share_creation.sh

Login Information

When prompted, enter your polybox username and password. The password input will be hidden for security.

---- Login Information ----
Please enter the username: example_username
Please enter the password: ****************

Path Declaration

You will be asked to enter the path of the folder you want to use on polybox and the local-path to the file containing the folder names (and optionally, email addresses).

---- Path Declaration ----
Please Enter the Path of the Folder you want to use on polybox: /Example/Path/To/Folder
Please Enter the Path to the file containing the Folder Names (and Emails): /Example/Path/To/File

Folder and Email List File Format

The file (.txt file) containing the folder names should have each folder name on a new line. If you want to send email notifications, include the email address after the folder name, separated by a semicolon (`;`). Only one email per share is allowed. So if you would like to send email notifications, the file containing the folder names and email addresses have to be formatted like the following example:

FolderName1;email1@example.com
FolderName2;email2@example.com

spaces inside the folder name are allowed

Folder Name1;email1@example.com
Folder Name2;email2@example.com

If email notifications should not be sent, the file should look like this:

FolderName1
FolderName2

The semicolon (;) is the deciding factor:

  • semicolon present = email notifications will be sent
  • semicolon not present = email notifications will not be sent

So make sure it’s either one or the other. The script will not allow a mixed mode and will just stop the process. The script will not allow a list in the following format:

FolderName1;
FolderName2;

Even if there’s only one email address missing, the script won’t allow it. So, the following is also not allowed:

FolderName1;email1@example.com
FolderName2;

And if all email addresses are provided but they’re not separated by a semicolon, it will treat the email address as part of the folder name.

Special Characters Check

If any special characters are found in the declaration of the directory you want to use on polybox, the script will terminate with an error message. The script will automatically check for special characters in folder names and paths.

The special characters that aren’t allowed, include: % * < > ö ü etc.

Some special characters are allowed, those are: Spaces, __ (underscores), – (hyphens) and the necessary / (slashes).

Folder Existence and Content Check

The script checks if the specified folder exists on polybox and whether it is empty. If the folder does not exist or is not empty, the script will terminate with an error message.

Email Notifications

If the list contains semicolons, the script assumes that email notifications should be sent. It will validate email addresses and terminate with an error if an invalid email is found.
As mentioned earlier a mixed mode is not possible, either everybody is getting an email or no one is getting one.

Expiration Date

You can set an expiration date for the shares by responding yes when prompted and entering the date in the format YYYY-MM-DD. Invalid dates like 30 February or dates in the past are not allowed.

Do you want to set an expiration date for the shares? (yes/no): yes
Please enter the expiration date in the following format (YYYY-MM-DD): 2025-05-05
(Example Date)

Folder and Share Creation

The script will create folders and shares according to the list provided. If email notifications are enabled, it will send the notifications with the share links.

Completion

Upon successful completion, the script will output the names of the created folders and shares, along with the status of email notifications if applicable. You will also be given urls
for the shares that you can copy and share.

with email notifications

----Created Folders and Shares----
Alex Tom Musterman https://polybox.ethz.ch/index.php/s/Mdi8Ncjz952oMxv | Email: ok
Jeremy Hiegelman https://polybox.ethz.ch/index.php/s/AbjhuaN0je3SYoW | Email: ok
Lerome Liakondre https://polybox.ethz.ch/index.php/s/7o1I6VGdjEzFWEf | Email: ok
Silvia Duarte https://polybox.ethz.ch/index.php/s/AfXXpBMKnc6cfXG | Email: ok
Giorgio Azzariti https://polybox.ethz.ch/index.php/s/BAV449AKQt0z4hW | Email: ok
Taeha Domi https://polybox.ethz.ch/index.php/s/nSdVnb7bQwMg4eO | Email: ok

no email notifications

----Created Folders and Shares----
Alex Tom Musterman https://polybox.ethz.ch/index.php/s/Mdi8Ncjz952oMxv
Jeremy Hiegelman https://polybox.ethz.ch/index.php/s/AbjhuaN0je3SYoW
Lerome Liakondre https://polybox.ethz.ch/index.php/s/7o1I6VGdjEzFWEf
Silvia Duarte https://polybox.ethz.ch/index.php/s/AfXXpBMKnc6cfXG
Giorgio Azzariti https://polybox.ethz.ch/index.php/s/BAV449AKQt0z4hW
Taeha Domi https://polybox.ethz.ch/index.php/s/nSdVnb7bQwMg4eO

Notes

  • Ensure that the file containing the folder names and email addresses is formatted correctly.
  • The script must have the necessary permissions to execute. You may need to set the executable permission with chmod +x polybox_folder_share_creation.sh.
  • The script is authored by Gianluca Caratsch and Taha El Isbihani with the last revision on February 28, 2024.
  • For any issues or further assistance, please contact the Service Desk (servicedesk@id.ethz.ch).

Support

The ITS Service Desk is available for assistance

Recent Posts