# Linux Shell

Contient les Scripts Shell et Bash pour linux.

# Archives

Contient les scripts d'activité de build.

# Bash - Build : InstallNextcloud.sh

<table id="bkmrk-status-%3A-%C2%A0termin%C3%A9%C2%A0-a" style="border-collapse:collapse;width:53.7037%;border-width:0px;height:121px;"><colgroup><col style="width:42.9899%;"></col><col style="width:57.0139%;"></col></colgroup><tbody><tr style="height:28.8px;"><td style="border-width:0px;height:28.8px;">**Status :**  
</td><td style="border-width:0px;height:28.8px;"><span style="background-color:rgb(191,237,210);color:rgb(22,145,121);"> Terminé </span>  
</td></tr><tr style="height:28.8px;"><td style="border-width:0px;height:28.8px;">**Auteur :**  
</td><td style="border-width:0px;height:28.8px;"><span style="background-color:rgb(236,202,250);color:rgb(132,63,161);"> Olivier </span>  
</td></tr><tr style="height:28.8px;"><td style="border-width:0px;height:28.8px;">**Dernière version :**  
</td><td style="border-width:0px;height:28.8px;"><span style="background-color:rgb(194,224,244);color:rgb(35,111,161);"> V 1.0 </span>  
</td></tr><tr style="height:34.6px;"><td style="border-width:0px;height:34.6px;">**Dernière modification :**  
</td><td style="border-width:0px;height:34.6px;"><span style="background-color:rgb(206,212,217);color:rgb(52,73,94);"> 05/03/2023 </span>  
</td></tr></tbody></table>

---

#### <span style="text-decoration:underline;">I. Fonctionnalités</span>

Peut être utilisé dans les modes suivants : *<span style="background-color:rgb(236,202,250);color:rgb(132,63,161);"> CLI </span>*

La commande "-help" est présente :<span style="color:rgb(22,145,121);"> </span><span style="color:rgb(22,145,121);background-color:rgb(191,237,210);"><span style="color:rgb(186,55,42);background-color:rgb(248,202,198);"> non </span></span>

---

#### <span style="text-decoration:underline;">II. Captures d'écran</span>

<span style="background-color:rgb(251,238,184);">n/a</span>

---

#### <span style="text-decoration:underline;">III. Script</span>

<details id="bkmrk-createtechnicalfolde"><summary>InstallNextcloud.sh</summary>

```shell
#!/bin/bash

#Take Arguments
NEXTCLOUD_DOWNLOAD_LINK="https://download.nextcloud.com/server/releases/latest.zip"
NEXTCLOUD_APP_NAME=""

#Upgrade systservicessem
apt update
apt upgrade -y

#disable interactive mode
export DEBIAN_FRONTEND=noninteractive

#Install prerequisites
apt install -y wget vim zip

#Install apache2
apt install -y apache2 php8.1 libapache2-mod-php8.1
#Install required php modules
apt install -y php8.1-common php8.1-curl php8.1-dom php8.1-gd php8.1-mbstring php8.1-xml php8.1-zip php8.1-mysql
#Install optionnal php modules
apt install -y php8.1-bz2 php8.1-intl php8.1-ldap php8.1-smbclient php8.1-imap php8.1-bcmath php8.1-gmp php8.1-apcu 

#Go into apache directory
cd /etc/apache2/sites-available

#Disable all sites
a2dissite *

#Create site Configuration file
touch /etc/apache2/sites-available/nextcloud-http.conf
cat << EOF >> /etc/apache2/sites-available/nextcloud-http.conf
<VirtualHost *:80>
  DocumentRoot /var/www/nextcloud/
  ServerName  $NEXTCLOUD_APP_NAME

  <Directory /var/www/nextcloud/>
    Require all granted
    AllowOverride All
    Options FollowSymLinks MultiViews

    <IfModule mod_dav.c>
      Dav off
    </IfModule>
  </Directory>
</VirtualHost>
EOF

#Enable nextcloud site
a2ensite nextcloud-http

#Enable necessary apache module
a2enmod rewrite env dir mime

#Create website directory
mkdir /var/www/nextcloud

#Go into apache directory
cd /var/www/

#Download nextcloud installer
wget $NEXTCLOUD_DOWNLOAD_LINK

#Unzip
unzip *.zip

#Remove zip file
rm *.zip

#set permissions
chown -R www-data:www-data /var/www/nextcloud/

#restart apache2 service
service apache2 restart
```

</details>---

#### <span style="text-decoration:underline;">IV. Changelog</span>

##### V 1.0

- Met à jour.
- Installe les prérequis.
- Installe le serveur web.
- Installe nextcloud.
- Adapte les configurations.
- Lance le serveur web.

# Bash - Build : InstallPHPMyAdmin.sh

