Browse Source

install2

main
pvincent 3 weeks ago
parent
commit
1eb8459950
  1. 8
      install2.sh
  2. 28
      lib/functions.bash

8
install2.sh

@ -15,10 +15,12 @@ function install {
echo INSTALL echo INSTALL
MIAOU_BASH_DIR=/opt/miaou-bash MIAOU_BASH_DIR=/opt/miaou-bash
export MIAOU_BASH_DIR export MIAOU_BASH_DIR
cd /tmp
curl -sO $MAIN_TAR_GZ_URL
sudo tar -xzf main.tar.gz --directory "$(dirname "$MIAOU_BASH_DIR")"
local tempfile
tempfile="/tmp/$(basename "$MAIN_TAR_GZ_URL")"
curl -sO $MAIN_TAR_GZ_URL -o "$tempfile"
sudo tar -xzf "$tempfile" --directory "$(dirname "$MIAOU_BASH_DIR")"
execute_miaou_lib initiate execute_miaou_lib initiate
source /etc/profile source /etc/profile

28
lib/functions.bash

@ -2,17 +2,13 @@
## ASSERT Functions ## ASSERT Functions
function sudo_root {
[[ "$UID" -ne 0 ]] && sudo -vp 'SUDO privilege required: '
}
function assert_root { function assert_root {
[[ "$UID" -ne 0 ]] && echo 'root privilege required' && return 1 [[ "$UID" -ne 0 ]] && echo 'root privilege required' && return 1
true true
} }
function assert_container { function assert_container {
cat /proc/self/cgroup | grep -E '/session-c[0-9]+.scope'
cat /proc/self/cgroup | grep -qE'session-c[0-9]+\.scope'
} }
function assert_system_mode { function assert_system_mode {
@ -26,7 +22,6 @@ function assert_system_mode {
true true
} }
## =============== ## ===============
## ARRAY Functions ## ARRAY Functions
## =============== ## ===============
@ -34,7 +29,10 @@ function assert_system_mode {
function _array_contains { function _array_contains {
local -n array=$1 local -n array=$1
local element=$2 local element=$2
[[ " ${array[@]} " =~ " ${element} " ]] && return 0 || return 1
for item in "${array[@]}"; do
[[ "$item" == "$element" ]] && return 0
done
return 1
} }
function _array_intersect { function _array_intersect {
@ -50,9 +48,10 @@ function _array_intersect {
} }
function _array_subtract { function _array_subtract {
local -n arr1=$1 # First array
local -n arr2=$2 # Array to subtract
local -n result=$3 # Output array
local -n arr1 arr2 result
arr1=$1 # First array
arr2=$2 # Array to subtract
result=$3 # Output array
[[ ${#arr2[@]} == 0 ]] && result=("${arr1[@]}") && return [[ ${#arr2[@]} == 0 ]] && result=("${arr1[@]}") && return
@ -68,7 +67,7 @@ function _array_subtract {
function _pluralize_simple { function _pluralize_simple {
echo -n "$1 " echo -n "$1 "
[[ $1 -eq 1 || $1 -eq -1 ]] && echo ${2} || echo ${2}s
[[ $1 -eq 1 || $1 -eq -1 ]] && echo "${2}" || echo "${2}s"
} }
## ============== ## ==============
@ -89,7 +88,7 @@ function fetch_distro_like {
function _confirm_destructive { function _confirm_destructive {
local message="${1:-This cannot be undone!}" local message="${1:-This cannot be undone!}"
echo "⚠️ WARNING: $message" echo "⚠️ WARNING: $message"
read -p "Type YES to confirm: " response
read -rp "Type YES to confirm: " response
case "$response" in case "$response" in
[yY][eE][sS] | [yY]) return 0 ;; [yY][eE][sS] | [yY]) return 0 ;;
*) echo "canceled!" && return 1 ;; *) echo "canceled!" && return 1 ;;
@ -103,7 +102,7 @@ function _confirm_destructive {
function _flatten_short_options { function _flatten_short_options {
local -n args=$1 local -n args=$1
local result=() local result=()
for word in ${args[@]}; do
for word in "${args[@]}"; do
[[ $word == -- ]] && break [[ $word == -- ]] && break
if [[ $word =~ ^-[a-z][a-z] ]]; then if [[ $word =~ ^-[a-z][a-z] ]]; then
word=${word:1} word=${word:1}
@ -134,8 +133,7 @@ function get_distro_like {
return 1 return 1
} }
## ==============
## Deprecated: FIXME: to remove
## FIXME: Deprecated -> to remove
## ============== ## ==============
## ##

Loading…
Cancel
Save