20 Commits
1.0 ... dev

Author SHA1 Message Date
Lucas
a87604c1f3 ajout du gitignore 2025-10-10 17:27:40 +02:00
Lucas
622e386eac optimisation, correction de stucture, etc 2025-10-10 17:26:39 +02:00
Lucas
a7df64ffb1 ajout de la commande --env pour choisir l'env de lancement 2025-10-10 17:20:24 +02:00
Lucas
e5451d3711 ajout de la commande env 2025-10-10 17:10:32 +02:00
Lucas
cc963059d4 petits ajouts 2025-10-10 16:33:33 +02:00
Lucas
42e369b563 ajout de la commande -v 2025-10-10 10:12:50 +02:00
Lucas
422e5ef3b8 sup d'un fichier indesirable 2025-10-10 09:29:42 +02:00
Lucas
f8742efed4 ajout de la verfication de la presences des commandes 2025-10-10 09:20:16 +02:00
Lucas
b25efc9aac ajout du fichier i3 2025-10-09 09:04:14 +02:00
Lucas
ae70a4c960 ajout du raccourci clavier de i3 pour le launcher 2025-10-09 01:04:51 +02:00
Lucas Morel
5d1faa3afb Refactor main function and cleanup setup code
Refactor launcher.sh to streamline the main function and remove unnecessary setup code.
2025-10-08 20:09:08 +02:00
Lucas
2d37d86fcd correction de bugs 2025-10-08 19:49:56 +02:00
Lucas Morel
f95de8af9e Fix directory creation for AFS configuration 2025-10-08 19:01:45 +02:00
Lucas Morel
5d30dc479f Configure environment and afs directory in launcher.sh
Set environment variable and adjust afs path based on environment.
2025-10-08 18:59:26 +02:00
Lucas Morel
01009b8cea Reformat check functions and add cop_files call 2025-10-08 18:52:54 +02:00
Lucas
8d0640a6e2 Ajout de beaucoup de chose 2025-10-08 18:44:12 +02:00
Lucas
4a8af061ca optimisations 2025-10-07 23:56:35 +02:00
Lucas Morel
83bcc68f8d Change shebang to use env for bash 2025-09-25 20:06:11 +02:00
Lucas
4bfb7e5d0e final 2025-09-25 19:03:28 +02:00
Lucas
1e7c22beae correction repo 2025-09-25 18:59:19 +02:00
4 changed files with 291 additions and 121 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
.launcher.sh.un~

Binary file not shown.

290
launcher.sh Normal file
View File

