improved readability
This commit is contained in:
+41
-31
@@ -1,39 +1,49 @@
|
||||
#!/bin/bash
|
||||
|
||||
## CONSTANTS
|
||||
|
||||
function install() {
|
||||
readonly CURDIR=$PWD
|
||||
readonly REQUIRED_PKGS=(file git bc)
|
||||
readonly MAIN_TAR_GZ_URL="https://git.artcode.re/miaou/miaou-bash/archive/main.tar.gz"
|
||||
|
||||
## FUNCTIONS
|
||||
|
||||
function push_directory {
|
||||
pushd "$1" || echo "unable to push directory <$1>" && exit 1
|
||||
}
|
||||
|
||||
function pop_directory {
|
||||
popd || echo "unable to pop from previous directory" && exit 1
|
||||
}
|
||||
|
||||
function root_required {
|
||||
[ "$(id -u)" -ne 0 ] && echo 'root privilege required' && exit 1
|
||||
|
||||
if [[ ! $CURDIR == '/opt/miaou-bash' ]]; then
|
||||
# download and fullfill /opt/miaou-bash, then run it from folder
|
||||
|
||||
if [[ -L /opt/miaou-bash ]]; then
|
||||
cd /opt/miaou-bash && ./install.sh
|
||||
exit 0
|
||||
else
|
||||
rm -rf /opt/miaou-bash
|
||||
TEMP=$(mktemp -d)
|
||||
cd "$TEMP" || return
|
||||
echo "$TEMP"
|
||||
wget https://git.artcode.re/miaou/miaou-bash/archive/main.tar.gz
|
||||
tar -xzf main.tar.gz
|
||||
mv miaou-bash /opt/
|
||||
cd /opt/miaou-bash || return
|
||||
./install.sh "$PARAM1"
|
||||
rm -rf "$TEMP"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
else
|
||||
apt-get update
|
||||
apt-get install -y "${REQUIRED_PKGS[@]}"
|
||||
./init.sh
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
## MAIN
|
||||
|
||||
CURDIR=$PWD
|
||||
REQUIRED_PKGS=(file git bc)
|
||||
install
|
||||
root_required
|
||||
|
||||
if [[ $CURDIR != '/opt/miaou-bash' ]]; then
|
||||
# download and fullfill /opt/miaou-bash, then run it from folder
|
||||
|
||||
if [[ -L /opt/miaou-bash ]]; then
|
||||
/opt/miaou-bash/install.sh
|
||||
else
|
||||
rm -rf /opt/miaou-bash
|
||||
|
||||
push_directory "$(mktemp -d)"
|
||||
wget $MAIN_TAR_GZ_URL
|
||||
tar -xzf main.tar.gz
|
||||
mv miaou-bash /opt/
|
||||
pop_directory
|
||||
rm -rf "$TEMP"
|
||||
|
||||
push_directory /opt/miaou-bash && ./install.sh
|
||||
|
||||
fi
|
||||
|
||||
else
|
||||
apt-get install -y "${REQUIRED_PKGS[@]}"
|
||||
./init.sh
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user