diff --git a/check.bash b/check.bash index 4709c7b..60352b0 100755 --- a/check.bash +++ b/check.bash @@ -1,101 +1,14 @@ #!/bin/bash -#set -x # debug mode +# The componet to check system related things -# This should work on a Debian based system, any of them -# Requires makeself and apt +if [ -f /usr/bin/makeself.sh ]; then + # makeself is installed + echo "makeself is installed, good" -# Some menu things - -# colors -# red = 1 -# green = 2 -# yellow = 3 -# blue = 4 - -function cprint () { - color="$1" - shift - echo "$(tput setaf $color)$*$(tput sgr0)" - -} - -function mprint (){ - echo " $1 - $2" -} - -function incorrect_selection() { - cprint 1 "Incorrect selection! Try again." -} - -function press_enter() { - echo "" - cprint 3 "Press Enter to continue " - read - clear -} - -function copy_config() { - cprint 2 "Creating restorable package..." - sleep 1 - tmpdir=$(mktemp -d) - echo $tmpdir - cp -r /etc/ $tmpdir - dpkg --get-selections > $tmpdir/installed_packages - arcdir=$(mktemp -d) - echo $arcdir - mkslf=$(which makeself.sh) - echo $mkslf - cp ./restore.bash $tmpdir - $mkslf --gzip $tmpdir $arcdir/restore.run "SFX archive for restoration" ./restore.bash - cp $arcdir/restore.run ./ - - cprint 2 "Done!" - -} - -function menu_option_two() { - cprint 2 "Installing makeself..." - sleep 1 - wget https://github.com/megastep/makeself/releases/download/release-2.5.0/makeself-2.5.0.run - chmod +x makeself-2.5.0.run - ./makeself-2.5.0.run - cd makeself-2.5.0 - cp *.sh /usr/bin - cprint 2 "Done!" -} - -function cleanup() { - cprint 2 "Cleaning up..." - sleep 1 - rm -rf $tmpdir - rm -rf $arcdir -} - -# Check for root only important on pure Debian as there is no sudo by default -if [ "$(id -u)" != "0" ]; then - # check is the system is debian - if [ -f /etc/debian_version ]; then - cprint 3 "Notice: This script may need to be run as root on Debian, especially if its a stock install. Also requires makeself to created a distributable self restorable package" ; press_enter ; - fi -fi - -until [ "$selection" = "0" ]; do -clear - echo "" - cprint 3 " Main Menu" - mprint 1 "Create a self restorable package" - mprint 2 "Install makeself(required) to create self restorable package" - mprint 0 "Exit" - echo "" - echo -n " Enter selection: " - read selection - echo "" - case $selection in - 1 ) clear ; copy_config ; press_enter ;; - 2 ) clear ; menu_option_two ; press_enter ;; - 0 ) clear ; cleanup ; exit ;; - * ) clear ; incorrect_selection ; press_enter ;; - esac -done +else + # makeself is not installed + echo "makeself is not installed please install via this application" + sleep 3 +fi \ No newline at end of file diff --git a/os_probe.bash b/os_probe.bash new file mode 100755 index 0000000..7fe0eef --- /dev/null +++ b/os_probe.bash @@ -0,0 +1,23 @@ +#!/bin/bash + +# OS probing component + +# Not an easy task to identify the distro, this app supports Debian based and Arch based +# Our best bet is to look for which package manager is installed + +# check if apt-get is installed + +if [ -x "$(command -v apt-get)" ]; then + # set environment variable for os + export osp="Debian" +fi + +# check if pacman is installed + +if [ -x "$(command -v pacman)" ]; then + export osp="Arch" +fi + +# I know its so high tech and amazing right? + + diff --git a/restore.bash b/restore.bash index 53c003d..9f80cb7 100755 --- a/restore.bash +++ b/restore.bash @@ -34,6 +34,7 @@ function restore_config() { apt install -y $(cat $aptpkgfile | awk '{print $1}') # we should be set app wise now the configs cp -R etc/ /etc + cprint 3 "You may want to reboot for changes to take effect" cprint 2 "Done!" } diff --git a/syssetup.bash b/syssetup.bash new file mode 100755 index 0000000..cae4160 --- /dev/null +++ b/syssetup.bash @@ -0,0 +1,97 @@ +#!/bin/bash + +if [ "$(id -u)" != "0" ]; then + echo "You should run this script as root" + sleep 3 + # exit 1 +fi + +# Check the OS, it sets a env variable as a result +./os_probe.bash +./check.bash + +# Some menu things + +# colors +# red = 1 +# green = 2 +# yellow = 3 +# blue = 4 + +function cprint () { + color="$1" + shift + echo "$(tput setaf $color)$*$(tput sgr0)" + +} + +function mprint (){ + echo " $1 - $2" +} + +function incorrect_selection() { + cprint 1 "Incorrect selection! Try again." +} + +function press_enter() { + echo "" + cprint 3 "Press Enter to continue " + read + clear +} + +function copy_config() { + cprint 2 "Creating restorable package..." + sleep 1 + tmpdir=$(mktemp -d) + echo $tmpdir + cp -r /etc/ $tmpdir + dpkg --get-selections > $tmpdir/installed_packages + arcdir=$(mktemp -d) + echo $arcdir + mkslf=$(which makeself.sh) + echo $mkslf + cp ./restore.bash $tmpdir + $mkslf --gzip $tmpdir $arcdir/restore.run "SFX archive for restoration" ./restore.bash + cp $arcdir/restore.run ./ + + cprint 2 "Done!" + +} + +function menu_option_two() { + cprint 2 "Installing makeself..." + sleep 1 + wget https://github.com/megastep/makeself/releases/download/release-2.5.0/makeself-2.5.0.run + chmod +x makeself-2.5.0.run + ./makeself-2.5.0.run + cd makeself-2.5.0 + cp *.sh /usr/bin + cprint 2 "Done!" +} + +function cleanup() { + cprint 2 "Cleaning up..." + sleep 1 + rm -rf $tmpdir + rm -rf $arcdir +} + +until [ "$selection" = "0" ]; do +clear + echo "" + cprint 3 " Main Menu" + mprint 1 "Create a self restorable package" + mprint 2 "Install makeself(required) to create self restorable package" + mprint 0 "Exit" + echo "" + echo -n " Enter selection: " + read selection + echo "" + case $selection in + 1 ) clear ; copy_config ; press_enter ;; + 2 ) clear ; menu_option_two ; press_enter ;; + 0 ) clear ; cleanup ; exit ;; + * ) clear ; incorrect_selection ; press_enter ;; + esac +done