Utils
This commit is contained in:
@@ -1,10 +1,16 @@
|
|||||||
Each script helps you to install compiler
|
Each script helps you to install compiler
|
||||||
|
|
||||||
Example to use docker:
|
Examples to install
|
||||||
|
|
||||||
|
docker:
|
||||||
|
```bash
|
||||||
. <(wget -qO- http://astrader.net:3006/sem/Utils/raw/branch/main/Installers/docker.sh)
|
. <(wget -qO- http://astrader.net:3006/sem/Utils/raw/branch/main/Installers/docker.sh)
|
||||||
|
```
|
||||||
go:
|
go:
|
||||||
|
```bash
|
||||||
. <(wget -qO- http://astrader.net:3006/sem/Utils/raw/branch/main/Installers/golang.sh)
|
. <(wget -qO- http://astrader.net:3006/sem/Utils/raw/branch/main/Installers/golang.sh)
|
||||||
|
```
|
||||||
rust:
|
rust:
|
||||||
|
```bash
|
||||||
. <(wget -qO- http://astrader.net:3006/sem/Utils/raw/branch/main/Installers/rust.sh)
|
. <(wget -qO- http://astrader.net:3006/sem/Utils/raw/branch/main/Installers/rust.sh)
|
||||||
|
```
|
||||||
@@ -1,2 +1,19 @@
|
|||||||
# Utils
|
Examples to install
|
||||||
This repository contains useful scriptis for server management. More usefull tools are coming soon...
|
|
||||||
|
docker:
|
||||||
|
```bash
|
||||||
|
. <(wget -qO- http://astrader.net:3006/sem/Utils/raw/branch/main/Installers/docker.sh)
|
||||||
|
```
|
||||||
|
go:
|
||||||
|
```bash
|
||||||
|
. <(wget -qO- http://astrader.net:3006/sem/Utils/raw/branch/main/Installers/golang.sh)
|
||||||
|
```
|
||||||
|
rust:
|
||||||
|
```bash
|
||||||
|
. <(wget -qO- http://astrader.net:3006/sem/Utils/raw/branch/main/Installers/rust.sh)
|
||||||
|
```
|
||||||
|
|
||||||
|
Example to use insert variable:
|
||||||
|
```bash
|
||||||
|
. <(wget -qO- http://astrader.net:3006/sem/Utils/raw/branch/main/miscellaneous/insert_variable.sh) -n USERNAME -v "YOUR_NAME"
|
||||||
|
```
|
||||||
+45
-30
@@ -1,26 +1,17 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
# Default variables
|
||||||
name=""
|
name=""
|
||||||
value=""
|
value=""
|
||||||
type="export"
|
type="export"
|
||||||
rename=""
|
rename=""
|
||||||
delete_type="none"
|
delete_type="none"
|
||||||
|
|
||||||
#. <(wget -qO- https://raw.githubusercontent.com/letsnode/Utils/main/bashbuilder/colors.sh) --
|
# Options
|
||||||
. <(wget -qO- http://astrader.net:3006/sem/Utils/raw/branch/main/bashbuilder/colors.sh)
|
. <(wget -qO- http://astrader.net:3006/sem/Utils/raw/branch/main/bashbuilder/colors.sh) --
|
||||||
|
option_value(){ echo "$1" | sed -e 's%^--[^=]*=%%g; s%^-[^=]*=%%g'; }
|
||||||
function option_value() {
|
|
||||||
echo "$1" | sed -e 's%^--[^=]*=%%g; s%^-[^=]*=%%g';
|
|
||||||
}
|
|
||||||
|
|
||||||
function printf_n() {
|
|
||||||
printf "$1\n" "${@:2}";
|
|
||||||
}
|
|
||||||
|
|
||||||
while test $# -gt 0; do
|
while test $# -gt 0; do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
-h|--help)
|
-h|--help)
|
||||||
#. <(wget -qO- https://raw.githubusercontent.com/letsnode/Utils/main/bashbuilder/logo.sh)
|
|
||||||
. <(wget -qO- http://astrader.net:3006/sem/Utils/raw/branch/main/bashbuilder/logo.sh)
|
. <(wget -qO- http://astrader.net:3006/sem/Utils/raw/branch/main/bashbuilder/logo.sh)
|
||||||
echo
|
echo
|
||||||
echo -e "${C_LGn}Functionality${RES}: the script inserts variable or alias to ${C_LGn}$HOME/.bash_profile${RES}"
|
echo -e "${C_LGn}Functionality${RES}: the script inserts variable or alias to ${C_LGn}$HOME/.bash_profile${RES}"
|
||||||
@@ -38,9 +29,9 @@ while test $# -gt 0; do
|
|||||||
echo
|
echo
|
||||||
echo -e "You can use either \"=\" or \" \" as an option and value ${C_LGn}delimiter${RES}"
|
echo -e "You can use either \"=\" or \" \" as an option and value ${C_LGn}delimiter${RES}"
|
||||||
echo
|
echo
|
||||||
echo -e "${C_LGn}Useful URLs${RES}:"
|
# echo -e "${C_LGn}Useful URLs${RES}:"
|
||||||
echo -e "Script URL: http://astrader.net:3006/sem/Utils/raw/branch/main/bashbuilder/addvar.sh"
|
# echo -e "https://github.com/SecorD0/utils/blob/main/miscellaneous/insert_variable.sh - script URL"
|
||||||
#echo -e "Telegram comunity: https://t.me/letskynode"
|
# echo -e "https://t.me/letskynode — node Community"
|
||||||
echo
|
echo
|
||||||
return 0 2>/dev/null; exit 0
|
return 0 2>/dev/null; exit 0
|
||||||
;;
|
;;
|
||||||
@@ -77,26 +68,51 @@ while test $# -gt 0; do
|
|||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
touch $HOME/.bash_profile
|
# Functions
|
||||||
. $HOME/.bash_profile
|
printf_n(){ printf "$1\n" "${@:2}"; }
|
||||||
|
|
||||||
|
# Actions
|
||||||
|
|
||||||
|
#touch $HOME/.bash_profile
|
||||||
|
FILE_BASH=$HOME/.bash_profile
|
||||||
|
if [ -f $FILE_BASH ];
|
||||||
|
then
|
||||||
|
echo -e "${C_LGn}File bash_profile is exist${RES}"
|
||||||
|
if [ -f $HOME/.profile ];
|
||||||
|
then
|
||||||
|
FILE_BASH=$HOME/.profile
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
if [ -f $HOME/.profile ];
|
||||||
|
then
|
||||||
|
echo -e "${C_LGn}Make necessary link to file bash_profile${RES}"
|
||||||
|
ln -s $HOME/.profile $HOME/.bash_profile
|
||||||
|
FILE_BASH=$HOME/.profile
|
||||||
|
else
|
||||||
|
echo "создаем файл bash_profle"
|
||||||
|
touch $HOME/.bash_profile
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
. $FILE_BASH
|
||||||
if [ ! -n "$name" ]; then
|
if [ ! -n "$name" ]; then
|
||||||
printf_n "${C_R}You didn't specify a name via${RES} -n ${C_R}option!${RES}"
|
printf_n "${C_R}You didn't specify a name via${RES} -n ${C_R}option!${RES}"
|
||||||
return 1 2>/dev/null; exit 1
|
return 1 2>/dev/null; exit 1
|
||||||
fi
|
fi
|
||||||
if [ "$delete_type" != "none" ]; then
|
if [ "$delete_type" != "none" ]; then
|
||||||
if [ "$delete_type" = "delete" ]; then
|
if [ "$delete_type" = "delete" ]; then
|
||||||
sed -i "0,/ ${name}=/{/ ${name}=/d;}" $HOME/.bash_profile
|
sed -i "0,/ ${name}=/{/ ${name}=/d;}" $FILE_BASH
|
||||||
elif [ "$delete_type" = "delete_all" ]; then
|
elif [ "$delete_type" = "delete_all" ]; then
|
||||||
sed -i "/ ${name}=/d" $HOME/.bash_profile
|
sed -i "/ ${name}=/d" $FILE_BASH
|
||||||
fi
|
fi
|
||||||
unset "$name"
|
unset "$name"
|
||||||
unalias "$name" 2>/dev/null
|
unalias "$name" 2>/dev/null
|
||||||
else
|
else
|
||||||
if [ -n "$rename" ]; then
|
if [ -n "$rename" ]; then
|
||||||
sed -i "s%${rename}%${name}%" $HOME/.bash_profile
|
sed -i "s%${rename}%${name}%" $FILE_BASH
|
||||||
unset "$rename"
|
unset "$rename"
|
||||||
unalias "$rename" 2>/dev/null
|
unalias "$rename" 2>/dev/null
|
||||||
if [ ! -n "$value" ]; then
|
if [ ! -n "$value" ]; then
|
||||||
|
. $FILE_BASH
|
||||||
return 0 2>/dev/null; exit 0
|
return 0 2>/dev/null; exit 0
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
@@ -104,16 +120,15 @@ else
|
|||||||
printf "${C_LGn}Enter the value:${RES} "
|
printf "${C_LGn}Enter the value:${RES} "
|
||||||
read -r value
|
read -r value
|
||||||
fi
|
fi
|
||||||
if ! cat $HOME/.bash_profile | grep -q " ${name}="; then
|
if ! cat $FILE_BASH | grep -q " ${name}="; then
|
||||||
echo "${type} ${name}=\"${value}\"" >> $HOME/.bash_profile
|
echo "${type} ${name}=\"${value}\"" >> $FILE_BASH
|
||||||
elif ! cat $HOME/.bash_profile | grep -qF "${name}=\"${value}\""; then
|
elif ! cat $FILE_BASH | grep -qF "${name}=\"${value}\""; then
|
||||||
sed -i "s%^.*${name}*=.*%${type} ${name}=\"${value}\"%" $HOME/.bash_profile
|
sed -i "s%^.*${name}*=.*%${type} ${name}=\"${value}\"%" $FILE_BASH
|
||||||
fi
|
fi
|
||||||
variable=`cat $HOME/.bash_profile | grep -qF "${name}=\"${value}\""`
|
variable=`cat $FILE_BASH | grep -qF "${name}=\"${value}\""`
|
||||||
if ! grep -q "${type}" <<< "$variable"; then
|
if ! grep -q "${type}" <<< "$variable"; then
|
||||||
sed -i "s%^.*${name}*=.*%${type} ${name}=\"${value}\"%" $HOME/.bash_profile
|
sed -i "s%^.*${name}*=.*%${type} ${name}=\"${value}\"%" $FILE_BASH
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
sed -i '/^$/d' $FILE_BASH
|
||||||
sed -i '/^$/d' $HOME/.bash_profile
|
. $FILE_BASH
|
||||||
. $HOME/.bash_profile
|
|
||||||
Reference in New Issue
Block a user