-3

Unix Bash Script

I have been assigned my colleague's task to write a bash script which would copy the contents from one Debian 10 server [Non Production] to another Debian 10 server [Production].

The request that has been shared is :

PART A

#!/bin/bash
#SYSTEM_VARIABLES
INSTALLATION_DIR=/var/www/kapp
GIT_DIR=
SSL_CERT=
SSL_KEY=
NGINX_CONF=/etc/nignx/sites-available/kapp.zimpa.com

In reference to the above, the variables being declared, please do let me know how I would get the following data from Debian 10 server [Non Production]

GIT_DIR=
SSL_CERT=
SSL_KEY=

PART B

installPHPComposer
installLaravel
cloneGitFirstTome
pullFromGit
checkInstallationDir
if [ -e $INSTALLATION_DIR ]; then

fi

case "$1" in
    first-install)
        installPHPComposer
        installPHPComposer
        installPHPComposer
        installPHPComposer
        ;;
     
    update_from_git)
        stop
        ;;
     
    status)
        status anacron
        ;;
    restart)
        stop
        start
        ;;
    condrestart)
        if test "x`pidof anacron`" != x; then
            stop
            start
        fi
        ;;
     
    *)
        echo $"Usage: $0 {first-install|update-from-git}"
        exit 1

In the above PART B, the installation directory has to be reviewed. Then, within a case construct, need to: 1) Install PHP Composer 2) Install Laravel 3) Clone the GIT 4) Create a Pull Request from GIT.

Puck
  • 2,080
  • 4
  • 19
  • 30
Bonku Roy
  • 1
  • 1
  • 1
    What is your question? Can you specify more clearly what do you need in the question title? – Davide Casiraghi Jul 07 '20 at 08:57
  • I require a shell script that would enable to install laravel , PHP composer, clone the GIT, create a GIT Pul Request. Additionally I have been directed that all these needs to be carried out in case construct. I hope I am able to clarify the doubts. – Bonku Roy Jul 07 '20 at 09:08
  • 1
    Then you should make some research and make some attempts. If you run into some specific issue along the way, come back, explain the specific issue in detail, show us what you've tried, the expected result and what currently happens. We're not here to just "plug in the holes" in your code for you. – M. Eriksson Jul 07 '20 at 09:09

1 Answers1

1

I will not provide the whole code to do all those things, you should try first but here are some hints you can use

You can check if php is installed

php -v > /dev/null 2>&1
PHP_IS_INSTALLED=$?
if [[ $PHP_IS_INSTALLED -ne 0 ]]; then
    echo "PHP is not installed"
else
    php -v 
fi

Then you can install php using these(there are other methods as well)

sudo add-apt-repository ppa:ondrej/php
sudo apt-get update

For Composer

composer -V > /dev/null 2>&1
COMPOSER_IS_INSTALLED=$?
if [[ $COMPOSER_IS_INSTALLED -ne 0 ]]; then
    echo 'Composer is not installed'
else
    echo 'Composer is installed' && composer -V 
fi

Then check if command line php is installed you will need that to install composer. If installed follow below steps to install composer.

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
echo ">>> Verfiying Composer setup data integrity "
HASH="$(wget -q -O - https://composer.github.io/installer.sig)"
php -r "if (hash_file('SHA384', 'composer-setup.php') === '$HASH') { echo 'Installer Verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
        
        
echo ">>> Installing Composer${NC}"
sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer
rm composer-setup.php
bhucho
  • 3,903
  • 3
  • 16
  • 34
  • Thanks for the hint. Let me try and get back to you. – Bonku Roy Jul 07 '20 at 10:21
  • I have the script. Now the issue is that when I run the script, it runs and then it throws an error grep: : No such file or directory. Please do let me know how do I share my script as I am unable to do so as I see no attachment option available. – Bonku Roy Jul 07 '20 at 16:28
  • try this answer https://stackoverflow.com/questions/6426363/how-can-i-have-grep-not-print-out-no-such-file-or-directory-errors – bhucho Jul 07 '20 at 18:29
  • Thanks but this does not work for me. I do have the code but unable to paste it here because of limited space. Do let me know if there is any way I can share my complete code here ... – Bonku Roy Jul 07 '20 at 19:20