@@ -0,0 +1,290 @@
#!/usr/bin/env bash
# -----------------------------------------------------------------------------
# AVERTISSEMENT LÉGAL ET TECHNIQUE
# Date : 2025-10-08
# Auteur : Lucas Morel <lucas.morel@epita.fr>
# Version : v1.2 (https://github.com/PixPix20/Minecraft-Installer)
#
# 1) Objet : Ce script vise à automatiser le lancement et l'installation de PrismLauncher.
#
# 2) Garantie : Fourni "tel quel", sans garantie expresse ou implicite.
#
# 3) Responsabilité : L'utilisateur est responsable de l'exécution sur son AFS.
# Je décline toute responsabilité pour toute perte, corruption ou modification
# de données, que le script ait été modifié ou non.
#
# 4) Modifications : Toute modification du script implique que le modificateur
# assume l'entière responsabilité des conséquences.
#
# Contact : https://github.com/PixPix20
# -----------------------------------------------------------------------------
set -euo pipefail
VERSION="1.2"
# Variables globales
env="prod"
afs="$HOME/afs"
i3="$afs/.confs/config/i3"
i3_config="$i3/config"
max_storage=2147483648 #2Go max sur l'afs
minecraft_storage=943718400 #900Mo pour Minecraft
margin_storage=419430400 #400Mo de marge
minecraft_path="$afs/minecraft"
launcher_name="PrismLauncher"
launcher_config_path="$minecraft_path/config"
launcher_appimage="$minecraft_path/PrismLauncher-Linux-x86_64.AppImage"
instances_path="$minecraft_path/Instances"
mods_path="$minecraft_path/mods"
java_path="$minecraft_path/java"
downloads_path="$HOME/Downloads"
launcher_local_files_path="$HOME/.local/share/PrismLauncher"
bin_path="$minecraft_path/bin"
launcher_url="https://github.com/PrismLauncher/PrismLauncher/releases/download/9.4/PrismLauncher-Linux-x86_64.AppImage"
config_url="https://raw.githubusercontent.com/PixPix20/Minecraft-Installer/refs/heads/main/prismlauncher.cfg"
# Fonctions
set_env() {
if [ "${env:-prod}" = "dev" ]; then
afs="$HOME/test"
printf "ATTENTION: Vous êtes en mode 'dev'. Les chemins ont changé !\n"
else
afs="$HOME/afs"
fi
i3="$afs/.confs/config/i3"
i3_config="$i3/config"
mkdir -p "$afs" "$i3"
}
show_version() {
printf "Version %s\n" "$VERSION"
}
show_env() {
printf "Environnement : %s\n--PATHS :\n" "$env"
printf "AFS : %s\n" "$afs"
printf "i3 : %s\n" "$i3_config"
printf "Config launcher : %s\n" "$launcher_config_path"
printf "AppImage : %s\n" "$launcher_appimage"
printf "Instances : %s\n" "$instances_path"
printf "Mods : %s\n" "$mods_path"
printf "Java : %s\n" "$java_path"
printf "Téléchargements : %s\n" "$downloads_path"
printf "Fichiers locaux launcher : %s\n" "$launcher_local_files_path"
printf "Script : %s\n" "$bin_path"
}
help_msg() {
cat <<EOF
Minecraft Installer v$VERSION
Usage: $0 [option]
Options:
-v, --version Affiche la version du script
-e, --env [dev|prod] Définit l'environnement (dev/prod)
-se, --show-env Affiche l'environnement et les paths
-i, --install Installe PrismLauncher
-u, --update Met à jour le script
-r, --remove Désinstalle le launcher et ses fichiers
-l, --launch Lance PrismLauncher
-ad, --add-dmenu Ajoute le script à dmenu
-h, --help Affiche ce texte
EOF
}
check_commands() {
local err=0
for cmd in wget curl sed grep nix-shell bc; do
if ! command -v "$cmd" &>/dev/null; then
printf "%s n'est pas installé !\n" "$cmd"
err=1
fi
done
return $err
}
check_storage() {
local used_storage total_storage
used_storage=$(du -sb "$afs" 2>/dev/null | awk '{print $1}')
total_storage=$((used_storage + minecraft_storage + margin_storage))
if ((max_storage < total_storage)); then
printf "Erreur, pas assez de place pour l'installation ! %d octets requis.\n" "$total_storage"
return 1
fi
return 0
}
check_path() {
mkdir -p "$minecraft_path" "$launcher_config_path" "$instances_path" "$mods_path" "$java_path" "$bin_path"
}
check_config() {
local config="$launcher_config_path/prismlauncher.cfg"
if [ ! -f "$config" ]; then
wget -q -P "$launcher_config_path/" "$config_url"
sed -i \
-e "s|DownloadsDir=.*|DownloadsDir=$downloads_path|" \
-e "s|InstanceDir=.*|InstanceDir=$instances_path|" \
-e "s|CentralModsDir=.*|CentralModsDir=$mods_path|" \
-e "s|JavaDir=.*|JavaDir=$java_path|" \
"$config"
fi
}
add_to_dmenu() {
sed -i "s|bindsym \$mod+d exec --no-startup-id dmenu_run|bindsym \$mod+d exec --no-startup-id PATH=$bin_path:\$PATH dmenu_run|" "$i3_config"
if ! grep -q "PATH=$bin_path" "$HOME/.bashrc"; then
echo "export PATH=$bin_path:\$PATH" >> "$HOME/.bashrc"
fi
if ! grep -q "minecraft-launcher" "$i3_config"; then
echo "bindsym \$mod+m exec --no-startup-id minecraft-launcher -l" >> "$i3_config"
fi
cp "$0" "$bin_path/minecraft-launcher"
chmod +x "$bin_path/minecraft-launcher"
}
remove_all() {
rm -rf "$minecraft_path"
sed -i "s|PATH=$bin_path:\$PATH||g" "$HOME/.bashrc"
}
update_script() {
local script_url="https://raw.githubusercontent.com/PixPix20/Minecraft-Installer/main/launcher.sh"
wget -q -O "$0.tmp" "$script_url"
if [ -s "$0.tmp" ]; then
mv "$0.tmp" "$0"
chmod +x "$0"
echo "Script mis à jour !"
else
echo "Erreur lors du téléchargement de la mise à jour."
rm -f "$0.tmp"
fi
}
get_remote_version() {
local remote_url="https://api.github.com/repos/PixPix20/Minecraft-Installer/releases/latest"
curl -s "$remote_url" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/'
}
check_script_update() {
local local_version="$VERSION"
local remote_version
remote_version=$(get_remote_version)
if [ -z "$remote_version" ]; then
echo "Impossible de récupérer la version distante."
return 1
fi
echo "Version locale : $local_version"
echo "Version distante : $remote_version"
if [ "$(printf '%s\n' "$remote_version" "$local_version" | sort -V | head -n1)" != "$remote_version" ]; then
echo "Une nouvelle version du script est disponible."
read -r -p "Voulez-vous la mettre à jour ? [o/N] " answer
if [[ "$answer" =~ ^[Oo]$ ]]; then
update_script
else
echo "Mise à jour annulée."
fi
else
echo "Le script est à jour."
fi
}
check_account() {
while [ ! -f "$launcher_local_files_path/accounts.json" ]; do
sleep 2
done
printf "Compte détecté, sauvegarde\n"
cp "$launcher_local_files_path/accounts.json" "$launcher_config_path"
}
check_launcher() {
if [ ! -f "$launcher_appimage" ]; then
mkdir -p "$(dirname "$launcher_appimage")"
wget -q -O "$launcher_appimage" "$launcher_url"
chmod +x "$launcher_appimage"
fi
}
cop_files() {
mkdir -p "$launcher_local_files_path"
cp "$launcher_config_path"/* "$launcher_local_files_path"
}
start_launcher() {
nix-shell -p appimage-run --run "appimage-run $launcher_appimage"
}
main() {
set_env
if [ $# -eq 0 ]; then
check_commands || exit 1
check_path
check_config
check_launcher
cop_files
check_account & start_launcher
exit 0
fi
case "${1:-}" in
-e|--env)
if [[ -n "${2:-}" ]]; then
env="$2"
else
echo "Usage: $0 --env [dev|prod]"
exit 1
fi
set_env
;;
-se|--show-env)
show_env
;;
-i|--install)
check_commands || exit 1
check_storage || exit 1
check_path
check_config
check_launcher
add_to_dmenu
echo "Installation terminée."
;;
-u|--update)
check_commands || exit 1
check_script_update
;;
-r|--remove)
remove_all
;;
-l|--launch)
check_commands || exit 1
check_path
check_config
check_launcher
cop_files
check_account & start_launcher
;;
-ad|--add-dmenu)
add_to_dmenu
;;
-v|--version)
show_version
;;
-h|--help)
help_msg
;;
*)
echo "Option inconnue: $1"
help_msg
exit 1
;;
esac
}
main "$@"

View File

@@ -1,121 +0,0 @@
#!/bin/bash
set -euo pipefail
VERSION=1.0
#NOTES:
#Verification du stockage : OK
#creation des dossiers : OK
#creation de la config : OK
#creation du compte : OK mais A VOIR
#sys de deplacement des files : OK
#sys de lancement: OK
#telechargement du launcher : OK
#On verifie qu'il y a assez de place pour installer minecraft en plus de garder un peu de place pour le reste
max_storage=2147483648 #2Go, le stockage max de l'afs, je deconseille fortement d'augmenter cette valeur !
used_storage=$(du -sb "$HOME/afs" | awk '{print $1}') #La taille actuelle de votre afs
minecraft_storage=943718400 #900Mo, j'utilise cette valeur si vous voulez jouer avec un modpack qui est lourd
margin_storage=419430400 #400Mo, marge de securité pour que vous puissiez utiliser l'afs aprés l'installation du jeu, je deconseille de modifier cette valeur
afs="$HOME/afs"
launcher_name="PrismLauncher"
minecraft_path="$afs/minecraft" #dossier qui contient minecraft la conf du launcher etc
launcher_config_path="$minecraft_path/config" #dossier qui contient les configurations du launcher
instances_path="$minecraft_path/Instances" #dossier qui contient les instances minecraft
mods_path="$minecraft_path/mods" #Dossier qui contient les mods minecraft
java_path="$minecraft_path/java" #Dossier qui contient java(installe auto)
downloads_path="$HOME/Downloads"
prismlocal_path="$HOME/.local/share/PrismLauncher"
appimage="$minecraft_path/PrismLauncher-Linux-x86_64.AppImage" #Dossier sense contenir le .appimage du launcher
url="https://github.com/PrismLauncher/PrismLauncher/releases/download/9.4/PrismLauncher-Linux-x86_64.AppImage" #URL du github pour telecharger le launcher
total_storage=$(($used_storage+$minecraft_storage+$margin_storage))
check_storage(){
#verification si l'AFS peut installer minecraft en plus de garder un marge pour les autre fichiers
if [ $total_storage -gt $max_storage ]; then
printf "Impossible d'installer minecraft, il n'y a pas assez de place."
printf "\n\tEssayez de supprimer quelques fichiers, regardez dans les configuration (du -h --max-depth=1 ~/.confs) pour connaitre la taille des differentes configuration"
printf "\n\tNote: Chez moi la configuration de Discord faisait plus de 700Mo et celle de Firefox plus de 600Mo"
return 1
else
return 0
fi
}
check_path(){
#Verfication de l'arbo du dossier minecraft
if [ ! -d "$minecraft_path" ]; then
mkdir $minecraft_path $launcher_config_path $instances_path $mods_path $java_path
else
if [ ! -d "$instances_path" ]; then
mkdir $instances_path
fi
if [ ! -d "$mods_path" ]; then
mkdir $mods_path
fi
if [ ! -d "$java_path" ]; then
mkdir $java_path
fi
if [ ! -d "$launcher_config_path" ]; then
mkdir $launcher_config_path
fi
if [ ! -d "$downloads_path" ]; then
mkdir $downloads_path
fi
fi
}
check_config(){
#telechargement et modification de la config
if [ ! -f "$launcher_config_path/prismlauncher.cfg" ]; then
wget -P "$launcher_config_path/" "https://raw.githubusercontent.com/PixPix20/Minecraft-Installer/refs/heads/main/prismlauncher.cfg"
sed -i "s|DownloadsDir=|DownloadsDir=$downloads_path|" $launcher_config_path/prismlauncher.cfg
sed -i "s|InstanceDir=|InstanceDir=$instances_path|" $launcher_config_path/prismlauncher.cfg
sed -i "s|CentralModsDir=|CentralModsDir=$mods_path|" $launcher_config_path/prismlauncher.cfg
sed -i "s|JavaDir=|JavaDir=$java_path|" $launcher_config_path/prismlauncher.cfg
fi
}
check_account(){
#enregistrement du compte une fois connecte
while [ ! -f "$prismlocal_path/accounts.json" ]; do
sleep 2
done
cp $prismlocal_path/accounts.json $launcher_config_path
}
check_launcher(){
#telechargement du launcher si inexistant
if [ ! -f "$appimage" ]; then
echo "Téléchargement de PrismLauncher..."
mkdir -p "$(dirname "$appimage")"
#curl -L -o "$appimage" "$url"
wget -O "$appimage" "$url"
chmod +x "$appimage"
fi
}
cop_files(){
#deplacement des fichers de config et du compte dans le .local du launcher
if [ ! -f "$prismlocal_path" ]; then
mkdir -p $prismlocal_path
fi
cp $launcher_config_path/* $prismlocal_path
}
start_launcher(){
nix-shell -p appimage-run --run "appimage-run $appimage"
}
#installation
check_storage
check_path
check_config
cop_files
check_launcher
echo fin
start_launcher & check_account # doit se faire en para