Skip to content

Commit

Permalink
fix: zsh script (#65)
Browse files Browse the repository at this point in the history
* fix: zshScript

Signed-off-by: Ayush Sharma <[email protected]>

* removed comments

Signed-off-by: Ayush Sharma <[email protected]>

* fixed scripts

Signed-off-by: Ayush Sharma <[email protected]>

* removed sudo

Signed-off-by: Ayush Sharma <[email protected]>

---------

Signed-off-by: Ayush Sharma <[email protected]>
  • Loading branch information
ayush3160 authored Sep 26, 2024
1 parent 7ccfcf6 commit 322526e
Show file tree
Hide file tree
Showing 10 changed files with 127 additions and 125 deletions.
15 changes: 1 addition & 14 deletions scripts/bash/keploy_record_script.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/bin/bash -i

# folderpath="$2"
log_file_path="$1"

# Extract command from keploy.yml
Expand All @@ -11,9 +10,7 @@ if [[ ! -f "$keploy_config" ]]; then
fi

command=$(awk '/command:/ { $1=""; sub(/^ /, ""); print }' "$keploy_config")
# echo "Command in yml file: $command"

# Check if command is empty
if [[ -z "$command" ]]; then
echo "Command is not specified in keploy.yml."
exit 1
Expand All @@ -31,22 +28,14 @@ if [[ "$command" =~ .*"go".* ]]; then
go build -o application

elif [[ "$command" =~ .*"python3".* ]]; then
# echo "Python3 command found"
python3 -m venv venv
# echo "venv created"
source venv/bin/activate
# echo "venv activated"
pip install -r requirements.txt
# echo "requirements installed"

elif [[ "$command" =~ .*"python".* ]] ; then
# echo "Python command found"
python -m venv venv
# echo "venv created"
source venv/bin/activate
# echo "venv activated"
pip install -r requirements.txt
# echo "requirements installed"

elif [[ "$command" =~ .*"node".* ]]; then
npm install
Expand All @@ -58,7 +47,7 @@ fi
# Check if running on WSL
if grep -qEi "(Microsoft|WSL)" /proc/version &> /dev/null ; then
export PATH=$(echo "$PATH" | tr ' ' '\n' | grep -v " " | tr '\n' ':')
keploycmd="sudo -E keploy"
keploycmd="sudo -E env PATH=\"$PATH\" keploy"
else
keploycmd="sudo -E env PATH=\"$PATH\" keploy"
fi
Expand All @@ -80,9 +69,7 @@ sudo -E $keploycmd record > "$fifo" 2>&1

# Clean up: Wait for keploy command to finish
wait $!
touch ./log_file.txt


# Terminate the dummy process and the logging process
kill $dummy_pid
wait $cat_pid
Expand Down
27 changes: 2 additions & 25 deletions scripts/bash/keploy_test_script.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/bin/bash -i

# folderpath="$2"
log_file_path="$1"

# Create log file if it doesn't exist
Expand All @@ -12,57 +11,35 @@ chmod 666 "$log_file_path"

# Extract the command from keploy.yml
command=$(awk -F: '/command:/ {gsub(/^[ \t]+|[ \t]+$/, "", $2); print $2}' keploy.yml)
# echo "Command in yml file: $command"

# echo "Command in yml file: $command"
if [[ "$command" =~ .*"go".* ]]; then
# echo "Go is present."
go mod download
go build -o application

elif [[ "$command" =~ .*"python3".* ]]; then
# echo "Python 3 is present, Activating Virtual Environment 🐍"
python3 -m venv venv
source venv/bin/activate
# echo 'Installing requirements 📦'
pip install -r requirements.txt
# echo 'Test Mode Starting 🎉'

elif [[ "$command" =~ .*"python".* ]] ; then
# echo "Python is present, Activating Virtual Environment 🐍"
python -m venv venv
source venv/bin/activate
# echo 'Installing requirements 📦'
pip install -r requirements.txt
# echo 'Test Mode Starting 🎉'

elif [[ "$command" =~ .*"node".* ]]; then
# echo "Node is present."
npm install

elif [[ "$command" =~ .*"java".* ]] || [[ "$command" =~ .*"mvn".* ]]; then
# echo "Java is present."
mvn clean install

fi

# Check if running on WSL
if grep -qEi "(Microsoft|WSL)" /proc/version &> /dev/null ; then
# echo "Running on WSL"
# Temporarily modify PATH
export PATH=$(echo "$PATH" | tr ' ' '\n' | grep -v " " | tr '\n' ':')
keploycmd="sudo -E keploy"
keploycmd="sudo -E env PATH=\"$PATH\" keploy"
else
# echo "Not running on WSL"
# Original PATH handling
keploycmd="sudo -E env PATH=\"$PATH\" keploy"
fi

# echo "Keploy command: $keploycmd"

# cd "$folderpath"

# Execute the keploy command and append the output to the log file
sudo $keploycmd test | tee -a "$log_file_path"
touch ./log_file.txt

sudo $keploycmd test | tee -a "$log_file_path"
74 changes: 74 additions & 0 deletions scripts/zsh/keploy_record_script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#!/bin/zsh

log_file_path="$1"

# Extract command from keploy.yml
keploy_config="keploy.yml"
if [[ ! -f "$keploy_config" ]]; then
echo "keploy.yml file not found in the current directory."
exit 1
fi

command=$(awk '/command:/ { $1=""; sub(/^ /, ""); print }' "$keploy_config")

# Check if command is empty
if [[ -z "$command" ]]; then
echo "Command is not specified in keploy.yml."
exit 1
fi

# Create log file if it doesn't exist
touch "$log_file_path"
: > "$log_file_path" # Clear the log file

# Set permissions of the log file
chmod 666 "$log_file_path"

if [[ "$command" =~ .*"go".* ]]; then
go mod download
go build -o application

elif [[ "$command" =~ .*"python3".* ]]; then
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt

elif [[ "$command" =~ .*"python".* ]] ; then
python -m venv venv
source venv/bin/activate
pip install -r requirements.txt

elif [[ "$command" =~ .*"node".* ]]; then
npm install

elif [[ "$command" =~ .*"java".* ]] || [[ "$command" =~ .*"mvn".* ]]; then
mvn clean install
fi

# Create a named pipe
fifo=$(mktemp -u)
mkfifo "$fifo"

# Background process to read from the named pipe and write to the log file
cat "$fifo" | tee -a "$log_file_path" &
cat_pid=$!

# Dummy background process to keep the parent script running
(while true; do sleep 1; done) &
dummy_pid=$!

# Check if running on WSL
if grep -qEi "(Microsoft|WSL)" /proc/version &> /dev/null ; then
sudo -E env "PATH=$PATH" keploy record > "$fifo" 2>&1
else
keploycmd="sudo -E env PATH=\"$PATH\" keploy"
eval $keploycmd record > "$fifo" 2>&1
fi

# Clean up: Wait for keploy command to finish
wait $!

# Terminate the dummy process and the logging process
kill $dummy_pid
wait $cat_pid
rm "$fifo"
53 changes: 0 additions & 53 deletions scripts/zsh/keploy_record_script.zsh

This file was deleted.

43 changes: 43 additions & 0 deletions scripts/zsh/keploy_test_script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/bin/zsh

log_file_path="$1"

# Create log file if it doesn't exist
touch "$log_file_path"
: > "$log_file_path" # Clear the log file

# Set permissions of the log file
chmod 666 "$log_file_path"

# Extract the command from keploy.yml
command=$(awk -F: '/command:/ {gsub(/^[ \t]+|[ \t]+$/, "", $2); print $2}' keploy.yml)

if [[ "$command" =~ .*"go".* ]]; then
go mod download
go build -o application

elif [[ "$command" =~ .*"python3".* ]]; then
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt

elif [[ "$command" =~ .*"python".* ]] ; then
python -m venv venv
source venv/bin/activate
pip install -r requirements.txt

elif [[ "$command" =~ .*"node".* ]]; then
npm install

elif [[ "$command" =~ .*"java".* ]] || [[ "$command" =~ .*"mvn".* ]]; then
mvn clean install

fi

# Check if running on WSL
if grep -qEi "(Microsoft|WSL)" /proc/version &> /dev/null ; then
sudo -E env "PATH=$PATH" keploy test | tee -a "$log_file_path"
else
keploycmd="sudo -E env PATH=\"$PATH\" keploy"
eval $keploycmd test | tee -a "$log_file_path"
fi
26 changes: 0 additions & 26 deletions scripts/zsh/keploy_test_script.zsh

This file was deleted.

2 changes: 1 addition & 1 deletion src/OneClickInstall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default function executeKeployOneClickCommand(): void {
const checkKeployExistsCommand = `keploy`;

// The command to download and install Keploy
const installationCommand = `curl --silent -L https://keploy.io/install.sh -o /tmp/install.sh && chmod +x /tmp/install.sh && bash /tmp/install.sh -noRoot -platform bash`;
const installationCommand = `curl --silent -L https://keploy.io/install.sh -o /tmp/install.sh && chmod +x /tmp/install.sh && /tmp/install.sh -noRoot`;
exec(checkKeployExistsCommand, (error, stdout, stderr) => {
if (error) {
// Execute the installation command
Expand Down
4 changes: 2 additions & 2 deletions src/Record.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export async function startRecording( wslscriptPath: string, wsllogfilePath: str

console.log(`Current default shell: ${currentShell}`);
//uncomment the below line if you want to use the default shell (for zsh test)
// terminalPath = currentShell;
terminalPath = currentShell;
}
console.log(`Terminal path: ${terminalPath}`);
const terminal = vscode.window.createTerminal({
Expand All @@ -121,7 +121,7 @@ export async function startRecording( wslscriptPath: string, wsllogfilePath: str
if (currentShell.includes('zsh')) {
// Use a Zsh-specific script if needed
//replace bashScriptPath with zshScriptPath for zsh
recordCmd = `"${bashScriptPath}" "${logfilePath}" `;
recordCmd = `"${zshScriptPath}" "${logfilePath}" ;exit 0`;
} else {
// Default to Bash script
recordCmd = `"${bashScriptPath}" "${logfilePath}" ;exit 0`;
Expand Down
4 changes: 2 additions & 2 deletions src/SidebarProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ export class SidebarProvider implements vscode.WebviewViewProvider {
console.log('Start Recording button clicked');

const bashScript = vscode.Uri.joinPath(this._extensionUri, "scripts", "bash", "keploy_record_script.sh");
const zshScript = vscode.Uri.joinPath(this._extensionUri, "scripts", "zsh", "keploy_record_script.zsh");
const zshScript = vscode.Uri.joinPath(this._extensionUri, "scripts", "zsh", "keploy_record_script.sh");
const logfilePath = vscode.Uri.joinPath(this._extensionUri, "scripts", "logs", "record_mode.log");
let wslscriptPath = bashScript.fsPath;
let wsllogPath = logfilePath.fsPath;
Expand Down Expand Up @@ -222,7 +222,7 @@ export class SidebarProvider implements vscode.WebviewViewProvider {
try {
console.log('Start Testing button clicked');
const bashScript = vscode.Uri.joinPath(this._extensionUri, "scripts", "bash", "keploy_test_script.sh");
const zshScript = vscode.Uri.joinPath(this._extensionUri, "scripts", "zsh", "keploy_test_script.zsh");
const zshScript = vscode.Uri.joinPath(this._extensionUri, "scripts", "zsh", "keploy_test_script.sh");
const logfilePath = vscode.Uri.joinPath(this._extensionUri, "scripts", "logs", "test_mode.log");
let wslscriptPath = bashScript.fsPath;
let wsllogPath = logfilePath.fsPath;
Expand Down
4 changes: 2 additions & 2 deletions src/Test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ export async function startTesting(wslscriptPath: string, wsllogfilePath: string

console.log(`Current default shell: ${currentShell}`);
//uncomment the below line if you want to use the default shell (for zsh test)
// terminalPath = currentShell;
terminalPath = currentShell;
}
console.log(`Terminal path: ${terminalPath}`);
const terminal = vscode.window.createTerminal({
Expand All @@ -338,7 +338,7 @@ export async function startTesting(wslscriptPath: string, wsllogfilePath: string
// Use a Zsh-specific script if needed
console.log('Using Zsh script');
//replace bashScriptPath with zshScriptPath for zsh
testCmd = `"${bashScriptPath}" "${logfilePath}"; exit 0`;
testCmd = `"${zshScriptPath}" "${logfilePath}"; exit 0`;
} else {
// Default to Bash script
testCmd = `"${bashScriptPath}" "${logfilePath}" ; exit 0`;
Expand Down

0 comments on commit 322526e

Please sign in to comment.