<table id="bkmrk-status-%3A-%C2%A0termin%C3%A9%C2%A0-a" style="border-collapse:collapse;width:53.7037%;border-width:0px;height:121px;"><colgroup><col style="width:42.9899%;"></col><col style="width:57.0139%;"></col></colgroup><tbody><tr style="height:28.8px;"><td style="border-width:0px;height:28.8px;">**Status :**  
</td><td style="border-width:0px;height:28.8px;"><span style="background-color:rgb(191,237,210);color:rgb(22,145,121);"> Terminé </span>  
</td></tr><tr style="height:28.8px;"><td style="border-width:0px;height:28.8px;">**Auteur :**  
</td><td style="border-width:0px;height:28.8px;"><span style="background-color:rgb(236,202,250);color:rgb(132,63,161);"> Olivier </span>  
</td></tr><tr style="height:28.8px;"><td style="border-width:0px;height:28.8px;">**Dernière version :**  
</td><td style="border-width:0px;height:28.8px;"><span style="background-color:rgb(194,224,244);color:rgb(35,111,161);"> V 1.0 </span>  
</td></tr><tr style="height:34.6px;"><td style="border-width:0px;height:34.6px;">**Dernière modification :**  
</td><td style="border-width:0px;height:34.6px;"><span style="background-color:rgb(206,212,217);color:rgb(52,73,94);"> 03/03/2023 </span>  
</td></tr></tbody></table>

---

#### <span style="text-decoration:underline;">I. Fonctionnalités</span>

Peut être utilisé dans les modes suivants : *<span style="background-color:rgb(236,202,250);color:rgb(132,63,161);"> CLI </span>*

La commande "-help" est présente :<span style="color:rgb(22,145,121);"> </span><span style="color:rgb(22,145,121);background-color:rgb(191,237,210);"><span style="color:rgb(186,55,42);background-color:rgb(248,202,198);"> non </span></span>

---

#### <span style="text-decoration:underline;">II. Captures d'écran</span>

<span style="background-color:rgb(251,238,184);">n/a</span>

---

#### <span style="text-decoration:underline;">III. Script</span>

<details id="bkmrk-createtechnicalfolde"><summary>InstallPHPMyAdmin.sh</summary>

```bash
#!/bin/bash

#Take Arguments
PHPMYADMIN_DOWNLOAD_LINK="https://files.phpmyadmin.net/phpMyAdmin/5.2.0/phpMyAdmin-5.2.0-all-languages.zip"
BLOWFISH_SECRET=""
MYSQL_SERVER_ADDRESS="mysql"

#Upgrade system
apt update
apt upgrade -y

#Install Prerequisites
apt install -y vim wget zip

#disable interactive mode
export DEBIAN_FRONTEND=noninteractive

#Install apache+php
apt install -y apache2 php php-mysqli php-mbstring

#Clean install
apt autoclean

#Install PHP My Admin
cd /var/www/html
rm index.html
wget $PHPMYADMIN_DOWNLOAD_LINK
unzip phpMyAdmin-*
mv phpMyAdmin-*/* ./
rm -rf phpMyAdmin-*

#Configure PHPMyAdmin
cp config.sample.inc.php config.inc.php
sed -i "s|cfg\['blowfish_secret'\] = ''|cfg['blowfish_secret'] = '$BLOWFISH_SECRET'|" /var/www/html/config.inc.php
sed -i "s|'localhost'|'$MYSQL_SERVER_ADDRESS'|" /var/www/html/config.inc.php

#create TMP directory and set rights on it
mkdir tmp
chown www-data:www-data tmp/
chmod 700 tmp/

#Restart apache2 service
service apache2 restart
```

</details>---

#### <span style="text-decoration:underline;">IV. Changelog</span>

##### V 1.0

- Installe apache2 et les modules php.
- Installe phpMyAdmin.
- Adapte les configurations.

# Bash - Utiliser les couleurs dans les messages

Les couleurs peuvent s'utiliser grâce à la matrice de couleur suivante :

```bash
Black        0;30     Dark Gray     1;30
Red          0;31     Light Red     1;31
Green        0;32     Light Green   1;32
Brown/Orange 0;33     Yellow        1;33
Blue         0;34     Light Blue    1;34
Purple       0;35     Light Purple  1;35
Cyan         0;36     Light Cyan    1;36
Light Gray   0;37     White         1;37

```

---

Pour les utiliser dans les scripts, il faudra les déclarer en début de script.

Pour cela deux méthodes, soit déclarer les couleurs et les utiliser ensuite dans le script :

```bash
RED='\033[0;31m' #Red, for error
NC='\033[0m' # No Color

```

```bash
echo -e "${RED} error s{NC} - ceci est une erreur"
```

ou déclarer un message entier, couleurs comprises :

```bash
#Declare color code
ERROR='[\033[0;31mERROR\033[0m]' # is for error
SUCCESS='[\033[0;32mSUCCESS\033[0m]' # is for Success
WARNING='[\033[0;33mWARNING\033[0m]' # is for warning
INFORMATION='[\033[0;34mINFO\033[0m]' # is fo informations
```

```bash
echo -e "${ERROR} Ceci est une erreur."
```