Utils
This commit is contained in:
@@ -1,10 +1,16 @@
|
||||
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)
|
||||
|
||||
```
|
||||
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)
|
||||
```
|
||||
@@ -1,2 +1,19 @@
|
||||
# Utils
|
||||
This repository contains useful scriptis for server management. More usefull tools are coming soon...
|
||||
Examples to install
|
||||
|
||||
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"
|
||||
```
|
||||
+44
-29
@@ -1,26 +1,17 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Default variables
|
||||
name=""
|
||||
value=""
|
||||
type="export"
|
||||
rename=""
|
||||
delete_type="none"
|
||||
|
||||
#. <(wget -qO- https://raw.githubusercontent.com/letsnode/Utils/main/bashbuilder/colors.sh) --
|
||||
. <(wget -qO- http://astrader.net:3006/sem/Utils/raw/branch/main/bashbuilder/colors.sh)
|
||||
|
||||
function option_value() {
|
||||
echo "$1" | sed -e 's%^--[^=]*=%%g; s%^-[^=]*=%%g';
|
||||
}
|
||||
|
||||
function printf_n() {
|
||||
printf "$1\n" "${@:2}";
|
||||
}
|
||||
|
||||
# Options
|
||||
. <(wget -qO- http://astrader.net:3006/sem/Utils/raw/branch/main/bashbuilder/colors.sh) --
|
||||
option_value(){ echo "$1" | sed -e 's%^--[^=]*=%%g; s%^-[^=]*=%%g'; }
|
||||
while test $# -gt 0; do
|
||||
case "$1" in
|
||||
-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)
|
||||
echo
|
||||
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 -e "You can use either \"=\" or \" \" as an option and value ${C_LGn}delimiter${RES}"
|
||||
echo
|
||||
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 "Telegram comunity: https://t.me/letskynode"
|
||||
# echo -e "${C_LGn}Useful URLs${RES}:"
|
||||
# echo -e "https://github.com/SecorD0/utils/blob/main/miscellaneous/insert_variable.sh - script URL"
|
||||
# echo -e "https://t.me/letskynode — node Community"
|
||||
echo
|
||||
return 0 2>/dev/null; exit 0
|
||||
;;
|
||||
@@ -77,26 +68,51 @@ while test $# -gt 0; do
|
||||
esac
|
||||
done
|
||||
|
||||
# Functions
|
||||
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
|
||||
. $HOME/.bash_profile
|
||||
fi
|
||||
fi
|
||||
. $FILE_BASH
|
||||
if [ ! -n "$name" ]; then
|
||||
printf_n "${C_R}You didn't specify a name via${RES} -n ${C_R}option!${RES}"
|
||||
return 1 2>/dev/null; exit 1
|
||||
fi
|
||||
if [ "$delete_type" != "none" ]; 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
|
||||
sed -i "/ ${name}=/d" $HOME/.bash_profile
|
||||
sed -i "/ ${name}=/d" $FILE_BASH
|
||||
fi
|
||||
unset "$name"
|
||||
unalias "$name" 2>/dev/null
|
||||
else
|
||||
if [ -n "$rename" ]; then
|
||||
sed -i "s%${rename}%${name}%" $HOME/.bash_profile
|
||||
sed -i "s%${rename}%${name}%" $FILE_BASH
|
||||
unset "$rename"
|
||||
unalias "$rename" 2>/dev/null
|
||||
if [ ! -n "$value" ]; then
|
||||
. $FILE_BASH
|
||||
return 0 2>/dev/null; exit 0
|
||||
fi
|
||||
fi
|
||||
@@ -104,16 +120,15 @@ else
|
||||
printf "${C_LGn}Enter the value:${RES} "
|
||||
read -r value
|
||||
fi
|
||||
if ! cat $HOME/.bash_profile | grep -q " ${name}="; then
|
||||
echo "${type} ${name}=\"${value}\"" >> $HOME/.bash_profile
|
||||
elif ! cat $HOME/.bash_profile | grep -qF "${name}=\"${value}\""; then
|
||||
sed -i "s%^.*${name}*=.*%${type} ${name}=\"${value}\"%" $HOME/.bash_profile
|
||||
if ! cat $FILE_BASH | grep -q " ${name}="; then
|
||||
echo "${type} ${name}=\"${value}\"" >> $FILE_BASH
|
||||
elif ! cat $FILE_BASH | grep -qF "${name}=\"${value}\""; then
|
||||
sed -i "s%^.*${name}*=.*%${type} ${name}=\"${value}\"%" $FILE_BASH
|
||||
fi
|
||||
variable=`cat $HOME/.bash_profile | grep -qF "${name}=\"${value}\""`
|
||||
variable=`cat $FILE_BASH | grep -qF "${name}=\"${value}\""`
|
||||
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
|
||||
|
||||
sed -i '/^$/d' $HOME/.bash_profile
|
||||
. $HOME/.bash_profile
|
||||
sed -i '/^$/d' $FILE_BASH
|
||||
. $FILE_BASH
|
||||
Reference in New Issue
Block a user