Skip to content

Commit

Permalink
Merge pull request #7 from arian24b/master
Browse files Browse the repository at this point in the history
Add AlmaLinux in installer and fix install epel-release bug
  • Loading branch information
SaintShit authored Feb 29, 2024
2 parents a499012 + 8a7bbde commit 5746d4f
Showing 1 changed file with 44 additions and 44 deletions.
88 changes: 44 additions & 44 deletions marzban.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ COMPOSE_FILE="$APP_DIR/docker-compose.yml"
colorized_echo() {
local color=$1
local text=$2

case $color in
"red")
printf "\e[91m${text}\e[0m\n";;
Expand Down Expand Up @@ -61,10 +61,10 @@ detect_and_update_package_manager() {
if [[ "$OS" == "Ubuntu"* ]] || [[ "$OS" == "Debian"* ]]; then
PKG_MANAGER="apt-get"
$PKG_MANAGER update
elif [[ "$OS" == "CentOS"* ]]; then
elif [[ "$OS" == "CentOS"* ]] || [[ "$OS" == "AlmaLinux"* ]]; then
PKG_MANAGER="yum"
$PKG_MANAGER update -y
$PKG_MANAGER epel-release -y
$PKG_MANAGER install -y epel-release
elif [ "$OS" == "Fedora"* ]; then
PKG_MANAGER="dnf"
$PKG_MANAGER update
Expand Down Expand Up @@ -93,12 +93,12 @@ install_package () {
if [ -z $PKG_MANAGER ]; then
detect_and_update_package_manager
fi

PACKAGE=$1
colorized_echo blue "Installing $PACKAGE"
if [[ "$OS" == "Ubuntu"* ]] || [[ "$OS" == "Debian"* ]]; then
$PKG_MANAGER -y install "$PACKAGE"
elif [[ "$OS" == "CentOS"* ]]; then
elif [[ "$OS" == "CentOS"* ]] || [[ "$OS" == "AlmaLinux"* ]]; then
$PKG_MANAGER install -y "$PACKAGE"
elif [ "$OS" == "Fedora"* ]; then
$PKG_MANAGER install -y "$PACKAGE"
Expand Down Expand Up @@ -128,26 +128,26 @@ install_marzban_script() {
install_marzban() {
# Fetch releases
FILES_URL_PREFIX="https://raw.githubusercontent.com/Gozargah/Marzban/master"

mkdir -p "$DATA_DIR"
mkdir -p "$APP_DIR"

colorized_echo blue "Fetching compose file"
curl -sL "$FILES_URL_PREFIX/docker-compose.yml" -o "$APP_DIR/docker-compose.yml"
colorized_echo green "File saved in $APP_DIR/docker-compose.yml"

colorized_echo blue "Fetching .env file"
curl -sL "$FILES_URL_PREFIX/.env.example" -o "$APP_DIR/.env"
sed -i 's/^# \(XRAY_JSON = .*\)$/\1/' "$APP_DIR/.env"
sed -i 's/^# \(SQLALCHEMY_DATABASE_URL = .*\)$/\1/' "$APP_DIR/.env"
sed -i 's~\(XRAY_JSON = \).*~\1"/var/lib/marzban/xray_config.json"~' "$APP_DIR/.env"
sed -i 's~\(SQLALCHEMY_DATABASE_URL = \).*~\1"sqlite:////var/lib/marzban/db.sqlite3"~' "$APP_DIR/.env"
colorized_echo green "File saved in $APP_DIR/.env"

colorized_echo blue "Fetching xray config file"
curl -sL "$FILES_URL_PREFIX/xray_config.json" -o "$DATA_DIR/xray_config.json"
colorized_echo green "File saved in $DATA_DIR/xray_config.json"

colorized_echo green "Marzban's files downloaded successfully"
}

Expand All @@ -168,7 +168,7 @@ uninstall_marzban() {

uninstall_marzban_docker_images() {
images=$(docker images | grep marzban | awk '{print $3}')

if [ -n "$images" ]; then
colorized_echo yellow "Removing Docker images of Marzban"
for image in $images; do
Expand Down Expand Up @@ -270,21 +270,21 @@ uninstall_command() {
colorized_echo red "Marzban's not installed!"
exit 1
fi

read -p "Do you really want to uninstall Marzban? (y/n) "
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
colorized_echo red "Aborted"
exit 1
fi

detect_compose
if is_marzban_up; then
down_marzban
fi
uninstall_marzban_script
uninstall_marzban
uninstall_marzban_docker_images

read -p "Do you want to remove Marzban's data files too ($DATA_DIR)? (y/n) "
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
colorized_echo green "Marzban uninstalled successfully"
Expand All @@ -302,7 +302,7 @@ up_command() {
echo " -h, --help display this help message"
echo " -n, --no-logs do not follow logs after starting"
}

local no_logs=false
while [[ "$#" -gt 0 ]]; do
case "$1" in
Expand All @@ -321,41 +321,41 @@ up_command() {
esac
shift
done

# Check if marzban is installed
if ! is_marzban_installed; then
colorized_echo red "Marzban's not installed!"
exit 1
fi

detect_compose

if is_marzban_up; then
colorized_echo red "Marzban's already up"
exit 1
fi

up_marzban
if [ "$no_logs" = false ]; then
follow_marzban_logs
fi
}

down_command() {

# Check if marzban is installed
if ! is_marzban_installed; then
colorized_echo red "Marzban's not installed!"
exit 1
fi

detect_compose

if ! is_marzban_up; then
colorized_echo red "Marzban's already down"
exit 1
fi

down_marzban
}

Expand All @@ -367,7 +367,7 @@ restart_command() {
echo " -h, --help display this help message"
echo " -n, --no-logs do not follow logs after starting"
}

local no_logs=false
while [[ "$#" -gt 0 ]]; do
case "$1" in
Expand All @@ -386,15 +386,15 @@ restart_command() {
esac
shift
done

# Check if marzban is installed
if ! is_marzban_installed; then
colorized_echo red "Marzban's not installed!"
exit 1
fi

detect_compose

down_marzban
up_marzban
if [ "$no_logs" = false ]; then
Expand All @@ -403,25 +403,25 @@ restart_command() {
}

status_command() {

# Check if marzban is installed
if ! is_marzban_installed; then
echo -n "Status: "
colorized_echo red "Not Installed"
exit 1
fi

detect_compose

if ! is_marzban_up; then
echo -n "Status: "
colorized_echo blue "Down"
exit 1
fi

echo -n "Status: "
colorized_echo green "Up"

json=$($COMPOSE -f $COMPOSE_FILE ps -a --format=json)
services=$(echo "$json" | jq -r 'if type == "array" then .[] else . end | .Service')
states=$(echo "$json" | jq -r 'if type == "array" then .[] else . end | .State')
Expand All @@ -446,7 +446,7 @@ logs_command() {
echo " -h, --help display this help message"
echo " -n, --no-follow do not show follow logs"
}

local no_follow=false
while [[ "$#" -gt 0 ]]; do
case "$1" in
Expand All @@ -465,20 +465,20 @@ logs_command() {
esac
shift
done

# Check if marzban is installed
if ! is_marzban_installed; then
colorized_echo red "Marzban's not installed!"
exit 1
fi

detect_compose

if ! is_marzban_up; then
colorized_echo red "Marzban is not up."
exit 1
fi

if [ "$no_follow" = true ]; then
show_marzban_logs
else
Expand All @@ -492,14 +492,14 @@ cli_command() {
colorized_echo red "Marzban's not installed!"
exit 1
fi

detect_compose

if ! is_marzban_up; then
colorized_echo red "Marzban is not up."
exit 1
fi

marzban_cli "$@"
}

Expand All @@ -510,17 +510,17 @@ update_command() {
colorized_echo red "Marzban's not installed!"
exit 1
fi

detect_compose

update_marzban_script
colorized_echo blue "Pulling latest version"
update_marzban

colorized_echo blue "Restarting Marzban's services"
down_marzban
up_marzban

colorized_echo blue "Marzban updated successfully"
}

Expand Down

0 comments on commit 5746d4f

Please sign in to comment.