Skip to content
This repository was archived by the owner on Jan 6, 2026. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions backupdb/backup.sh
Original file line number Diff line number Diff line change
@@ -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"

Expand Down
12 changes: 12 additions & 0 deletions backupdb/remove_old_backups.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down
21 changes: 21 additions & 0 deletions config/.bash_aliases
Original file line number Diff line number Diff line change
@@ -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
Expand Down
15 changes: 15 additions & 0 deletions config/add_pgtune_settings.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down
17 changes: 17 additions & 0 deletions config/check_file_and_replace.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down
11 changes: 11 additions & 0 deletions config/check_or_create_dirs.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down
12 changes: 12 additions & 0 deletions config/check_package_installed.sh
Original file line number Diff line number Diff line change
@@ -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

Expand Down
12 changes: 12 additions & 0 deletions config/create_kolibri_commands_file.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down
19 changes: 19 additions & 0 deletions config/flyway_bl.sh
Original file line number Diff line number Diff line change
@@ -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(){
Expand Down
10 changes: 10 additions & 0 deletions config/increase_session_timeout.sh
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions config/insert_zm_gr7_revision_into_channel_module.sh
Original file line number Diff line number Diff line change
@@ -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;"
10 changes: 10 additions & 0 deletions config/reinstall_dbhelpers_package.sh
Original file line number Diff line number Diff line change
@@ -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')\""
9 changes: 9 additions & 0 deletions config/replace_host_key.sh
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
10 changes: 10 additions & 0 deletions config/test_report_submission.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down
11 changes: 11 additions & 0 deletions reporting/alldata.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down
15 changes: 15 additions & 0 deletions reporting/monthend.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down
10 changes: 10 additions & 0 deletions reporting/send_report.sh
Original file line number Diff line number Diff line change
@@ -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

Expand Down
13 changes: 13 additions & 0 deletions swapdb/swapdb.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down