diff --git a/install_guac.sh b/install_guac.sh index b0f6157..7426a87 100644 --- a/install_guac.sh +++ b/install_guac.sh @@ -12,25 +12,22 @@ GUACVERSION="1.5.5" GUAC_USER="guacamole_user" GUAC_DB="guacamole_db" TOMCAT_VER=9.0.109 +CRED_FILE="/root/guacamole-credentials.txt" -# Root check -if [ "$(id -u)" -ne 0 ]; then - echo -e "${RED}Please run as root${NC}" - exit 1 -fi +# --- Secure password generation --- +MYSQL_ROOT_PWD=$(openssl rand -base64 20) +GUAC_PWD=$(openssl rand -base64 20) +GUACADMIN_PWD=$(openssl rand -base64 20) -# --- Interactive prompts --- -read -p "Enter MySQL root password [default: password]: " MYSQL_ROOT_PWD -MYSQL_ROOT_PWD=${MYSQL_ROOT_PWD:-password} - -read -p "Enter Guacamole DB user password [default: password]: " GUAC_PWD -GUAC_PWD=${GUAC_PWD:-password} - -read -p "Enter server name (FQDN) for Nginx (e.g. guac.example.com): " SERVER_NAME -if [ -z "$SERVER_NAME" ]; then - echo -e "${RED}Server name is required for Nginx reverse proxy${NC}" - exit 1 -fi +# --- Server name prompt --- +while true; do + read -p "Enter server name (FQDN) for Nginx/Let's Encrypt (e.g. guac.example.com): " SERVER_NAME + if [ -n "$SERVER_NAME" ]; then + break + else + echo -e "${RED}Server name cannot be empty!${NC}" + fi +done # --- Base packages --- echo -e "${BLUE}>>> Installing base packages...${NC}" @@ -42,7 +39,7 @@ DEBIAN_FRONTEND=noninteractive apt-get install -yq \ freerdp2-dev libpango1.0-dev libssh2-1-dev libtelnet-dev \ libvncserver-dev libpulse-dev libssl-dev libvorbis-dev libwebp-dev \ libwebsockets-dev freerdp2-x11 libtool-bin ghostscript dpkg-dev crudini \ - mariadb-server mariadb-client nginx + mariadb-server mariadb-client nginx certbot python3-certbot-nginx openssl # --- Java --- if ! command -v java >/dev/null 2>&1; then @@ -52,51 +49,12 @@ JAVA_HOME=$(dirname $(dirname $(readlink -f $(which java)))) echo -e "${GREEN}JAVA_HOME detected as ${JAVA_HOME}${NC}" # --- Firewall --- -echo -e "${BLUE}>>> Configuring UFW...${NC}" ufw --force enable ufw allow ssh ufw allow 80/tcp ufw allow 443/tcp ufw reload -# --- VNC --- -if [ ! -f "$HOME/.vnc/xstartup" ]; then - echo -e "${BLUE}>>> Configuring VNC server...${NC}" - umask 0077 - mkdir -p "$HOME/.vnc" - vncpasswd -f <<<"password" >"$HOME/.vnc/passwd" - vncserver || true - sleep 2 && vncserver -kill :1 || true - cat > ~/.vnc/xstartup < /etc/systemd/system/vncserver@.service < /dev/null 2>&1 -ExecStart=/usr/bin/vncserver -depth 24 -geometry 1280x800 -localhost :%i -ExecStop=/usr/bin/vncserver -kill :%i -[Install] -WantedBy=multi-user.target -EOF - systemctl daemon-reload - systemctl enable vncserver@1.service -fi -systemctl restart vncserver@1 || true - # --- Tomcat 9 --- if [ ! -d /opt/apache-tomcat-${TOMCAT_VER} ]; then echo -e "${BLUE}>>> Installing Tomcat ${TOMCAT_VER}...${NC}" @@ -133,7 +91,6 @@ systemctl enable --now tomcat9 cd /root SERVER="https://downloads.apache.org/guacamole/${GUACVERSION}" -# Download if missing if [ ! -d guacamole-server-${GUACVERSION} ]; then wget -q ${SERVER}/source/guacamole-server-${GUACVERSION}.tar.gz tar -xzf guacamole-server-${GUACVERSION}.tar.gz @@ -142,7 +99,6 @@ if [ ! -d guacamole-server-${GUACVERSION} ]; then tar -xzf guacamole-auth-jdbc-${GUACVERSION}.tar.gz fi -# Build guacd if not present if ! command -v guacd >/dev/null 2>&1; then cd guacamole-server-${GUACVERSION} ./configure --with-systemd-dir=/etc/systemd/system @@ -152,7 +108,6 @@ if ! command -v guacd >/dev/null 2>&1; then cd .. fi -# guacd service if [ ! -f /etc/systemd/system/guacd.service ]; then cat > /etc/systemd/system/guacd.service <>> Setting up MySQL database...${NC}" +mysql -u root </dev/null; then mysql -u root -p${MYSQL_ROOT_PWD} -e "CREATE DATABASE ${GUAC_DB};" fi @@ -202,11 +160,14 @@ mysql-username: ${GUAC_USER} mysql-password: ${GUAC_PWD} EOF +# Reset guacadmin password +HASHED=$(echo -n "${GUACADMIN_PWD}" | openssl md5 | awk '{print $2}') +mysql -u root -p${MYSQL_ROOT_PWD} ${GUAC_DB} -e "UPDATE guacamole_user SET password='${HASHED}' WHERE username='guacadmin';" + systemctl restart tomcat9 -# --- Chrome --- +# --- Chrome + Tampermonkey --- if ! command -v google-chrome >/dev/null 2>&1; then - echo -e "${BLUE}>>> Installing Google Chrome...${NC}" ARCH=$(dpkg --print-architecture) if [ "$ARCH" = "amd64" ]; then CHROME_DEB="https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb" @@ -219,7 +180,6 @@ if ! command -v google-chrome >/dev/null 2>&1; then rm -f "$TMP_DEB" fi -# --- Tampermonkey --- EXT_ID="dhdgffkkebhmkfjojejmpbldmpobfkfo" EXT_DIR="/opt/google/chrome/extensions" if [ ! -f "$EXT_DIR/$EXT_ID.json" ]; then @@ -232,7 +192,6 @@ EOF fi # --- Nginx reverse proxy --- -echo -e "${BLUE}>>> Configuring Nginx reverse proxy...${NC}" cat > /etc/nginx/sites-available/guacamole < /etc/nginx/sites-available/guacamole <>> Installing Tailscale...${NC}" +curl -fsSL https://tailscale.com/install.sh | sh +systemctl enable --now tailscaled + +echo +echo "Tailscale auth:" +echo " - Enter auth key (from https://login.tailscale.com/admin/settings/keys)" +echo " - Leave blank for interactive login" +read -p "Tailscale auth key: " TSKEY +if [ -n "$TSKEY" ]; then + tailscale up --authkey=${TSKEY} --ssh +else + tailscale up --ssh +fi + +# --- Save credentials --- +cat > ${CRED_FILE} <