55 lines
1.3 KiB
Bash
55 lines
1.3 KiB
Bash
|
|
#!/bin/bash
|
||
|
|
|
||
|
|
site() {
|
||
|
|
command="$1"
|
||
|
|
site="$2"
|
||
|
|
file="/etc/nginx/sites-available/$site"
|
||
|
|
link="/etc/nginx/sites-enabled/$site"
|
||
|
|
|
||
|
|
if [ -z "$site" ]; then
|
||
|
|
echo "Usage: site <edit/enable/disable> name" 2>&1
|
||
|
|
return 1
|
||
|
|
fi
|
||
|
|
|
||
|
|
case "$command" in
|
||
|
|
create) sudo touch "$file"; return;;
|
||
|
|
esac
|
||
|
|
|
||
|
|
if [ ! -e "$file" ]; then
|
||
|
|
echo "Site $site doesnt exist!" 2>&1
|
||
|
|
return 1
|
||
|
|
fi
|
||
|
|
|
||
|
|
case "$command" in
|
||
|
|
delete) sudo rm "$file" "$link";;
|
||
|
|
edit) sudoedit "$file";;
|
||
|
|
copy) sudo cp "$file" "/etc/nginx/sites-available/$3";;
|
||
|
|
enable)
|
||
|
|
if [ ! -e "$link" ]; then
|
||
|
|
sudo ln -s "../sites-available/$site" "$link"
|
||
|
|
fi;;
|
||
|
|
disable)
|
||
|
|
if [ -e "$link" ]; then
|
||
|
|
sudo rm "$link"
|
||
|
|
fi;;
|
||
|
|
*)
|
||
|
|
echo "Unknown command $command" 2>&1
|
||
|
|
return 1;;
|
||
|
|
esac
|
||
|
|
}
|
||
|
|
|
||
|
|
_site() {
|
||
|
|
if [[ "$COMP_CWORD" -eq 1 ]]; then
|
||
|
|
COMPREPLY=($(compgen -W "create edit delete copy enable disable" -- "${COMP_WORDS[1]}"))
|
||
|
|
elif [[ "$COMP_CWORD" -eq 2 ]]; then
|
||
|
|
case "${COMP_WORDS[1]}" in
|
||
|
|
edit|enable|delete|copy) dir=sites-available;;
|
||
|
|
disable) dir=sites-enabled;;
|
||
|
|
*) return;;
|
||
|
|
esac
|
||
|
|
COMPREPLY=($(cd "/etc/nginx/$dir/" && compgen -f "${COMP_WORDS[2]}"))
|
||
|
|
fi
|
||
|
|
}
|
||
|
|
|
||
|
|
complete -F _site site
|