#!/bin/bash
# Copyleft Free-Solutions Sàrl 2019
# Script to create Free-Solutions OS USB key Sandisk 32GB ultrafit
#
# Need to have superuser privileges ...
if [ "X${XDG_RUNTIME_DIR}" = "X" ]; then
if [ ! -d /tmp/runtime-root ]; then
mkdir /tmp/runtime-root
fi
export XDG_RUNTIME_DIR=/tmp/runtime-root
fi
if [ $(id -u) -ne 0 ]; then
echo "Ce programme nécessite des accès privilégiés."
echo "Redémarrez ce programme avec sudo ou en temps qu'utilisateur 'root'"
kdialog --msgbox "Ce programme nécessite des accès privilégiés.\nRedémarrez ce programme avec sudo ou en temps qu'utilisateur 'root'"
exit
fi
# settings ulimits, if needed ...
if [ $(ulimit -Hi) -ne $(ulimit -Si) ]; then
ulimit -i unlimited
fi
if [ $(ulimit -Hl) -ne $(ulimit -Sl) ]; then
ulimit -l unlimited
fi
ulimit -n 512000
if [ $(ulimit -Hq) -ne $(ulimit -Sq) ]; then
ulimit -q unlimited
fi
if [ $(ulimit -Hu) -ne $(ulimit -Su) ]; then
ulimit -u unlimited
fi
if [ "$(ulimit -Hs)" != "$(ulimit -Ss)" ]; then
ulimit -s unlimited
fi
download_zcf() {
link=$1
text=$2" "$3" "$4
part=$5
a=$(kdialog --title `echo $text` --progressbar $text 200);sleep 2
qdbus $a showCancelButton true
while read line ;do
read -r p t <<< "$line"
#echo $part
echo "."
qdbus $a Set org.kde.kdialog.ProgressDialog value $p
while [[ $(qdbus $a wasCancelled) != "false" ]] ; do
# echo "KILLING THE PROCESS AND KDIALOG"
qdbus $a org.kde.kdialog.ProgressDialog.close
exit
done
qdbus $a org.kde.kdialog.ProgressDialog.setLabelText "FREE-SOLUTIONS OS $part Download temps restant : $t"
done< <(wget "$link" 2>&1 |mawk -W interactive '{ gsub(/\%/," "); print int($7)" "$9 }')
}
downloadtitle="Téléchargement Free-Solutions OS"
#Choose distro Url
distroUrl="https://www.free-solutions.ch/GREEN_SPIDER/4.0/"
#
# Introduction
#
# Warning disk size
#
# Dial box html
#
#
# Get DialBox image
if [ ! -f Sandisk_PC.jpg ] ; then wget https://www.free-solutions.ch/GREEN_SPIDER/images/Sandisk_PC.jpg && echo "Downloading FS image..." ; fi
#
kdialog --textinputbox "
Free-Solutions OS - Easy Installer
Veuillez vous munir d'une Clé USB Sandisk Ultra Fit 32 ou 128GB
Vous pouvez aussi installer l'OS sur votre disque dur
Aucun support ne sera fourni pour la version téléchargée
Fonctionne sur distro à base Debian
Ubuntu Debian Mint etc...
si vous n'êtes pas sur,
songez à nous acheter une clé pour un résultat immédiat
" "Patience & bonne Installation\nPour acheter une clé Free-Solutions OS\nVisitez https://www.free-solutions.ch" 380 280
#
#kdialog --textinputbox "Free-Solutions OS - Easy Installer
Veuillez vous munir d'une Clé USB Sandisk Ultra Fit 32 ou 128GB
Vous pouvez aussi installer l'OS Sur votre disque dur
Aucun support ne sera fourni pour la version Téléchargée
Fonctionne sur distro à base Debian
Ubuntu Debian Mint etc...
si vous n'êtes pas sur,
songez à nous acheter une clé pour un résultat immédiat et correct
" /dev/stdin 380 280
# Warning disk size
#
kdialog --title "ESPACE DISQUE" --warningyesno "Assurez vous d'avoir 6GB d'espace disque disponible"
if [ $? = 1 ]; then exit ;fi
#
#Checking Pre-Requisits for FREE_SOLUTIONS OS INSTALL
# Check OS version
#
if [ -f /etc/debian_version ] ; then kdialog --warningcontinuecancel "Votre system est OK, Soyez prêt pour installer\n FREE_SOLUTIONS\n Votre OS est basé sur Debian :)" ; else kdialog --msgbox "Votre OS n'est pas basé sur Debian :(\n Veuillez utiliser un OS Debian ou Ubuntu\n pour installer FREE-SOLUTIONS OS" && exit ; fi
if [ $? = 2 ]; then exit ;fi
if [ ! -d TEMPFS ] ; then mkdir TEMPFS ; else kdialog --title "Check DISTRO" --warningyesno "Une Distribution FREE-SOLUTIONS\nse trouve sur votre disque\nVoulez vous l'utiliser ?" ; fi
if [ $? = 1 ]; then rm -f TEMPFS/* ;fi
cd TEMPFS
DISTFOLDER=`pwd`
rm -f *.zst.*
rm -f *-log*
if [ -f listedev.txt ] ; then rm listedev.txt ; fi
#Install zstd compress ???
if dpkg -l | grep "zstd " >/dev/null ; then kdialog --msgbox "Le package ZSTD compression\n est déja installé" ; else kdialog --title "Installation du software zstd compression" --warningcontinuecancel "Le Software ZST compression\n est manquant sur votre system\n ZST software sera installé\n Cliquez Continue pour installer" && apt install -y zstd && kdialog --msgbox "Le Software ZSTD compression \n est installé" ; fi
if [ $? = 2 ]; then exit ;fi
#Install pv package ???
if dpkg -l | grep "pv" | grep "pipeline" >/dev/null ; then kdialog --msgbox "Le package PV\n est déja installé" ; else kdialog --title "Installation du software PV" --warningcontinuecancel "Le Software PV \n est manquant sur votre system\n PV software sera installé\n Cliquez Continue pour installer" && apt install -y pv && kdialog --msgbox "Le Software PV compression \n est installé" ; fi
if [ $? = 2 ]; then exit ;fi
kdialog --title "Plug USB Sandisk Ultrafit" --warningcontinuecancel "UNIQUEMENT SANDISK ULTRAFIT 32GB & 128GB et Patriot 128GB sont supportés" --passivepopup "Waiting for USB Key"
if [ $? = 2 ]; then exit ;fi
while [ ! -e /dev/sd[a-z] ] ; do echo "VEUILLEZ BRANCHEZ UNE CLEF USB..." && sleep 1 ; done
lsblk | grep disk | awk '{ print $1 }' > listedev.txt
DRIVEUSB=$(kdialog --combobox "Free-Solutions installation Disk" `cat listedev.txt`)
MANUFACTURER=`dmesg | grep usb | grep Manufacturer | grep -v Linux | awk '{ print $5" "$6 }' | tail -1l | grep -oE '[^ ]+$'`
PRODUCT=`dmesg | grep usb | grep Product: | grep -v Linux | awk '{ print $5" "$6 }' | tail -1l `
SECTORS=`fdisk -l /dev/$DRIVEUSB | head -1l | awk ' { print $7 }'`
# Test du type de clé 32GB Sandisk
#if [ $MANUFACTURER = "SanDisk" ]
if [ `lsusb | grep 0781 | awk '{ print $7}' | tail -1l` ]
then echo "SANDISK KEY DETECTED" && echo "SECTEURS "$SECTORS
if [ $SECTORS = 60062500 ]
then DETECTEDTYPE="sandisk_ultra32_old"
fi
if [ $SECTORS = 60063744 ]
then DETECTEDTYPE="sandisk_ultra32"
fi
if [ $SECTORS = 60088320 ]
then DETECTEDTYPE="sandisk_ultra32_usb31"
fi
if [ $SECTORS = 242614272 ]
then DETECTEDTYPE="sandisk_ultra128_old"
fi
if [ $SECTORS = 240353280 ]
then DETECTEDTYPE="sandisk_ultra128"
fi
fi
kdialog --msgbox "USB Key detected\n\n\nFabricant : $MANUFACTURER\n$PRODUCT\nTYPE DETECTE: $DETECTEDTYPE "
keytype=$(kdialog --combobox "Choisissez votre modèle de clé\n type détecté :$DETECTEDTYPE" "sandisk_ultra32_old" "sandisk_ultra32" "sandisk_ultra32_usb31" "sandisk_ultra128_old" "sandisk_ultra128" "FSkey_32" "PatriotX_128")
if [ $? = 1 ]; then exit ;fi
echo "KEYTYPE"
echo $keytype
kdialog --title "EFFACEMENT COMPLET du Disque" --warningyesno " Le Disque $DRIVEUSB \n SERA COMPLETEMENT EFFACE"
if [ $? = 1 ]; then exit ;fi
# exit a effacer
#exit
# Download Packages from Free-Solutions servers
if [ ! -f sda1.dd.zst ] ; then download_zcf $distroUrl/sda1.dd.zst $downloadtitle Partition1 ; fi
pid=`ps -ef | grep /usr/bin/kdialog_progress_helper | grep -v grep | awk '{print $2 }'` && if [ $pid ] ; then kill -9 $pid ; fi
if [ ! -f sda2.dd.zst ] ; then download_zcf $distroUrl/sda2.dd.zst $downloadtitle Partition2 ; fi
pid=`ps -ef | grep /usr/bin/kdialog_progress_helper | grep -v grep | awk '{print $2 }'` && if [ $pid ] ; then kill -9 $pid ; fi
if [ ! -f sda3.dd.zst ] ; then download_zcf $distroUrl/sda3.dd.zst $downloadtitle Partition3 ; fi
# exit a effacer
#exit
pid=`ps -ef | grep /usr/bin/kdialog_progress_helper | grep -v grep | awk '{print $2 }'` && if [ $pid ] ; then kill -9 $pid ; fi
if [ ! -f sda4.dd.zst ] ; then download_zcf $distroUrl/sda4.dd.zst $downloadtitle Partition4 ; fi
pid=`ps -ef | grep /usr/bin/kdialog_progress_helper | grep -v grep | awk '{print $2 }'` && if [ $pid ] ; then kill -9 $pid ; fi
if [ ! -f sda5.tar.zst ] ; then download_zcf $distroUrl/sda5.tar.zst $downloadtitle Partition5 ; fi
pid=`ps -ef | grep /usr/bin/kdialog_progress_helper | grep -v grep | awk '{print $2 }'` && if [ $pid ] ; then kill -9 $pid ; fi
if [ ! -f sdapart_$keytype ] ; then download_zcf $distroUrl/sdapart_$keytype $downloadtitle Partitionement ; fi
pid=`ps -ef | grep /usr/bin/kdialog_progress_helper | grep -v grep | awk '{print $2 }'` && if [ $pid ] ; then kill -9 $pid ; fi
if [ ! -f Partitions_$keytype.dd ] ; then download_zcf $distroUrl/Partitions_$keytype.dd $downloadtitle Partitionement ; fi
pid=`ps -ef | grep /usr/bin/kdialog_progress_helper | grep -v grep | awk '{print $2 }'` && if [ $pid ] ; then kill -9 $pid ; fi
# Prepare key partitions
# exit a dropper
#exit
kdialog --title "Partitionement et formatage du disque $DRIVEUSB" --passivepopup "Veuillez patienter..." 5 &
#Cleaning any existing partitions definitions
dd if=/dev/zero of=/dev/$DRIVEUSB bs=1 count=2047
sfdisk /dev/$DRIVEUSB < sdapart_$keytype
partprobe
echo "USB PARTITIONS CREATED !"
kdialog --title "Creation de la clé FREE_SOLUTIONS OS sur le Disque : $DRIVEUSB" --passivepopup "Veuillez patienter jusqu'au message\n\"Clé USB Free-Solutions OS Prette à l'utilisation\"\nCeci peut durer plusieurs heures..." 10 &
echo "Copying Partitions ..."
unzstd -c sda1.dd.zst | pv -B4096 > /dev/$DRIVEUSB\1
unzstd -c sda2.dd.zst | pv -B4096 > /dev/$DRIVEUSB\2
unzstd -c sda3.dd.zst | pv -B4096 > /dev/$DRIVEUSB\3
kdialog --title "Creation de la clé FREE_SOLUTIONS OS sur le Disque : $DRIVEUSB" --passivepopup "Veuillez patienter jusqu'au message\n\"Clé USB Free-Solutions OS Prette à l'utilisation\"\nCeci peut durer plusieurs heures..." 20 &
unzstd -c sda4.dd.zst | pv -B4096 > /dev/$DRIVEUSB\4
kdialog --title "Creation de la clé FREE_SOLUTIONS OS sur le Disque : $DRIVEUSB" --passivepopup "Veuillez patienter jusqu'au message\n\"Clé USB Free-Solutions OS Prette à l'utilisation\"\nCeci peut durer plusieurs heures..." 20 &
sleep 1
mkfs -F -t ext4 -L casper-rw /dev/$DRIVEUSB\5
sync
/bin/mount -o noatime /dev/$DRIVEUSB\5 /mnt
if ! mountpoint -q /mnt
then
echo "IMPOSSIBLE DE MONTER LA PARTITION 5 \n VEUILLEZ vérifier votre clé USB \n L'installation a échoué" && exit
kdialog --msgbox "Linstallation de Free-Solutions a échoué\nVeuillez vérifier votre clé !!!"
fi
cd /mnt
kdialog --title "Installation de la distrubution sur le Disque : $DRIVEUSB" --passivepopup "Veuillez patienter jusqu'au message\n\"Clé USB Free-Solutions OS Prette à l'utilisation\"\nCeci peut durer plusieurs heures..." 20 &
unzstd -c $DISTFOLDER/sda5.tar.zst | tar xvf -
cd /
kdialog --title "SYNCHRONISATION sur le Disque : $DRIVEUSB" --passivepopup "Veuillez Patienter \n Synchronisation fichier et bien attendre jusqu'au message clé prette !!!\n Ca peut être long, selon votre machine..." 30 &
echo "SYNC en cours... Veuillez patienter"
sync
/bin/umount /mnt
cd ..
sleep 2
# Partion compat for USB 2.0 definition
#
echo "Recreating Partition table for USB 2.0 UEFI Boot..."
dd if=$DISTFOLDER/Partitions_$keytype.dd of=/dev/$DRIVEUSB bs=1 count=2047
sync
#
echo "Reformatting Swap Partition"
mkswap /dev/$DRIVEUSB\6
kdialog --msgbox "Clé USB version 4.0x Free-Solutions OS Prette à l'utilisation"
#
# Cleanup DISTRO Folder
#
kdialog --title "Effacer la DISTRO - 6GB en moins" --warningyesno "La Distribution FREE-SOLUTIONS\nse trouve sur votre disque\nVoulez vous la garder ?"
if [ $? = 1 ]; then rm -rf $DISTFOLDER ;fi
kdialog --msgbox "Félicitations, vous pouvez maintenant bootez votre Clé USB Free-Solutions !!!"