diff --git a/about-us.txt b/components/about-us.txt similarity index 100% rename from about-us.txt rename to components/about-us.txt diff --git a/components/blastdb/16S_ribosomal_RNA/16S_ribosomal_RNA.ndb b/components/blastdb/16S_ribosomal_RNA/16S_ribosomal_RNA.ndb new file mode 100644 index 0000000..3c90147 Binary files /dev/null and b/components/blastdb/16S_ribosomal_RNA/16S_ribosomal_RNA.ndb differ diff --git a/components/blastdb/16S_ribosomal_RNA/16S_ribosomal_RNA.nhr b/components/blastdb/16S_ribosomal_RNA/16S_ribosomal_RNA.nhr new file mode 100644 index 0000000..faf44b7 Binary files /dev/null and b/components/blastdb/16S_ribosomal_RNA/16S_ribosomal_RNA.nhr differ diff --git a/components/blastdb/16S_ribosomal_RNA/16S_ribosomal_RNA.nin b/components/blastdb/16S_ribosomal_RNA/16S_ribosomal_RNA.nin new file mode 100644 index 0000000..ef18c7f Binary files /dev/null and b/components/blastdb/16S_ribosomal_RNA/16S_ribosomal_RNA.nin differ diff --git a/components/blastdb/16S_ribosomal_RNA/16S_ribosomal_RNA.nnd b/components/blastdb/16S_ribosomal_RNA/16S_ribosomal_RNA.nnd new file mode 100644 index 0000000..759332b Binary files /dev/null and b/components/blastdb/16S_ribosomal_RNA/16S_ribosomal_RNA.nnd differ diff --git a/components/blastdb/16S_ribosomal_RNA/16S_ribosomal_RNA.nni b/components/blastdb/16S_ribosomal_RNA/16S_ribosomal_RNA.nni new file mode 100644 index 0000000..67c2d2f Binary files /dev/null and b/components/blastdb/16S_ribosomal_RNA/16S_ribosomal_RNA.nni differ diff --git a/components/blastdb/16S_ribosomal_RNA/16S_ribosomal_RNA.nog b/components/blastdb/16S_ribosomal_RNA/16S_ribosomal_RNA.nog new file mode 100644 index 0000000..6a4c42d Binary files /dev/null and b/components/blastdb/16S_ribosomal_RNA/16S_ribosomal_RNA.nog differ diff --git a/components/blastdb/16S_ribosomal_RNA/16S_ribosomal_RNA.nos b/components/blastdb/16S_ribosomal_RNA/16S_ribosomal_RNA.nos new file mode 100644 index 0000000..178a225 Binary files /dev/null and b/components/blastdb/16S_ribosomal_RNA/16S_ribosomal_RNA.nos differ diff --git a/components/blastdb/16S_ribosomal_RNA/16S_ribosomal_RNA.not b/components/blastdb/16S_ribosomal_RNA/16S_ribosomal_RNA.not new file mode 100644 index 0000000..b987b4c Binary files /dev/null and b/components/blastdb/16S_ribosomal_RNA/16S_ribosomal_RNA.not differ diff --git a/components/blastdb/16S_ribosomal_RNA/16S_ribosomal_RNA.nsq b/components/blastdb/16S_ribosomal_RNA/16S_ribosomal_RNA.nsq new file mode 100644 index 0000000..7fb4244 Binary files /dev/null and b/components/blastdb/16S_ribosomal_RNA/16S_ribosomal_RNA.nsq differ diff --git a/components/blastdb/16S_ribosomal_RNA/16S_ribosomal_RNA.ntf b/components/blastdb/16S_ribosomal_RNA/16S_ribosomal_RNA.ntf new file mode 100644 index 0000000..5a4d0d3 Binary files /dev/null and b/components/blastdb/16S_ribosomal_RNA/16S_ribosomal_RNA.ntf differ diff --git a/components/blastdb/16S_ribosomal_RNA/16S_ribosomal_RNA.nto b/components/blastdb/16S_ribosomal_RNA/16S_ribosomal_RNA.nto new file mode 100644 index 0000000..48a6ded Binary files /dev/null and b/components/blastdb/16S_ribosomal_RNA/16S_ribosomal_RNA.nto differ diff --git a/components/countries.json b/components/countries.json new file mode 100644 index 0000000..ffa870f --- /dev/null +++ b/components/countries.json @@ -0,0 +1,252 @@ +{ + "AD": "Andorra", + "AE": "United Arab Emirates", + "AF": "Afghanistan", + "AG": "Antigua and Barbuda", + "AI": "Anguilla", + "AL": "Albania", + "AM": "Armenia", + "AN": "Netherlands Antilles", + "AO": "Angola", + "AQ": "Antarctica", + "AR": "Argentina", + "AS": "American Samoa", + "AT": "Austria", + "AU": "Australia", + "AW": "Aruba", + "AX": "Aland Islands", + "AZ": "Azerbaijan", + "BA": "Bosnia and Herzegovina", + "BB": "Barbados", + "BD": "Bangladesh", + "BE": "Belgium", + "BF": "Burkina Faso", + "BG": "Bulgaria", + "BH": "Bahrain", + "BI": "Burundi", + "BJ": "Benin", + "BL": "Saint Barthélemy", + "BM": "Bermuda", + "BN": "Brunei", + "BO": "Bolivia", + "BQ": "Caribbean Netherlands", + "BR": "Brazil", + "BS": "Bahamas", + "BT": "Bhutan", + "BV": "Bouvet Island", + "BW": "Botswana", + "BY": "Belarus", + "BZ": "Belize", + "CA": "Canada", + "CC": "Cocos (Keeling) Islands", + "CD": "Congo (Kinshasa)", + "CF": "Central African Republic", + "CG": "Congo (Brazzaville)", + "CH": "Switzerland", + "CI": "Ivory Coast", + "CK": "Cook Islands", + "CL": "Chile", + "CM": "Cameroon", + "CN": "China", + "CO": "Colombia", + "CR": "Costa Rica", + "CU": "Cuba", + "CV": "Cape Verde", + "CW": "Curaçao", + "CX": "Christmas Island", + "CY": "Cyprus", + "CZ": "Czech Republic", + "DE": "Germany", + "DJ": "Djibouti", + "DK": "Denmark", + "DM": "Dominica", + "DO": "Dominican Republic", + "DZ": "Algeria", + "EC": "Ecuador", + "EE": "Estonia", + "EG": "Egypt", + "EH": "Western Sahara", + "ER": "Eritrea", + "ES": "Spain", + "ET": "Ethiopia", + "FI": "Finland", + "FJ": "Fiji", + "FK": "Falkland Islands", + "FM": "Micronesia", + "FO": "Faroe Islands", + "FR": "France", + "GA": "Gabon", + "GB": "United Kingdom", + "GD": "Grenada", + "GE": "Georgia", + "GF": "French Guiana", + "GG": "Guernsey", + "GH": "Ghana", + "GI": "Gibraltar", + "GL": "Greenland", + "GM": "Gambia", + "GN": "Guinea", + "GP": "Guadeloupe", + "GQ": "Equatorial Guinea", + "GR": "Greece", + "GS": "South Georgia and the South Sandwich Islands", + "GT": "Guatemala", + "GU": "Guam", + "GW": "Guinea-Bissau", + "GY": "Guyana", + "HK": "Hong Kong S.A.R., China", + "HM": "Heard Island and McDonald Islands", + "HN": "Honduras", + "HR": "Croatia", + "HT": "Haiti", + "HU": "Hungary", + "ID": "Indonesia", + "IE": "Ireland", + "IL": "Israel", + "IM": "Isle of Man", + "IN": "India", + "IO": "British Indian Ocean Territory", + "IQ": "Iraq", + "IR": "Iran", + "IS": "Iceland", + "IT": "Italy", + "JE": "Jersey", + "JM": "Jamaica", + "JO": "Jordan", + "JP": "Japan", + "KE": "Kenya", + "KG": "Kyrgyzstan", + "KH": "Cambodia", + "KI": "Kiribati", + "KM": "Comoros", + "KN": "Saint Kitts and Nevis", + "KP": "North Korea", + "KR": "South Korea", + "KW": "Kuwait", + "KY": "Cayman Islands", + "KZ": "Kazakhstan", + "LA": "Laos", + "LB": "Lebanon", + "LC": "Saint Lucia", + "LI": "Liechtenstein", + "LK": "Sri Lanka", + "LR": "Liberia", + "LS": "Lesotho", + "LT": "Lithuania", + "LU": "Luxembourg", + "LV": "Latvia", + "LY": "Libya", + "MA": "Morocco", + "MC": "Monaco", + "MD": "Moldova", + "ME": "Montenegro", + "MF": "Saint Martin (French part)", + "MG": "Madagascar", + "MH": "Marshall Islands", + "MK": "Macedonia", + "ML": "Mali", + "MM": "Myanmar", + "MN": "Mongolia", + "MO": "Macao S.A.R., China", + "MP": "Northern Mariana Islands", + "MQ": "Martinique", + "MR": "Mauritania", + "MS": "Montserrat", + "MT": "Malta", + "MU": "Mauritius", + "MV": "Maldives", + "MW": "Malawi", + "MX": "Mexico", + "MY": "Malaysia", + "MZ": "Mozambique", + "NA": "Namibia", + "NC": "New Caledonia", + "NE": "Niger", + "NF": "Norfolk Island", + "NG": "Nigeria", + "NI": "Nicaragua", + "NL": "Netherlands", + "NO": "Norway", + "NP": "Nepal", + "NR": "Nauru", + "NU": "Niue", + "NZ": "New Zealand", + "OM": "Oman", + "PA": "Panama", + "PE": "Peru", + "PF": "French Polynesia", + "PG": "Papua New Guinea", + "PH": "Philippines", + "PK": "Pakistan", + "PL": "Poland", + "PM": "Saint Pierre and Miquelon", + "PN": "Pitcairn", + "PR": "Puerto Rico", + "PS": "Palestinian Territory", + "PT": "Portugal", + "PW": "Palau", + "PY": "Paraguay", + "QA": "Qatar", + "RE": "Reunion", + "RO": "Romania", + "RS": "Serbia", + "RU": "Russia", + "RW": "Rwanda", + "SA": "Saudi Arabia", + "SB": "Solomon Islands", + "SC": "Seychelles", + "SD": "Sudan", + "SE": "Sweden", + "SG": "Singapore", + "SH": "Saint Helena", + "SI": "Slovenia", + "SJ": "Svalbard and Jan Mayen", + "SK": "Slovakia", + "SL": "Sierra Leone", + "SM": "San Marino", + "SN": "Senegal", + "SO": "Somalia", + "SR": "Suriname", + "SS": "South Sudan", + "ST": "Sao Tome and Principe", + "SV": "El Salvador", + "SX": "Sint Maarten", + "SY": "Syria", + "SZ": "Swaziland", + "TC": "Turks and Caicos Islands", + "TD": "Chad", + "TF": "French Southern Territories", + "TG": "Togo", + "TH": "Thailand", + "TJ": "Tajikistan", + "TK": "Tokelau", + "TL": "Timor-Leste", + "TM": "Turkmenistan", + "TN": "Tunisia", + "TO": "Tonga", + "TR": "Turkey", + "TT": "Trinidad and Tobago", + "TV": "Tuvalu", + "TW": "Taiwan", + "TZ": "Tanzania", + "UA": "Ukraine", + "UG": "Uganda", + "UM": "United States Minor Outlying Islands", + "US": "United States", + "UY": "Uruguay", + "UZ": "Uzbekistan", + "VA": "Vatican", + "VC": "Saint Vincent and the Grenadines", + "VE": "Venezuela", + "VG": "British Virgin Islands", + "VI": "U.S. Virgin Islands", + "VN": "Vietnam", + "VU": "Vanuatu", + "WF": "Wallis and Futuna", + "WS": "Samoa", + "YE": "Yemen", + "YT": "Mayotte", + "ZA": "South Africa", + "ZM": "Zambia", + "ZW": "Zimbabwe" +} diff --git a/components/dependencies.txt b/components/dependencies.txt new file mode 100644 index 0000000..639f1fe --- /dev/null +++ b/components/dependencies.txt @@ -0,0 +1,4 @@ +bind9-dnsutils +curl +jq +wget diff --git a/scripts/field_formatter_settings.patch b/components/field_formatter_settings.patch similarity index 100% rename from scripts/field_formatter_settings.patch rename to components/field_formatter_settings.patch diff --git a/functions/_input_db_name.sh b/functions/_input_db_name.sh index 905645b..f97f80e 100644 --- a/functions/_input_db_name.sh +++ b/functions/_input_db_name.sh @@ -2,32 +2,30 @@ function _input_db_name { while true; do - if command -v whiptail > /dev/null; then # Whiptail is installed - psqldb=$(whiptail --title "USER INPUT" --inputbox \ - "\nEnter the name for a new database for our website:\ - \n\n (Press ENTER to continue)" \ - 12 47 \ - "$psqldb" \ - 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 1 ]; then - exit 1 - fi - else # Whiptail is not installed - read -r -p "Enter the name for a new database for our website: " psqldb + psqldb=$(whiptail --title "USER INPUT" --inputbox \ + "\nEnter the name for a new database for our website:\ + \n\n (Press ENTER to continue)" \ + 12 47 \ + "$psqldb" \ + 3>&1 1>&2 2>&3) + exitstatus=$? + if [ $exitstatus = 1 ]; then + exit 1 fi # Check if input is empty - if [ -n "$psqldb" ]; then + if _is_variable_nonempty "$psqldb"; then + break + fi + + # Check if database name is valid + if _is_db_name_valid "$psqldb"; then break else - whiptail --msgbox " Please enter a value" 7 30 + continue fi done - # Replaces 'spaces' with 'hyphens' - psqldb=$(echo "$psqldb" | tr ' ' '-') - # Export variable for use by child scripts export psqldb } diff --git a/functions/_input_db_pass.sh b/functions/_input_db_pass.sh index 9e658df..d37256e 100644 --- a/functions/_input_db_pass.sh +++ b/functions/_input_db_pass.sh @@ -2,25 +2,19 @@ function _input_db_pass { while true; do - if command -v whiptail > /dev/null; then - PGPASSWORD=$(whiptail --title "USER INPUT" --passwordbox \ - "\nEnter a password for the new user:\n\n (Press ENTER to continue)" \ - 11 38 \ - "$PGPASSWORD" \ - 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 1 ]; then - exit 1 - fi - else - read -r -p "Enter a password for the new user: " PGPASSWORD + PGPASSWORD=$(whiptail --title "USER INPUT" --passwordbox \ + "\nEnter a password for the new user:\n\n (Press ENTER to continue)" \ + 11 38 \ + "$PGPASSWORD" \ + 3>&1 1>&2 2>&3) + exitstatus=$? + if [ $exitstatus = 1 ]; then + exit 1 fi # Check if input is empty - if [ -n "$PGPASSWORD" ]; then + if _is_variable_nonempty "$PGPASSWORD"; then break - else - whiptail --msgbox " Please enter a value" 7 30 fi done # Hide PGPASSWORD by replacing characters with * diff --git a/functions/_input_db_username.sh b/functions/_input_db_username.sh index bc40cf3..cf6e2a2 100644 --- a/functions/_input_db_username.sh +++ b/functions/_input_db_username.sh @@ -2,29 +2,28 @@ function _input_db_username { while true; do - if command -v whiptail > /dev/null; then - psqluser=$(whiptail --title "USER INPUT" --inputbox \ - "\nEnter username for a new database user:\n\n (Press ENTER to continue)" \ - 11 44 \ - "$psqluser" \ - 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 1 ]; then - exit 1 - fi - else - read -r -p "Enter a new username (role) for postgres: " psqluser + psqluser=$(whiptail --title "USER INPUT" --inputbox \ + "\nEnter username for a new database user:\n\n (Press ENTER to continue)" \ + 11 44 \ + "$psqluser" \ + 3>&1 1>&2 2>&3) + exitstatus=$? + if [ $exitstatus = 1 ]; then + exit 1 fi # Check if input is empty - if [ -n "$psqluser" ]; then + if _is_variable_nonempty "$psqluser"; then + break + fi + + # Check if directory name is valid + if _is_username_valid "$psqluser"; then break else - whiptail --msgbox " Please enter a value" 7 30 + whiptail --msgbox "Username is invalid. It should only contain alphabets, numbers and underscores & must start with an alphabet." 9 47 fi done - # Replaces 'spaces' with 'hyphens' - psqluser=$(echo "$psqluser" | tr ' ' '-') # Export the variable for use by child scripts export psqluser diff --git a/functions/_input_drupal_country.sh b/functions/_input_drupal_country.sh index a3c2bd9..3329def 100644 --- a/functions/_input_drupal_country.sh +++ b/functions/_input_drupal_country.sh @@ -1,284 +1,40 @@ #!/usr/bin/env bash function _input_drupal_country { - # Install dependencies - if command -v apt-get > /dev/null; then - sudo apt-get install -y curl jq - fi - # Create an array of country codes - country_codes=("AD" "AE" "AF" "AG" "AI" "AL" "AM" "AN" "AO" "AQ" "AR" "AS" "AT" "AU" "AW" "AX" "AZ" "BA" "BB" "BD" "BE" "BF" "BG" "BH" "BI" "BJ" "BL" "BM" "BN" "BO" "BQ" "BR" "BS" "BT" "BV" "BW" "BY" "BZ" "CA" "CC" "CD" "CF" "CG" "CH" "CI" "CK" "CL" "CM" "CN" "CO" "CR" "CU" "CV" "CW" "CX" "CY" "CZ" "DE" "DJ" "DK" "DM" "DO" "DZ" "EC" "EE" "EG" "EH" "ER" "ES" "ET" "FI" "FJ" "FK" "FM" "FO" "FR" "GA" "GB" "GD" "GE" "GF" "GG" "GH" "GI" "GL" "GM" "GN" "GP" "GQ" "GR" "GS" "GT" "GU" "GW" "GY" "HK" "HM" "HN" "HR" "HT" "HU" "ID" "IE" "IL" "IM" "IN" "IO" "IQ" "IR" "IS" "IT" "JE" "JM" "JO" "JP" "KE" "KG" "KH" "KI" "KM" "KN" "KP" "KR" "KW" "KY" "KZ" "LA" "LB" "LC" "LI" "LK" "LR" "LS" "LT" "LU" "LV" "LY" "MA" "MC" "MD" "ME" "MF" "MG" "MH" "MK" "ML" "MM" "MN" "MO" "MP" "MQ" "MR" "MS" "MT" "MU" "MV" "MW" "MX" "MY" "MZ" "NA" "NC" "NE" "NF" "NG" "NI" "NL" "NO" "NP" "NR" "NU" "NZ" "OM" "PA" "PE" "PF" "PG" "PH" "PK" "PL" "PM" "PN" "PR" "PS" "PT" "PW" "PY" "QA" "RE" "RO" "RS" "RU" "RW" "SA" "SB" "SC" "SD" "SE" "SG" "SH" "SI" "SJ" "SK" "SL" "SM" "SN" "SO" "SR" "SS" "ST" "SV" "SX" "SY" "SZ" "TC" "TD" "TF" "TG" "TH" "TJ" "TK" "TL" "TM" "TN" "TO" "TR" "TT" "TV" "TW" "TZ" "UA" "UG" "UM" "US" "UY" "UZ" "VA" "VC" "VE" "VG" "VI" "VN" "VU" "WF" "WS" "YE" "YT" "ZA" "ZM" "ZW") + # Try to automatically detect country using curl, jq commands + drupal_country_code=$(curl -s ipinfo.io | jq -r '.country') - # Validate http status code to see if ipinfo.io is reachable - response=$(curl -s -w "%{http_code}" ipinfo.io) - http_status=$(echo "$response" | tail -c 4) + # Use jq to check if the country code exists in the JSON + cc_exists=$(jq --arg key "$drupal_country_code" 'has($key)' ./components/countries.json) - if [ "$http_status" -eq 200 ]; then - # Try to automatically detect country using curl, jq commands - drupal_country=$(curl -s ipinfo.io | jq -r '.country') - fi + if [ "$cc_exists" = "false" ]; then + # Load JSON data into a string + countries=$(jq -r 'to_entries | map("\(.key) \(.value)") | .[]' ./components/countries.json) + + # Create an array with country codes and names + country_items=() + while read -r line; do + country_code=$(echo "$line" | cut -d' ' -f1) + country_name=$(echo "$line" | cut -d' ' -f2-) + country_items+=("$country_code" "$country_name") + done <<< "$countries" - if [[ ! " ${country_codes[@]} " =~ " $drupal_country " ]]; then - if command -v whiptail > /dev/null; then - drupal_country=$(whiptail --title "SELECT COUNTRY" --menu "\n (UP/DOWN ARROW KEYS to select, ENTER to confirm)" 18 55 9 \ - "AD" "Andorra" \ - "AE" "United Arab Emirates" \ - "AF" "Afghanistan" \ - "AG" "Antigua and Barbuda" \ - "AI" "Anguilla" \ - "AL" "Albania" \ - "AM" "Armenia" \ - "AN" "Netherlands Antilles" \ - "AO" "Angola" \ - "AQ" "Antarctica" \ - "AR" "Argentina" \ - "AS" "American Samoa" \ - "AT" "Austria" \ - "AU" "Australia" \ - "AW" "Aruba" \ - "AX" "Aland Islands" \ - "AZ" "Azerbaijan" \ - "BA" "Bosnia and Herzegovina" \ - "BB" "Barbados" \ - "BD" "Bangladesh" \ - "BE" "Belgium" \ - "BF" "Burkina Faso" \ - "BG" "Bulgaria" \ - "BH" "Bahrain" \ - "BI" "Burundi" \ - "BJ" "Benin" \ - "BL" "Saint Barthélemy" \ - "BM" "Bermuda" \ - "BN" "Brunei" \ - "BO" "Bolivia" \ - "BQ" "Caribbean Netherlands" \ - "BR" "Brazil" \ - "BS" "Bahamas" \ - "BT" "Bhutan" \ - "BV" "Bouvet Island" \ - "BW" "Botswana" \ - "BY" "Belarus" \ - "BZ" "Belize" \ - "CA" "Canada" \ - "CC" "Cocos (Keeling) Islands" \ - "CD" "Congo (Kinshasa)" \ - "CF" "Central African Republic" \ - "CG" "Congo (Brazzaville)" \ - "CH" "Switzerland" \ - "CI" "Ivory Coast" \ - "CK" "Cook Islands" \ - "CL" "Chile" \ - "CM" "Cameroon" \ - "CN" "China" \ - "CO" "Colombia" \ - "CR" "Costa Rica" \ - "CU" "Cuba" \ - "CV" "Cape Verde" \ - "CW" "Curaçao" \ - "CX" "Christmas Island" \ - "CY" "Cyprus" \ - "CZ" "Czech Republic" \ - "DE" "Germany" \ - "DJ" "Djibouti" \ - "DK" "Denmark" \ - "DM" "Dominica" \ - "DO" "Dominican Republic" \ - "DZ" "Algeria" \ - "EC" "Ecuador" \ - "EE" "Estonia" \ - "EG" "Egypt" \ - "EH" "Western Sahara" \ - "ER" "Eritrea" \ - "ES" "Spain" \ - "ET" "Ethiopia" \ - "FI" "Finland" \ - "FJ" "Fiji" \ - "FK" "Falkland Islands" \ - "FM" "Micronesia" \ - "FO" "Faroe Islands" \ - "FR" "France" \ - "GA" "Gabon" \ - "GB" "United Kingdom" \ - "GD" "Grenada" \ - "GE" "Georgia" \ - "GF" "French Guiana" \ - "GG" "Guernsey" \ - "GH" "Ghana" \ - "GI" "Gibraltar" \ - "GL" "Greenland" \ - "GM" "Gambia" \ - "GN" "Guinea" \ - "GP" "Guadeloupe" \ - "GQ" "Equatorial Guinea" \ - "GR" "Greece" \ - "GS" "South Georgia and the South Sandwich Islands" \ - "GT" "Guatemala" \ - "GU" "Guam" \ - "GW" "Guinea-Bissau" \ - "GY" "Guyana" \ - "HK" "Hong Kong S.A.R., China" \ - "HM" "Heard Island and McDonald Islands" \ - "HN" "Honduras" \ - "HR" "Croatia" \ - "HT" "Haiti" \ - "HU" "Hungary" \ - "ID" "Indonesia" \ - "IE" "Ireland" \ - "IL" "Israel" \ - "IM" "Isle of Man" \ - "IN" "India" \ - "IO" "British Indian Ocean Territory" \ - "IQ" "Iraq" \ - "IR" "Iran" \ - "IS" "Iceland" \ - "IT" "Italy" \ - "JE" "Jersey" \ - "JM" "Jamaica" \ - "JO" "Jordan" \ - "JP" "Japan" \ - "KE" "Kenya" \ - "KG" "Kyrgyzstan" \ - "KH" "Cambodia" \ - "KI" "Kiribati" \ - "KM" "Comoros" \ - "KN" "Saint Kitts and Nevis" \ - "KP" "North Korea" \ - "KR" "South Korea" \ - "KW" "Kuwait" \ - "KY" "Cayman Islands" \ - "KZ" "Kazakhstan" \ - "LA" "Laos" \ - "LB" "Lebanon" \ - "LC" "Saint Lucia" \ - "LI" "Liechtenstein" \ - "LK" "Sri Lanka" \ - "LR" "Liberia" \ - "LS" "Lesotho" \ - "LT" "Lithuania" \ - "LU" "Luxembourg" \ - "LV" "Latvia" \ - "LY" "Libya" \ - "MA" "Morocco" \ - "MC" "Monaco" \ - "MD" "Moldova" \ - "ME" "Montenegro" \ - "MF" "Saint Martin (French part)" \ - "MG" "Madagascar" \ - "MH" "Marshall Islands" \ - "MK" "Macedonia" \ - "ML" "Mali" \ - "MM" "Myanmar" \ - "MN" "Mongolia" \ - "MO" "Macao S.A.R., China" \ - "MP" "Northern Mariana Islands" \ - "MQ" "Martinique" \ - "MR" "Mauritania" \ - "MS" "Montserrat" \ - "MT" "Malta" \ - "MU" "Mauritius" \ - "MV" "Maldives" \ - "MW" "Malawi" \ - "MX" "Mexico" \ - "MY" "Malaysia" \ - "MZ" "Mozambique" \ - "NA" "Namibia" \ - "NC" "New Caledonia" \ - "NE" "Niger" \ - "NF" "Norfolk Island" \ - "NG" "Nigeria" \ - "NI" "Nicaragua" \ - "NL" "Netherlands" \ - "NO" "Norway" \ - "NP" "Nepal" \ - "NR" "Nauru" \ - "NU" "Niue" \ - "NZ" "New Zealand" \ - "OM" "Oman" \ - "PA" "Panama" \ - "PE" "Peru" \ - "PF" "French Polynesia" \ - "PG" "Papua New Guinea" \ - "PH" "Philippines" \ - "PK" "Pakistan" \ - "PL" "Poland" \ - "PM" "Saint Pierre and Miquelon" \ - "PN" "Pitcairn" \ - "PR" "Puerto Rico" \ - "PS" "Palestinian Territory" \ - "PT" "Portugal" \ - "PW" "Palau" \ - "PY" "Paraguay" \ - "QA" "Qatar" \ - "RE" "Reunion" \ - "RO" "Romania" \ - "RS" "Serbia" \ - "RU" "Russia" \ - "RW" "Rwanda" \ - "SA" "Saudi Arabia" \ - "SB" "Solomon Islands" \ - "SC" "Seychelles" \ - "SD" "Sudan" \ - "SE" "Sweden" \ - "SG" "Singapore" \ - "SH" "Saint Helena" \ - "SI" "Slovenia" \ - "SJ" "Svalbard and Jan Mayen" \ - "SK" "Slovakia" \ - "SL" "Sierra Leone" \ - "SM" "San Marino" \ - "SN" "Senegal" \ - "SO" "Somalia" \ - "SR" "Suriname" \ - "SS" "South Sudan" \ - "ST" "Sao Tome and Principe" \ - "SV" "El Salvador" \ - "SX" "Sint Maarten" \ - "SY" "Syria" \ - "SZ" "Swaziland" \ - "TC" "Turks and Caicos Islands" \ - "TD" "Chad" \ - "TF" "French Southern Territories" \ - "TG" "Togo" \ - "TH" "Thailand" \ - "TJ" "Tajikistan" \ - "TK" "Tokelau" \ - "TL" "Timor-Leste" \ - "TM" "Turkmenistan" \ - "TN" "Tunisia" \ - "TO" "Tonga" \ - "TR" "Turkey" \ - "TT" "Trinidad and Tobago" \ - "TV" "Tuvalu" \ - "TW" "Taiwan" \ - "TZ" "Tanzania" \ - "UA" "Ukraine" \ - "UG" "Uganda" \ - "UM" "United States Minor Outlying Islands" \ - "US" "United States" \ - "UY" "Uruguay" \ - "UZ" "Uzbekistan" \ - "VA" "Vatican" \ - "VC" "Saint Vincent and the Grenadines" \ - "VE" "Venezuela" \ - "VG" "British Virgin Islands" \ - "VI" "U.S. Virgin Islands" \ - "VN" "Vietnam" \ - "VU" "Vanuatu" \ - "WF" "Wallis and Futuna" \ - "WS" "Samoa" \ - "YE" "Yemen" \ - "YT" "Mayotte" \ - "ZA" "South Africa" \ - "ZM" "Zambia" \ - "ZW" "Zimbabwe" 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 1 ]; then - exit 1 - fi + # Whiptail menu + drupal_country_code=$(whiptail --title "SELECT COUNTRY" --menu "\n (UP/DOWN ARROW KEYS to select, ENTER to confirm)" 18 55 9 "${country_items[@]}" 3>&1 1>&2 2>&3) + + exitstatus=$? + if [ $exitstatus = 1 ]; then + exit 1 fi fi - - export drupal_country # Export drupal country variable to be used by child scripts + + # Change country code to country name + drupal_country_name=$(jq -r --arg key "$drupal_country_code" '.[$key]' ./components/countries.json) + + # Export drupal country variables to be used by child scripts + export drupal_country_code + export drupal_country_name } # Export the function to be used by child scripts diff --git a/functions/_input_drupal_dir.sh b/functions/_input_drupal_dir.sh index dbd0943..cb35dc3 100644 --- a/functions/_input_drupal_dir.sh +++ b/functions/_input_drupal_dir.sh @@ -2,32 +2,39 @@ function _input_drupal_dir { while true; do - if command -v whiptail > /dev/null; then - drupalsitedir=$(whiptail --title "DRUPAL WEBSITE DETAILS" --inputbox \ - "\nEnter the name of the directory to which\n drupal website needs to be installed:\ - \n (Press ENTER to continue)" \ - 12 45 \ - "$drupalsitedir" \ - 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 1 ]; then - exit 1 - fi - else - printf "Enter the name of the directory to which drupal website needs to be installed: " - read -r drupalsitedir + DRUPAL_HOME=$(whiptail --title "DRUPAL WEBSITE DETAILS" --inputbox \ + "\nEnter the name of the directory to which\n drupal website needs to be installed:\ + \n (Press ENTER to continue)" \ + 12 45 \ + "$DRUPAL_HOME" \ + 3>&1 1>&2 2>&3) + exitstatus=$? + if [ $exitstatus = 1 ]; then + exit 1 fi # Check if input is empty - if [ -n "$drupalsitedir" ]; then + if _is_variable_nonempty "$DRUPAL_HOME"; then + break + fi + + # Check if directory name is valid + if _is_dir_name_valid "$DRUPAL_HOME"; then break else - whiptail --msgbox " Please enter a value" 7 30 + whiptail --msgbox "Directory name is invalid. It should only contain alphabets, numbers, hyphens and underscores & should not start with a hyphen." 9 49 + fi + + # Check if directory exists + if [ -d "$WEB_ROOT"/"$DRUPAL_HOME" ]; then + whiptail --msgbox " Directory exists." 7 27 + else + break fi done - drupalsitedir=$(echo "$drupalsitedir" | tr ' ' '-') # Replaces 'spaces' with 'hyphens' - export drupalsitedir + DRUPAL_HOME=$(echo "$DRUPAL_HOME" | tr ' ' '-') # Replaces 'spaces' with 'hyphens' + export DRUPAL_HOME } export -f _input_drupal_dir diff --git a/functions/_input_drupal_mail.sh b/functions/_input_drupal_mail.sh index 8b5ff24..c3d4d28 100644 --- a/functions/_input_drupal_mail.sh +++ b/functions/_input_drupal_mail.sh @@ -2,36 +2,23 @@ function _input_drupal_mail { while true; do - if command -v whiptail > /dev/null; then - drupal_mail=$(whiptail --title "DRUPAL WEBSITE DETAILS" --inputbox \ - "\n""$wrong_email_msg""Enter a mail to be added to drupal website:\ - \n (Press ENTER to continue)" \ - 12 47 \ - "$drupal_mail" \ - 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 1 ]; then - exit 1 - fi - else - printf "\n""$wrong_email_msg""Enter a mail to be added to drupal website: " - read -r drupal_mail + drupal_mail=$(whiptail --title "DRUPAL WEBSITE DETAILS" --inputbox \ + "\nEnter a mail to be added to drupal website:\ + \n (Press ENTER to continue)" \ + 12 47 \ + "$drupal_mail" \ + 3>&1 1>&2 2>&3) + exitstatus=$? + if [ $exitstatus = 1 ]; then + exit 1 fi # Check if email is valid - _is_email_valid "$drupal_mail" - - # Check the return value - return_value=$? - - # Act upon return value - if [ $return_value = 1 ]; then - wrong_email_msg="Invalid Email Address\n" - _set_whiptail_colors_bg_red - continue - else - _set_whiptail_colors_bg_cyan + if _is_email_valid "$drupal_mail"; then break + else + whiptail --msgbox " Email address invalid" 7 28 + continue fi done export drupal_mail # Export drupal email to be used by child scripts diff --git a/functions/_input_drupal_pass.sh b/functions/_input_drupal_pass.sh index fec1430..15eb28f 100644 --- a/functions/_input_drupal_pass.sh +++ b/functions/_input_drupal_pass.sh @@ -2,27 +2,20 @@ function _input_drupal_pass { while true; do - if command -v whiptail > /dev/null; then - drupal_pass=$(whiptail --title "DRUPAL WEBSITE DETAILS" --passwordbox \ - "\nEnter a password for the new drupal user:\ - \n (Press ENTER to continue)" \ - 11 45 \ - "$drupal_pass" \ - 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 1 ]; then - exit 1 - fi - else - printf "\nEnter a password for the new drupal user: " - read -r drupal_pass + drupal_pass=$(whiptail --title "DRUPAL WEBSITE DETAILS" --passwordbox \ + "\nEnter a password for the new drupal user:\ + \n (Press ENTER to continue)" \ + 11 45 \ + "$drupal_pass" \ + 3>&1 1>&2 2>&3) + exitstatus=$? + if [ $exitstatus = 1 ]; then + exit 1 fi # Check if input is empty - if [ -n "$drupal_pass" ]; then + if _is_variable_nonempty "$drupal_pass"; then break - else - whiptail --msgbox " Please enter a value" 7 30 fi done diff --git a/functions/_input_drupal_site_name.sh b/functions/_input_drupal_site_name.sh index 7c5bf5b..be900e2 100644 --- a/functions/_input_drupal_site_name.sh +++ b/functions/_input_drupal_site_name.sh @@ -2,27 +2,20 @@ function _input_drupal_site_name { while true; do - if command -v whiptail > /dev/null; then - drupal_site_name=$(whiptail --title "DRUPAL WEBSITE DETAILS" --inputbox \ - "\nEnter a Name for your Drupal website:\n (Example: My Beautiful Website)\ - \n (Press ENTER to continue)" \ - 12 41 \ - "$drupal_site_name" \ - 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 1 ]; then - exit 1 - fi - else - printf "\nEnter a Name for your Drupal website(eg: My Beautiful Website) : " - read -r drupal_site_name + drupal_site_name=$(whiptail --title "DRUPAL WEBSITE DETAILS" --inputbox \ + "\nEnter a Name for your Drupal website:\n (Example: My Beautiful Website)\ + \n (Press ENTER to continue)" \ + 12 41 \ + "$drupal_site_name" \ + 3>&1 1>&2 2>&3) + exitstatus=$? + if [ $exitstatus = 1 ]; then + exit 1 fi # Check if input is empty - if [ -n "$drupal_site_name" ]; then + if _is_variable_nonempty "$drupal_site_name"; then break - else - whiptail --msgbox " Please enter a value" 7 30 fi done diff --git a/functions/_input_drupal_username.sh b/functions/_input_drupal_username.sh index df8d083..bc16ad8 100644 --- a/functions/_input_drupal_username.sh +++ b/functions/_input_drupal_username.sh @@ -2,31 +2,30 @@ function _input_drupal_username { while true; do - if command -v whiptail > /dev/null; then - drupal_user=$(whiptail --title "DRUPAL WEBSITE DETAILS" --inputbox \ - "\nEnter the username to be used for drupal:\ - \n (Press ENTER to continue)" \ - 11 45 \ - "$drupal_user" \ - 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 1 ]; then - exit 1 - fi - else - printf "\nEnter the username to be used for drupal: " - read -r drupal_user + drupal_user=$(whiptail --title "DRUPAL WEBSITE DETAILS" --inputbox \ + "\nEnter the username to be used for drupal:\ + \n (Press ENTER to continue)" \ + 11 45 \ + "$drupal_user" \ + 3>&1 1>&2 2>&3) + exitstatus=$? + if [ $exitstatus = 1 ]; then + exit 1 fi # Check if input is empty - if [ -n "$drupal_user" ]; then + if _is_variable_nonempty "$drupal_user"; then + break + fi + + # Check if directory name is valid + if _is_username_valid "$drupal_user"; then break else - whiptail --msgbox " Please enter a value" 7 30 + whiptail --msgbox "Username is invalid. It should only contain alphabets, numbers and underscores & must start with an alphabet." 9 47 fi done - drupal_user=$(echo "$drupal_user" | tr ' ' '-') # Repace 'spaces' with 'hyphens' export drupal_user # Export drupal username to be used by child scripts } diff --git a/functions/_input_memory_limit.sh b/functions/_input_memory_limit.sh index d9ec8e0..2cf4368 100644 --- a/functions/_input_memory_limit.sh +++ b/functions/_input_memory_limit.sh @@ -1,56 +1,28 @@ #!/usr/bin/env bash function _input_memory_limit { - if command -v whiptail > /dev/null; then - memory_limit_title="USER INPUT" - memory_limit_msg="" - total_memory="$(command free --mega | awk 'NR==2{print $2}')" - - while true; do - memorylimit=$(whiptail --title "$memory_limit_title" --inputbox \ - "\n$memory_limit_msg""How much memory to allocate to the website (in MB)?\ - \n (Press ENTER to continue)" \ - 12 46 \ - "$memorylimit" \ - 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 1 ]; then - exit 1 - fi - _set_whiptail_colors_bg_red # Change whiptail bg color to RED - if [[ ! "$memorylimit" =~ ^[0-9]+$ ]] &> /dev/null; then - memory_limit_title="ERROR" - memory_limit_msg="Only integer values are accepted.\n" - continue - elif [ "$memorylimit" -ge "$total_memory" ]; then - memory_limit_title="ERROR" - memory_limit_msg="Value is Larger than Total RAM ($total_memory""MB).\n" - continue - else - _set_whiptail_colors_default # Restore default colorscheme - break - fi - done - else - memory_limit_title="" - memory_limit_msg="" - total_memory="$(command free --mega | awk 'NR==2{print $2}')" - while true; do # This while loop enables checking if memory limit entered valid - printf "$memory_limit_title\n$memory_limit_msg""How much memory to allocate to the website? (in MB): " - read -r memorylimit - if [ "$memorylimit" -ne "$memorylimit" ] &> /dev/null; then - memory_limit_title='\nERROR!! ' - memory_limit_msg="Only integer values are accepted.\n" - continue - elif [ "$memorylimit" -ge "$total_memory" ]; then - memory_limit_title='\nERROR!! ' - memory_limit_msg="Value is Larger than Total RAM ($total_memory""MB).\n" - continue - else - break - fi - done - fi + total_memory="$(command free --mega | awk 'NR==2{print $2}')" + while true; do + memorylimit=$(whiptail --title "USER INPUT" --inputbox \ + "\nHow much memory to allocate to the website (in MB)?\ + \n (Press ENTER to continue)" \ + 12 46 \ + "$memorylimit" \ + 3>&1 1>&2 2>&3) + exitstatus=$? + if [ $exitstatus = 1 ]; then + exit 1 + fi + if [[ ! "$memorylimit" =~ ^[0-9]+$ ]] &> /dev/null; then + whiptail --msgbox "Only numbers are allowed. For example, if you want to specify 1GB, enter 1024." 8 43 + continue + elif [ "$memorylimit" -ge "$total_memory" ]; then + whiptail --msgbox "Value is Larger than Total RAM ($total_memory""MB). Specify a value less than $total_memory." 8 46 + continue + else + break + fi + done export memorylimit } diff --git a/functions/_install_whiptail.sh b/functions/_install_whiptail.sh index bbaf11b..f88bd46 100644 --- a/functions/_install_whiptail.sh +++ b/functions/_install_whiptail.sh @@ -12,6 +12,12 @@ function _install_whiptail { sudo yum install -y newt fi fi + + # Exit if whiptail can't be installed + if ! command -v whiptail > /dev/null; then + echo "Whiptail can't be installed. Exiting..." + exit 1 + fi } export -f _install_whiptail diff --git a/functions/_is_db_name_valid.sh b/functions/_is_db_name_valid.sh new file mode 100644 index 0000000..fd051c7 --- /dev/null +++ b/functions/_is_db_name_valid.sh @@ -0,0 +1,31 @@ +#!/usr/bin/env bash + +function _is_db_name_valid { + local db_name="$1" + + # Check if the length is between 1 and 63 characters + if [[ ${#db_name} -lt 1 || ${#db_name} -gt 63 ]]; then + echo "Invalid length for database name." + whiptail --msgbox "Invalid length for database name. It should be 1-63 characters long." 8 38 + return 1 + fi + + # Check if the first character is a letter or an underscore + if [[ ! "$db_name" =~ ^[a-zA-Z_] ]]; then + whiptail --msgbox "Database name must start with a\n letter or underscore." 8 35 + return 1 + fi + + # Check if subsequent characters are letters, underscores, or digits + if [[ ! "$db_name" =~ ^[a-zA-Z_][a-zA-Z0-9_]*$ ]]; then + whiptail --msgbox "Invalid characters in the database name.\n It should only contain letters, \n underscores and digits." 9 44 + return 1 + fi + + # If all checks pass, the name is valid + return 0 +} + +# Export the function to be used by child scripts +export -f _is_db_name_valid + diff --git a/functions/_is_dir_name_valid.sh b/functions/_is_dir_name_valid.sh new file mode 100644 index 0000000..8e1cf1c --- /dev/null +++ b/functions/_is_dir_name_valid.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash + +function _is_dir_name_valid { +local dir_name="$1" + # Check if the directory name contains only valid characters + if [[ ! "$dir_name" =~ ^[a-zA-Z0-9_-]+$ ]]; then + return 1 + fi + + # Check if the directory name doesn't start with a hyphen + if [[ "$dir_name" == -* ]]; then + return 1 + fi + + # If all checks pass, the directory name is valid + return 0 +} + +# Export the function to be used by child scripts +export -f _is_dir_name_valid + diff --git a/functions/_is_internet_available.sh b/functions/_is_internet_available.sh index 8578d43..49f8fe8 100644 --- a/functions/_is_internet_available.sh +++ b/functions/_is_internet_available.sh @@ -1,19 +1,9 @@ #!/usr/bin/env bash function _is_internet_available { - printf "Checking internet connectivity. Please wait.." + printf "Checking internet connectivity. Please wait ...\n" if ! curl -Is https://www.google.com | head -n 1 | grep -q '200' > /dev/null; then - if command -v whiptail > /dev/null; then - _set_whiptail_colors_bg_red # Change whiptail bg color to RED - whiptail --title "WARNING" --msgbox \ - "Unable to connect to internet. Check and make sure you are connected to internet before executing the script.\ - \n\n (Press ENTER to exit)" \ - 11 44 - _set_whiptail_colors_default # Restore default colorscheme - printf "\n" - else - printf "\nUnable to connect to internet. Check and make sure you are connected to internet before executing the script.\n" - fi + printf "\nUnable to connect to internet. Connect to internet before continuing.\n" exit 1 fi } diff --git a/functions/_is_os_supported.sh b/functions/_is_os_supported.sh index c56306b..0a16ff1 100644 --- a/functions/_is_os_supported.sh +++ b/functions/_is_os_supported.sh @@ -14,7 +14,6 @@ function _is_os_supported { fi # Give warning if OS is not supported - if command -v whiptail > /dev/null; then # Display messages using whiptail _set_whiptail_colors_bg_red # Change whiptail bg color to RED if ! command -v apt-get > /dev/null; then # Checking is OS is not Debian-based whiptail --title "WARNING" --yesno \ @@ -42,23 +41,6 @@ function _is_os_supported { fi fi _set_whiptail_colors_default # Restore default colorscheme - else # Display messages using command-line - if ! command -v apt-get > /dev/null; then # Checking is OS is not Debian-based - printf "This doesn't seem to be a Debian Linux system. Installation might not work properly. But you can continue with the installation if you want. Continue (yes/no): " - read -r continue_or_not - case $continue_or_not in - no|n|NO) - exit 1 ;; - esac - elif [ "$debian_version" -ne 11 ]; then # Checking if OS is debian but not version 11 - printf "Drupal 7 (and thereby Tripal 3) works best in Debian 11. This system is Debian %s. Installation might not work properly in this system. But you can continue with the installation if you want. Continue? (yes/no): " "$debian_version" - read -r continue_or_not - case $continue_or_not in - no|n|NO) - exit 1 ;; - esac - fi - fi } export -f _is_os_supported diff --git a/functions/_is_username_valid.sh b/functions/_is_username_valid.sh new file mode 100644 index 0000000..9726e99 --- /dev/null +++ b/functions/_is_username_valid.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash + +function _is_username_valid { +local username="$1" + # Check if the username contains only valid characters + if [[ ! "$username" =~ ^[a-zA-Z][a-zA-Z0-9_]+$ ]]; then + return 1 + fi + + # If all checks pass, the directory name is valid + return 0 +} + +# Export the function to be used by child scripts +export -f _is_username_valid + diff --git a/functions/_is_variable_nonempty.sh b/functions/_is_variable_nonempty.sh new file mode 100644 index 0000000..1ef656c --- /dev/null +++ b/functions/_is_variable_nonempty.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash + +function _is_variable_nonempty { + local variable_name="$1" + # Check if variable is empty + if [ -z "$variable_name" ]; then + whiptail --msgbox " Please enter a value" 7 30 + return 1 + else + return 0 + fi +} + +# Export the function to be used by child scripts +export -f _is_variable_nonempty + diff --git a/functions/_printtitle.sh b/functions/_printtitle.sh index b03b329..e0498ea 100644 --- a/functions/_printtitle.sh +++ b/functions/_printtitle.sh @@ -5,7 +5,7 @@ function _draw_the_line { printf "\n" - for i in $(seq $number_of_columns); do + for _ in $(seq "$number_of_columns"); do printf '-' done @@ -16,7 +16,7 @@ function _add_left_padding { printf "\n" - for i in $(seq $left_padding); do + for _ in $(seq "$left_padding"); do printf ' ' done @@ -28,15 +28,14 @@ function _printtitle { # Define Variables number_of_columns="$(tput cols)" title="$*" - length_of_title="$(expr length "$title")" - left_padding="$(((($number_of_columns - $length_of_title)) / 2))" - + length_of_title="${#title}" + left_padding=$(( (number_of_columns - length_of_title) / 2 )) _draw_the_line _add_left_padding - printf "$title" + printf "%s" "$title" _draw_the_line diff --git a/install.sh b/install.sh index ada8ca5..4cc624f 100755 --- a/install.sh +++ b/install.sh @@ -27,36 +27,32 @@ # Sabarinath Subramaniam [https://www.linkedin.com/in/sabarinath-subramaniam-a228014] # Create a log file and add time of execution to it -printf -- "\n-----------------------------------------\ -\nONECLICK WEBSITE DEPLOYER LOG\ -\n$(date)\ -\n-----------------------------------------\ -\n" >> ~/oneclick-website-deployer.log >> ~/oneclick-website-deployer-errors.log +printf -- "---------------------------------------\ +\n%s\ +\n---------------------------------------\ +\n" "$(date)" >> ~/oneclick-website-deployer.log >> ~/oneclick-website-deployer-errors.log # Redirect stdout to one log file and stderr to another exec > >(tee -a ~/oneclick-website-deployer.log) 2>&1 2> >(tee -a ~/oneclick-website-deployer-errors.log >&2) # Define web root folder -export DRUPAL_HOME=/var/www/html +export WEB_ROOT=/var/www/html # Change directory SCRIPT_DIR=$(dirname -- "$( readlink -f -- "$0"; )") && cd "$SCRIPT_DIR" || exit # Source functions -for fn in ./functions/*; do +for fn in ./functions/*.sh; do . "$fn" done -# Check environment -_is_os_supported # Check if the OS is on the supported list -_is_internet_available # Check if system is connected to internet - -# Prepare environment -_install_whiptail # Install whiptail program that poweres the script -_set_whiptail_colors_default # Apply default whiptail colors - -# Display the "About Us" page on the screen -./show-about-us-page.sh +# Check & prepare environment +_install_whiptail # Install whiptail program that poweres the script +_set_whiptail_colors_default # Apply default whiptail colors +_is_os_supported # Check if the OS is on the supported list +_is_internet_available # Check if system is connected to internet +./scripts/show-about-us-page.sh # Display the "About Us" page on the screen +./scripts/install-dependencies.sh # Install dependency programs like wget, jq, etc. # Prompt the user to enter inputs (database creds & memory limit) while true; do @@ -100,12 +96,12 @@ while true; do --defaultno \ --yes-button "Edit" \ --no-button "Continue" \ - "Drupal Website Directory: $DRUPAL_HOME/$drupalsitedir\ + "Drupal Website Directory: $WEB_ROOT/$DRUPAL_HOME\ \nDrupal Site Name: $drupal_site_name\ \nDrupal Username: $drupal_user\ \nDrupal Password: $hidden_drupal_pass\ \nDrupal Email: $drupal_mail\ - \nCountry: $drupal_country\ + \nCountry: $drupal_country_name\ \n\n You can edit the data if you want.\ \n (ARROW KEYS to move, ENTER to confirm)" \ 16 53 @@ -125,7 +121,6 @@ while true; do \n (ARROW KEYS to move, SPACE to select,\ \n TAB to move between sections, ENTER to confirm):" 14 64 4 \ "Webform" "[Drupal module used to create Forms]" OFF \ - "Tripal Daemon" "[To automatically execute Tripal Jobs]" OFF \ "Tripal Blast" "[Interface for using NCBI Blast+]" OFF \ "Tripal JBrowse" "[Integrate GMOD JBrowse with Tripal]" OFF \ 3>&1 1>&2 2>&3) @@ -134,7 +129,7 @@ while true; do exit 1 fi - if [[ ! -n $website_components ]]; then # Prompt user if they chose nothing + if [[ -z $website_components ]]; then # Prompt user if they chose nothing _set_whiptail_colors_bg_red # Set whiptail BG color to red indicating warning whiptail --title 'ATTENTION PLEASE !!' --yesno \ --defaultno \ @@ -158,16 +153,20 @@ done _set_whiptail_colors_default # Custom scripts -./scripts/install-web-server.sh -./scripts/install-psql.sh -./scripts/install-drupal.sh -./scripts/setup-cron.sh -./scripts/install-tripal.sh +./scripts/install-apache.sh # Web server used to run website +./scripts/install-php.sh # Major backend program for Drupal +./scripts/install-psql.sh # PostgreSQL - the database backend for Drupal +./scripts/install-drush.sh # Drush is the utility to manage Drupal from cli +./scripts/install-drupal.sh # Drupal powers the whole website +./scripts/setup-cron.sh # Replace drupal cron tasks with system cronjob +./scripts/install-tripal.sh # Install Tripal +./scripts/install-chado.sh # Install chado database +./scripts/prepare-chado.sh # Prepare website to work with chado +./scripts/install-tripal-daemon.sh # Tripal Daemon is used to automate execution of tripal jobs if [[ -n $website_components ]]; then # Install tripal extensions based on user choice [[ $website_components == *"Webform"* ]] && ./scripts/install-webform.sh - [[ $website_components == *"Tripal Daemon"* ]] && ./scripts/install-tripal-daemon.sh [[ $website_components == *"Tripal Blast"* ]] && ./scripts/install-tripal-blast.sh && ./scripts/setup-sample-blast-db.sh - [[ $website_components == *"Tripal JBrowse"* ]] && ./scripts/install-tripal-jbrowse.sh + [[ $website_components == *"Tripal JBrowse"* ]] && ./scripts/install-jbrowse.sh && ./scripts/install-tripal-jbrowse.sh fi # Unset PGPASSWORD diff --git a/scripts/auto-system-reboot.sh b/scripts/auto-system-reboot.sh index 41e2400..3a30975 100755 --- a/scripts/auto-system-reboot.sh +++ b/scripts/auto-system-reboot.sh @@ -5,24 +5,15 @@ if type _printtitle &> /dev/null; then _printtitle "AUTOMATIC SYSTEM REBOOT" fi -if command -v whiptail > /dev/null; then - whiptail --title "INSTALLATION COMPLETE" --yesno \ - --no-button "Later" \ - "Reboot the system for site installation\n to fully take effect. Reboot now? \ - \n (ARROW KEYS to move, ENTER to confirm)" \ - 9 44 - exitstatus=$? - if [ $exitstatus = 0 ]; then - sudo reboot - else - printf "\nUser chose not to reboot.\n\n" - fi +whiptail --title "INSTALLATION COMPLETE" --yesno \ + --no-button "Later" \ + "Reboot the system for site installation\n to fully take effect. Reboot now? \ + \n (ARROW KEYS to move, ENTER to confirm)" \ + 9 44 +exitstatus=$? +if [ $exitstatus = 0 ]; then + sudo reboot else - printf "Installation Complete. Reboot the system for site installation to fully take effect. Reboot now? (yes/no): " - read -r choice_of_reboot - case $choice_of_reboot in - yes|y|YES) - sudo reboot ;; - esac + printf "\nUser chose not to reboot.\n\n" fi diff --git a/scripts/install-apache.sh b/scripts/install-apache.sh new file mode 100755 index 0000000..5b6f96d --- /dev/null +++ b/scripts/install-apache.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash + +# Display title of script +if type _printtitle &> /dev/null; then + _printtitle "INSTALLING - APACHE" +fi + +# Install apache +if command -v apt-get > /dev/null; then # Install for debian-based distros + sudo apt-get -y install apache2 +fi + +# Setup apache +cd /etc/apache2/mods-enabled || exit +sudo ln -s ../mods-available/rewrite.load # Enable Rewrite module for apache +sudo sed -i "\$i\n Options Indexes FollowSymLinks MultiViews\n AllowOverride All\n Order allow,deny\n allow from all\n" /etc/apache2/sites-available/000-default.conf # Set web root directory + +# Restart apache for the new configurations to take effect +sudo service apache2 restart + diff --git a/scripts/install-chado.sh b/scripts/install-chado.sh new file mode 100755 index 0000000..1da8151 --- /dev/null +++ b/scripts/install-chado.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash + +# Display title of script +if type _printtitle &> /dev/null; then + _printtitle "INSTALLING - CHADO" +fi + +# Install Tripal chado +drush php-eval "module_load_include('inc', 'tripal_chado', 'includes/tripal_chado.install'); tripal_chado_load_drush_submit('Install Chado v1.3');" --username="$drupal_user" --root="$WEB_ROOT"/"$DRUPAL_HOME" +drush trp-run-jobs --username="$drupal_user" --root="$WEB_ROOT"/"$DRUPAL_HOME" + diff --git a/scripts/install-dependencies.sh b/scripts/install-dependencies.sh new file mode 100755 index 0000000..7e084a5 --- /dev/null +++ b/scripts/install-dependencies.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash + +# Change directory +SCRIPT_DIR=$(dirname -- "$( readlink -f -- "$0"; )") && cd "$SCRIPT_DIR" || exit + +if command -v apt-get > /dev/null; then # Install for debian-based distros + sudo apt-get update + xargs -a "../components/dependencies.txt" sudo apt-get install -y +fi + diff --git a/scripts/install-drupal.sh b/scripts/install-drupal.sh index 3c71569..fb5985a 100755 --- a/scripts/install-drupal.sh +++ b/scripts/install-drupal.sh @@ -5,40 +5,32 @@ if type _printtitle &> /dev/null; then _printtitle "INSTALLING - DRUPAL" fi -# Install dependencies -wget https://github.com/drush-ops/drush/releases/download/8.4.12/drush.phar # Install Drush (command-line shell interface for Drupal) -chmod +x drush.phar -sudo mv drush.phar /usr/local/bin/drush -if command -v apt-get > /dev/null; then # Install other dependencies for debian-based distros - sudo apt-get install -y curl tar wget -fi - # Install Drupal -sudo chown -R "$USER" "$DRUPAL_HOME" -cd "$DRUPAL_HOME" || exit +sudo chown -R "$USER" "$WEB_ROOT" +cd "$WEB_ROOT" || exit mv index.html index.html.orig -drush dl drupal --drupal-project-rename="$drupalsitedir" +drush dl drupal --drupal-project-rename="$DRUPAL_HOME" # Setup Drupal -cd "$drupalsitedir" || exit +cd "$DRUPAL_HOME" || exit cp sites/default/default.settings.php sites/default/settings.php mkdir sites/default/files/ sudo chgrp -R www-data sites/default/files/ sudo chmod g+rw sites/default/files/ -drush site-install standard --db-url=pgsql://"$psqluser":"$PGPASSWORD"@localhost:5432/"$psqldb" --account-mail="$drupal_mail" --account-name="$drupal_user" --account-pass="$drupal_pass" --site-mail="$drupal_mail" --site-name="$drupal_site_name" install_configure_form.site_default_country="$drupal_country" -y +drush site-install standard --db-url=pgsql://"$psqluser":"$PGPASSWORD"@localhost:5432/"$psqldb" --account-mail="$drupal_mail" --account-name="$drupal_user" --account-pass="$drupal_pass" --site-mail="$drupal_mail" --site-name="$drupal_site_name" install_configure_form.site_default_country="$drupal_country_code" -y # Set temp-path for drupal to prevent issues in future -mkdir -p "$DRUPAL_HOME"/"$drupalsitedir"/sites/default/files/tmp/ -sudo chgrp www-data "$DRUPAL_HOME"/"$drupalsitedir"/sites/default/files/tmp/ -chmod g+w "$DRUPAL_HOME"/"$drupalsitedir"/sites/default/files/tmp/ -drush variable-set file_temporary_path "$DRUPAL_HOME"/"$drupalsitedir"/sites/default/files/tmp --root="$DRUPAL_HOME"/"$drupalsitedir" +mkdir -p "$WEB_ROOT"/"$DRUPAL_HOME"/sites/default/files/tmp/ +sudo chgrp www-data "$WEB_ROOT"/"$DRUPAL_HOME"/sites/default/files/tmp/ +chmod g+w "$WEB_ROOT"/"$DRUPAL_HOME"/sites/default/files/tmp/ +drush variable-set file_temporary_path "$WEB_ROOT"/"$DRUPAL_HOME"/sites/default/files/tmp --root="$WEB_ROOT"/"$DRUPAL_HOME" # Prompt user to login to Drupal whiptail --title "DRUPAL SETUP" --msgbox \ --ok-button "OK" \ --notags \ "Drupal is installed and setup.\ - \n\n1. Now you can go to http://localhost/""$drupalsitedir"" and test out your site by logging in with your drupal username and password.\ + \n\n1. Now you can go to http://localhost/""$DRUPAL_HOME"" and test out your site by logging in with your drupal username and password.\ \n2. Press ENTER to continue." 13 56 diff --git a/scripts/install-drush.sh b/scripts/install-drush.sh new file mode 100755 index 0000000..46dcdb0 --- /dev/null +++ b/scripts/install-drush.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash + +# Display title of script +if type _printtitle &> /dev/null; then + _printtitle "INSTALLING - DRUSH" +fi + +# Install drush +wget https://github.com/drush-ops/drush/releases/download/8.4.12/drush.phar +chmod +x drush.phar +sudo mv drush.phar /usr/local/bin/drush + diff --git a/scripts/install-jbrowse.sh b/scripts/install-jbrowse.sh new file mode 100755 index 0000000..7c67ca2 --- /dev/null +++ b/scripts/install-jbrowse.sh @@ -0,0 +1,35 @@ +#!/usr/bin/env bash + +# Display title of script +if type _printtitle &> /dev/null; then + _printtitle "INSTALLING - JBROWSE" +fi + +# Install dependencies +if command -v apt-get > /dev/null; then # Install for debian-based distros + sudo apt-get -y install build-essential curl unzip wget zlib1g-dev +fi + +# Prepare environment +cd "$WEB_ROOT"/"$DRUPAL_HOME" || exit +[ -d ./tools ] || mkdir tools/ +mkdir -p sites/default/files/jbrowse/data/ +sudo chgrp -R www-data sites/default/files/jbrowse/ +sudo chmod -R g+w sites/default/files/jbrowse + +# Install jbrowse +curl -L -O https://github.com/GMOD/jbrowse/releases/download/1.16.11-release/JBrowse-1.16.11.zip +unzip -q JBrowse-1.16.11.zip +rm JBrowse-1.16.11.zip +mv JBrowse-1.16.11 tools/jbrowse +cd tools/jbrowse/ || exit +./setup.sh + +# User intervention +whiptail --title "JBROWSE EXAMPLE DATA (VOLVOX)" --msgbox \ + --ok-button "OK" \ + --notags \ + "To see JBrowse example data, go to http://localhost/""$DRUPAL_HOME""/tools/jbrowse/index.html?data=sample_data/json/volvox\ + \nPress ENTER to continue." \ + 9 86 + diff --git a/scripts/install-php.sh b/scripts/install-php.sh new file mode 100755 index 0000000..f12b4d6 --- /dev/null +++ b/scripts/install-php.sh @@ -0,0 +1,23 @@ +#!/usr/bin/env bash + +# Display title of script +if type _printtitle &> /dev/null; then + _printtitle "INSTALLING - PHP" +fi + +# Install php +if command -v apt-get > /dev/null; then # Install for debian-based distros + php_version=$(apt-cache show php | grep version | awk '{print $4}' | awk -F ')' '{print $1}') # Store php version into a variable + sudo apt-get -y install libapache2-mod-php php phppgadmin php-apcu php-cli php-curl php-dev php-gd php-pgsql php-uploadprogress php-xml php"$php_version"-mbstring php"$php_version"-zip +fi + +# Set max RAM a PHP script can consume +sudo sed -i "/memory_limit/ c\memory_limit = $memorylimit\M" /etc/php/"$php_version"/apache2/php.ini + +# Fix for "The PHP error_log at is not writable!" +sudo touch /var/log/php-errors.log +sudo sed -i "/error_log\ =\ php/ c\error_log\ =\ /var/log/php-errors.log" /etc/php/"$php_version"/cli/php.ini + +# Restart apache for the new configurations to take effect +sudo service apache2 restart + diff --git a/scripts/install-psql.sh b/scripts/install-psql.sh index be1f572..0a7a1b1 100755 --- a/scripts/install-psql.sh +++ b/scripts/install-psql.sh @@ -5,17 +5,20 @@ if type _printtitle &> /dev/null; then _printtitle "INSTALLING - POSTGRESQL DATABASE" fi -# Install dependencies +# Install postgresql if command -v apt-get > /dev/null; then sudo apt-get install -y postgresql fi -# Setup postgreSQL -sudo -u postgres createuser "$psqluser" # Create a user -sudo -u postgres createdb "$psqldb" # Create a database -sudo -u postgres psql -c "alter user \"$psqluser\" with encrypted password '$PGPASSWORD';" # Set new password to the user -sudo -u postgres psql -c "grant all privileges on database \"$psqldb\" to \"$psqluser\" ;" # Set ownership of database to the user +# Create a postgresql user +sudo -u postgres createuser "$psqluser" -# Create pg_trgm extension that is a dependency of Drupal -psql -U "$psqluser" -d "$psqldb" -h localhost -c "CREATE EXTENSION pg_trgm;" +# Create database +sudo -u postgres createdb "$psqldb" + +# Set new password to newly created user +sudo -u postgres psql -c "alter user \"$psqluser\" with encrypted password '$PGPASSWORD';" + +# Set ownership of database to newly created user +sudo -u postgres psql -c "grant all privileges on database \"$psqldb\" to \"$psqluser\" ;" diff --git a/scripts/install-tripal-blast.sh b/scripts/install-tripal-blast.sh index e55c0ba..3848b10 100755 --- a/scripts/install-tripal-blast.sh +++ b/scripts/install-tripal-blast.sh @@ -5,22 +5,13 @@ if type _printtitle &> /dev/null; then _printtitle "INSTALLING - TRIPAL BLAST" fi -# Install dependencies -if command -v apt-get > /dev/null; then - sudo apt-get install -y git unzip wget # Install some necessary programs -fi - # Change to drupal directory -cd "$DRUPAL_HOME"/"$drupalsitedir"/ || exit +cd "$WEB_ROOT"/"$DRUPAL_HOME"/ || exit # Install NCBI Blast+ -mkdir -p tools/blast -wget --no-remove-listing ftp.ncbi.nlm.nih.gov/blast/executables/LATEST -wget https://ftp.ncbi.nlm.nih.gov/blast/executables/LATEST/"$(grep x64-linux.tar.gz LATEST | awk 'NR==1{print $2}' | awk -F '>' '{print $2}' | awk -F '<' '{print $1}')" -tar zxvpf ncbi-blast-*+-x64-linux.tar.gz -cp -r ncbi-blast-*+/bin tools/blast/ -rm -rf ncbi-blast-*+/ ncbi-blast-*+-x64-linux.tar.gz -rm LATEST +if command -v apt-get > /dev/null; then # Install for debian-based distros + sudo apt-get install -y ncbi-blast+ +fi # Install & enable libraries module (dependency of tripal_blast) drush pm-download -y libraries @@ -36,7 +27,7 @@ chmod g+w sites/default/files/tripal/tripal_blast drush pm-enable blast_ui -y # Set blast+ bin folder in tripal_blast ui -drush variable-set blast_path "$DRUPAL_HOME"/"$drupalsitedir"/tools/blast/bin/ --root="$DRUPAL_HOME"/"$drupalsitedir" +drush variable-set blast_path "$(dirname $(which blastn))/" --root="$WEB_ROOT"/"$DRUPAL_HOME" # Restart tripal_daemon to fix an error that happens # if we start a blast run without rebooting system diff --git a/scripts/install-tripal-daemon.sh b/scripts/install-tripal-daemon.sh index d59beeb..db6a51e 100755 --- a/scripts/install-tripal-daemon.sh +++ b/scripts/install-tripal-daemon.sh @@ -6,7 +6,7 @@ if type _printtitle &> /dev/null; then fi # Change into drupal directory -cd "$DRUPAL_HOME"/"$drupalsitedir"/ || exit +cd "$WEB_ROOT"/"$DRUPAL_HOME"/ || exit # Install dependencies drush pm-download libraries -y @@ -30,5 +30,5 @@ sed -i "/is_array/ c\ if\ (\!is_array(\$error)\ ||\ \!isset(\$error['type'])) drush trpjob-daemon start # Set daemon to autostart during boot -echo "@reboot $USER /usr/local/bin/drush trpjob-daemon start --root=$DRUPAL_HOME/$drupalsitedir" | sudo tee /etc/cron.d/tripal-daemon-autostart > /dev/null +echo "@reboot $USER /usr/local/bin/drush trpjob-daemon start --root=$WEB_ROOT/$DRUPAL_HOME" | sudo tee /etc/cron.d/tripal-daemon-autostart > /dev/null diff --git a/scripts/install-tripal-jbrowse.sh b/scripts/install-tripal-jbrowse.sh index eb2c9ba..0546ad4 100755 --- a/scripts/install-tripal-jbrowse.sh +++ b/scripts/install-tripal-jbrowse.sh @@ -5,41 +5,13 @@ if type _printtitle &> /dev/null; then _printtitle "INSTALLING - TRIPAL JBROWSE" fi -# Install dependencies -if command -v apt-get > /dev/null; then # Install for debian-based distros - sudo apt-get -y install build-essential curl unzip wget zlib1g-dev -fi - -# Prepare environment -cd "$DRUPAL_HOME"/"$drupalsitedir" || exit -[ -d ./tools ] || mkdir tools/ -mkdir -p sites/default/files/jbrowse/data/ -sudo chgrp -R www-data sites/default/files/jbrowse/ -sudo chmod -R g+w sites/default/files/jbrowse - -# Install jbrowse -curl -L -O https://github.com/GMOD/jbrowse/releases/download/1.16.11-release/JBrowse-1.16.11.zip -unzip -q JBrowse-1.16.11.zip -rm JBrowse-1.16.11.zip -mv JBrowse-1.16.11 tools/jbrowse -cd tools/jbrowse/ || exit -./setup.sh - # Install tripal_jbrowse wget https://github.com/tripal/tripal_jbrowse/archive/refs/tags/7.x-3.0.zip unzip -q 7.x-3.0.zip rm 7.x-3.0.zip -mv tripal_jbrowse-7.x-3.0 "$DRUPAL_HOME"/"$drupalsitedir"/sites/all/modules/tripal_jbrowse -drush pm-enable -y tripal_jbrowse_mgmt tripal_jbrowse_page +mv tripal_jbrowse-7.x-3.0 "$WEB_ROOT"/"$DRUPAL_HOME"/sites/all/modules/tripal_jbrowse +drush pm-enable -y tripal_jbrowse_mgmt tripal_jbrowse_page --root="$WEB_ROOT"/"$DRUPAL_HOME" # Setup tripal_jbrowse -drush variable-set tripal_jbrowse_mgmt_settings "{\"data_dir\":\"$DRUPAL_HOME/$drupalsitedir/sites/default/files/jbrowse/data\",\"data_path\":\"$drupalsitedir/sites/default/files/jbrowse/data\",\"bin_path\":\"$DRUPAL_HOME\/$drupalsitedir/tools/jbrowse/bin\",\"link\":\"tools/jbrowse\",\"menu_template\":[]}" --root="$DRUPAL_HOME"/"$drupalsitedir" - -# User intervention -whiptail --title "JBROWSE EXAMPLE DATA (VOLVOX)" --msgbox \ - --ok-button "OK" \ - --notags \ - "To see JBrowse example data, go to http://localhost/""$drupalsitedir""/tools/jbrowse/index.html?data=sample_data/json/volvox\ - \nPress ENTER to continue." \ - 9 86 +drush variable-set tripal_jbrowse_mgmt_settings "{\"data_dir\":\"$WEB_ROOT/$DRUPAL_HOME/sites/default/files/jbrowse/data\",\"data_path\":\"$DRUPAL_HOME/sites/default/files/jbrowse/data\",\"bin_path\":\"$WEB_ROOT\/$DRUPAL_HOME/tools/jbrowse/bin\",\"link\":\"tools/jbrowse\",\"menu_template\":[]}" --root="$WEB_ROOT"/"$DRUPAL_HOME" diff --git a/scripts/install-tripal.sh b/scripts/install-tripal.sh index 9581d85..cc86484 100755 --- a/scripts/install-tripal.sh +++ b/scripts/install-tripal.sh @@ -9,12 +9,9 @@ fi SCRIPT_DIR=$(dirname -- "$( readlink -f -- "$0"; )") # Change directory to drupal directory -cd "$DRUPAL_HOME"/"$drupalsitedir" || exit +cd "$WEB_ROOT"/"$DRUPAL_HOME" || exit # Install dependencies -if command -v apt-get > /dev/null; then - sudo apt-get install -y bind9-dnsutils -fi drush pm-download -y entity views ctools ds field_group field_group_table field_formatter_class field_formatter_settings ckeditor_lts jquery_update drush pm-enable -y entity views views_ui ctools ds field_group field_group_table field_formatter_class field_formatter_settings ckeditor jquery_update @@ -22,66 +19,9 @@ drush pm-enable -y entity views views_ui ctools ds field_group field_group_table drush pm-download tripal-7.x-3.10 -y drush pm-enable -y tripal tripal_chado tripal_ds tripal_ws -# Install Tripal chado -drush php-eval "module_load_include('inc', 'tripal_chado', 'includes/tripal_chado.install'); tripal_chado_load_drush_submit('Install Chado v1.3');" --username="$drupal_user" --root="$DRUPAL_HOME"/"$drupalsitedir" -drush trp-run-jobs --username="$drupal_user" --root="$DRUPAL_HOME"/"$drupalsitedir" - -# Checking if chado installation was successful -exitstatus=$? -if [ $exitstatus -eq 0 ]; then - printf "\nChado Installation Successful.\n\n" -else - printf "\nChado Installation Failed.\n\n" -fi - -# Save initial network configuration into a string -initial_network_config=$(dig +short myip.opendns.com @resolver1.opendns.com) - -# Prepare Tripal Chado -while true; do - goodtogo=true - _is_raw.githubusercontent.com_accessible - if [ "$goodtogo" = false ]; then - _set_whiptail_colors_bg_red # Change whiptail bg color to RED - # Ask the user if they want to try different network setup - whiptail --title "UNABLE TO PROCEED" --yesno \ - --yes-button "Retry" \ - --no-button "Continue" \ - "* Unable to connect to raw.githubusercontent.com.\ - \n* For preparing website with chado, this connection is necessary.\ - \n* You can 'Continue' if you want but it is advisable to change network configuration and 'Retry'.\ - \n (ARROW KEYS to move, ENTER to confirm)" \ - 12 59 - exitstatus=$? - if [ $exitstatus = 0 ]; then - continue - else - _set_whiptail_colors_default # Restore default colorscheme - break - fi - else - break - fi -done -drush trp-prepare-chado --user="$drupal_user" --root="$DRUPAL_HOME"/"$drupalsitedir" -drush trp-run-jobs --username="$drupal_user" --root="$DRUPAL_HOME"/"$drupalsitedir" -drush cache-clear all --root="$DRUPAL_HOME"/"$drupalsitedir" - -# Save current network configuration into a string -current_network_config=$(dig +short myip.opendns.com @resolver1.opendns.com) - -# If network change is detected, promt user if they want to change network back -if [ "$current_network_config" != "$initial_network_config" ]; then - whiptail --title "JUST A PAUSE" --msgbox \ - "* We've noticed that you've switched network before.\ - \n* If you wish to change it back, do that and press ENTER." \ - 9 61 - while ! ({ curl -Is https://www.google.com | head -n 1 | grep -q '200'; } &> /dev/null); do :; done -fi - # Fix for "Trying to access array offset on value of type null" error that gets displayed # when we refresh overlay menus (eg: localhost/drupal/bio_data/1#overlay-context=&overlay=admin/tripal) # source: https://www.drupal.org/project/field_formatter_settings/issues/3166628 -cd "$DRUPAL_HOME"/"$drupalsitedir"/sites/all/modules/field_formatter_settings || exit -patch -p1 < "$SCRIPT_DIR"/field_formatter_settings.patch +cd "$WEB_ROOT"/"$DRUPAL_HOME"/sites/all/modules/field_formatter_settings || exit +patch -p1 < "$SCRIPT_DIR"/../components/field_formatter_settings.patch diff --git a/scripts/install-web-server.sh b/scripts/install-web-server.sh deleted file mode 100755 index a6e7504..0000000 --- a/scripts/install-web-server.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/env bash - -# Display title of script -if type _printtitle &> /dev/null; then - _printtitle "INSTALLING - WEB SERVER" -fi - -# Install dependencies -if command -v apt-get > /dev/null; then # Install for debian-based distros - sudo apt-get -y install apache2 libapache2-mod-php # Install apache - php_version=$(apt-cache show php | grep version | awk '{print $4}' | awk -F ')' '{print $1}') # Store php version into a variable - sudo apt-get -y install php phppgadmin php-apcu php-cli php-curl php-dev php-gd php-pgsql php-uploadprogress php-xml php"$php_version"-mbstring php"$php_version"-zip # Install php -fi - -# Setup the system -cd /etc/apache2/mods-enabled || exit -sudo ln -s ../mods-available/rewrite.load # Enable Rewrite module for apache -sudo sed -i '$i\n Options Indexes FollowSymLinks MultiViews\n AllowOverride All\n Order allow,deny\n allow from all\n' /etc/apache2/sites-available/000-default.conf # Set web root directory -sudo sed -i "/memory_limit/ c\memory_limit = $memorylimit\M" /etc/php/"$php_version"/apache2/php.ini # Set max amount of RAM a PHP script can consume -sudo touch /var/log/php-errors.log # Fix for "The PHP error_log at is not writable!" -sudo sed -i "/error_log\ =\ php/ c\error_log\ =\ /var/log/php-errors.log" /etc/php/"$php_version"/cli/php.ini - -# Restart apache for the new configurations to take effect -sudo service apache2 restart - diff --git a/scripts/install-webform.sh b/scripts/install-webform.sh index 743ef63..22d8d20 100755 --- a/scripts/install-webform.sh +++ b/scripts/install-webform.sh @@ -6,7 +6,7 @@ if type _printtitle &> /dev/null; then fi # Change directory -cd "$DRUPAL_HOME"/"$drupalsitedir" || exit +cd "$WEB_ROOT"/"$DRUPAL_HOME" || exit # Install module drush pm-download -y webform diff --git a/scripts/prepare-chado.sh b/scripts/prepare-chado.sh new file mode 100755 index 0000000..fbd5305 --- /dev/null +++ b/scripts/prepare-chado.sh @@ -0,0 +1,51 @@ +#!/usr/bin/env bash + +# Display title of script +if type _printtitle &> /dev/null; then + _printtitle "PREPARING - CHADO" +fi + +# Save initial network configuration into a string +initial_network_config=$(dig +short myip.opendns.com @resolver1.opendns.com) + +# Prepare Tripal Chado +while true; do + goodtogo=true + _is_raw.githubusercontent.com_accessible + if [ "$goodtogo" = false ]; then + _set_whiptail_colors_bg_red # Change whiptail bg color to RED + # Ask the user if they want to try different network setup + whiptail --title "UNABLE TO PROCEED" --yesno \ + --yes-button "Retry" \ + --no-button "Continue" \ + "* Unable to connect to raw.githubusercontent.com.\ + \n* For preparing website with chado, this connection is necessary.\ + \n* You can 'Continue' if you want but it is advisable to change network configuration and 'Retry'.\ + \n (ARROW KEYS to move, ENTER to confirm)" \ + 12 59 + exitstatus=$? + if [ $exitstatus = 0 ]; then + continue + else + _set_whiptail_colors_default # Restore default colorscheme + break + fi + else + break + fi +done +drush trp-prepare-chado --user="$drupal_user" --root="$WEB_ROOT"/"$DRUPAL_HOME" +drush cache-clear all --root="$WEB_ROOT"/"$DRUPAL_HOME" + +# Save current network configuration into a string +current_network_config=$(dig +short myip.opendns.com @resolver1.opendns.com) + +# If network change is detected, promt user if they want to change network back +if [ "$current_network_config" != "$initial_network_config" ]; then + whiptail --title "JUST A PAUSE" --msgbox \ + "* We've noticed that you've switched network before.\ + \n* If you wish to change it back, do that and press ENTER." \ + 9 61 + while ! ({ curl -Is https://www.google.com | head -n 1 | grep -q '200'; } &> /dev/null); do :; done +fi + diff --git a/scripts/setup-cron.sh b/scripts/setup-cron.sh index 7f81f13..40560d3 100755 --- a/scripts/setup-cron.sh +++ b/scripts/setup-cron.sh @@ -5,17 +5,16 @@ if type _printtitle &> /dev/null; then _printtitle "SETTING UP - CRON" fi -# Set up system cronjob to do drupal tasks -echo "0,30 * * * * /usr/bin/wget -O - -q http://localhost/""$drupalsitedir""/cron.php?cron_key=""$drupal_cron_key" | sudo tee /etc/cron.d/drupal-cron-tasks > /dev/null - # Disable drupal cron to prevent website slowing down when users visit -drush vset cron_safe_threshold 0 --root="$DRUPAL_HOME"/"$drupalsitedir" +drush vset cron_safe_threshold 0 --root="$WEB_ROOT"/"$DRUPAL_HOME" # Store exit status to variable exitstatus=$? # Display result of operation if [ $exitstatus = 0 ]; then + # Set up system cronjob to do drupal tasks + echo "0,30 * * * * /usr/bin/wget -O - -q http://localhost/""$DRUPAL_HOME""/cron.php?cron_key=""$drupal_cron_key" | sudo tee /etc/cron.d/drupal-cron-tasks > /dev/null echo "Cron setup Successfull" else echo "Cron setup Unsuccessful" diff --git a/scripts/setup-sample-blast-db.sh b/scripts/setup-sample-blast-db.sh index dd41c9a..b485d18 100755 --- a/scripts/setup-sample-blast-db.sh +++ b/scripts/setup-sample-blast-db.sh @@ -5,33 +5,31 @@ if type _printtitle &> /dev/null; then _printtitle "SETTING UP - SAMPLE BLAST DATABASE" fi -# Store path to directory in which this script resides into a variable +# Store current directory into a variable SCRIPT_DIR=$(dirname -- "$( readlink -f -- "$0"; )") +# Change directory +cd "$WEB_ROOT"/"$DRUPAL_HOME" || exit + # Gathering test database -mkdir -p "$DRUPAL_HOME"/"$drupalsitedir"/tools/blast/db/16S_ribosomal_RNA -cd "$DRUPAL_HOME"/"$drupalsitedir"/tools/blast/db/16S_ribosomal_RNA || exit -echo "Downloading Sample Blat database from NCBI. Please be patient..." -"$DRUPAL_HOME"/"$drupalsitedir"/tools/blast/bin/update_blastdb.pl --passive --decompress 16S_ribosomal_RNA - -# Check if Sample data was downloaded -if [ ! -f "$DRUPAL_HOME/$drupalsitedir/tools/blast/db/16S_ribosomal_RNA/16S_ribosomal_RNA.ndb" ]; then - echo "\nSample data could not be downloaded. Hence aborting Blast Database setup." - sleep 3 - exit # Don't setup if Sample data was not downloaded -fi +mkdir -p tools/blast/db/16S_ribosomal_RNA +cp "$SCRIPT_DIR"/../components/blastdb/16S_ribosomal_RNA/* tools/blast/db/16S_ribosomal_RNA/ # Automatic blast db setup -drush php-script "$SCRIPT_DIR"/create-blastdb.php --root="$DRUPAL_HOME"/"$drupalsitedir" +drush php-script "$SCRIPT_DIR"/create-blastdb.php --root="$WEB_ROOT"/"$DRUPAL_HOME" + +# Store exit status in a variable exitstatus=$? # User Intervention if [ $exitstatus = 0 ]; then + printf "Sample Blast Database Setup successful\n" + sleep 2 whiptail --title "SAMPLE BLAST DB SETUP" --msgbox \ --ok-button "OK" \ --notags \ "Sample Blast Database is set.\ - \n\n1. Now you can go to http://localhost/""$drupalsitedir""/blast/nucleotide/nucleotide and test out blast by Entering a FASTA sequence (or uploading one) & Selecting the newly added database (16S_ribosomal_RNA) from dropdown under Nucleotide BLAST Databases & Clicking 'BLAST'\ + \n\n1. Now you can go to http://localhost/""$DRUPAL_HOME""/blast/nucleotide/nucleotide and test out blast by Entering a FASTA sequence (or uploading one) & Selecting the newly added database (16S_ribosomal_RNA) from dropdown under Nucleotide BLAST Databases & Clicking 'BLAST'\ \n2. Press ENTER to continue." 15 60 else printf "\n\nSorry! Sample Blast Database setup failed for some reason.\n" diff --git a/show-about-us-page.sh b/scripts/show-about-us-page.sh similarity index 94% rename from show-about-us-page.sh rename to scripts/show-about-us-page.sh index 941021c..c0aa400 100755 --- a/show-about-us-page.sh +++ b/scripts/show-about-us-page.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # Input file -input_file="./about-us.txt" +input_file="../components/about-us.txt" # Change directory SCRIPT_DIR=$(dirname -- "$( readlink -f -- "$0"; )") && cd "$SCRIPT_DIR" || exit