diff --git a/backupdb/backup.sh b/backupdb/backup.sh index 98dc768..a231aff 100755 --- a/backupdb/backup.sh +++ b/backupdb/backup.sh @@ -1,5 +1,21 @@ #!/bin/bash + +if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then + echo "NAME" + echo " backup - Backup" + echo + echo "DESCRIPTION" + echo " This script is used to create backups of the Kolibri and Baseline databases." + echo " It uses the credentials from environment variables to connect to the databases and create backups." + echo " The backups are then zipped and stored in the specified backup directory." + echo + echo "USAGE" + echo " ./backup.sh " + echo " ./backup.sh ~/Desktop" + exit 1 +fi + # File extension for backup files is custom format with extension .backup file_extension=".backup" diff --git a/backupdb/remove_old_backups.sh b/backupdb/remove_old_backups.sh index 95a5952..fbfb226 100755 --- a/backupdb/remove_old_backups.sh +++ b/backupdb/remove_old_backups.sh @@ -1,5 +1,17 @@ #!/bin/sh +if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then + echo "NAME" + echo " - " + echo + echo "DESCRIPTION" + echo " This script is used to clean up old backups in the specified directory." + echo " The number of days specified in 'DAYS' determines how old the backups must be before being deleted." + echo + echo " Backup files with the extension '.py' will not be deleted." + exit 1 +fi + # Backups directory DIR=~/backups # Today's date diff --git a/config/.bash_aliases b/config/.bash_aliases index 2fb8099..f9b01d9 100755 --- a/config/.bash_aliases +++ b/config/.bash_aliases @@ -1,4 +1,25 @@ #!/bin/bash + +if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then + echo "NAME" + echo " bashaliases - Bash aliases" + echo + echo "DESCRIPTION" + echo " This script contains several command aliases that can be used to perform various actions such as backup, upgrade, reboot, etc." + echo + echo " The available aliases are: shutdown, reboot, whoru, alldata, monthend, monthend_swap, restartko, backup, upgrade, tunnel, swapdb," + echo " baseline, restartbl, getkousers, flyway_bl, assign_learners, make_quiz, update_channels, export_channels." + echo " Each alias can be used to perform a specific action and can be executed by typing the alias name in the command line followed by enter." + echo + echo " Documentation for script run by the aliase can be viewed by using -h or --help option for the repective script." + echo + echo "Example" + echo " shutdown: runs kolibri stop;~/.scripts/backupdb/backup.sh;sudo shutdown -h now" + echo " backup: runs python -m kolibri stop;sudo service nginx stop;~/.scripts/backupdb/backup.sh" + exit 1 +fi + + # source the file containing colors and text output styling # shellcheck source=/dev/null diff --git a/config/add_pgtune_settings.sh b/config/add_pgtune_settings.sh index c0c2785..87c57eb 100755 --- a/config/add_pgtune_settings.sh +++ b/config/add_pgtune_settings.sh @@ -1,5 +1,20 @@ #!/bin/bash +if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then + echo "NAME" + echo " add_pgtune_settings - Postgres DB settings" + echo + echo "DESCRIPTION" + echo " This script is used to add tuning settings to a Postgres 13 database. It will check if the Postgres 13 has been set up and if" + echo " it has, the script will add the settings for 2 cores, 4GB RAM, HDD storage, data warehouse and then restart the postgresql service." + echo " The script also takes a backup of the postgresql.conf file before adding the tuning settings." + echo + echo "NOTE:" + echo " sudo prevalages are required to run the script" + exit 1 +fi + + DIRECTORY="/etc/postgresql/13/main" # Store path to conf file in variable diff --git a/config/check_file_and_replace.sh b/config/check_file_and_replace.sh index 0c24720..c511463 100755 --- a/config/check_file_and_replace.sh +++ b/config/check_file_and_replace.sh @@ -1,4 +1,21 @@ #!/bin/bash + +if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then + echo "NAME" + echo " check_file_and_replace - Check file and replace" + echo + echo "DESCRIPTION" + echo " This script contains a function 'check_file_and_replace' which is used to check for a file and create or replace it with a specified file." + echo " The function takes 3 arguments: " + echo " 1. file to check for" + echo " 2. file to create or replace it with" + echo " 3. (1 or 0) Source the file immediately after creating or replacing it" + echo " It also creates a backup of the file before replacing it." + echo + exit 1 +fi + + # shellcheck source=/dev/null # Function to check for a file, then create or replace diff --git a/config/check_or_create_dirs.sh b/config/check_or_create_dirs.sh index 5a1190e..50d1dee 100755 --- a/config/check_or_create_dirs.sh +++ b/config/check_or_create_dirs.sh @@ -1,5 +1,16 @@ #!/bin/bash +if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then + echo "NAME" + echo " check_or_create_dirs - Check or create directories" + echo + echo "DESCRIPTION" + echo " This script contains a function 'check_or_create_dirs' which is used to check and create directories specified as arguments." + echo " The function takes any number of directory paths as arguments and checks if they exist, if not it creates them." + echo " The function also prints messages to inform if a directory already exists or was created." + exit 1 +fi + check_or_create_dirs(){ DIRECTORIES=("$@") for DIRECTORY in "${DIRECTORIES[@]}"; do diff --git a/config/check_package_installed.sh b/config/check_package_installed.sh index 012d1aa..e202efd 100755 --- a/config/check_package_installed.sh +++ b/config/check_package_installed.sh @@ -1,5 +1,17 @@ #!/bin/bash +if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then + echo "NAME" + echo " check_package_installed - Check package installed" + echo + echo "DESCRIPTION" + echo " This script contains a function 'check_package_installed' which is used to check if a package is installed on the system." + echo " The function takes the package name as the argument, and checks if it is already installed by using the 'which' command." + echo " If the package is installed it informs the user, otherwise it prompts the user that the package is not installed." + echo + exit 1 +fi + check_package_installed(){ package_name=$1 diff --git a/config/create_kolibri_commands_file.sh b/config/create_kolibri_commands_file.sh index 18f0b9e..478afca 100755 --- a/config/create_kolibri_commands_file.sh +++ b/config/create_kolibri_commands_file.sh @@ -1,5 +1,17 @@ #!/bin/bash +if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then + echo "NAME" + echo " create_kolibri_commands_file - Create Kolibri commands file" + echo + echo "DESCRIPTION" + echo " This script is used to check if a file named 'kolibri_commands.txt' exists on the desktop. If the file exists, it informs the user" + echo " that it already exists and skips the script, otherwise it creates the file and writes some content to it." + echo " The file created contains information on how to execute kolibri commands in case they stop working and also a tip on how to copy and" + echo " paste commands in the terminal." + exit 1 +fi + if test -f ~/Desktop/kolibri_commands.txt; then echo "Kolibri commands file already exists. Skipping...." else diff --git a/config/flyway_bl.sh b/config/flyway_bl.sh index ec3eb78..50aa2b3 100755 --- a/config/flyway_bl.sh +++ b/config/flyway_bl.sh @@ -1,5 +1,24 @@ #!/bin/bash +if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then + echo "NAME" + echo " flyway_bl - Flyway Baseline " + echo + echo "DESCRIPTION" + echo " The function first switches to the baseline testing directory, resets the code to match the remote branch, replaces " + echo " placeholders in the migrations file with values from environment variables, and then invokes flyway with the " + echo " supplied argument. The script then calls the function with the command line argument supplied." + echo + echo "NOTE:" + echo " sudo prevalages are required to run the script" + echo + echo "Example" + echo " flyway info" + echo " flyway migrate" + echo " flyway etc" + exit 1 +fi + # Invoke flyway on baseline testing database function flyway_bl(){ diff --git a/config/increase_session_timeout.sh b/config/increase_session_timeout.sh index 1562093..17599b4 100755 --- a/config/increase_session_timeout.sh +++ b/config/increase_session_timeout.sh @@ -1,4 +1,14 @@ #!/bin/bash +if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then + echo "NAME" + echo " increase_session_timeout - Increase session timeout" + echo + echo "DESCRIPTION" + echo " This script is used to increase the idle session timeout to 15 minutes. It does this by using the 'sed' command to replace" + echo " the value 720 in the KOLIBRI_SESSION_TIMEOUT variable in the .bashrc file with the value 900." + exit 1 +fi + #Increase idle session timeout to 15 mins sudo sed -i 's/KOLIBRI_SESSION_TIMEOUT=720/KOLIBRI_SESSION_TIMEOUT=900/g' ~/.bashrc \ No newline at end of file diff --git a/config/insert_zm_gr7_revision_into_channel_module.sh b/config/insert_zm_gr7_revision_into_channel_module.sh index 7795b86..3518289 100755 --- a/config/insert_zm_gr7_revision_into_channel_module.sh +++ b/config/insert_zm_gr7_revision_into_channel_module.sh @@ -1,3 +1,15 @@ #!/bin/bash + +if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then + echo "NAME" + echo " insert_zm_gr7_revision_into_channel_module - Insert Zambia grade 7 revision" + echo + echo "DESCRIPTION" + echo " This script is used to insert a grade 7 revision Zambia channel into the channel module table in the Kolibri database, " + echo " if it does not already exist. It does this by using the 'psql' command to connect to the Kolibri database using the provided" + echo " host, user, password, and database name, and then using the 'INSERT INTO' and 'ON CONFLICT' SQL statements to insert or update" + echo " the specified channel ID and module value." + exit 1 +fi # insert grade 7 revision zambia into channel module if it does not exist PGPASSWORD=$KOLIBRI_DATABASE_PASSWORD psql -h "$KOLIBRI_DATABASE_HOST" -U "$KOLIBRI_DATABASE_USER" -d "$KOLIBRI_DATABASE_NAME" -c "INSERT INTO channel_module(channel_id, module) VALUES ('8d368058-6565-44e2-b7fe-62eb2a632698', 'numeracy') on conflict (channel_id) DO UPDATE SET module = EXCLUDED.module;" \ No newline at end of file diff --git a/config/reinstall_dbhelpers_package.sh b/config/reinstall_dbhelpers_package.sh index c7ce963..473bd7a 100755 --- a/config/reinstall_dbhelpers_package.sh +++ b/config/reinstall_dbhelpers_package.sh @@ -1,2 +1,12 @@ #!/bin/bash + +if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then + echo "NAME" + echo " reinstall_dbhelpers_package - Reinstall dbhelpers R package" + echo + echo "DESCRIPTION" + echo " This script installs the 'dbhelpers' R package from the 'Aypak' GitHub repository using 'devtools' package." + exit 1 +fi + sudo su - -c "R -e \"devtools::install_github('Aypak/dbhelpers', upgrade = 'never')\"" \ No newline at end of file diff --git a/config/replace_host_key.sh b/config/replace_host_key.sh index 4b5505c..f44aaa7 100755 --- a/config/replace_host_key.sh +++ b/config/replace_host_key.sh @@ -1,5 +1,14 @@ #!/bin/bash +if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then + echo "NAME" + echo " replace_host_key - Replace Host key" + echo + echo "DESCRIPTION" + echo " This script removes an old host key and adds a new host key for the IP address '130.211.93.74' in the known_hosts file." + exit 1 +fi + #remove old host key echo "Removing old host key" ssh-keygen -R "130.211.93.74" diff --git a/config/test_report_submission.sh b/config/test_report_submission.sh index 63fce98..82e6f65 100755 --- a/config/test_report_submission.sh +++ b/config/test_report_submission.sh @@ -1,5 +1,15 @@ #!/bin/bash +if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then + echo "NAME" + echo " test_report_submission - Test report submission" + echo + echo "DESCRIPTION" + echo " This function tests the report submission by creating a test file, populating it with the output of the 'whoru' script, and" + echo " sending it to a remote server" + exit 1 +fi + test_report_submission(){ # Send testfile to make sure scripts are correctly set up touch ~/.reports/test.R diff --git a/reporting/alldata.sh b/reporting/alldata.sh index 7a91476..95b0641 100755 --- a/reporting/alldata.sh +++ b/reporting/alldata.sh @@ -1,5 +1,16 @@ #!/bin/bash +if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then + echo "NAME" + echo " alldata - All data" + echo + echo "DESCRIPTION" + echo " This script pulls the latest changes from the 'zambia' branch of the '~/.scripts' repository, performs a silent" + echo " upgrade of all scripts, checks if the postgresql process is running, and extracts a report using the Rscript 'alldata.R' " + echo " with the first argument as its parameter. The extracted report is then sent using the 'send_report.sh' script" + exit 1 +fi + #pull latest changes from master branch in repo cd ~/.scripts || exit git reset --hard origin/zambia > /dev/null diff --git a/reporting/monthend.sh b/reporting/monthend.sh index 7fa6105..d8c9e7c 100755 --- a/reporting/monthend.sh +++ b/reporting/monthend.sh @@ -1,5 +1,20 @@ #!/bin/bash +if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then + echo "NAME" + echo " monthend - Monthend " + echo + echo "DESCRIPTION" + echo " Extracts data for the specified month and year and sends report" + echo " year and month in format MM-YY, e.g. 02-23" + echo + echo "Usage" + echo " ./monthend.sh MM-YY or monthend MM-YY" + echo " ./monthend.sh 01-23 or monthend 01-23" + + exit 1 +fi + # Pull latest changes from master branch in repo cd ~/.scripts || exit git reset --hard origin/zambia > /dev/null diff --git a/reporting/send_report.sh b/reporting/send_report.sh index 6de76f3..1f0b3b0 100755 --- a/reporting/send_report.sh +++ b/reporting/send_report.sh @@ -1,5 +1,15 @@ #!/bin/bash +if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then + echo "NAME" + echo " - " + echo + echo "DESCRIPTION" + echo " Send the most recently created file from the '/.reports' folder and then checks for the" + echo " file that was most recently created. It then creates a zip file with the file using bzip2 compression" + exit 1 +fi + # Go into reports folder cd ~/.reports || exit diff --git a/swapdb/swapdb.sh b/swapdb/swapdb.sh index 7d75aef..da92d58 100755 --- a/swapdb/swapdb.sh +++ b/swapdb/swapdb.sh @@ -1,5 +1,18 @@ #!/bin/bash +if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then + echo "NAME" + echo " swapdb - Swap database" + echo + echo "DESCRIPTION" + echo " This script is used to swap the Kolibri and Baseline Testing databases." + echo " It checks if the swap databases exist, stops the servers, and then swaps the databases." + echo + echo "Example" + echo " ./swap_db.sh " + exit 1 +fi + # source script to check if database exists # shellcheck source=/dev/null source ~/.baseline_testing/scripts/check_db_exists.sh