From d8a0f595e86f287b926995945313e21161b52ad9 Mon Sep 17 00:00:00 2001 From: xpamych Date: Sun, 2 Apr 2023 15:21:12 +0300 Subject: [PATCH] =?UTF-8?q?=D1=81=D0=BA=D1=80=D0=B8=D0=BF=D1=82=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hlna-git/lure.sh | 4 +++- hlna-git/postinstall.sh | 42 +++++++++++++++++++++++++++-------------- hlna-git/postremove.sh | 27 ++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 15 deletions(-) mode change 100755 => 100644 hlna-git/postinstall.sh create mode 100644 hlna-git/postremove.sh diff --git a/hlna-git/lure.sh b/hlna-git/lure.sh index b302d2d..7a1fbb4 100644 --- a/hlna-git/lure.sh +++ b/hlna-git/lure.sh @@ -1,4 +1,5 @@ -name='hlna-git' + + ['postremove']='postremove.sh'name='hlna-git' version='latest' release='1' desc='Этот инструмент позволяет управлять выделенным сервером ARK: Survival Evolved на Linux. Он предоставляет множество функций, чтобы получить полный список, ознакомьтесь с разделом использования. (находится в разарботке и может содержать ошибки)' @@ -22,6 +23,7 @@ version() { scripts=( ['postinstall']='postinstall.sh' + ['postremove']='postremove.sh' ) prepare() { diff --git a/hlna-git/postinstall.sh b/hlna-git/postinstall.sh old mode 100755 new mode 100644 index a233679..6d46d01 --- a/hlna-git/postinstall.sh +++ b/hlna-git/postinstall.sh @@ -1,14 +1,28 @@ -if test -f /home/$SUDO_USER/.zshrc; then -echo "zshrc" -echo 'alias hlna="hlna.py"'>>/home/$SUDO_USER/.zshrc -echo 'alias hlna-bot="hlna-bot.py"'>>/home/$SUDO_USER/.zshrc -fi -if test -f /home/$SUDO_USER/.config/fish/config.fish; then -echo 'alias hlna="hlna.py"'>>/home/$SUDO_USER/.config/fish/config.fish -echo 'alias hlna-bot="hlna-bot.py"'>>/home/$SUDO_USER/.config/fish/config.fish -fi -if test -f /home/$SUDO_USER/.bashrc; then -echo 'alias hlna="hlna.py"'>>/home/$SUDO_USER/.bashrc -echo 'alias hlna-bot="hlna-bot.py"'>>/home/$SUDO_USER/.bashrc -source /home/$SUDO_USER/.bashrc -fi \ No newline at end of file +line1_to_add='alias hlna="hlna.py"' +line2_to_add='alias hlna-bot="hlna-bot.py"' +file_paths=( "/home/$SUDO_USER/.zshrc" "/home/$SUDO_USER/.bashrc" "/home/$SUDO_USER/.config/fish/config.fish" ) + +for file_path in "${file_paths[@]}" +do + if [ -f "$file_path" ]; then + # Check if the lines are already in the file + grep -qF "$line1_to_add" "$file_path" + if [ $? -ne 0 ]; then + echo "$line1_to_add" >> "$file_path" + echo "Alias hlna добавлен в $file_path" + else + echo "Alias hlna уже есть в файле $file_path" + fi + + grep -qF "$line2_to_add" "$file_path" + if [ $? -ne 0 ]; then + echo "$line2_to_add" >> "$file_path" + echo "Alias hlna-bot добавлен в $file_path" + else + echo "Alias hlna-bot уже есть в файле $file_path" + fi + + else + echo "$file_path не существует" + fi +done \ No newline at end of file diff --git a/hlna-git/postremove.sh b/hlna-git/postremove.sh new file mode 100644 index 0000000..ea8a779 --- /dev/null +++ b/hlna-git/postremove.sh @@ -0,0 +1,27 @@ +line1_to_remove='alias hlna="hlna.py"' +line2_to_remove='alias hlna-bot="hlna-bot.py"' +file_paths=( "/home/$SUDO_USER/.zshrc" "/home/$SUDO_USER/.bashrc" "/home/$SUDO_USER/.config/fish/config.fish" ) + +for file_path in "${file_paths[@]}" +do + if [ -f "$file_path" ]; then + # Check if the line is in the file + grep -qF "$line1_to_remove" "$file_path" + if [ $? -eq 0 ]; then + sed -i "/$line1_to_remove/d" "$file_path" + echo "Alias hlna удалён из $file_path" + else + echo "Alias hlna нет в $file_path" + fi + + grep -qF "$line2_to_remove" "$file_path" + if [ $? -eq 0 ]; then + sed -i "/$line2_to_remove/d" "$file_path" + echo "Alias hlna-bot удалён из $file_path" + else + echo "Alias hlna-bot нет в $file_path" + fi + else + echo "$file_path не существует" + fi +done \ No newline at end of file