Skip to content

Commit 577e02d

Browse files
committed
Update install script (#190)
1 parent 26b1c4e commit 577e02d

File tree

1 file changed

+36
-66
lines changed

1 file changed

+36
-66
lines changed

install.sh

+36-66
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,9 @@ show_usage() {
5757
printf "\n"
5858
printf "Options:\n"
5959
printf " --verbose Show detailed output\n"
60-
printf " -y, --yes Automatic yes to prompts (for uninstall)\n"
60+
printf " -y, --yes Automatic yes to prompts\n"
6161
printf " --help Show this help message\n"
6262
printf "\n"
63-
printf "Examples:\n"
64-
printf " $0 install Install AliasVault using remote images\n"
65-
printf " $0 install start Install AliasVault using remote images and start containers\n"
66-
printf " $0 install stop Stop containers using remote images\n"
67-
printf " $0 install restart Restart containers using remote images\n"
68-
printf " $0 build Build from source\n"
69-
printf " $0 build start Start using local images\n"
70-
printf " $0 build stop Stop containers using local build configuration\n"
71-
printf " $0 build restart Restart containers using local build configuration\n"
7263

7364
}
7465

@@ -210,21 +201,7 @@ main() {
210201
print_logo
211202
case $COMMAND in
212203
"build")
213-
if [ -z "$COMMAND_ARG" ]; then
214-
handle_build
215-
else
216-
case $COMMAND_ARG in
217-
"start")
218-
handle_start "build"
219-
;;
220-
"stop")
221-
handle_stop "build"
222-
;;
223-
"restart")
224-
handle_restart "build"
225-
;;
226-
esac
227-
fi
204+
handle_build
228205
;;
229206
"install")
230207
handle_install "$COMMAND_ARG"
@@ -235,6 +212,12 @@ main() {
235212
"reset-password")
236213
generate_admin_password
237214
if [ $? -eq 0 ]; then
215+
printf "${CYAN}> Restarting admin container...${NC}\n"
216+
if [ "$VERBOSE" = true ]; then
217+
$(get_docker_compose_command) up -d --force-recreate admin
218+
else
219+
$(get_docker_compose_command) up -d --force-recreate admin > /dev/null 2>&1
220+
fi
238221
print_password_reset_message
239222
fi
240223
;;
@@ -596,13 +579,14 @@ print_success_message() {
596579

597580
# Function to recreate (restart) Docker containers
598581
recreate_docker_containers() {
599-
printf "${CYAN}> Recreating Docker containers...${NC}\n"
582+
printf "${CYAN}> (Re)creating Docker containers...${NC}\n"
583+
600584
if [ "$VERBOSE" = true ]; then
601-
docker compose up -d --force-recreate
585+
$(get_docker_compose_command) up -d --force-recreate
602586
else
603-
docker compose up -d --force-recreate > /dev/null 2>&1
587+
$(get_docker_compose_command) up -d --force-recreate > /dev/null 2>&1
604588
fi
605-
printf "${GREEN}> Docker containers recreated.${NC}\n"
589+
printf "${GREEN}> Docker containers (re)created successfully.${NC}\n"
606590
}
607591

608592
# Function to print password reset success message
@@ -612,11 +596,6 @@ print_password_reset_message() {
612596
printf "\n"
613597
printf "${GREEN}The admin password has been successfully reset, see the output above.${NC}\n"
614598
printf "\n"
615-
printf "${YELLOW}Important: You must restart the admin container for the new password to take effect:${NC}\n"
616-
printf " docker compose restart admin\n"
617-
printf "\n"
618-
printf "After restarting, you can login to the admin panel using the new password.\n"
619-
printf "\n"
620599
printf "${MAGENTA}=========================================================${NC}\n"
621600
printf "\n"
622601
}
@@ -626,7 +605,7 @@ get_docker_compose_command() {
626605
local base_command="docker compose -f docker-compose.yml"
627606

628607
# Check if using build configuration
629-
if [ "$1" = "build" ]; then
608+
if grep -q "^DEPLOYMENT_MODE=build" "$ENV_FILE" 2>/dev/null; then
630609
base_command="$base_command -f docker-compose.build.yml"
631610
fi
632611

@@ -749,6 +728,8 @@ handle_install() {
749728
# Function to handle build
750729
handle_build() {
751730
printf "${YELLOW}+++ Building AliasVault from source +++${NC}\n"
731+
# Set deployment mode to build to ensure container lifecycle uses build configuration
732+
set_deployment_mode "build"
752733
printf "\n"
753734

754735
# Check for required build files
@@ -811,17 +792,9 @@ handle_build() {
811792
printf "\n${GREEN}> Docker Compose stack built successfully.${NC}\n"
812793

813794
printf "${CYAN}> Starting Docker Compose stack...${NC}\n"
814-
if [ "$VERBOSE" = true ]; then
815-
$(get_docker_compose_command "build") up -d --force-recreate || {
816-
printf "${RED}> Failed to start Docker Compose stack${NC}\n"
817-
exit 1
818-
}
819-
else
820-
$(get_docker_compose_command "build") up -d --force-recreate > /dev/null 2>&1 || {
821-
printf "${RED}> Failed to start Docker Compose stack${NC}\n"
822-
exit 1
823-
}
824-
fi
795+
796+
recreate_docker_containers
797+
825798
printf "${GREEN}> Docker Compose stack started successfully.${NC}\n"
826799

827800
# Only show success message if we made it here without errors
@@ -1227,42 +1200,26 @@ generate_self_signed_cert() {
12271200

12281201
# New functions to handle container lifecycle:
12291202
handle_start() {
1230-
local mode="$1"
12311203
printf "${CYAN}> Starting AliasVault containers...${NC}\n"
1232-
if [ "$mode" = "build" ]; then
1233-
$(get_docker_compose_command "build") up -d
1234-
else
1235-
$(get_docker_compose_command) up -d
1236-
fi
1204+
$(get_docker_compose_command) up -d
12371205
printf "${GREEN}> AliasVault containers started successfully.${NC}\n"
12381206
}
12391207

12401208
handle_stop() {
1241-
local mode="$1"
12421209
printf "${CYAN}> Stopping AliasVault containers...${NC}\n"
12431210
if ! docker compose ps --quiet 2>/dev/null | grep -q .; then
12441211
printf "${YELLOW}> No containers are currently running.${NC}\n"
12451212
exit 0
12461213
fi
12471214

1248-
if [ "$mode" = "build" ]; then
1249-
$(get_docker_compose_command "build") down
1250-
else
1251-
$(get_docker_compose_command) down
1252-
fi
1215+
$(get_docker_compose_command) down
12531216
printf "${GREEN}> AliasVault containers stopped successfully.${NC}\n"
12541217
}
12551218

12561219
handle_restart() {
1257-
local mode="$1"
12581220
printf "${CYAN}> Restarting AliasVault containers...${NC}\n"
1259-
if [ "$mode" = "build" ]; then
1260-
$(get_docker_compose_command "build") down
1261-
$(get_docker_compose_command "build") up -d
1262-
else
1263-
$(get_docker_compose_command) down
1264-
$(get_docker_compose_command) up -d
1265-
fi
1221+
$(get_docker_compose_command) down
1222+
$(get_docker_compose_command) up -d
12661223
printf "${GREEN}> AliasVault containers restarted successfully.${NC}\n"
12671224
}
12681225

@@ -1457,6 +1414,8 @@ handle_install_version() {
14571414
fi
14581415

14591416
printf "${YELLOW}+++ Installing AliasVault ${target_version} +++${NC}\n"
1417+
# Set deployment mode to install to ensure container lifecycle uses install configuration
1418+
set_deployment_mode "install"
14601419
printf "\n"
14611420

14621421
# Initialize workspace which makes sure all required directories and files exist
@@ -1465,6 +1424,7 @@ handle_install_version() {
14651424
# Update docker-compose files with correct version so we pull the correct images
14661425
handle_docker_compose "$target_version"
14671426

1427+
14681428
# Initialize environment
14691429
create_env_file || { printf "${RED}> Failed to create .env file${NC}\n"; exit 1; }
14701430
populate_hostname || { printf "${RED}> Failed to set hostname${NC}\n"; exit 1; }
@@ -1725,4 +1685,14 @@ handle_migrate_db() {
17251685
printf "${GREEN}> Check migration output above for details.${NC}\n"
17261686
}
17271687

1688+
# Function to set deployment mode in .env
1689+
set_deployment_mode() {
1690+
local mode=$1
1691+
if [ "$mode" != "build" ] && [ "$mode" != "install" ]; then
1692+
printf "${RED}Invalid deployment mode: $mode${NC}\n"
1693+
exit 1
1694+
fi
1695+
update_env_var "DEPLOYMENT_MODE" "$mode"
1696+
}
1697+
17281698
main "$@"

0 commit comments

Comments
 (0)