Repository navigation
Expand file tree
/
Copy pathinstall_with_auth.sh
More file actions
executable file
·173 lines (146 loc) · 5.17 KB
/
Copy pathinstall_with_auth.sh
File metadata and controls
executable file
·173 lines (146 loc) · 5.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#!/bin/bash
#
# Samba Manager Installation Script with GitHub Authentication
# This script downloads and installs Samba Manager from a GitHub repository
#
# Check if script is running as root
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root. Please use sudo."
exit 1
fi
echo "=========================================================="
echo " Samba Manager Installation Script"
echo "=========================================================="
echo ""
# Ask for GitHub credentials if needed
read -p "Do you need to authenticate with GitHub? (y/n): " need_auth
if [[ "$need_auth" == "y" || "$need_auth" == "Y" ]]; then
read -p "Enter GitHub username: " github_username
read -s -p "Enter GitHub password or personal access token: " github_token
echo ""
# Create temporary netrc file for authentication
cat > ~/.netrc << EOF
machine github.com
login $github_username
password $github_token
machine api.github.com
login $github_username
password $github_token
EOF
chmod 600 ~/.netrc
echo "GitHub authentication configured."
fi
# Create a temporary directory
TEMP_DIR=$(mktemp -d)
echo "Created temporary directory: $TEMP_DIR"
cd $TEMP_DIR
# Check for required tools
check_requirements() {
echo "Checking for required tools..."
# Check for git
if ! command -v git &> /dev/null; then
echo "Git is not installed. Installing..."
# Detect the Linux distribution
if [ -f /etc/os-release ]; then
. /etc/os-release
DISTRO=$ID
DISTRO_FAMILY=$ID_LIKE
else
echo "Cannot detect Linux distribution. Please install git manually."
exit 1
fi
# Install git based on distribution
if [[ "$DISTRO" == "ubuntu" || "$DISTRO" == "debian" || "$DISTRO_FAMILY" == *"debian"* ]]; then
apt-get update
apt-get install -y git
elif [[ "$DISTRO" == "fedora" || "$DISTRO" == "rhel" || "$DISTRO" == "centos" || "$DISTRO_FAMILY" == *"fedora"* || "$DISTRO_FAMILY" == *"rhel"* ]]; then
dnf install -y git
elif [[ "$DISTRO" == "arch" || "$DISTRO" == "manjaro" || "$DISTRO_FAMILY" == *"arch"* ]]; then
pacman -Sy --noconfirm git
else
echo "Unsupported distribution for automatic git installation."
echo "Please install git manually and run this script again."
exit 1
fi
fi
echo "Git is installed."
}
# Download Samba Manager
download_samba_manager() {
echo "Downloading Samba Manager from repository..."
# Try to clone the repository
echo "Attempting to clone from: https://github.com/lyarinet/Samba-Manager.git"
git clone https://github.com/lyarinet/Samba-Manager.git
# If that fails, try with the lowercase name
if [ $? -ne 0 ]; then
echo "First attempt failed. Trying alternate repository name..."
git clone https://github.com/lyarinet/samba_manager.git
if [ $? -ne 0 ]; then
echo "Failed to download Samba Manager."
echo "Please check your internet connection and GitHub credentials."
# Ask for repository URL
read -p "Enter the correct repository URL (e.g., https://github.com/username/repo.git): " repo_url
git clone "$repo_url"
if [ $? -ne 0 ]; then
echo "Failed to clone repository. Exiting."
exit 1
fi
# Get the directory name from the repo URL
REPO_DIR=$(basename "$repo_url" .git)
cd "$REPO_DIR"
else
echo "Download complete using alternate name."
cd samba_manager
fi
else
echo "Download complete."
cd Samba-Manager
fi
}
# Run the installation script
run_installation() {
echo "Running installation script..."
# Check which installation script exists
if [ -f "install_all_distros.sh" ]; then
chmod +x install_all_distros.sh
./install_all_distros.sh
elif [ -f "install.sh" ]; then
chmod +x install.sh
./install.sh
else
echo "No installation script found. Available files:"
ls -la
exit 1
fi
if [ $? -ne 0 ]; then
echo "Installation failed. Please check the error messages above."
exit 1
fi
}
# Clean up
cleanup() {
echo "Cleaning up temporary files..."
cd /
rm -rf $TEMP_DIR
# Remove netrc file if it was created
if [[ "$need_auth" == "y" || "$need_auth" == "Y" ]]; then
rm -f ~/.netrc
fi
echo "Cleanup complete."
}
# Main function
main() {
check_requirements
download_samba_manager
run_installation
cleanup
echo ""
echo "=========================================================="
echo " Samba Manager Installation Complete!"
echo "=========================================================="
echo "Samba Manager has been successfully installed on your system."
echo "You can access it at: http://$(hostname -I | awk '{print $1}'):5000"
echo "=========================================================="
}
# Run the main function
main