aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkaotisk <kaotisk@arching-kaos.org>2025-03-08 17:14:59 +0200
committerkaotisk <kaotisk@arching-kaos.org>2025-03-08 17:14:59 +0200
commit08910e5a4f53eb4d99e6ac06951977857535d9ca (patch)
tree2f593b55099dd098afe7f084e47a83ed6e436452
parent5b9d80959bdfab7fedb7a307d324811ba49b6aa5 (diff)
downloadarching-kaos-tools-08910e5a4f53eb4d99e6ac06951977857535d9ca.tar.gz
arching-kaos-tools-08910e5a4f53eb4d99e6ac06951977857535d9ca.tar.bz2
arching-kaos-tools-08910e5a4f53eb4d99e6ac06951977857535d9ca.zip
Refactored install scripts
-rwxr-xr-xinit.sh10
-rwxr-xr-xinstall.sh40
-rwxr-xr-xipfs-check-install-setup-init-update44
-rwxr-xr-xlib/_ak_ipfs39
-rwxr-xr-xlib/_ak_script50
5 files changed, 98 insertions, 85 deletions
diff --git a/init.sh b/init.sh
index 06a390c..b0bacfd 100755
--- a/init.sh
+++ b/init.sh
@@ -2,6 +2,7 @@
#set -x
source lib/_ak_ipfs
source lib/_ak_settings
+source lib/_ak_gpg
# TODO GPG/PGP setup:: possibly done
# eg gpg2 --full-key-generate and/or gpg2 --set-default key
@@ -65,15 +66,16 @@ then
printf "%s" "$(_ak_ipfs key list -l | grep zchain | awk '{ print $1 }')" > $AK_ZCHAIN
fi
fi
+
if [ ! -f $AK_ZLATEST ] ; then cp $AK_ZGENESIS $AK_ZLATEST;fi
if [ ! -f $AK_ZCHAINASC ] ; then gpg2 --homedir $AK_GPGHOME -bao $AK_ZCHAINASC $AK_ZCHAIN;fi
if [ ! -f $AK_ZZCHAIN ] ; then printf "%s" "$(_ak_ipfs add -q $AK_ZCHAINASC)" > $AK_ZZCHAIN;fi
if [ ! -f $AK_GENESISASC ] ; then gpg2 --homedir $AK_GPGHOME -bao $AK_GENESISASC $AK_GENESIS;fi
if [ ! -f $AK_ZGENESISASC ] ; then printf "%s" "$(_ak_ipfs add -q $AK_GENESISASC)" > $AK_ZGENESISASC;fi
-if [ ! -f $AK_ZBLOCKSFILE ] ; then printf "[]" > $AK_ZBLOCKSFILE;fi
-if [ ! -f $AK_ZPAIRSFILE ] ; then printf "[]" > $AK_ZPAIRSFILE;fi
-if [ ! -f $AK_ZPEERSFILE ] ; then printf "[]" > $AK_ZPEERSFILE;fi
-if [ ! -d $AK_ZPEERSDIR ] ; then mkdir $AK_ZPEERSDIR;fi
+
+_ak_init_file_as_json_array $AK_ZPAIRSFILE
+_ak_init_file_as_json_array $AK_ZPEERSFILE
+_ak_init_file_as_json_array $AK_ZBLOCKSFILE
ipfs_zarchive_check_or_mkdir
diff --git a/install.sh b/install.sh
index d90db3e..922d7c2 100755
--- a/install.sh
+++ b/install.sh
@@ -69,40 +69,8 @@ _ak_usage
printf "Installation starts in..."
-countdown_seconds(){
- default_countdown=5
- if [ ! -z "$1" ] && [ -n "$1" ]
- then
- if [ "$(echo -n $1 | sed -e 's/^[0-9]*$//g')" == "" ]
- then
- countdown=$1
- else
- countdown=${default_countdown}
- fi
- else
- countdown=${default_countdown}
- fi
- printf " %s" "$countdown"
- countdown="$(expr $countdown - 1)"
- sleep 1
- while [ $countdown -gt 0 ]
- do
- if [ $countdown -lt 10 ]
- then
- printf "\b\b %s" "$countdown"
- else
- printf "\b\b%s" "$countdown"
- fi
- countdown="$(expr $countdown - 1)"
- sleep 1
- done
- printf "\b\b starting!!!"
- sleep 1
- printf "\n"
-}
-
-countdown_seconds 5
+_ak_countdown_seconds 5
_ak_check_and_create_dir $AK_CONFIGDIR
_ak_check_and_create_dir $AK_BINDIR
@@ -119,6 +87,7 @@ _ak_check_and_create_dir $AK_CHUNKSDIR
_ak_check_and_create_dir $AK_LEAFSDIR
_ak_check_and_create_dir $AK_MAPSDIR
_ak_check_and_create_dir $AK_GPGHOME
+_ak_check_and_create_dir $AK_ZPEERSDIR
chmod 700 $AK_GPGHOME
_ak_let_there_be_file $AK_ZLATEST_HISTORY
_ak_let_there_be_file $AK_GENESIS
@@ -226,7 +195,7 @@ then
if [ $? -eq 0 ]
then
_ak_log_debug "Making a gpg2 link"
- $sudoBin ln -s `which gpg` /usr/bin/gpg2
+ ln -s `which gpg` $AK_BINDIR/gpg2
fi
fi
@@ -270,7 +239,8 @@ else
fi
bash update.sh
-bash ipfs-check-install-setup-init-update
+source ./lib/_ak_ipfs
+_ak_ipfs_check_and_install
source ./config.sh
source $HOME/$SHELLRC
bash init.sh
diff --git a/ipfs-check-install-setup-init-update b/ipfs-check-install-setup-init-update
deleted file mode 100755
index 3aa1d6d..0000000
--- a/ipfs-check-install-setup-init-update
+++ /dev/null
@@ -1,44 +0,0 @@
-#!/usr/bin/env bash
-PROGRAM="$(basename $0)"
-source lib/_ak_script
-source lib/_ak_log
-source lib/_ak_ipfs
-
-if [ ! -d $AK_BINDIR ]; then mkdir $AK_BINDIR ;fi
-if [ ! -d $AK_ARCHIVESDIR ]; then mkdir $AK_ARCHIVESDIR ;fi
-
-_ak_ipfs_install(){
- _ak_log_info "Making temp files"
- pwd > pwd
- mktemp -d > tempassin
- ak_curdir=$(cat pwd)
- TEMPASSIN=$(cat tempassin)
- cd $TEMPASSIN
- tar xf $AK_ARCHIVESDIR/$IPFS_TARGET_FILE
- cp kubo/ipfs $AK_BINDIR/kubo
- cd $ak_curdir
- rm -rf $TEMPASSIN
- _ak_log_info "ipfs installed on $AK_BINDIR"
-}
-
-which kubo > /dev/null 2>&1
-if [ $? -ne 0 ]
-then
- _ak_ipfs_download
- _ak_ipfs_install
- _ak_ipfs init
- _ak_ipfs_swarm_install
-else
- _ak_log_info "Found IPFS! Skipping downloading..."
- _ak_ipfs_swarm_install
-fi
-if [ ! -d $AK_IPFS_REPO ]
-then
- _ak_ipfs init
- _ak_ipfs_swarm_install
-fi
-
-if [ ! -f $AK_ZGENESIS ]
-then
- ipfs add -Q $AK_GENESIS > $AK_ZGENESIS
-fi
diff --git a/lib/_ak_ipfs b/lib/_ak_ipfs
index c2787be..c357f07 100755
--- a/lib/_ak_ipfs
+++ b/lib/_ak_ipfs
@@ -458,7 +458,7 @@ function _ak_ipfs_init(){
}
function _ak_ipfs_download(){
- _ak_log_info "Attempting to install IPFS..."
+ _ak_log_info "Figuring latest compatible version of kubo (IPFS)..."
IPFS_VERSION="$(curl \
--connect-timeout 3 \
-s https://dist.ipfs.tech/kubo/versions | tail -1)"
@@ -489,6 +489,43 @@ function _ak_ipfs_download(){
fi
}
+_ak_ipfs_install(){
+ _ak_log_info "Making temp files"
+ pwd > pwd
+ mktemp -d > tempassin
+ ak_curdir=$(cat pwd)
+ TEMPASSIN=$(cat tempassin)
+ cd $TEMPASSIN
+ tar xf $AK_ARCHIVESDIR/$IPFS_TARGET_FILE
+ cp kubo/ipfs $AK_BINDIR/kubo
+ cd $ak_curdir
+ rm -rf $TEMPASSIN
+ _ak_log_info "ipfs installed on $AK_BINDIR"
+}
+
+function _ak_ipfs_check_and_install(){
+ which kubo > /dev/null 2>&1
+ if [ $? -ne 0 ]
+ then
+ _ak_ipfs_download
+ _ak_ipfs_install
+ _ak_ipfs init
+ _ak_ipfs_swarm_install
+ else
+ _ak_log_info "Found IPFS! Skipping downloading..."
+ _ak_ipfs_swarm_install
+ fi
+ if [ ! -d $AK_IPFS_REPO ]
+ then
+ _ak_ipfs init
+ _ak_ipfs_swarm_install
+ fi
+ if [ ! -f $AK_ZGENESIS ]
+ then
+ _ak_ipfs add -Q $AK_GENESIS > $AK_ZGENESIS
+ fi
+}
+
function _ak_ipfs_cid_v0_check(){
if [ -z $1 ] || [ ! -n "$1" ]
then
diff --git a/lib/_ak_script b/lib/_ak_script
index ee422d5..b0a0785 100755
--- a/lib/_ak_script
+++ b/lib/_ak_script
@@ -140,7 +140,7 @@ function _ak_make_temp_file(){
}
function _ak_check_and_create_dir(){
- if [ ! -d "$1" ]
+ if [ ! -z "$1" ] && [ -n "$1" ] && [ ! -d "$1" ]
then
mkdir -p "$1"
if [ $? -eq 0 ]
@@ -170,3 +170,51 @@ function _ak_let_there_be_file(){
_ak_log_debug "$1 file found"
fi
}
+
+function _ak_init_file_as_json_array(){
+ if [ ! -f "$1" ]
+ then
+ printf "[]" > $1
+ if [ $? -eq 0 ]
+ then
+ _ak_log_info "File $1 created!"
+ else
+ _ak_log_error "Problem occured while creating $1"
+ exit 1
+ fi
+ else
+ _ak_log_debug "$1 file found"
+ fi
+}
+
+function _ak_countdown_seconds(){
+ default_countdown=5
+ if [ ! -z "$1" ] && [ -n "$1" ]
+ then
+ if [ "$(echo -n $1 | sed -e 's/^[0-9]*$//g')" == "" ]
+ then
+ countdown=$1
+ else
+ countdown=${default_countdown}
+ fi
+ else
+ countdown=${default_countdown}
+ fi
+ printf " %s" "$countdown"
+ countdown="$(expr $countdown - 1)"
+ sleep 1
+ while [ $countdown -gt 0 ]
+ do
+ if [ $countdown -lt 10 ]
+ then
+ printf "\b\b %s" "$countdown"
+ else
+ printf "\b\b%s" "$countdown"
+ fi
+ countdown="$(expr $countdown - 1)"
+ sleep 1
+ done
+ printf "\b\b starting!!!"
+ sleep 1
+ printf "\n"
+}