Depfreez for Linux [Made Indonesia]


#!/bin/bash

# =============================================
#  Dafturn Ofris Erdana - Locking your Systems
# =============================================
# Version       : 1.9.05-en
# Created by    : Dafturn Group Software
#                 The Mad Transition
# Author        : Muhammad Faruq Nuruddinsyah
# E-Mail        : faruq_dafturn@yahoo.co.id
# Date Creating : October, 12th 2008
# =============================================
# An Open Source from Indonesia
# =============================================


#----- Starting ----
echo 
echo "==================================================="
echo "    Dafturn Ofris Erdana - Locking your Systems"
echo "         By : Muhammad Faruq Nuruddinsyah"
echo "==================================================="
echo 
echo "Your choice :"
echo "  1. Freeze the system for this User only"
echo "  2. Freeze the system for specified User"
echo "  3. Freeze the system for all Users"
echo "  4. Unfreeze the system"
echo "  5. View status"
echo "  6. Exit"
echo 
#-------------------

#----- Mendeklarasikan variabel -----
is_opt=false
is_success=true
ofris_n=6
ofris_tmp_co=1
is_cho=false
#------------------------------------

#----- Awal script untuk menentukan pilihan -----
while [ $is_opt = false ]; do
echo -n "Please insert your choice number : "
read ofris_opt

if [[ $ofris_opt = 1 ]]; then
is_opt=true
ofris_tmp_co=1
elif [[ $ofris_opt = 2 ]]; then
is_opt=true
ofris_tmp_co=2
elif [[ $ofris_opt = 3 ]]; then
is_opt=true
ofris_tmp_co=3
elif [[ $ofris_opt = 4 ]]; then
is_opt=true
elif [[ $ofris_opt = 5 ]]; then
is_opt=true
elif [[ $ofris_opt = 6 ]]; then
is_opt=true
echo 
exit
else
echo "Sorry, your choice number is wrong. Please try again..."
echo
is_opt=false
fi

done
#------------------------------------------------

#----- Script utama -----------------------------
if [[ $ofris_tmp_co = 1 ]]; then
ofris_user="${HOME:$ofris_n}"
elif [[ $ofris_tmp_co = 3 ]]; then
ofris_user=""
elif [[ $ofris_tmp_co = 2 ]]; then
is_cho=true
ofris_user=""
fi

grep -v "sudo rsync -a --delete /etc/" /etc/rc.local > ofris_tmp
set $(wc -l ofris_tmp)
ofris_orig=$1
set $(wc -l /etc/rc.local)
ofris_recnt=$1
ofris_rst=$[$ofris_recnt-$ofris_orig]
rm ofris_tmp

if [[ $ofris_opt = '1' || $ofris_opt = '2' || $ofris_opt = '3' ]]; then
#----- Mengunci sistem -----
echo 
echo "===== Freeze the System ====="
echo 
echo "Please wait..."
echo 

if [[ $is_cho = true ]]; then
is_cho_suc=false
while [ $is_cho_suc = false ]; do
is_cho_suc=false
echo -n "Please insert the User name that you will be Freezed : "
read ofris_cho
if [ -d "/home/$ofris_cho" ]; then
echo 
is_cho_suc=true
ofris_user=$ofris_cho
else
echo "Sorry, the User name is wrong. Please try again..."
echo 
fi
done
fi

if [ $ofris_rst = 1 ]; then 
echo "Error : The system has been locked, please select the fourth choice to unfreeze the system..."
echo 
is_success=false
else
grep -v "exit 0" /etc/rc.local > ofris_tmp
echo "sudo rsync -a --delete /etc/.ofris/$ofris_user/ /home/$ofris_user/" >> ofris_tmp
echo "exit 0" >> ofris_tmp
sudo rm /etc/rc.local
sudo cp ofris_tmp /etc/rc.local
rm ofris_tmp
fi

if [ $is_success = true ]; then
if [ -d /etc/.ofris ]; then
sudo rm -r /etc/.ofris
fi
if [ -d /etc/.ofris ]; then
sudo rsync -a --delete /home/$ofris_user /etc/.ofris/
else
sudo mkdir /etc/.ofris/
if [[ $ofris_user != "" ]]; then
sudo mkdir /etc/.ofris/$ofris_user
fi
sudo rsync -a --delete /home/$ofris_user /etc/.ofris/
fi
sudo chmod +x /etc/rc.local
fi

if [ $is_success = true ]; then
echo "The system was successfully freezed, please restart your computer now..."
echo 
fi

elif [ $ofris_opt = '4' ]; then
#----- Membuka sistem -----
echo 
echo "===== Unfreeze the System ====="
echo 
echo "Please wait..."
grep -v "sudo rsync -a --delete /etc/" /etc/rc.local > ofris_tmp_b
sudo rm /etc/rc.local
sudo cp ofris_tmp_b /etc/rc.local
rm ofris_tmp_b
if [ -d /etc/.ofris ]; then
sudo rm -r /etc/.ofris
fi
echo 
echo "The system was successfully unfreezed..."
echo 

elif [ $ofris_opt = '5' ]; then
#----- Menampilkan status -----
if [ $ofris_rst = 1 ]; then
echo 
echo "===== Status ====="
echo " The system has been locked..."
echo 
else
echo 
echo "===== Status ====="
echo " The system has not locked yet..."
echo 
fi
fi

#----- Ending session -----
echo -n "[Press any key to exit...] "
read -s -n 1
echo 
echo 

#========== Selesai ===================================================================

Share on Google Plus

About Elmirakom

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment