mirror of
https://github.com/fsquillace/junest.git
synced 2026-01-23 18:45:53 +00:00
166 lines
4.7 KiB
Bash
Executable file
166 lines
4.7 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
#
|
|
# This file is part of JuJu: The portable GNU/Linux distribution
|
|
#
|
|
# Copyright (c) 2012-2014 Filippo Squillace <feel.squally@gmail.com>
|
|
#
|
|
# This program is free software; you can redistribute it and/or modify it
|
|
# under the terms of the GNU Library General Public License as published
|
|
# by the Free Software Foundation; either version 2, or (at your option)
|
|
# any later version.
|
|
#
|
|
# This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
|
#
|
|
|
|
NAME='juju'
|
|
VERSION='1.0'
|
|
|
|
source "$(dirname $0)/../lib/core.sh"
|
|
|
|
###################################
|
|
### General functions ###
|
|
###################################
|
|
|
|
usage() {
|
|
echo -e "JuJu: The portable GNU/Linux distribution"
|
|
echo -e "Usage: $NAME [options]"
|
|
echo -e "Options:"
|
|
echo -e "-i, --setup-from-file <image> Setup the JuJu image in ${JUJU_HOME}"
|
|
echo -e "-f, --fakeroot Run JuJu with fakeroot privileges"
|
|
echo -e "-r, --root Run JuJu with root privileges"
|
|
echo -e "-b, --build-image Build a JuJu image (must run in ArchLinux)"
|
|
echo -e "-d, --delete Delete JuJu from ${JUJU_HOME}"
|
|
echo -e "-h, --help Show this help message"
|
|
echo -e "-v, --version Show the $NAME version"
|
|
}
|
|
|
|
version() {
|
|
echo -e "JuJu ($VERSION): The portable GNU/Linux distribution"
|
|
echo -e "Copyright (c) 2012-2014 Filippo Squillace <feel.squally@gmail.com>"
|
|
echo -e "Homepage: http://github.com/fsquillace/juju"
|
|
}
|
|
|
|
check_cli(){
|
|
if $OPT_BUILD_IMAGE
|
|
then
|
|
if $OPT_DELETE || $OPT_HELP || $OPT_VERSION || $OPT_SETUP_FROM_FILE || \
|
|
$OPT_FAKEROOT || $OPT_ROOT
|
|
then
|
|
die "The build image option must be used exclusively"
|
|
fi
|
|
fi
|
|
if $OPT_DELETE
|
|
then
|
|
if $OPT_BUILD_IMAGE || $OPT_HELP || $OPT_VERSION || $OPT_SETUP_FROM_FILE || \
|
|
$OPT_FAKEROOT || $OPT_ROOT
|
|
then
|
|
die "The JuJu delete option must be used exclusively"
|
|
fi
|
|
fi
|
|
if $OPT_HELP
|
|
then
|
|
if $OPT_BUILD_IMAGE || $OPT_DELETE || $OPT_VERSION || $OPT_SETUP_FROM_FILE || \
|
|
$OPT_FAKEROOT || $OPT_ROOT
|
|
then
|
|
die "The JuJu help option must be used exclusively"
|
|
fi
|
|
fi
|
|
if $OPT_VERSION
|
|
then
|
|
if $OPT_BUILD_IMAGE || $OPT_DELETE || $OPT_HELP || $OPT_SETUP_FROM_FILE || \
|
|
$OPT_FAKEROOT || $OPT_ROOT
|
|
then
|
|
die "The JuJu version option must be used exclusively"
|
|
fi
|
|
fi
|
|
|
|
if $OPT_FAKEROOT && $OPT_ROOT
|
|
then
|
|
die "You must access to JuJu with either fakeroot or root permissions"
|
|
fi
|
|
|
|
[ "$ARGS" != "" ] && die "No arguments are needed. For the CLI syntax run: $NAME --help"
|
|
|
|
return 0
|
|
}
|
|
|
|
|
|
###################################
|
|
### MAIN PROGRAM ###
|
|
###################################
|
|
|
|
TEMP=`getopt -o drfbi:hv --long delete,root,fakeroot,build-image,setup-from-file:,help,version -n 'juju' -- "$@"`
|
|
|
|
if [ $? != 0 ] ; then error "Error on parsing the command line. Try juju -h." ; exit ; fi
|
|
|
|
# Note the quotes around `$TEMP': they are essential!
|
|
eval set -- "$TEMP"
|
|
|
|
OPT_SETUP_FROM_FILE=false
|
|
IMAGE_FILE=""
|
|
OPT_FAKEROOT=false
|
|
OPT_ROOT=false
|
|
OPT_BUILD_IMAGE=false
|
|
OPT_DELETE=false
|
|
OPT_HELP=false
|
|
OPT_VERSION=false
|
|
while true ; do
|
|
case "$1" in
|
|
-i|--setup-from-file) OPT_SETUP_FROM_FILE=true ; shift ; IMAGE_FILE=$1 ; shift ;;
|
|
-f|--fakeroot) OPT_FAKEROOT=true ; shift ;;
|
|
-r|--root) OPT_ROOT=true ; shift ;;
|
|
-b|--build-image) OPT_BUILD_IMAGE=true ; shift ;;
|
|
-d|--delete) OPT_DELETE=true ; shift ;;
|
|
-h|--help) OPT_HELP=true ; shift ;;
|
|
-v|--version) OPT_VERSION=true ; shift ;;
|
|
--) shift ; break ;;
|
|
*) error "Internal error!" ; exit 1 ;;
|
|
esac
|
|
done
|
|
|
|
ARGS=()
|
|
for arg do
|
|
ARGS+=($arg)
|
|
done
|
|
|
|
check_cli || exit 1
|
|
|
|
################ DEFINE ACTION ########################
|
|
|
|
$OPT_HELP && usage && exit
|
|
$OPT_VERSION && version && exit
|
|
|
|
if $OPT_BUILD_IMAGE; then
|
|
build_image_juju
|
|
exit
|
|
elif $OPT_DELETE; then
|
|
delete_juju
|
|
exit
|
|
fi
|
|
|
|
if ! is_juju_installed
|
|
then
|
|
if $OPT_SETUP_FROM_FILE; then
|
|
setup_from_file_juju $IMAGE_FILE
|
|
else
|
|
setup_juju
|
|
fi
|
|
elif $OPT_SETUP_FROM_FILE; then
|
|
die "Error: The image cannot be installed since $JUJU_HOME is not empty."
|
|
fi
|
|
|
|
if $OPT_FAKEROOT; then
|
|
run_juju_as_fakeroot
|
|
elif $OPT_ROOT; then
|
|
run_juju_as_root
|
|
else
|
|
run_juju_as_user
|
|
fi
|
|
|
|
# vim: set ts=4 sw=4 noet:
|