Skip to content

Commit

Permalink
Merge pull request #2299 from 13MrBlackCat13/patch-2
Browse files Browse the repository at this point in the history
Update install.sh
  • Loading branch information
shamhi authored Sep 1, 2024
2 parents 54a1628 + fabe0aa commit b8208db
Showing 1 changed file with 34 additions and 3 deletions.
37 changes: 34 additions & 3 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@ install_python() {
echo "3) Python 3.11"
echo "4) Python 3.12"
read -p "Enter the number of your choice: " choice

case $choice in
1) version="3.9" ;;
2) version="3.10" ;;
3) version="3.11" ;;
4) version="3.12" ;;
*) echo "Invalid choice"; exit 1 ;;
esac

if command -v apt-get &> /dev/null; then
sudo apt-get update
sudo apt-get install -y python$version python$version-venv python$version-pip
Expand All @@ -30,6 +28,37 @@ install_python() {
fi
}

create_service() {
read -p "Do you want to create a system service for automatic startup? (y/n): " create_service_choice
if [[ $create_service_choice == "y" || $create_service_choice == "Y" ]]; then
read -p "Enter the name for the service: " service_name
read -p "Enter the full path to your Python script: " script_path

# Create service file
echo "[Unit]
Description=$service_name
After=network.target
[Service]
ExecStart=$(which python3) $script_path
WorkingDirectory=$(dirname $script_path)
Restart=always
User=$USER
[Install]
WantedBy=multi-user.target" | sudo tee /etc/systemd/system/$service_name.service > /dev/null

# Reload systemd, enable and start the service
sudo systemctl daemon-reload
sudo systemctl enable $service_name
sudo systemctl start $service_name

echo "Service $service_name has been created, enabled, and started."
else
echo "Skipping service creation."
fi
}

if ! command -v python3 &> /dev/null; then
install_python
fi
Expand All @@ -50,4 +79,6 @@ echo "Copying .env-example to .env..."
cp .env-example .env

echo "Please edit the .env file to add your API_ID and API_HASH."
read -p "Press any key to continue..."
read -p "Press any key to continue..."

create_service

0 comments on commit b8208db

Please sign in to comment.