Create new script to run this python script from anywhere, and a setup script to add it to path.
This commit is contained in:
27
setup.sh
Executable file
27
setup.sh
Executable file
@@ -0,0 +1,27 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Create executable backup script
|
||||
chmod +x backup.py
|
||||
chmod +x backup
|
||||
|
||||
# Create a symlink in /usr/local/bin to make it accessible from anywhere
|
||||
if [ -w /usr/local/bin ]; then
|
||||
# If we have write permission to /usr/local/bin
|
||||
ln -sf "$(realpath backup)" /usr/local/bin/backup
|
||||
echo "Created symlink in /usr/local/bin/backup"
|
||||
else
|
||||
# If we don't have permission, suggest using sudo
|
||||
echo "To install system-wide, run:"
|
||||
echo "sudo ln -sf $(realpath backup) /usr/local/bin/backup"
|
||||
|
||||
# Offer to add to user's path as an alternative
|
||||
read -p "Would you like to add it to your PATH in ~/.bashrc instead? (y/n) " choice
|
||||
if [[ $choice == "y" || $choice == "Y" ]]; then
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
echo "export PATH=\"\$PATH:$SCRIPT_DIR\"" >> ~/.bashrc
|
||||
echo "Added to PATH in ~/.bashrc"
|
||||
echo "Run 'source ~/.bashrc' to apply changes"
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "Setup complete. You can now run 'backup' from anywhere."
|
||||
Reference in New Issue
Block a user