Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import os
|
| 3 |
+
from subprocess import Popen, PIPE
|
| 4 |
+
import re
|
| 5 |
+
|
| 6 |
+
# Function to upload and save files
|
| 7 |
+
def save_uploadedfile(uploadedfile):
|
| 8 |
+
with open(os.path.join("uploads", uploadedfile.name), "wb") as f:
|
| 9 |
+
f.write(uploadedfile.getbuffer())
|
| 10 |
+
return uploadedfile.name
|
| 11 |
+
|
| 12 |
+
# Function to analyze shell script with shellcheck
|
| 13 |
+
def analyze_shell_script(script_path):
|
| 14 |
+
command = f'shellcheck {script_path}'
|
| 15 |
+
process = Popen(command, shell=True, stdout=PIPE, stderr=PIPE)
|
| 16 |
+
stdout, stderr = process.communicate()
|
| 17 |
+
return stdout.decode(), stderr.decode()
|
| 18 |
+
|
| 19 |
+
# Function to fix common shell script issues (simple example)
|
| 20 |
+
def fix_shell_script_errors(script_content):
|
| 21 |
+
# Example: Remove unused variables warning (SC2034)
|
| 22 |
+
fixed_content = re.sub(r'\b\w+=["\'].+["\']\s*# SC2034', '', script_content)
|
| 23 |
+
return fixed_content
|
| 24 |
+
|
| 25 |
+
# Streamlit app layout
|
| 26 |
+
st.title("Shell Script Investigation and Fixing App")
|
| 27 |
+
|
| 28 |
+
# Upload the file
|
| 29 |
+
uploaded_file = st.file_uploader("Upload your shell script", type=["sh"])
|
| 30 |
+
|
| 31 |
+
if uploaded_file is not None:
|
| 32 |
+
# Save uploaded file
|
| 33 |
+
file_name = save_uploadedfile(uploaded_file)
|
| 34 |
+
st.write(f"File '{file_name}' uploaded successfully!")
|
| 35 |
+
|
| 36 |
+
# Show the content of the uploaded file
|
| 37 |
+
st.subheader("Uploaded Shell Script")
|
| 38 |
+
script_content = uploaded_file.read().decode("utf-8")
|
| 39 |
+
st.code(script_content, language='bash')
|
| 40 |
+
|
| 41 |
+
# Provide button to run investigation
|
| 42 |
+
if st.button("Investigate"):
|
| 43 |
+
stdout, stderr = analyze_shell_script(os.path.join("uploads", file_name))
|
| 44 |
+
if stderr:
|
| 45 |
+
st.error(f"Error during analysis: {stderr}")
|
| 46 |
+
else:
|
| 47 |
+
st.subheader("Investigation Results")
|
| 48 |
+
st.text(stdout)
|
| 49 |
+
|
| 50 |
+
# Provide button to fix errors
|
| 51 |
+
if st.button("Fix Issues"):
|
| 52 |
+
fixed_content = fix_shell_script_errors(script_content)
|
| 53 |
+
st.subheader("Fixed Shell Script")
|
| 54 |
+
st.code(fixed_content, language='bash')
|
| 55 |
+
st.download_button("Download Fixed Script", data=fixed_content, file_name=f"fixed_{file_name}")
|