Skip to content

Commit

Permalink
Add install-ssh command (Closes #42) #14 #16 #19 #20 #28 #35 #36 #40
Browse files Browse the repository at this point in the history
  • Loading branch information
ysdragon committed Dec 17, 2024
1 parent 6750528 commit 847b327
Showing 1 changed file with 111 additions and 16 deletions.
127 changes: 111 additions & 16 deletions run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,25 @@ GREEN='\033[0;32m'
YELLOW='\033[0;33m'
NC='\033[0m'

# Configuration
HOSTNAME="MyVPS"
HISTORY_FILE="${HOME}/.custom_shell_history"
MAX_HISTORY=1000

# Check if not installed
if [ ! -e "/.installed" ]; then
if [ ! -e "/.installed" ]; then
# Check if rootfs.tar.xz or rootfs.tar.gz exists and remove them if they do
if [ -f "/rootfs.tar.xz" ]; then
rm -f "/rootfs.tar.xz"
fi

if [ -f "/rootfs.tar.gz" ]; then
rm -f "/rootfs.tar.gz"
fi

# Wipe the files we downloaded into /tmp previously
rm -rf /tmp/sbin

# Mark as installed.
touch "/.installed"
fi
Expand All @@ -36,14 +41,22 @@ printf "${GREEN}Starting..${NC}\n"
sleep 1
printf "\033c"

# Configuration
HOSTNAME="MyVPS"
HISTORY_FILE="${HOME}/.custom_shell_history"
MAX_HISTORY=1000
# Logger function
log() {
local level=$1
local message=$2
local color=$3

if [ -z "$color" ]; then
color=${NC}
fi

printf "${color}[$level] $message${NC}\n"
}

# Function to handle cleanup on exit
cleanup() {
printf "\n${GREEN}Session ended. Goodbye!${NC}\n"
log "INFO" "Session ended. Goodbye!" "$GREEN"
exit 0
}

Expand All @@ -67,14 +80,14 @@ print_banner() {
printf "${GREEN}│ │${NC}\n"
printf "${GREEN}│ Pterodactyl VPS EGG │${NC}\n"
printf "${GREEN}│ │${NC}\n"
printf "${GREEN}${RED}© 2021 - 2024 ${PURPLE}ysdragon${GREEN} ${NC}\n"
printf "${GREEN}${RED}© 2021 - 2024 ${PURPLE}@ysdragon${GREEN}${NC}\n"
printf "${GREEN}│ │${NC}\n"
printf "${GREEN}╰────────────────────────────────────────────────────────────────────────────────╯${NC}\n"
printf " \n"
}

print_instructions() {
printf "${YELLOW}Type 'help' to view a list of available custom commands.${NC}\n\n"
log "INFO" "Type 'help' to view a list of available custom commands." "$YELLOW"
}

# Function to print prompt
Expand All @@ -100,14 +113,91 @@ save_to_history() {
reinstall() {
# Source the /etc/os-release file to get OS information
. /etc/os-release

if [ "$ID" = "alpine" ] || [ "$ID" = "chimera" ]; then
rm -rf / > /dev/null 2>&1
else
rm -rf --no-preserve-root / > /dev/null 2>&1
fi
}

# Function to install wget
install_wget() {
distro=$(grep -E '^ID=' /etc/os-release | cut -d= -f2 | tr -d '"')

case "$distro" in
"debian"|"ubuntu"|"devuan"|"linuxmint"|"kali")
apt-get update -qq && apt-get install -y -qq wget > /dev/null 2>&1
;;
"void")
xbps-install -Syu -q wget > /dev/null 2>&1
;;
"centos"|"fedora"|"rockylinux"|"almalinux"|"openEuler"|"amzn"|"ol")
yum install -y -q wget > /dev/null 2>&1
;;
"opensuse"|"opensuse-tumbleweed"|"opensuse-leap")
zypper install -y -q wget > /dev/null 2>&1
;;
"alpine"|"chimera")
apk add --no-scripts -q wget > /dev/null 2>&1
;;
"gentoo")
emerge --sync -q && emerge -q wget > /dev/null 2>&1
;;
"arch")
pacman -Syu --noconfirm --quiet wget > /dev/null 2>&1
;;
"slackware")
yes | slackpkg install wget > /dev/null 2>&1
;;
*)
log "ERROR" "Unsupported distribution: $distro" "$RED"
return 1
;;
esac
}

# Function to install SSH from the repository
install_ssh() {
# Install wget if not found
if ! command -v wget &> /dev/null; then
log "INFO" "Installing wget." "$YELLOW"
install_wget
fi

log "INFO" "Installing SSH." "$YELLOW"

# Determine the architecture
arch=$(uname -m)
case "$arch" in
x86_64)
arch="amd64"
;;
*)
arch="$arch"
;;
esac

# URL to download the SSH binary
url="https://github.com/ysdragon/ssh/releases/latest/download/ssh-$arch"

# Download the SSH binary
wget -q -O /usr/local/bin/ssh "$url"
if [ $? -ne 0 ]; then
log "ERROR" "Failed to download SSH." "$RED"
return 1
fi

# Make the binary executable
chmod +x /usr/local/bin/ssh
if [ $? -ne 0 ]; then
log "ERROR" "Failed to make ssh executable." "$RED"
return 1
fi

log "INFO" "SSH installed successfully." "$GREEN"
}

# Function to print a beautiful help message
print_help_message() {
printf "${PURPLE}╭────────────────────────────────────────────────────────────────────────────────╮${NC}\n"
Expand All @@ -118,6 +208,7 @@ print_help_message() {
printf "${PURPLE}${YELLOW}exit${GREEN} - Shutdown the server. ${PURPLE}${NC}\n"
printf "${PURPLE}${YELLOW}history${GREEN} - Show command history. ${PURPLE}${NC}\n"
printf "${PURPLE}${YELLOW}reinstall${GREEN} - Reinstall the server. ${PURPLE}${NC}\n"
printf "${PURPLE}${YELLOW}install-ssh${GREEN} - Install our custom SSH server. ${PURPLE}${NC}\n"
printf "${PURPLE}${YELLOW}help${GREEN} - Display this help message. ${PURPLE}${NC}\n"
printf "${PURPLE}│ │${NC}\n"
printf "${PURPLE}╰────────────────────────────────────────────────────────────────────────────────╯${NC}\n"
Expand Down Expand Up @@ -149,12 +240,17 @@ execute_command() {
return 0
;;
"reinstall")
printf "\n${GREEN}Reinstalling....${NC}\n"
log "INFO" "Reinstalling...." "$GREEN"
reinstall
exit 2
;;
"sudo"*|"su"*)
printf "${RED}You are already running as root.${NC}\n"
log "ERROR" "You are already running as root." "$RED"
print_prompt "$user"
return 0
;;
"install-ssh")
install_ssh
print_prompt "$user"
return 0
;;
Expand All @@ -180,7 +276,6 @@ run_prompt() {
print_prompt "$user"
}


# Create history file if it doesn't exist
touch "$HISTORY_FILE"

Expand All @@ -190,7 +285,7 @@ trap cleanup INT TERM
# Print initial banner
print_banner

# Print the initial instructions
# Print the initial instructions
print_instructions

# Print initial command
Expand Down

0 comments on commit 847b327

Please sign in to comment.