Bash Kernel Basics Notebook
Testing of the Bash kernel
- Hack 1 - Is there anything we use to verify tools we install?
- Hack 2 - Is there anything we could verify with Anaconda?
- Hack 3 - How would you update a repository?
- This is a small script to show understanding of BASH
- Below is a script I developed to automate deployment
echo "List of all files in the root folder ... "
cd vscode/Fastpages
ls
echo ""
echo "List of all files in the repository including all hidden files:"
cd vscode/Fastpages
ls -a
echo "Checking versions and existence of python and java ... "
python3 --version
python2 --version
java --version
javac --version
echo "Running checks with Anaconda ... "
conda --version
echo ""
conda list python
cd ~/vscode/Fastpages
git pull
echo ""
echo "This script will create a file in the _pages directory
and will put all files inside including hidden files."
cd ~
echo ""
cd vscode/Fastpages/_pages
ls
touch 06_bash.md
cd ~
ls -al > vscode/Fastpages/_pages/06_bash.md
echo ""
echo "vscode/Fastpages/_pages/06_bash.md"
nl vscode/Fastpages/_pages/06_bash.md
sudo apt update; sudo apt upgrade
sudo apt install default-jre
java --version
sudo apt install default-jdk
javac --version
sudo apt update
sudo apt upgrade
sudo apt install maven
mvn --version
# This segment of code clones the repository and goes into that directory after done cloning
cd ~
git clone https://github.com/guapbeast/Spring.git
cd ~/Spring
# Runs the maven wrapper package
./mvnw package
# This assigns the result of the previous command to RESULT
# Then runs an if/else statement
# Saying that if the previous commands result comes back as exit code 0
# Then to proceed with changing the directory
# If it does not work, then execute the following commands
RESULT=$?
if [[ $RESULT -eq 0 ]]
then
cd ~/Spring
else
sudo apt install -y dos2unix
dos2unix ./mvnw
chmod +x ./mvnw
fi
# ">" overrides whatever is already in the file and writes
# What is in the "echo"
echo '
# syntax=docker/dockerfile:1
FROM openjdk:16-alpine3.13
WORKDIR /app
RUN apk update && apk upgrade && \
apk add --no-cache git maven
RUN git clone https://github.com/guapbeast/Spring.git /app
RUN ./mvnw package
CMD ["java", "-jar", "target/spring-0.0.1-SNAPSHOT.jar"]
# EXPOSE port that is defined in spring_portfolio.git application.properties
EXPOSE 8085' > Dockerfile
# ">" overrides whatever is already in the file and writes
# What is in the "echo"
echo '
version: "3"
services:
web:
image: java_springv1
build: .
ports:
- "8085:8085"
volumes:
- persistent_volume:/app/volumes
volumes:
persistent_volume:
driver: local
driver_opts:
o: bind
type: none
device: /home/ubuntu/Spring/volumes' > docker-compose.yml
# Installs docker and docker-compose
sudo apt install docker-compose -y
sudo docker-compose up -d
sudo apt install nginx
cd /etc/nginx/sites-available
sudo touch Spring
# ">" overrides whatever is already in the file and writes
# What is in the "echo"
echo '
server {
listen 80;
listen [::]:80;
server_name csarithwikh.live www.csarithwikh.live;
location / {
proxy_pass http://localhost:8085;
# Simple requests
if ($request_method ~* "(GET|POST)") {
add_header "Access-Control-Allow-Origin" *;
}
# Preflight requests
if ($request_method = OPTIONS ) {
add_header "Access-Control-Allow-Origin" *;
add_header "Access-Control-Allow-Methods" "GET, POST, OPTIONS, HEAD";
add_header "Access-Control-Allow-Headers" "Authorization, Origin, X-Requested-With, Content-Type, Accept";
return 200;
}
}
}' > Spring
sudo ln -s /etc/nginx/sites-available/Spring /etc/nginx/sites-enabled
sudo nginx -t
# This assigns the result of the previous command to RESULT
# Then runs an if/else statement
# Saying that if the previous commands result comes back as exit code 0
# Then to run the following code
# If it does not work, then execute the other commands
RESULT=$?
if [[ $RESULT -eq 0 ]]
then
sudo systemctl restart nginx
else
echo "Something went wrong!!!"
fi
# Transfers data to the address
curl http://localhost:8085;
sudo snap install core; sudo snap refresh core
sudo snap install --classic certbot
sudo ln -s /snap/bin/certbot /usr/bin/certbot
sudo certbot --nginx