Skip to content

Commit fd58950

Browse files
committed
Install mkpasswd dependency when missing
1 parent ae59432 commit fd58950

4 files changed

Lines changed: 81 additions & 12 deletions

File tree

build-dist.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ GREEN='\033[0;32m'
77
BLUE='\033[0;34m'
88
NC='\033[0m'
99

10-
VERSION="1.3.2"
10+
VERSION="1.3.3"
1111
DIST_DIR="dist"
1212
ARCHIVE_NAME="shipnode-payload.tar.gz"
1313
INSTALLER_NAME="shipnode-installer.sh"
@@ -90,7 +90,7 @@ YELLOW='\033[1;33m'
9090
BLUE='\033[0;34m'
9191
NC='\033[0m'
9292
93-
VERSION="1.3.2"
93+
VERSION="1.3.3"
9494
INSTALL_DIR="$HOME/.shipnode"
9595
9696
# Parse flags

lib/commands/mkpasswd.sh

Lines changed: 77 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,82 @@
1-
cmd_mkpasswd() {
2-
# Check if mkpasswd is available
3-
if ! command -v mkpasswd &> /dev/null; then
4-
error "mkpasswd not found. Install it with: sudo apt-get install whois"
1+
install_mkpasswd() {
2+
if command -v mkpasswd &> /dev/null; then
3+
return 0
4+
fi
5+
6+
info "mkpasswd not found. Installing password hash helper..."
7+
8+
local os_info pkg_manager
9+
IFS='|' read -r os_info pkg_manager <<< "$(detect_os)"
10+
11+
if [ -z "$pkg_manager" ]; then
12+
warn "Could not detect package manager."
13+
return 1
14+
fi
15+
16+
local sudo_cmd="sudo"
17+
if [ "$(id -u 2>/dev/null || echo 1)" -eq 0 ]; then
18+
sudo_cmd=""
19+
elif ! command -v sudo &> /dev/null && [ "$pkg_manager" != "brew" ]; then
20+
warn "sudo is required to install mkpasswd with $pkg_manager."
21+
return 1
22+
fi
23+
24+
local install_success=false
25+
local log_file="/tmp/shipnode_mkpasswd_install_$$.log"
26+
27+
case "$pkg_manager" in
28+
apt)
29+
info "Using apt to install whois..."
30+
$sudo_cmd apt update &> "$log_file" && \
31+
$sudo_cmd apt install -y whois >> "$log_file" 2>&1 && install_success=true
32+
;;
33+
dnf|yum)
34+
info "Using $pkg_manager to install whois..."
35+
$sudo_cmd "$pkg_manager" install -y whois &> "$log_file" && install_success=true
36+
;;
37+
apk)
38+
info "Using apk to install whois..."
39+
$sudo_cmd apk add --no-cache whois &> "$log_file" && install_success=true
40+
;;
41+
pacman)
42+
info "Using pacman to install whois..."
43+
$sudo_cmd pacman -S --needed --noconfirm whois &> "$log_file" && install_success=true
44+
;;
45+
brew)
46+
info "Using Homebrew to install whois..."
47+
brew install whois &> "$log_file" && install_success=true
48+
;;
49+
*)
50+
warn "Unsupported package manager: $pkg_manager"
51+
return 1
52+
;;
53+
esac
54+
55+
if [ "$install_success" = true ] && command -v mkpasswd &> /dev/null; then
56+
success "mkpasswd installed successfully"
57+
rm -f "$log_file"
58+
return 0
559
fi
660

61+
warn "Failed to install mkpasswd."
62+
if [ -f "$log_file" ]; then
63+
warn "Installation log available at: $log_file"
64+
fi
65+
warn "Install it manually with your package manager (Debian/Ubuntu package: whois)."
66+
return 1
67+
}
68+
69+
ensure_mkpasswd() {
70+
if command -v mkpasswd &> /dev/null; then
71+
return 0
72+
fi
73+
74+
install_mkpasswd || error "mkpasswd not found. Install it manually with your package manager (Debian/Ubuntu: sudo apt-get install whois)"
75+
}
76+
77+
cmd_mkpasswd() {
78+
ensure_mkpasswd
79+
780
info "Generate password hash for users.yml"
881
echo ""
982

@@ -33,4 +106,3 @@ cmd_mkpasswd() {
33106
echo " password: \"$hash\""
34107
echo ""
35108
}
36-

lib/core.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ BLUE='\033[0;34m'
1010
NC='\033[0m' # No Color
1111

1212
# ShipNode version
13-
VERSION="1.3.2"
13+
VERSION="1.3.3"
1414

1515
# SSH multiplexing for connection reuse
1616
SSH_CONTROL_PATH="/tmp/shipnode-ssh-%r@%h:%p"

lib/users.sh

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,7 @@ prompt_yes_no() {
4444
# Generate password hash (reuses cmd_mkpasswd logic)
4545
generate_password_hash() {
4646
local password=$1
47-
# Check if mkpasswd is available
48-
if ! command -v mkpasswd &> /dev/null; then
49-
error "mkpasswd not found. Install it with: sudo apt-get install whois"
50-
fi
47+
ensure_mkpasswd
5148
mkpasswd -m sha-512 "$password"
5249
}
5350

0 commit comments

Comments
 (0)