Skip to content

Commit

Permalink
fix(installation): create MyBash for scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
abolfazl8131 committed Dec 8, 2024
1 parent c7eb0a9 commit 26c3bd8
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 19 deletions.
15 changes: 15 additions & 0 deletions app/media/MyBash/bash.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!bin/bash

sudo apt-get update && sudo apt-get install -y gnupg software-properties-common

wget -O- https://apt.releases.hashicorp.com/gpg | \
gpg --dearmor | \
sudo tee /usr/share/keyrings/hashicorp-archive-keyring.gpg > /dev/null

echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] \
https://apt.releases.hashicorp.com $(lsb_release -cs) main" | \
sudo tee /etc/apt/sources.list.d/hashicorp.list

sudo apt update

sudo apt-get install terraform
6 changes: 3 additions & 3 deletions app/routes/terraform.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ async def IaC_bugfix_generation(request:IaCBugfixInput) -> Output:
@app.post("/api/IaC-install/")
async def IaC_install_generation(request:IaCInstallationInput) -> Output:
if os.environ.get("TEST"):
return Output(output='apt-get install xyz \n apt-get update (covert them to shell file output)')
selected_script = select_install(request)
return Output(output=selected_script)
return Output(output='nothing special')
select_install(request)
return Output(output="pk")

@app.post("/api/IaC-template/docker")
async def IaC_template_generation_docker(request:IaCTemplateGenerationDocker) -> Output:
Expand Down
44 changes: 28 additions & 16 deletions app/template_generators/terraform/Installation/main.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,43 @@
import os
import shutil


def create_MyBash_directory():

dir = 'app/media/MyBash'


if not os.path.exists(dir):
os.makedirs(dir)
os.path.join(dir, 'bash.sh')



def select_install(input):
create_MyBash_directory()

match input.os:


case "Ubuntu":
with open("app/media/Installation_base/Terraform/ubuntu.sh", 'r') as file:
file_content = file.read()

return file_content
source = 'app/media/Installation_base/Terraform/ubuntu.sh'
dest = 'app/media/MyBash/bash.sh'
shutil.copyfile(source, dest)

case "Fedora":
with open("app/media/Installation_base/Terraform/fedora.sh", 'r') as file:
file_content = file.read()

return file_content
source = 'app/media/Installation_base/Terraform/fedora.sh'
dest = 'app/media/MyBash/bash.sh'
shutil.copyfile(source, dest)

case "Centos":
with open("app/media/Installation_base/Terraform/centos.sh", 'r') as file:
file_content = file.read()

return file_content
source = 'app/media/Installation_base/Terraform/centos.sh'
dest = 'app/media/MyBash/bash.sh'
shutil.copyfile(source, dest)

case "Amazon_linux":
with open("app/media/Installation_base/Terraform/amazon_linux.sh", 'r') as file:
file_content = file.read()

return file_content
source = 'app/media/Installation_base/Terraform/amazon_linux.sh'
dest = 'app/media/MyBash/bash.sh'
shutil.copyfile(source, dest)
case _:
raise ValueError()

Expand Down

0 comments on commit 26c3bd8

Please sign in to comment.