mirror of
https://github.com/bytedream/scripts.git
synced 2025-05-09 20:25:12 +02:00
Moved pathify to globalize
This commit is contained in:
parent
7a5385812f
commit
6399cfedbd
@ -11,4 +11,4 @@ This repository contains some (linux) scripts I am using to simplify my daily wo
|
|||||||
- [Beautify java source code](/java-beautifier)
|
- [Beautify java source code](/java-beautifier)
|
||||||
|
|
||||||
|
|
||||||
If you want to use any of the (bash!) scripts globaly, see [pathify](/pathify)
|
If you want to use any of the scripts globally, execute [globalize.sh](globalize.sh)
|
||||||
|
76
globalize.sh
Normal file
76
globalize.sh
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
check_and_exit() {
|
||||||
|
if [ $? -eq 0 ]; then
|
||||||
|
echo $1
|
||||||
|
exit 0
|
||||||
|
else
|
||||||
|
echo $2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
validate_script() {
|
||||||
|
if [ ! -f "$1/$1.sh" ]; then
|
||||||
|
echo "'$1' cannot be globalized"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
main() {
|
||||||
|
while getopts "?h?l?r?" opt; do
|
||||||
|
case $opt in
|
||||||
|
h)
|
||||||
|
echo "Usage: $0 [-l|-r] <script name>"
|
||||||
|
echo " 'script name' must be the name of a sub-directory in this directory"
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
l)
|
||||||
|
link=true
|
||||||
|
;;
|
||||||
|
r)
|
||||||
|
remove=true
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
shift $((OPTIND -1))
|
||||||
|
|
||||||
|
if [ $# -ge 1 ]; then
|
||||||
|
if [ -d $1 ]; then
|
||||||
|
executablePath="/usr/bin/$1"
|
||||||
|
copyDir="/usr/share/$1"
|
||||||
|
|
||||||
|
if ([ -f $executablePath ] || [ -d $copyDir ]) || [ ! -z $remove ] ; then
|
||||||
|
if [ ! -z $remove ]; then
|
||||||
|
if [ -d $copyDir ]; then
|
||||||
|
rm -r $copyDir
|
||||||
|
fi
|
||||||
|
rm $executablePath
|
||||||
|
check_and_exit "Unglobalized '$1'" "Failed to unglobalize '$1'"
|
||||||
|
else
|
||||||
|
echo "The script is already globalized"
|
||||||
|
fi
|
||||||
|
elif [ ! -z $link ]; then
|
||||||
|
validate_script $1
|
||||||
|
ln -s $1.* $executablePath
|
||||||
|
chmod +x $executablePath
|
||||||
|
check_and_exit "Globalized '$1'" "Failed to globalize '$1'"
|
||||||
|
else
|
||||||
|
validate_script $1
|
||||||
|
cp -r $1 /usr/share
|
||||||
|
ln -s /usr/share/$1/$1.* $executablePath
|
||||||
|
chmod +x $executablePath
|
||||||
|
check_and_exit "Globalized '$1'" "Failed to globalize '$1'"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "This script '$1' does not exist"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "No script to globalize were given"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
main $@
|
@ -1,18 +0,0 @@
|
|||||||
## Pathify
|
|
||||||
|
|
||||||
A script to make other bash scripts in this repository global available on your computer
|
|
||||||
|
|
||||||
|
|
||||||
#### Usage
|
|
||||||
|
|
||||||
Make a script global
|
|
||||||
```
|
|
||||||
$ ./pathify.sh <script name>
|
|
||||||
```
|
|
||||||
|
|
||||||
Remove a script
|
|
||||||
```
|
|
||||||
$ ./pathify.sh -f <script name>
|
|
||||||
```
|
|
||||||
|
|
||||||
NOTE: The `script name` can only be the name of a folder in the repository root
|
|
@ -1,44 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
while getopts "?l?f?" opt; do
|
|
||||||
case $opt in
|
|
||||||
l)
|
|
||||||
link=true
|
|
||||||
;;
|
|
||||||
f)
|
|
||||||
force=true
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
shift $((OPTIND -1))
|
|
||||||
|
|
||||||
if [ $# -ge 1 ]; then
|
|
||||||
path="$(cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P)/../$1"
|
|
||||||
if [ -d $path ]; then
|
|
||||||
executablePath="/usr/bin/$1"
|
|
||||||
copyDir="/usr/share/$1"
|
|
||||||
|
|
||||||
if [ -f $executablePath ] || [ -d $copyDir ]; then
|
|
||||||
if [ ! -z $force ]; then
|
|
||||||
rm $executablePath
|
|
||||||
if [ -d $copyDir ]; then
|
|
||||||
rm -r $copyDir
|
|
||||||
fi
|
|
||||||
echo "Unpathified $1"
|
|
||||||
else
|
|
||||||
echo "The script is already installed"
|
|
||||||
fi
|
|
||||||
elif [ ! -z $link ]; then
|
|
||||||
ln -s $path/$1.* $executablePath
|
|
||||||
echo "Pathified $1"
|
|
||||||
else
|
|
||||||
cp -r $path /usr/share
|
|
||||||
ln -s /usr/share/$1/$1.* $executablePath
|
|
||||||
echo "Pathified $1"
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
echo "This script does not exist"
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
echo "No script to pathify were given"
|
|
||||||
fi
|
|
Loading…
x
Reference in New Issue
Block a user