Skip to content

Instantly share code, notes, and snippets.

@kalbasit
Created February 1, 2011 17:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kalbasit/806209 to your computer and use it in GitHub Desktop.
Save kalbasit/806209 to your computer and use it in GitHub Desktop.
Un script pour nous aider à installer facilement Kenshin
#!/usr/bin/env bash
# -*- encoding : utf-8 -*-
# -*- bash -*-
#--
# vim:ft=sh:fenc=UTF-8:ts=2:sts=2:sw=2:expandtab
#
# Copyright 2011 Wael Nasreddine <wael@agence-durable.com>
#
# install_kenshin is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option)
# any later version.
#
# Cardslib is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# install_kenshin. If not, see http://www.gnu.org/licenses/
#++
####
if [ ! -x `/usr/bin/which sudo 2>/dev/null` -a `id -u` != 0 ]; then
echo "sudo n'est pas installé, vous devez lancer ce script sous root, en faisant su -"
exit 1
elif [ -x `/usr/bin/which sudo 2>/dev/null` ]; then
SUDO=`/usr/bin/which sudo 2>/dev/null`
if yes 'NOPASS' | $SUDO -S -l 2> /dev/null | grep -q "NOPASSWD"; then
SUDO_NOPASSWD=1
else
SUDO_NOPASSWD=0
fi
fi
if [ `id -u` = 0 ]; then
echo "Quel utilisateur linux vous souhaiter configurer pour accèder à Kenshin?"
read unixuser
else
unixuser=$USER
fi
echo "Quel est votre prénom (sans accent)?"
read first_name
echo "Quel est votre mot de passe pour accèder à Kenshin?"
read password
user_home=`grep $unixuser /etc/passwd | cut -d: -f6`
user_group_id=`id -g $unixuser`
user_group=`grep $user_group_id /etc/group | cut -d: -f1`
echo "Avez-vous accès au dossier Associes [O/n]?"
read associes
if [ "`echo ${associes} | tr A-Z a-z`" = "o" ]; then
associes=1
else
associes=0
fi
if [ "${associes}" = 1 ]; then
mkdir -p "${user_home}/Kenshin/Associes"
fi
for dir in Equipe Stagiaire Home; do
mkdir -p "${user_home}/Kenshin/${dir}"
done
if [ "${unixuser}" != $USER ]; then
sudo chown -R "${unixuser}:" "${user_home}/Kenshin"
fi
if [ "${SUDO_NOPASSWD}" = 0 ]; then
echo "Renseigner votre mot de passe sudo pour ouvrir une session sudo"
sudo echo "Merci"
fi
echo "username=${first_name}" | sudo tee /etc/cifspwd > /dev/null
echo "password=${password}" | sudo tee -a /etc/cifspwd > /dev/null
sudo chown root: /etc/cifspwd
sudo chmod 0600 /etc/cifspwd
echo "" | sudo tee -a /etc/fstab > /dev/null
echo "# Kenshin" | sudo tee -a /etc/fstab > /dev/null
if [ "${associes}" = 1 ]; then
echo "192.168.1.2:/volume1/Associes ${user_home}/Kenshin/Associes nfs noauto,user 0 0" | sudo tee -a /etc/fstab > /dev/null
fi
echo "192.168.1.2:/volume1/Equipe ${user_home}/Kenshin/Equipe nfs noauto,user 0 0" | sudo tee -a /etc/fstab > /dev/null
echo "192.168.1.2:/volume1/Stagiaire ${user_home}/Kenshin/Stagiaire nfs noauto,user 0 0" | sudo tee -a /etc/fstab > /dev/null
echo "//192.168.1.2/home ${user_home}/Kenshin/Home cifs user,uid=$unixuser,gid=$user_group,rw,suid,credentials=/etc/cifspwd 0 0" | sudo tee -a /etc/fstab > /dev/null
cat <<EOF | sudo tee /usr/local/bin/Kenshin > /dev/null
#!/usr/bin/env bash
if [ \`id -u\` = 0 ]; then
echo "Quel est votre utilisateur?"
read unixuser
else
unixuser=\$USER
fi
if [ -x \`/usr/bin/which sudo 2>/dev/null\` ]; then
SUDO=\`/usr/bin/which sudo 2>/dev/null\`
if yes 'NOPASS' | \$SUDO -S -l 2> /dev/null | grep -q "NOPASSWD"; then
SUDO_NOPASSWD=1
else
SUDO_NOPASSWD=0
fi
fi
user_home=\`grep \$unixuser /etc/passwd | cut -d: -f6\`
cd "\${user_home}/Kenshin"
for dir in Associes Equipe Stagiaire; do
if [ -d "\${dir}" ]; then
mount "\${dir}"
fi
done
if [ "\${SUDO_NOPASSWD}" = 0 ]; then
echo "Merci de renseigner votre mot de passe sudo (si demandé)"
fi
sudo mount Home
EOF
sudo chmod a+x /usr/local/bin/Kenshin
echo
echo 'Félicitations!'
echo "L'installation est terminée, assurez-vous que CIFS et NFS sont installé"
echo "Sur Ubuntu/Debian, faites sudo apt-get install smbfs nfs-common"
echo "Sur Fedora, faites sudo yum install nfs-utils cifs-utils"
echo
echo "Pour monter Kenshin, lancer /usr/local/bin/Kenshin ou tout simplement Kenshin"
echo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment