-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstallchroot.sh
62 lines (52 loc) · 1.45 KB
/
installchroot.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/bin/sh
LGREEN=$(tput setaf 2; tput setaf bold)
ERRCOLOR=$(tput setaf 7; tput setaf bold; tput setab 1)
NC=$(tput sgr0)
ERRTAG="[${ERRCOLOR}ERROR${NC}]"
BASEPATH="${HOME}/Downloads"
CHROOTPATH="${BASEPATH}/chroots"
BOOTSTRAPPATH=${CHROOTPATH}/bootstraps
if [ $# -lt 1 ] || [ $# -gt 2 ]; then
echo "${ERRTAG} Invalid number of arguments; expected 1-2, got ${#}." >&2
exit 1
fi
CHROOTKERNEL=$1
while getopts ":n:p:" flags; do
case $flags in
n)
NFLAG=1
NAME=$OPTARG
;;
p)
BASEPATH=$OPTARG
CHROOTPATH="${BASEPATH}/chroots"
if [ ! -d $BASEPATH ]; then
echo "${ERRTAG} Invalid path: ${BASEPATH}" >&2
fi
;;
\?)
echo "${ERRTAG} Invalid option: -${OPTARG}" >&2
;;
:)
echo "${ERRTAG} Option -${OPTARG} requires argument." >&2
;;
esac
done
if [ ! -e ${CHROOTPATH}/crouton ]; then
ERRMSG="${ERRTAG} Crouton not installed."
ERRMSG="${ERRMSG} Run ${LGREEN}setupcrouton${NC} first."
echo $ERRMSG >&2
exit 1
fi
SHELLCMD="sudo sh ${CHROOTPATH}/crouton${NFLAG:+" -n ${NAME}"}"
BOOTSTRAPFILE=${BOOTSTRAPPATH}/${CHROOTKERNEL}bootstrap.tar.gz
if [ -f $BOOTSTRAPFILE ]; then
SHELLCMD="${SHELLCMD} -f ${BOOTSTRAPFILE}"
else
SHELLCMD="${SHELLCMD} -r ${CHROOTKERNEL}"
fi
if [ $# -eq 2 ]; then
CHROOTTARGETS=$2
SHELLCMD="${SHELLCMD} -t ${CHROOTTARGETS}"
fi
$SHELLCMD