Skip to content

Commit

Permalink
✨ feat: added shell scripts #3
Browse files Browse the repository at this point in the history
  • Loading branch information
pnguyen215 committed Dec 17, 2023
1 parent e665baf commit 1ff7e78
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 29 deletions.
30 changes: 13 additions & 17 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,37 @@ echo "🚀 Installing wsdkit..."

# Specify the GitHub repository owner and name
owner="pnguyen215"
repository="wsdkit"
mark="$repository-master"
wsdkit_repository="wsdkit"
wsdkit_mark="$wsdkit_repository-master"

# Try fetching the latest release information using GitHub API
release_info=$(curl -s "https://api.github.com/repos/$owner/$repository/releases/latest")
wsdkit_release_url=$(curl -s "https://api.github.com/repos/$owner/$wsdkit_repository/releases/latest")

# Extract the download URL for the source code zip file
zip_url=$(echo "$release_info" | grep -o '"browser_download_url": ".*wsdkit.*.zip"' | cut -d'"' -f4)
wsdkit_zip_url=$(echo "$wsdkit_release_url" | grep -o '"browser_download_url": ".*wsdkit.*.zip"' | cut -d'"' -f4)

if [ -z "$zip_url" ]; then
if [ -z "$wsdkit_zip_url" ]; then
echo "🚨 Latest release not found. Downloading from the master branch."
zip_url="https://github.com/$owner/$repository/archive/master.zip"
wsdkit_zip_url="https://github.com/$owner/$wsdkit_repository/archive/master.zip"
fi

# Specify the installation directory
install_dir="$HOME/wsdkit"
wsdkit_wrk="$HOME/wsdkit"

# Download the repository as a zip file
curl -LJO "$zip_url"
curl -LJO "$wsdkit_zip_url"

# Extract the contents of the zip file directly into the install directory
unzip -o "$mark.zip" -d "$install_dir"
unzip -o "$wsdkit_mark.zip" -d "$wsdkit_wrk"

# Adjusted the directory structure to avoid nested wsdkit directory
mv "$install_dir/$mark"/* "$install_dir/"
mv "$wsdkit_wrk/$wsdkit_mark"/* "$wsdkit_wrk/"

# Remove the unnecessary nested wsdkit directory
rmdir "$install_dir/$mark"
rmdir "$wsdkit_wrk/$wsdkit_mark"

# Add command to .zshrc if not already present
line="source $install_dir/src/wsdkit.sh"
line="source $wsdkit_wrk/src/wsdkit.sh"
zshrc="$HOME/.zshrc"

if ! grep -q "$line" "$zshrc"; then
Expand All @@ -44,10 +44,6 @@ else
fi

# Clean up: remove the downloaded zip file
rm "$mark.zip"

# Adjust paths in wsdkit.sh for the moved files
# sed -i "" "s|source src/brew.sh|source $install_dir/src/brew.sh|" "$install_dir/src/wsdkit.sh"
# sed -i "" "s|source src/plugins.sh|source $install_dir/src/plugins.sh|" "$install_dir/src/wsdkit.sh"
rm "$wsdkit_mark.zip"

echo "🍺 wsdkit has been successfully installed. Please restart your terminal or run 'source ~/.zshrc' to apply changes."
Empty file removed src/lib.sh
Empty file.
29 changes: 17 additions & 12 deletions src/wsdkit.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
# Get the absolute path of the directory containing this script
# SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd)"

echo "DEBUG: Script directory is $SCRIPT_DIR"
function add_suffix_if_missing() {
local path="$1"
local suffix="$2"
if [[ "$path" != *"$suffix" ]]; then
path="$path/$suffix"
fi
echo "$path"
}
# Get the absolute path of wsdkit
wsdkit_bash_source="$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd)"
wsdkit_suffix="/wsdkit"
wsdkit_wrk=$(add_suffix_if_missing "$wsdkit_bash_source" "$wsdkit_suffix")
echo "🍺 DEBUG: wsdkit working on $wsdkit_wrk"

# Reload functions
# source "$SCRIPT_DIR/src/brew.sh"
# source "$SCRIPT_DIR/src/plugins.sh"
# source "$SCRIPT_DIR/src/git.sh"
. src/brew.sh
. src/git.sh
. src/plugins.sh
source "$wsdkit_wrk/src/brew.sh"
source "$wsdkit_wrk/src/plugins.sh"
source "$wsdkit_wrk/src/git.sh"

######################
#### Requirements ####
Expand All @@ -21,7 +26,7 @@ install_jq_if_needed

# WsdKit installations
function wsdkit() {
local json_file="assets/usage.json"
local json_file="$wsdkit_wrk/assets/usage.json"

if [ ! -f "$json_file" ]; then
echo "❌ Error JSON file 'usage.json' not found."
Expand Down

0 comments on commit 1ff7e78

Please sign in to comment.