feat: script to add stuff to the bin directory

This commit is contained in:
Hazel 2024-04-18 12:25:13 +02:00
parent 01f0fc9672
commit 031a3dc1bc
1 changed files with 35 additions and 0 deletions

35
scripts/add-to-bin Executable file
View File

@ -0,0 +1,35 @@
#!/bin/bash
# this script links the script given as an argument to the /usr/bin directory, and makes it executable
# it also checks if the script is already in the bin directory
# check if the script is given as an argument
if [ -z "$1" ]; then
echo "Usage: $0 <script>"
exit 1
fi
# check if the script exists
if [ ! -f "$1" ]; then
echo "Error: $1 does not exist"
exit 1
fi
# check if the script is already in the bin directory
if [ -f "/usr/bin/$(basename $1)" ]; then
echo "Error: $(basename $1) is already in the bin directory"
exit 1
fi
# make the script executable
sudo chmod +x "$1"
# link the script to the bin directory, the origin has to be an absolute path
sudo ln -s "$(realpath $1)" /usr/bin/$(basename $1)
# check if the link was successful
if [ $? -eq 0 ]; then
echo "Success: $(basename $1) is now in the bin directory"
else
echo "Error: failed to link $(basename $1) to the bin directory"
fi